Código para o menu no LCD

Dependencies:   mbed SDFileSystemSD TextLCD

Fork of TextLCD_HelloWorld2 by Wim Huiskamp

Committer:
lucasfontenla
Date:
Mon Jun 11 20:09:48 2018 +0000
Revision:
43:4684aba69ba6
Parent:
42:48096cfdea78
Child:
44:15968c7431c6
mudan?as

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