Rev 15 | Rev 17 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 15 | Rev 16 | ||
---|---|---|---|
Line 7... | Line 7... | ||
7 | 7 | ||
8 | #include "libOLED/ap_math.H" |
8 | #include "libOLED/ap_math.H" |
9 | #include "libOLED/displayclass.H" |
9 | #include "libOLED/displayclass.H" |
10 | #include "libOLED/fontclass.H" |
10 | #include "libOLED/fontclass.H" |
11 | #include "libOLED/displayDial.H" |
11 | #include "libOLED/displayDial.H" |
- | 12 | #include <string.h> |
|
12 | 13 | ||
13 | static ap_math math; |
14 | static ap_math math; |
14 | 15 | ||
15 | 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) |
16 | 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), |
- | 17 | m_xo(x), m_yo(y), m_siz(siz), m_angleLow(angle_low), m_angleRange(angle_high - angle_low), m_unitStr(nullptr) |
|
16 | { |
18 | { |
17 | } |
19 | } |
18 | 20 | ||
19 | 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_) |
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_angleLow(-angle_), m_angleRange(2 * angle_), m_unitStr(nullptr) |
20 | { |
22 | { |
- | 23 | } |
|
21 | 24 | ||
22 | /* position is integer from 0 to SINE_STEPS */ |
25 | /* position is integer from 0 to SINE_STEPS */ |
23 | void displayDial_t::draw_needle(int16_t position) |
26 | void displayDial_t::draw_needle(int16_t position) |
24 | { |
27 | { |
25 | // 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); |
Line 40... | Line 43... | ||
40 | ys = -yl; |
43 | ys = -yl; |
41 | int step; |
44 | int step; |
42 | for (step = 0; step < 3; step++) |
45 | for (step = 0; step < 3; step++) |
43 | { |
46 | { |
44 | m_display.drawLine(math.AP_SCALE(si * si2 - xs) + m_xo, m_yo - math.AP_SCALE(co * si2 - ys), |
47 | m_display.drawLine(math.AP_SCALE(si * si2 - xs) + m_xo, m_yo - math.AP_SCALE(co * si2 - ys), |
45 | - | ||
46 | math.AP_SCALE(si * si3 - xs) + m_xo, m_yo - math.AP_SCALE(co * si3 - ys), INVERT); |
48 | math.AP_SCALE(si * si3 - xs) + m_xo, m_yo - math.AP_SCALE(co * si3 - ys), INVERT); |
47 | xs += xl; |
49 | xs += xl; |
48 | ys += yl; |
50 | ys += yl; |
49 | } |
51 | } |
50 | } |
52 | } |
Line 58... | Line 60... | ||
58 | int sc_low = low / scale; |
60 | int sc_low = low / scale; |
59 | int sc_high = high / scale; |
61 | int sc_high = high / scale; |
60 | int step = 256 * m_angleRange / (4 * (sc_high - sc_low)); |
62 | int step = 256 * m_angleRange / (4 * (sc_high - sc_low)); |
61 | int t; |
63 | int t; |
62 | ang = m_angleLow * 256; |
64 | ang = m_angleLow * 256; |
63 | int d = sc_low < sc_high ? 1 : -1; |
65 | int d = sc_low < sc_high ? 1 : -1; |
64 | t = sc_low * 4; |
66 | t = sc_low * 4; |
65 | while(1) |
67 | while (1) |
66 | { |
68 | { |
67 | int si = math.ap_sin((ang * math.SINE_SCALING) / 256); |
69 | int si = math.ap_sin((ang * math.SINE_SCALING) / 256); |
68 | int co = math.ap_cos((ang * math.SINE_SCALING) / 256); |
70 | int co = math.ap_cos((ang * math.SINE_SCALING) / 256); |
69 | 71 | ||
70 | int len; |
72 | int len; |
Line 86... | Line 88... | ||
86 | } |
88 | } |
87 | 89 | ||
88 | m_display.drawLine(math.AP_SCALE((m_siz)*si) + m_xo, m_yo - math.AP_SCALE((m_siz)*co), |
90 | m_display.drawLine(math.AP_SCALE((m_siz)*si) + m_xo, m_yo - math.AP_SCALE((m_siz)*co), |
89 | math.AP_SCALE((m_siz - len) * si) + m_xo, |
91 | math.AP_SCALE((m_siz - len) * si) + m_xo, |
90 | m_yo - math.AP_SCALE((m_siz - len) * co), WHITE); |
92 | m_yo - math.AP_SCALE((m_siz - len) * co), WHITE); |
91 | 93 | ||
92 | if (t == sc_high * 4) |
94 | if (t == sc_high * 4) |
93 | break; |
95 | break; |
94 | 96 | ||
95 | ang += step; |
97 | ang += step; |
96 | t += d; |
98 | t += d; |
97 | } |
99 | } |
98 | } |
100 | } |
99 | 101 | ||
- | 102 | void displayDial_t::draw_value_items(int val, int dpCode, int width, int x, int y) |
|
- | 103 | { |
|
- | 104 | ||
- | 105 | m_display.gotoxy(x, y); |
|
- | 106 | m_display.fontDigits(large_font, width, dpCode, val, WHITE); |
|
- | 107 | m_display.gotoxy(x, y+16); |
|
- | 108 | if (m_unitStr) |
|
- | 109 | { |
|
- | 110 | int l = strlen(m_unitStr); |
|
- | 111 | if (l > 4) |
|
- | 112 | l = 4; |
|
- | 113 | m_display.printString(small_font, m_unitStr, l); |
|
- | 114 | m_display.printString(small_font, " ", 4 - l); |
|
- | 115 | } |
|
- | 116 | else |
|
- | 117 | { |
|
100 | // this only works for a fullsize display. |
118 | m_display.printString(small_font, " ", 4); |
- | 119 | } |
|
- | 120 | } |
|
- | 121 | ||
- | 122 | //////////////////////////////////////////////////////////////////////////////// |
|
- | 123 | displayFullDial_t::displayFullDial_t(display_t &display) : displayDial_t(display, 64, 60, 60, 90) |
|
- | 124 | { |
|
- | 125 | } |
|
- | 126 | ||
101 | void displayDial_t::draw_limits() |
127 | void displayFullDial_t::draw_limits() |
102 | { |
128 | { |
103 | m_display.fontSigDigits(small_font, 0, 56, 0, 10, m_low, WHITE); |
129 | m_display.fontSigDigits(small_font, 0, 56, 0, 10, m_low, WHITE); |
104 | m_display.fontSigDigits(small_font, 120, 56, 1, 10, m_high, WHITE); |
130 | m_display.fontSigDigits(small_font, 120, 56, 1, 10, m_high, WHITE); |
105 | } |
131 | } |
- | 132 | ||
- | 133 | void displayFullDial_t ::draw_value(int val, int dp) |
|
- | 134 | { |
|
- | 135 | draw_value_items(val, dp, 4, 30, 32); |
|
- | 136 | } |
|
- | 137 | ||
- | 138 | //////////////////////////////////////////////////////////////////////////////// |
|
- | 139 | displayLeftQuadrantDial_t::displayLeftQuadrantDial_t(display_t &display) : displayDial_t(display, 0, 60, 60, 90, 0){}; |
|
- | 140 | ||
- | 141 | void displayLeftQuadrantDial_t::draw_limits() |
|
- | 142 | { |
|
- | 143 | m_display.fontSigDigits(small_font, 0, 10, false, display_t::NO_DECIMAL, m_high, WHITE); |
|
- | 144 | m_display.fontSigDigits(small_font, 56, 56, true, display_t::NO_DECIMAL, m_low, WHITE); |
|
- | 145 | } |
|
- | 146 | ||
- | 147 | void displayLeftQuadrantDial_t ::draw_value(int val, int dp) |
|
- | 148 | { |
|
- | 149 | draw_value_items(val, dp, 3, 0, 32); |
|
- | 150 | } |
|
- | 151 | ||
- | 152 | //////////////////////////////////////////////////////////////////////////////// |
|
- | 153 | displayRightQuadrantDial_t::displayRightQuadrantDial_t(display_t &display) : displayDial_t(display, 127, 60, 60, -90, 0){}; |
|
- | 154 | ||
- | 155 | void displayRightQuadrantDial_t::draw_limits() |
|
- | 156 | { |
|
- | 157 | m_display.fontSigDigits(small_font, 128, 10, true, display_t::NO_DECIMAL, m_high, WHITE); |
|
- | 158 | m_display.fontSigDigits(small_font, 128 - 56, 56, false, display_t::NO_DECIMAL, m_low, WHITE); |
|
- | 159 | } |
|
- | 160 | ||
- | 161 | void displayRightQuadrantDial_t::draw_value(int val, int dp) |
|
- | 162 | { |
|
- | 163 | draw_value_items(val, dp, 3, 90, 32); |
|
- | 164 | } |