Attempts to merge SPI_TFT2 & SPI_TFT_ILI9341
Dependencies: SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed
Fork of CANary by
Revision 117:49883c779a74, committed 2013-07-04
- Comitter:
- TickTock
- Date:
- Thu Jul 04 18:01:52 2013 +0000
- Branch:
- Metric
- Parent:
- 116:5cd72bae7c12
- Child:
- 118:02010b18efdc
- Commit message:
- Added delay to initial poll to give BMS time to measure;
Changed in this revision
--- a/main.cpp Thu Jul 04 05:27:15 2013 +0000 +++ b/main.cpp Thu Jul 04 18:01:52 2013 +0000 @@ -24,7 +24,7 @@ #include "displayModes.h" #include "TOUCH_TFTx2.h" -char revStr[7] = "116"; // gg - revision string, max 6 characters +char revStr[7] = "117"; // gg - revision string, max 6 characters FATFS USBdrive; LocalFileSystem local("local"); @@ -45,8 +45,6 @@ DigitalOut led4(LED4); InterruptIn touchpad(p17); -InterruptIn hwInt(p24); // Assigning p24 as both input interrupt and -DigitalOut swInt(p24); // digital out to create a SW interrupt CAN can1(p9, p10); // CAN1 (EV) uses pins 9 and 10 (rx, tx) and pin 8 (rs) DigitalOut can1SleepMode(p8); // Use pin 8 to control the sleep mode of can2 CAN can2(p30, p29); // CAN2 (CAR) uses pins 30 and 29 (rx, tx) and pin 28 (rs) @@ -112,6 +110,7 @@ float accV = 0; bool playbackEn = false; bool playbackOpen = false; +//float playbackInt = 0.05; //read messages every 50 ms float playbackInt = 0.005; //read messages every 5 ms bool step = false; char header[5]; @@ -151,20 +150,15 @@ tt.cls(); tt.claim(stdout); // send stdout to the TFT display touchpad.rise(&touch_ISR); - hwInt.rise(&dumpBuffer); tt.wfi(); // enable interrupt on touch dled = 0.8; // turn on display LED 80% - swInt = 0; + timer.start() ; RTC_Init(); // start the RTC Interrupts that sync the timer struct tm t; // pointer to a static tm structure NVIC_SetPriority(CAN_IRQn, 2); //set can priority just below RTC - NVIC_SetPriority(EINT0_IRQn, 3); //set hardware interrupt - NVIC_SetPriority(EINT1_IRQn, 3); //not sure which InterruptIn uses - NVIC_SetPriority(EINT2_IRQn, 3); //so set them all - NVIC_SetPriority(EINT3_IRQn, 3); - NVIC_SetPriority(TIMER3_IRQn, 4); //set ticker priority just below can - + NVIC_SetPriority(TIMER3_IRQn, 3); //set ticker priority just below can + seconds = time(NULL); t = *localtime(&seconds) ; // is it a date before 2012 ? @@ -254,14 +248,33 @@ } }//logging enabled and USB detected } else { // if (logOpen) - if (canIdle||!logEn) { - swInt=1; //trigger buffer dump ISR - } // if canbus has stopped, or logging stopped + pointerSep=(writePointer+maxBufLen-readPointer)%maxBufLen; + if (pointerSep>(maxBufLen/16)||canIdle||!logEn) { + // Dump buffer if > 1/16 full or canbus has stopped + //if (&efile == NULL) { + if (efr != FR_OK) { + logOpen = false; + printMsg("Failed to append log file.\n"); // failed to append + spkr.beep(3000,0.25); + spkr.beep(1500,0.25); + spkr.beep(750,0.25); + spkr.beep(375,0.25); + logEn=false; + } else { + while (readPointer != writePointer) { + efr=f_write(&efile,&writeBuffer[readPointer][0],13,&bytesRW); + if(++readPointer >= maxBufLen){ + readPointer=0; + led4 = !led4; + } + } + } + } // if > 1/16 full, canbus has stopped, or logging stopped if (!logEn) { - logOpen=false; sprintf(sTemp,"Stopping Can Log %s\n",fileName); printMsg(sTemp); // stopping alc log file f_close(&efile); + logOpen=false; pointerSep=0; led4=false; } @@ -513,7 +526,7 @@ can2.attach(&doNothing); } } else { - printMsg("Must stop logging first\n"); // Must stop logging first + printMsg("Must stop logging first\n"); } } else { playback.detach();
--- a/utility.cpp Thu Jul 04 05:27:15 2013 +0000 +++ b/utility.cpp Thu Jul 04 18:01:52 2013 +0000 @@ -83,6 +83,9 @@ // overlay the last message with a "Lost0002" comment writeBuffer[tempWritePointer][0]=0; + // leave the ts of the overlaid message + //writeBuffer[tempWritePointer][1]=(ts&0xff00)>>8; // Time Stamp (2 bytes_ + //writeBuffer[tempWritePointer][2]=(ts&0x00ff); // force the MsgID to an Event Message writeBuffer[tempWritePointer][3]=0xfe; // MsgID, low byte writeBuffer[tempWritePointer][4]=0xff; // Len nibble, and MsgID high nibble @@ -162,11 +165,11 @@ for(i=5;i<13;i++){ // Is there a better way to do this? (writeBuffer[localWritePointer][5]=canRXmsg.data?) writeBuffer[localWritePointer][i]=canRXmsg.data[i-5]; } - //if (localWritePointer==readPointer) { //Just caught up to read pointer - // printMsg("Write buffer overrun.\n"); - // spkr.beep(500,0.125); - //} - swInt=1; // trigger buffer dump + if (writePointer==readPointer) { + // Just caught up to read pointer + printMsg("Write buffer overrun.\n"); // write buffer overrun + spkr.beep(500,0.25); + } } } @@ -390,6 +393,9 @@ } void autoPollISR(){ + //char sTemp[40]; // just for debug + //sprintf(sTemp,"Requesting cp data\n"); // just for debug + //printMsg(sTemp); // just for debug reqMsgCnt = 0; //reset message counter msgReq.attach(&sendReq,0.015); } @@ -795,32 +801,3 @@ } return(usbEn); } - -void dumpBuffer(void){ - int localWritePointer=writePointer; - //NVIC_DisableIRQ(EINT0_IRQn); - //NVIC_DisableIRQ(EINT1_IRQn); - //NVIC_DisableIRQ(EINT2_IRQn); - //NVIC_DisableIRQ(EINT3_IRQn); - while (readPointer != localWritePointer) { - FRESULT efr=f_write(&efile,&writeBuffer[readPointer][0],13,&bytesRW); - if (efr != FR_OK) { - logOpen = false; - printMsg("Failed to append log file.\n"); // failed to append - spkr.beep(3000,0.25); - spkr.beep(1500,0.25); - spkr.beep(750,0.25); - spkr.beep(375,0.25); - logEn=false; - } - if(++readPointer >= maxBufLen){ - readPointer=0; - led4 = !led4; - } - } - swInt=0; - //NVIC_EnableIRQ(EINT0_IRQn); - //NVIC_EnableIRQ(EINT1_IRQn); - //NVIC_EnableIRQ(EINT2_IRQn); - //NVIC_EnableIRQ(EINT3_IRQn); -} \ No newline at end of file
--- a/utility.h Thu Jul 04 05:27:15 2013 +0000 +++ b/utility.h Thu Jul 04 18:01:52 2013 +0000 @@ -16,7 +16,6 @@ extern char displayLog[20][40]; extern unsigned char displayLoc; extern bool touched; -extern bool logEn; extern bool logOpen; extern bool logCP; // Turbo3 extern bool yesBattLog ; // gg - Batt Log @@ -28,14 +27,15 @@ extern char indexLastMsg[0x800]; extern unsigned char dMode[2]; extern unsigned char msgChanged[100]; -extern FIL efile; -extern unsigned int bytesRW; + +//extern unsigned char battData[256]; // extern unsigned char battData[BatDataBufMax]; // BatDataBufMax extern CANMessage lastMsg[100]; extern CAN can1,can2; extern unsigned int fwCount; -extern DigitalOut can1SleepMode,can2SleepMode,swInt; +extern DigitalOut can1SleepMode,can2SleepMode; +//extern bool pollCP; extern bool tick; extern bool ZeroSecTick; extern bool headlights; @@ -91,7 +91,6 @@ void tripLog(); // Turbo3 void updateFirmware(); // LM - Update firmware off USB bool detectUSB(); - void dumpBuffer(); } //LEAF OBD