
Código para o menu no LCD
Dependencies: mbed SDFileSystemSD TextLCD
Fork of TextLCD_HelloWorld2 by
Revision 41:a1ab19cc1387, committed 2018-06-10
- Comitter:
- lucasfontenla
- Date:
- Sun Jun 10 06:18:14 2018 +0000
- Parent:
- 40:e70f811c69dc
- Child:
- 42:48096cfdea78
- Commit message:
- Recebendo e enviando comandos do WiFi
Changed in this revision
classes.h | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/classes.h Sat Jun 09 18:41:32 2018 +0000 +++ b/classes.h Sun Jun 10 06:18:14 2018 +0000 @@ -16,33 +16,10 @@ public: int debug; - // PUBLIC FUNCTIONS ---------------------------------------------------------------------------------------------------------------------------------------- - void move_to(float x, float y, float z, string type, int speed){ - - } - - void move(int x_axis, int y_axis, int z_axis, float pct_speed){ - buffer = ""; - - buffer.append("f"); - - //buffer.append("X"); - n = sprintf(buffer_char, "%d", x_axis); - buffer.append(buffer_char); - - //buffer.append("Y"); - n = sprintf(buffer_char, "%d", y_axis); - buffer.append(buffer_char); - - //buffer.append("Z"); - n = sprintf(buffer_char, "%d", z_axis); - buffer.append(buffer_char); - - buffer.append("F"); - n = sprintf(buffer_char, "%.2f", pct_speed); - buffer.append(buffer_char); - - send(buffer); + // PUBLIC FUNCTIONS ---------------------------------------------------------------------------------------------------------------------------------------- + void move(string move_code){ + printf("Moving: %s\n\r", move_code); + send(move_code); } void save_point(int mode, float pct_speed){ @@ -61,7 +38,7 @@ void start_program(void){ send("b"); - printf("b\n\r"); + printf("Starting Program\n\r"); } void cancel_program(void){ @@ -74,7 +51,7 @@ void machine_zero(void){ send("zm"); - printf("zm\n\r"); + printf("Zero Machine\n\r"); } void set_zero(string axis){ @@ -86,15 +63,15 @@ void jog(void){ send("j"); - printf("j\n\r"); + printf("Starting Jog\n\r"); } void kill_jog(void){ send("jk"); - printf("jk\n\r"); + printf("Killing Jog\n\r"); } - void reset (void){ + void reset(void){ send("r"); } @@ -103,6 +80,8 @@ buffer.append("u"); buffer.append(gcode); + printf("Uploading GCODE: %s\n\r", gcode); + send(buffer); } @@ -116,7 +95,7 @@ void clean_glue(void){ send("g"); - printf("g\n\r"); + printf("Cleaning Glue\n\r"); } private: @@ -314,6 +293,10 @@ lcd.locate(col,min); lcd.printf("%c", 0x3E); while (bot_enter==penter){ + if(emerg){ + func = 31; + break; + } if (bot_cima==0){ if (linha==min){ lcd.locate(col,min); @@ -1297,7 +1280,10 @@ } void tela_emergencia(void){ lcd.cls(); - lcd.printf("EMERGENCIA"); + lcd.printf("EMERGENCIA"); + printf("Waiting release..."); + func = 1; + while(!emergencia.read()); } //função para ler os pontos @@ -1326,6 +1312,7 @@ limpar_cola = 0; printf("oi\n\r"); action = 1; + WiFi.putc('ax'); } if (recv == 'p'){
--- 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