Código para o menu no LCD

Dependencies:   mbed SDFileSystemSD TextLCD

Fork of TextLCD_HelloWorld2 by Wim Huiskamp

Committer:
lucasfontenla
Date:
Tue Feb 26 00:56:55 2019 +0000
Revision:
49:ab4ab0924fd1
Parent:
44:15968c7431c6
Uploading for Projeto Mecatronico 2019;

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