![](/media/cache/profiles/0df840aed5f513a02964d0c27bc4f277.jpg.50x50_q85.jpg)
Attempts to merge SPI_TFT2 & SPI_TFT_ILI9341
Dependencies: SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed
Fork of CANary by
main.cpp@176:9c19f9856c76, 2014-02-17 (annotated)
- Committer:
- TickTock
- Date:
- Mon Feb 17 02:39:54 2014 +0000
- Revision:
- 176:9c19f9856c76
- Parent:
- 175:0357b4159b40
- Child:
- 177:6fda79c2fda1
// Added to the temperature lookup table; // Fixed div0 boundary condition bug in CP histogram; // Splash trip meter on second screen when turned off if showHealth is enabled; // Max and min efficiency computed over 24 hour interval (to get roundtrip ef
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TickTock | 13:62e0f7f39ff5 | 1 | // main.cpp |
TickTock | 108:29b5a760adc2 | 2 | // |
TickTock | 4:8d7759f4fe7a | 3 | //To Do: |
TickTock | 166:ec3951ba9701 | 4 | // * Fix USB hot plug (must reset every time USB plugged) |
TickTock | 33:a277743ebdeb | 5 | // * Add 50% charge option |
TickTock | 152:a4d66901785d | 6 | // * Add linear efficiency graph with 10 minute values |
TickTock | 146:88f7bda79d8e | 7 | // * Add in-device config editor |
TickTock | 149:e9739523109f | 8 | // * Change pack volt color when CVLI fails |
TickTock | 149:e9739523109f | 9 | // * Add tire pressure cal (40psi for me = FR 38, RR 38.2, FL 37.8, RL 38 - maybe 2psi error on my tire gauge?) |
TickTock | 164:46ed06263b0e | 10 | // * Add on screen messages for heater on, etc, and use refresh feature above to clear in x seconds |
TickTock | 169:84d790ac18a2 | 11 | // * Be more efficient with write buffer (use msgLen instead of always storing 8 bytes) |
TickTock | 176:9c19f9856c76 | 12 | // * Base best and worse case on full round trip (per charge efficiency) |
TickTock | 157:1a100a5ed06f | 13 | |
TickTock | 175:0357b4159b40 | 14 | // rev175 |
TickTock | 175:0357b4159b40 | 15 | // Added to the temperature lookup table |
TickTock | 175:0357b4159b40 | 16 | // Fixed div0 boundary condition bug in CP histogram |
TickTock | 175:0357b4159b40 | 17 | // Splash trip meter on second screen when turned off if showHealth is enabled |
TickTock | 176:9c19f9856c76 | 18 | // Max and min efficiency computed over 24 hour interval (to get roundtrip efficiency) |
TickTock | 134:ad243e4f1a17 | 19 | |
TickTock | 12:8e42d7ba8468 | 20 | #include "mbed.h" |
TickTock | 12:8e42d7ba8468 | 21 | #include "CAN.h" |
TickTock | 109:3e6f0e8fca0d | 22 | #include "ff.h" |
TickTock | 12:8e42d7ba8468 | 23 | #include "PowerControl.h" |
TickTock | 12:8e42d7ba8468 | 24 | #include "EthernetPowerControl.h" |
TickTock | 12:8e42d7ba8468 | 25 | #include "utility.h" |
TickTock | 12:8e42d7ba8468 | 26 | #include "displayModes.h" |
TickTock | 23:cd03f9c3395e | 27 | #include "TOUCH_TFTx2.h" |
TickTock | 172:53548bf8bf85 | 28 | |
TickTock | 175:0357b4159b40 | 29 | char revStr[7] = "175"; |
TickTock | 170:7ee98e3611bc | 30 | unsigned long maxTarget = 1000; |
TickTock | 109:3e6f0e8fca0d | 31 | FATFS USBdrive; |
TickTock | 13:62e0f7f39ff5 | 32 | LocalFileSystem local("local"); |
TickTock | 115:549410af477d | 33 | unsigned char wait5secs = 5; |
TickTock | 13:62e0f7f39ff5 | 34 | // to write to USB Flash Drives, or equivalent (SD card in Reader/Writer) |
TickTock | 119:0e2b641e98a2 | 35 | // class10 SDcard in Reader/Writer recommended |
TickTock | 111:d1559bb25c43 | 36 | FRESULT mfr = f_mount(0,&USBdrive); |
TickTock | 13:62e0f7f39ff5 | 37 | time_t seconds ; |
TickTock | 13:62e0f7f39ff5 | 38 | |
TickTock | 36:dbd39c315258 | 39 | Ticker autoPoll; |
TickTock | 36:dbd39c315258 | 40 | Ticker playback; |
TickTock | 78:a383971fe02f | 41 | Ticker msgReq; |
TickTock | 140:ab3e94eb0227 | 42 | Ticker geiger; |
TickTock | 13:62e0f7f39ff5 | 43 | Timer timer; |
TickTock | 13:62e0f7f39ff5 | 44 | |
TickTock | 13:62e0f7f39ff5 | 45 | DigitalOut led1(LED1); |
TickTock | 13:62e0f7f39ff5 | 46 | DigitalOut led2(LED2); |
TickTock | 13:62e0f7f39ff5 | 47 | DigitalOut led3(LED3); |
TickTock | 13:62e0f7f39ff5 | 48 | DigitalOut led4(LED4); |
TickTock | 13:62e0f7f39ff5 | 49 | |
TickTock | 13:62e0f7f39ff5 | 50 | InterruptIn touchpad(p17); |
TickTock | 13:62e0f7f39ff5 | 51 | CAN can1(p9, p10); // CAN1 (EV) uses pins 9 and 10 (rx, tx) and pin 8 (rs) |
TickTock | 13:62e0f7f39ff5 | 52 | DigitalOut can1SleepMode(p8); // Use pin 8 to control the sleep mode of can2 |
TickTock | 13:62e0f7f39ff5 | 53 | CAN can2(p30, p29); // CAN2 (CAR) uses pins 30 and 29 (rx, tx) and pin 28 (rs) |
TickTock | 13:62e0f7f39ff5 | 54 | DigitalOut can2SleepMode(p28); // Use pin 28 to control the sleep mode of can1 |
TickTock | 35:5acbd8a64a89 | 55 | AnalogIn mon12V(p15); |
TickTock | 13:62e0f7f39ff5 | 56 | TOUCH_TFTx2 tt(p16, p17, p19, p20, p11, p12, p13, p6, p7, p5, "TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs0, cs1, reset |
TickTock | 35:5acbd8a64a89 | 57 | PwmOut dled(p23); |
TickTock | 155:f31006516956 | 58 | PwmOut spkr(p21); |
TickTock | 13:62e0f7f39ff5 | 59 | |
garygid | 87:46ac3f2519d6 | 60 | bool debugMode = false; |
TickTock | 108:29b5a760adc2 | 61 | bool usbEn = false; |
TickTock | 131:0d926c080a65 | 62 | bool logEn = false; |
TickTock | 108:29b5a760adc2 | 63 | bool logOpen = false; |
TickTock | 115:549410af477d | 64 | bool yesBattLog = true; // gg - Batt Log |
TickTock | 108:29b5a760adc2 | 65 | unsigned char tNavRow = 3; // gg - 4x4 touch |
TickTock | 140:ab3e94eb0227 | 66 | bool brakeMon = false; // disable until desired value read from config |
TickTock | 155:f31006516956 | 67 | bool regenMon = false; |
TickTock | 159:577e9d015693 | 68 | bool heaterMon = false; |
TickTock | 152:a4d66901785d | 69 | bool autoSync = false; // auto clock sync on powerup |
TickTock | 152:a4d66901785d | 70 | bool syncDone = true; |
TickTock | 159:577e9d015693 | 71 | bool heaterOn = false; |
TickTock | 159:577e9d015693 | 72 | bool lHeaterOn = false; |
TickTock | 164:46ed06263b0e | 73 | bool CCon = false; |
TickTock | 164:46ed06263b0e | 74 | bool lCCon = false; |
garygid | 54:6ce808d0995e | 75 | |
TickTock | 109:3e6f0e8fca0d | 76 | FILE *hfile; // history file |
TickTock | 109:3e6f0e8fca0d | 77 | FIL efile; // external usb file |
TickTock | 109:3e6f0e8fca0d | 78 | FRESULT efr; // external file access flags |
TickTock | 109:3e6f0e8fca0d | 79 | unsigned int bytesRW; |
TickTock | 108:29b5a760adc2 | 80 | char fileName[35] = ""; |
TickTock | 84:fd21e5d32dab | 81 | char writeBuffer[maxBufLen][13] __attribute__ ((section("AHBSRAM1"))); // buffer for USB write |
TickTock | 13:62e0f7f39ff5 | 82 | char indexLastMsg[0x800]={0}; // index table for last message |
TickTock | 13:62e0f7f39ff5 | 83 | CANMessage lastMsg[100]; // table to store last message of eachtype |
garygid | 87:46ac3f2519d6 | 84 | |
TickTock | 124:0d622967b764 | 85 | unsigned char battData[BatDataBufMax]={0}; // 7 * 0x3D = BatDataBufMax |
garygid | 87:46ac3f2519d6 | 86 | |
TickTock | 13:62e0f7f39ff5 | 87 | unsigned char msgChanged[100]; // inidcates which bytes changed |
TickTock | 13:62e0f7f39ff5 | 88 | char c; |
TickTock | 76:fb6779d0963e | 89 | volatile int writePointer = 0; |
TickTock | 76:fb6779d0963e | 90 | int readPointer=0; |
TickTock | 141:cf13a632ddb5 | 91 | volatile unsigned short secsNoCarCanMsg = canTimeout; |
TickTock | 141:cf13a632ddb5 | 92 | volatile unsigned short secsNoEvCanMsg = canTimeout; |
TickTock | 75:77bd26829dca | 93 | volatile unsigned short secsNoTouch = 0; |
TickTock | 132:08748a67280a | 94 | volatile bool carCanIdle,evCanIdle,userIdle; |
TickTock | 26:462ccb580472 | 95 | bool touched=false; //flag to read touchscreen |
TickTock | 42:4533b13b297d | 96 | unsigned char whichTouched = 0; |
TickTock | 13:62e0f7f39ff5 | 97 | char counter = 0; |
TickTock | 41:8d4609ea7259 | 98 | unsigned char dMode[2] = {mainScreen,brakeScreen}; //display mode |
TickTock | 13:62e0f7f39ff5 | 99 | unsigned char sMode = 0; // setup mode |
TickTock | 13:62e0f7f39ff5 | 100 | unsigned char lastDMode[2] = {0,0}; //last screen mode |
TickTock | 131:0d926c080a65 | 101 | unsigned char dtMode = 0; |
TickTock | 13:62e0f7f39ff5 | 102 | char displayLog[20][40]; |
TickTock | 13:62e0f7f39ff5 | 103 | unsigned char displayLoc = 0; |
leafman | 98:9f8bab96edff | 104 | unsigned int fwCount=1; |
TickTock | 13:62e0f7f39ff5 | 105 | unsigned char indexOffset = 1; |
TickTock | 13:62e0f7f39ff5 | 106 | bool showCP = false; |
TickTock | 39:eef8beac7411 | 107 | bool logCP = false; //Turbo3 |
TickTock | 108:29b5a760adc2 | 108 | bool logOnce = false; |
TickTock | 103:1389e9efe8c3 | 109 | bool repeatPoll = true; |
TickTock | 34:4751a8259b18 | 110 | bool headlights = false; |
TickTock | 140:ab3e94eb0227 | 111 | bool miles_kmbar = true; |
TickTock | 34:4751a8259b18 | 112 | bool tick = false; |
garygid | 69:6bfdfc002036 | 113 | bool ZeroSecTick = false; |
TickTock | 35:5acbd8a64a89 | 114 | float ledHi = 0.8; // Bright LED value (until config file read) |
TickTock | 35:5acbd8a64a89 | 115 | float ledLo = 0.1; // Dim LED value (until config file read) |
TickTock | 35:5acbd8a64a89 | 116 | unsigned short pollInt = 300; // polling interval=5 minutes (until config file read) |
TickTock | 35:5acbd8a64a89 | 117 | bool accOn = false; // Accessories on |
TickTock | 49:a3d2c5bb3cfa | 118 | bool laccOn = false; |
TickTock | 35:5acbd8a64a89 | 119 | float scale12V = 16.2; // R1:R2 ratio |
TickTock | 170:7ee98e3611bc | 120 | float kWperGid = 0.080; |
TickTock | 170:7ee98e3611bc | 121 | unsigned short startGids = 0; // Gids at start of trip |
TickTock | 172:53548bf8bf85 | 122 | bool getGids = false; |
TickTock | 40:0e6e71a7323f | 123 | signed long mWs_x4 = 0; |
TickTock | 40:0e6e71a7323f | 124 | unsigned short numWsamples = 0; |
TickTock | 41:8d4609ea7259 | 125 | unsigned short numSsamples = 0; |
TickTock | 35:5acbd8a64a89 | 126 | float accV = 0; |
TickTock | 143:88b5155622a5 | 127 | float accV2 = 0; |
TickTock | 161:71ac85d11f03 | 128 | float CCkW = 0; |
TickTock | 36:dbd39c315258 | 129 | bool playbackEn = false; |
TickTock | 36:dbd39c315258 | 130 | bool playbackOpen = false; |
TickTock | 49:a3d2c5bb3cfa | 131 | //float playbackInt = 0.05; //read messages every 50 ms |
TickTock | 78:a383971fe02f | 132 | float playbackInt = 0.005; //read messages every 5 ms |
TickTock | 36:dbd39c315258 | 133 | bool step = false; |
TickTock | 37:fea2c1d52c5f | 134 | char header[5]; |
TickTock | 36:dbd39c315258 | 135 | char data[8]; |
TickTock | 174:cd27e80f197d | 136 | signed long motorRPM; |
garygid | 65:821fc79cd7fe | 137 | unsigned char skin = ttSkin ; |
TickTock | 50:83d5864c64a0 | 138 | unsigned char dtePeriod = 14; //ten minute averaging interval |
TickTock | 176:9c19f9856c76 | 139 | float CCkWh_trip[4]={0}; |
TickTock | 176:9c19f9856c76 | 140 | float kWh_trip[4]={0}; |
TickTock | 176:9c19f9856c76 | 141 | float miles_trip[4]={0}; |
TickTock | 144:b0c9d30dd346 | 142 | float curEff = 0; |
TickTock | 158:059abeb44ba1 | 143 | float maxTripEff = 0; |
TickTock | 158:059abeb44ba1 | 144 | float minTripEff = 5; |
TickTock | 167:58d4edf403d4 | 145 | float maxTripMiles = 0; |
TickTock | 167:58d4edf403d4 | 146 | float maxTripkWh = 1; |
TickTock | 167:58d4edf403d4 | 147 | float maxTripCCkWh = 0; |
TickTock | 167:58d4edf403d4 | 148 | float minTripMiles = 5; |
TickTock | 167:58d4edf403d4 | 149 | float minTripkWh = 1; |
TickTock | 167:58d4edf403d4 | 150 | float minTripCCkWh = 0; |
TickTock | 49:a3d2c5bb3cfa | 151 | float mph[39]={0}; |
TickTock | 49:a3d2c5bb3cfa | 152 | float kW[39]={0}; |
TickTock | 49:a3d2c5bb3cfa | 153 | float mpkWh[39]={0}; |
TickTock | 162:c6545fc0164a | 154 | float mpkWh_noCC=0; |
TickTock | 120:041edeec08f5 | 155 | float unloadedV_x2,Resr,curRmax,curRmin,redRmax,redRmin,incRmax,incRmin; |
TickTock | 121:553faf139a20 | 156 | signed short Imax, Imin; |
TickTock | 49:a3d2c5bb3cfa | 157 | // Logarithmic division scale (roughly - snapped to common units of time) |
TickTock | 49:a3d2c5bb3cfa | 158 | float timeConstant[39] = {1, 1.58, 2.51, 3.98, 6.31, 10, 15.8, 25.1, 39.8, 60, // 1 minute |
TickTock | 52:d5385fbf4ea1 | 159 | 60*1.58, 60*2.51, 60*3.98, 60*6.31, 60*10, 60*15.8, 60*25.1, 60*39.8, 60*60, // 1 hour |
TickTock | 52:d5385fbf4ea1 | 160 | 60*60*1.58, 60*60*2.51, 60*60*3.98, 60*60*6.31, 60*60*10, 60*60*15.8, 60*60*24, // 1 day |
TickTock | 52:d5385fbf4ea1 | 161 | 60*60*24*1.58, 60*60*24*2.51, 60*60*24*3.98, 60*60*24*6.31, 60*60*24*10, 60*60*24*15.8, 60*60*24*30, // 1 month |
TickTock | 52:d5385fbf4ea1 | 162 | 60*60*24*39.8, 60*60*24*63.1, 60*60*24*100, 60*60*24*158, 60*60*24*251, 60*60*24*365}; // 1 year |
TickTock | 121:553faf139a20 | 163 | bool tock = false; |
TickTock | 73:62ee8eae3a84 | 164 | unsigned short pointerSep; |
TickTock | 78:a383971fe02f | 165 | unsigned char reqMsgCnt = 99; |
TickTock | 102:fd19f777a0b4 | 166 | unsigned long Ah_x10000 = 0; |
TickTock | 102:fd19f777a0b4 | 167 | unsigned long SOC_x10000 = 0; |
TickTock | 143:88b5155622a5 | 168 | unsigned short SOH2_x100 = 0; |
TickTock | 108:29b5a760adc2 | 169 | float maxTemp = 0; |
leafman | 98:9f8bab96edff | 170 | bool metric = false; |
TickTock | 121:553faf139a20 | 171 | bool shunt[96]={0}; |
TickTock | 121:553faf139a20 | 172 | bool charging=false; |
TickTock | 131:0d926c080a65 | 173 | bool showHealth=false; |
TickTock | 175:0357b4159b40 | 174 | unsigned char saveDmode[2] = {99, 99}; |
TickTock | 131:0d926c080a65 | 175 | bool moving=false; |
TickTock | 140:ab3e94eb0227 | 176 | unsigned short chirpInt; |
TickTock | 150:ef46ce63345c | 177 | unsigned short uMsgId[8] = {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000}; // messages to display on debug screen msgId:byte |
TickTock | 152:a4d66901785d | 178 | unsigned short modelYear = 2011; |
TickTock | 153:e94cfe3c339c | 179 | bool idir, lidir; |
TickTock | 154:90ea16ca7475 | 180 | bool enableSound=false; |
TickTock | 158:059abeb44ba1 | 181 | bool clearTest=true; |
TickTock | 171:355e284f5201 | 182 | unsigned long tbScalar = 72464; |
TickTock | 171:355e284f5201 | 183 | unsigned long rbScalar = 8696; |
TickTock | 171:355e284f5201 | 184 | unsigned long fbScalar = 132; |
TickTock | 13:62e0f7f39ff5 | 185 | |
TickTock | 0:1596b8644523 | 186 | int main() { |
TickTock | 4:8d7759f4fe7a | 187 | char sTemp[40]; |
TickTock | 2:71b1999a8ea5 | 188 | unsigned long secs; |
TickTock | 49:a3d2c5bb3cfa | 189 | unsigned char i,j,display=0,lwt=0; |
TickTock | 22:a43df3905863 | 190 | point lastTouch; |
TickTock | 52:d5385fbf4ea1 | 191 | float average; |
TickTock | 3:3e879b043bc5 | 192 | tt.set_orientation(1); |
TickTock | 4:8d7759f4fe7a | 193 | tt.background(Black); |
TickTock | 19:d576298c46f3 | 194 | tt.set_display(2); // select both displays |
TickTock | 3:3e879b043bc5 | 195 | tt.cls(); |
TickTock | 137:70853cf5a30f | 196 | tt.foreground(White); |
TickTock | 137:70853cf5a30f | 197 | tt.set_font((unsigned char*) Arial12x12_prop); // select the font |
TickTock | 137:70853cf5a30f | 198 | tt.locate(0,0); |
TickTock | 1:9dcd70c32180 | 199 | tt.claim(stdout); // send stdout to the TFT display |
TickTock | 137:70853cf5a30f | 200 | if(tt.is_touched()){ // If touching screen on poweron then update firmware |
TickTock | 137:70853cf5a30f | 201 | updateFirmware(); |
TickTock | 137:70853cf5a30f | 202 | } |
TickTock | 12:8e42d7ba8468 | 203 | touchpad.rise(&touch_ISR); |
TickTock | 4:8d7759f4fe7a | 204 | tt.wfi(); // enable interrupt on touch |
TickTock | 155:f31006516956 | 205 | dled.period(0.001); |
TickTock | 154:90ea16ca7475 | 206 | dled = ledHi; // turn on display LED 80% |
TickTock | 155:f31006516956 | 207 | spkr = 0; |
TickTock | 120:041edeec08f5 | 208 | Resr = 0.075; // initial guess of Resr |
TickTock | 2:71b1999a8ea5 | 209 | timer.start() ; |
TickTock | 2:71b1999a8ea5 | 210 | RTC_Init(); // start the RTC Interrupts that sync the timer |
TickTock | 176:9c19f9856c76 | 211 | struct tm t,lt; // pointer to a static tm structure |
TickTock | 93:c2402e8cd0e2 | 212 | NVIC_SetPriority(CAN_IRQn, 2); //set can priority just below RTC |
TickTock | 117:49883c779a74 | 213 | NVIC_SetPriority(TIMER3_IRQn, 3); //set ticker priority just below can |
TickTock | 33:a277743ebdeb | 214 | |
TickTock | 1:9dcd70c32180 | 215 | seconds = time(NULL); |
TickTock | 1:9dcd70c32180 | 216 | t = *localtime(&seconds) ; |
TickTock | 1:9dcd70c32180 | 217 | // is it a date before 2012 ? |
TickTock | 26:462ccb580472 | 218 | if ((t.tm_year + 1900) < 2012 ) { |
TickTock | 26:462ccb580472 | 219 | // before 2013 so update year to make date entry easier |
TickTock | 26:462ccb580472 | 220 | t.tm_year = 2013 - 1900; |
TickTock | 1:9dcd70c32180 | 221 | // set the RTC |
TickTock | 1:9dcd70c32180 | 222 | set_time(mktime(&t)); |
TickTock | 1:9dcd70c32180 | 223 | seconds = time(NULL); |
TickTock | 26:462ccb580472 | 224 | } |
TickTock | 20:3bf176d14b14 | 225 | t = *localtime(&seconds) ; |
TickTock | 20:3bf176d14b14 | 226 | strftime(sTemp, 32, "%a %m/%d/%Y %X\n", &t); |
TickTock | 93:c2402e8cd0e2 | 227 | printMsg(sTemp); // record RTC |
garygid | 54:6ce808d0995e | 228 | |
TickTock | 62:ffd15edb5431 | 229 | // revision |
garygid | 70:0700b769ac15 | 230 | sprintf(sTemp,"CANary firmware rev%s\n", revStr); // gg - for Logging the revision |
TickTock | 93:c2402e8cd0e2 | 231 | printMsg(sTemp); // revision |
TickTock | 17:e32324a2678d | 232 | |
TickTock | 49:a3d2c5bb3cfa | 233 | //read efficiency history data |
TickTock | 150:ef46ce63345c | 234 | hfile = fopen("/local/ehist.cny", "r"); |
TickTock | 97:a25940fd7b5b | 235 | if (hfile!=NULL){ // found a efficiency history file |
TickTock | 49:a3d2c5bb3cfa | 236 | for(i=0;i<39;i++){ |
TickTock | 97:a25940fd7b5b | 237 | if(!feof(hfile)){ |
TickTock | 97:a25940fd7b5b | 238 | fscanf(hfile,"%f %f\r\n",&mph[i],&kW[i]); |
TickTock | 49:a3d2c5bb3cfa | 239 | mpkWh[i]=mph[i]/kW[i]; |
TickTock | 166:ec3951ba9701 | 240 | if(i==dtePeriod) mpkWh_noCC=mpkWh[i]; |
TickTock | 49:a3d2c5bb3cfa | 241 | } |
TickTock | 49:a3d2c5bb3cfa | 242 | } |
TickTock | 134:ad243e4f1a17 | 243 | if(!feof(hfile)){ |
TickTock | 134:ad243e4f1a17 | 244 | fscanf(hfile,"%f %f\r\n",&maxTripEff,&minTripEff); |
TickTock | 134:ad243e4f1a17 | 245 | } |
TickTock | 155:f31006516956 | 246 | if(!feof(hfile)){ |
TickTock | 155:f31006516956 | 247 | fscanf(hfile,"%f\r\n",&Resr); |
TickTock | 155:f31006516956 | 248 | } |
TickTock | 167:58d4edf403d4 | 249 | if(!feof(hfile)){ |
TickTock | 167:58d4edf403d4 | 250 | fscanf(hfile,"%f %f\r\n",&maxTripMiles,&minTripMiles); |
TickTock | 167:58d4edf403d4 | 251 | } |
TickTock | 167:58d4edf403d4 | 252 | if(!feof(hfile)){ |
TickTock | 167:58d4edf403d4 | 253 | fscanf(hfile,"%f %f\r\n",&maxTripkWh,&minTripkWh); |
TickTock | 167:58d4edf403d4 | 254 | } |
TickTock | 167:58d4edf403d4 | 255 | if(!feof(hfile)){ |
TickTock | 167:58d4edf403d4 | 256 | fscanf(hfile,"%f %f\r\n",&maxTripCCkWh,&minTripCCkWh); |
TickTock | 167:58d4edf403d4 | 257 | } |
TickTock | 97:a25940fd7b5b | 258 | fclose(hfile); |
TickTock | 116:5cd72bae7c12 | 259 | printMsg("History Loaded.\n"); // History loaded |
TickTock | 49:a3d2c5bb3cfa | 260 | } else { // create initial file |
TickTock | 116:5cd72bae7c12 | 261 | printMsg("History not found. Created.\n"); // history not found, created |
TickTock | 49:a3d2c5bb3cfa | 262 | for(i=0;i<39;i++){ |
TickTock | 49:a3d2c5bb3cfa | 263 | // Pre-load with 4 mpkWh @ 40 mph |
TickTock | 49:a3d2c5bb3cfa | 264 | mph[i]=40*timeConstant[i]; |
TickTock | 49:a3d2c5bb3cfa | 265 | kW[i]=10*timeConstant[i]; |
TickTock | 49:a3d2c5bb3cfa | 266 | mpkWh[i]=4; |
TickTock | 49:a3d2c5bb3cfa | 267 | } |
TickTock | 49:a3d2c5bb3cfa | 268 | } |
TickTock | 49:a3d2c5bb3cfa | 269 | |
TickTock | 46:73e8716f976f | 270 | // Read config file |
TickTock | 46:73e8716f976f | 271 | readConfig(); |
TickTock | 140:ab3e94eb0227 | 272 | if (brakeMon){ |
TickTock | 140:ab3e94eb0227 | 273 | geiger.attach(&chirp,0.02); |
TickTock | 140:ab3e94eb0227 | 274 | } |
TickTock | 108:29b5a760adc2 | 275 | if (repeatPoll) { // enable autopolling if enabled |
TickTock | 108:29b5a760adc2 | 276 | autoPoll.attach(&autoPollISR,pollInt); |
TickTock | 108:29b5a760adc2 | 277 | } |
TickTock | 108:29b5a760adc2 | 278 | |
TickTock | 77:7c136766466c | 279 | // Start monitors |
TickTock | 77:7c136766466c | 280 | can1.monitor(true); // set to snoop mode |
TickTock | 77:7c136766466c | 281 | can2.monitor(true); // set to snoop mode |
TickTock | 77:7c136766466c | 282 | can1.frequency(500000); |
TickTock | 77:7c136766466c | 283 | can2.frequency(500000); |
TickTock | 120:041edeec08f5 | 284 | can1SleepMode = VP230Sleep; // Turn on Monitor_only Mode |
TickTock | 120:041edeec08f5 | 285 | can2SleepMode = VP230Sleep; // Turn on Monitor_only Mode |
TickTock | 77:7c136766466c | 286 | can1.attach(&recieve1); |
TickTock | 77:7c136766466c | 287 | can2.attach(&recieve2); |
TickTock | 77:7c136766466c | 288 | |
TickTock | 26:462ccb580472 | 289 | touched=false; |
TickTock | 26:462ccb580472 | 290 | secsNoTouch=2; |
TickTock | 2:71b1999a8ea5 | 291 | while (true) { |
TickTock | 4:8d7759f4fe7a | 292 | if (!logOpen) { // Open new file if one is not already open |
TickTock | 131:0d926c080a65 | 293 | if(logEn&&usbEn){ //logging enabled and USB device detected |
TickTock | 109:3e6f0e8fca0d | 294 | strftime(fileName, 32, "%m%d%H%M.alc", &t); //mmddhhmm.alc |
TickTock | 109:3e6f0e8fca0d | 295 | efr = f_open(&efile,fileName,FA_WRITE|FA_OPEN_ALWAYS); |
TickTock | 7:17bf9ceaf0aa | 296 | seconds = time(NULL); |
TickTock | 7:17bf9ceaf0aa | 297 | t = *localtime(&seconds) ; |
TickTock | 94:c3a14b3975d6 | 298 | lastDMode[0]=99;//force refresh |
TickTock | 94:c3a14b3975d6 | 299 | lastDMode[1]=99;//force refresh |
TickTock | 109:3e6f0e8fca0d | 300 | if(efr != FR_OK){ |
TickTock | 109:3e6f0e8fca0d | 301 | sprintf(sTemp,"\nERR:%d Unable to open %s\n\n\n\n",efr,fileName); |
TickTock | 93:c2402e8cd0e2 | 302 | printMsg(sTemp); // cannot open alc file |
TickTock | 7:17bf9ceaf0aa | 303 | logEn=false; |
TickTock | 155:f31006516956 | 304 | beep(1000,0.25); |
TickTock | 109:3e6f0e8fca0d | 305 | wait_ms(500); |
TickTock | 155:f31006516956 | 306 | beep(1000,0.25); |
TickTock | 7:17bf9ceaf0aa | 307 | } else { |
TickTock | 7:17bf9ceaf0aa | 308 | logOpen = true; |
TickTock | 7:17bf9ceaf0aa | 309 | readPointer=writePointer; |
TickTock | 7:17bf9ceaf0aa | 310 | sprintf(sTemp,"Starting Can Log %s\n",fileName); |
TickTock | 93:c2402e8cd0e2 | 311 | printMsg(sTemp); // starting alc log file |
garygid | 69:6bfdfc002036 | 312 | |
garygid | 69:6bfdfc002036 | 313 | logTS(); // Date Time at start |
TickTock | 93:c2402e8cd0e2 | 314 | logEvent("Starting"); // Log startup msg for testing |
garygid | 69:6bfdfc002036 | 315 | sprintf(sTemp,"Cr%s",revStr); |
TickTock | 108:29b5a760adc2 | 316 | logEvent(sTemp); // gg - log firmware version |
TickTock | 155:f31006516956 | 317 | beep(2000,0.25); |
TickTock | 7:17bf9ceaf0aa | 318 | } |
TickTock | 108:29b5a760adc2 | 319 | }//logging enabled and USB detected |
TickTock | 15:a359fecf85ba | 320 | } else { // if (logOpen) |
TickTock | 73:62ee8eae3a84 | 321 | pointerSep=(writePointer+maxBufLen-readPointer)%maxBufLen; |
TickTock | 131:0d926c080a65 | 322 | if (pointerSep>(maxBufLen/16)||carCanIdle||!logEn) { |
TickTock | 7:17bf9ceaf0aa | 323 | // Dump buffer if > 1/16 full or canbus has stopped |
TickTock | 117:49883c779a74 | 324 | if (efr != FR_OK) { |
TickTock | 7:17bf9ceaf0aa | 325 | logOpen = false; |
TickTock | 117:49883c779a74 | 326 | printMsg("Failed to append log file.\n"); // failed to append |
TickTock | 155:f31006516956 | 327 | beep(3000,0.25); |
TickTock | 155:f31006516956 | 328 | beep(1500,0.25); |
TickTock | 155:f31006516956 | 329 | beep(750,0.25); |
TickTock | 155:f31006516956 | 330 | beep(375,0.25); |
TickTock | 7:17bf9ceaf0aa | 331 | logEn=false; |
TickTock | 7:17bf9ceaf0aa | 332 | } else { |
TickTock | 7:17bf9ceaf0aa | 333 | while (readPointer != writePointer) { |
TickTock | 117:49883c779a74 | 334 | efr=f_write(&efile,&writeBuffer[readPointer][0],13,&bytesRW); |
TickTock | 117:49883c779a74 | 335 | if(++readPointer >= maxBufLen){ |
TickTock | 117:49883c779a74 | 336 | readPointer=0; |
TickTock | 117:49883c779a74 | 337 | led4 = !led4; |
TickTock | 4:8d7759f4fe7a | 338 | } |
TickTock | 4:8d7759f4fe7a | 339 | } |
TickTock | 7:17bf9ceaf0aa | 340 | } |
TickTock | 30:e633a63eb257 | 341 | } // if > 1/16 full, canbus has stopped, or logging stopped |
TickTock | 30:e633a63eb257 | 342 | if (!logEn) { |
TickTock | 77:7c136766466c | 343 | sprintf(sTemp,"Stopping Can Log %s\n",fileName); |
TickTock | 93:c2402e8cd0e2 | 344 | printMsg(sTemp); // stopping alc log file |
TickTock | 109:3e6f0e8fca0d | 345 | f_close(&efile); |
TickTock | 30:e633a63eb257 | 346 | logOpen=false; |
TickTock | 77:7c136766466c | 347 | pointerSep=0; |
TickTock | 108:29b5a760adc2 | 348 | led4=false; |
TickTock | 30:e633a63eb257 | 349 | } |
TickTock | 4:8d7759f4fe7a | 350 | } // if logOpen |
TickTock | 132:08748a67280a | 351 | if (carCanIdle && (evCanIdle || !logOpen) && userIdle && !playbackEn) { // canbus idle --> sleep to save power |
TickTock | 95:248b3c25a7df | 352 | if (repeatPoll) { // stop autopolling if enabled |
TickTock | 95:248b3c25a7df | 353 | autoPoll.detach(); |
TickTock | 95:248b3c25a7df | 354 | } |
TickTock | 111:d1559bb25c43 | 355 | if (logOpen){ //close file to dump buffer |
TickTock | 111:d1559bb25c43 | 356 | f_close(&efile); |
TickTock | 134:ad243e4f1a17 | 357 | } else { //detach EVcan so only carcan will trigger wake |
TickTock | 134:ad243e4f1a17 | 358 | can1.attach(NULL); |
TickTock | 134:ad243e4f1a17 | 359 | }// if (logOpen) |
TickTock | 20:3bf176d14b14 | 360 | seconds = time(NULL); |
TickTock | 20:3bf176d14b14 | 361 | t = *localtime(&seconds) ; |
TickTock | 21:22bdce9efcb5 | 362 | strftime(sTemp, 40, "Sleeping: %a %m/%d/%Y %X\n", &t); |
TickTock | 93:c2402e8cd0e2 | 363 | printMsg(sTemp); // sleeping date time |
TickTock | 25:ddf0ec209f03 | 364 | updateDisplay(0); //Added for turbo3 who has a display override and wants to see the sleep message before going to sleep |
TickTock | 25:ddf0ec209f03 | 365 | updateDisplay(1); |
TickTock | 4:8d7759f4fe7a | 366 | //LPC_RTC->CIIR=0x00; // block RTC interrupts |
TickTock | 4:8d7759f4fe7a | 367 | led1=0; |
TickTock | 4:8d7759f4fe7a | 368 | led2=0; |
TickTock | 4:8d7759f4fe7a | 369 | led3=0; |
TickTock | 4:8d7759f4fe7a | 370 | led4=0; |
TickTock | 4:8d7759f4fe7a | 371 | dled=0; // turn off display |
TickTock | 4:8d7759f4fe7a | 372 | secs = time(NULL); // seconds past 12:00:00 AM 1 Jan 1900 |
TickTock | 132:08748a67280a | 373 | while (secsNoCarCanMsg>canTimeout && (secsNoEvCanMsg>canTimeout || !logOpen) && !touched) { |
TickTock | 4:8d7759f4fe7a | 374 | //DeepPowerDown(); |
TickTock | 12:8e42d7ba8468 | 375 | tt.wfi(); //enable touch interrupt |
TickTock | 21:22bdce9efcb5 | 376 | //__wfi(); // freeze CPU and wait for interrupt (from canbus or touch) |
TickTock | 21:22bdce9efcb5 | 377 | Sleep(); |
TickTock | 4:8d7759f4fe7a | 378 | } |
TickTock | 135:89986950d501 | 379 | if (!logOpen){ // Re-attach EVcan |
TickTock | 134:ad243e4f1a17 | 380 | can1.attach(&recieve1); |
TickTock | 134:ad243e4f1a17 | 381 | } |
TickTock | 43:e7f6f80590e3 | 382 | secsNoTouch=2; |
TickTock | 131:0d926c080a65 | 383 | carCanIdle=secsNoCarCanMsg>canTimeout; |
TickTock | 132:08748a67280a | 384 | evCanIdle=secsNoEvCanMsg>canTimeout; |
TickTock | 154:90ea16ca7475 | 385 | dled=ledHi; // turn on display LED |
TickTock | 20:3bf176d14b14 | 386 | seconds = time(NULL); |
TickTock | 20:3bf176d14b14 | 387 | t = *localtime(&seconds) ; |
TickTock | 21:22bdce9efcb5 | 388 | strftime(sTemp, 40, "Waking: %a %m/%d/%Y %X\n", &t); |
TickTock | 93:c2402e8cd0e2 | 389 | printMsg(sTemp); // wakeup date time |
TickTock | 4:8d7759f4fe7a | 390 | if (time(NULL)>(secs+1800)) { |
TickTock | 110:ffddff3ad2f2 | 391 | if (logOpen){ |
TickTock | 110:ffddff3ad2f2 | 392 | f_close(&efile); |
TickTock | 110:ffddff3ad2f2 | 393 | logOpen = false; // Start new file if asleep for more than 30 minutes |
TickTock | 110:ffddff3ad2f2 | 394 | } // if (logOpen) |
TickTock | 4:8d7759f4fe7a | 395 | if (secsNoTouch>100) secsNoTouch = 100; // also mostly reset user Idle counter |
TickTock | 43:e7f6f80590e3 | 396 | } else if (logOpen){ // insert timestamp on each wake if logging enabled (disabled for now) |
TickTock | 111:d1559bb25c43 | 397 | efr = f_open(&efile,fileName,FA_WRITE|FA_OPEN_ALWAYS); |
TickTock | 111:d1559bb25c43 | 398 | f_lseek(&efile,0xffffffff); // goto end of file (append existing) |
TickTock | 93:c2402e8cd0e2 | 399 | logEvent("WakingUp"); // gg - use messeges |
garygid | 69:6bfdfc002036 | 400 | logTS(); // Date-Time at wakeup |
TickTock | 4:8d7759f4fe7a | 401 | } |
TickTock | 95:248b3c25a7df | 402 | if (repeatPoll) { // re-enable autopolling if enabled |
TickTock | 124:0d622967b764 | 403 | autoPoll.attach(&autoPollISR,pollInt); |
TickTock | 95:248b3c25a7df | 404 | } |
TickTock | 136:41a204105511 | 405 | wait5secs=5; // Refresh screen after 5 seconds |
TickTock | 4:8d7759f4fe7a | 406 | } // if idle |
TickTock | 4:8d7759f4fe7a | 407 | |
TickTock | 15:a359fecf85ba | 408 | if(touched){ // call touchscreen procedure if touch interrupt detected |
TickTock | 7:17bf9ceaf0aa | 409 | lastTouch = tt.get_touch(); |
TickTock | 7:17bf9ceaf0aa | 410 | lastTouch = tt.to_pixel(lastTouch); // convert to pixel pos |
TickTock | 40:0e6e71a7323f | 411 | if((lastTouch.x!=639)&&(lastTouch.x!=319)&&(lastTouch.y!=239)){ // filter phantom touches |
TickTock | 43:e7f6f80590e3 | 412 | if (userIdle) { |
TickTock | 43:e7f6f80590e3 | 413 | secsNoTouch=2; // Ignore first touch if user idle |
TickTock | 43:e7f6f80590e3 | 414 | userIdle=false; |
TickTock | 40:0e6e71a7323f | 415 | } else { |
TickTock | 43:e7f6f80590e3 | 416 | secsNoTouch=0; |
TickTock | 40:0e6e71a7323f | 417 | } |
TickTock | 43:e7f6f80590e3 | 418 | if (lastTouch.x>320){ |
TickTock | 43:e7f6f80590e3 | 419 | whichTouched=1; |
TickTock | 43:e7f6f80590e3 | 420 | } else { |
TickTock | 43:e7f6f80590e3 | 421 | whichTouched=0; |
TickTock | 43:e7f6f80590e3 | 422 | } |
TickTock | 43:e7f6f80590e3 | 423 | if (whichTouched!=lwt){ |
TickTock | 43:e7f6f80590e3 | 424 | lastDMode[lwt]=99; // Repaint lastTouched |
TickTock | 43:e7f6f80590e3 | 425 | lwt=whichTouched; |
TickTock | 43:e7f6f80590e3 | 426 | } |
TickTock | 43:e7f6f80590e3 | 427 | sMode = 1; |
TickTock | 22:a43df3905863 | 428 | } |
TickTock | 22:a43df3905863 | 429 | //sprintf(sTemp,"%d,%d ",lastTouch.x,lastTouch.y); |
TickTock | 93:c2402e8cd0e2 | 430 | //printMsg(sTemp); // touch x,y - for debug |
TickTock | 12:8e42d7ba8468 | 431 | touched = false; // clear interrupt flag |
TickTock | 7:17bf9ceaf0aa | 432 | } |
garygid | 54:6ce808d0995e | 433 | //--------------- |
garygid | 54:6ce808d0995e | 434 | // gg - 4x4 touch |
TickTock | 62:ffd15edb5431 | 435 | //unsigned char tScrn = 0 ; // screen 0 |
garygid | 54:6ce808d0995e | 436 | unsigned char tCol ; |
garygid | 54:6ce808d0995e | 437 | unsigned char tRow ; |
garygid | 54:6ce808d0995e | 438 | |
TickTock | 4:8d7759f4fe7a | 439 | if (!userIdle) { |
TickTock | 4:8d7759f4fe7a | 440 | if (secsNoTouch<2) {// Recently touched |
TickTock | 4:8d7759f4fe7a | 441 | secsNoTouch +=2; // increment to prevent double touch |
TickTock | 43:e7f6f80590e3 | 442 | sMode = 1; |
TickTock | 22:a43df3905863 | 443 | //sprintf(sTemp,"button %d %d,%d %d\n",i,buttonX(lastTouch.x,3),buttonY(lastTouch.y,3),lastTouch.x); |
TickTock | 93:c2402e8cd0e2 | 444 | //printMsg(sTemp); // button parms - for debug |
TickTock | 23:cd03f9c3395e | 445 | switch (sMode) { |
TickTock | 23:cd03f9c3395e | 446 | case 0: // no select |
TickTock | 23:cd03f9c3395e | 447 | break; |
TickTock | 63:aa3bf6a33635 | 448 | case 1: // select screen |
garygid | 54:6ce808d0995e | 449 | //-------------- |
garygid | 54:6ce808d0995e | 450 | // gg - 4x4 touch |
garygid | 54:6ce808d0995e | 451 | tCol = buttonX(lastTouch.x,4) ; |
TickTock | 62:ffd15edb5431 | 452 | if( tCol >= 4 ){ tCol -= 4; } // touch is on screen 1 |
garygid | 54:6ce808d0995e | 453 | |
garygid | 54:6ce808d0995e | 454 | tRow = buttonY(lastTouch.y,4) ; |
garygid | 54:6ce808d0995e | 455 | |
TickTock | 63:aa3bf6a33635 | 456 | highlightButton( tCol,tRow, whichTouched, 4,4) ; // gg - highlight |
garygid | 58:4d06288d75a2 | 457 | |
TickTock | 63:aa3bf6a33635 | 458 | if( tRow == tNavRow ) tRow = 7 ; // gg |
garygid | 54:6ce808d0995e | 459 | switch ( (tCol*10) + tRow ) { |
garygid | 54:6ce808d0995e | 460 | //--------------------------------- |
garygid | 67:2022fce701d0 | 461 | case 00: // top row, left button on screen 0 or 1 |
TickTock | 42:4533b13b297d | 462 | if (dMode[whichTouched]==monitorScreen||dMode[whichTouched]==changedScreen) { |
garygid | 67:2022fce701d0 | 463 | indexOffset=indexOffset>4?indexOffset-4:1; |
garygid | 67:2022fce701d0 | 464 | } else if (dMode[whichTouched] == indexScreen) { // gg - index |
garygid | 67:2022fce701d0 | 465 | dMode[whichTouched] = mainScreen ; // GoTo Main Screen |
TickTock | 73:62ee8eae3a84 | 466 | sMode=0; |
TickTock | 157:1a100a5ed06f | 467 | } else if (dMode[whichTouched]==config2Screen) { |
TickTock | 23:cd03f9c3395e | 468 | wait_ms(500); |
TickTock | 37:fea2c1d52c5f | 469 | tt.background(Black); |
TickTock | 23:cd03f9c3395e | 470 | tt.calibrate(); |
TickTock | 42:4533b13b297d | 471 | } else if (dMode[whichTouched]==playbackScreen) { // slower |
TickTock | 36:dbd39c315258 | 472 | playbackInt *=2; |
TickTock | 36:dbd39c315258 | 473 | if(playbackEn){ |
TickTock | 36:dbd39c315258 | 474 | playback.detach(); |
TickTock | 36:dbd39c315258 | 475 | playback.attach(&playbackISR,playbackInt); |
TickTock | 36:dbd39c315258 | 476 | } |
TickTock | 62:ffd15edb5431 | 477 | } else { |
TickTock | 62:ffd15edb5431 | 478 | lastDMode[whichTouched]=99;//repaint to clear highlight |
TickTock | 23:cd03f9c3395e | 479 | } |
TickTock | 23:cd03f9c3395e | 480 | break; |
garygid | 54:6ce808d0995e | 481 | //----------------------------------------------- |
garygid | 67:2022fce701d0 | 482 | case 10: // 1,0 (col left of center,top row) on screen 0 or 1 |
TickTock | 42:4533b13b297d | 483 | if (dMode[whichTouched]==changedScreen) { |
TickTock | 23:cd03f9c3395e | 484 | for(j=0;j<100;j++) msgChanged[j]=0; // clear changed data |
TickTock | 42:4533b13b297d | 485 | lastDMode[whichTouched]=99;//force refresh |
TickTock | 169:84d790ac18a2 | 486 | sMode=0; |
garygid | 67:2022fce701d0 | 487 | } else if (dMode[whichTouched] == indexScreen) { // gg - index |
TickTock | 73:62ee8eae3a84 | 488 | sMode=0; |
garygid | 67:2022fce701d0 | 489 | dMode[whichTouched] = brakeScreen ; // GoTo Brake Screen |
TickTock | 42:4533b13b297d | 490 | } else if (dMode[whichTouched]==cpScreen) { |
TickTock | 78:a383971fe02f | 491 | reqMsgCnt=0; |
TickTock | 79:68f0dd8d1f19 | 492 | msgReq.attach(&sendReq,0.015); |
TickTock | 48:d1ce92104a1f | 493 | } else if (dMode[whichTouched]==cpHistScreen) { // gg - hist |
TickTock | 78:a383971fe02f | 494 | reqMsgCnt=0; |
TickTock | 79:68f0dd8d1f19 | 495 | msgReq.attach(&sendReq,0.015); |
TickTock | 48:d1ce92104a1f | 496 | } else if (dMode[whichTouched]==cpBarScreen) { // gg - cpbars |
TickTock | 78:a383971fe02f | 497 | reqMsgCnt=0; |
TickTock | 79:68f0dd8d1f19 | 498 | msgReq.attach(&sendReq,0.015); |
leafman | 98:9f8bab96edff | 499 | } else if (dMode[whichTouched]==configScreen) { |
TickTock | 23:cd03f9c3395e | 500 | mbed_reset(); |
TickTock | 157:1a100a5ed06f | 501 | } else if (dMode[whichTouched]==config2Screen) { // reset DTE Max/Min |
TickTock | 158:059abeb44ba1 | 502 | maxTripEff = 0; |
TickTock | 158:059abeb44ba1 | 503 | minTripEff = 5; |
TickTock | 161:71ac85d11f03 | 504 | beep(2000,0.25); |
TickTock | 42:4533b13b297d | 505 | } else if (dMode[whichTouched]==playbackScreen) { // pause/unpause |
TickTock | 36:dbd39c315258 | 506 | playbackEn=!playbackEn; |
TickTock | 36:dbd39c315258 | 507 | if(playbackEn){ |
TickTock | 36:dbd39c315258 | 508 | playback.attach(&playbackISR,playbackInt); |
TickTock | 62:ffd15edb5431 | 509 | } else { |
TickTock | 36:dbd39c315258 | 510 | playback.detach(); |
TickTock | 36:dbd39c315258 | 511 | } |
TickTock | 62:ffd15edb5431 | 512 | } else { |
TickTock | 62:ffd15edb5431 | 513 | lastDMode[whichTouched]=99;//repaint to clear highlight |
TickTock | 23:cd03f9c3395e | 514 | } |
TickTock | 62:ffd15edb5431 | 515 | |
TickTock | 23:cd03f9c3395e | 516 | break; |
garygid | 54:6ce808d0995e | 517 | //-------------------------------------- |
garygid | 54:6ce808d0995e | 518 | case 20: // col 2 and row 0 on either screen 0 or 1 |
TickTock | 42:4533b13b297d | 519 | if (dMode[whichTouched]==monitorScreen||dMode[whichTouched]==changedScreen) { |
TickTock | 23:cd03f9c3395e | 520 | indexOffset=indexOffset<77?indexOffset+4:80; |
garygid | 67:2022fce701d0 | 521 | } else if (dMode[whichTouched] == indexScreen) { // gg - index |
garygid | 67:2022fce701d0 | 522 | dMode[whichTouched] = effScreen ; // GoTo EFF Screen |
TickTock | 73:62ee8eae3a84 | 523 | sMode=0; |
leafman | 98:9f8bab96edff | 524 | } else if (dMode[whichTouched]==configScreen) { |
TickTock | 143:88b5155622a5 | 525 | dMode[whichTouched]=mainScreen; |
TickTock | 25:ddf0ec209f03 | 526 | saveConfig(); |
TickTock | 155:f31006516956 | 527 | beep(2000,0.25); |
TickTock | 169:84d790ac18a2 | 528 | //write efficiency history data |
TickTock | 169:84d790ac18a2 | 529 | hfile = fopen("/local/ehist.cny", "w"); |
TickTock | 169:84d790ac18a2 | 530 | if (hfile!=NULL){ // found a efficiency history file |
TickTock | 169:84d790ac18a2 | 531 | for(i=0;i<39;i++){ |
TickTock | 169:84d790ac18a2 | 532 | fprintf(hfile,"%f %f\r\n",mph[i],kW[i]); |
TickTock | 169:84d790ac18a2 | 533 | } |
TickTock | 169:84d790ac18a2 | 534 | fprintf(hfile,"%f %f\r\n",maxTripEff,minTripEff); // Save max and min |
TickTock | 169:84d790ac18a2 | 535 | fprintf(hfile,"%f \r\n",Resr); // Save series resistance |
TickTock | 169:84d790ac18a2 | 536 | fprintf(hfile,"%f %f\r\n",maxTripMiles,minTripMiles); // Save max and min |
TickTock | 169:84d790ac18a2 | 537 | fprintf(hfile,"%f %f\r\n",maxTripkWh,minTripkWh); // Save max and min |
TickTock | 169:84d790ac18a2 | 538 | fprintf(hfile,"%f %f\r\n",maxTripCCkWh,minTripCCkWh); // Save max and min |
TickTock | 169:84d790ac18a2 | 539 | fclose(hfile); |
TickTock | 169:84d790ac18a2 | 540 | } |
TickTock | 169:84d790ac18a2 | 541 | beep(2000,0.25); |
TickTock | 169:84d790ac18a2 | 542 | } else if (dMode[whichTouched]==config2Screen) { |
TickTock | 169:84d790ac18a2 | 543 | showHealth = !showHealth; |
TickTock | 42:4533b13b297d | 544 | } else if (dMode[whichTouched]==playbackScreen) { // faster |
TickTock | 36:dbd39c315258 | 545 | if(playbackInt>.002){ |
TickTock | 36:dbd39c315258 | 546 | playbackInt/=2; |
TickTock | 36:dbd39c315258 | 547 | if(playbackEn){ |
TickTock | 36:dbd39c315258 | 548 | playback.detach(); |
TickTock | 36:dbd39c315258 | 549 | playback.attach(&playbackISR,playbackInt); |
TickTock | 36:dbd39c315258 | 550 | } |
TickTock | 36:dbd39c315258 | 551 | } |
TickTock | 86:d1c9e8ac1c4b | 552 | } else { |
TickTock | 62:ffd15edb5431 | 553 | lastDMode[whichTouched]=99;//repaint to clear highlight |
TickTock | 23:cd03f9c3395e | 554 | } |
TickTock | 62:ffd15edb5431 | 555 | |
TickTock | 23:cd03f9c3395e | 556 | break; |
garygid | 65:821fc79cd7fe | 557 | |
garygid | 67:2022fce701d0 | 558 | case 30: // right-most on top row |
garygid | 65:821fc79cd7fe | 559 | |
TickTock | 157:1a100a5ed06f | 560 | if (dMode[whichTouched]==config2Screen) { |
garygid | 65:821fc79cd7fe | 561 | // step through skins |
garygid | 65:821fc79cd7fe | 562 | if( skin < maxSkin ) skin += 1 ; |
garygid | 65:821fc79cd7fe | 563 | else skin = 0 ; |
garygid | 65:821fc79cd7fe | 564 | |
garygid | 65:821fc79cd7fe | 565 | // repaint both screens, I think |
garygid | 65:821fc79cd7fe | 566 | lastDMode[whichTouched]=99;//repaint to clear highlight |
garygid | 65:821fc79cd7fe | 567 | // and re-paint the other screen too, to see new skin there |
garygid | 65:821fc79cd7fe | 568 | lastDMode[whichTouched ^ 1]=99; // repaint other screen (^ = XOR) |
garygid | 67:2022fce701d0 | 569 | } else if (dMode[whichTouched] == indexScreen) { // gg - index |
TickTock | 122:138a40892a4c | 570 | dMode[whichTouched] = healthScreen ; // Goto health screen |
TickTock | 73:62ee8eae3a84 | 571 | sMode=0; |
TickTock | 169:84d790ac18a2 | 572 | } else if (dMode[whichTouched] == testScreen) { // gg - |
TickTock | 158:059abeb44ba1 | 573 | clearTest=true; |
TickTock | 158:059abeb44ba1 | 574 | } else { // top-right corner always mute/unmute unless used by specific screen |
TickTock | 154:90ea16ca7475 | 575 | enableSound = !enableSound; |
TickTock | 155:f31006516956 | 576 | if(!enableSound) spkr=0; |
garygid | 65:821fc79cd7fe | 577 | } |
garygid | 65:821fc79cd7fe | 578 | |
garygid | 65:821fc79cd7fe | 579 | break; |
garygid | 54:6ce808d0995e | 580 | //---------------------------------- |
garygid | 54:6ce808d0995e | 581 | //---------------------------------- |
garygid | 67:2022fce701d0 | 582 | case 01: // left col middle row |
leafman | 98:9f8bab96edff | 583 | if (dMode[whichTouched]==configScreen) { |
TickTock | 23:cd03f9c3395e | 584 | logEn = !logEn; |
garygid | 67:2022fce701d0 | 585 | } else if (dMode[whichTouched] == indexScreen) { // gg - index |
TickTock | 73:62ee8eae3a84 | 586 | dMode[whichTouched] = cpScreen ; // GoTo CP Data Screen |
TickTock | 73:62ee8eae3a84 | 587 | sMode=0; |
TickTock | 42:4533b13b297d | 588 | } else if (dMode[whichTouched]==dateScreen){ |
TickTock | 131:0d926c080a65 | 589 | dtMode=(dtMode<5)?dtMode+1:0; |
TickTock | 42:4533b13b297d | 590 | lastDMode[whichTouched]=99; |
TickTock | 62:ffd15edb5431 | 591 | } else { |
TickTock | 62:ffd15edb5431 | 592 | lastDMode[whichTouched]=99;//repaint to clear highlight |
TickTock | 23:cd03f9c3395e | 593 | } |
TickTock | 62:ffd15edb5431 | 594 | |
TickTock | 23:cd03f9c3395e | 595 | break; |
garygid | 54:6ce808d0995e | 596 | //------------------------------ |
TickTock | 23:cd03f9c3395e | 597 | case 11: |
leafman | 98:9f8bab96edff | 598 | if (dMode[whichTouched]==configScreen){ |
TickTock | 77:7c136766466c | 599 | repeatPoll = !repeatPoll; |
TickTock | 33:a277743ebdeb | 600 | if (repeatPoll) { |
TickTock | 36:dbd39c315258 | 601 | autoPoll.attach(&autoPollISR,pollInt); |
TickTock | 33:a277743ebdeb | 602 | } else { |
TickTock | 36:dbd39c315258 | 603 | autoPoll.detach(); |
TickTock | 33:a277743ebdeb | 604 | } |
garygid | 67:2022fce701d0 | 605 | } else if (dMode[whichTouched] == indexScreen) { // gg - index |
garygid | 67:2022fce701d0 | 606 | dMode[whichTouched] = cpHistScreen ; // GoTo CP Hist Screen |
TickTock | 73:62ee8eae3a84 | 607 | sMode=0; |
TickTock | 42:4533b13b297d | 608 | } else if (dMode[whichTouched]==playbackScreen) { |
TickTock | 36:dbd39c315258 | 609 | // Start/stop playback |
TickTock | 36:dbd39c315258 | 610 | if(!playbackOpen){ |
TickTock | 131:0d926c080a65 | 611 | if(!carCanIdle){ |
TickTock | 131:0d926c080a65 | 612 | printMsg("Cannot playback while connected to canbus\n"); |
TickTock | 131:0d926c080a65 | 613 | }else if(!logOpen){ |
TickTock | 109:3e6f0e8fca0d | 614 | efr = f_open(&efile,"playback.alc",FA_READ|FA_OPEN_EXISTING); |
TickTock | 50:83d5864c64a0 | 615 | lastDMode[whichTouched]=99;//force refresh |
TickTock | 109:3e6f0e8fca0d | 616 | if(efr != FR_OK){ |
TickTock | 116:5cd72bae7c12 | 617 | printMsg("Unable to open /usb/playback.alc\n"); // no playback.alc |
TickTock | 155:f31006516956 | 618 | beep(1000,0.25); |
TickTock | 36:dbd39c315258 | 619 | } else { |
TickTock | 36:dbd39c315258 | 620 | playbackOpen = true; |
TickTock | 50:83d5864c64a0 | 621 | playbackEn=true; |
TickTock | 50:83d5864c64a0 | 622 | playback.attach(&playbackISR,playbackInt); |
TickTock | 116:5cd72bae7c12 | 623 | printMsg("Starting playback\n"); // start playback |
TickTock | 155:f31006516956 | 624 | beep(2000,0.25); |
TickTock | 138:a2f5af85ed0d | 625 | can1.attach(NULL);// Stop recieving EVCAN data |
TickTock | 138:a2f5af85ed0d | 626 | can2.attach(NULL);// Stop recieving CARCAN data |
TickTock | 36:dbd39c315258 | 627 | } |
TickTock | 36:dbd39c315258 | 628 | } else { |
TickTock | 117:49883c779a74 | 629 | printMsg("Must stop logging first\n"); |
TickTock | 36:dbd39c315258 | 630 | } |
TickTock | 36:dbd39c315258 | 631 | } else { |
TickTock | 36:dbd39c315258 | 632 | playback.detach(); |
TickTock | 109:3e6f0e8fca0d | 633 | f_close(&efile); |
TickTock | 36:dbd39c315258 | 634 | playbackOpen=false; |
TickTock | 50:83d5864c64a0 | 635 | playbackEn=false; |
TickTock | 138:a2f5af85ed0d | 636 | can1.attach(&recieve1);// Restore EVCAN data recieve |
TickTock | 138:a2f5af85ed0d | 637 | can2.attach(&recieve2);// Restore EVCAN data recieve |
TickTock | 42:4533b13b297d | 638 | lastDMode[whichTouched]=99; |
TickTock | 36:dbd39c315258 | 639 | } |
TickTock | 42:4533b13b297d | 640 | } else if (dMode[whichTouched]==dateScreen){ |
TickTock | 25:ddf0ec209f03 | 641 | upDate(dtMode,true); |
TickTock | 42:4533b13b297d | 642 | lastDMode[whichTouched]=99; |
TickTock | 62:ffd15edb5431 | 643 | } else { |
TickTock | 62:ffd15edb5431 | 644 | lastDMode[whichTouched]=99;//repaint to clear highlight |
TickTock | 25:ddf0ec209f03 | 645 | } |
TickTock | 62:ffd15edb5431 | 646 | |
TickTock | 23:cd03f9c3395e | 647 | break; |
garygid | 54:6ce808d0995e | 648 | //--------------------------------- |
garygid | 54:6ce808d0995e | 649 | case 21: // col 2 row 1 |
leafman | 98:9f8bab96edff | 650 | if (dMode[whichTouched]==configScreen) { // gg - Batt Log Enable Button |
TickTock | 48:d1ce92104a1f | 651 | yesBattLog = !yesBattLog; |
garygid | 67:2022fce701d0 | 652 | } else if (dMode[whichTouched] == indexScreen) { // gg - index |
garygid | 67:2022fce701d0 | 653 | dMode[whichTouched] = cpBarScreen ; // GoTo CP Bars Screen |
TickTock | 73:62ee8eae3a84 | 654 | sMode=0; |
TickTock | 48:d1ce92104a1f | 655 | } else if (dMode[whichTouched]==dateScreen){ |
TickTock | 25:ddf0ec209f03 | 656 | upDate(dtMode,false); |
TickTock | 42:4533b13b297d | 657 | lastDMode[whichTouched]=99; |
TickTock | 62:ffd15edb5431 | 658 | } else { |
TickTock | 62:ffd15edb5431 | 659 | lastDMode[whichTouched]=99;//repaint to clear highlight |
TickTock | 25:ddf0ec209f03 | 660 | } |
TickTock | 62:ffd15edb5431 | 661 | |
TickTock | 23:cd03f9c3395e | 662 | break; |
garygid | 54:6ce808d0995e | 663 | |
garygid | 87:46ac3f2519d6 | 664 | case 31: // col 3 row 1 |
TickTock | 157:1a100a5ed06f | 665 | if (dMode[whichTouched]==config2Screen) { // gg - Batt Log Enable Button |
garygid | 87:46ac3f2519d6 | 666 | debugMode = !debugMode; |
leafman | 98:9f8bab96edff | 667 | } else if (dMode[whichTouched] == indexScreen) { // gg - index |
TickTock | 152:a4d66901785d | 668 | dMode[whichTouched] = configScreen ; // GoTo Config Screen |
TickTock | 152:a4d66901785d | 669 | } else if ((dMode[whichTouched]==dateScreen)&&accOn){ |
TickTock | 160:905fe45ed54b | 670 | syncDone=false; // initiate clock sync |
TickTock | 152:a4d66901785d | 671 | lastDMode[whichTouched]=99; |
garygid | 87:46ac3f2519d6 | 672 | } else { |
garygid | 87:46ac3f2519d6 | 673 | lastDMode[whichTouched]=99;//repaint to clear highlight |
garygid | 87:46ac3f2519d6 | 674 | } |
garygid | 87:46ac3f2519d6 | 675 | break; |
garygid | 87:46ac3f2519d6 | 676 | |
garygid | 54:6ce808d0995e | 677 | //----------------------------------- |
garygid | 67:2022fce701d0 | 678 | case 02: // left col, bottom row (not nav) |
garygid | 67:2022fce701d0 | 679 | if (dMode[whichTouched] == indexScreen) { // gg - index |
leafman | 98:9f8bab96edff | 680 | dMode[whichTouched] = playbackScreen ; // GoTo Playback Screen |
leafman | 98:9f8bab96edff | 681 | } else if (dMode[whichTouched]==configScreen) { |
TickTock | 140:ab3e94eb0227 | 682 | brakeMon = !brakeMon; |
TickTock | 140:ab3e94eb0227 | 683 | if(brakeMon){ |
TickTock | 140:ab3e94eb0227 | 684 | geiger.attach(&chirp,0.02); |
TickTock | 140:ab3e94eb0227 | 685 | }else{ |
TickTock | 140:ab3e94eb0227 | 686 | geiger.detach(); |
TickTock | 140:ab3e94eb0227 | 687 | } |
TickTock | 158:059abeb44ba1 | 688 | } else if (dMode[whichTouched]==config2Screen) { |
TickTock | 158:059abeb44ba1 | 689 | autoSync = !autoSync; |
garygid | 87:46ac3f2519d6 | 690 | } else { |
garygid | 87:46ac3f2519d6 | 691 | lastDMode[whichTouched]=99;//repaint to clear highlight |
garygid | 87:46ac3f2519d6 | 692 | } |
garygid | 67:2022fce701d0 | 693 | break; |
garygid | 67:2022fce701d0 | 694 | |
garygid | 67:2022fce701d0 | 695 | case 12: // left-middle col, bottom row (not nav) |
TickTock | 158:059abeb44ba1 | 696 | if (dMode[whichTouched]==configScreen) { |
TickTock | 158:059abeb44ba1 | 697 | regenMon = !regenMon; |
TickTock | 158:059abeb44ba1 | 698 | } else if (dMode[whichTouched]==config2Screen) { // gg - index |
leafman | 98:9f8bab96edff | 699 | dMode[whichTouched] = dateScreen ; // GoTo Set Date/Time Screen |
garygid | 87:46ac3f2519d6 | 700 | } else { |
garygid | 87:46ac3f2519d6 | 701 | lastDMode[whichTouched]=99;//repaint to clear highlight |
garygid | 87:46ac3f2519d6 | 702 | } |
garygid | 67:2022fce701d0 | 703 | break; |
garygid | 67:2022fce701d0 | 704 | |
garygid | 67:2022fce701d0 | 705 | case 22: // right-middle col, bottom row (not nav) |
TickTock | 158:059abeb44ba1 | 706 | if (dMode[whichTouched]==indexScreen) { // gg - index |
leafman | 98:9f8bab96edff | 707 | dMode[whichTouched] = logScreen ; |
TickTock | 169:84d790ac18a2 | 708 | sMode=0; |
TickTock | 159:577e9d015693 | 709 | } else if (dMode[whichTouched]==configScreen) { |
TickTock | 159:577e9d015693 | 710 | heaterMon = !heaterMon; |
TickTock | 157:1a100a5ed06f | 711 | } else if (dMode[whichTouched]==config2Screen) { |
TickTock | 169:84d790ac18a2 | 712 | updateConfig(); |
TickTock | 169:84d790ac18a2 | 713 | lastDMode[whichTouched]=99;//force refresh |
TickTock | 169:84d790ac18a2 | 714 | sMode=0; |
garygid | 87:46ac3f2519d6 | 715 | } else { |
garygid | 87:46ac3f2519d6 | 716 | lastDMode[whichTouched]=99;//repaint to clear highlight |
garygid | 87:46ac3f2519d6 | 717 | } |
garygid | 67:2022fce701d0 | 718 | break; |
TickTock | 72:f9a6faa28873 | 719 | |
leafman | 98:9f8bab96edff | 720 | case 32: // right col, bottom row (not nav) |
TickTock | 158:059abeb44ba1 | 721 | if (dMode[whichTouched]==config2Screen) { |
TickTock | 114:3f8c59a8a2b9 | 722 | logEn=false; |
leafman | 98:9f8bab96edff | 723 | updateFirmware(); |
TickTock | 158:059abeb44ba1 | 724 | } else if (dMode[whichTouched]==tripScreen) { |
TickTock | 108:29b5a760adc2 | 725 | miles_trip[2]=0; |
TickTock | 108:29b5a760adc2 | 726 | kWh_trip[2]=0; |
TickTock | 167:58d4edf403d4 | 727 | CCkWh_trip[2]=0; |
TickTock | 73:62ee8eae3a84 | 728 | sMode=0; |
TickTock | 108:29b5a760adc2 | 729 | lastDMode[whichTouched]=99;//repaint to clear highlight |
TickTock | 158:059abeb44ba1 | 730 | } else if (dMode[whichTouched]==indexScreen) { |
TickTock | 108:29b5a760adc2 | 731 | dMode[whichTouched] = tripScreen ; |
TickTock | 169:84d790ac18a2 | 732 | sMode=0; |
TickTock | 152:a4d66901785d | 733 | } else if (dMode[whichTouched]==dateScreen){ |
TickTock | 152:a4d66901785d | 734 | autoSync=!autoSync; // toggle autoSync mode |
TickTock | 152:a4d66901785d | 735 | lastDMode[whichTouched]=99; |
leafman | 98:9f8bab96edff | 736 | } else { |
garygid | 87:46ac3f2519d6 | 737 | lastDMode[whichTouched]=99;//repaint to clear highlight |
TickTock | 72:f9a6faa28873 | 738 | } |
TickTock | 72:f9a6faa28873 | 739 | break; |
TickTock | 72:f9a6faa28873 | 740 | |
garygid | 67:2022fce701d0 | 741 | //----------------------------------- |
garygid | 54:6ce808d0995e | 742 | //----------------------------------- |
garygid | 54:6ce808d0995e | 743 | // Prev Navigation |
garygid | 54:6ce808d0995e | 744 | case 07: // col 0 row tNavRow |
TickTock | 42:4533b13b297d | 745 | dMode[whichTouched]=dMode[whichTouched]>0?dMode[whichTouched]-1:maxScreens; |
TickTock | 22:a43df3905863 | 746 | break; |
garygid | 54:6ce808d0995e | 747 | //----------------------------------- |
garygid | 54:6ce808d0995e | 748 | // Select Screen Navigation |
garygid | 54:6ce808d0995e | 749 | case 17: |
TickTock | 43:e7f6f80590e3 | 750 | sMode=0; |
TickTock | 43:e7f6f80590e3 | 751 | lastDMode[whichTouched]=99; // Repaint |
TickTock | 22:a43df3905863 | 752 | break; |
garygid | 54:6ce808d0995e | 753 | //----------------------------------- |
garygid | 54:6ce808d0995e | 754 | // Index Navigation |
garygid | 54:6ce808d0995e | 755 | case 27: // col 2 row tNavRow |
garygid | 67:2022fce701d0 | 756 | dMode[whichTouched]= indexScreen ; // gg - index |
garygid | 54:6ce808d0995e | 757 | break; |
garygid | 54:6ce808d0995e | 758 | //------------------------------------ |
garygid | 54:6ce808d0995e | 759 | // Next Navigation |
garygid | 54:6ce808d0995e | 760 | case 37: // lower right on Nav Line gg - move next |
TickTock | 42:4533b13b297d | 761 | dMode[whichTouched]=dMode[whichTouched]<maxScreens?dMode[whichTouched]+1:0; |
TickTock | 22:a43df3905863 | 762 | break; |
garygid | 54:6ce808d0995e | 763 | //------------------------------------ |
garygid | 54:6ce808d0995e | 764 | //------------------------------------ |
TickTock | 22:a43df3905863 | 765 | default: |
TickTock | 62:ffd15edb5431 | 766 | lastDMode[whichTouched]=99;//repaint to clear highlight |
TickTock | 25:ddf0ec209f03 | 767 | break; |
TickTock | 25:ddf0ec209f03 | 768 | } |
TickTock | 23:cd03f9c3395e | 769 | break; |
TickTock | 23:cd03f9c3395e | 770 | case 2: // numpad |
TickTock | 23:cd03f9c3395e | 771 | break; |
TickTock | 23:cd03f9c3395e | 772 | case 3: |
TickTock | 23:cd03f9c3395e | 773 | break; |
TickTock | 23:cd03f9c3395e | 774 | default: |
TickTock | 23:cd03f9c3395e | 775 | break; |
TickTock | 23:cd03f9c3395e | 776 | } // case sMode |
TickTock | 22:a43df3905863 | 777 | } //recently touched |
TickTock | 4:8d7759f4fe7a | 778 | } else { // userIdle |
TickTock | 8:67eed72f3e10 | 779 | if(sMode==1){ |
TickTock | 8:67eed72f3e10 | 780 | sMode=0; |
TickTock | 43:e7f6f80590e3 | 781 | lastDMode[whichTouched]=99; |
TickTock | 8:67eed72f3e10 | 782 | } |
TickTock | 4:8d7759f4fe7a | 783 | } |
TickTock | 34:4751a8259b18 | 784 | |
TickTock | 153:e94cfe3c339c | 785 | // Sound tone on power reversal |
TickTock | 153:e94cfe3c339c | 786 | idir=(kW[0]>0)?true:false; |
TickTock | 155:f31006516956 | 787 | if(regenMon){ |
TickTock | 153:e94cfe3c339c | 788 | if (idir&&!lidir){ |
TickTock | 155:f31006516956 | 789 | beep(800,0.02); // Started sinking current |
TickTock | 153:e94cfe3c339c | 790 | }else if(!idir&&lidir){ |
TickTock | 155:f31006516956 | 791 | beep(3200,0.02); // Started regen |
TickTock | 153:e94cfe3c339c | 792 | } |
TickTock | 153:e94cfe3c339c | 793 | } |
TickTock | 154:90ea16ca7475 | 794 | lidir=idir; |
TickTock | 153:e94cfe3c339c | 795 | |
TickTock | 34:4751a8259b18 | 796 | if(tick){ // Executes once a second |
TickTock | 108:29b5a760adc2 | 797 | tick=false; |
TickTock | 164:46ed06263b0e | 798 | lCCon = CCon; |
TickTock | 161:71ac85d11f03 | 799 | CCkW = (lastMsg[indexLastMsg[0x510]].data[3]&0x7f)*0.125; |
TickTock | 164:46ed06263b0e | 800 | if(lastMsg[indexLastMsg[0x510]].data[3]&0x80){ |
TickTock | 164:46ed06263b0e | 801 | CCon=true; // On when button pushed |
TickTock | 164:46ed06263b0e | 802 | } else if(CCkW==0) { |
TickTock | 164:46ed06263b0e | 803 | CCon=false; // Off when power drops back to zero |
TickTock | 164:46ed06263b0e | 804 | } |
TickTock | 164:46ed06263b0e | 805 | if(!CCon && lCCon){ |
TickTock | 164:46ed06263b0e | 806 | lastDMode[0]=99;//force refresh |
TickTock | 164:46ed06263b0e | 807 | lastDMode[1]=99;//force refresh |
TickTock | 164:46ed06263b0e | 808 | } |
TickTock | 93:c2402e8cd0e2 | 809 | headlights = (lastMsg[indexLastMsg[0x358]].data[1]&0x80)?true:false; // headlight/turn signal indicator |
TickTock | 160:905fe45ed54b | 810 | if(heaterOn){ |
TickTock | 160:905fe45ed54b | 811 | lHeaterOn=true; // Only indicate heater once per power cycle |
TickTock | 160:905fe45ed54b | 812 | } |
TickTock | 159:577e9d015693 | 813 | heaterOn =((lastMsg[indexLastMsg[0x54f]].data[5]&0x3f)>0)?true:false; |
TickTock | 159:577e9d015693 | 814 | if(heaterMon && heaterOn && !lHeaterOn){ //Heat on alarm |
TickTock | 160:905fe45ed54b | 815 | beep3(800,0.25,1200,0.25,1600,0.25); |
TickTock | 160:905fe45ed54b | 816 | //beep(1600,0.5); |
TickTock | 159:577e9d015693 | 817 | } |
TickTock | 148:6e3b9135fad2 | 818 | if(accOn&&indexLastMsg[0x355]>0){ |
TickTock | 141:cf13a632ddb5 | 819 | miles_kmbar = (lastMsg[indexLastMsg[0x355]].data[4]&0x20)?true:false; // indicates selected distance units |
TickTock | 141:cf13a632ddb5 | 820 | metric = !miles_kmbar; |
TickTock | 141:cf13a632ddb5 | 821 | } |
TickTock | 41:8d4609ea7259 | 822 | accV=floor(mon12V*scale12V*10+0.5)/10; //Round to nearest 10th |
TickTock | 172:53548bf8bf85 | 823 | accOn=(playbackOpen||(accV>5))?true:false; |
TickTock | 131:0d926c080a65 | 824 | moving=(mph[0]>0.1); |
TickTock | 151:3047ebb3c9a8 | 825 | charging=(lastMsg[indexLastMsg[0x5bf]].data[2]>0)?true:false; // FF when charging |
TickTock | 134:ad243e4f1a17 | 826 | if (laccOn&&!accOn){ // Car turned off |
TickTock | 160:905fe45ed54b | 827 | lHeaterOn=false; |
TickTock | 172:53548bf8bf85 | 828 | if (showHealth&&!playbackOpen){ |
TickTock | 175:0357b4159b40 | 829 | if (saveDmode[0]==99){ |
TickTock | 175:0357b4159b40 | 830 | saveDmode[0]=dMode[0]; |
TickTock | 175:0357b4159b40 | 831 | saveDmode[1]=dMode[1]; |
TickTock | 134:ad243e4f1a17 | 832 | } |
TickTock | 134:ad243e4f1a17 | 833 | dMode[0]=healthScreen; |
TickTock | 175:0357b4159b40 | 834 | dMode[1]=tripScreen; |
TickTock | 135:89986950d501 | 835 | secsNoTouch=2;// Keep display on a few seconds |
TickTock | 134:ad243e4f1a17 | 836 | sMode=0; |
TickTock | 134:ad243e4f1a17 | 837 | userIdle=false; |
TickTock | 134:ad243e4f1a17 | 838 | } |
TickTock | 176:9c19f9856c76 | 839 | // Move to car on clause to use 24hour efficiency |
TickTock | 132:08748a67280a | 840 | // Keep track of max and min trip efficiency |
TickTock | 176:9c19f9856c76 | 841 | //if (miles_trip[0]>5){ // Ignore short trips |
TickTock | 176:9c19f9856c76 | 842 | // curEff = miles_trip[0]/kWh_trip[0]; |
TickTock | 176:9c19f9856c76 | 843 | // if (maxTripEff<curEff) { |
TickTock | 176:9c19f9856c76 | 844 | // maxTripEff=curEff; |
TickTock | 176:9c19f9856c76 | 845 | // maxTripMiles=miles_trip[0]; |
TickTock | 176:9c19f9856c76 | 846 | // maxTripkWh=kWh_trip[0]; |
TickTock | 176:9c19f9856c76 | 847 | // maxTripCCkWh=CCkWh_trip[0]; |
TickTock | 176:9c19f9856c76 | 848 | // } |
TickTock | 176:9c19f9856c76 | 849 | // if (minTripEff>curEff) { |
TickTock | 176:9c19f9856c76 | 850 | // minTripEff=curEff; |
TickTock | 176:9c19f9856c76 | 851 | // minTripMiles=miles_trip[0]; |
TickTock | 176:9c19f9856c76 | 852 | // minTripkWh=kWh_trip[0]; |
TickTock | 176:9c19f9856c76 | 853 | // minTripCCkWh=CCkWh_trip[0]; |
TickTock | 176:9c19f9856c76 | 854 | // } |
TickTock | 176:9c19f9856c76 | 855 | //} |
TickTock | 108:29b5a760adc2 | 856 | if (repeatPoll) { // Log on shutdown if autopoll enabled |
TickTock | 108:29b5a760adc2 | 857 | tripLog(); // Write trip log on powerdown |
TickTock | 108:29b5a760adc2 | 858 | } |
TickTock | 49:a3d2c5bb3cfa | 859 | //write efficiency history data |
TickTock | 97:a25940fd7b5b | 860 | hfile = fopen("/local/ehist.cny", "w"); |
TickTock | 97:a25940fd7b5b | 861 | if (hfile!=NULL){ // found a efficiency history file |
TickTock | 49:a3d2c5bb3cfa | 862 | for(i=0;i<39;i++){ |
TickTock | 97:a25940fd7b5b | 863 | fprintf(hfile,"%f %f\r\n",mph[i],kW[i]); |
TickTock | 49:a3d2c5bb3cfa | 864 | } |
TickTock | 134:ad243e4f1a17 | 865 | fprintf(hfile,"%f %f\r\n",maxTripEff,minTripEff); // Save max and min |
TickTock | 155:f31006516956 | 866 | fprintf(hfile,"%f \r\n",Resr); // Save series resistance |
TickTock | 167:58d4edf403d4 | 867 | fprintf(hfile,"%f %f\r\n",maxTripMiles,minTripMiles); // Save max and min |
TickTock | 167:58d4edf403d4 | 868 | fprintf(hfile,"%f %f\r\n",maxTripkWh,minTripkWh); // Save max and min |
TickTock | 167:58d4edf403d4 | 869 | fprintf(hfile,"%f %f\r\n",maxTripCCkWh,minTripCCkWh); // Save max and min |
TickTock | 97:a25940fd7b5b | 870 | fclose(hfile); |
TickTock | 49:a3d2c5bb3cfa | 871 | } |
TickTock | 49:a3d2c5bb3cfa | 872 | } |
TickTock | 134:ad243e4f1a17 | 873 | if (!laccOn&&accOn){ // Car turned on |
TickTock | 160:905fe45ed54b | 874 | lHeaterOn=false; |
TickTock | 108:29b5a760adc2 | 875 | miles_trip[0]=0; |
TickTock | 108:29b5a760adc2 | 876 | kWh_trip[0]=0; |
TickTock | 167:58d4edf403d4 | 877 | CCkWh_trip[0]=0; |
TickTock | 176:9c19f9856c76 | 878 | seconds = time(NULL); |
TickTock | 176:9c19f9856c76 | 879 | t = *localtime(&seconds); |
TickTock | 176:9c19f9856c76 | 880 | if((t.tm_hour>=2)&&(lt.tm_hour<2)){ // Reset daily efficiency every day at 2am |
TickTock | 176:9c19f9856c76 | 881 | if (miles_trip[3]>25){ // Ignore low mileage data |
TickTock | 176:9c19f9856c76 | 882 | curEff = miles_trip[3]/kWh_trip[3]; |
TickTock | 176:9c19f9856c76 | 883 | if (maxTripEff<curEff) { |
TickTock | 176:9c19f9856c76 | 884 | maxTripEff=curEff; |
TickTock | 176:9c19f9856c76 | 885 | maxTripMiles=miles_trip[3]; |
TickTock | 176:9c19f9856c76 | 886 | maxTripkWh=kWh_trip[3]; |
TickTock | 176:9c19f9856c76 | 887 | maxTripCCkWh=CCkWh_trip[3]; |
TickTock | 176:9c19f9856c76 | 888 | } |
TickTock | 176:9c19f9856c76 | 889 | if (minTripEff>curEff) { |
TickTock | 176:9c19f9856c76 | 890 | minTripEff=curEff; |
TickTock | 176:9c19f9856c76 | 891 | minTripMiles=miles_trip[3]; |
TickTock | 176:9c19f9856c76 | 892 | minTripkWh=kWh_trip[3]; |
TickTock | 176:9c19f9856c76 | 893 | minTripCCkWh=CCkWh_trip[3]; |
TickTock | 176:9c19f9856c76 | 894 | } |
TickTock | 176:9c19f9856c76 | 895 | } |
TickTock | 176:9c19f9856c76 | 896 | miles_trip[3]=0; |
TickTock | 176:9c19f9856c76 | 897 | kWh_trip[3]=0; |
TickTock | 176:9c19f9856c76 | 898 | CCkWh_trip[3]=0; |
TickTock | 176:9c19f9856c76 | 899 | } |
TickTock | 176:9c19f9856c76 | 900 | lt=t; |
TickTock | 115:549410af477d | 901 | wait5secs=5; |
TickTock | 172:53548bf8bf85 | 902 | getGids=true; |
TickTock | 172:53548bf8bf85 | 903 | if (showHealth&&!playbackOpen){ |
TickTock | 175:0357b4159b40 | 904 | if (saveDmode[0]==99){ |
TickTock | 175:0357b4159b40 | 905 | saveDmode[0]=dMode[0]; |
TickTock | 134:ad243e4f1a17 | 906 | } |
TickTock | 131:0d926c080a65 | 907 | dMode[0]=healthScreen; |
TickTock | 131:0d926c080a65 | 908 | } |
TickTock | 152:a4d66901785d | 909 | syncDone=!autoSync; // clear syncDone flag if autoSync enabled |
TickTock | 115:549410af477d | 910 | } |
TickTock | 49:a3d2c5bb3cfa | 911 | laccOn=accOn; |
TickTock | 135:89986950d501 | 912 | if(!accOn&&userIdle&&!playbackEn){ // Car off and no user activity - turn off screen |
TickTock | 134:ad243e4f1a17 | 913 | dled = 0; |
TickTock | 175:0357b4159b40 | 914 | if (saveDmode[0]<99){ |
TickTock | 175:0357b4159b40 | 915 | dMode[0]=saveDmode[0]; |
TickTock | 175:0357b4159b40 | 916 | saveDmode[0]=99; |
TickTock | 175:0357b4159b40 | 917 | } |
TickTock | 175:0357b4159b40 | 918 | if (saveDmode[1]<99){ |
TickTock | 175:0357b4159b40 | 919 | dMode[1]=saveDmode[1]; |
TickTock | 175:0357b4159b40 | 920 | saveDmode[1]=99; |
TickTock | 134:ad243e4f1a17 | 921 | } |
TickTock | 35:5acbd8a64a89 | 922 | }else if(!headlights){ |
TickTock | 35:5acbd8a64a89 | 923 | dled = ledHi; |
TickTock | 115:549410af477d | 924 | } else { |
TickTock | 35:5acbd8a64a89 | 925 | dled = ledLo; |
TickTock | 34:4751a8259b18 | 926 | } |
TickTock | 172:53548bf8bf85 | 927 | if(getGids){ |
TickTock | 172:53548bf8bf85 | 928 | startGids=(lastMsg[indexLastMsg[0x5bc]].data[0]<<2)+(lastMsg[indexLastMsg[0x5bc]].data[1]>>6); //Get gids |
TickTock | 172:53548bf8bf85 | 929 | if((startGids>0)&&(startGids<300)){ |
TickTock | 172:53548bf8bf85 | 930 | getGids=false; |
TickTock | 172:53548bf8bf85 | 931 | } |
TickTock | 172:53548bf8bf85 | 932 | } |
TickTock | 115:549410af477d | 933 | if(wait5secs>0){ // Wait a few seconds after poweron to give BMS time to measure CP's |
TickTock | 115:549410af477d | 934 | wait5secs-=1; |
TickTock | 172:53548bf8bf85 | 935 | if(wait5secs==0){ |
TickTock | 172:53548bf8bf85 | 936 | if (repeatPoll) { // Poll on startup if autopoll enabled |
TickTock | 172:53548bf8bf85 | 937 | logOnce=true; |
TickTock | 172:53548bf8bf85 | 938 | reqMsgCnt=0; |
TickTock | 172:53548bf8bf85 | 939 | msgReq.attach(&sendReq,0.015); |
TickTock | 172:53548bf8bf85 | 940 | lastDMode[0]=99; |
TickTock | 172:53548bf8bf85 | 941 | lastDMode[1]=99; |
TickTock | 172:53548bf8bf85 | 942 | } |
TickTock | 108:29b5a760adc2 | 943 | } |
TickTock | 107:e9be732c1ad4 | 944 | } |
TickTock | 173:9815b1467039 | 945 | //remove health screen once moving |
TickTock | 175:0357b4159b40 | 946 | if(moving&&(saveDmode[0]<99)&&(wait5secs==0)){ |
TickTock | 175:0357b4159b40 | 947 | dMode[0]=saveDmode[0]; |
TickTock | 175:0357b4159b40 | 948 | saveDmode[0]=99; |
TickTock | 173:9815b1467039 | 949 | } |
TickTock | 115:549410af477d | 950 | |
TickTock | 49:a3d2c5bb3cfa | 951 | //compute historic efficiency |
TickTock | 41:8d4609ea7259 | 952 | if(numSsamples>0){ // Avoid div0 |
TickTock | 160:905fe45ed54b | 953 | // calibrated to dash mph which reads slightly fast. |
TickTock | 160:905fe45ed54b | 954 | // 227 would give more accurate mph for MXV4s@40psi - 11.75" distance from center of tire to pavement |
TickTock | 160:905fe45ed54b | 955 | // but then efficiency estimation would not track miles driven as read from the odometer so |
TickTock | 160:905fe45ed54b | 956 | // making CANary have the same error as the Leaf instrumentation |
TickTock | 174:cd27e80f197d | 957 | mph[0]=((float) motorRPM)/numSsamples/110; |
TickTock | 86:d1c9e8ac1c4b | 958 | } else { |
TickTock | 49:a3d2c5bb3cfa | 959 | mph[0]=0; |
TickTock | 36:dbd39c315258 | 960 | } |
TickTock | 49:a3d2c5bb3cfa | 961 | if(mph[0]>99){ |
TickTock | 49:a3d2c5bb3cfa | 962 | mph[0]=0; |
TickTock | 49:a3d2c5bb3cfa | 963 | } |
TickTock | 121:553faf139a20 | 964 | numSsamples=0; |
TickTock | 107:e9be732c1ad4 | 965 | |
TickTock | 41:8d4609ea7259 | 966 | if(numWsamples>0){ // Avoid div0 |
TickTock | 121:553faf139a20 | 967 | mpkWh[0]=mph[0]; |
TickTock | 161:71ac85d11f03 | 968 | kW[0]=((float) mWs_x4)/numWsamples/4e3; |
TickTock | 49:a3d2c5bb3cfa | 969 | mpkWh[0]/=kW[0]; |
TickTock | 49:a3d2c5bb3cfa | 970 | if (mpkWh[0]<0) { |
TickTock | 49:a3d2c5bb3cfa | 971 | mpkWh[0]=99;// negative means inf. |
TickTock | 49:a3d2c5bb3cfa | 972 | } |
TickTock | 161:71ac85d11f03 | 973 | kW[0]-=CCkW; // subtract climate control power from recorded value |
TickTock | 161:71ac85d11f03 | 974 | } else { |
TickTock | 49:a3d2c5bb3cfa | 975 | kW[0]=0; |
TickTock | 49:a3d2c5bb3cfa | 976 | mpkWh[0]=0; |
TickTock | 49:a3d2c5bb3cfa | 977 | } |
TickTock | 121:553faf139a20 | 978 | numWsamples=0; |
TickTock | 121:553faf139a20 | 979 | |
TickTock | 172:53548bf8bf85 | 980 | if(accOn&&!charging){ // Calculate averages |
TickTock | 161:71ac85d11f03 | 981 | for(i=1;i<39;i++){ |
TickTock | 161:71ac85d11f03 | 982 | average=mph[i]/timeConstant[i]; |
TickTock | 161:71ac85d11f03 | 983 | mph[i]-=average; |
TickTock | 161:71ac85d11f03 | 984 | mph[i]+=mph[0]; |
TickTock | 161:71ac85d11f03 | 985 | mpkWh[i]=average; |
TickTock | 161:71ac85d11f03 | 986 | average=kW[i]/timeConstant[i]; |
TickTock | 161:71ac85d11f03 | 987 | kW[i]-=average; |
TickTock | 161:71ac85d11f03 | 988 | kW[i]+=kW[0]; |
TickTock | 162:c6545fc0164a | 989 | if(i==dtePeriod) mpkWh_noCC=mpkWh[i]/average; // compute efficiency w/o CC for dtePeriod |
TickTock | 161:71ac85d11f03 | 990 | average+=CCkW; //add climate control power back in for display |
TickTock | 161:71ac85d11f03 | 991 | mpkWh[i]/=average; |
TickTock | 161:71ac85d11f03 | 992 | if (mpkWh[i]<0) { |
TickTock | 161:71ac85d11f03 | 993 | mpkWh[i]=99;// negative means inf. |
TickTock | 161:71ac85d11f03 | 994 | } |
TickTock | 161:71ac85d11f03 | 995 | } |
TickTock | 161:71ac85d11f03 | 996 | } |
TickTock | 161:71ac85d11f03 | 997 | |
TickTock | 121:553faf139a20 | 998 | if (!charging){ |
TickTock | 151:3047ebb3c9a8 | 999 | miles_trip[0]+=mph[0]/3600; // per trip |
TickTock | 151:3047ebb3c9a8 | 1000 | miles_trip[1]+=mph[0]/3600; // per charge |
TickTock | 151:3047ebb3c9a8 | 1001 | miles_trip[2]+=mph[0]/3600; // user |
TickTock | 176:9c19f9856c76 | 1002 | miles_trip[3]+=mph[0]/3600; // user |
TickTock | 121:553faf139a20 | 1003 | kWh_trip[0]+=kW[0]/3600; |
TickTock | 121:553faf139a20 | 1004 | kWh_trip[1]+=kW[0]/3600; |
TickTock | 121:553faf139a20 | 1005 | kWh_trip[2]+=kW[0]/3600; |
TickTock | 176:9c19f9856c76 | 1006 | kWh_trip[3]+=kW[0]/3600; |
TickTock | 167:58d4edf403d4 | 1007 | CCkWh_trip[0]+=CCkW/3600; |
TickTock | 167:58d4edf403d4 | 1008 | CCkWh_trip[1]+=CCkW/3600; |
TickTock | 167:58d4edf403d4 | 1009 | CCkWh_trip[2]+=CCkW/3600; |
TickTock | 176:9c19f9856c76 | 1010 | CCkWh_trip[3]+=CCkW/3600; |
TickTock | 161:71ac85d11f03 | 1011 | } else { // charging so reset per charge trip meter |
TickTock | 151:3047ebb3c9a8 | 1012 | miles_trip[1]=0; |
TickTock | 151:3047ebb3c9a8 | 1013 | kWh_trip[1]=0; |
TickTock | 167:58d4edf403d4 | 1014 | CCkWh_trip[1]=0; |
TickTock | 121:553faf139a20 | 1015 | } |
TickTock | 121:553faf139a20 | 1016 | |
TickTock | 174:cd27e80f197d | 1017 | motorRPM=0; |
TickTock | 40:0e6e71a7323f | 1018 | mWs_x4=0; |
TickTock | 121:553faf139a20 | 1019 | |
TickTock | 121:553faf139a20 | 1020 | // Compute ESR |
TickTock | 121:553faf139a20 | 1021 | if((Imax-Imin)<40){ // do nothing - insufficient delta_I to measure |
TickTock | 121:553faf139a20 | 1022 | unloadedV_x2 = (curRmax+curRmin)/2; |
TickTock | 154:90ea16ca7475 | 1023 | }else if ((redRmax-redRmin)<(curRmax-curRmin)) { // less variation on reduced Resr |
TickTock | 120:041edeec08f5 | 1024 | Resr-=0.001; |
TickTock | 120:041edeec08f5 | 1025 | unloadedV_x2 = (redRmax+redRmin)/2; |
TickTock | 154:90ea16ca7475 | 1026 | } else if ((incRmax-incRmin)<(curRmax-curRmin)) { // less variation on increased Resr |
TickTock | 120:041edeec08f5 | 1027 | Resr+=0.001; |
TickTock | 120:041edeec08f5 | 1028 | unloadedV_x2 = (incRmax+incRmin)/2; |
TickTock | 154:90ea16ca7475 | 1029 | } else { // current Resr is still best answer |
TickTock | 120:041edeec08f5 | 1030 | unloadedV_x2 = (curRmax+curRmin)/2; |
TickTock | 120:041edeec08f5 | 1031 | } |
TickTock | 120:041edeec08f5 | 1032 | curRmin=1000; |
TickTock | 120:041edeec08f5 | 1033 | curRmax=0; |
TickTock | 120:041edeec08f5 | 1034 | incRmin=1000; |
TickTock | 120:041edeec08f5 | 1035 | incRmax=0; |
TickTock | 120:041edeec08f5 | 1036 | redRmin=1000; |
TickTock | 120:041edeec08f5 | 1037 | redRmax=0; |
TickTock | 121:553faf139a20 | 1038 | Imax=-1000; |
TickTock | 121:553faf139a20 | 1039 | Imin=1000; |
TickTock | 121:553faf139a20 | 1040 | |
TickTock | 108:29b5a760adc2 | 1041 | if(logCP&&usbEn){ |
TickTock | 108:29b5a760adc2 | 1042 | if(logOnce){ |
TickTock | 108:29b5a760adc2 | 1043 | tripLog(); |
TickTock | 108:29b5a760adc2 | 1044 | logOnce=false; |
TickTock | 108:29b5a760adc2 | 1045 | } |
garygid | 69:6bfdfc002036 | 1046 | logPackVoltages(); // Turbo3, only call |
TickTock | 108:29b5a760adc2 | 1047 | } |
TickTock | 137:70853cf5a30f | 1048 | if(!usbEn){ |
TickTock | 108:29b5a760adc2 | 1049 | usbEn=detectUSB(); // Keep looking if none found |
TickTock | 132:08748a67280a | 1050 | if(usbEn){ // Force update to clear USB init garbage |
TickTock | 132:08748a67280a | 1051 | lastDMode[0]=99; |
TickTock | 132:08748a67280a | 1052 | lastDMode[1]=99; |
TickTock | 132:08748a67280a | 1053 | } |
TickTock | 108:29b5a760adc2 | 1054 | } |
TickTock | 152:a4d66901785d | 1055 | if(!syncDone){ |
TickTock | 153:e94cfe3c339c | 1056 | syncDone=syncDateTime(); |
TickTock | 152:a4d66901785d | 1057 | } |
TickTock | 121:553faf139a20 | 1058 | tock=true; |
TickTock | 121:553faf139a20 | 1059 | } // tick |
TickTock | 39:eef8beac7411 | 1060 | |
TickTock | 36:dbd39c315258 | 1061 | if(step){ // playback |
TickTock | 36:dbd39c315258 | 1062 | if(playbackOpen&&playbackEn){ |
TickTock | 38:155ec32c5e91 | 1063 | for(i=0;i<120;i++){ |
TickTock | 109:3e6f0e8fca0d | 1064 | if(!f_eof(&efile)){ |
TickTock | 109:3e6f0e8fca0d | 1065 | efr=f_read(&efile,&header,5,&bytesRW); |
TickTock | 109:3e6f0e8fca0d | 1066 | efr=f_read(&efile,&data,8,&bytesRW); |
garygid | 69:6bfdfc002036 | 1067 | logCan(header[0],CANMessage(0x7ff&((header[4]<<8)+header[3]), data, 8)); // Playback |
TickTock | 86:d1c9e8ac1c4b | 1068 | } else { |
TickTock | 109:3e6f0e8fca0d | 1069 | f_close(&efile); // restart |
TickTock | 109:3e6f0e8fca0d | 1070 | efr = f_open(&efile,"playback.alc",FA_READ|FA_OPEN_EXISTING); |
TickTock | 50:83d5864c64a0 | 1071 | lastDMode[whichTouched]=99;//force refresh |
TickTock | 155:f31006516956 | 1072 | beep(2000,0.25); |
TickTock | 36:dbd39c315258 | 1073 | } |
TickTock | 36:dbd39c315258 | 1074 | } |
TickTock | 36:dbd39c315258 | 1075 | } |
TickTock | 36:dbd39c315258 | 1076 | step=false; |
TickTock | 36:dbd39c315258 | 1077 | } |
TickTock | 37:fea2c1d52c5f | 1078 | |
TickTock | 140:ab3e94eb0227 | 1079 | display=display<1?display+1:0; // toggle display |
TickTock | 140:ab3e94eb0227 | 1080 | updateDisplay(display); |
TickTock | 2:71b1999a8ea5 | 1081 | } //while (true) |
TickTock | 0:1596b8644523 | 1082 | } |