Rev 11 | Rev 15 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 11 | Rev 14 | ||
|---|---|---|---|
| Line 12... | Line 12... | ||
| 12 | 12 | ||
| 13 | static ap_math math; |
13 | static ap_math math; |
| 14 | // this is the number of degrees between top centre of scale and |
14 | // this is the number of degrees between top centre of scale and |
| 15 | // left or right hand end of scale : 90 degrees produces a semicircle. |
15 | // left or right hand end of scale : 90 degrees produces a semicircle. |
| 16 | 16 | ||
| - | 17 | displayDial_t::displayDial_t(display_t &display, uint8_t x, uint8_t y, uint8_t siz, int16_t angle_low, int16_t angle_high) : m_display(display), m_xo(x), m_yo(y), m_siz(siz), m_angleRange(angle_high - angle_low), m_angleLow(angle_low) |
|
| - | 18 | { |
|
| - | 19 | } |
|
| - | 20 | ||
| 17 | displayDial_t::displayDial_t(display_t &display, uint8_t x, uint8_t y, uint8_t siz, uint16_t angle_) : m_display(display), m_xo(x), m_yo(y), m_siz(siz), m_a1(angle_) |
21 | displayDial_t::displayDial_t(display_t &display, uint8_t x, uint8_t y, uint8_t siz, uint16_t angle_) : m_display(display), m_xo(x), m_yo(y), m_siz(siz), m_angleRange(2 * angle_), m_angleLow(-angle_) |
| 18 | { |
22 | { |
| 19 | } |
23 | } |
| 20 | 24 | ||
| 21 | /* position is integer from 0 to SINE_STEPS */ |
25 | /* position is integer from 0 to SINE_STEPS */ |
| 22 | void displayDial_t::draw_needle(int16_t position) |
26 | void displayDial_t::draw_needle(int16_t position) |
| 23 | { |
27 | { |
| 24 | int ang = math.SINE_SCALING * ((position - (math.SINE_STEPS / 2)) * m_a1) / (math.SINE_STEPS / 2); |
28 | // int ang = math.SINE_SCALING * ((position - (math.SINE_STEPS / 2)) * m_a1) / (math.SINE_STEPS / 2); |
| 25 | - | ||
| - | 29 | int ang = (math.SINE_SCALING * position * m_angleRange) / math.SINE_STEPS + m_angleLow * math.SINE_SCALING; |
|
| 26 | int si = math.ap_sin(ang); |
30 | int si = math.ap_sin(ang); |
| 27 | int co = math.ap_cos(ang); |
31 | int co = math.ap_cos(ang); |
| 28 | 32 | ||
| 29 | /* calculate a shift for a second side of the needle */ |
33 | /* calculate a shift for a second side of the needle */ |
| 30 | int xl = math.ap_sin(ang - math.SINE_STEPS); |
34 | int xl = math.ap_sin(ang - math.SINE_STEPS); |
| Line 54... | Line 58... | ||
| 54 | int ang; |
58 | int ang; |
| 55 | m_low = low; |
59 | m_low = low; |
| 56 | m_high = high; |
60 | m_high = high; |
| 57 | int sc_low = low / scale; |
61 | int sc_low = low / scale; |
| 58 | int sc_high = high / scale; |
62 | int sc_high = high / scale; |
| 59 | int step = 256 * m_a1 * 2 / (4 * (sc_high - sc_low)); |
63 | int step = 256 * m_angleRange / (4 * (sc_high - sc_low)); |
| 60 | int t; |
64 | int t; |
| 61 | ang = -m_a1 * 256; |
65 | ang = m_angleLow * 256; |
| 62 | for (t = sc_low * 4; t <= sc_high * 4; t++) |
66 | int d = sc_low < sc_high ? 1 : -1; |
| - | 67 | t = sc_low * 4; |
|
| - | 68 | while(1) |
|
| 63 | { |
69 | { |
| 64 | int si = math.ap_sin((ang * math.SINE_SCALING) / 256); |
70 | int si = math.ap_sin((ang * math.SINE_SCALING) / 256); |
| 65 | int co = math.ap_cos((ang * math.SINE_SCALING) / 256); |
71 | int co = math.ap_cos((ang * math.SINE_SCALING) / 256); |
| 66 | 72 | ||
| 67 | int len; |
73 | int len; |
| Line 83... | Line 89... | ||
| 83 | } |
89 | } |
| 84 | 90 | ||
| 85 | m_display.drawLine(math.AP_SCALE((m_siz)*si) + m_xo, m_yo - math.AP_SCALE((m_siz)*co), |
91 | m_display.drawLine(math.AP_SCALE((m_siz)*si) + m_xo, m_yo - math.AP_SCALE((m_siz)*co), |
| 86 | math.AP_SCALE((m_siz - len) * si) + m_xo, |
92 | math.AP_SCALE((m_siz - len) * si) + m_xo, |
| 87 | m_yo - math.AP_SCALE((m_siz - len) * co), WHITE); |
93 | m_yo - math.AP_SCALE((m_siz - len) * co), WHITE); |
| - | 94 | ||
| - | 95 | if (t == sc_high * 4) |
|
| - | 96 | break; |
|
| - | 97 | ||
| 88 | ang += step; |
98 | ang += step; |
| - | 99 | t += d; |
|
| 89 | } |
100 | } |
| 90 | } |
101 | } |
| 91 | 102 | ||
| 92 | void displayDial_t::draw_limits() |
103 | void displayDial_t::draw_limits() |
| 93 | { |
104 | { |
| 94 | m_display.fontSigDigits(small_font, 0, 56, 0, 10, m_low, WHITE); |
105 | m_display.fontSigDigits(small_font, 0, 56, 0, 10, m_low, WHITE); |
| 95 | m_display.fontSigDigits(small_font, 120, 56, 1, 10, m_high, WHITE); |
106 | m_display.fontSigDigits(small_font, 120, 56, 1, 10, m_high, WHITE); |
| 96 | } |
107 | } |
| 97 | - | ||
| 98 | - | ||
| 99 | - | ||