Touch screen drivers control dashboard for miniature locomotive. Features meters for speed, volts, power. Switches for lights, horns. Drives multiple STM3_ESC brushless motor controllers for complete brushless loco system as used in "The Brute" - www.jons-workshop.com
Dependencies: TS_DISCO_F746NG mbed Servo LCD_DISCO_F746NG BSP_DISCO_F746NG QSPI_DISCO_F746NG AsyncSerial FastPWM
graphics.cpp@14:6bcec5ac21ca, 2019-03-04 (annotated)
- Committer:
- JonFreeman
- Date:
- Mon Mar 04 17:47:27 2019 +0000
- Revision:
- 14:6bcec5ac21ca
- Parent:
- 12:a25bdf135348
'Brute' Locomotive Touch Screen Controller - Driver's Controls; Always a 'Work In Progress', snapshot March 2019
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JonFreeman | 4:67478861c670 | 1 | #include "mbed.h" |
JonFreeman | 4:67478861c670 | 2 | #include "TS_DISCO_F746NG.h" |
JonFreeman | 4:67478861c670 | 3 | #include "LCD_DISCO_F746NG.h" |
JonFreeman | 4:67478861c670 | 4 | #include "Electric_Loco.h" |
JonFreeman | 4:67478861c670 | 5 | |
JonFreeman | 4:67478861c670 | 6 | |
JonFreeman | 4:67478861c670 | 7 | extern LCD_DISCO_F746NG lcd; |
JonFreeman | 4:67478861c670 | 8 | extern TS_DISCO_F746NG touch_screen; |
JonFreeman | 4:67478861c670 | 9 | extern Serial pc; |
JonFreeman | 4:67478861c670 | 10 | |
JonFreeman | 12:a25bdf135348 | 11 | /* |
JonFreeman | 12:a25bdf135348 | 12 | moving_coil_meter Voltmeter ( LCD_COLOR_BLACK, // Frame / body colour |
JonFreeman | 12:a25bdf135348 | 13 | LCD_COLOR_WHITE, // Dial face colour |
JonFreeman | 12:a25bdf135348 | 14 | LCD_COLOR_RED, // Moving needle colour |
JonFreeman | 12:a25bdf135348 | 15 | LCD_COLOR_BLUE, // Text colour for Units e.g. 'V' and e.g. '32.7' |
JonFreeman | 12:a25bdf135348 | 16 | LCD_COLOR_MAGENTA, // Scale graduations colour |
JonFreeman | 12:a25bdf135348 | 17 | VOLTMETER_X, // X co-ord, centre of meter |
JonFreeman | 12:a25bdf135348 | 18 | VOLTMETER_Y, // Y co-ord, centre of meter |
JonFreeman | 12:a25bdf135348 | 19 | V_A_SIZE, // Meter is square with rounded corners. This is meter dial face radius |
JonFreeman | 12:a25bdf135348 | 20 | 22.0, // Scale not limited to e.g. 0 to 10. This is reading at anti-clock limit |
JonFreeman | 12:a25bdf135348 | 21 | 59.0, // This is reading at full scale deflection |
JonFreeman | 12:a25bdf135348 | 22 | 1.25 * PI, // Angle of needle at anti-clockwise limit |
JonFreeman | 12:a25bdf135348 | 23 | -0.25 * PI , // Angle of needle at full scale deflection (clockwise max) |
JonFreeman | 12:a25bdf135348 | 24 | 30, // Number of scale graduation marks drwan |
JonFreeman | 12:a25bdf135348 | 25 | "V", // Text for Units, e.g. 'V' or 'MPH' |
JonFreeman | 12:a25bdf135348 | 26 | ONE_DP, // NO_DPS or ONE_DP - supports only no decimal places or one |
JonFreeman | 12:a25bdf135348 | 27 | false) ; // true to show '+' or '-', false to supress sign display |
JonFreeman | 12:a25bdf135348 | 28 | */ |
JonFreeman | 12:a25bdf135348 | 29 | /*moving_coil_meter Voltmeter ( LCD_COLOR_BLACK, LCD_COLOR_WHITE, LCD_COLOR_RED, LCD_COLOR_BLUE, LCD_COLOR_MAGENTA, |
JonFreeman | 12:a25bdf135348 | 30 | VOLTMETER_X, VOLTMETER_Y, V_A_SIZE, 22.0, 61.0, 1.25 * PI, -0.25 * PI , 20, "V", ONE_DP, false), |
JonFreeman | 12:a25bdf135348 | 31 | Powermeter ( LCD_COLOR_BLACK, LCD_COLOR_WHITE, LCD_COLOR_RED, LCD_COLOR_BLUE, LCD_COLOR_BLUE, |
JonFreeman | 12:a25bdf135348 | 32 | AMMETER_X, AMMETER_Y, V_A_SIZE, -1400.0, 1400.0, 1.25 * PI, -0.25 * PI , 14, "Watt", NO_DPS, false), |
JonFreeman | 12:a25bdf135348 | 33 | Speedo ( SPEEDO_BODY_COLOUR, SPEEDO_DIAL_COLOUR, LCD_COLOR_RED, SPEEDO_TEXT_COLOUR, LCD_COLOR_BLACK, |
JonFreeman | 12:a25bdf135348 | 34 | SPEEDO_X, SPEEDO_Y, SPEEDO_SIZE, 0.0, 12.0, 1.25 * PI, -0.25 * PI , 12, "MPH", ONE_DP, false); // 3 instances of moving coil meter graphic |
JonFreeman | 12:a25bdf135348 | 35 | |
JonFreeman | 12:a25bdf135348 | 36 | */ |
JonFreeman | 4:67478861c670 | 37 | |
JonFreeman | 4:67478861c670 | 38 | |
JonFreeman | 4:67478861c670 | 39 | |
JonFreeman | 4:67478861c670 | 40 | void displaytext (int x, int y, const int font, char * txt) ; |
JonFreeman | 4:67478861c670 | 41 | |
JonFreeman | 12:a25bdf135348 | 42 | extern uint32_t odometer_out () ; |
JonFreeman | 12:a25bdf135348 | 43 | void rewrite_odometer () { |
JonFreeman | 12:a25bdf135348 | 44 | char dist[20]; |
JonFreeman | 12:a25bdf135348 | 45 | sprintf (dist, "%06dm", odometer_out()); // 12th June 2018 changed 05 to 06 to allow correct display of tot distance > 99999 metres |
JonFreeman | 12:a25bdf135348 | 46 | lcd.SetTextColor (LCD_COLOR_BLACK); |
JonFreeman | 12:a25bdf135348 | 47 | displaytext (241, 224, 2, dist); |
JonFreeman | 4:67478861c670 | 48 | } |
JonFreeman | 4:67478861c670 | 49 | |
JonFreeman | 4:67478861c670 | 50 | struct rect { struct point a, b; } ; |
JonFreeman | 4:67478861c670 | 51 | |
JonFreeman | 12:a25bdf135348 | 52 | struct button_specs { |
JonFreeman | 4:67478861c670 | 53 | struct rect area; |
JonFreeman | 4:67478861c670 | 54 | int border_colour, body_colour; |
JonFreeman | 4:67478861c670 | 55 | bool in_use, pressed;//, released; |
JonFreeman | 4:67478861c670 | 56 | char txt1[12]; |
JonFreeman | 4:67478861c670 | 57 | char txt2[12]; |
JonFreeman | 4:67478861c670 | 58 | } ; |
JonFreeman | 4:67478861c670 | 59 | |
JonFreeman | 12:a25bdf135348 | 60 | struct button_specs button[NUMOF_BUTTONS]; |
JonFreeman | 4:67478861c670 | 61 | |
JonFreeman | 4:67478861c670 | 62 | int get_button_press (struct point & pt) ; |
JonFreeman | 4:67478861c670 | 63 | int get_but_p (int x, int y) |
JonFreeman | 4:67478861c670 | 64 | { |
JonFreeman | 4:67478861c670 | 65 | struct point p; |
JonFreeman | 4:67478861c670 | 66 | p.x = x; |
JonFreeman | 4:67478861c670 | 67 | p.y = y; |
JonFreeman | 4:67478861c670 | 68 | return get_button_press (p); |
JonFreeman | 4:67478861c670 | 69 | } |
JonFreeman | 4:67478861c670 | 70 | |
JonFreeman | 12:a25bdf135348 | 71 | /** |
JonFreeman | 12:a25bdf135348 | 72 | void read_keypresses (struct ky_bd & a) |
JonFreeman | 12:a25bdf135348 | 73 | Sets values in struct ky_bd, containing : |
JonFreeman | 12:a25bdf135348 | 74 | struct ky_bd { int count, slider_y; keystr key[MAX_TOUCHES + 1]; bool sli; } ; |
JonFreeman | 12:a25bdf135348 | 75 | struct keystr { int keynum; int x; int y; } ; |
JonFreeman | 12:a25bdf135348 | 76 | sets a.count to number of fingers found pressing buttons |
JonFreeman | 12:a25bdf135348 | 77 | fills a.key[].keynum with list of 'a.count' button return codes |
JonFreeman | 12:a25bdf135348 | 78 | fills corresponding a.key[].x and a.key[].y with finger coordinates |
JonFreeman | 12:a25bdf135348 | 79 | if button is SLIDER_BUTTON |
JonFreeman | 12:a25bdf135348 | 80 | sets a.sli true else sets false |
JonFreeman | 12:a25bdf135348 | 81 | sets a.slider_y with new slider y coordinate - 0 at top |
JonFreeman | 12:a25bdf135348 | 82 | */ |
JonFreeman | 4:67478861c670 | 83 | void read_keypresses (struct ky_bd & a) |
JonFreeman | 4:67478861c670 | 84 | { |
JonFreeman | 4:67478861c670 | 85 | int x; |
JonFreeman | 4:67478861c670 | 86 | a.count = 0; |
JonFreeman | 4:67478861c670 | 87 | a.sli = false; |
JonFreeman | 4:67478861c670 | 88 | for (x = 0; x < MAX_TOUCHES; x++) |
JonFreeman | 12:a25bdf135348 | 89 | a.key[x].keynum = -1; |
JonFreeman | 4:67478861c670 | 90 | int touches, but; |
JonFreeman | 4:67478861c670 | 91 | TS_StateTypeDef TS_State; |
JonFreeman | 4:67478861c670 | 92 | touch_screen.GetState(&TS_State); |
JonFreeman | 4:67478861c670 | 93 | touches = TS_State.touchDetected; |
JonFreeman | 4:67478861c670 | 94 | for (int h = 0; h < touches; h++) { |
JonFreeman | 4:67478861c670 | 95 | but = get_but_p (TS_State.touchX[h], TS_State.touchY[h]); |
JonFreeman | 4:67478861c670 | 96 | if (but > - 1) { |
JonFreeman | 12:a25bdf135348 | 97 | a.key[a.count].keynum = but; |
JonFreeman | 12:a25bdf135348 | 98 | a.key[a.count].x = TS_State.touchX[h]; |
JonFreeman | 12:a25bdf135348 | 99 | a.key[a.count].y = TS_State.touchY[h]; |
JonFreeman | 12:a25bdf135348 | 100 | if (but == SLIDER_BUTTON) { |
JonFreeman | 4:67478861c670 | 101 | a.sli = true; |
JonFreeman | 12:a25bdf135348 | 102 | a.slider_y = a.key[a.count].y; |
JonFreeman | 4:67478861c670 | 103 | } |
JonFreeman | 4:67478861c670 | 104 | a.count++; |
JonFreeman | 4:67478861c670 | 105 | } |
JonFreeman | 4:67478861c670 | 106 | } |
JonFreeman | 4:67478861c670 | 107 | } |
JonFreeman | 4:67478861c670 | 108 | |
JonFreeman | 4:67478861c670 | 109 | |
JonFreeman | 4:67478861c670 | 110 | void displaytext (int x, int y, char * txt) |
JonFreeman | 4:67478861c670 | 111 | { |
JonFreeman | 4:67478861c670 | 112 | lcd.DisplayStringAt(x, y, (uint8_t *)txt, LEFT_MODE); |
JonFreeman | 4:67478861c670 | 113 | } |
JonFreeman | 4:67478861c670 | 114 | |
JonFreeman | 4:67478861c670 | 115 | void displaytext (int x, int y, const int font, char * txt) |
JonFreeman | 4:67478861c670 | 116 | { |
JonFreeman | 4:67478861c670 | 117 | sFONT * const fp[] = {&Font8, &Font12, &Font16, &Font20, &Font24}; |
JonFreeman | 4:67478861c670 | 118 | lcd.SetFont(fp[font]); |
JonFreeman | 4:67478861c670 | 119 | displaytext (x, y, txt); |
JonFreeman | 4:67478861c670 | 120 | } |
JonFreeman | 4:67478861c670 | 121 | |
JonFreeman | 4:67478861c670 | 122 | void displaytext (int x, int y, const int font, uint32_t BCol, uint32_t TCol, char * txt) |
JonFreeman | 4:67478861c670 | 123 | { |
JonFreeman | 4:67478861c670 | 124 | uint32_t otc, obc; |
JonFreeman | 4:67478861c670 | 125 | otc = lcd.GetTextColor(); |
JonFreeman | 4:67478861c670 | 126 | obc = lcd.GetBackColor(); |
JonFreeman | 4:67478861c670 | 127 | lcd.SetTextColor(TCol); |
JonFreeman | 4:67478861c670 | 128 | lcd.SetBackColor(BCol); |
JonFreeman | 4:67478861c670 | 129 | displaytext (x, y, font, txt); |
JonFreeman | 4:67478861c670 | 130 | lcd.SetTextColor(otc); |
JonFreeman | 4:67478861c670 | 131 | lcd.SetBackColor(obc); |
JonFreeman | 4:67478861c670 | 132 | } |
JonFreeman | 4:67478861c670 | 133 | |
JonFreeman | 12:a25bdf135348 | 134 | void draw_button (struct button_specs & bu) |
JonFreeman | 4:67478861c670 | 135 | { |
JonFreeman | 4:67478861c670 | 136 | int oldbgcolour; |
JonFreeman | 4:67478861c670 | 137 | lcd.SetTextColor (bu.body_colour); |
JonFreeman | 4:67478861c670 | 138 | lcd.FillRect(bu.area.a.x + 2, bu.area.a.y + 2, bu.area.b.x - bu.area.a.x - 2, bu.area.b.y - bu.area.a.y - 2); //, bu.body_colour); |
JonFreeman | 4:67478861c670 | 139 | oldbgcolour = lcd.GetBackColor(); |
JonFreeman | 4:67478861c670 | 140 | lcd.SetBackColor(bu.body_colour); |
JonFreeman | 4:67478861c670 | 141 | lcd.SetTextColor(LCD_COLOR_BLACK); |
JonFreeman | 4:67478861c670 | 142 | if (strlen(bu.txt2) == 0) { |
JonFreeman | 4:67478861c670 | 143 | displaytext (bu.area.a.x + 4, bu.area.a.y + 14, 4, bu.txt1); // largest font 4 |
JonFreeman | 4:67478861c670 | 144 | } else { |
JonFreeman | 4:67478861c670 | 145 | displaytext (bu.area.a.x + 4, bu.area.a.y + 4, 3, bu.txt1); // not so large font 3 |
JonFreeman | 4:67478861c670 | 146 | displaytext (bu.area.a.x + 4, bu.area.a.y + 26, bu.txt2); |
JonFreeman | 4:67478861c670 | 147 | } |
JonFreeman | 4:67478861c670 | 148 | lcd.SetBackColor(LCD_COLOR_BLACK); |
JonFreeman | 4:67478861c670 | 149 | lcd.SetTextColor(bu.border_colour); |
JonFreeman | 4:67478861c670 | 150 | lcd.DrawRect(bu.area.a.x, bu.area.a.y, bu.area.b.x - bu.area.a.x, bu.area.b.y - bu.area.a.y); //, bu.border_colour); |
JonFreeman | 4:67478861c670 | 151 | lcd.DrawRect(bu.area.a.x + 1, bu.area.a.y + 1, bu.area.b.x - bu.area.a.x - 1, bu.area.b.y - bu.area.a.y - 1); //, bu.border_colour); |
JonFreeman | 4:67478861c670 | 152 | lcd.SetBackColor(oldbgcolour); |
JonFreeman | 4:67478861c670 | 153 | } |
JonFreeman | 4:67478861c670 | 154 | |
JonFreeman | 4:67478861c670 | 155 | void draw_button_hilight (int but, int colour) |
JonFreeman | 4:67478861c670 | 156 | { |
JonFreeman | 4:67478861c670 | 157 | if (but < 0 || but > NUMOF_BUTTONS) { |
JonFreeman | 4:67478861c670 | 158 | pc.printf ("Button out of range in draw_button_hilight %d\r\n", but) ; |
JonFreeman | 4:67478861c670 | 159 | } else { |
JonFreeman | 12:a25bdf135348 | 160 | struct button_specs * bu = &button[but]; |
JonFreeman | 4:67478861c670 | 161 | int oldbgcolour = lcd.GetBackColor();//, minx, miny, maxx, maxy; |
JonFreeman | 4:67478861c670 | 162 | lcd.SetTextColor(colour); |
JonFreeman | 4:67478861c670 | 163 | lcd.DrawRect(bu->area.a.x - 1, bu->area.a.y - 1, bu->area.b.x - bu->area.a.x + 2, bu->area.b.y - bu->area.a.y + 2); |
JonFreeman | 4:67478861c670 | 164 | lcd.DrawRect(bu->area.a.x - 2, bu->area.a.y - 2, bu->area.b.x - bu->area.a.x + 4, bu->area.b.y - bu->area.a.y + 4); |
JonFreeman | 4:67478861c670 | 165 | lcd.DrawRect(bu->area.a.x - 2, bu->area.a.y - 3, bu->area.b.x - bu->area.a.x + 5, bu->area.b.y - bu->area.a.y + 6); |
JonFreeman | 4:67478861c670 | 166 | lcd.SetBackColor(oldbgcolour); |
JonFreeman | 4:67478861c670 | 167 | } |
JonFreeman | 4:67478861c670 | 168 | } |
JonFreeman | 4:67478861c670 | 169 | |
JonFreeman | 12:a25bdf135348 | 170 | void draw_button (struct button_specs & bu, int body_colour) |
JonFreeman | 4:67478861c670 | 171 | { |
JonFreeman | 4:67478861c670 | 172 | bu.body_colour = body_colour; |
JonFreeman | 4:67478861c670 | 173 | draw_button (bu); |
JonFreeman | 4:67478861c670 | 174 | } |
JonFreeman | 4:67478861c670 | 175 | |
JonFreeman | 12:a25bdf135348 | 176 | void setup_button (struct button_specs & bu, int x1, int y1, int dx, int dy, int bord, int body, char * txt1, char * txt2) |
JonFreeman | 4:67478861c670 | 177 | { |
JonFreeman | 4:67478861c670 | 178 | static const int margin = 3; |
JonFreeman | 4:67478861c670 | 179 | int xsize = lcd.GetXSize(); |
JonFreeman | 4:67478861c670 | 180 | int ysize = lcd.GetXSize(); |
JonFreeman | 4:67478861c670 | 181 | int x2 = x1 + dx, y2 = y1 + dy; |
JonFreeman | 4:67478861c670 | 182 | if (x1 < margin) x1 = margin; |
JonFreeman | 4:67478861c670 | 183 | if (y1 < margin) y1 = margin; |
JonFreeman | 4:67478861c670 | 184 | if (x2 > xsize - margin) x2 = xsize - margin; |
JonFreeman | 4:67478861c670 | 185 | if (y2 > ysize - margin) y2 = ysize - margin; |
JonFreeman | 4:67478861c670 | 186 | bu.area.a.x = x1; |
JonFreeman | 4:67478861c670 | 187 | bu.area.a.y = y1; |
JonFreeman | 4:67478861c670 | 188 | bu.area.b.x = x2; |
JonFreeman | 4:67478861c670 | 189 | bu.area.b.y = y2; |
JonFreeman | 4:67478861c670 | 190 | bu.border_colour = bord; |
JonFreeman | 4:67478861c670 | 191 | bu.body_colour = body; |
JonFreeman | 4:67478861c670 | 192 | strcpy (bu.txt1, txt1); |
JonFreeman | 4:67478861c670 | 193 | strcpy (bu.txt2, txt2); |
JonFreeman | 4:67478861c670 | 194 | bu.in_use = true; |
JonFreeman | 4:67478861c670 | 195 | bu.pressed = false; |
JonFreeman | 4:67478861c670 | 196 | draw_button(bu); |
JonFreeman | 4:67478861c670 | 197 | } |
JonFreeman | 4:67478861c670 | 198 | |
JonFreeman | 12:a25bdf135348 | 199 | /*bool ifpressed (int key) |
JonFreeman | 4:67478861c670 | 200 | { |
JonFreeman | 4:67478861c670 | 201 | return button[key].pressed; |
JonFreeman | 4:67478861c670 | 202 | } |
JonFreeman | 12:a25bdf135348 | 203 | */ |
JonFreeman | 12:a25bdf135348 | 204 | bool is_button_pressed (struct point & pt, struct button_specs & bu) |
JonFreeman | 4:67478861c670 | 205 | { |
JonFreeman | 4:67478861c670 | 206 | if (bu.in_use) { |
JonFreeman | 12:a25bdf135348 | 207 | if ( bu.area.a.x < pt.x |
JonFreeman | 12:a25bdf135348 | 208 | && bu.area.b.x > pt.x |
JonFreeman | 12:a25bdf135348 | 209 | && bu.area.a.y < pt.y |
JonFreeman | 12:a25bdf135348 | 210 | && bu.area.b.y > pt.y) |
JonFreeman | 4:67478861c670 | 211 | return true; |
JonFreeman | 4:67478861c670 | 212 | } |
JonFreeman | 4:67478861c670 | 213 | return false; |
JonFreeman | 4:67478861c670 | 214 | } |
JonFreeman | 4:67478861c670 | 215 | |
JonFreeman | 4:67478861c670 | 216 | int get_button_press (struct point & pt) |
JonFreeman | 4:67478861c670 | 217 | { |
JonFreeman | 4:67478861c670 | 218 | for (int j = 0; j < NUMOF_BUTTONS; j++) |
JonFreeman | 4:67478861c670 | 219 | if (button[j].in_use && is_button_pressed (pt, button[j])) |
JonFreeman | 4:67478861c670 | 220 | return j; |
JonFreeman | 4:67478861c670 | 221 | return -1; |
JonFreeman | 4:67478861c670 | 222 | } |
JonFreeman | 4:67478861c670 | 223 | |
JonFreeman | 4:67478861c670 | 224 | void setup_buttons () |
JonFreeman | 4:67478861c670 | 225 | { |
JonFreeman | 12:a25bdf135348 | 226 | setup_button (button[SPEEDO_BUTTON], |
JonFreeman | 4:67478861c670 | 227 | SPEEDO_X - SPEEDO_SIZE, SPEEDO_Y - SPEEDO_SIZE, |
JonFreeman | 4:67478861c670 | 228 | SPEEDO_SIZE * 2, SPEEDO_SIZE * 2, SPEEDO_BODY_COLOUR, LCD_COLOR_RED, " X", "") ; |
JonFreeman | 12:a25bdf135348 | 229 | setup_button (button[VMETER_BUTTON], |
JonFreeman | 4:67478861c670 | 230 | VOLTMETER_X - V_A_SIZE, VOLTMETER_Y - V_A_SIZE, V_A_SIZE * 2, V_A_SIZE * 2, VMETER_BODY_COLOUR, LCD_COLOR_RED, " Y", "") ; |
JonFreeman | 12:a25bdf135348 | 231 | setup_button (button[AMETER_BUTTON], |
JonFreeman | 4:67478861c670 | 232 | AMMETER_X - V_A_SIZE, AMMETER_Y - V_A_SIZE, V_A_SIZE * 2, V_A_SIZE * 2, AMETER_BODY_COLOUR, LCD_COLOR_RED, " Z", "") ; |
JonFreeman | 12:a25bdf135348 | 233 | setup_button (button[SLIDER_BUTTON], SLIDERX, SLIDERY, SLIDERW, SLIDERH, LCD_COLOR_BLUE, LCD_COLOR_MAGENTA, "", "") ; |
JonFreeman | 4:67478861c670 | 234 | } |
JonFreeman | 4:67478861c670 | 235 | |
JonFreeman | 12:a25bdf135348 | 236 | void screen_touch_handler::DrawSlider () { |
JonFreeman | 12:a25bdf135348 | 237 | uint32_t |
JonFreeman | 12:a25bdf135348 | 238 | colr, |
JonFreeman | 12:a25bdf135348 | 239 | oldbgcolr = lcd.GetBackColor (), |
JonFreeman | 12:a25bdf135348 | 240 | oldtxtcolr = lcd.GetTextColor (); |
JonFreeman | 4:67478861c670 | 241 | char txt[4]; |
JonFreeman | 4:67478861c670 | 242 | txt[1] = 0; |
JonFreeman | 12:a25bdf135348 | 243 | if (position > MAX_POS) |
JonFreeman | 12:a25bdf135348 | 244 | position = MAX_POS; |
JonFreeman | 12:a25bdf135348 | 245 | if (position < MIN_POS) |
JonFreeman | 12:a25bdf135348 | 246 | position = MIN_POS; |
JonFreeman | 12:a25bdf135348 | 247 | if (position != oldpos) { |
JonFreeman | 4:67478861c670 | 248 | // Draw slider background colour rectangle overwriting previous circles |
JonFreeman | 4:67478861c670 | 249 | // Redraw black vertical |
JonFreeman | 4:67478861c670 | 250 | // Draw new circles |
JonFreeman | 4:67478861c670 | 251 | // Write text char |
JonFreeman | 4:67478861c670 | 252 | lcd.SetTextColor(LCD_COLOR_MAGENTA); |
JonFreeman | 12:a25bdf135348 | 253 | lcd.FillRect (SLIDERX + 1, oldpos - BUTTON_RAD, SLIDERW - 2, SLIDERW); |
JonFreeman | 4:67478861c670 | 254 | lcd.SetTextColor(LCD_COLOR_BLACK); |
JonFreeman | 4:67478861c670 | 255 | lcd.FillRect (SLIDERX + (SLIDERW / 2) - 3, 6, 7, SLIDERH - 8); |
JonFreeman | 12:a25bdf135348 | 256 | oldpos = position; |
JonFreeman | 4:67478861c670 | 257 | lcd.SetTextColor(LCD_COLOR_WHITE); |
JonFreeman | 12:a25bdf135348 | 258 | lcd.DrawCircle (CIRC_CTR, position, BUTTON_RAD); // seel also FillCircle |
JonFreeman | 12:a25bdf135348 | 259 | lcd.DrawCircle (CIRC_CTR, position, BUTTON_RAD - 1); |
JonFreeman | 12:a25bdf135348 | 260 | switch (next_state) { |
JonFreeman | 12:a25bdf135348 | 261 | case RUN_DOWN: |
JonFreeman | 4:67478861c670 | 262 | case RUN: |
JonFreeman | 4:67478861c670 | 263 | txt[0] = 'R'; |
JonFreeman | 4:67478861c670 | 264 | colr = LCD_COLOR_GREEN; |
JonFreeman | 4:67478861c670 | 265 | break; |
JonFreeman | 12:a25bdf135348 | 266 | case INTO_NEUTRAL_DRIFT: |
JonFreeman | 4:67478861c670 | 267 | case NEUTRAL_DRIFT: |
JonFreeman | 12:a25bdf135348 | 268 | case INTO_RUN: |
JonFreeman | 4:67478861c670 | 269 | txt[0] = 'N'; |
JonFreeman | 4:67478861c670 | 270 | colr = LCD_COLOR_BLUE; |
JonFreeman | 4:67478861c670 | 271 | break; |
JonFreeman | 4:67478861c670 | 272 | case REGEN_BRAKE: |
JonFreeman | 12:a25bdf135348 | 273 | case INTO_REGEN_BRAKE: |
JonFreeman | 4:67478861c670 | 274 | txt[0] = 'B'; |
JonFreeman | 4:67478861c670 | 275 | colr = LCD_COLOR_ORANGE; |
JonFreeman | 4:67478861c670 | 276 | break; |
JonFreeman | 4:67478861c670 | 277 | default: |
JonFreeman | 4:67478861c670 | 278 | txt[0] = 'X'; |
JonFreeman | 4:67478861c670 | 279 | colr = LCD_COLOR_CYAN; |
JonFreeman | 12:a25bdf135348 | 280 | // pc.printf ("State %d\r\n", next_state); |
JonFreeman | 4:67478861c670 | 281 | } // End of switch |
JonFreeman | 4:67478861c670 | 282 | lcd.SetTextColor(colr); |
JonFreeman | 12:a25bdf135348 | 283 | lcd.FillCircle (CIRC_CTR, position, BUTTON_RAD - 2); |
JonFreeman | 4:67478861c670 | 284 | lcd.SetBackColor (colr); |
JonFreeman | 4:67478861c670 | 285 | lcd.SetTextColor(LCD_COLOR_YELLOW); |
JonFreeman | 12:a25bdf135348 | 286 | displaytext(SLIDERX + 17, position - 10, 4, txt); // largest font |
JonFreeman | 4:67478861c670 | 287 | lcd.SetBackColor (LCD_COLOR_BLACK); |
JonFreeman | 4:67478861c670 | 288 | } // End of else |
JonFreeman | 4:67478861c670 | 289 | lcd.SetTextColor (oldtxtcolr); |
JonFreeman | 4:67478861c670 | 290 | lcd.SetBackColor (oldbgcolr); |
JonFreeman | 4:67478861c670 | 291 | } |
JonFreeman | 4:67478861c670 | 292 | |
JonFreeman | 4:67478861c670 | 293 | |
JonFreeman | 4:67478861c670 | 294 | |
JonFreeman | 4:67478861c670 | 295 |