Dual CANbus monitor and instrumentation cluster supporting ILI9341 display controller
Dependencies: SPI_TFTx2_ILI9341 TOUCH_TFTx2_ILI9341 TFT_fonts mbed
Fork of CANary by
Revision 31:082372c83f68, committed 2013-03-17
- Comitter:
- TickTock
- Date:
- Sun Mar 17 12:17:33 2013 +0000
- Parent:
- 30:e633a63eb257
- Child:
- 32:c9d9b6cb5de1
- Commit message:
- Removed wait_ms() on cellpair request so prevent blocking in log
Changed in this revision
--- a/common.h Sat Mar 16 16:33:11 2013 +0000 +++ b/common.h Sun Mar 17 12:17:33 2013 +0000 @@ -11,6 +11,6 @@ #define maxScreens 9 #define btnGap 10 -#define maxBufLen 768 +#define maxBufLen 512 #define canTimeout 5 #define userTimeout 10
--- a/main.cpp Sat Mar 16 16:33:11 2013 +0000 +++ b/main.cpp Sun Mar 17 12:17:33 2013 +0000 @@ -65,7 +65,8 @@ volatile bool userIdle; bool touched=false; //flag to read touchscreen char counter = 0; -unsigned char dMode[2] = {dteScreen,brakeScreen}; //display mode +//unsigned char dMode[2] = {dteScreen,brakeScreen}; //display mode +unsigned char dMode[2] = {cpScreen,logScreen}; //display mode unsigned char sMode = 0; // setup mode unsigned char lastDMode[2] = {0,0}; //last screen mode unsigned char dtMode = 6; @@ -73,7 +74,9 @@ unsigned char displayLoc = 0; unsigned char indexOffset = 1; bool showCP = false; -bool pollCP = false; +bool tick16 = false; +unsigned char CPcount = 99; +unsigned char Tcount = 99; int main() { int readPointer=0; @@ -105,7 +108,8 @@ 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) - + //ticker.attach(&tickerISR, 0.016); //send commands at 16ms rate + ticker.attach(&msgSend, 0.016); //send commands at 16ms rate seconds = time(NULL); t = *localtime(&seconds) ; @@ -293,7 +297,10 @@ for(j=0;j<100;j++) msgChanged[j]=0; // clear changed data lastDMode[i]=99;//force refresh } else if (dMode[i]==cpScreen) { - pollCP=true; + if (Tcount>3){ + CPcount=0; //reset CP message counter + Tcount=0; //reset Temp message counter + } } else if (dMode[i]==config1Screen) { mbed_reset(); } @@ -365,15 +372,13 @@ } } - 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 - wait_ms(16); - pollCP=false; - showCP=true; - } - display=display<1?display+1:0; // toggle display - updateDisplay(display); + if (Tcount>4){ + display=display<1?display+1:0; // toggle display + updateDisplay(display); + }/* else if(tick16){ // We do this inside main loop instead of ticker so CAN RX will not be blocked + msgSend(); + tick16=false; + }*/ + } //while (true) } \ No newline at end of file
--- a/utility.cpp Sat Mar 16 16:33:11 2013 +0000 +++ b/utility.cpp Sun Mar 17 12:17:33 2013 +0000 @@ -11,7 +11,7 @@ LPC_RTC->ILR |= (1<<0); // clear interrupt to prepare for next } -extern "C" void RTC_Init (void) { +void RTC_Init (void) { LPC_RTC->ILR=0x00; // set up the RTC interrupts LPC_RTC->CIIR=0x01; // interrupts each second LPC_RTC->CCR = 0x01; // Clock enable @@ -155,9 +155,55 @@ can1.monitor(true); // set to snoop mode } +void msgSend() { + //char sTemp[40]; + char data[8] = {0x02, 0x21, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff}; + if (CPcount<30) { + switch (CPcount) { + case 0: + can1.monitor(false); // set to active mode + can1SleepMode = 0; // enable TX + //data[8] = {0x02, 0x21, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff}; + data[2] = 0x02; + //sprintf(sTemp,"Sending cp request\n"); + //logMsg(sTemp); + break; + default: + data[0]=0x30; //change to request next line message + data[1]=0x01; + data[2]=0x00; + break; + } + can1.write(CANMessage(0x79b, data, 8)); + CPcount+=1; + } else if (Tcount<4) { + switch (Tcount) { + case 0: + //data[8] = {0x02, 0x21, 0x04, 0xff, 0xff, 0xff, 0xff, 0xff}; + data[2] = 0x04; + //sprintf(sTemp,"Sending temp request\n"); + //logMsg(sTemp); + break; + default: + data[0]=0x30; //change to request next line message + data[1]=0x01; + data[2]=0x00; + break; + } + can1.write(CANMessage(0x79b, data, 8)); + Tcount+=1; + } else if (Tcount<5){ + showCP=true; + Tcount+=1; + can1SleepMode = 1; // disable TX + can1.monitor(true); // set to snoop mode + } +} + void tickerISR() { //This is the ticker ISR for auto-polling - pollCP=true; //Set a flag to do in main loop instead of here -} //since ticker blocks other interrupts + CPcount=0; //reset CP message counter + Tcount=0; //reset Temp message counter +} void recieve1() { CANMessage msg1;
--- a/utility.h Sat Mar 16 16:33:11 2013 +0000 +++ b/utility.h Sun Mar 17 12:17:33 2013 +0000 @@ -24,8 +24,11 @@ extern CANMessage lastMsg[100]; extern CAN can1,can2; extern DigitalOut can1SleepMode,can2SleepMode; -extern bool pollCP; +extern bool showCP; +extern bool tick16; extern TOUCH_TFTx2 tt; +extern unsigned char CPcount; +extern unsigned char Tcount; extern "C" { void mbed_reset(); @@ -39,6 +42,7 @@ void sendCPreq(); void sendTreq(); void tickerISR(); + void msgSend(); void recieve1(); void recieve2(); unsigned char buttonX(unsigned short X, unsigned char columns);