Jon Freeman / Mbed 2 deprecated Brute_TS_Controller_2018_11

Dependencies:   TS_DISCO_F746NG mbed Servo LCD_DISCO_F746NG BSP_DISCO_F746NG QSPI_DISCO_F746NG AsyncSerial FastPWM

Committer:
JonFreeman
Date:
Tue May 01 08:34:36 2018 +0000
Revision:
5:21a8ac83142c
Parent:
4:67478861c670
Child:
8:5945d506a872
Added servo throttle, odometer not complete, ready for trial run

Who changed what in which revision?

UserRevisionLine numberNew 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 #define VOLTMETER_X 68 // Voltmeter screen position
JonFreeman 4:67478861c670 7 #define VOLTMETER_Y 68
JonFreeman 4:67478861c670 8 #define AMMETER_X 68 // Ammeter screen position - Now replaced by Power meter
JonFreeman 4:67478861c670 9 #define AMMETER_Y 202
JonFreeman 4:67478861c670 10 #define SPEEDO_X 274 // Speedometer screen position
JonFreeman 4:67478861c670 11 #define SPEEDO_Y 135
JonFreeman 4:67478861c670 12 #define V_A_SIZE 54 // Size of voltmeter and ammeter
JonFreeman 4:67478861c670 13 #define SPEEDO_SIZE 112
JonFreeman 4:67478861c670 14
JonFreeman 4:67478861c670 15 #define SPEEDO_BODY_COLOUR LCD_COLOR_BLACK
JonFreeman 4:67478861c670 16 #define SPEEDO_DIAL_COLOUR LCD_COLOR_WHITE
JonFreeman 4:67478861c670 17 #define SPEEDO_TEXT_COLOUR LCD_COLOR_BLUE
JonFreeman 4:67478861c670 18
JonFreeman 4:67478861c670 19 #define VMETER_BODY_COLOUR LCD_COLOR_BLACK
JonFreeman 4:67478861c670 20 #define VMETER_DIAL_COLOUR LCD_COLOR_WHITE
JonFreeman 4:67478861c670 21 #define VMETER_TEXT_COLOUR LCD_COLOR_BLUE
JonFreeman 4:67478861c670 22
JonFreeman 4:67478861c670 23 #define AMETER_BODY_COLOUR LCD_COLOR_BLACK
JonFreeman 4:67478861c670 24 #define AMETER_DIAL_COLOUR LCD_COLOR_WHITE
JonFreeman 4:67478861c670 25 #define AMETER_TEXT_COLOUR LCD_COLOR_BLUE
JonFreeman 4:67478861c670 26
JonFreeman 4:67478861c670 27 extern LCD_DISCO_F746NG lcd;
JonFreeman 4:67478861c670 28 extern TS_DISCO_F746NG touch_screen;
JonFreeman 4:67478861c670 29 extern Serial pc;
JonFreeman 4:67478861c670 30
JonFreeman 4:67478861c670 31 static const int char_widths[] = {5, 7, 11, 14, 17, 17} ,
JonFreeman 4:67478861c670 32 meter_radius_min = 30, meter_radius_max = 120;
JonFreeman 4:67478861c670 33
JonFreeman 4:67478861c670 34
JonFreeman 4:67478861c670 35 // Uses our own generated sine and cosines from lookup table. For some unexplained reason, using inbuilt sin and cos fns cause display flicker !
JonFreeman 4:67478861c670 36 extern double jcos (double angle); // Used in DrawNeedle, plain sin and cos functions cause display flicker !!
JonFreeman 4:67478861c670 37 extern double jsin (double angle);
JonFreeman 4:67478861c670 38
JonFreeman 4:67478861c670 39 /*void costabgen (int points) {
JonFreeman 4:67478861c670 40 double angle = 0.0;
JonFreeman 4:67478861c670 41 while (angle < 2.1 * PI) {
JonFreeman 4:67478861c670 42 pc.printf ("Angle %f, my cos %+f, c cos %+f\r\n", angle, jcos(angle), cos(angle));
JonFreeman 4:67478861c670 43 // pc.printf ("Angle %f, my sin %+f, c sin %+f\r\n", angle, jsin(angle), sin(angle));
JonFreeman 4:67478861c670 44 angle += PI / 24;
JonFreeman 4:67478861c670 45 }
JonFreeman 4:67478861c670 46 // double angle;
JonFreeman 4:67478861c670 47 *//* int step, perline = 0;
JonFreeman 4:67478861c670 48 double interval = PI / 2.0 / (double)points;
JonFreeman 4:67478861c670 49 pc.printf ("//At costabgen with %d points\r\n", points);
JonFreeman 4:67478861c670 50 pc.printf ("static const double costab[] = {\r\n");
JonFreeman 4:67478861c670 51 for (step = 0; step <= points; step++) {
JonFreeman 4:67478861c670 52 angle = interval * (double)step;
JonFreeman 4:67478861c670 53 // pc.printf ("cos %+.3f = %+.3f\r\n", angle, cos(angle));
JonFreeman 4:67478861c670 54 if (++perline == 8) {
JonFreeman 4:67478861c670 55 pc.printf ("%+.6f,\r\n", cos(angle));
JonFreeman 4:67478861c670 56 perline = 0;
JonFreeman 4:67478861c670 57 }
JonFreeman 4:67478861c670 58 else
JonFreeman 4:67478861c670 59 pc.printf ("%+.6f, ", cos(angle));
JonFreeman 4:67478861c670 60 wait (0.025);
JonFreeman 4:67478861c670 61 }
JonFreeman 4:67478861c670 62 pc.printf ("0.0\t}\t;\r\n//End of costab\r\n");
JonFreeman 4:67478861c670 63 */
JonFreeman 4:67478861c670 64 //}
JonFreeman 4:67478861c670 65
JonFreeman 4:67478861c670 66 /**
JonFreeman 4:67478861c670 67 * @brief Fills a triangle (between 3 points).
JonFreeman 4:67478861c670 68 * @param x1: Point 1 X position
JonFreeman 4:67478861c670 69 * @param y1: Point 1 Y position
JonFreeman 4:67478861c670 70 * @param x2: Point 2 X position
JonFreeman 4:67478861c670 71 * @param y2: Point 2 Y position
JonFreeman 4:67478861c670 72 * @param x3: Point 3 X position
JonFreeman 4:67478861c670 73 * @param y3: Point 3 Y position
JonFreeman 4:67478861c670 74 * @retval None
JonFreeman 4:67478861c670 75 */
JonFreeman 4:67478861c670 76 static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3)
JonFreeman 4:67478861c670 77 {
JonFreeman 4:67478861c670 78 int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
JonFreeman 4:67478861c670 79 yinc1 = 0, yinc2 = 0, den = 0, num = 0, num_add = 0, num_pixels = 0,
JonFreeman 4:67478861c670 80 curpixel = 0;
JonFreeman 4:67478861c670 81
JonFreeman 4:67478861c670 82 deltax = abs(x2 - x1); /* The difference between the x's */
JonFreeman 4:67478861c670 83 deltay = abs(y2 - y1); /* The difference between the y's */
JonFreeman 4:67478861c670 84 x = x1; /* Start x off at the first pixel */
JonFreeman 4:67478861c670 85 y = y1; /* Start y off at the first pixel */
JonFreeman 4:67478861c670 86
JonFreeman 4:67478861c670 87 if (x2 >= x1) { /* The x-values are increasing */
JonFreeman 4:67478861c670 88 xinc1 = 1;
JonFreeman 4:67478861c670 89 xinc2 = 1;
JonFreeman 4:67478861c670 90 } else { /* The x-values are decreasing */
JonFreeman 4:67478861c670 91 xinc1 = -1;
JonFreeman 4:67478861c670 92 xinc2 = -1;
JonFreeman 4:67478861c670 93 }
JonFreeman 4:67478861c670 94
JonFreeman 4:67478861c670 95 if (y2 >= y1) { /* The y-values are increasing */
JonFreeman 4:67478861c670 96 yinc1 = 1;
JonFreeman 4:67478861c670 97 yinc2 = 1;
JonFreeman 4:67478861c670 98 } else { /* The y-values are decreasing */
JonFreeman 4:67478861c670 99 yinc1 = -1;
JonFreeman 4:67478861c670 100 yinc2 = -1;
JonFreeman 4:67478861c670 101 }
JonFreeman 4:67478861c670 102
JonFreeman 4:67478861c670 103 if (deltax >= deltay) { /* There is at least one x-value for every y-value */
JonFreeman 4:67478861c670 104 xinc1 = 0; /* Don't change the x when numerator >= denominator */
JonFreeman 4:67478861c670 105 yinc2 = 0; /* Don't change the y for every iteration */
JonFreeman 4:67478861c670 106 den = deltax;
JonFreeman 4:67478861c670 107 num = deltax / 2;
JonFreeman 4:67478861c670 108 num_add = deltay;
JonFreeman 4:67478861c670 109 num_pixels = deltax; /* There are more x-values than y-values */
JonFreeman 4:67478861c670 110 } else { /* There is at least one y-value for every x-value */
JonFreeman 4:67478861c670 111 xinc2 = 0; /* Don't change the x for every iteration */
JonFreeman 4:67478861c670 112 yinc1 = 0; /* Don't change the y when numerator >= denominator */
JonFreeman 4:67478861c670 113 den = deltay;
JonFreeman 4:67478861c670 114 num = deltay / 2;
JonFreeman 4:67478861c670 115 num_add = deltax;
JonFreeman 4:67478861c670 116 num_pixels = deltay; /* There are more y-values than x-values */
JonFreeman 4:67478861c670 117 }
JonFreeman 4:67478861c670 118
JonFreeman 4:67478861c670 119 for (curpixel = 0; curpixel <= num_pixels; curpixel++) {
JonFreeman 4:67478861c670 120 lcd.DrawLine(x, y, x3, y3);
JonFreeman 4:67478861c670 121
JonFreeman 4:67478861c670 122 num += num_add; /* Increase the numerator by the top of the fraction */
JonFreeman 4:67478861c670 123 if (num >= den) { /* Check if numerator >= denominator */
JonFreeman 4:67478861c670 124 num -= den; /* Calculate the new numerator value */
JonFreeman 4:67478861c670 125 x += xinc1; /* Change the x as appropriate */
JonFreeman 4:67478861c670 126 y += yinc1; /* Change the y as appropriate */
JonFreeman 4:67478861c670 127 }
JonFreeman 4:67478861c670 128 x += xinc2; /* Change the x as appropriate */
JonFreeman 4:67478861c670 129 y += yinc2; /* Change the y as appropriate */
JonFreeman 4:67478861c670 130 }
JonFreeman 4:67478861c670 131 }
JonFreeman 4:67478861c670 132
JonFreeman 4:67478861c670 133 double anglefix (double a) { // Ensures 0.0 <= angle <= + two PI
JonFreeman 4:67478861c670 134 while (a > PI) a -= 2.0 * PI;
JonFreeman 4:67478861c670 135 while (a < 0.0) a += 2.0 * PI;
JonFreeman 4:67478861c670 136 return a;
JonFreeman 4:67478861c670 137 }
JonFreeman 4:67478861c670 138
JonFreeman 4:67478861c670 139 class moving_coil_meter
JonFreeman 4:67478861c670 140 {
JonFreeman 4:67478861c670 141 int meter_radius, cent_x, cent_y, needle_len, scale_ticks,
JonFreeman 4:67478861c670 142 disc_colour, needle_colour, scale_colour, text_colour, body_colour, dec_places;
JonFreeman 4:67478861c670 143 double start_angle, end_angle, old_angle, value_min, value_max, rad_per_value, swept_angle, value_range;
JonFreeman 4:67478861c670 144 double Value; // This is the one that determines pointer angle
JonFreeman 5:21a8ac83142c 145 bool draw_sign;
JonFreeman 4:67478861c670 146
JonFreeman 4:67478861c670 147 void DrawNeedle (double alpha, int colour) ;
JonFreeman 4:67478861c670 148 void DrawScaleGraduations(int colour) ;
JonFreeman 4:67478861c670 149 double get_pointer_angle (double value) ;
JonFreeman 4:67478861c670 150 int get_font () ;
JonFreeman 4:67478861c670 151
JonFreeman 4:67478861c670 152 public:
JonFreeman 4:67478861c670 153
JonFreeman 4:67478861c670 154 moving_coil_meter () { // constructor
JonFreeman 4:67478861c670 155 meter_radius = 100;
JonFreeman 4:67478861c670 156 value_min = -1.0;
JonFreeman 4:67478861c670 157 value_max = 1.0;
JonFreeman 4:67478861c670 158 cent_x = cent_y = 150;
JonFreeman 4:67478861c670 159 disc_colour = LCD_COLOR_BLACK;
JonFreeman 4:67478861c670 160 needle_colour = LCD_COLOR_WHITE;
JonFreeman 4:67478861c670 161 scale_colour = LCD_COLOR_MAGENTA;
JonFreeman 4:67478861c670 162 text_colour = LCD_COLOR_RED;
JonFreeman 4:67478861c670 163 body_colour = LCD_COLOR_CYAN;
JonFreeman 4:67478861c670 164 old_angle = 0.0;
JonFreeman 4:67478861c670 165 }
JonFreeman 4:67478861c670 166
JonFreeman 5:21a8ac83142c 167 bool setup (int cx, int cy, int size, double lo, double hi, double start_ang, double end_ang, int scaleticks, char * units, int decimal_places, bool sign) ;
JonFreeman 4:67478861c670 168 void set_colours (int bod_colour, int bgcol, int needlecol, int textcolour, int scalecol) ;
JonFreeman 4:67478861c670 169 void set_value (double v) ;
JonFreeman 4:67478861c670 170 } Voltmeter, Powermeter, Speedo; // 3 instances of moving coil meter graphic
JonFreeman 4:67478861c670 171
JonFreeman 4:67478861c670 172 void moving_coil_meter::set_colours (int bod_col, int bgcol, int needlecol, int textcol, int scalecol) {
JonFreeman 4:67478861c670 173 body_colour = bod_col;
JonFreeman 4:67478861c670 174 disc_colour = bgcol;
JonFreeman 4:67478861c670 175 needle_colour = needlecol;
JonFreeman 4:67478861c670 176 text_colour = textcol;
JonFreeman 4:67478861c670 177 scale_colour = scalecol;
JonFreeman 4:67478861c670 178 }
JonFreeman 4:67478861c670 179
JonFreeman 4:67478861c670 180 void moving_coil_meter::DrawNeedle (double alpha, int colour)
JonFreeman 4:67478861c670 181 {
JonFreeman 4:67478861c670 182 point pixpts[4];
JonFreeman 4:67478861c670 183 int save_colour, ssa, sca;
JonFreeman 4:67478861c670 184 alpha = anglefix (alpha);
JonFreeman 4:67478861c670 185 double shortln = (needle_len / 18.7),
JonFreeman 4:67478861c670 186 sina = jsin(alpha),
JonFreeman 4:67478861c670 187 cosa = jcos(alpha);
JonFreeman 4:67478861c670 188
JonFreeman 4:67478861c670 189 save_colour = lcd.GetTextColor ();
JonFreeman 4:67478861c670 190 ssa = (int)(shortln * sina);
JonFreeman 4:67478861c670 191 sca = (int)(shortln * cosa);
JonFreeman 4:67478861c670 192 old_angle = alpha;
JonFreeman 4:67478861c670 193 pixpts[0].x = cent_x - ssa;//(int)(shortln * sin(alpha));
JonFreeman 4:67478861c670 194 pixpts[0].y = cent_y - sca;//(int)(shortln * cos(alpha));
JonFreeman 4:67478861c670 195 pixpts[1].x = cent_x + (int)(needle_len * cosa);
JonFreeman 4:67478861c670 196 pixpts[1].y = cent_y - (int)(needle_len * sina); // - as increasing y is downwards
JonFreeman 4:67478861c670 197 pixpts[2].x = cent_x + ssa;//(int)(shortln * sin(alpha));
JonFreeman 4:67478861c670 198 pixpts[2].y = cent_y + sca;//(int)(shortln * cos(alpha));
JonFreeman 4:67478861c670 199 lcd.SetTextColor (colour);
JonFreeman 4:67478861c670 200 lcd.FillCircle (cent_x, cent_y, (int)(needle_len / 15.0));
JonFreeman 4:67478861c670 201 FillTriangle (pixpts[0].x, pixpts[1].x, pixpts[2].x, pixpts[0].y, pixpts[1].y, pixpts[2].y);
JonFreeman 4:67478861c670 202 lcd.SetTextColor (save_colour);
JonFreeman 4:67478861c670 203 }
JonFreeman 4:67478861c670 204
JonFreeman 4:67478861c670 205 void moving_coil_meter::DrawScaleGraduations (int colour)
JonFreeman 4:67478861c670 206 {
JonFreeman 4:67478861c670 207 int save_colour = lcd.GetTextColor ();
JonFreeman 4:67478861c670 208 int i, radius_inner = (int) meter_radius - 2, radius_outer = (int) (meter_radius * 0.9);
JonFreeman 4:67478861c670 209 double ang, cosang, sinang, angle_step;
JonFreeman 4:67478861c670 210 lcd.SetTextColor (colour);
JonFreeman 4:67478861c670 211 ang = start_angle;
JonFreeman 4:67478861c670 212 angle_step = (start_angle - end_angle) / scale_ticks;
JonFreeman 4:67478861c670 213 for (i = 0; i <= scale_ticks; i++) { //
JonFreeman 4:67478861c670 214 cosang = cos(ang);
JonFreeman 4:67478861c670 215 sinang = sin(ang);
JonFreeman 4:67478861c670 216 lcd.DrawLine (cent_x + radius_outer * cosang, cent_y - radius_outer * sinang, cent_x + radius_inner * cosang, cent_y - radius_inner * sinang);
JonFreeman 4:67478861c670 217 ang -= angle_step;
JonFreeman 4:67478861c670 218 }
JonFreeman 4:67478861c670 219 lcd.SetTextColor (save_colour);
JonFreeman 4:67478861c670 220 }
JonFreeman 4:67478861c670 221
JonFreeman 4:67478861c670 222 void displaytext (int x, int y, const int font, char * txt) ;
JonFreeman 4:67478861c670 223
JonFreeman 5:21a8ac83142c 224 bool moving_coil_meter::setup (int cx, int cy, int size, double lo, double hi, double start_ang, double end_ang, int scaleticks, char * units, int decimal_places, bool sign)
JonFreeman 4:67478861c670 225 {
JonFreeman 4:67478861c670 226 bool retval = true;
JonFreeman 4:67478861c670 227 int font, charwid, x_offset;
JonFreeman 4:67478861c670 228 if (size < meter_radius_min || size > meter_radius_max)
JonFreeman 4:67478861c670 229 return false;
JonFreeman 4:67478861c670 230 meter_radius = size;
JonFreeman 4:67478861c670 231 if (meter_radius > cx || meter_radius > cy)
JonFreeman 4:67478861c670 232 return false;
JonFreeman 4:67478861c670 233 int corner_rad = meter_radius / 6,
JonFreeman 4:67478861c670 234 screw_hole_offset = meter_radius * 92 / 100,
JonFreeman 4:67478861c670 235 screw_rad = meter_radius / 13;
JonFreeman 4:67478861c670 236 cent_x = cx;
JonFreeman 4:67478861c670 237 cent_y = cy;
JonFreeman 4:67478861c670 238
JonFreeman 4:67478861c670 239 start_angle = start_ang;
JonFreeman 4:67478861c670 240 end_angle = end_ang;
JonFreeman 4:67478861c670 241 value_min = lo;
JonFreeman 4:67478861c670 242 value_max = hi;
JonFreeman 4:67478861c670 243 scale_ticks = scaleticks;
JonFreeman 4:67478861c670 244 swept_angle = abs(start_angle - end_angle);
JonFreeman 4:67478861c670 245 value_range = (value_max - value_min);
JonFreeman 4:67478861c670 246 rad_per_value = swept_angle / value_range;
JonFreeman 4:67478861c670 247 dec_places = decimal_places;
JonFreeman 5:21a8ac83142c 248 draw_sign = sign;
JonFreeman 4:67478861c670 249
JonFreeman 4:67478861c670 250 needle_len = (int)(0.87 * (double)meter_radius);
JonFreeman 4:67478861c670 251 int oldcolour1 = lcd.GetTextColor ();
JonFreeman 4:67478861c670 252 int oldcolour2 = lcd.GetBackColor ();
JonFreeman 4:67478861c670 253 lcd.SetTextColor (body_colour);
JonFreeman 4:67478861c670 254 // Draw meter body as solid square with rounded corners, complete with mounting screw holes !
JonFreeman 4:67478861c670 255 lcd.FillRect (cent_x - meter_radius, cent_y - meter_radius - corner_rad, meter_radius * 2, corner_rad);
JonFreeman 4:67478861c670 256 lcd.FillRect (cent_x - meter_radius, cent_y + meter_radius, meter_radius * 2, corner_rad + 1);
JonFreeman 4:67478861c670 257 lcd.FillRect (cent_x - meter_radius - corner_rad, cent_y - meter_radius, 1 +(meter_radius + corner_rad) * 2, meter_radius * 2);
JonFreeman 4:67478861c670 258 lcd.FillCircle (cent_x - meter_radius, cent_y - meter_radius, corner_rad); // meter box has rounded corners
JonFreeman 4:67478861c670 259 lcd.FillCircle (cent_x - meter_radius, cent_y + meter_radius, corner_rad);
JonFreeman 4:67478861c670 260 lcd.FillCircle (cent_x + meter_radius, cent_y - meter_radius, corner_rad);
JonFreeman 4:67478861c670 261 lcd.FillCircle (cent_x + meter_radius, cent_y + meter_radius, corner_rad);
JonFreeman 4:67478861c670 262 lcd.SetTextColor (LCD_COLOR_DARKGRAY);
JonFreeman 4:67478861c670 263 lcd.FillCircle (cent_x - screw_hole_offset, cent_y - screw_hole_offset, screw_rad); // panel mounting screw holes near corners
JonFreeman 4:67478861c670 264 lcd.FillCircle (cent_x - screw_hole_offset, cent_y + screw_hole_offset, screw_rad);
JonFreeman 4:67478861c670 265 lcd.FillCircle (cent_x + screw_hole_offset, cent_y - screw_hole_offset, screw_rad);
JonFreeman 4:67478861c670 266 lcd.FillCircle (cent_x + screw_hole_offset, cent_y + screw_hole_offset, screw_rad);
JonFreeman 4:67478861c670 267 lcd.SetTextColor (disc_colour);
JonFreeman 4:67478861c670 268 lcd.FillCircle (cent_x, cent_y, meter_radius);
JonFreeman 4:67478861c670 269 DrawScaleGraduations (scale_colour); //drew the green trace around active needle-sweep angle
JonFreeman 4:67478861c670 270
JonFreeman 4:67478861c670 271 font = get_font ();
JonFreeman 4:67478861c670 272 charwid = char_widths[font];
JonFreeman 4:67478861c670 273 x_offset = charwid * strlen(units) / 2;
JonFreeman 4:67478861c670 274 lcd.SetTextColor (text_colour);
JonFreeman 4:67478861c670 275 lcd.SetBackColor (disc_colour);
JonFreeman 4:67478861c670 276 // displaytext (cent_x - x_offset, cent_y + (meter_radius * 7) / 19, font, units);
JonFreeman 4:67478861c670 277 displaytext (cent_x - x_offset, cent_y + (meter_radius * 6) / 19, font, units);
JonFreeman 4:67478861c670 278 lcd.SetBackColor (oldcolour2);
JonFreeman 4:67478861c670 279 lcd.SetTextColor (oldcolour1);
JonFreeman 4:67478861c670 280 return retval;
JonFreeman 4:67478861c670 281 }
JonFreeman 4:67478861c670 282
JonFreeman 4:67478861c670 283 int moving_coil_meter::get_font ()
JonFreeman 4:67478861c670 284 {
JonFreeman 4:67478861c670 285 int font = meter_radius - meter_radius_min;
JonFreeman 4:67478861c670 286 font /= 17;
JonFreeman 4:67478861c670 287 if (font > 4)
JonFreeman 4:67478861c670 288 font = 4;
JonFreeman 4:67478861c670 289 if (font < 2)
JonFreeman 4:67478861c670 290 font = 2;
JonFreeman 4:67478861c670 291 return font;
JonFreeman 4:67478861c670 292 }
JonFreeman 4:67478861c670 293
JonFreeman 4:67478861c670 294 double moving_coil_meter::get_pointer_angle (double v)
JonFreeman 4:67478861c670 295 {
JonFreeman 4:67478861c670 296 double vabvmin, retval;
JonFreeman 4:67478861c670 297 if (v < value_min) v = value_min;
JonFreeman 4:67478861c670 298 if (v > value_max) v = value_max;
JonFreeman 4:67478861c670 299 Value = v; // clipped copy of supplied value
JonFreeman 4:67478861c670 300 vabvmin = v - value_min;
JonFreeman 4:67478861c670 301 retval = start_angle - (vabvmin * rad_per_value);
JonFreeman 4:67478861c670 302 return anglefix (retval);
JonFreeman 4:67478861c670 303 }
JonFreeman 4:67478861c670 304
JonFreeman 4:67478861c670 305 void moving_coil_meter::set_value (double meter_read_value)
JonFreeman 4:67478861c670 306 {
JonFreeman 4:67478861c670 307 char txt[32];
JonFreeman 4:67478861c670 308 int x_offset, font, charwid, lenchk;//,
JonFreeman 4:67478861c670 309 DrawNeedle (old_angle, disc_colour); // un-draw needle
JonFreeman 4:67478861c670 310 DrawNeedle (get_pointer_angle (meter_read_value), needle_colour) ; // re-draw needle
JonFreeman 5:21a8ac83142c 311 // if (draw_sign) {
JonFreeman 4:67478861c670 312 if (dec_places == ONE_DP)
JonFreeman 4:67478861c670 313 sprintf (txt, " %+.1f \0", meter_read_value);
JonFreeman 4:67478861c670 314 else
JonFreeman 4:67478861c670 315 sprintf (txt, " %+.0f \0", meter_read_value);
JonFreeman 4:67478861c670 316 lenchk = strlen(txt);
JonFreeman 5:21a8ac83142c 317 if (!draw_sign) {
JonFreeman 5:21a8ac83142c 318 for (int i = 1; i < lenchk; i++)
JonFreeman 5:21a8ac83142c 319 txt[i] = txt[i + 1];
JonFreeman 5:21a8ac83142c 320 // lenchk--; // Stupidly, this gives the display flicker blight
JonFreeman 5:21a8ac83142c 321 }
JonFreeman 5:21a8ac83142c 322 lenchk = strlen(txt);// Stupidly, repeating this instead does NOT give the display flicker blight
JonFreeman 4:67478861c670 323 font = get_font();
JonFreeman 4:67478861c670 324 charwid = char_widths[font];
JonFreeman 4:67478861c670 325 x_offset = charwid * lenchk / 2;
JonFreeman 4:67478861c670 326 lcd.SetTextColor (text_colour);
JonFreeman 4:67478861c670 327 lcd.SetBackColor (disc_colour);
JonFreeman 4:67478861c670 328 if (lenchk > 0 && lenchk < 9)
JonFreeman 4:67478861c670 329 displaytext (cent_x - x_offset, cent_y + (meter_radius * 11) / 19, font, txt);
JonFreeman 4:67478861c670 330 }
JonFreeman 4:67478861c670 331 //bool moving_coil_meter::setup (int cx, int cy, int size, double lo, double hi, double start_ang, double end_ang,
JonFreeman 4:67478861c670 332 // int scale_ticks, char * units)
JonFreeman 4:67478861c670 333 void vm_set () //x y size minv maxv min angle max angle,
JonFreeman 4:67478861c670 334 {
JonFreeman 4:67478861c670 335 Speedo.set_colours (SPEEDO_BODY_COLOUR, SPEEDO_DIAL_COLOUR, LCD_COLOR_RED, SPEEDO_TEXT_COLOUR, LCD_COLOR_BLACK);
JonFreeman 5:21a8ac83142c 336 Speedo.setup (SPEEDO_X, SPEEDO_Y, SPEEDO_SIZE, 0.0, 12.0, 1.25 * PI, -0.25 * PI , 12, "MPH", ONE_DP, false);
JonFreeman 4:67478861c670 337 Voltmeter.set_colours (LCD_COLOR_BLACK, LCD_COLOR_WHITE, LCD_COLOR_RED, LCD_COLOR_BLUE, LCD_COLOR_MAGENTA);
JonFreeman 5:21a8ac83142c 338 Voltmeter.setup (VOLTMETER_X, VOLTMETER_Y, V_A_SIZE, 22.0, 59.0, 1.25 * PI, -0.25 * PI , 30, "V", ONE_DP, false);
JonFreeman 4:67478861c670 339 Powermeter.set_colours (LCD_COLOR_BLACK, LCD_COLOR_WHITE, LCD_COLOR_RED, LCD_COLOR_BLUE, LCD_COLOR_BLUE);
JonFreeman 5:21a8ac83142c 340 Powermeter.setup (AMMETER_X, AMMETER_Y, V_A_SIZE, -1400.0, 1400.0, 1.25 * PI, -0.25 * PI , 14, "Watt", NO_DPS, false);
JonFreeman 4:67478861c670 341 }
JonFreeman 4:67478861c670 342
JonFreeman 4:67478861c670 343 //void update_meters (double speed, double current, double voltage)
JonFreeman 4:67478861c670 344 void update_meters (double speed, double power, double voltage)
JonFreeman 4:67478861c670 345 {
JonFreeman 4:67478861c670 346 // Powermeter.set_value(voltage * current);
JonFreeman 4:67478861c670 347 Powermeter.set_value(power);
JonFreeman 4:67478861c670 348 Voltmeter.set_value (voltage);
JonFreeman 4:67478861c670 349 Speedo.set_value (speed);
JonFreeman 4:67478861c670 350 }
JonFreeman 4:67478861c670 351
JonFreeman 4:67478861c670 352
JonFreeman 4:67478861c670 353
JonFreeman 4:67478861c670 354 struct rect { struct point a, b; } ;
JonFreeman 4:67478861c670 355
JonFreeman 4:67478861c670 356 struct butt_on {
JonFreeman 4:67478861c670 357 struct rect area;
JonFreeman 4:67478861c670 358 int border_colour, body_colour;
JonFreeman 4:67478861c670 359 bool in_use, pressed;//, released;
JonFreeman 4:67478861c670 360 char txt1[12];
JonFreeman 4:67478861c670 361 char txt2[12];
JonFreeman 4:67478861c670 362 } ;
JonFreeman 4:67478861c670 363
JonFreeman 4:67478861c670 364 struct butt_on button[NUMOF_BUTTONS];
JonFreeman 4:67478861c670 365
JonFreeman 4:67478861c670 366 int get_button_press (struct point & pt) ;
JonFreeman 4:67478861c670 367 int get_but_p (int x, int y)
JonFreeman 4:67478861c670 368 {
JonFreeman 4:67478861c670 369 struct point p;
JonFreeman 4:67478861c670 370 p.x = x;
JonFreeman 4:67478861c670 371 p.y = y;
JonFreeman 4:67478861c670 372 return get_button_press (p);
JonFreeman 4:67478861c670 373 }
JonFreeman 4:67478861c670 374
JonFreeman 4:67478861c670 375
JonFreeman 4:67478861c670 376 void read_keypresses (struct ky_bd & a)
JonFreeman 4:67478861c670 377 {
JonFreeman 4:67478861c670 378 int x;
JonFreeman 4:67478861c670 379 a.count = 0;
JonFreeman 4:67478861c670 380 a.sli = false;
JonFreeman 4:67478861c670 381 for (x = 0; x < MAX_TOUCHES; x++)
JonFreeman 4:67478861c670 382 a.ky[x].keynum = -1;
JonFreeman 4:67478861c670 383 int touches, but;
JonFreeman 4:67478861c670 384 TS_StateTypeDef TS_State;
JonFreeman 4:67478861c670 385 touch_screen.GetState(&TS_State);
JonFreeman 4:67478861c670 386 touches = TS_State.touchDetected;
JonFreeman 4:67478861c670 387 for (int h = 0; h < touches; h++) {
JonFreeman 4:67478861c670 388 but = get_but_p (TS_State.touchX[h], TS_State.touchY[h]);
JonFreeman 4:67478861c670 389 if (but > - 1) {
JonFreeman 4:67478861c670 390 a.ky[a.count].keynum = but;
JonFreeman 4:67478861c670 391 a.ky[a.count].x = TS_State.touchX[h];
JonFreeman 4:67478861c670 392 a.ky[a.count].y = TS_State.touchY[h];
JonFreeman 4:67478861c670 393 if (but == SLIDER) {
JonFreeman 4:67478861c670 394 a.sli = true;
JonFreeman 4:67478861c670 395 a.slider_y = a.ky[a.count].y;
JonFreeman 4:67478861c670 396 }
JonFreeman 4:67478861c670 397 a.count++;
JonFreeman 4:67478861c670 398 }
JonFreeman 4:67478861c670 399 }
JonFreeman 4:67478861c670 400 }
JonFreeman 4:67478861c670 401
JonFreeman 4:67478861c670 402
JonFreeman 4:67478861c670 403 void displaytext (int x, int y, char * txt)
JonFreeman 4:67478861c670 404 {
JonFreeman 4:67478861c670 405 lcd.DisplayStringAt(x, y, (uint8_t *)txt, LEFT_MODE);
JonFreeman 4:67478861c670 406 }
JonFreeman 4:67478861c670 407
JonFreeman 4:67478861c670 408 void displaytext (int x, int y, const int font, char * txt)
JonFreeman 4:67478861c670 409 {
JonFreeman 4:67478861c670 410 sFONT * const fp[] = {&Font8, &Font12, &Font16, &Font20, &Font24};
JonFreeman 4:67478861c670 411 lcd.SetFont(fp[font]);
JonFreeman 4:67478861c670 412 displaytext (x, y, txt);
JonFreeman 4:67478861c670 413 }
JonFreeman 4:67478861c670 414
JonFreeman 4:67478861c670 415 void displaytext (int x, int y, const int font, uint32_t BCol, uint32_t TCol, char * txt)
JonFreeman 4:67478861c670 416 {
JonFreeman 4:67478861c670 417 uint32_t otc, obc;
JonFreeman 4:67478861c670 418 otc = lcd.GetTextColor();
JonFreeman 4:67478861c670 419 obc = lcd.GetBackColor();
JonFreeman 4:67478861c670 420 lcd.SetTextColor(TCol);
JonFreeman 4:67478861c670 421 lcd.SetBackColor(BCol);
JonFreeman 4:67478861c670 422 displaytext (x, y, font, txt);
JonFreeman 4:67478861c670 423 lcd.SetTextColor(otc);
JonFreeman 4:67478861c670 424 lcd.SetBackColor(obc);
JonFreeman 4:67478861c670 425 }
JonFreeman 4:67478861c670 426
JonFreeman 4:67478861c670 427 void draw_button (struct butt_on & bu)
JonFreeman 4:67478861c670 428 {
JonFreeman 4:67478861c670 429 int oldbgcolour;
JonFreeman 4:67478861c670 430 lcd.SetTextColor (bu.body_colour);
JonFreeman 4:67478861c670 431 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 432 oldbgcolour = lcd.GetBackColor();
JonFreeman 4:67478861c670 433 lcd.SetBackColor(bu.body_colour);
JonFreeman 4:67478861c670 434 lcd.SetTextColor(LCD_COLOR_BLACK);
JonFreeman 4:67478861c670 435 if (strlen(bu.txt2) == 0) {
JonFreeman 4:67478861c670 436 displaytext (bu.area.a.x + 4, bu.area.a.y + 14, 4, bu.txt1); // largest font 4
JonFreeman 4:67478861c670 437 } else {
JonFreeman 4:67478861c670 438 displaytext (bu.area.a.x + 4, bu.area.a.y + 4, 3, bu.txt1); // not so large font 3
JonFreeman 4:67478861c670 439 displaytext (bu.area.a.x + 4, bu.area.a.y + 26, bu.txt2);
JonFreeman 4:67478861c670 440 }
JonFreeman 4:67478861c670 441 lcd.SetBackColor(LCD_COLOR_BLACK);
JonFreeman 4:67478861c670 442 lcd.SetTextColor(bu.border_colour);
JonFreeman 4:67478861c670 443 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 444 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 445 lcd.SetBackColor(oldbgcolour);
JonFreeman 4:67478861c670 446 }
JonFreeman 4:67478861c670 447
JonFreeman 4:67478861c670 448 void draw_button_hilight (int but, int colour)
JonFreeman 4:67478861c670 449 {
JonFreeman 4:67478861c670 450 if (but < 0 || but > NUMOF_BUTTONS) {
JonFreeman 4:67478861c670 451 pc.printf ("Button out of range in draw_button_hilight %d\r\n", but) ;
JonFreeman 4:67478861c670 452 } else {
JonFreeman 4:67478861c670 453 struct butt_on * bu = &button[but];
JonFreeman 4:67478861c670 454 int oldbgcolour = lcd.GetBackColor();//, minx, miny, maxx, maxy;
JonFreeman 4:67478861c670 455 lcd.SetTextColor(colour);
JonFreeman 4:67478861c670 456 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 457 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 458 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 459 lcd.SetBackColor(oldbgcolour);
JonFreeman 4:67478861c670 460 }
JonFreeman 4:67478861c670 461 }
JonFreeman 4:67478861c670 462
JonFreeman 4:67478861c670 463 void draw_button (struct butt_on & bu, int body_colour)
JonFreeman 4:67478861c670 464 {
JonFreeman 4:67478861c670 465 bu.body_colour = body_colour;
JonFreeman 4:67478861c670 466 draw_button (bu);
JonFreeman 4:67478861c670 467 }
JonFreeman 4:67478861c670 468
JonFreeman 4:67478861c670 469 void setup_button (struct butt_on & bu, int x1, int y1, int dx, int dy, int bord, int body, char * txt1, char * txt2)
JonFreeman 4:67478861c670 470 {
JonFreeman 4:67478861c670 471 static const int margin = 3;
JonFreeman 4:67478861c670 472 int xsize = lcd.GetXSize();
JonFreeman 4:67478861c670 473 int ysize = lcd.GetXSize();
JonFreeman 4:67478861c670 474 int x2 = x1 + dx, y2 = y1 + dy;
JonFreeman 4:67478861c670 475 if (x1 < margin) x1 = margin;
JonFreeman 4:67478861c670 476 if (y1 < margin) y1 = margin;
JonFreeman 4:67478861c670 477 if (x2 > xsize - margin) x2 = xsize - margin;
JonFreeman 4:67478861c670 478 if (y2 > ysize - margin) y2 = ysize - margin;
JonFreeman 4:67478861c670 479 bu.area.a.x = x1;
JonFreeman 4:67478861c670 480 bu.area.a.y = y1;
JonFreeman 4:67478861c670 481 bu.area.b.x = x2;
JonFreeman 4:67478861c670 482 bu.area.b.y = y2;
JonFreeman 4:67478861c670 483 bu.border_colour = bord;
JonFreeman 4:67478861c670 484 bu.body_colour = body;
JonFreeman 4:67478861c670 485 strcpy (bu.txt1, txt1);
JonFreeman 4:67478861c670 486 strcpy (bu.txt2, txt2);
JonFreeman 4:67478861c670 487 bu.in_use = true;
JonFreeman 4:67478861c670 488 bu.pressed = false;
JonFreeman 4:67478861c670 489 draw_button(bu);
JonFreeman 4:67478861c670 490 }
JonFreeman 4:67478861c670 491
JonFreeman 4:67478861c670 492 bool ifpressed (int key)
JonFreeman 4:67478861c670 493 {
JonFreeman 4:67478861c670 494 return button[key].pressed;
JonFreeman 4:67478861c670 495 }
JonFreeman 4:67478861c670 496
JonFreeman 4:67478861c670 497 bool is_button_pressed (struct point & pt, struct butt_on & bu)
JonFreeman 4:67478861c670 498 {
JonFreeman 4:67478861c670 499 if (bu.in_use) {
JonFreeman 4:67478861c670 500 if (bu.area.a.x < pt.x && bu.area.b.x > pt.x
JonFreeman 4:67478861c670 501 && bu.area.a.y < pt.y && bu.area.b.y > pt.y)
JonFreeman 4:67478861c670 502 return true;
JonFreeman 4:67478861c670 503 }
JonFreeman 4:67478861c670 504 return false;
JonFreeman 4:67478861c670 505 }
JonFreeman 4:67478861c670 506
JonFreeman 4:67478861c670 507 bool keyrelease (int key)
JonFreeman 4:67478861c670 508 {
JonFreeman 4:67478861c670 509 bool rv = false;
JonFreeman 4:67478861c670 510 if (button[key].pressed) {
JonFreeman 4:67478861c670 511 rv = true;
JonFreeman 4:67478861c670 512 button[key].pressed = false;
JonFreeman 4:67478861c670 513 }
JonFreeman 4:67478861c670 514 return rv;
JonFreeman 4:67478861c670 515 }
JonFreeman 4:67478861c670 516 void setpressed (int key, bool torf)
JonFreeman 4:67478861c670 517 {
JonFreeman 4:67478861c670 518 button[key].pressed = torf;
JonFreeman 4:67478861c670 519 }
JonFreeman 4:67478861c670 520 void setinuse (int key, bool torf)
JonFreeman 4:67478861c670 521 {
JonFreeman 4:67478861c670 522 button[key].in_use = torf;
JonFreeman 4:67478861c670 523 }
JonFreeman 4:67478861c670 524
JonFreeman 4:67478861c670 525
JonFreeman 4:67478861c670 526 int get_button_press (struct point & pt)
JonFreeman 4:67478861c670 527 {
JonFreeman 4:67478861c670 528 for (int j = 0; j < NUMOF_BUTTONS; j++)
JonFreeman 4:67478861c670 529 if (button[j].in_use && is_button_pressed (pt, button[j]))
JonFreeman 4:67478861c670 530 return j;
JonFreeman 4:67478861c670 531 return -1;
JonFreeman 4:67478861c670 532 }
JonFreeman 4:67478861c670 533
JonFreeman 4:67478861c670 534 void setup_buttons ()
JonFreeman 4:67478861c670 535 {
JonFreeman 4:67478861c670 536 setup_button (button[SPEEDO_BUT],
JonFreeman 4:67478861c670 537 SPEEDO_X - SPEEDO_SIZE, SPEEDO_Y - SPEEDO_SIZE,
JonFreeman 4:67478861c670 538 SPEEDO_SIZE * 2, SPEEDO_SIZE * 2, SPEEDO_BODY_COLOUR, LCD_COLOR_RED, " X", "") ;
JonFreeman 4:67478861c670 539 setup_button (button[VMETER_BUT],
JonFreeman 4:67478861c670 540 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 4:67478861c670 541 setup_button (button[AMETER_BUT],
JonFreeman 4:67478861c670 542 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 4:67478861c670 543 setup_button (button[SLIDER], SLIDERX, SLIDERY, SLIDERW, SLIDERH, LCD_COLOR_BLUE, LCD_COLOR_MAGENTA, "", "") ;
JonFreeman 4:67478861c670 544 }
JonFreeman 4:67478861c670 545
JonFreeman 4:67478861c670 546
JonFreeman 4:67478861c670 547 void SliderGraphic (struct slide & q) {
JonFreeman 4:67478861c670 548 int
JonFreeman 4:67478861c670 549 colr,
JonFreeman 4:67478861c670 550 oldbgcolr = lcd.GetBackColor (),
JonFreeman 4:67478861c670 551 oldtxtcolr = lcd.GetTextColor ();
JonFreeman 4:67478861c670 552 char txt[4];
JonFreeman 4:67478861c670 553 txt[1] = 0;
JonFreeman 4:67478861c670 554 if (q.position > MAX_POS)
JonFreeman 4:67478861c670 555 q.position = MAX_POS;
JonFreeman 4:67478861c670 556 if (q.position < MIN_POS)
JonFreeman 4:67478861c670 557 q.position = MIN_POS;
JonFreeman 4:67478861c670 558 if (q.position == NEUTRAL_VAL)
JonFreeman 4:67478861c670 559 q.state = NEUTRAL_DRIFT;
JonFreeman 4:67478861c670 560 if (q.position > NEUTRAL_VAL)
JonFreeman 4:67478861c670 561 q.state = REGEN_BRAKE;
JonFreeman 4:67478861c670 562 if (q.position < NEUTRAL_VAL)
JonFreeman 4:67478861c670 563 if (q.state == REGEN_BRAKE) { // Ensure transition from BRAKE to RUN passes through NEUTRAL
JonFreeman 4:67478861c670 564 q.position = NEUTRAL_VAL;
JonFreeman 4:67478861c670 565 q.state = NEUTRAL_DRIFT;
JonFreeman 4:67478861c670 566 }
JonFreeman 4:67478861c670 567 else
JonFreeman 4:67478861c670 568 q.state = RUN;
JonFreeman 4:67478861c670 569 if (q.position == MAX_POS) {
JonFreeman 4:67478861c670 570 if (q.loco_speed < LOCO_HANDBRAKE_ESCAPE_SPEED)
JonFreeman 4:67478861c670 571 q.state = PARK;
JonFreeman 4:67478861c670 572 else {
JonFreeman 4:67478861c670 573 q.state = REGEN_BRAKE;
JonFreeman 4:67478861c670 574 q.position--;
JonFreeman 4:67478861c670 575 }
JonFreeman 4:67478861c670 576 }
JonFreeman 4:67478861c670 577 if (q.position != q.oldpos) {
JonFreeman 4:67478861c670 578 // Draw slider background colour rectangle overwriting previous circles
JonFreeman 4:67478861c670 579 // Redraw black vertical
JonFreeman 4:67478861c670 580 // Draw new circles
JonFreeman 4:67478861c670 581 // Write text char
JonFreeman 4:67478861c670 582 lcd.SetTextColor(LCD_COLOR_MAGENTA);
JonFreeman 4:67478861c670 583 lcd.FillRect (SLIDERX + 1, q.oldpos - BUTTON_RAD, SLIDERW - 2, SLIDERW);
JonFreeman 4:67478861c670 584 lcd.SetTextColor(LCD_COLOR_BLACK);
JonFreeman 4:67478861c670 585 lcd.FillRect (SLIDERX + (SLIDERW / 2) - 3, 6, 7, SLIDERH - 8);
JonFreeman 4:67478861c670 586 q.oldpos = q.position;
JonFreeman 4:67478861c670 587 lcd.SetTextColor(LCD_COLOR_WHITE);
JonFreeman 4:67478861c670 588 lcd.DrawCircle (CIRC_CTR, q.position, BUTTON_RAD); // seel also FillCircle
JonFreeman 4:67478861c670 589 lcd.DrawCircle (CIRC_CTR, q.position, BUTTON_RAD - 1);
JonFreeman 4:67478861c670 590 switch (q.state) {
JonFreeman 4:67478861c670 591 case RUN:
JonFreeman 4:67478861c670 592 txt[0] = 'R';
JonFreeman 4:67478861c670 593 colr = LCD_COLOR_GREEN;
JonFreeman 4:67478861c670 594 break;
JonFreeman 4:67478861c670 595 case NEUTRAL_DRIFT:
JonFreeman 4:67478861c670 596 txt[0] = 'N';
JonFreeman 4:67478861c670 597 colr = LCD_COLOR_BLUE;
JonFreeman 4:67478861c670 598 break;
JonFreeman 4:67478861c670 599 case REGEN_BRAKE:
JonFreeman 4:67478861c670 600 txt[0] = 'B';
JonFreeman 4:67478861c670 601 colr = LCD_COLOR_ORANGE;
JonFreeman 4:67478861c670 602 break;
JonFreeman 4:67478861c670 603 case PARK:
JonFreeman 4:67478861c670 604 txt[0] = 'P';
JonFreeman 4:67478861c670 605 colr = LCD_COLOR_RED;
JonFreeman 4:67478861c670 606 break;
JonFreeman 4:67478861c670 607 default:
JonFreeman 4:67478861c670 608 txt[0] = 'X';
JonFreeman 4:67478861c670 609 colr = LCD_COLOR_CYAN;
JonFreeman 4:67478861c670 610 } // End of switch
JonFreeman 4:67478861c670 611 lcd.SetTextColor(colr);
JonFreeman 4:67478861c670 612 lcd.FillCircle (CIRC_CTR, q.position, BUTTON_RAD - 2);
JonFreeman 4:67478861c670 613 lcd.SetBackColor (colr);
JonFreeman 4:67478861c670 614 lcd.SetTextColor(LCD_COLOR_YELLOW);
JonFreeman 4:67478861c670 615 displaytext(SLIDERX + 17, q.position - 10, 4, txt); // largest font
JonFreeman 4:67478861c670 616 lcd.SetBackColor (LCD_COLOR_BLACK);
JonFreeman 4:67478861c670 617 } // End of else
JonFreeman 4:67478861c670 618 lcd.SetTextColor (oldtxtcolr);
JonFreeman 4:67478861c670 619 lcd.SetBackColor (oldbgcolr);
JonFreeman 4:67478861c670 620 // pc.printf ("SliderG %d, %d, %d\r\n", q.position, q.oldpos, q.state);
JonFreeman 4:67478861c670 621 }
JonFreeman 4:67478861c670 622
JonFreeman 4:67478861c670 623
JonFreeman 4:67478861c670 624
JonFreeman 4:67478861c670 625