Shish

Dependencies:   mbed USBDevice GLCD

Committer:
protopapaandrea
Date:
Fri Jul 30 09:51:38 2021 +0000
Revision:
4:fc3364c83df6
Parent:
3:2bf723da1732
Child:
5:2dce07562de8
modified line thickness (for each picked pixel -> 3x3 matrix)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
montie97 0:9ae27a35a771 1 #include "mbed.h"
montie97 0:9ae27a35a771 2 #include "GLCD.h"
montie97 0:9ae27a35a771 3 #include "GLCD.c"
montie97 0:9ae27a35a771 4 #include "AsciiLib.c"
montie97 0:9ae27a35a771 5 #include "HzLib.c"
montie97 0:9ae27a35a771 6 #include "USBSerial.h"
montie97 0:9ae27a35a771 7 #include "TouchPanel.h"
protopapaandrea 1:a32ccf18194d 8
pepperu96 2:4b3d056967a8 9 #define DEBUG
montie97 0:9ae27a35a771 10
montie97 0:9ae27a35a771 11 //FUNZIONI GIORGIO
montie97 0:9ae27a35a771 12 void readtouch();
montie97 0:9ae27a35a771 13
montie97 0:9ae27a35a771 14 //VARIABILI GIORGIO
montie97 0:9ae27a35a771 15 Coordinate tocco;
montie97 0:9ae27a35a771 16 int x,y,k,avg_x,avg_y,ready;
montie97 0:9ae27a35a771 17
montie97 0:9ae27a35a771 18 int startGame=0;
montie97 0:9ae27a35a771 19 int isWritten=0;
montie97 0:9ae27a35a771 20 int inferenceStarted=0;
montie97 0:9ae27a35a771 21 uint8_t drawnPoints[28][28];
protopapaandrea 4:fc3364c83df6 22 uint8_t finalMatrix[28][28];
protopapaandrea 4:fc3364c83df6 23 int threshold = 16;
montie97 0:9ae27a35a771 24 USBSerial serial;
montie97 0:9ae27a35a771 25
protopapaandrea 1:a32ccf18194d 26 int charPos;
protopapaandrea 1:a32ccf18194d 27
montie97 0:9ae27a35a771 28 /*Buttons*/
montie97 0:9ae27a35a771 29 typedef enum {space,infer,del} button;
montie97 0:9ae27a35a771 30
montie97 0:9ae27a35a771 31 /* Private function prototypes -----------------------------------------------*/
montie97 0:9ae27a35a771 32 void spaceText(int x1, int x2, int yText, int spessore, uint16_t color);
montie97 0:9ae27a35a771 33 void clearPad(void);
montie97 0:9ae27a35a771 34 void showCompression(void);
montie97 0:9ae27a35a771 35 void clearBar(void);
montie97 0:9ae27a35a771 36 void drawButtons(void);
montie97 0:9ae27a35a771 37 void drawButton(button b, uint16_t color);
montie97 0:9ae27a35a771 38 void start(void);
montie97 0:9ae27a35a771 39 void drawTriangle(int posX, int posY, int lungMax);
protopapaandrea 1:a32ccf18194d 40 void readTouch(void);
montie97 0:9ae27a35a771 41
montie97 0:9ae27a35a771 42 int main() {
montie97 0:9ae27a35a771 43 LCD_Initialization();
montie97 0:9ae27a35a771 44 TP_Init();
protopapaandrea 1:a32ccf18194d 45 TouchPanel_Calibrate();
protopapaandrea 1:a32ccf18194d 46
montie97 0:9ae27a35a771 47 LCD_Clear(Blue2);
montie97 0:9ae27a35a771 48
montie97 0:9ae27a35a771 49 clearBar();
montie97 0:9ae27a35a771 50 drawButtons();
montie97 0:9ae27a35a771 51 start();
montie97 0:9ae27a35a771 52
montie97 0:9ae27a35a771 53 while(1){
protopapaandrea 1:a32ccf18194d 54 readTouch();
protopapaandrea 1:a32ccf18194d 55 wait_us(500);
montie97 0:9ae27a35a771 56 }
montie97 0:9ae27a35a771 57 }
montie97 0:9ae27a35a771 58
montie97 0:9ae27a35a771 59 /*******************************************************************************
montie97 0:9ae27a35a771 60 * Function Name : spaceText
montie97 0:9ae27a35a771 61 * Description :
montie97 0:9ae27a35a771 62 * Input : None
montie97 0:9ae27a35a771 63 * Output : None
montie97 0:9ae27a35a771 64 * Return : None
montie97 0:9ae27a35a771 65 * Attention : None
montie97 0:9ae27a35a771 66 *******************************************************************************/
montie97 0:9ae27a35a771 67 void spaceText(int x1, int x2, int yText, int spessore, uint16_t color){ //Spazio di un unico colore
montie97 0:9ae27a35a771 68 int i;
montie97 0:9ae27a35a771 69 for(i=spessore;i>0;i--){
montie97 0:9ae27a35a771 70 LCD_DrawLine(x1,yText-i,x2,yText-i,color);
montie97 0:9ae27a35a771 71 }
montie97 0:9ae27a35a771 72 return;
montie97 0:9ae27a35a771 73 }
montie97 0:9ae27a35a771 74
montie97 0:9ae27a35a771 75 /*******************************************************************************
montie97 0:9ae27a35a771 76 * Function Name : clearPad
montie97 0:9ae27a35a771 77 * Description :
montie97 0:9ae27a35a771 78 * Input : None
montie97 0:9ae27a35a771 79 * Output : None
montie97 0:9ae27a35a771 80 * Return : None
montie97 0:9ae27a35a771 81 * Attention : None
montie97 0:9ae27a35a771 82 *******************************************************************************/
montie97 0:9ae27a35a771 83 void clearPad(){
montie97 0:9ae27a35a771 84 int i,j;
montie97 0:9ae27a35a771 85 for(i=0;i<224;i++){
montie97 0:9ae27a35a771 86 LCD_DrawLine(8,52+i,232,52+i,White);
montie97 0:9ae27a35a771 87 }
montie97 0:9ae27a35a771 88 for(i=0;i<28;i++) //also clear the matrix
protopapaandrea 4:fc3364c83df6 89 for(j=0;j<28;j++){
montie97 0:9ae27a35a771 90 drawnPoints[i][j]=0;
protopapaandrea 4:fc3364c83df6 91 finalMatrix[i][j]=0;
protopapaandrea 4:fc3364c83df6 92 }
montie97 0:9ae27a35a771 93
montie97 0:9ae27a35a771 94 return;
montie97 0:9ae27a35a771 95 }
montie97 0:9ae27a35a771 96
montie97 0:9ae27a35a771 97 /*******************************************************************************
montie97 0:9ae27a35a771 98 * Function Name : showCompression
montie97 0:9ae27a35a771 99 * Description :
montie97 0:9ae27a35a771 100 * Input : None
montie97 0:9ae27a35a771 101 * Output : None
montie97 0:9ae27a35a771 102 * Return : None
montie97 0:9ae27a35a771 103 * Attention : None
montie97 0:9ae27a35a771 104 *******************************************************************************/
montie97 0:9ae27a35a771 105 void showCompression(){
montie97 0:9ae27a35a771 106 int i,j;
montie97 0:9ae27a35a771 107 for(i=0;i<224;i++){ //clean the pad
montie97 0:9ae27a35a771 108 LCD_DrawLine(8,52+i,232,52+i,White);
montie97 0:9ae27a35a771 109 }
montie97 0:9ae27a35a771 110 for(i=0;i<28;i++)
montie97 0:9ae27a35a771 111 for(j=0;j<28;j++)
protopapaandrea 4:fc3364c83df6 112 if(finalMatrix[i][j]==1)
montie97 0:9ae27a35a771 113 LCD_SetPoint(i+110,j+150,Black);
montie97 0:9ae27a35a771 114
montie97 0:9ae27a35a771 115 return;
montie97 0:9ae27a35a771 116 }
montie97 0:9ae27a35a771 117
montie97 0:9ae27a35a771 118 /*******************************************************************************
montie97 0:9ae27a35a771 119 * Function Name : clearBar
montie97 0:9ae27a35a771 120 * Description :
montie97 0:9ae27a35a771 121 * Input : None
montie97 0:9ae27a35a771 122 * Output : None
montie97 0:9ae27a35a771 123 * Return : None
montie97 0:9ae27a35a771 124 * Attention : None
montie97 0:9ae27a35a771 125 *******************************************************************************/
montie97 0:9ae27a35a771 126 void clearBar(){
montie97 0:9ae27a35a771 127 int i;
montie97 0:9ae27a35a771 128 for(i=0;i<32;i++){
montie97 0:9ae27a35a771 129 LCD_DrawLine(8,10+i,232,10+i,White);
montie97 0:9ae27a35a771 130 }
montie97 0:9ae27a35a771 131 return;
montie97 0:9ae27a35a771 132 }
montie97 0:9ae27a35a771 133
montie97 0:9ae27a35a771 134 /*******************************************************************************
montie97 0:9ae27a35a771 135 * Function Name : drawButton
montie97 0:9ae27a35a771 136 * Description :
montie97 0:9ae27a35a771 137 * Input : None
montie97 0:9ae27a35a771 138 * Output : None
montie97 0:9ae27a35a771 139 * Return : None
montie97 0:9ae27a35a771 140 * Attention : None
montie97 0:9ae27a35a771 141 *******************************************************************************/
montie97 0:9ae27a35a771 142 void drawButton(button b, uint16_t color){
montie97 0:9ae27a35a771 143 int i;
montie97 0:9ae27a35a771 144 switch(b){
montie97 0:9ae27a35a771 145 case space: //Space Button
montie97 0:9ae27a35a771 146 spaceText(8,87,291,8,color);
montie97 0:9ae27a35a771 147 GUI_Text(8, 291, (uint8_t *) " Space ", Blue, color,1);
montie97 0:9ae27a35a771 148 spaceText(8,87,291+16+8,8,color);
montie97 0:9ae27a35a771 149 break;
montie97 0:9ae27a35a771 150 case infer: //Infer Button
montie97 0:9ae27a35a771 151 for(i=0;i<32;i++){
montie97 0:9ae27a35a771 152 LCD_DrawLine(100,283+i,139,283+i,color);
montie97 0:9ae27a35a771 153 }
montie97 0:9ae27a35a771 154 drawTriangle(112,289,10);
montie97 0:9ae27a35a771 155 break;
montie97 0:9ae27a35a771 156 case del: //Delete Button
montie97 0:9ae27a35a771 157 spaceText(153,232,291,8,color);
montie97 0:9ae27a35a771 158 GUI_Text(153, 291, (uint8_t *) " Delete ", Blue, color,1);
montie97 0:9ae27a35a771 159 spaceText(153,232,291+16+8,8,color);
montie97 0:9ae27a35a771 160 break;
montie97 0:9ae27a35a771 161 default:
montie97 0:9ae27a35a771 162 break;
montie97 0:9ae27a35a771 163 }
montie97 0:9ae27a35a771 164 return;
montie97 0:9ae27a35a771 165 }
montie97 0:9ae27a35a771 166
montie97 0:9ae27a35a771 167 /*******************************************************************************
montie97 0:9ae27a35a771 168 * Function Name : drawButtons
montie97 0:9ae27a35a771 169 * Description :
montie97 0:9ae27a35a771 170 * Input : None
montie97 0:9ae27a35a771 171 * Output : None
montie97 0:9ae27a35a771 172 * Return : None
montie97 0:9ae27a35a771 173 * Attention : None
montie97 0:9ae27a35a771 174 *******************************************************************************/
montie97 0:9ae27a35a771 175 void drawButtons(){
montie97 0:9ae27a35a771 176 drawButton(space,White);
montie97 0:9ae27a35a771 177 drawButton(infer,White);
montie97 0:9ae27a35a771 178 drawButton(del,White);
montie97 0:9ae27a35a771 179 return;
montie97 0:9ae27a35a771 180 }
montie97 0:9ae27a35a771 181
montie97 0:9ae27a35a771 182 /*******************************************************************************
montie97 0:9ae27a35a771 183 * Function Name : drawTriangle
montie97 0:9ae27a35a771 184 * Description :
montie97 0:9ae27a35a771 185 * Input : None
montie97 0:9ae27a35a771 186 * Output : None
montie97 0:9ae27a35a771 187 * Return : None
montie97 0:9ae27a35a771 188 * Attention : None
montie97 0:9ae27a35a771 189 *******************************************************************************/
montie97 0:9ae27a35a771 190 void drawTriangle(int posX, int posY, int lungMax){
montie97 0:9ae27a35a771 191 int i;
montie97 0:9ae27a35a771 192 uint16_t color=Green2;
montie97 0:9ae27a35a771 193 for(i=0;i<lungMax;i++){ //Direction EAST
montie97 0:9ae27a35a771 194 LCD_DrawLine(posX+5,posY+i+1,posX+5+i,posY+i+1,color);
montie97 0:9ae27a35a771 195 }
montie97 0:9ae27a35a771 196 for(i=0;i<lungMax-1;i++){
montie97 0:9ae27a35a771 197 LCD_DrawLine(posX+5,posY+lungMax+i+1,posX+5+(lungMax-2)-i,posY+lungMax+i+1,color);
montie97 0:9ae27a35a771 198 }
montie97 0:9ae27a35a771 199 }
montie97 0:9ae27a35a771 200
montie97 0:9ae27a35a771 201 /*******************************************************************************
montie97 0:9ae27a35a771 202 * Function Name : start
montie97 0:9ae27a35a771 203 * Description :
montie97 0:9ae27a35a771 204 * Input : None
montie97 0:9ae27a35a771 205 * Output : None
montie97 0:9ae27a35a771 206 * Return : None
montie97 0:9ae27a35a771 207 * Attention : None
montie97 0:9ae27a35a771 208 *******************************************************************************/
montie97 0:9ae27a35a771 209 void start(){
montie97 0:9ae27a35a771 210 //disable_timer(0);
montie97 0:9ae27a35a771 211 //reset_timer(0);
montie97 0:9ae27a35a771 212
montie97 0:9ae27a35a771 213 clearPad();
montie97 0:9ae27a35a771 214 GUI_Text(22, 90, (uint8_t *) "Touch to", Black, White, 3);
montie97 0:9ae27a35a771 215 GUI_Text(32, 135, (uint8_t *)" start", Black, White, 3);
montie97 0:9ae27a35a771 216 GUI_Text(28, 185, (uint8_t *) "writing!", Black, White, 3);
montie97 0:9ae27a35a771 217
montie97 0:9ae27a35a771 218 startGame=0;
montie97 0:9ae27a35a771 219 isWritten=0;
montie97 0:9ae27a35a771 220 inferenceStarted=0;
montie97 0:9ae27a35a771 221 //enable_timer(0);
montie97 0:9ae27a35a771 222
montie97 0:9ae27a35a771 223 return;
montie97 0:9ae27a35a771 224 }
montie97 0:9ae27a35a771 225
montie97 0:9ae27a35a771 226 // FUNZIONI GIORGIO
montie97 0:9ae27a35a771 227
montie97 0:9ae27a35a771 228 void readtouch(){
montie97 0:9ae27a35a771 229 if(Read_X()!=4095){
montie97 0:9ae27a35a771 230 wait(0.1);
montie97 0:9ae27a35a771 231 for(k=0; k<400;k++){
montie97 0:9ae27a35a771 232 x=Read_Y();
montie97 0:9ae27a35a771 233 y=Read_X();
montie97 0:9ae27a35a771 234 x=(x-300)*240/3900;
montie97 0:9ae27a35a771 235 y=(y-220)*320/3800;
montie97 0:9ae27a35a771 236 avg_x+=x;
montie97 0:9ae27a35a771 237 avg_y+=y;
montie97 0:9ae27a35a771 238 }
montie97 0:9ae27a35a771 239 avg_x=avg_x/400;
montie97 0:9ae27a35a771 240 avg_y=avg_y/400;
montie97 0:9ae27a35a771 241 tocco.x=avg_x+10;
montie97 0:9ae27a35a771 242 tocco.y=avg_y+19;
montie97 0:9ae27a35a771 243 ready=1;
montie97 0:9ae27a35a771 244 }
montie97 0:9ae27a35a771 245 else
montie97 0:9ae27a35a771 246 ready=0;
protopapaandrea 1:a32ccf18194d 247 }
protopapaandrea 1:a32ccf18194d 248
protopapaandrea 1:a32ccf18194d 249 void readTouch(){
protopapaandrea 4:fc3364c83df6 250 int i,j,k,m;
protopapaandrea 1:a32ccf18194d 251 Coordinate p;
protopapaandrea 1:a32ccf18194d 252 getDisplayPoint(&display, Read_Ads7846(), &matrix ) ; //resto in attesa di un punto che venga toccato
protopapaandrea 1:a32ccf18194d 253 if(display.x <= 240 && display.x > 0){
protopapaandrea 1:a32ccf18194d 254 if(display.y >= 52 && display.y <= 275 && display.x >=8 && display.x <= 232){//punto in zona alta (start writing)
protopapaandrea 1:a32ccf18194d 255 if(!startGame){
protopapaandrea 1:a32ccf18194d 256 startGame=1;
protopapaandrea 1:a32ccf18194d 257 clearPad();
protopapaandrea 1:a32ccf18194d 258 charPos=0;
protopapaandrea 1:a32ccf18194d 259 }
protopapaandrea 1:a32ccf18194d 260 else{//game already started: handwriting input
protopapaandrea 1:a32ccf18194d 261 if(charPos<26*8){ //topbar bound: otherwise the topbar is full
protopapaandrea 1:a32ccf18194d 262 #ifdef DEBUG
protopapaandrea 1:a32ccf18194d 263 if(!isWritten)
protopapaandrea 1:a32ccf18194d 264 clearPad();//clear to delete the testing result printed on screen before
protopapaandrea 1:a32ccf18194d 265 #endif
protopapaandrea 1:a32ccf18194d 266 isWritten=1;
protopapaandrea 1:a32ccf18194d 267 p.x=display.x-8;
protopapaandrea 1:a32ccf18194d 268 p.y=display.y-52;
protopapaandrea 4:fc3364c83df6 269 /*
protopapaandrea 4:fc3364c83df6 270 for(i=-1;i<2;i++) //for each point, we select a square matrix 3x3 around it
protopapaandrea 1:a32ccf18194d 271 for(j=-1;j<2;j++){
protopapaandrea 1:a32ccf18194d 272 if((p.x+i)>=0&&(p.y+j)>=0&&(p.x+i)<224&&(p.y+j)<224){
protopapaandrea 1:a32ccf18194d 273 TP_DrawPoint(display.x+i,display.y+j);
protopapaandrea 4:fc3364c83df6 274 if(((p.x/8)+i)>=0&&((p.y/8)+j)>=0&&((p.x/8)+i)<28&&((p.y/8)+j)<28)
protopapaandrea 4:fc3364c83df6 275 drawnPoints[(p.x/8)+i][(p.y+j/8)+j]++; //count +1 for the macrocell containing this pixel
protopapaandrea 1:a32ccf18194d 276 }
protopapaandrea 1:a32ccf18194d 277 }
protopapaandrea 4:fc3364c83df6 278 */
protopapaandrea 4:fc3364c83df6 279 TP_DrawPoint(display.x,display.y);
protopapaandrea 4:fc3364c83df6 280 drawnPoints[p.x/8][p.y/8]++; //count +1 for the macrocell containing this pixel
protopapaandrea 4:fc3364c83df6 281
protopapaandrea 1:a32ccf18194d 282 }
protopapaandrea 1:a32ccf18194d 283 }
protopapaandrea 1:a32ccf18194d 284 }
protopapaandrea 1:a32ccf18194d 285 else{
protopapaandrea 1:a32ccf18194d 286 if(display.y >= 283 && display.y <= 315 && display.x >=8 && display.x <= 87 && startGame && !isWritten && !inferenceStarted){//punto in tasto Space
protopapaandrea 1:a32ccf18194d 287 if(charPos<26*8){ //topbar bound: otherwise the topbar is full
protopapaandrea 1:a32ccf18194d 288 drawButton(space,Yellow);
protopapaandrea 1:a32ccf18194d 289
protopapaandrea 1:a32ccf18194d 290 //space operation: writing a whitespace into the topbar
protopapaandrea 1:a32ccf18194d 291
protopapaandrea 1:a32ccf18194d 292 //--TO BE COMPLETED--//
protopapaandrea 1:a32ccf18194d 293 if(charPos!=0)
protopapaandrea 1:a32ccf18194d 294 LCD_DrawLine(15+charPos-8, 35, 15+charPos+8-8, 35, White); //delete last cursor
protopapaandrea 1:a32ccf18194d 295 GUI_Text(15+charPos, 20, (uint8_t *)" ", Black, White,1); //testing space on topbar
protopapaandrea 1:a32ccf18194d 296 LCD_DrawLine(15+charPos, 35, 15+charPos+8, 35, Black); //cursor
protopapaandrea 1:a32ccf18194d 297 charPos+=8;
protopapaandrea 1:a32ccf18194d 298
protopapaandrea 1:a32ccf18194d 299 clearPad(); //useful only to see the same response time of the other buttons
protopapaandrea 1:a32ccf18194d 300
protopapaandrea 1:a32ccf18194d 301 drawButton(space,White);
protopapaandrea 1:a32ccf18194d 302 }
protopapaandrea 1:a32ccf18194d 303 }
protopapaandrea 1:a32ccf18194d 304 else{
protopapaandrea 1:a32ccf18194d 305 if(display.y >= 283 && display.y <= 315 && display.x >=100 && display.x <= 139 && startGame && isWritten &&!inferenceStarted){//punto in tasto Infer
protopapaandrea 1:a32ccf18194d 306 //wait flag to able
protopapaandrea 1:a32ccf18194d 307
protopapaandrea 1:a32ccf18194d 308 drawButton(infer,Yellow);
protopapaandrea 1:a32ccf18194d 309
protopapaandrea 1:a32ccf18194d 310 inferenceStarted=1;
protopapaandrea 1:a32ccf18194d 311 //infer operation: compress the matrix and send the final 28x28 matrix to the inference step
protopapaandrea 1:a32ccf18194d 312
protopapaandrea 1:a32ccf18194d 313 //--TO BE COMPLETED--//
protopapaandrea 1:a32ccf18194d 314 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
protopapaandrea 1:a32ccf18194d 315 for(j=0;j<28;j++)
protopapaandrea 4:fc3364c83df6 316 if(drawnPoints[i][j]>=threshold){
protopapaandrea 4:fc3364c83df6 317 for(k=-1;k<2;k++) //for each point, we select a square matrix 3x3 around it
protopapaandrea 4:fc3364c83df6 318 for(m=-1;m<2;m++)
protopapaandrea 4:fc3364c83df6 319 if((i+k)>=0&&(j+m)>=0&&(i+k)<28&&(j+m)<28){
protopapaandrea 4:fc3364c83df6 320 finalMatrix[i+k][j+m]=1;
protopapaandrea 4:fc3364c83df6 321 }
protopapaandrea 4:fc3364c83df6 322
protopapaandrea 4:fc3364c83df6 323 }
protopapaandrea 1:a32ccf18194d 324
protopapaandrea 1:a32ccf18194d 325 #ifdef DEBUG
protopapaandrea 1:a32ccf18194d 326 showCompression();
protopapaandrea 1:a32ccf18194d 327 if(charPos!=0)
protopapaandrea 1:a32ccf18194d 328 LCD_DrawLine(15+charPos-8, 35, 15+charPos+8-8, 35, White); //delete last cursor
protopapaandrea 1:a32ccf18194d 329 GUI_Text(15+charPos, 20, (uint8_t *)"T", Black, White,1); //testing text on topbar
protopapaandrea 1:a32ccf18194d 330 LCD_DrawLine(15+charPos, 35, 15+charPos+8, 35, Black); //cursor
protopapaandrea 1:a32ccf18194d 331 charPos+=8;
protopapaandrea 4:fc3364c83df6 332 #else
pepperu96 2:4b3d056967a8 333 for(i=0;i<28;i++) {
pepperu96 2:4b3d056967a8 334 for(j=0;j<28;j++) {
protopapaandrea 4:fc3364c83df6 335 serial.printf("%d",static_cast<int>(finalMatrix[j][i]));
pepperu96 2:4b3d056967a8 336 }
pepperu96 2:4b3d056967a8 337 }
protopapaandrea 1:a32ccf18194d 338
pepperu96 3:2bf723da1732 339 clearPad(); //here the matix is also cleaned
pepperu96 3:2bf723da1732 340 #endif
pepperu96 3:2bf723da1732 341
protopapaandrea 1:a32ccf18194d 342 isWritten=0;
protopapaandrea 1:a32ccf18194d 343 inferenceStarted=0;
protopapaandrea 1:a32ccf18194d 344
protopapaandrea 1:a32ccf18194d 345
protopapaandrea 1:a32ccf18194d 346 drawButton(infer,White);
protopapaandrea 1:a32ccf18194d 347 }
protopapaandrea 1:a32ccf18194d 348 else{
protopapaandrea 1:a32ccf18194d 349 if(display.y >= 283 && display.y <= 315 && display.x >=153 && display.x <= 232 && startGame &&!inferenceStarted){//punto in tasto Delete
protopapaandrea 1:a32ccf18194d 350 //wait flag to able
protopapaandrea 1:a32ccf18194d 351
protopapaandrea 1:a32ccf18194d 352 drawButton(del,Yellow);
protopapaandrea 1:a32ccf18194d 353
protopapaandrea 1:a32ccf18194d 354 if(isWritten){ //delete operation - handwriting on pad, before inference: clear the pad
protopapaandrea 1:a32ccf18194d 355 clearPad();
protopapaandrea 1:a32ccf18194d 356 isWritten=0;
protopapaandrea 1:a32ccf18194d 357 }
protopapaandrea 1:a32ccf18194d 358 else{ //delete operation - no handwriting on pad, after inference: delete last char printed on the topbar
protopapaandrea 1:a32ccf18194d 359 //--TO BE COMPLETED--//
protopapaandrea 1:a32ccf18194d 360 clearPad(); //useful only to see the same response time of the other cases
protopapaandrea 1:a32ccf18194d 361 if(charPos!=0){
protopapaandrea 1:a32ccf18194d 362 LCD_DrawLine(15+charPos-8, 35, 15+charPos+8-8, 35, White); //delete last cursor
protopapaandrea 1:a32ccf18194d 363 GUI_Text(15+charPos-8, 20, (uint8_t *)" ", Black, White,1); //testing text on topbar
protopapaandrea 1:a32ccf18194d 364 if(charPos!=8){ //otherwise we are going to the first character, no cursor
protopapaandrea 1:a32ccf18194d 365 LCD_DrawLine(15+charPos-16, 35, 15+charPos-8, 35, Black); //cursor
protopapaandrea 1:a32ccf18194d 366 }
protopapaandrea 1:a32ccf18194d 367 charPos-=8;
protopapaandrea 1:a32ccf18194d 368 }
protopapaandrea 1:a32ccf18194d 369 }
protopapaandrea 1:a32ccf18194d 370
protopapaandrea 1:a32ccf18194d 371 drawButton(del,White);
protopapaandrea 1:a32ccf18194d 372 }
protopapaandrea 1:a32ccf18194d 373 }
protopapaandrea 1:a32ccf18194d 374 }
protopapaandrea 1:a32ccf18194d 375 }
protopapaandrea 1:a32ccf18194d 376 }
protopapaandrea 1:a32ccf18194d 377 else{
protopapaandrea 1:a32ccf18194d 378 //do nothing if touch returns values out of bounds
protopapaandrea 1:a32ccf18194d 379 }
protopapaandrea 1:a32ccf18194d 380 return;
montie97 0:9ae27a35a771 381 }