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

Revision:
10:0bdfd342f393
Parent:
9:644867052318
--- a/Electric_Loco.h	Fri Jun 01 07:05:58 2018 +0000
+++ b/Electric_Loco.h	Fri Jun 22 14:35:00 2018 +0000
@@ -1,5 +1,5 @@
 #include "mbed.h"
-/*  Updated 9 May 2018
+/*  Updated 21 June 2018
     Jon Freeman
 
   5" and 7.25" gauge Electric Locomotive Controller - ST DISCO-F746NG
@@ -7,7 +7,7 @@
 
 Display shows 'analogue' moving coil meter movements for :
     Locomotive speed Miles per Hour
-    System voltage (range 20v - 90v or thereabouts)
+    System voltage (range 10v - 62v)
     Power Watts delivered to drive motors.
 
 Touch screen has three 'buttons', these are currently unused, and are where the meter movements show.
@@ -19,7 +19,48 @@
 Moving towards top of screen powers drive motors, move further up applies more torque (current controller implemented)
 Take finger off and control drifts down to central 'neutral' position.
 */
+//----------------------------------    KEEP THIS IDENTICAL IN DualBLS
+enum    {MOTADIR, MOTBDIR, GANG, SVO1, SVO2, COMM_SRC, ID, WHEELDIA, MOTPIN, WHEELGEAR, BOGHUNWAT, FUT1, FUT2, FUT3, FUT4, FUT5}  ;  //  Identical in TS and DualBLS
+struct  optpar  {
+    int min, max, def;  //  min, max, default
+    const char * t;     //  description
+}   ;
+struct  optpar const option_list[] = {
+    {0, 1, 1, "MotorA direction 0 or 1"},
+    {0, 1, 0, "MotorB direction 0 or 1"},
+    {0, 1, 1, "gang 0 for separate control (robot mode), 1 for ganged loco bogie mode"},
+    {0, 2, 2, "Servo1 0, 1, 2 = Not used, Input, Output"},
+    {0, 2, 2, "Servo2 0, 1, 2 = Not used, Input, Output"},
+    {1, 5, 2, "Command source 0 Invalid, 1 COM1, 2 COM2, 3 Pot, 4 Servo1, 5 Servo2"},
+    {'1', '9', '0', "Alternative ID ascii '1' to '9'"}, //  defaults to '0' before eerom setup for first time
+    {50, 250, 98,  "Wheel diameter mm"},   //  New 01/06/2018
+    {10, 250, 27,  "Motor pinion"},   //  New 01/06/2018
+    {50, 250, 85,  "Wheel gear"},   //  New 01/06/2018
+    {1, 20, 4, "Bogie power closest hundreds of Watt"}, //  New 22/06/2018
+    {0, 100, 0, "Future 1"},
+    {0, 100, 0, "Future 2"},
+    {0, 100, 0, "Future 3"},
+    {0, 100, 0, "Future 4"},
+    {0, 100, 0, "Future 5"},
+}   ;
+const int    numof_eeprom_options    = sizeof(option_list) / sizeof (struct optpar);
 
+struct  single_bogie_options   {
+//    char    motoradir, motorbdir, gang, svo1, svo2, comm_src, id, wheeldia, motpin, wheelgear, spare;
+    char    p[numof_eeprom_options + 8];
+}   ;
+
+/*
+struct  single_bogie_options   {
+    char    motoradir, motorbdir, gang, svo1, svo2, comm_src, id, wheeldia, motpin, wheelgear, spare;
+}   ;
+*/
+static const int    MAX_BOGIES = 4;
+struct  multi_bogie_options   {
+    struct  single_bogie_options    bogie[MAX_BOGIES];    
+}  ;   //  gets initialised in main
+
+//----------------------------------
 #define QSPI
 
 #define MAX_TOUCHES 6       //  Touch screen can decode up to this many simultaneous finger press positions
@@ -41,11 +82,12 @@
     MAX_POS     = SLIDERH - (BUTTON_RAD + 1),   //  bottom of screen
     CIRC_CTR = SLIDERX + BUTTON_RAD + 4;
 
-static const double
-#ifdef  BOGIE_7_and_a_quarter_INCH
+static const double    PI = 4.0 * atan(1.0);
+
+/*#ifdef  BOGIE_7_and_a_quarter_INCH
     MOTOR_PINION_T  = 17.0, //  motor pinion teeth, wheel gear teeth and wheel dia required to calculate speed and distance.
     WHEEL_GEAR_T    = 76.0,
-    WHEEL_DIA_MM    = 147.0,
+    WHEEL_DIA_MM    = 145.0,    //was 147
 #endif
 #ifdef  BOGIE_5_INCH
     MOTOR_PINION_T  = 27.0, //  motor pinion teeth, wheel gear teeth and wheel dia required to calculate speed and distance.
@@ -62,7 +104,7 @@
                   * 39.37                             //  = inches per hour
                   / (1760 * 36)                       //  = miles per hour
                   ;
-
+*/
 const   double LOCO_HANDBRAKE_ESCAPE_SPEED = 0.5;
 
 enum    {NO_DPS, ONE_DP};