test fork
Dependencies: SPI_TFTx2 SPI_TFTx2_ILI9341 TFT_fonts TOUCH_TFTx2 mbed
Fork of CANary_9341 by
Revision 22:a43df3905863, committed 2013-03-11
- Comitter:
- TickTock
- Date:
- Mon Mar 11 06:23:00 2013 +0000
- Parent:
- 21:22bdce9efcb5
- Child:
- 23:cd03f9c3395e
- Commit message:
- Fixed display LED connection. Parameterized the Touch screen controls and added routines to simplify menu creation.
Changed in this revision
--- a/common.h Fri Mar 08 04:43:24 2013 +0000 +++ b/common.h Mon Mar 11 06:23:00 2013 +0000 @@ -1,4 +1,4 @@ -#define maxScreens 7 +#define maxScreens 8 #define offScreen 0 #define logScreen 1 #define dteScreen 2 @@ -7,19 +7,9 @@ #define monitorScreen 5 #define changedScreen 6 #define cpScreen 7 +#define configScreen 8 #define upLine "\033[1A" #define maxBufLen 768 #define canTimeout 5 #define userTimeout 10 -#define btn31x1 12 -#define btn31x2 101 -#define btn32x1 115 -#define btn32x2 204 -#define btn33x1 218 -#define btn33x2 307 -#define btn31y1 12 -#define btn31y2 77 -#define btn32y1 87 -#define btn32y2 152 -#define btn33y1 162 -#define btn33y2 228 +#define btnGap 10 \ No newline at end of file
--- a/displayModes.cpp Fri Mar 08 04:43:24 2013 +0000 +++ b/displayModes.cpp Mon Mar 11 06:23:00 2013 +0000 @@ -1,6 +1,7 @@ //displayModes.cpp #include "displayModes.h" +char sTemp[16]; void printLast (bool force){ CANMessage msg; @@ -249,15 +250,19 @@ tt.foreground(Yellow); tt.background(DarkCyan); tt.set_font((unsigned char*) Arial12x12); - tt.fillrect(btn31x1,btn31y1,btn31x2,btn31y2,DarkCyan); - tt.locate(btn31x1+5,btn31y1+5); - printf(" <up>\n"); + sprintf(sTemp,"<up>"); + showButton(0,0,sTemp,3,3); + //tt.fillrect(btn31x1,btn31y1,btn31x2,btn31y2,DarkCyan); + //tt.locate(btn31x1+5,btn31y1+5); + //printf(" <up>\n"); tt.foreground(Yellow); tt.background(DarkCyan); tt.set_font((unsigned char*) Arial12x12); - tt.fillrect(btn33x1,btn31y1,btn33x2,btn31y2,DarkCyan); - tt.locate(btn33x1+5,btn31y1+5); - printf(" <down>\n"); + sprintf(sTemp,"<down>"); + showButton(2,0,sTemp,3,3); + //tt.fillrect(btn33x1,btn31y1,btn33x2,btn31y2,DarkCyan); + //tt.locate(btn33x1+5,btn31y1+5); + //printf(" <down>\n"); } break; case changedScreen: @@ -269,13 +274,14 @@ tt.foreground(Yellow); tt.background(DarkCyan); tt.set_font((unsigned char*) Arial12x12); - tt.fillrect(btn32x1,btn31y1,btn32x2,btn31y2,DarkCyan); - tt.locate(btn32x1+5,btn31y1+5); - printf(" Request\n"); - tt.locate(btn32x1+5,btn31y1+20); - printf(" CP data\n"); + sprintf(sTemp,"Request"); + showButton(1,0,sTemp,3,3); } break; + case configScreen: + printLog(changed); + //sMode=2; + break; default: tt.background(Black); tt.cls(); @@ -284,26 +290,60 @@ lastDMode[display]=dMode[display]; switch (sMode) { - case 1: + case 1: // Select screens tt.foreground(Yellow); tt.background(DarkCyan); tt.set_font((unsigned char*) Arial12x12); - tt.fillrect(btn31x1,btn33y1,btn31x2,btn33y2,DarkCyan); - tt.locate(btn31x1+5,btn33y1+5); - printf("<-Prev\n"); - tt.fillrect(btn32x1,btn33y1,btn32x2,btn33y2,DarkCyan); - tt.fillrect(btn33x1,btn33y1,btn33x2,btn33y2,DarkCyan); - tt.locate(btn33x2-50,btn33y1+5); - printf("Next->\n"); - tt.set_display(0); - tt.locate(btn32x1+15,btn33y1+5); - printf("Select %d\n",dMode[0]); - tt.set_display(1); - tt.locate(btn32x1+15,btn33y1+5); - printf("Select %d\n",dMode[1]); - tt.background(Black); + sprintf(sTemp,"<-Prev"); + showButton(0,2,sTemp,3,3); + sprintf(sTemp," Select %d",dMode[display]); + showButton(1,2,sTemp,3,3); + sprintf(sTemp," Next->"); + showButton(2,2,sTemp,3,3); break; + case 2: // numpad + tt.foreground(Yellow); + tt.background(DarkCyan); + tt.set_font((unsigned char*) Arial24x23); + sprintf(sTemp," 1"); + showButton(0,0,sTemp,4,4); + sprintf(sTemp," 2"); + showButton(1,0,sTemp,4,4); + sprintf(sTemp," 3"); + showButton(2,0,sTemp,4,4); + sprintf(sTemp," 4"); + showButton(0,1,sTemp,4,4); + sprintf(sTemp," 5"); + showButton(1,1,sTemp,4,4); + sprintf(sTemp," 6"); + showButton(2,1,sTemp,4,4); + sprintf(sTemp," 7"); + showButton(0,2,sTemp,4,4); + sprintf(sTemp," 8"); + showButton(1,2,sTemp,4,4); + sprintf(sTemp," 9"); + showButton(2,2,sTemp,4,4); + sprintf(sTemp," 0"); + showButton(1,3,sTemp,4,4); + sprintf(sTemp,"<--"); + showButton(0,3,sTemp,4,4); + sprintf(sTemp,"-->"); + showButton(2,3,sTemp,4,4); + sprintf(sTemp,"rtn"); + showButton(3,3,sTemp,4,4); + default: break; } } + +void showButton(unsigned char column, unsigned char row, char * text, unsigned char columns, unsigned char rows){ + unsigned short x1,x2,y1,y2; + x1=column*(320/columns)+btnGap/2; + x2=(column+1)*(320/columns)-btnGap/2; + y1=row*(240/rows)+btnGap/2; + y2=(row+1)*(240/rows)-btnGap/2; + tt.fillrect(x1,y1,x2,y2,DarkCyan); + tt.locate(x1+btnGap,y1+btnGap); + printf("%s\n",text); +}
--- a/displayModes.h Fri Mar 08 04:43:24 2013 +0000 +++ b/displayModes.h Mon Mar 11 06:23:00 2013 +0000 @@ -3,6 +3,7 @@ #include "TOUCH_TFTx2.h" #include "Arial12x12.h" #include "Arial12x12_prop.h" +#include "Arial24x23.h" #include "Arial28x28.h" #include "Neu42x35.h" #include "SCProSB31x55.h" @@ -29,4 +30,5 @@ void braking (bool force, bool prdata); void cpData(bool force); void updateDisplay(char display); + void showButton(unsigned char column, unsigned char row, char * text, unsigned char columns, unsigned char rows); } \ No newline at end of file
--- a/main.cpp Fri Mar 08 04:43:24 2013 +0000 +++ b/main.cpp Mon Mar 11 06:23:00 2013 +0000 @@ -2,7 +2,7 @@ //To Do: // * USB device detect -// * user programmable message decode +// * end user programmable message decode // * brake trainer // * write and read the Mode Data // * Date entry config screen (keypad) @@ -35,7 +35,7 @@ DigitalOut led3(LED3); DigitalOut led4(LED4); -PwmOut dled(p24); +PwmOut dled(p23); InterruptIn touchpad(p17); CAN can1(p9, p10); // CAN1 (EV) uses pins 9 and 10 (rx, tx) and pin 8 (rs) @@ -76,7 +76,7 @@ char sTemp[40]; unsigned long secs; char i,j,ff,display=0; - point lastTouch; + point lastTouch; can1.monitor(true); // set to snoop mode can2.monitor(true); // set to snoop mode @@ -265,7 +265,7 @@ led4=0; dled=0; // turn off display secs = time(NULL); // seconds past 12:00:00 AM 1 Jan 1900 - while (secsNoMsg>canTimeout && secsNoTouch>userTimeout) { + while (secsNoMsg>canTimeout && !touched) { //DeepPowerDown(); tt.wfi(); //enable touch interrupt //__wfi(); // freeze CPU and wait for interrupt (from canbus or touch) @@ -292,45 +292,71 @@ if(touched){ // call touchscreen procedure if touch interrupt detected lastTouch = tt.get_touch(); lastTouch = tt.to_pixel(lastTouch); // convert to pixel pos + if((lastTouch.x!=639)&&(lastTouch.x!=319)&&(lastTouch.y!=239)){ + secsNoTouch=0; //debounce + } + //sprintf(sTemp,"%d,%d ",lastTouch.x,lastTouch.y); + //logMsg(sTemp); touched = false; // clear interrupt flag } - if (!userIdle) { if (secsNoTouch<2) {// Recently touched secsNoTouch +=2; // increment to prevent double touch if (lastTouch.x>320){ i=1; - lastTouch.x-=320; + //lastTouch.x-=320; } else { i=0; } - if (lastTouch.y>btn33y1 && lastTouch.y<btn33y2) { - if(sMode==1){ - if (lastTouch.x>btn31x1 && lastTouch.x<btn31x2) { - dMode[i]=dMode[i]>0?dMode[i]-1:maxScreens; - } else if (lastTouch.x>btn32x1 && lastTouch.x<btn32x2) { - secsNoTouch = userTimeout; // immediately exit config mode - } else if (lastTouch.x>btn33x1 && lastTouch.x<btn33x2) { - dMode[i]=dMode[i]<maxScreens?dMode[i]+1:0; + //sprintf(sTemp,"button %d %d,%d %d\n",i,buttonX(lastTouch.x,3),buttonY(lastTouch.y,3),lastTouch.x); + //logMsg(sTemp); + if (buttonY(lastTouch.y,3)==2) { //bottom row + if (sMode==1) { + switch (buttonX(lastTouch.x,3)) { + case 0: + case 3: + dMode[i]=dMode[i]>0?dMode[i]-1:maxScreens; + break; + case 1: + case 4: + secsNoTouch = userTimeout; // immediately exit config mode + break; + case 2: + case 5: + dMode[i]=dMode[i]<maxScreens?dMode[i]+1:0; + break; + default: + break; } } else sMode=1; - } else if (lastTouch.y>btn31y1 && lastTouch.y<btn31y2){ - if (dMode[i]==monitorScreen||dMode[i]==changedScreen) { - if (lastTouch.x>btn31x1 && lastTouch.x<btn31x2) { - indexOffset=indexOffset>4?indexOffset-4:1; - } else if (lastTouch.x>btn32x1 && lastTouch.x<btn32x2) { - for(j=0;j<100;j++) msgChanged[j]=0; // clear changed data - lastDMode[i]=99;//force refresh - } else if (lastTouch.x>btn33x1 && lastTouch.x<btn33x2) { - indexOffset=indexOffset<77?indexOffset+4:80; - } - } else if (dMode[i]==cpScreen) { - if (lastTouch.x>btn32x1 && lastTouch.x<btn32x2){ - pollCP=true; - } + } else if (buttonY(lastTouch.y,3)==0) { // top row + switch (buttonX(lastTouch.x,3)) { + case 0: + case 3: + if (dMode[i]==monitorScreen||dMode[i]==changedScreen) { + indexOffset=indexOffset>4?indexOffset-4:1; + } + break; + case 1: + case 4: + if (dMode[i]==changedScreen) { + for(j=0;j<100;j++) msgChanged[j]=0; // clear changed data + lastDMode[i]=99;//force refresh + } else if (dMode[i]==cpScreen) { + pollCP=true; + } + break; + case 2: + case 5: + if (dMode[i]==monitorScreen||dMode[i]==changedScreen) { + indexOffset=indexOffset<77?indexOffset+4:80; + } + break; + default: + break; } - } //top of screen - } + } //top row + } //recently touched } else { // userIdle if(sMode==1){ sMode=0;
--- a/utility.cpp Fri Mar 08 04:43:24 2013 +0000 +++ b/utility.cpp Mon Mar 11 06:23:00 2013 +0000 @@ -3,6 +3,7 @@ #include "utility.h" void mbed_reset(); + void RTC_IRQHandler() { timer.reset(); // zero ms at the-seconds-tic canIdle=(++secsNoMsg>canTimeout)?true:false; @@ -25,8 +26,7 @@ void touch_ISR(){ LPC_GPIOINT->IO2IntClr = (LPC_GPIOINT->IO2IntStatR | LPC_GPIOINT->IO2IntStatF); - secsNoTouch = 0; - touched=true; + touched=true; // jsut set flag - touch screen algorythm is long and we don't want to block other interrupts } unsigned short getTimeStamp() { @@ -175,3 +175,12 @@ led2 = !led2; } +unsigned char buttonX(unsigned short X, unsigned char columns) { + unsigned char val = X*columns/320; + return val; +} + +unsigned char buttonY(unsigned short Y, unsigned char rows) { + unsigned short val = Y*rows/240; + return val; +}
--- a/utility.h Fri Mar 08 04:43:24 2013 +0000 +++ b/utility.h Mon Mar 11 06:23:00 2013 +0000 @@ -39,6 +39,8 @@ void tickerISR(); void recieve1(); void recieve2(); + unsigned char buttonX(unsigned short X, unsigned char columns); + unsigned char buttonY(unsigned short Y,unsigned char rows); } //LEAF OBD @@ -74,9 +76,9 @@ //2: NC:VIN (4.5-9V supply) //3: NC:VB //4: NC:nR -//5: SPI:CS0 -//6: SPI:CS1 -//7: SPI:Reset +//5: SPI:Reset +//6: SPI:CS0 +//7: SPI:CS1 //8: CAN1:Sleep --> 8:CAN1:RS //9: CAN1:RX --> 4:CAN1:R //10: CAN1:TX --> 1:CAN1:D @@ -91,9 +93,9 @@ //19: TOUCH_Y+ //20: TOUCH_Y- //21: Spkr+ -//22: Spkr- (optional complimentary output for more volume) -//23: NC:pwm -//24: LED +//22: NC:pwm +//23: LED +//24: NC:pwm //25: NC:pwm //26: NC:pwm //27: NC