new battery bar

Dependencies:   CAN_IDs CanControl Dashboard PinDetect PowerControl mbed-rtos mbed

Committer:
Marrkk_92
Date:
Tue May 23 21:40:51 2017 +0000
Revision:
28:63ef4790703f
Parent:
27:6ffb44623906
update for temp bars and comment-out updateThrottleBar

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kwasymodo 1:c5d8ea5d049b 1 /*******************************************************************************
kwasymodo 4:dfd10f43cc8b 2 This software is especially designed for Solarboat Twente for the use in their Solarboat v1.0
kwasymodo 1:c5d8ea5d049b 3
kwasymodo 1:c5d8ea5d049b 4 Written by:
zathorix 23:970a5603da43 5 Niels Leijen, Jesse van Rhijn, Bram Seinhorst, Mark Bruijn
kwasymodo 1:c5d8ea5d049b 6
kwasymodo 1:c5d8ea5d049b 7 Thanks to:
kwasymodo 1:c5d8ea5d049b 8 Jasper Admiraal, Hidde Pik (hihihihi), Lisa Postma, Heleen Jeurink, Ruben Peters,
kwasymodo 1:c5d8ea5d049b 9 Martijn Groot Jebbink, Martijn Wilpshaar, Bram Seinhorst, Robert Geels, Arnoud Meutstege,
kwasymodo 4:dfd10f43cc8b 10 Jeroen te Braake, Ids de Vos, Jesse van Rhijn, Sam Benou, Niels Leijen and Mark Bruijn
kwasymodo 1:c5d8ea5d049b 11
kwasymodo 1:c5d8ea5d049b 12 DISCLAIMER:
kwasymodo 1:c5d8ea5d049b 13 THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT.
kwasymodo 1:c5d8ea5d049b 14 SOLARBOATTWENTE ASSUMES NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE.
kwasymodo 1:c5d8ea5d049b 15 *******************************************************************************/
kwasymodo 1:c5d8ea5d049b 16
kwasymodo 1:c5d8ea5d049b 17 // uncomment to send debug information
zathorix 22:8fdbdfbdf74a 18 //#define DEBUG
kwasymodo 1:c5d8ea5d049b 19
kwasymodo 1:c5d8ea5d049b 20 //include 3rd party libraries
kwasymodo 4:dfd10f43cc8b 21 #include "mbed.h" //needs to be revision 136 else SD filesystem will not work
kwasymodo 1:c5d8ea5d049b 22 #include "rtos.h"
kwasymodo 1:c5d8ea5d049b 23
kwasymodo 1:c5d8ea5d049b 24 // include Solarboat libraries
kwasymodo 1:c5d8ea5d049b 25 #include "pinout.h"
zathorix 14:0ad1bc8be76b 26 #include "CAN_IDs.h"
kwasymodo 1:c5d8ea5d049b 27 #include "PowerControl.h"
zathorix 16:c5427db9edf0 28 #include "TelemetryAndDaq.h"
zathorix 16:c5427db9edf0 29 #include "Dashboard.h"
kwasymodo 1:c5d8ea5d049b 30
zathorix 15:56b25cffa523 31 #define SPEED_THRESH 0.02 //threshold for setting speed to prevent CAN spam
zathorix 22:8fdbdfbdf74a 32 #define DEBUG
zathorix 22:8fdbdfbdf74a 33 // initialize serial connection for debug and file retrieval
kwasymodo 3:b164662f9740 34 RawSerial pc(SERIAL_TX, SERIAL_RX);
kwasymodo 1:c5d8ea5d049b 35
kwasymodo 1:c5d8ea5d049b 36 // initialize canbus
kwasymodo 1:c5d8ea5d049b 37 CAN can(CAN_RD, CAN_TD);
kwasymodo 1:c5d8ea5d049b 38
zathorix 14:0ad1bc8be76b 39 //init throttle
zathorix 14:0ad1bc8be76b 40 AnalogIn analogThrottle(STEER_THROTTLE);
zathorix 14:0ad1bc8be76b 41
zathorix 18:aa6feb4b73e7 42 //initialize steering wheel buttons
zathorix 18:aa6feb4b73e7 43
zathorix 18:aa6feb4b73e7 44 //NEEDS FIXING!!!!!!!!!!!
zathorix 18:aa6feb4b73e7 45 DigitalIn menu_button(STEER_MENU);
zathorix 18:aa6feb4b73e7 46 DigitalIn fly_button(STEER_FLY);
zathorix 18:aa6feb4b73e7 47 DigitalIn reverse_button(STEER_REV);
zathorix 18:aa6feb4b73e7 48
kwasymodo 1:c5d8ea5d049b 49 // initialze onboard leds
kwasymodo 1:c5d8ea5d049b 50 DigitalOut ledError(LED3);
kwasymodo 1:c5d8ea5d049b 51 DigitalOut ledSD(LED1);
kwasymodo 1:c5d8ea5d049b 52 DigitalOut ledFona(LED5);
kwasymodo 1:c5d8ea5d049b 53 DigitalOut led24V(LED4);
kwasymodo 1:c5d8ea5d049b 54
kwasymodo 11:005a50dd7db5 55 DigitalOut buckXSens(BUCK3);
kwasymodo 11:005a50dd7db5 56 DigitalOut buckScreen(BUCK4);
kwasymodo 11:005a50dd7db5 57 DigitalOut buck24V(BUCK5);
kwasymodo 1:c5d8ea5d049b 58
zathorix 16:c5427db9edf0 59 //external classes
zathorix 16:c5427db9edf0 60 extern DataAcquisition daq;
zathorix 17:91ba27c14991 61 extern Telemetrics telemetrics;
zathorix 18:aa6feb4b73e7 62 extern Dashboard dash;
kwasymodo 1:c5d8ea5d049b 63
zathorix 16:c5427db9edf0 64 //external variables
zathorix 16:c5427db9edf0 65 extern long long int starttime;
kwasymodo 11:005a50dd7db5 66
zathorix 16:c5427db9edf0 67 //external threads
zathorix 16:c5427db9edf0 68 extern Thread threadbg;
kwasymodo 1:c5d8ea5d049b 69
zathorix 15:56b25cffa523 70 //global var for speed; ugly solution but works
zathorix 14:0ad1bc8be76b 71 float speed = 0;
zathorix 14:0ad1bc8be76b 72
zathorix 16:c5427db9edf0 73 //thread function declarations
zathorix 16:c5427db9edf0 74 void readThrottle();
zathorix 16:c5427db9edf0 75 void power();
zathorix 16:c5427db9edf0 76 void test();
zathorix 16:c5427db9edf0 77 void background();
zathorix 18:aa6feb4b73e7 78 void screens();
zathorix 22:8fdbdfbdf74a 79 void resetScreens();
zathorix 22:8fdbdfbdf74a 80
zathorix 22:8fdbdfbdf74a 81 //varables for screens
zathorix 22:8fdbdfbdf74a 82 extern batterydata * battery;
zathorix 22:8fdbdfbdf74a 83 extern variable * velocitysqrd;
zathorix 22:8fdbdfbdf74a 84 extern variable * motortemp;
zathorix 22:8fdbdfbdf74a 85 //ticker for resetting screens
zathorix 22:8fdbdfbdf74a 86 Ticker ticker;
zathorix 18:aa6feb4b73e7 87
zathorix 18:aa6feb4b73e7 88 //screen function declarations
zathorix 18:aa6feb4b73e7 89 void readEssentials();
zathorix 18:aa6feb4b73e7 90
zathorix 18:aa6feb4b73e7 91 //Screen placeholder variables
zathorix 18:aa6feb4b73e7 92 int battery_percentage_left = 0;
zathorix 18:aa6feb4b73e7 93 int battery_minutes_left = 0;
zathorix 18:aa6feb4b73e7 94 int race_percentage_left = 0;
zathorix 18:aa6feb4b73e7 95 int race_minutes_left = 0;
zathorix 18:aa6feb4b73e7 96 int race_minutes_done = 0;
zathorix 18:aa6feb4b73e7 97 int throttle_power = 0;
zathorix 18:aa6feb4b73e7 98 int advised_throttle_power = 0;
zathorix 18:aa6feb4b73e7 99 int power_in = 0;
zathorix 18:aa6feb4b73e7 100 int power_out = 0;
zathorix 18:aa6feb4b73e7 101 int voltage_in = 0;
zathorix 18:aa6feb4b73e7 102 int motor_temperature = 0;
zathorix 18:aa6feb4b73e7 103 int battery_temperature = 0;
zathorix 18:aa6feb4b73e7 104 int velocity = 0;
zathorix 18:aa6feb4b73e7 105 int rpm_motor = 0;
zathorix 18:aa6feb4b73e7 106 int checkIfButtonPressed(int current_menu);
zathorix 18:aa6feb4b73e7 107 int battery_voltage = 0;
zathorix 18:aa6feb4b73e7 108 int current_menu = 0;
zathorix 18:aa6feb4b73e7 109 time_t start = time(0);
zathorix 18:aa6feb4b73e7 110 void readEssentials();
zathorix 18:aa6feb4b73e7 111 bool menu_button_pressed = true;
zathorix 18:aa6feb4b73e7 112 bool reverse_button_pressed = true;
zathorix 18:aa6feb4b73e7 113 bool fly_request = true;
zathorix 18:aa6feb4b73e7 114 bool transmitting = false;
zathorix 18:aa6feb4b73e7 115 bool reverse = false;
zathorix 18:aa6feb4b73e7 116
kwasymodo 1:c5d8ea5d049b 117 // Thread 0 - DO NOT CHANGE THIS!
kwasymodo 1:c5d8ea5d049b 118 int main() {
kwasymodo 1:c5d8ea5d049b 119 #ifdef DEBUG
kwasymodo 1:c5d8ea5d049b 120 pc.baud(115200);
kwasymodo 3:b164662f9740 121 pc.printf("Starting SOS V1.0\n");
kwasymodo 1:c5d8ea5d049b 122 #endif
kwasymodo 1:c5d8ea5d049b 123 // change CAN frequency
kwasymodo 1:c5d8ea5d049b 124 can.frequency(250000);
kwasymodo 1:c5d8ea5d049b 125
kwasymodo 1:c5d8ea5d049b 126 // initialze threads
zathorix 15:56b25cffa523 127 Thread threadpower;
zathorix 15:56b25cffa523 128 Thread threadtest;
zathorix 14:0ad1bc8be76b 129 Thread threadthrottle;
zathorix 18:aa6feb4b73e7 130 Thread threaddash;
zathorix 22:8fdbdfbdf74a 131 Thread threadresetscr;
zathorix 22:8fdbdfbdf74a 132
kwasymodo 1:c5d8ea5d049b 133 // start threads
zathorix 15:56b25cffa523 134 threadpower.start(&power);
zathorix 22:8fdbdfbdf74a 135 Thread::wait(50);
zathorix 16:c5427db9edf0 136 threadbg.start(&background);
zathorix 22:8fdbdfbdf74a 137 Thread::wait(50);
zathorix 15:56b25cffa523 138 threadtest.start(&test);
zathorix 22:8fdbdfbdf74a 139 Thread::wait(50);
zathorix 22:8fdbdfbdf74a 140
zathorix 22:8fdbdfbdf74a 141 toggleControlSys(0x01);
zathorix 22:8fdbdfbdf74a 142
zathorix 18:aa6feb4b73e7 143 threaddash.start(&screens);
zathorix 22:8fdbdfbdf74a 144 Thread::wait(50);
zathorix 14:0ad1bc8be76b 145 threadthrottle.start(&readThrottle);
zathorix 22:8fdbdfbdf74a 146 Thread::wait(50);
zathorix 17:91ba27c14991 147 telemetrics.enable();
zathorix 22:8fdbdfbdf74a 148 Thread::wait(50);
zathorix 16:c5427db9edf0 149 daq.enable(starttime);
zathorix 16:c5427db9edf0 150
zathorix 16:c5427db9edf0 151 //BMS message parser, now imlpemented in DAQ lib
zathorix 16:c5427db9edf0 152 /*CANMessage msg;
kwasymodo 11:005a50dd7db5 153 while(1) {
kwasymodo 11:005a50dd7db5 154 if(can.read(msg)) {
kwasymodo 11:005a50dd7db5 155 pc.printf("Message received: 0x %x; %u %u%u %d%d %c %u %u\n", msg.id, msg.data[0], msg.data[1], msg.data[2], msg.data[3], msg.data[4], msg.data[5], msg.data[6], msg.data[7]);
zathorix 16:c5427db9edf0 156 }
zathorix 16:c5427db9edf0 157 Thread::wait(10);
zathorix 16:c5427db9edf0 158 }*/
zathorix 16:c5427db9edf0 159 Thread::wait(osWaitForever);
zathorix 16:c5427db9edf0 160 }
zathorix 16:c5427db9edf0 161
zathorix 16:c5427db9edf0 162 //send motor command
zathorix 16:c5427db9edf0 163 void sendMotorSpeed(float throttle) {
zathorix 16:c5427db9edf0 164 if ((abs(throttle - speed)) > SPEED_THRESH) {
zathorix 16:c5427db9edf0 165 union {
zathorix 16:c5427db9edf0 166 char msg[4];
zathorix 16:c5427db9edf0 167 float value;
zathorix 16:c5427db9edf0 168 } packet;
zathorix 16:c5427db9edf0 169 packet.value = throttle;
zathorix 16:c5427db9edf0 170 can.write(CANMessage(MOTOR_COMMAND, packet.msg));
zathorix 16:c5427db9edf0 171 printf("Sent motor speed: %f\r\n", packet.value);
zathorix 16:c5427db9edf0 172 speed = throttle;
kwasymodo 11:005a50dd7db5 173 }
zathorix 16:c5427db9edf0 174 }
zathorix 16:c5427db9edf0 175
zathorix 16:c5427db9edf0 176 //thread functions
zathorix 16:c5427db9edf0 177 void readThrottle() {
zathorix 16:c5427db9edf0 178 float throttleread;
zathorix 22:8fdbdfbdf74a 179 int rev;
zathorix 16:c5427db9edf0 180 while(1) {
zathorix 22:8fdbdfbdf74a 181 if (reverse) {
zathorix 22:8fdbdfbdf74a 182 rev = -1;
zathorix 22:8fdbdfbdf74a 183 } else {
zathorix 22:8fdbdfbdf74a 184 rev = 1;
zathorix 22:8fdbdfbdf74a 185 }
zathorix 22:8fdbdfbdf74a 186 throttleread = rev*(1 - analogThrottle.read());
zathorix 16:c5427db9edf0 187 sendMotorSpeed(throttleread);
zathorix 16:c5427db9edf0 188 Thread::wait(10);
zathorix 16:c5427db9edf0 189 }
zathorix 16:c5427db9edf0 190 }
zathorix 16:c5427db9edf0 191
zathorix 16:c5427db9edf0 192
zathorix 16:c5427db9edf0 193
zathorix 16:c5427db9edf0 194 void power() {
zathorix 16:c5427db9edf0 195 PowerControl powercontrol(PUSH_GREEN);
zathorix 16:c5427db9edf0 196
zathorix 16:c5427db9edf0 197 #ifdef DEBUG
zathorix 16:c5427db9edf0 198 pc.printf("Thread 1 - Power started\r\n ");
zathorix 16:c5427db9edf0 199 #endif
zathorix 16:c5427db9edf0 200
kwasymodo 1:c5d8ea5d049b 201 Thread::wait(osWaitForever);
zathorix 16:c5427db9edf0 202 }
zathorix 16:c5427db9edf0 203
zathorix 16:c5427db9edf0 204 void test() {
zathorix 16:c5427db9edf0 205 ledError = 0;
zathorix 16:c5427db9edf0 206 ledSD = 0;
zathorix 16:c5427db9edf0 207 ledFona = 0 ;
zathorix 16:c5427db9edf0 208 led24V=1;
zathorix 16:c5427db9edf0 209
zathorix 16:c5427db9edf0 210 //DigitalOut buckCan(BUCK2);
zathorix 22:8fdbdfbdf74a 211 buckXSens = 1;
zathorix 18:aa6feb4b73e7 212 buckScreen = 1;
zathorix 16:c5427db9edf0 213 buck24V = 1;
zathorix 16:c5427db9edf0 214 }
zathorix 18:aa6feb4b73e7 215
zathorix 22:8fdbdfbdf74a 216 void resetScreens() {
zathorix 22:8fdbdfbdf74a 217
zathorix 22:8fdbdfbdf74a 218 Thread::wait(10000);
zathorix 22:8fdbdfbdf74a 219
zathorix 22:8fdbdfbdf74a 220 dash.powerOnOLED(1);
zathorix 22:8fdbdfbdf74a 221 dash.powerOnOLED(2);
zathorix 22:8fdbdfbdf74a 222 dash.powerOnOLED(3);
zathorix 22:8fdbdfbdf74a 223
zathorix 22:8fdbdfbdf74a 224 dash.clearDisplay(1);
zathorix 22:8fdbdfbdf74a 225 dash.clearDisplay(2);
zathorix 22:8fdbdfbdf74a 226 dash.clearDisplay(3);
zathorix 22:8fdbdfbdf74a 227 }
zathorix 22:8fdbdfbdf74a 228
zathorix 18:aa6feb4b73e7 229 void screens()
zathorix 18:aa6feb4b73e7 230 {
zathorix 18:aa6feb4b73e7 231 dash.powerOnOLED(1);
zathorix 18:aa6feb4b73e7 232 dash.powerOnOLED(2);
zathorix 18:aa6feb4b73e7 233 dash.powerOnOLED(3);
zathorix 22:8fdbdfbdf74a 234
zathorix 18:aa6feb4b73e7 235 dash.clearDisplay(1);
zathorix 18:aa6feb4b73e7 236 dash.clearDisplay(2);
zathorix 18:aa6feb4b73e7 237 dash.clearDisplay(3);
zathorix 22:8fdbdfbdf74a 238
zathorix 18:aa6feb4b73e7 239 while(1) {
zathorix 18:aa6feb4b73e7 240
zathorix 18:aa6feb4b73e7 241 Thread::wait(100);
zathorix 18:aa6feb4b73e7 242
zathorix 18:aa6feb4b73e7 243 //listen to menu button
zathorix 18:aa6feb4b73e7 244 current_menu = checkIfButtonPressed(current_menu);
zathorix 18:aa6feb4b73e7 245 //listen to steering wheel at all time
zathorix 18:aa6feb4b73e7 246 readEssentials();
zathorix 18:aa6feb4b73e7 247 //check for errors at all time
zathorix 18:aa6feb4b73e7 248 dash.checkForErrors(current_menu, velocity, battery_temperature, motor_temperature, battery_percentage_left, battery_minutes_left);
zathorix 18:aa6feb4b73e7 249
zathorix 18:aa6feb4b73e7 250
zathorix 18:aa6feb4b73e7 251 switch (current_menu) {
zathorix 18:aa6feb4b73e7 252
zathorix 18:aa6feb4b73e7 253 case 0:
zathorix 18:aa6feb4b73e7 254 //circular display (1)
zathorix 18:aa6feb4b73e7 255 //updateProgressCircle(1, race_percentage_left);
zathorix 22:8fdbdfbdf74a 256 race_minutes_done = daq.time/60000; //TODO give starting point
zathorix 18:aa6feb4b73e7 257 dash.showRaceMinutesDone(race_minutes_done);
zathorix 18:aa6feb4b73e7 258 dash.showRaceMinutesLeft(race_minutes_left);
zathorix 18:aa6feb4b73e7 259 dash.showRacePercentageLeft(race_percentage_left);
zathorix 18:aa6feb4b73e7 260
zathorix 18:aa6feb4b73e7 261 //main display (2)
zathorix 22:8fdbdfbdf74a 262 dash.displayTime(daq.time + starttime);
zathorix 18:aa6feb4b73e7 263 dash.checkTransmitter(transmitting);
zathorix 18:aa6feb4b73e7 264 dash.displayVelocity(velocity);
zathorix 22:8fdbdfbdf74a 265 dash.displayThrottle(abs(throttle_power), reverse);
Marrkk_92 28:63ef4790703f 266 //dash.updateThrottleBar(2, abs(throttle_power), 50, 20, 20, 5);
zathorix 18:aa6feb4b73e7 267 //displayAdvisedThrottle(advised_throttle_power);
Marrkk_92 27:6ffb44623906 268 //dash.updatePowerBars(power_out, power_in);
Marrkk_92 27:6ffb44623906 269 dash.updateTemperatureBars(motor_temperature, battery_temperature);
zathorix 18:aa6feb4b73e7 270
zathorix 18:aa6feb4b73e7 271 //circular display (3)
zathorix 18:aa6feb4b73e7 272 //updateProgressCircle(3, battery_percentage_left);
zathorix 18:aa6feb4b73e7 273 dash.showBatteryMinutesLeft(battery_minutes_left);
zathorix 18:aa6feb4b73e7 274 dash.showBatteryPercentageLeft(battery_percentage_left);
zathorix 18:aa6feb4b73e7 275 break;
zathorix 18:aa6feb4b73e7 276
zathorix 18:aa6feb4b73e7 277 case 1:
zathorix 18:aa6feb4b73e7 278 //circular display (1)
zathorix 18:aa6feb4b73e7 279 //updateProgressCircle(1, race_percentage_left);
zathorix 22:8fdbdfbdf74a 280 race_minutes_done = daq.time/60000; //TODO give starting point
zathorix 18:aa6feb4b73e7 281 dash.showRaceMinutesDone(race_minutes_done);
zathorix 18:aa6feb4b73e7 282 dash.showRaceMinutesLeft(race_minutes_left);
zathorix 18:aa6feb4b73e7 283 dash.showRacePercentageLeft(race_percentage_left);
zathorix 18:aa6feb4b73e7 284
zathorix 18:aa6feb4b73e7 285 //main display (2)
zathorix 18:aa6feb4b73e7 286 dash.displayData1(rpm_motor, battery_temperature, motor_temperature, voltage_in, power_out, power_in);
zathorix 18:aa6feb4b73e7 287
zathorix 18:aa6feb4b73e7 288 //circular display (3)
zathorix 18:aa6feb4b73e7 289 //updateProgressCircle(3, battery_percentage_left);
zathorix 18:aa6feb4b73e7 290 dash.showBatteryMinutesLeft(battery_minutes_left);
zathorix 18:aa6feb4b73e7 291 dash.showBatteryPercentageLeft(battery_percentage_left);
zathorix 18:aa6feb4b73e7 292 break;
zathorix 18:aa6feb4b73e7 293
zathorix 18:aa6feb4b73e7 294 case 2:
zathorix 18:aa6feb4b73e7 295 //circular display (1)
zathorix 18:aa6feb4b73e7 296 //updateProgressCircle(1, race_percentage_left);
zathorix 22:8fdbdfbdf74a 297 race_minutes_done = daq.time/60000; //TODO give starting point
zathorix 18:aa6feb4b73e7 298 dash.showRaceMinutesDone(race_minutes_done);
zathorix 18:aa6feb4b73e7 299 dash.showRaceMinutesLeft(race_minutes_left);
zathorix 18:aa6feb4b73e7 300 dash.showRacePercentageLeft(race_percentage_left);
zathorix 18:aa6feb4b73e7 301
zathorix 18:aa6feb4b73e7 302 //main display (2)
zathorix 18:aa6feb4b73e7 303 dash.displayData2(battery_voltage, battery_temperature, motor_temperature, voltage_in, power_out, power_in);
zathorix 18:aa6feb4b73e7 304
zathorix 18:aa6feb4b73e7 305 //circular display (3)
zathorix 18:aa6feb4b73e7 306 //updateProgressCircle(3, battery_percentage_left);
zathorix 18:aa6feb4b73e7 307 dash.showBatteryMinutesLeft(battery_minutes_left);
zathorix 18:aa6feb4b73e7 308 dash.showBatteryPercentageLeft(battery_percentage_left);
zathorix 18:aa6feb4b73e7 309 break;
zathorix 18:aa6feb4b73e7 310 default:
zathorix 18:aa6feb4b73e7 311 //empty, catch
zathorix 18:aa6feb4b73e7 312 break;
zathorix 18:aa6feb4b73e7 313 }
zathorix 18:aa6feb4b73e7 314 }
zathorix 18:aa6feb4b73e7 315 }
zathorix 18:aa6feb4b73e7 316
zathorix 18:aa6feb4b73e7 317 int checkIfButtonPressed(int current_menu)
zathorix 18:aa6feb4b73e7 318 {
zathorix 18:aa6feb4b73e7 319 //--------------MENU BUTTON--------------------
zathorix 18:aa6feb4b73e7 320 if (menu_button == 0 && menu_button_pressed == false) {
zathorix 18:aa6feb4b73e7 321 menu_button_pressed = true;
zathorix 18:aa6feb4b73e7 322 start = time(0);
zathorix 18:aa6feb4b73e7 323 current_menu++;
zathorix 18:aa6feb4b73e7 324 if (current_menu > 2) current_menu = 0;
zathorix 22:8fdbdfbdf74a 325
zathorix 22:8fdbdfbdf74a 326 //clear displays and reset settings
Marrkk_92 24:d848de26452b 327 dash.clearDisplay(1);
Marrkk_92 24:d848de26452b 328 dash.clearDisplay(2);
Marrkk_92 24:d848de26452b 329 dash.clearDisplay(3);
zathorix 22:8fdbdfbdf74a 330
zathorix 18:aa6feb4b73e7 331 } else if (menu_button == 1) menu_button_pressed = false;
zathorix 18:aa6feb4b73e7 332 //timeout for back to home screen
zathorix 22:8fdbdfbdf74a 333 /*double seconds_since_start = difftime(time(0), start);
zathorix 18:aa6feb4b73e7 334 if (current_menu != 0 && seconds_since_start > MENU_TIMEOUT_TIME) {
zathorix 18:aa6feb4b73e7 335 current_menu = 0;
zathorix 18:aa6feb4b73e7 336 dash.clearDisplay(1);
zathorix 18:aa6feb4b73e7 337 dash.clearDisplay(2);
zathorix 18:aa6feb4b73e7 338 dash.clearDisplay(3);
zathorix 22:8fdbdfbdf74a 339 }*/
zathorix 18:aa6feb4b73e7 340
zathorix 18:aa6feb4b73e7 341 //--------------REVERSE BUTTON--------------------
zathorix 18:aa6feb4b73e7 342 if (reverse_button == 0 && reverse_button_pressed == false) {
zathorix 18:aa6feb4b73e7 343 reverse_button_pressed = true;
zathorix 18:aa6feb4b73e7 344 if (velocity < MAX_REVERSE_VELOCITY) reverse = !reverse;
zathorix 18:aa6feb4b73e7 345 } else if (reverse_button == 1) reverse_button_pressed = false;
zathorix 18:aa6feb4b73e7 346
zathorix 18:aa6feb4b73e7 347 //--------------FLY BUTTON--------------------
zathorix 18:aa6feb4b73e7 348 if (fly_button == 0 && fly_request == false) {
zathorix 18:aa6feb4b73e7 349 fly_request = true;
zathorix 18:aa6feb4b73e7 350 if (velocity > MIN_FLY_VELOCITY) fly_request = !fly_request;
zathorix 18:aa6feb4b73e7 351 } else if (fly_button == 1) fly_request = false;
zathorix 18:aa6feb4b73e7 352
zathorix 18:aa6feb4b73e7 353 //return for menu
zathorix 18:aa6feb4b73e7 354 return current_menu;
zathorix 18:aa6feb4b73e7 355 }
zathorix 18:aa6feb4b73e7 356
zathorix 22:8fdbdfbdf74a 357 //power_out is now power_in minus power_out, can only fix
zathorix 18:aa6feb4b73e7 358 void readEssentials()
zathorix 18:aa6feb4b73e7 359 {
zathorix 18:aa6feb4b73e7 360
zathorix 18:aa6feb4b73e7 361 //get current throttle set + adjust params -------- DEBUG
zathorix 22:8fdbdfbdf74a 362 throttle_power = 100*speed;
zathorix 22:8fdbdfbdf74a 363 power_out = (int) ((battery->current) * (battery->voltage));
zathorix 18:aa6feb4b73e7 364 power_in = 680;
zathorix 22:8fdbdfbdf74a 365 velocity = (int) (3.6*sqrt((velocitysqrd->value))); //velocity in kph
zathorix 18:aa6feb4b73e7 366 battery_minutes_left = throttle_power/6;
zathorix 22:8fdbdfbdf74a 367 battery_percentage_left = battery->SOC;
zathorix 22:8fdbdfbdf74a 368 motor_temperature = (int) (motortemp->value);
zathorix 22:8fdbdfbdf74a 369 battery_temperature = (int) (battery->maxtemp);
zathorix 22:8fdbdfbdf74a 370 battery_voltage = (int) (battery->voltage);
zathorix 18:aa6feb4b73e7 371 rpm_motor = throttle_power;
zathorix 23:970a5603da43 372 //voltage_in = 44;
zathorix 23:970a5603da43 373 //race_minutes_left = 12;
zathorix 18:aa6feb4b73e7 374 race_percentage_left = 100*race_minutes_done/(race_minutes_left+race_minutes_done);
zathorix 18:aa6feb4b73e7 375 }