Attempts to merge SPI_TFT2 & SPI_TFT_ILI9341

Dependencies:   SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed

Fork of CANary by Tick Tock

Branch:
Metric
Revision:
116:5cd72bae7c12
Parent:
115:549410af477d
Child:
117:49883c779a74
diff -r 549410af477d -r 5cd72bae7c12 main.cpp
--- a/main.cpp	Thu Jul 04 00:09:28 2013 +0000
+++ b/main.cpp	Thu Jul 04 05:27:15 2013 +0000
@@ -24,7 +24,7 @@
 #include "displayModes.h"
 #include "TOUCH_TFTx2.h"
 
-char revStr[7] = "115"; // gg - revision string, max 6 characters
+char revStr[7] = "116"; // gg - revision string, max 6 characters
 
 FATFS USBdrive;
 LocalFileSystem local("local");
@@ -45,6 +45,8 @@
 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)
@@ -110,7 +112,6 @@
 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];
@@ -150,15 +151,20 @@
     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(TIMER3_IRQn, 3); //set ticker priority just below can
-
+    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
+   
     seconds = time(NULL);
     t = *localtime(&seconds) ;
     // is it a date before 2012 ?
@@ -176,8 +182,6 @@
     // revision
     sprintf(sTemp,"CANary firmware rev%s\n", revStr); // gg - for Logging the revision
     printMsg(sTemp); // revision
-    //sprintf(sTemp,"free clusters = %d\n", freeClusters);
-    //printMsg(sTemp); // revision
 
     secsNoMsg = 0;
 
@@ -191,11 +195,9 @@
             }
         }
         fclose(hfile);
-        sprintf(sTemp,"History Loaded.\n");
-        printMsg(sTemp); // History loaded
+        printMsg("History Loaded.\n"); // History loaded
     } else { // create initial file
-        sprintf(sTemp,"History not found.  Created.\n");
-        printMsg(sTemp); // history not found, created
+        printMsg("History not found.  Created.\n"); // history not found, created
         for(i=0;i<39;i++){
             // Pre-load with 4 mpkWh @ 40 mph
             mph[i]=40*timeConstant[i];
@@ -252,34 +254,14 @@
                 }
             }//logging enabled and USB detected
         } else { // if (logOpen)
-            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;
-                    sprintf(sTemp,"Failed to append log file.\n");
-                    printMsg(sTemp); // 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 (canIdle||!logEn) {
+                swInt=1; //trigger buffer dump ISR
+            } // if 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;
             }
@@ -448,8 +430,7 @@
                                     dMode[whichTouched] = effScreen ; // GoTo EFF Screen
                                     sMode=0;
                                 } else if (dMode[whichTouched]==configScreen) {
-                                    sprintf(sTemp,"Saving config file.\n");
-                                    printMsg(sTemp); // saving config
+                                    printMsg("Saving config file.\n"); // saving config
                                     saveConfig();
                                     spkr.beep(2000,0.25);
                                 } else if (dMode[whichTouched]==playbackScreen) { // faster
@@ -520,22 +501,19 @@
                                             efr = f_open(&efile,"playback.alc",FA_READ|FA_OPEN_EXISTING);
                                             lastDMode[whichTouched]=99;//force refresh
                                             if(efr != FR_OK){
-                                                sprintf(sTemp,"Unable to open /usb/playback.alc\n");
-                                                printMsg(sTemp); // no playback.alc
+                                                printMsg("Unable to open /usb/playback.alc\n"); // 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
+                                                printMsg("Starting playback\n"); // 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
+                                            printMsg("Must stop logging first\n"); // Must stop logging first
                                         }
                                     } else {
                                         playback.detach();