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

Committer:
JonFreeman
Date:
Sat Jun 23 09:37:41 2018 +0000
Revision:
11:a573664b1a59
Parent:
9:644867052318
Child:
12:a25bdf135348
Seemingly un-broken, yet to master replacing rpm with mph

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JonFreeman 4:67478861c670 1 #include "mbed.h"
JonFreeman 9:644867052318 2 /* Updated 9 May 2018
JonFreeman 4:67478861c670 3 Jon Freeman
JonFreeman 4:67478861c670 4
JonFreeman 4:67478861c670 5 5" and 7.25" gauge Electric Locomotive Controller - ST DISCO-F746NG
JonFreeman 4:67478861c670 6 Uses built in display and touch screen.
JonFreeman 4:67478861c670 7
JonFreeman 4:67478861c670 8 Display shows 'analogue' moving coil meter movements for :
JonFreeman 4:67478861c670 9 Locomotive speed Miles per Hour
JonFreeman 4:67478861c670 10 System voltage (range 20v - 90v or thereabouts)
JonFreeman 4:67478861c670 11 Power Watts delivered to drive motors.
JonFreeman 4:67478861c670 12
JonFreeman 4:67478861c670 13 Touch screen has three 'buttons', these are currently unused, and are where the meter movements show.
JonFreeman 4:67478861c670 14 Idea is to use two for two horns,
JonFreeman 4:67478861c670 15
JonFreeman 4:67478861c670 16 Display has 'slider' touch control. This drives the loco.
JonFreeman 4:67478861c670 17 Control in central position when not driving or drfting.
JonFreeman 4:67478861c670 18 Moving towards bottom of screen applies regenerative braking - move further down applies harder braking.
JonFreeman 4:67478861c670 19 Moving towards top of screen powers drive motors, move further up applies more torque (current controller implemented)
JonFreeman 4:67478861c670 20 Take finger off and control drifts down to central 'neutral' position.
JonFreeman 4:67478861c670 21 */
JonFreeman 4:67478861c670 22
JonFreeman 4:67478861c670 23 #define QSPI
JonFreeman 4:67478861c670 24
JonFreeman 4:67478861c670 25 #define MAX_TOUCHES 6 // Touch screen can decode up to this many simultaneous finger press positions
JonFreeman 4:67478861c670 26 #define NEUTRAL_VAL 150 // Number of pixels
JonFreeman 4:67478861c670 27
JonFreeman 4:67478861c670 28 #define SLIDERX 418 // slider graphic x position
JonFreeman 4:67478861c670 29 #define SLIDERY 2 // slider graphic y position
JonFreeman 4:67478861c670 30 #define SLIDERW 50 // pixel width of slider
JonFreeman 4:67478861c670 31 #define SLIDERH 268 // pixel height of slider
JonFreeman 4:67478861c670 32
JonFreeman 4:67478861c670 33 // To get speedo reading correctly, need to use correct gear ratio and wheel size info
JonFreeman 11:a573664b1a59 34 //#define BOGIE_5_INCH
JonFreeman 11:a573664b1a59 35 #define BOGIE_7_and_a_quarter_INCH
JonFreeman 4:67478861c670 36
JonFreeman 4:67478861c670 37 const int
JonFreeman 4:67478861c670 38
JonFreeman 4:67478861c670 39 BUTTON_RAD = (SLIDERW / 2) - 4, // radius of circular 'knob' in slider control
JonFreeman 4:67478861c670 40 MIN_POS = BUTTON_RAD + 5, // top of screen
JonFreeman 4:67478861c670 41 MAX_POS = SLIDERH - (BUTTON_RAD + 1), // bottom of screen
JonFreeman 4:67478861c670 42 CIRC_CTR = SLIDERX + BUTTON_RAD + 4;
JonFreeman 4:67478861c670 43
JonFreeman 4:67478861c670 44 static const double
JonFreeman 4:67478861c670 45 #ifdef BOGIE_7_and_a_quarter_INCH
JonFreeman 4:67478861c670 46 MOTOR_PINION_T = 17.0, // motor pinion teeth, wheel gear teeth and wheel dia required to calculate speed and distance.
JonFreeman 4:67478861c670 47 WHEEL_GEAR_T = 76.0,
JonFreeman 4:67478861c670 48 WHEEL_DIA_MM = 147.0,
JonFreeman 4:67478861c670 49 #endif
JonFreeman 4:67478861c670 50 #ifdef BOGIE_5_INCH
JonFreeman 4:67478861c670 51 MOTOR_PINION_T = 27.0, // motor pinion teeth, wheel gear teeth and wheel dia required to calculate speed and distance.
JonFreeman 4:67478861c670 52 WHEEL_GEAR_T = 85.0,
JonFreeman 4:67478861c670 53 WHEEL_DIA_MM = 98.0,
JonFreeman 4:67478861c670 54 #endif
JonFreeman 4:67478861c670 55 PI = 4.0 * atan(1.0),
JonFreeman 4:67478861c670 56 WHEEL_CIRCUMFERENCE_METRE = PI * WHEEL_DIA_MM / 1000.0,
JonFreeman 4:67478861c670 57 PULSES_PER_WHEEL_REV = 32.0 * WHEEL_GEAR_T / MOTOR_PINION_T,
JonFreeman 4:67478861c670 58 PULSES_PER_METRE = PULSES_PER_WHEEL_REV / WHEEL_CIRCUMFERENCE_METRE,
JonFreeman 4:67478861c670 59 rpm2mph = 60.0 // = Motor Revs per hour;
JonFreeman 4:67478861c670 60 * (MOTOR_PINION_T / WHEEL_GEAR_T) // = Wheel rev per hour
JonFreeman 4:67478861c670 61 * WHEEL_CIRCUMFERENCE_METRE // = metres per hour
JonFreeman 4:67478861c670 62 * 39.37 // = inches per hour
JonFreeman 4:67478861c670 63 / (1760 * 36) // = miles per hour
JonFreeman 4:67478861c670 64 ;
JonFreeman 4:67478861c670 65
JonFreeman 4:67478861c670 66 const double LOCO_HANDBRAKE_ESCAPE_SPEED = 0.5;
JonFreeman 4:67478861c670 67
JonFreeman 4:67478861c670 68 enum {NO_DPS, ONE_DP};
JonFreeman 4:67478861c670 69 // Assign unique number to every button we may use, and keep count of total number of them
JonFreeman 4:67478861c670 70 enum {
JonFreeman 4:67478861c670 71 ENTER, SLIDER, SPEEDO_BUT, VMETER_BUT, AMETER_BUT,
JonFreeman 4:67478861c670 72 NUMOF_BUTTONS} ; // button names
JonFreeman 4:67478861c670 73 enum {
JonFreeman 4:67478861c670 74 STATES, INACTIVE, RUN, NEUTRAL_DRIFT, REGEN_BRAKE, PARK, HANDBRAKE_SLIPPING};
JonFreeman 4:67478861c670 75
JonFreeman 4:67478861c670 76 struct slide { int position; int oldpos; int state; int direction; bool recalc_run; bool handbrake_slipping;
JonFreeman 4:67478861c670 77 double handbrake_effort; double loco_speed; } ;
JonFreeman 4:67478861c670 78 struct point { int x; int y; } ;
JonFreeman 4:67478861c670 79 struct key { int keynum; int x; int y; bool pressed; } ;
JonFreeman 4:67478861c670 80 struct ky_bd { int count, slider_y; key ky[MAX_TOUCHES + 1]; bool sli; } ;
JonFreeman 4:67478861c670 81
JonFreeman 5:21a8ac83142c 82 const int MAX_PARAMS = 20;
JonFreeman 5:21a8ac83142c 83 struct parameters {
JonFreeman 5:21a8ac83142c 84 struct kb_command const * clist;
JonFreeman 5:21a8ac83142c 85 char cmd_line[120];
JonFreeman 5:21a8ac83142c 86 char * cmd_line_ptr;
JonFreeman 5:21a8ac83142c 87 int32_t position_in_list, numof_dbls, target_unit, numof_menu_items, com_no, cl_index, gp_i;
JonFreeman 5:21a8ac83142c 88 double dbl[MAX_PARAMS];
JonFreeman 5:21a8ac83142c 89 bool respond;
JonFreeman 5:21a8ac83142c 90 } ;
JonFreeman 5:21a8ac83142c 91
JonFreeman 11:a573664b1a59 92 class genio { // 23/06/2018 generic io handler
JonFreeman 11:a573664b1a59 93 public:
JonFreeman 11:a573664b1a59 94 uint32_t count; // Running total of times called
JonFreeman 11:a573664b1a59 95 bool available; // set true when number rec'd, set false by reading it
JonFreeman 11:a573664b1a59 96 int d_type; // loaded on setup indicating expected data type
JonFreeman 11:a573664b1a59 97 int d_len; // loaded on setup indicating expected num of parameters to handle
JonFreeman 11:a573664b1a59 98 uint32_t ui[MAX_PARAMS];
JonFreeman 11:a573664b1a59 99 double dbl[MAX_PARAMS];
JonFreeman 11:a573664b1a59 100 genio () {} // default constructor
JonFreeman 11:a573664b1a59 101 genio (int, int) ; // more useful constructor
JonFreeman 11:a573664b1a59 102 void store (struct parameters &) ; //
JonFreeman 11:a573664b1a59 103 bool read (uint32_t **) ;
JonFreeman 11:a573664b1a59 104 bool read (double &) ;
JonFreeman 11:a573664b1a59 105 } ;
JonFreeman 5:21a8ac83142c 106
JonFreeman 11:a573664b1a59 107