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:
- 15:a359fecf85ba
- Parent:
- 13:62e0f7f39ff5
- Child:
- 16:2a6ca248e1cb
diff -r 736a5e9650c5 -r a359fecf85ba main.cpp --- a/main.cpp Sun Mar 03 17:14:15 2013 +0000 +++ b/main.cpp Sun Mar 03 18:06:53 2013 +0000 @@ -47,7 +47,7 @@ TOUCH_TFTx2 tt(p16, p17, p19, p20, p11, p12, p13, p6, p7, p5, "TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs0, cs1, reset bool logEn = true,logOpen = false; -FILE *rfile; +FILE *cfile; FILE *file; char fileName[35] = "" ; char writeBuffer[maxBufLen][13]; // buffer for USB write @@ -92,11 +92,11 @@ tt.background(Black); tt.cls(); tt.set_display(0); // select left display - if(true){ // bypass calibration - tt.setcal(5570, 34030, 80, 108, 33700, 5780, 82, 108, 32500); - } else { // calibrate the touch - tt.calibrate(); - } + //if(true){ // bypass calibration + // tt.setcal(5570, 34030, 80, 108, 33700, 5780, 82, 108, 32500); + //} else { // calibrate the touch + // tt.calibrate(); + //} tt.claim(stdout); // send stdout to the TFT display touchpad.rise(&touch_ISR); tt.wfi(); // enable interrupt on touch @@ -137,6 +137,34 @@ // strftime(sTemp, 32, "%a %m/%d/%Y %X", localtime(&seconds)); // printf("%s\n", sTemp); // DAY MM/DD/YYYY HH:MM:SS } + + // Look for config file + cfile = fopen("/local/config.txt", "r"); + if (cfile==NULL){ // if doesn't exist --> create + tt.calibrate(); + cfile = fopen("/local/config.txt", "w"); + fprintf(cfile,"x0_off %d\r\n",tt.x0_off); + fprintf(cfile,"y0_off %d\r\n",tt.y0_off); + fprintf(cfile,"x0_pp %d\r\n",tt.x0_pp); + fprintf(cfile,"y0_pp %d\r\n",tt.y0_pp); + fprintf(cfile,"x1_off %d\r\n",tt.x1_off); + fprintf(cfile,"y1_off %d\r\n",tt.y1_off); + fprintf(cfile,"x1_pp %d\r\n",tt.x1_pp); + fprintf(cfile,"y1_pp %d\r\n",tt.y1_pp); + fprintf(cfile,"x_mid %d\r\n",tt.x_mid); + } else { // read params + fscanf(cfile, "x0_off %d\r\n", &tt.x0_off ) ; + fscanf(cfile, "y0_off %d\r\n", &tt.y0_off ) ; + fscanf(cfile, "x0_pp %d\r\n", &tt.x0_pp ) ; + fscanf(cfile, "y0_pp %d\r\n", &tt.y0_pp ) ; + fscanf(cfile, "x1_off %d\r\n", &tt.x1_off ) ; + fscanf(cfile, "y1_off %d\r\n", &tt.y1_off ) ; + fscanf(cfile, "x1_pp %d\r\n", &tt.x1_pp ) ; + fscanf(cfile, "y1_pp %d\r\n", &tt.y1_pp ) ; + fscanf(cfile, "x_mid %d\r\n", &tt.x_mid ) ; + } + fclose(cfile); + //ticker.attach(&tickerISR, 60); //poll cellpair data every minute while (true) { if (!logOpen) { // Open new file if one is not already open @@ -162,7 +190,7 @@ spkr.beep(2000,0.2); } }//logging enabled - } else { // if (!logOpen) + } else { // if (logOpen) if (((writePointer+maxBufLen-readPointer)%maxBufLen)>(maxBufLen/16)||canIdle) { // Dump buffer if > 1/16 full or canbus has stopped if (file == NULL) { @@ -217,11 +245,12 @@ } } // if idle - if(touched){ + if(touched){ // call touchscreen procedure if touch interrupt detected lastTouch = tt.get_touch(); lastTouch = tt.to_pixel(lastTouch); // convert to pixel pos touched = false; // clear interrupt flag } + if (!userIdle) { if (secsNoTouch<2) {// Recently touched secsNoTouch +=2; // increment to prevent double touch @@ -265,7 +294,8 @@ lastDMode[1]=99; } } - if(pollCP){ + + if(pollCP){ // We do this inside main loop instead of ticker so CAN RX will not be blocked sendCPreq(); // send cellpair data request. wait_ms(16); sendTreq(); //send temperature request @@ -273,8 +303,8 @@ pollCP=false; showCP=true; } + display=display<1?display+1:0; // toggle display updateDisplay(display); - //wait(0.1); // We get >2K messages per second } //while (true) } \ No newline at end of file