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:
Fri Jun 22 14:35:00 2018 +0000
Revision:
10:0bdfd342f393
Parent:
9:644867052318
seem to have broken comms a bit;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JonFreeman 4:67478861c670 1 #include "mbed.h"
JonFreeman 10:0bdfd342f393 2 /* Updated 21 June 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 10:0bdfd342f393 10 System voltage (range 10v - 62v)
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 10:0bdfd342f393 22 //---------------------------------- KEEP THIS IDENTICAL IN DualBLS
JonFreeman 10:0bdfd342f393 23 enum {MOTADIR, MOTBDIR, GANG, SVO1, SVO2, COMM_SRC, ID, WHEELDIA, MOTPIN, WHEELGEAR, BOGHUNWAT, FUT1, FUT2, FUT3, FUT4, FUT5} ; // Identical in TS and DualBLS
JonFreeman 10:0bdfd342f393 24 struct optpar {
JonFreeman 10:0bdfd342f393 25 int min, max, def; // min, max, default
JonFreeman 10:0bdfd342f393 26 const char * t; // description
JonFreeman 10:0bdfd342f393 27 } ;
JonFreeman 10:0bdfd342f393 28 struct optpar const option_list[] = {
JonFreeman 10:0bdfd342f393 29 {0, 1, 1, "MotorA direction 0 or 1"},
JonFreeman 10:0bdfd342f393 30 {0, 1, 0, "MotorB direction 0 or 1"},
JonFreeman 10:0bdfd342f393 31 {0, 1, 1, "gang 0 for separate control (robot mode), 1 for ganged loco bogie mode"},
JonFreeman 10:0bdfd342f393 32 {0, 2, 2, "Servo1 0, 1, 2 = Not used, Input, Output"},
JonFreeman 10:0bdfd342f393 33 {0, 2, 2, "Servo2 0, 1, 2 = Not used, Input, Output"},
JonFreeman 10:0bdfd342f393 34 {1, 5, 2, "Command source 0 Invalid, 1 COM1, 2 COM2, 3 Pot, 4 Servo1, 5 Servo2"},
JonFreeman 10:0bdfd342f393 35 {'1', '9', '0', "Alternative ID ascii '1' to '9'"}, // defaults to '0' before eerom setup for first time
JonFreeman 10:0bdfd342f393 36 {50, 250, 98, "Wheel diameter mm"}, // New 01/06/2018
JonFreeman 10:0bdfd342f393 37 {10, 250, 27, "Motor pinion"}, // New 01/06/2018
JonFreeman 10:0bdfd342f393 38 {50, 250, 85, "Wheel gear"}, // New 01/06/2018
JonFreeman 10:0bdfd342f393 39 {1, 20, 4, "Bogie power closest hundreds of Watt"}, // New 22/06/2018
JonFreeman 10:0bdfd342f393 40 {0, 100, 0, "Future 1"},
JonFreeman 10:0bdfd342f393 41 {0, 100, 0, "Future 2"},
JonFreeman 10:0bdfd342f393 42 {0, 100, 0, "Future 3"},
JonFreeman 10:0bdfd342f393 43 {0, 100, 0, "Future 4"},
JonFreeman 10:0bdfd342f393 44 {0, 100, 0, "Future 5"},
JonFreeman 10:0bdfd342f393 45 } ;
JonFreeman 10:0bdfd342f393 46 const int numof_eeprom_options = sizeof(option_list) / sizeof (struct optpar);
JonFreeman 4:67478861c670 47
JonFreeman 10:0bdfd342f393 48 struct single_bogie_options {
JonFreeman 10:0bdfd342f393 49 // char motoradir, motorbdir, gang, svo1, svo2, comm_src, id, wheeldia, motpin, wheelgear, spare;
JonFreeman 10:0bdfd342f393 50 char p[numof_eeprom_options + 8];
JonFreeman 10:0bdfd342f393 51 } ;
JonFreeman 10:0bdfd342f393 52
JonFreeman 10:0bdfd342f393 53 /*
JonFreeman 10:0bdfd342f393 54 struct single_bogie_options {
JonFreeman 10:0bdfd342f393 55 char motoradir, motorbdir, gang, svo1, svo2, comm_src, id, wheeldia, motpin, wheelgear, spare;
JonFreeman 10:0bdfd342f393 56 } ;
JonFreeman 10:0bdfd342f393 57 */
JonFreeman 10:0bdfd342f393 58 static const int MAX_BOGIES = 4;
JonFreeman 10:0bdfd342f393 59 struct multi_bogie_options {
JonFreeman 10:0bdfd342f393 60 struct single_bogie_options bogie[MAX_BOGIES];
JonFreeman 10:0bdfd342f393 61 } ; // gets initialised in main
JonFreeman 10:0bdfd342f393 62
JonFreeman 10:0bdfd342f393 63 //----------------------------------
JonFreeman 4:67478861c670 64 #define QSPI
JonFreeman 4:67478861c670 65
JonFreeman 4:67478861c670 66 #define MAX_TOUCHES 6 // Touch screen can decode up to this many simultaneous finger press positions
JonFreeman 4:67478861c670 67 #define NEUTRAL_VAL 150 // Number of pixels
JonFreeman 4:67478861c670 68
JonFreeman 4:67478861c670 69 #define SLIDERX 418 // slider graphic x position
JonFreeman 4:67478861c670 70 #define SLIDERY 2 // slider graphic y position
JonFreeman 4:67478861c670 71 #define SLIDERW 50 // pixel width of slider
JonFreeman 4:67478861c670 72 #define SLIDERH 268 // pixel height of slider
JonFreeman 4:67478861c670 73
JonFreeman 4:67478861c670 74 // To get speedo reading correctly, need to use correct gear ratio and wheel size info
JonFreeman 5:21a8ac83142c 75 #define BOGIE_5_INCH
JonFreeman 5:21a8ac83142c 76 //#define BOGIE_7_and_a_quarter_INCH
JonFreeman 4:67478861c670 77
JonFreeman 4:67478861c670 78 const int
JonFreeman 4:67478861c670 79
JonFreeman 4:67478861c670 80 BUTTON_RAD = (SLIDERW / 2) - 4, // radius of circular 'knob' in slider control
JonFreeman 4:67478861c670 81 MIN_POS = BUTTON_RAD + 5, // top of screen
JonFreeman 4:67478861c670 82 MAX_POS = SLIDERH - (BUTTON_RAD + 1), // bottom of screen
JonFreeman 4:67478861c670 83 CIRC_CTR = SLIDERX + BUTTON_RAD + 4;
JonFreeman 4:67478861c670 84
JonFreeman 10:0bdfd342f393 85 static const double PI = 4.0 * atan(1.0);
JonFreeman 10:0bdfd342f393 86
JonFreeman 10:0bdfd342f393 87 /*#ifdef BOGIE_7_and_a_quarter_INCH
JonFreeman 4:67478861c670 88 MOTOR_PINION_T = 17.0, // motor pinion teeth, wheel gear teeth and wheel dia required to calculate speed and distance.
JonFreeman 4:67478861c670 89 WHEEL_GEAR_T = 76.0,
JonFreeman 10:0bdfd342f393 90 WHEEL_DIA_MM = 145.0, //was 147
JonFreeman 4:67478861c670 91 #endif
JonFreeman 4:67478861c670 92 #ifdef BOGIE_5_INCH
JonFreeman 4:67478861c670 93 MOTOR_PINION_T = 27.0, // motor pinion teeth, wheel gear teeth and wheel dia required to calculate speed and distance.
JonFreeman 4:67478861c670 94 WHEEL_GEAR_T = 85.0,
JonFreeman 4:67478861c670 95 WHEEL_DIA_MM = 98.0,
JonFreeman 4:67478861c670 96 #endif
JonFreeman 4:67478861c670 97 PI = 4.0 * atan(1.0),
JonFreeman 4:67478861c670 98 WHEEL_CIRCUMFERENCE_METRE = PI * WHEEL_DIA_MM / 1000.0,
JonFreeman 4:67478861c670 99 PULSES_PER_WHEEL_REV = 32.0 * WHEEL_GEAR_T / MOTOR_PINION_T,
JonFreeman 4:67478861c670 100 PULSES_PER_METRE = PULSES_PER_WHEEL_REV / WHEEL_CIRCUMFERENCE_METRE,
JonFreeman 4:67478861c670 101 rpm2mph = 60.0 // = Motor Revs per hour;
JonFreeman 4:67478861c670 102 * (MOTOR_PINION_T / WHEEL_GEAR_T) // = Wheel rev per hour
JonFreeman 4:67478861c670 103 * WHEEL_CIRCUMFERENCE_METRE // = metres per hour
JonFreeman 4:67478861c670 104 * 39.37 // = inches per hour
JonFreeman 4:67478861c670 105 / (1760 * 36) // = miles per hour
JonFreeman 4:67478861c670 106 ;
JonFreeman 10:0bdfd342f393 107 */
JonFreeman 4:67478861c670 108 const double LOCO_HANDBRAKE_ESCAPE_SPEED = 0.5;
JonFreeman 4:67478861c670 109
JonFreeman 4:67478861c670 110 enum {NO_DPS, ONE_DP};
JonFreeman 4:67478861c670 111 // Assign unique number to every button we may use, and keep count of total number of them
JonFreeman 4:67478861c670 112 enum {
JonFreeman 4:67478861c670 113 ENTER, SLIDER, SPEEDO_BUT, VMETER_BUT, AMETER_BUT,
JonFreeman 4:67478861c670 114 NUMOF_BUTTONS} ; // button names
JonFreeman 4:67478861c670 115 enum {
JonFreeman 4:67478861c670 116 STATES, INACTIVE, RUN, NEUTRAL_DRIFT, REGEN_BRAKE, PARK, HANDBRAKE_SLIPPING};
JonFreeman 4:67478861c670 117
JonFreeman 4:67478861c670 118 struct slide { int position; int oldpos; int state; int direction; bool recalc_run; bool handbrake_slipping;
JonFreeman 4:67478861c670 119 double handbrake_effort; double loco_speed; } ;
JonFreeman 4:67478861c670 120 struct point { int x; int y; } ;
JonFreeman 4:67478861c670 121 struct key { int keynum; int x; int y; bool pressed; } ;
JonFreeman 4:67478861c670 122 struct ky_bd { int count, slider_y; key ky[MAX_TOUCHES + 1]; bool sli; } ;
JonFreeman 4:67478861c670 123
JonFreeman 5:21a8ac83142c 124 const int MAX_PARAMS = 20;
JonFreeman 5:21a8ac83142c 125 struct parameters {
JonFreeman 5:21a8ac83142c 126 struct kb_command const * clist;
JonFreeman 5:21a8ac83142c 127 char cmd_line[120];
JonFreeman 5:21a8ac83142c 128 char * cmd_line_ptr;
JonFreeman 5:21a8ac83142c 129 int32_t position_in_list, numof_dbls, target_unit, numof_menu_items, com_no, cl_index, gp_i;
JonFreeman 5:21a8ac83142c 130 double dbl[MAX_PARAMS];
JonFreeman 5:21a8ac83142c 131 bool respond;
JonFreeman 5:21a8ac83142c 132 } ;
JonFreeman 5:21a8ac83142c 133
JonFreeman 5:21a8ac83142c 134