Shish
Dependencies: mbed USBDevice GLCD
Diff: main.cpp
- Revision:
- 1:a32ccf18194d
- Parent:
- 0:9ae27a35a771
- Child:
- 2:4b3d056967a8
--- a/main.cpp Thu May 06 17:35:37 2021 +0000 +++ b/main.cpp Thu May 06 21:32:23 2021 +0000 @@ -5,7 +5,8 @@ #include "HzLib.c" #include "USBSerial.h" #include "TouchPanel.h" -#include <vector> + +//#define DEBUG //FUNZIONI GIORGIO void readtouch(); @@ -21,6 +22,8 @@ int threshold = 32; USBSerial serial; +int charPos; + /*Buttons*/ typedef enum {space,infer,del} button; @@ -33,10 +36,13 @@ void drawButton(button b, uint16_t color); void start(void); void drawTriangle(int posX, int posY, int lungMax); +void readTouch(void); int main() { LCD_Initialization(); TP_Init(); + TouchPanel_Calibrate(); + LCD_Clear(Blue2); clearBar(); @@ -44,9 +50,8 @@ start(); while(1){ - readtouch(); - serial.printf("%u %u\n", tocco.x, tocco.y); - wait(1); + readTouch(); + wait_us(500); } } @@ -236,4 +241,123 @@ } else ready=0; +} + +void readTouch(){ + int i,j; + Coordinate p; + getDisplayPoint(&display, Read_Ads7846(), &matrix ) ; //resto in attesa di un punto che venga toccato + if(display.x <= 240 && display.x > 0){ + if(display.y >= 52 && display.y <= 275 && display.x >=8 && display.x <= 232){//punto in zona alta (start writing) + if(!startGame){ + startGame=1; + clearPad(); + charPos=0; + } + else{//game already started: handwriting input + if(charPos<26*8){ //topbar bound: otherwise the topbar is full + #ifdef DEBUG + if(!isWritten) + clearPad();//clear to delete the testing result printed on screen before + #endif + isWritten=1; + p.x=display.x-8; + p.y=display.y-52; + for(i=-1;i<2;i++) + for(j=-1;j<2;j++){ + if((p.x+i)>=0&&(p.y+j)>=0&&(p.x+i)<224&&(p.y+j)<224){ + TP_DrawPoint(display.x+i,display.y+j); + drawnPoints[(p.x+i)/8][(p.y+j)/8]++; //count +1 for the macrocell containing this pixel + } + } + } + } + } + else{ + if(display.y >= 283 && display.y <= 315 && display.x >=8 && display.x <= 87 && startGame && !isWritten && !inferenceStarted){//punto in tasto Space + if(charPos<26*8){ //topbar bound: otherwise the topbar is full + drawButton(space,Yellow); + + //space operation: writing a whitespace into the topbar + + //--TO BE COMPLETED--// + if(charPos!=0) + LCD_DrawLine(15+charPos-8, 35, 15+charPos+8-8, 35, White); //delete last cursor + GUI_Text(15+charPos, 20, (uint8_t *)" ", Black, White,1); //testing space on topbar + LCD_DrawLine(15+charPos, 35, 15+charPos+8, 35, Black); //cursor + charPos+=8; + + clearPad(); //useful only to see the same response time of the other buttons + + drawButton(space,White); + } + } + else{ + if(display.y >= 283 && display.y <= 315 && display.x >=100 && display.x <= 139 && startGame && isWritten &&!inferenceStarted){//punto in tasto Infer + //wait flag to able + + drawButton(infer,Yellow); + + inferenceStarted=1; + //infer operation: compress the matrix and send the final 28x28 matrix to the inference step + + //--TO BE COMPLETED--// + for(i=0;i<28;i++) //if the counter of the macrocell is greater than threshold, set the final cell to 1, otherwise it would be a 0-cell + for(j=0;j<28;j++) + drawnPoints[i][j]=drawnPoints[i][j]>=threshold?1:0; + + #ifdef DEBUG + showCompression(); + if(charPos!=0) + LCD_DrawLine(15+charPos-8, 35, 15+charPos+8-8, 35, White); //delete last cursor + GUI_Text(15+charPos, 20, (uint8_t *)"T", Black, White,1); //testing text on topbar + LCD_DrawLine(15+charPos, 35, 15+charPos+8, 35, Black); //cursor + charPos+=8; + #else + clearPad(); //here the matix is also cleaned + serial.printf("-1"); + for(i=0;i<28;i++) + for(j=0;j<28;j++) + serial.printf("%d",drawnPoints[i][j]); + #endif + + isWritten=0; + inferenceStarted=0; + + + drawButton(infer,White); + } + else{ + if(display.y >= 283 && display.y <= 315 && display.x >=153 && display.x <= 232 && startGame &&!inferenceStarted){//punto in tasto Delete + //wait flag to able + + drawButton(del,Yellow); + + if(isWritten){ //delete operation - handwriting on pad, before inference: clear the pad + clearPad(); + isWritten=0; + } + else{ //delete operation - no handwriting on pad, after inference: delete last char printed on the topbar + //--TO BE COMPLETED--// + clearPad(); //useful only to see the same response time of the other cases + if(charPos!=0){ + LCD_DrawLine(15+charPos-8, 35, 15+charPos+8-8, 35, White); //delete last cursor + GUI_Text(15+charPos-8, 20, (uint8_t *)" ", Black, White,1); //testing text on topbar + if(charPos!=8){ //otherwise we are going to the first character, no cursor + LCD_DrawLine(15+charPos-16, 35, 15+charPos-8, 35, Black); //cursor + } + charPos-=8; + } + } + + drawButton(del,White); + } + } + } + } + } + else{ + //do nothing if touch returns values out of bounds + } + return; } \ No newline at end of file