Dual CANbus monitor and instrumentation cluster supporting ILI9341 display controller
Dependencies: SPI_TFTx2_ILI9341 TOUCH_TFTx2_ILI9341 TFT_fonts mbed
Fork of CANary by
Diff: main.cpp
- Revision:
- 26:462ccb580472
- Parent:
- 25:ddf0ec209f03
- Child:
- 30:e633a63eb257
--- a/main.cpp Fri Mar 15 04:28:34 2013 +0000 +++ b/main.cpp Sat Mar 16 02:07:09 2013 +0000 @@ -18,6 +18,8 @@ #include "EthernetPowerControl.h" #include "utility.h" #include "displayModes.h" +#include "GraphicsDisplay.h" +#include "SPI_TFTx2.h" #include "TOUCH_TFTx2.h" LocalFileSystem local("local"); @@ -61,7 +63,7 @@ volatile int secsNoTouch = 0; volatile bool canIdle; volatile bool userIdle; -bool touched=0; //flag to read touchscreen +bool touched=false; //flag to read touchscreen char counter = 0; unsigned char dMode[2] = {dteScreen,brakeScreen}; //display mode unsigned char sMode = 0; // setup mode @@ -97,45 +99,29 @@ touchpad.rise(&touch_ISR); tt.wfi(); // enable interrupt on touch dled = 0.8; // turn on display LED 80% + timer.start() ; RTC_Init(); // start the RTC Interrupts that sync the timer struct tm t; // pointer to a static tm structure NVIC_SetPriority(TIMER3_IRQn, 1); //set ticker priority NVIC_SetPriority(CAN_IRQn, 2); //higher than can (so RTC sync works) + + seconds = time(NULL); t = *localtime(&seconds) ; - secsNoMsg = 0; - secsNoTouch = 0; - // is it a date before 2012 ? - /*if ((t.tm_year + 1900) < 2012 ) { - // before 2012, so the RTC probably lost power - // So, set a near-recent date in 2012 - // enter people-values here - t.tm_year = 2013 ; // 28 May 2012 - t.tm_mon = 3 ; // 1 to 12 - t.tm_mday = 11; - t.tm_hour = 21; // 12:59:56 PM (after noon) - t.tm_min = 05; - t.tm_sec = 00; - - // adjust for tm structure required values - t.tm_year = t.tm_year - 1900; - t.tm_mon = t.tm_mon - 1; - + if ((t.tm_year + 1900) < 2012 ) { + // before 2013 so update year to make date entry easier + t.tm_year = 2013 - 1900; // set the RTC set_time(mktime(&t)); seconds = time(NULL); - - // printf("Set RTC to:\n" ); - // strftime(sTemp, 32, "%a %m/%d/%Y %X", localtime(&seconds)); - // printf("%s\n", sTemp); // DAY MM/DD/YYYY HH:MM:SS - }*/ + } t = *localtime(&seconds) ; strftime(sTemp, 32, "%a %m/%d/%Y %X\n", &t); logMsg(sTemp); - // Look for new binary + // Look for new binary on thumbdrive // Can't make this work right now since USB doesn't attach the right timestamp (so new binary isn't loaded) /*cfile = fopen("/fs/CANary.bin", "rb"); if (cfile!=NULL){ //found a new binary on the thumbdrive so copy it over @@ -169,10 +155,14 @@ } }*/ - // Look for config file + secsNoMsg = 0; + secsNoTouch = 0; + + // Read config file readConfig(); + touched=false; + secsNoTouch=2; - //ticker.attach(&tickerISR, 60); //poll cellpair data every minute while (true) { if (!logOpen) { // Open new file if one is not already open if(logEn){ //logging enable @@ -187,14 +177,14 @@ sprintf(sTemp,"\nUnable to open %s\n\n\n\n",fileName); logMsg(sTemp); logEn=false; - spkr.beep(1000,0.2); + spkr.beep(1000,0.25); } else { logOpen = true; readPointer=writePointer; sprintf(sTemp,"Starting Can Log %s\n",fileName); logMsg(sTemp); logTS(); - spkr.beep(2000,0.2); + spkr.beep(2000,0.25); } }//logging enabled } else { // if (logOpen) @@ -203,7 +193,7 @@ if (file == NULL) { logOpen = false; sprintf(sTemp,"Failed to append log file.\n\n"); - spkr.beep(1000,0.2); + spkr.beep(1000,0.25); logMsg(sTemp); logEn=false; } else { @@ -219,7 +209,7 @@ } // if > 1/16 full, canbus has stopped, or PB1 pressed } // if logOpen if (canIdle&&userIdle) { // canbus idle --> sleep to save power - if (logOpen){ + if (logOpen){ fclose(file); } // if (logOpen)*/ seconds = time(NULL); @@ -240,13 +230,11 @@ tt.wfi(); //enable touch interrupt //__wfi(); // freeze CPU and wait for interrupt (from canbus or touch) Sleep(); - //DeepPowerDown(); } secsNoTouch=0; canIdle=secsNoMsg>canTimeout; userIdle=secsNoTouch>userTimeout; dled=0.8; // turn on display LED - //sprintf(sTemp,"Waking uC.\n"); seconds = time(NULL); t = *localtime(&seconds) ; strftime(sTemp, 40, "Waking: %a %m/%d/%Y %X\n", &t); @@ -275,7 +263,6 @@ secsNoTouch +=2; // increment to prevent double touch if (lastTouch.x>320){ i=1; - //lastTouch.x-=320; } else { i=0; } @@ -315,6 +302,7 @@ sprintf(sTemp,"Saving config file.\n"); logMsg(sTemp); saveConfig(); + spkr.beep(2000,0.25); } break; case 01: @@ -382,11 +370,6 @@ showCP=true; } display=display<1?display+1:0; // toggle display - //spkr.beep(1000,0.2); - //wait(0.25); updateDisplay(display); - //updateDisplay(1); - //spkr.beep(2000,0.2); - //wait(0.25); } //while (true) } \ No newline at end of file