Attempts to merge SPI_TFT2 & SPI_TFT_ILI9341
Dependencies: SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed
Fork of CANary by
Diff: main.cpp
- Revision:
- 92:935adef49ea4
- Parent:
- 91:33ab084a184f
- Child:
- 93:c2402e8cd0e2
--- a/main.cpp Mon Apr 22 02:22:04 2013 +0000 +++ b/main.cpp Mon Apr 22 02:27:37 2013 +0000 @@ -51,7 +51,7 @@ // gg - revStr is used in 2 places // gg - and is easy to edit here // gg - added ZeroSecTick and revStr -char revStr[7] = "90"; +char revStr[7] = "92"; bool debugMode = false; bool logEn = false, logOpen = false; @@ -145,7 +145,7 @@ 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, 3); //set ticker priority + NVIC_SetPriority(TIMER3_IRQn, 1); //set ticker priority NVIC_SetPriority(CAN_IRQn, 2); //higher than can (so RTC sync works) seconds = time(NULL); @@ -160,11 +160,11 @@ } t = *localtime(&seconds) ; strftime(sTemp, 32, "%a %m/%d/%Y %X\n", &t); - printMsg(sTemp); // record RTC + logMsg(sTemp); // record RTC // revision sprintf(sTemp,"CANary firmware rev%s\n", revStr); // gg - for Logging the revision - printMsg(sTemp); // revision + logMsg(sTemp); // revision // 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) @@ -172,11 +172,11 @@ lastDMode[whichTouched]=99;//force refresh if (cfile!=NULL){ //found a new binary on the thumbdrive so copy it over sprintf(sTemp,"New binary found.\n"); - printMsg(sTemp); // new binary + logMsg(sTemp); // new binary file = fopen("/local/CANary.bin", "wb"); if (file==NULL){ //failed to open destination sprintf(sTemp,"Unable to open destination file.\n"); - printMsg(sTemp); // cannot open CANary.bin + logMsg(sTemp); // cannot open CANary.bin } else { tt.set_display(2); tt.foreground(White); @@ -206,7 +206,7 @@ //read efficiency history data cfile = fopen("/local/ehist.cny", "r"); if (cfile!=NULL){ // found a efficiency history file - for(i=0;i<39;++i){ + for(i=0;i<39;i++){ if(!feof(cfile)){ fscanf(cfile,"%f %f\r\n",&mph[i],&kW[i]); mpkWh[i]=mph[i]/kW[i]; @@ -214,11 +214,11 @@ } fclose(cfile); sprintf(sTemp,"History Loaded.\n"); - printMsg(sTemp); // History loaded + logMsg(sTemp); // History loaded } else { // create initial file sprintf(sTemp,"History not found. Created.\n"); - printMsg(sTemp); // history not found, created - for(i=0;i<39;++i){ + logMsg(sTemp); // history not found, created + for(i=0;i<39;i++){ // Pre-load with 4 mpkWh @ 40 mph mph[i]=40*timeConstant[i]; kW[i]=10*timeConstant[i]; @@ -251,24 +251,24 @@ t = *localtime(&seconds) ; strftime(fileName, 32, "/usb/%m%d%H%M.alc", &t); //mmddhhmm.alc //sprintf(sTemp,"Using file %s\n",fileName); - //printMsg(sTemp); // using alc file ... + //logMsg(sTemp); // using alc file ... file = fopen(fileName, "ab"); lastDMode[whichTouched]=99;//force refresh if(file==NULL){ sprintf(sTemp,"\nUnable to open %s\n\n\n\n",fileName); - printMsg(sTemp); // cannot open alc file + logMsg(sTemp); // cannot open alc file logEn=false; spkr.beep(1000,0.25); } else { logOpen = true; readPointer=writePointer; sprintf(sTemp,"Starting Can Log %s\n",fileName); - printMsg(sTemp); // starting alc log file + logMsg(sTemp); // starting alc log file logTS(); // Date Time at start - logEventMsg("Starting"); // Log startup msg for testing + logErrMsg("Starting"); // Log startup msg for testing sprintf(sTemp,"Cr%s",revStr); - logEventMsg(sTemp); // gg - log firmware version + logErrMsg(sTemp); // gg - log firmware version spkr.beep(2000,0.25); } @@ -280,12 +280,12 @@ if (file == NULL) { logOpen = false; sprintf(sTemp,"Failed to append log file.\n"); - printMsg(sTemp); // failed to append + logMsg(sTemp); // failed to append spkr.beep(1000,0.25); logEn=false; } else { while (readPointer != writePointer) { - for (j = 0; j<13; ++j){ + for (j = 0; j<13; j++){ fprintf(file,"%c",writeBuffer[readPointer][j]); } if(++readPointer >= maxBufLen){ @@ -297,7 +297,7 @@ } // if > 1/16 full, canbus has stopped, or logging stopped if (!logEn) { sprintf(sTemp,"Stopping Can Log %s\n",fileName); - printMsg(sTemp); // stopping alc log file + logMsg(sTemp); // stopping alc log file fclose(file); logOpen=false; pointerSep=0; @@ -310,7 +310,7 @@ seconds = time(NULL); t = *localtime(&seconds) ; strftime(sTemp, 40, "Sleeping: %a %m/%d/%Y %X\n", &t); - printMsg(sTemp); // sleeping date time + logMsg(sTemp); // sleeping date time updateDisplay(0); //Added for turbo3 who has a display override and wants to see the sleep message before going to sleep updateDisplay(1); //LPC_RTC->CIIR=0x00; // block RTC interrupts @@ -333,13 +333,13 @@ seconds = time(NULL); t = *localtime(&seconds) ; strftime(sTemp, 40, "Waking: %a %m/%d/%Y %X\n", &t); - printMsg(sTemp); // wakeup date time + logMsg(sTemp); // wakeup date time if (time(NULL)>(secs+1800)) { logOpen = false; // Start new file if asleep for more than 30 minutes if (secsNoTouch>100) secsNoTouch = 100; // also mostly reset user Idle counter } else if (logOpen){ // insert timestamp on each wake if logging enabled (disabled for now) file = fopen(fileName, "ab"); - logEventMsg("WakingUp"); // gg - use messeges + logErrMsg("WakingUp"); // gg - use messeges logTS(); // Date-Time at wakeup } } // if idle @@ -366,7 +366,7 @@ sMode = 1; } //sprintf(sTemp,"%d,%d ",lastTouch.x,lastTouch.y); - //printMsg(sTemp); // touch x,y - for debug + //logMsg(sTemp); // touch x,y - for debug touched = false; // clear interrupt flag } //--------------- @@ -380,7 +380,7 @@ secsNoTouch +=2; // increment to prevent double touch sMode = 1; //sprintf(sTemp,"button %d %d,%d %d\n",i,buttonX(lastTouch.x,3),buttonY(lastTouch.y,3),lastTouch.x); - //printMsg(sTemp); // button parms - for debug + //logMsg(sTemp); // button parms - for debug switch (sMode) { case 0: // no select break; @@ -420,7 +420,7 @@ //----------------------------------------------- case 10: // 1,0 (col left of center,top row) on screen 0 or 1 if (dMode[whichTouched]==changedScreen) { - for(j=0;j<100;++j) msgChanged[j]=0; // clear changed data + for(j=0;j<100;j++) msgChanged[j]=0; // clear changed data lastDMode[whichTouched]=99;//force refresh } else if (dMode[whichTouched] == indexScreen) { // gg - index sMode=0; @@ -457,7 +457,7 @@ sMode=0; } else if (dMode[whichTouched]==config1Screen) { sprintf(sTemp,"Saving config file.\n"); - printMsg(sTemp); // saving config + logMsg(sTemp); // saving config saveConfig(); spkr.beep(2000,0.25); } else if (dMode[whichTouched]==playbackScreen) { // faster @@ -487,7 +487,7 @@ lastDMode[whichTouched ^ 1]=99; // repaint other screen (^ = XOR) //sprintf(sTemp,"Changed Skin to %d.\n"); - //printMsg(sTemp); /// changed skin - for debug + //logMsg(sTemp); /// changed skin - for debug //saveConfig(); //spkr.beep(2000,0.25); @@ -539,21 +539,21 @@ lastDMode[whichTouched]=99;//force refresh if(file==NULL){ sprintf(sTemp,"Unable to open /usb/playback.alc\n"); - printMsg(sTemp); // no playback.alc + logMsg(sTemp); // no playback.alc spkr.beep(1000,0.25); } else { playbackOpen = true; playbackEn=true; playback.attach(&playbackISR,playbackInt); sprintf(sTemp,"Starting playback\n"); - printMsg(sTemp); // start playback + logMsg(sTemp); // start playback spkr.beep(2000,0.25); can1.attach(&doNothing);// Stop recieving CAN data can2.attach(&doNothing); } } else { sprintf(sTemp,"Must stop logging first\n"); - printMsg(sTemp); // Must stop logging first + logMsg(sTemp); // Must stop logging first } } else { playback.detach(); @@ -676,14 +676,13 @@ } if(tick){ // Executes once a second - headlights = (lastMsg[indexLastMsg[0x358]].data[1]&0x80)?true:false; // headlight/turn signal indicator accV=floor(mon12V*scale12V*10+0.5)/10; //Round to nearest 10th accOn=(accV>5)?true:false; if(laccOn&&!accOn){ // Car turned off //write efficiency history data cfile = fopen("/local/ehist.cny", "w"); if (cfile!=NULL){ // found a efficiency history file - for(i=0;i<39;++i){ + for(i=0;i<39;i++){ fprintf(cfile,"%f %f\r\n",mph[i],kW[i]); } fclose(cfile); @@ -692,7 +691,7 @@ laccOn=accOn; if(!accOn&&!logEn&&userIdle&&!playbackEn){ //sprintf(sTemp,"Display Off %4.2f\n",accV); - //printMsg(sTemp); // display off - for debug + //logMsg(sTemp); // display off - for debug dled = 0; // turn off display if car off and logging disabled and no user activity }else if(!headlights){ @@ -727,7 +726,7 @@ mWs_x4=0; numWsamples=0; if(accOn||playbackEn){ - for(i=1;i<39;++i){ + for(i=1;i<39;i++){ average=mph[i]/timeConstant[i]; mph[i]-=average; mph[i]+=mph[0]; @@ -746,7 +745,7 @@ if(logCP) logPackVoltages(); // Turbo3, only call tick=false; - }// tick + } display=display<1?display+1:0; // toggle display updateDisplay(display); @@ -760,7 +759,7 @@ if(step){ // playback if(playbackOpen&&playbackEn){ - for(i=0;i<120;++i){ + for(i=0;i<120;i++){ if(!feof(file)){ fscanf(file,"%5c%8c",&header,&data); logCan(header[0],CANMessage(0x7ff&((header[4]<<8)+header[3]), data, 8)); // Playback