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:
Wed May 09 17:09:18 2018 +0000
Revision:
8:5945d506a872
Parent:
5:21a8ac83142c
Child:
12:a25bdf135348
Removed custom sin and cos code, this was originally here because library sin and cos caused display breakup, now cured it seems

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