Shish

Dependencies:   mbed USBDevice GLCD

Committer:
montie97
Date:
Thu May 06 17:35:37 2021 +0000
Revision:
0:9ae27a35a771
Child:
1:a32ccf18194d
Primo tentativo di commit

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"
montie97 0:9ae27a35a771 8 #include <vector>
montie97 0:9ae27a35a771 9
montie97 0:9ae27a35a771 10 //FUNZIONI GIORGIO
montie97 0:9ae27a35a771 11 void readtouch();
montie97 0:9ae27a35a771 12
montie97 0:9ae27a35a771 13 //VARIABILI GIORGIO
montie97 0:9ae27a35a771 14 Coordinate tocco;
montie97 0:9ae27a35a771 15 int x,y,k,avg_x,avg_y,ready;
montie97 0:9ae27a35a771 16
montie97 0:9ae27a35a771 17 int startGame=0;
montie97 0:9ae27a35a771 18 int isWritten=0;
montie97 0:9ae27a35a771 19 int inferenceStarted=0;
montie97 0:9ae27a35a771 20 uint8_t drawnPoints[28][28];
montie97 0:9ae27a35a771 21 int threshold = 32;
montie97 0:9ae27a35a771 22 USBSerial serial;
montie97 0:9ae27a35a771 23
montie97 0:9ae27a35a771 24 /*Buttons*/
montie97 0:9ae27a35a771 25 typedef enum {space,infer,del} button;
montie97 0:9ae27a35a771 26
montie97 0:9ae27a35a771 27 /* Private function prototypes -----------------------------------------------*/
montie97 0:9ae27a35a771 28 void spaceText(int x1, int x2, int yText, int spessore, uint16_t color);
montie97 0:9ae27a35a771 29 void clearPad(void);
montie97 0:9ae27a35a771 30 void showCompression(void);
montie97 0:9ae27a35a771 31 void clearBar(void);
montie97 0:9ae27a35a771 32 void drawButtons(void);
montie97 0:9ae27a35a771 33 void drawButton(button b, uint16_t color);
montie97 0:9ae27a35a771 34 void start(void);
montie97 0:9ae27a35a771 35 void drawTriangle(int posX, int posY, int lungMax);
montie97 0:9ae27a35a771 36
montie97 0:9ae27a35a771 37 int main() {
montie97 0:9ae27a35a771 38 LCD_Initialization();
montie97 0:9ae27a35a771 39 TP_Init();
montie97 0:9ae27a35a771 40 LCD_Clear(Blue2);
montie97 0:9ae27a35a771 41
montie97 0:9ae27a35a771 42 clearBar();
montie97 0:9ae27a35a771 43 drawButtons();
montie97 0:9ae27a35a771 44 start();
montie97 0:9ae27a35a771 45
montie97 0:9ae27a35a771 46 while(1){
montie97 0:9ae27a35a771 47 readtouch();
montie97 0:9ae27a35a771 48 serial.printf("%u %u\n", tocco.x, tocco.y);
montie97 0:9ae27a35a771 49 wait(1);
montie97 0:9ae27a35a771 50 }
montie97 0:9ae27a35a771 51 }
montie97 0:9ae27a35a771 52
montie97 0:9ae27a35a771 53 /*******************************************************************************
montie97 0:9ae27a35a771 54 * Function Name : spaceText
montie97 0:9ae27a35a771 55 * Description :
montie97 0:9ae27a35a771 56 * Input : None
montie97 0:9ae27a35a771 57 * Output : None
montie97 0:9ae27a35a771 58 * Return : None
montie97 0:9ae27a35a771 59 * Attention : None
montie97 0:9ae27a35a771 60 *******************************************************************************/
montie97 0:9ae27a35a771 61 void spaceText(int x1, int x2, int yText, int spessore, uint16_t color){ //Spazio di un unico colore
montie97 0:9ae27a35a771 62 int i;
montie97 0:9ae27a35a771 63 for(i=spessore;i>0;i--){
montie97 0:9ae27a35a771 64 LCD_DrawLine(x1,yText-i,x2,yText-i,color);
montie97 0:9ae27a35a771 65 }
montie97 0:9ae27a35a771 66 return;
montie97 0:9ae27a35a771 67 }
montie97 0:9ae27a35a771 68
montie97 0:9ae27a35a771 69 /*******************************************************************************
montie97 0:9ae27a35a771 70 * Function Name : clearPad
montie97 0:9ae27a35a771 71 * Description :
montie97 0:9ae27a35a771 72 * Input : None
montie97 0:9ae27a35a771 73 * Output : None
montie97 0:9ae27a35a771 74 * Return : None
montie97 0:9ae27a35a771 75 * Attention : None
montie97 0:9ae27a35a771 76 *******************************************************************************/
montie97 0:9ae27a35a771 77 void clearPad(){
montie97 0:9ae27a35a771 78 int i,j;
montie97 0:9ae27a35a771 79 for(i=0;i<224;i++){
montie97 0:9ae27a35a771 80 LCD_DrawLine(8,52+i,232,52+i,White);
montie97 0:9ae27a35a771 81 }
montie97 0:9ae27a35a771 82 for(i=0;i<28;i++) //also clear the matrix
montie97 0:9ae27a35a771 83 for(j=0;j<28;j++)
montie97 0:9ae27a35a771 84 drawnPoints[i][j]=0;
montie97 0:9ae27a35a771 85
montie97 0:9ae27a35a771 86 return;
montie97 0:9ae27a35a771 87 }
montie97 0:9ae27a35a771 88
montie97 0:9ae27a35a771 89 /*******************************************************************************
montie97 0:9ae27a35a771 90 * Function Name : showCompression
montie97 0:9ae27a35a771 91 * Description :
montie97 0:9ae27a35a771 92 * Input : None
montie97 0:9ae27a35a771 93 * Output : None
montie97 0:9ae27a35a771 94 * Return : None
montie97 0:9ae27a35a771 95 * Attention : None
montie97 0:9ae27a35a771 96 *******************************************************************************/
montie97 0:9ae27a35a771 97 void showCompression(){
montie97 0:9ae27a35a771 98 int i,j;
montie97 0:9ae27a35a771 99 for(i=0;i<224;i++){ //clean the pad
montie97 0:9ae27a35a771 100 LCD_DrawLine(8,52+i,232,52+i,White);
montie97 0:9ae27a35a771 101 }
montie97 0:9ae27a35a771 102 for(i=0;i<28;i++)
montie97 0:9ae27a35a771 103 for(j=0;j<28;j++)
montie97 0:9ae27a35a771 104 if(drawnPoints[i][j]==1)
montie97 0:9ae27a35a771 105 LCD_SetPoint(i+110,j+150,Black);
montie97 0:9ae27a35a771 106
montie97 0:9ae27a35a771 107 return;
montie97 0:9ae27a35a771 108 }
montie97 0:9ae27a35a771 109
montie97 0:9ae27a35a771 110 /*******************************************************************************
montie97 0:9ae27a35a771 111 * Function Name : clearBar
montie97 0:9ae27a35a771 112 * Description :
montie97 0:9ae27a35a771 113 * Input : None
montie97 0:9ae27a35a771 114 * Output : None
montie97 0:9ae27a35a771 115 * Return : None
montie97 0:9ae27a35a771 116 * Attention : None
montie97 0:9ae27a35a771 117 *******************************************************************************/
montie97 0:9ae27a35a771 118 void clearBar(){
montie97 0:9ae27a35a771 119 int i;
montie97 0:9ae27a35a771 120 for(i=0;i<32;i++){
montie97 0:9ae27a35a771 121 LCD_DrawLine(8,10+i,232,10+i,White);
montie97 0:9ae27a35a771 122 }
montie97 0:9ae27a35a771 123 return;
montie97 0:9ae27a35a771 124 }
montie97 0:9ae27a35a771 125
montie97 0:9ae27a35a771 126 /*******************************************************************************
montie97 0:9ae27a35a771 127 * Function Name : drawButton
montie97 0:9ae27a35a771 128 * Description :
montie97 0:9ae27a35a771 129 * Input : None
montie97 0:9ae27a35a771 130 * Output : None
montie97 0:9ae27a35a771 131 * Return : None
montie97 0:9ae27a35a771 132 * Attention : None
montie97 0:9ae27a35a771 133 *******************************************************************************/
montie97 0:9ae27a35a771 134 void drawButton(button b, uint16_t color){
montie97 0:9ae27a35a771 135 int i;
montie97 0:9ae27a35a771 136 switch(b){
montie97 0:9ae27a35a771 137 case space: //Space Button
montie97 0:9ae27a35a771 138 spaceText(8,87,291,8,color);
montie97 0:9ae27a35a771 139 GUI_Text(8, 291, (uint8_t *) " Space ", Blue, color,1);
montie97 0:9ae27a35a771 140 spaceText(8,87,291+16+8,8,color);
montie97 0:9ae27a35a771 141 break;
montie97 0:9ae27a35a771 142 case infer: //Infer Button
montie97 0:9ae27a35a771 143 for(i=0;i<32;i++){
montie97 0:9ae27a35a771 144 LCD_DrawLine(100,283+i,139,283+i,color);
montie97 0:9ae27a35a771 145 }
montie97 0:9ae27a35a771 146 drawTriangle(112,289,10);
montie97 0:9ae27a35a771 147 break;
montie97 0:9ae27a35a771 148 case del: //Delete Button
montie97 0:9ae27a35a771 149 spaceText(153,232,291,8,color);
montie97 0:9ae27a35a771 150 GUI_Text(153, 291, (uint8_t *) " Delete ", Blue, color,1);
montie97 0:9ae27a35a771 151 spaceText(153,232,291+16+8,8,color);
montie97 0:9ae27a35a771 152 break;
montie97 0:9ae27a35a771 153 default:
montie97 0:9ae27a35a771 154 break;
montie97 0:9ae27a35a771 155 }
montie97 0:9ae27a35a771 156 return;
montie97 0:9ae27a35a771 157 }
montie97 0:9ae27a35a771 158
montie97 0:9ae27a35a771 159 /*******************************************************************************
montie97 0:9ae27a35a771 160 * Function Name : drawButtons
montie97 0:9ae27a35a771 161 * Description :
montie97 0:9ae27a35a771 162 * Input : None
montie97 0:9ae27a35a771 163 * Output : None
montie97 0:9ae27a35a771 164 * Return : None
montie97 0:9ae27a35a771 165 * Attention : None
montie97 0:9ae27a35a771 166 *******************************************************************************/
montie97 0:9ae27a35a771 167 void drawButtons(){
montie97 0:9ae27a35a771 168 drawButton(space,White);
montie97 0:9ae27a35a771 169 drawButton(infer,White);
montie97 0:9ae27a35a771 170 drawButton(del,White);
montie97 0:9ae27a35a771 171 return;
montie97 0:9ae27a35a771 172 }
montie97 0:9ae27a35a771 173
montie97 0:9ae27a35a771 174 /*******************************************************************************
montie97 0:9ae27a35a771 175 * Function Name : drawTriangle
montie97 0:9ae27a35a771 176 * Description :
montie97 0:9ae27a35a771 177 * Input : None
montie97 0:9ae27a35a771 178 * Output : None
montie97 0:9ae27a35a771 179 * Return : None
montie97 0:9ae27a35a771 180 * Attention : None
montie97 0:9ae27a35a771 181 *******************************************************************************/
montie97 0:9ae27a35a771 182 void drawTriangle(int posX, int posY, int lungMax){
montie97 0:9ae27a35a771 183 int i;
montie97 0:9ae27a35a771 184 uint16_t color=Green2;
montie97 0:9ae27a35a771 185 for(i=0;i<lungMax;i++){ //Direction EAST
montie97 0:9ae27a35a771 186 LCD_DrawLine(posX+5,posY+i+1,posX+5+i,posY+i+1,color);
montie97 0:9ae27a35a771 187 }
montie97 0:9ae27a35a771 188 for(i=0;i<lungMax-1;i++){
montie97 0:9ae27a35a771 189 LCD_DrawLine(posX+5,posY+lungMax+i+1,posX+5+(lungMax-2)-i,posY+lungMax+i+1,color);
montie97 0:9ae27a35a771 190 }
montie97 0:9ae27a35a771 191 }
montie97 0:9ae27a35a771 192
montie97 0:9ae27a35a771 193 /*******************************************************************************
montie97 0:9ae27a35a771 194 * Function Name : start
montie97 0:9ae27a35a771 195 * Description :
montie97 0:9ae27a35a771 196 * Input : None
montie97 0:9ae27a35a771 197 * Output : None
montie97 0:9ae27a35a771 198 * Return : None
montie97 0:9ae27a35a771 199 * Attention : None
montie97 0:9ae27a35a771 200 *******************************************************************************/
montie97 0:9ae27a35a771 201 void start(){
montie97 0:9ae27a35a771 202 //disable_timer(0);
montie97 0:9ae27a35a771 203 //reset_timer(0);
montie97 0:9ae27a35a771 204
montie97 0:9ae27a35a771 205 clearPad();
montie97 0:9ae27a35a771 206 GUI_Text(22, 90, (uint8_t *) "Touch to", Black, White, 3);
montie97 0:9ae27a35a771 207 GUI_Text(32, 135, (uint8_t *)" start", Black, White, 3);
montie97 0:9ae27a35a771 208 GUI_Text(28, 185, (uint8_t *) "writing!", Black, White, 3);
montie97 0:9ae27a35a771 209
montie97 0:9ae27a35a771 210 startGame=0;
montie97 0:9ae27a35a771 211 isWritten=0;
montie97 0:9ae27a35a771 212 inferenceStarted=0;
montie97 0:9ae27a35a771 213 //enable_timer(0);
montie97 0:9ae27a35a771 214
montie97 0:9ae27a35a771 215 return;
montie97 0:9ae27a35a771 216 }
montie97 0:9ae27a35a771 217
montie97 0:9ae27a35a771 218 // FUNZIONI GIORGIO
montie97 0:9ae27a35a771 219
montie97 0:9ae27a35a771 220 void readtouch(){
montie97 0:9ae27a35a771 221 if(Read_X()!=4095){
montie97 0:9ae27a35a771 222 wait(0.1);
montie97 0:9ae27a35a771 223 for(k=0; k<400;k++){
montie97 0:9ae27a35a771 224 x=Read_Y();
montie97 0:9ae27a35a771 225 y=Read_X();
montie97 0:9ae27a35a771 226 x=(x-300)*240/3900;
montie97 0:9ae27a35a771 227 y=(y-220)*320/3800;
montie97 0:9ae27a35a771 228 avg_x+=x;
montie97 0:9ae27a35a771 229 avg_y+=y;
montie97 0:9ae27a35a771 230 }
montie97 0:9ae27a35a771 231 avg_x=avg_x/400;
montie97 0:9ae27a35a771 232 avg_y=avg_y/400;
montie97 0:9ae27a35a771 233 tocco.x=avg_x+10;
montie97 0:9ae27a35a771 234 tocco.y=avg_y+19;
montie97 0:9ae27a35a771 235 ready=1;
montie97 0:9ae27a35a771 236 }
montie97 0:9ae27a35a771 237 else
montie97 0:9ae27a35a771 238 ready=0;
montie97 0:9ae27a35a771 239 }