Código para o menu no LCD
Dependencies: mbed SDFileSystemSD TextLCD
Fork of TextLCD_HelloWorld2 by
Diff: main.cpp
- Revision:
- 41:a1ab19cc1387
- Parent:
- 40:e70f811c69dc
- Child:
- 42:48096cfdea78
--- a/main.cpp Sat Jun 09 18:41:32 2018 +0000 +++ b/main.cpp Sun Jun 10 06:18:14 2018 +0000 @@ -12,6 +12,7 @@ Timer cima_debounce_timer; Timer baixo_debounce_timer; Timer tpontinhos; +Timer wifi_serial; //I2C Communication I2C i2c_lcd(D14,D15); // SDA, SCL //não apagar @@ -48,6 +49,9 @@ int f = 0; int limpar_cola = 0; +int jog_working = 0; +int emerg = 0; + //variáveis float float cx = 120.45; float cy = 457.85; @@ -79,7 +83,7 @@ printf("Starting...\n\r"); lcd.setBacklight(TextLCD::LightOn); //liga backlight lcd.setCursor(TextLCD::CurOff_BlkOff); //define tipo de cursor - + botao_enter.fall(&botenter_press); //chama função botao enter botao_cima.fall(&botcima_press); //chama função botao para cima botao_baixo.fall(&botbaixo_press); //chama função bota para baixo @@ -133,6 +137,8 @@ case 28: menu.chegou_limpeza(); break; case 29: menu.limpando(); break; case 30: menu.limpeza_completa(); break; + case 31: menu.tela_emergencia(); break; + case 32: menu.wifi(); break; } } } @@ -192,20 +198,124 @@ //printf("%f,%d, timer 2 RISE\n\r", t2, voltar); } - void wifiRx(void){ - if(WiFi.readable()){ - printf("Recv: %c\n\r", WiFi.getc()); - } - } +void wifiRx(void){ + wifi_serial.reset(); + float timeout_time = 2.0; + + char recv; + string buffer; + + int glue = 0; + int jog_mode = 0; + int kill_jog = 0; + int move_mode = 0; + int zero_mode = 0; + int machine_zero_mode = 0; + int upload_code = 0; + int start_mode = 0; + + if(menu.func == 1){ + wifi_serial.start(); + + while(WiFi.readable()){ + recv = WiFi.getc(); + printf("Recv: %c\n\r", recv); + + if(wifi_serial.read() > timeout_time){ + wifi_serial.stop(); + printf("Serial timeout"); + break; + } + + if(recv == 'x'){ + printf("X recv\n\r"); + if(glue){ + printf("Clean glue\n\r"); + machine.clean_glue(); + printf("Cleaned glue\n\r"); + } else if(jog_mode){ + if(kill_jog){ + machine.kill_jog(); + } else { + machine.jog(); + } + } else if(move_mode){ + machine.move(buffer); + machine.start_program(); + } else if(zero_mode){ + if(machine_zero_mode){ + machine.machine_zero(); + } + } else if(start_mode){ + machine.start_program(); + } + return; + + } + + if(recv == 'g'){ + printf("G recv\n\r"); + glue = 1; + } + + if(recv == 'b'){ + printf("B recv\n\r"); + start_mode = 1; + } + + if(recv == 'j'){ + printf("J recv\n\r"); + jog_mode = 1; + } + + if(recv == 'k' && jog_mode){ + printf("K recv\n\r"); + kill_jog = 1; + } + + if(recv == 'z'){ + printf("Z recv\n\r"); + zero_mode = 1; + } + + if(recv == 'm' && zero_mode){ + printf("M recv\n\r"); + machine_zero_mode = 1; + } + + if(recv == 'm' && !zero_mode){ + printf("M recv\n\r"); + buffer = ""; + move_mode = 1; + } + + if(recv == 'u'){ + printf("U recv\n\r"); + buffer = ""; + timeout_time = 10.0; + upload_code = 1; + } + + if(move_mode){ + printf("got\n\r"); + buffer.push_back(recv); + } + + if(upload_code && recv != 'u'){ + printf("got\n\r"); + buffer.push_back(recv); + } + + } + } +} void emergencia_press(void){ printf("Emerg Press\n\r"); - menu.tela_emergencia(); - while(!emergencia.read()); - printf("Emerg Out\n\r"); - main(); + emerg = 1; } void emergencia_release(void){ printf("Emerg Release\n\r"); + emerg = 0; } \ No newline at end of file