Código para o menu no LCD

Dependencies:   mbed SDFileSystemSD TextLCD

Fork of TextLCD_HelloWorld2 by Wim Huiskamp

Committer:
lucasfontenla
Date:
Sun Jun 10 06:18:14 2018 +0000
Revision:
41:a1ab19cc1387
Parent:
40:e70f811c69dc
Child:
42:48096cfdea78
Recebendo e enviando comandos do WiFi

Who changed what in which revision?

UserRevisionLine numberNew contents of line
claraluques 11:6b7accf18fe2 1 /*CÓDIGO PARA LCD MENU HELLEN - GRUPO T*/
claraluques 11:6b7accf18fe2 2
wim 0:a75049de1a82 3 #include "mbed.h"
wim 0:a75049de1a82 4 #include "TextLCD.h"
lucasfontenla 28:b3c51076ebe8 5 #include "SDFileSystem.h"
claraluques 19:2c890ae2d187 6 #include "string"
lucasfontenla 29:558eccdfc079 7 #include "vector"
claraluques 11:6b7accf18fe2 8
claraluques 32:c293f89170b0 9 Timer timer;
claraluques 33:0149960e95c1 10 Timer timer2;
claraluques 34:7c7fac39a250 11 Timer enter_debounce_timer;
claraluques 34:7c7fac39a250 12 Timer cima_debounce_timer;
claraluques 34:7c7fac39a250 13 Timer baixo_debounce_timer;
claraluques 36:12d202855231 14 Timer tpontinhos;
lucasfontenla 41:a1ab19cc1387 15 Timer wifi_serial;
wim 4:a3e4bb2053cb 16
claraluques 5:30f5ffe0ea0b 17 //I2C Communication
claraluques 11:6b7accf18fe2 18 I2C i2c_lcd(D14,D15); // SDA, SCL //não apagar
claraluques 5:30f5ffe0ea0b 19
claraluques 5:30f5ffe0ea0b 20 //Botão push
lucasfontenla 39:fbad08986621 21 InterruptIn botao_enter(D12);
lucasfontenla 40:e70f811c69dc 22 InterruptIn botao_cima(D9);
lucasfontenla 39:fbad08986621 23 InterruptIn botao_baixo(D13);
claraluques 5:30f5ffe0ea0b 24
lucasfontenla 40:e70f811c69dc 25 InterruptIn emergencia(D3);
lucasfontenla 40:e70f811c69dc 26
claraluques 5:30f5ffe0ea0b 27 //LCD instantiation
claraluques 11:6b7accf18fe2 28 TextLCD_I2C lcd(&i2c_lcd, 0x7E, TextLCD::LCD20x4); //não apagar
claraluques 5:30f5ffe0ea0b 29
claraluques 5:30f5ffe0ea0b 30 //variáveis int
claraluques 31:77eb51d4ee18 31 int bot_enter = 0;
claraluques 31:77eb51d4ee18 32 int bot_cima = 0;
claraluques 31:77eb51d4ee18 33 int bot_baixo = 0;
claraluques 31:77eb51d4ee18 34 int penter = 1;
claraluques 31:77eb51d4ee18 35 int pcima = 1;
claraluques 31:77eb51d4ee18 36 int pbaixo = 1;
claraluques 9:86b5a317fcd4 37 int cola;
claraluques 9:86b5a317fcd4 38 int exec;
claraluques 12:64ed645e79ad 39 int select = 0;
claraluques 26:59081efdce79 40 int pontos = 0;
claraluques 26:59081efdce79 41 int salvar = 0;
claraluques 35:11e3f3c8cb4e 42 int maxpontos = 100;
claraluques 26:59081efdce79 43 int home;
claraluques 32:c293f89170b0 44 int coluna = 1;
claraluques 32:c293f89170b0 45 int contador = 0;
claraluques 32:c293f89170b0 46 int sair = 0;
claraluques 33:0149960e95c1 47 int voltar = 0;
claraluques 33:0149960e95c1 48 int quebrar = 0;
claraluques 35:11e3f3c8cb4e 49 int f = 0;
claraluques 36:12d202855231 50 int limpar_cola = 0;
wim 0:a75049de1a82 51
lucasfontenla 41:a1ab19cc1387 52 int jog_working = 0;
lucasfontenla 41:a1ab19cc1387 53 int emerg = 0;
lucasfontenla 41:a1ab19cc1387 54
claraluques 5:30f5ffe0ea0b 55 //variáveis float
claraluques 33:0149960e95c1 56 float cx = 120.45;
claraluques 33:0149960e95c1 57 float cy = 457.85;
claraluques 33:0149960e95c1 58 float cz = 782.65;
claraluques 8:b80f50544ddd 59 float cx_salva;
claraluques 8:b80f50544ddd 60 float cy_salva;
claraluques 8:b80f50544ddd 61 float cz_salva;
claraluques 5:30f5ffe0ea0b 62
claraluques 5:30f5ffe0ea0b 63 //funções interrupt
claraluques 5:30f5ffe0ea0b 64 void botenter_press(void);
claraluques 32:c293f89170b0 65 void botcima_press(void);
claraluques 32:c293f89170b0 66 void botbaixo_press(void);
claraluques 32:c293f89170b0 67 void botenter_release(void);
claraluques 33:0149960e95c1 68 void botcima_release(void);
lucasfontenla 40:e70f811c69dc 69 void emergencia_press(void);
lucasfontenla 40:e70f811c69dc 70 void emergencia_release(void);
lucasfontenla 40:e70f811c69dc 71 void wifiRx(void);
wim 0:a75049de1a82 72
claraluques 5:30f5ffe0ea0b 73
claraluques 19:2c890ae2d187 74 #include "classes.h"
claraluques 19:2c890ae2d187 75
claraluques 9:86b5a317fcd4 76 Menu::Menu(){ //não apagar
claraluques 12:64ed645e79ad 77 func = 0;
claraluques 9:86b5a317fcd4 78 }
wim 3:f238b4f7874f 79
claraluques 5:30f5ffe0ea0b 80 Menu menu;
claraluques 19:2c890ae2d187 81
claraluques 5:30f5ffe0ea0b 82 int main () {
lucasfontenla 40:e70f811c69dc 83 printf("Starting...\n\r");
claraluques 5:30f5ffe0ea0b 84 lcd.setBacklight(TextLCD::LightOn); //liga backlight
claraluques 9:86b5a317fcd4 85 lcd.setCursor(TextLCD::CurOff_BlkOff); //define tipo de cursor
lucasfontenla 41:a1ab19cc1387 86
claraluques 31:77eb51d4ee18 87 botao_enter.fall(&botenter_press); //chama função botao enter
claraluques 31:77eb51d4ee18 88 botao_cima.fall(&botcima_press); //chama função botao para cima
claraluques 31:77eb51d4ee18 89 botao_baixo.fall(&botbaixo_press); //chama função bota para baixo
lucasfontenla 39:fbad08986621 90
claraluques 32:c293f89170b0 91 botao_enter.rise(&botenter_release); //chama função ler timer
claraluques 33:0149960e95c1 92 botao_cima.rise(&botcima_release);
claraluques 32:c293f89170b0 93
claraluques 34:7c7fac39a250 94 enter_debounce_timer.start(); // não apagar
claraluques 34:7c7fac39a250 95 cima_debounce_timer.start();
claraluques 34:7c7fac39a250 96 baixo_debounce_timer.start();
claraluques 6:24cbbdf2dac2 97
lucasfontenla 40:e70f811c69dc 98 emergencia.fall(&emergencia_press);
lucasfontenla 40:e70f811c69dc 99 emergencia.rise(&emergencia_release);
lucasfontenla 40:e70f811c69dc 100
lucasfontenla 40:e70f811c69dc 101 if(!emergencia.read()){
lucasfontenla 40:e70f811c69dc 102 printf("EMERGENCIA PRESSIONADO\n\r");
lucasfontenla 40:e70f811c69dc 103 menu.tela_emergencia();
lucasfontenla 40:e70f811c69dc 104 while(!emergencia.read());
lucasfontenla 40:e70f811c69dc 105 printf("OK\n\r");
lucasfontenla 40:e70f811c69dc 106 }
lucasfontenla 40:e70f811c69dc 107
lucasfontenla 40:e70f811c69dc 108 while(1){
claraluques 9:86b5a317fcd4 109 switch(menu.func){ //faz com que as telas sejam iniciadas
claraluques 5:30f5ffe0ea0b 110 case 0: menu.inicializar(); break;
claraluques 5:30f5ffe0ea0b 111 case 1: menu.menuprincipal(); break;
claraluques 6:24cbbdf2dac2 112 case 2: menu.jog(); break;
claraluques 12:64ed645e79ad 113 case 3: menu.automatico(); break;
claraluques 13:1670c34440a5 114 case 4: menu.config(); break;
claraluques 9:86b5a317fcd4 115 case 5: menu.telasalvamento(); break;
claraluques 9:86b5a317fcd4 116 case 6: menu.telacola(); break;
claraluques 9:86b5a317fcd4 117 case 7: menu.executarprograma(); break;
claraluques 9:86b5a317fcd4 118 case 8: menu.telazerar(); break;
claraluques 9:86b5a317fcd4 119 case 9: menu.executando(); break;
claraluques 9:86b5a317fcd4 120 case 10: menu.zerado(); break;
claraluques 9:86b5a317fcd4 121 case 11: menu.finalizado(); break;
claraluques 36:12d202855231 122 case 12: menu.limpeza_livre(); break;
claraluques 36:12d202855231 123 case 14: menu.limparcola(); break;
claraluques 27:83d2a710cc2f 124 case 15: menu.gohome(); break;
claraluques 13:1670c34440a5 125 case 16: menu.limitepontos(); break;
claraluques 26:59081efdce79 126 case 17: menu.salvarprog(); break;
claraluques 27:83d2a710cc2f 127 case 18: menu.ctzhome(); break;
claraluques 27:83d2a710cc2f 128 case 19: menu.origem(); break;
claraluques 30:614dcbd74cdc 129 case 20: menu.nomeprog(); break;
claraluques 32:c293f89170b0 130 case 21: menu.mudar_nome(); break;
claraluques 33:0149960e95c1 131 case 22: menu.salva2(); break;
claraluques 35:11e3f3c8cb4e 132 case 23: menu.deletepoint(); break;
claraluques 35:11e3f3c8cb4e 133 case 24: menu.sempontos(); break;
claraluques 36:12d202855231 134 case 25: menu.salvando_arq(); break;
claraluques 36:12d202855231 135 case 26: menu.exec_auto(); break;
claraluques 36:12d202855231 136 case 27: menu.indo_limpeza(); break;
claraluques 36:12d202855231 137 case 28: menu.chegou_limpeza(); break;
claraluques 36:12d202855231 138 case 29: menu.limpando(); break;
claraluques 36:12d202855231 139 case 30: menu.limpeza_completa(); break;
lucasfontenla 41:a1ab19cc1387 140 case 31: menu.tela_emergencia(); break;
lucasfontenla 41:a1ab19cc1387 141 case 32: menu.wifi(); break;
lucasfontenla 40:e70f811c69dc 142 }
lucasfontenla 40:e70f811c69dc 143 }
lucasfontenla 40:e70f811c69dc 144 }
claraluques 5:30f5ffe0ea0b 145
claraluques 11:6b7accf18fe2 146 //função interrupt botão enter
claraluques 34:7c7fac39a250 147 void botenter_press(void){
claraluques 34:7c7fac39a250 148 printf("ENTER!\n\r");
claraluques 35:11e3f3c8cb4e 149 //printf("timer: %.3f\n\r", enter_debounce_timer.read());
claraluques 34:7c7fac39a250 150 if(enter_debounce_timer.read()>0.2){
claraluques 34:7c7fac39a250 151 penter = bot_enter;
claraluques 34:7c7fac39a250 152 bot_enter = !bot_enter;
claraluques 35:11e3f3c8cb4e 153 //printf("enter high, timer reset FALL\n\r");
claraluques 34:7c7fac39a250 154 timer.reset();
claraluques 34:7c7fac39a250 155 timer.start();
claraluques 34:7c7fac39a250 156 enter_debounce_timer.reset();
claraluques 34:7c7fac39a250 157 enter_debounce_timer.start();
claraluques 34:7c7fac39a250 158 }
claraluques 34:7c7fac39a250 159 }
claraluques 9:86b5a317fcd4 160
claraluques 11:6b7accf18fe2 161 //função interrupt botão cima
claraluques 11:6b7accf18fe2 162 void botcima_press(void){
claraluques 34:7c7fac39a250 163 printf("CIMA!\n\r");
lucasfontenla 39:fbad08986621 164 printf("timer: %.3f\n\r", cima_debounce_timer.read());
lucasfontenla 39:fbad08986621 165 printf("timer: %.3f\n\r", baixo_debounce_timer.read());
claraluques 34:7c7fac39a250 166 if(cima_debounce_timer.read()>0.2){
claraluques 34:7c7fac39a250 167 pcima = bot_cima;
claraluques 34:7c7fac39a250 168 bot_cima = !bot_cima;
claraluques 34:7c7fac39a250 169 timer2.reset();
claraluques 34:7c7fac39a250 170 timer2.start();
claraluques 34:7c7fac39a250 171 cima_debounce_timer.reset();
claraluques 34:7c7fac39a250 172 cima_debounce_timer.start();
claraluques 34:7c7fac39a250 173 }
claraluques 34:7c7fac39a250 174 }
wim 0:a75049de1a82 175
claraluques 5:30f5ffe0ea0b 176 //função interrupt botão baixo
claraluques 11:6b7accf18fe2 177 void botbaixo_press(void){
claraluques 34:7c7fac39a250 178 printf("BAIXO!\n\r");
claraluques 35:11e3f3c8cb4e 179 //printf("timer: %.3f\n\r", baixo_debounce_timer.read());
claraluques 34:7c7fac39a250 180 if(baixo_debounce_timer.read()>0.2){
claraluques 34:7c7fac39a250 181 pbaixo = bot_baixo;
claraluques 34:7c7fac39a250 182 bot_baixo = !bot_baixo;
claraluques 34:7c7fac39a250 183 baixo_debounce_timer.reset();
claraluques 34:7c7fac39a250 184 baixo_debounce_timer.start();
claraluques 34:7c7fac39a250 185 }
claraluques 34:7c7fac39a250 186 }
claraluques 34:7c7fac39a250 187
claraluques 32:c293f89170b0 188 //função para ler o timer
claraluques 32:c293f89170b0 189 void botenter_release(void){
claraluques 32:c293f89170b0 190 timer.stop();
claraluques 33:0149960e95c1 191 quebrar = 1;
claraluques 33:0149960e95c1 192 }
claraluques 33:0149960e95c1 193
claraluques 33:0149960e95c1 194
claraluques 33:0149960e95c1 195 //função para ler o timer 2
claraluques 33:0149960e95c1 196 void botcima_release(void){
claraluques 33:0149960e95c1 197 timer2.stop();
claraluques 34:7c7fac39a250 198 //printf("%f,%d, timer 2 RISE\n\r", t2, voltar);
lucasfontenla 40:e70f811c69dc 199 }
lucasfontenla 40:e70f811c69dc 200
lucasfontenla 41:a1ab19cc1387 201 void wifiRx(void){
lucasfontenla 41:a1ab19cc1387 202 wifi_serial.reset();
lucasfontenla 41:a1ab19cc1387 203 float timeout_time = 2.0;
lucasfontenla 41:a1ab19cc1387 204
lucasfontenla 41:a1ab19cc1387 205 char recv;
lucasfontenla 41:a1ab19cc1387 206 string buffer;
lucasfontenla 41:a1ab19cc1387 207
lucasfontenla 41:a1ab19cc1387 208 int glue = 0;
lucasfontenla 41:a1ab19cc1387 209 int jog_mode = 0;
lucasfontenla 41:a1ab19cc1387 210 int kill_jog = 0;
lucasfontenla 41:a1ab19cc1387 211 int move_mode = 0;
lucasfontenla 41:a1ab19cc1387 212 int zero_mode = 0;
lucasfontenla 41:a1ab19cc1387 213 int machine_zero_mode = 0;
lucasfontenla 41:a1ab19cc1387 214 int upload_code = 0;
lucasfontenla 41:a1ab19cc1387 215 int start_mode = 0;
lucasfontenla 41:a1ab19cc1387 216
lucasfontenla 41:a1ab19cc1387 217 if(menu.func == 1){
lucasfontenla 41:a1ab19cc1387 218 wifi_serial.start();
lucasfontenla 41:a1ab19cc1387 219
lucasfontenla 41:a1ab19cc1387 220 while(WiFi.readable()){
lucasfontenla 41:a1ab19cc1387 221 recv = WiFi.getc();
lucasfontenla 41:a1ab19cc1387 222 printf("Recv: %c\n\r", recv);
lucasfontenla 41:a1ab19cc1387 223
lucasfontenla 41:a1ab19cc1387 224 if(wifi_serial.read() > timeout_time){
lucasfontenla 41:a1ab19cc1387 225 wifi_serial.stop();
lucasfontenla 41:a1ab19cc1387 226 printf("Serial timeout");
lucasfontenla 41:a1ab19cc1387 227 break;
lucasfontenla 41:a1ab19cc1387 228 }
lucasfontenla 41:a1ab19cc1387 229
lucasfontenla 41:a1ab19cc1387 230 if(recv == 'x'){
lucasfontenla 41:a1ab19cc1387 231 printf("X recv\n\r");
lucasfontenla 41:a1ab19cc1387 232 if(glue){
lucasfontenla 41:a1ab19cc1387 233 printf("Clean glue\n\r");
lucasfontenla 41:a1ab19cc1387 234 machine.clean_glue();
lucasfontenla 41:a1ab19cc1387 235 printf("Cleaned glue\n\r");
lucasfontenla 41:a1ab19cc1387 236 } else if(jog_mode){
lucasfontenla 41:a1ab19cc1387 237 if(kill_jog){
lucasfontenla 41:a1ab19cc1387 238 machine.kill_jog();
lucasfontenla 41:a1ab19cc1387 239 } else {
lucasfontenla 41:a1ab19cc1387 240 machine.jog();
lucasfontenla 41:a1ab19cc1387 241 }
lucasfontenla 41:a1ab19cc1387 242 } else if(move_mode){
lucasfontenla 41:a1ab19cc1387 243 machine.move(buffer);
lucasfontenla 41:a1ab19cc1387 244 machine.start_program();
lucasfontenla 41:a1ab19cc1387 245 } else if(zero_mode){
lucasfontenla 41:a1ab19cc1387 246 if(machine_zero_mode){
lucasfontenla 41:a1ab19cc1387 247 machine.machine_zero();
lucasfontenla 41:a1ab19cc1387 248 }
lucasfontenla 41:a1ab19cc1387 249 } else if(start_mode){
lucasfontenla 41:a1ab19cc1387 250 machine.start_program();
lucasfontenla 41:a1ab19cc1387 251 }
lucasfontenla 41:a1ab19cc1387 252 return;
lucasfontenla 41:a1ab19cc1387 253
lucasfontenla 41:a1ab19cc1387 254 }
lucasfontenla 41:a1ab19cc1387 255
lucasfontenla 41:a1ab19cc1387 256 if(recv == 'g'){
lucasfontenla 41:a1ab19cc1387 257 printf("G recv\n\r");
lucasfontenla 41:a1ab19cc1387 258 glue = 1;
lucasfontenla 41:a1ab19cc1387 259 }
lucasfontenla 41:a1ab19cc1387 260
lucasfontenla 41:a1ab19cc1387 261 if(recv == 'b'){
lucasfontenla 41:a1ab19cc1387 262 printf("B recv\n\r");
lucasfontenla 41:a1ab19cc1387 263 start_mode = 1;
lucasfontenla 41:a1ab19cc1387 264 }
lucasfontenla 41:a1ab19cc1387 265
lucasfontenla 41:a1ab19cc1387 266 if(recv == 'j'){
lucasfontenla 41:a1ab19cc1387 267 printf("J recv\n\r");
lucasfontenla 41:a1ab19cc1387 268 jog_mode = 1;
lucasfontenla 41:a1ab19cc1387 269 }
lucasfontenla 41:a1ab19cc1387 270
lucasfontenla 41:a1ab19cc1387 271 if(recv == 'k' && jog_mode){
lucasfontenla 41:a1ab19cc1387 272 printf("K recv\n\r");
lucasfontenla 41:a1ab19cc1387 273 kill_jog = 1;
lucasfontenla 41:a1ab19cc1387 274 }
lucasfontenla 41:a1ab19cc1387 275
lucasfontenla 41:a1ab19cc1387 276 if(recv == 'z'){
lucasfontenla 41:a1ab19cc1387 277 printf("Z recv\n\r");
lucasfontenla 41:a1ab19cc1387 278 zero_mode = 1;
lucasfontenla 41:a1ab19cc1387 279 }
lucasfontenla 41:a1ab19cc1387 280
lucasfontenla 41:a1ab19cc1387 281 if(recv == 'm' && zero_mode){
lucasfontenla 41:a1ab19cc1387 282 printf("M recv\n\r");
lucasfontenla 41:a1ab19cc1387 283 machine_zero_mode = 1;
lucasfontenla 41:a1ab19cc1387 284 }
lucasfontenla 41:a1ab19cc1387 285
lucasfontenla 41:a1ab19cc1387 286 if(recv == 'm' && !zero_mode){
lucasfontenla 41:a1ab19cc1387 287 printf("M recv\n\r");
lucasfontenla 41:a1ab19cc1387 288 buffer = "";
lucasfontenla 41:a1ab19cc1387 289 move_mode = 1;
lucasfontenla 41:a1ab19cc1387 290 }
lucasfontenla 41:a1ab19cc1387 291
lucasfontenla 41:a1ab19cc1387 292 if(recv == 'u'){
lucasfontenla 41:a1ab19cc1387 293 printf("U recv\n\r");
lucasfontenla 41:a1ab19cc1387 294 buffer = "";
lucasfontenla 41:a1ab19cc1387 295 timeout_time = 10.0;
lucasfontenla 41:a1ab19cc1387 296 upload_code = 1;
lucasfontenla 41:a1ab19cc1387 297 }
lucasfontenla 41:a1ab19cc1387 298
lucasfontenla 41:a1ab19cc1387 299 if(move_mode){
lucasfontenla 41:a1ab19cc1387 300 printf("got\n\r");
lucasfontenla 41:a1ab19cc1387 301 buffer.push_back(recv);
lucasfontenla 41:a1ab19cc1387 302 }
lucasfontenla 41:a1ab19cc1387 303
lucasfontenla 41:a1ab19cc1387 304 if(upload_code && recv != 'u'){
lucasfontenla 41:a1ab19cc1387 305 printf("got\n\r");
lucasfontenla 41:a1ab19cc1387 306 buffer.push_back(recv);
lucasfontenla 41:a1ab19cc1387 307 }
lucasfontenla 41:a1ab19cc1387 308
lucasfontenla 41:a1ab19cc1387 309 }
lucasfontenla 41:a1ab19cc1387 310 }
lucasfontenla 41:a1ab19cc1387 311 }
lucasfontenla 40:e70f811c69dc 312
lucasfontenla 40:e70f811c69dc 313 void emergencia_press(void){
lucasfontenla 40:e70f811c69dc 314 printf("Emerg Press\n\r");
lucasfontenla 41:a1ab19cc1387 315 emerg = 1;
lucasfontenla 40:e70f811c69dc 316 }
lucasfontenla 40:e70f811c69dc 317
lucasfontenla 40:e70f811c69dc 318 void emergencia_release(void){
lucasfontenla 40:e70f811c69dc 319 printf("Emerg Release\n\r");
lucasfontenla 41:a1ab19cc1387 320 emerg = 0;
lucasfontenla 40:e70f811c69dc 321 }