Código para o menu no LCD

Dependencies:   mbed SDFileSystemSD TextLCD

Fork of TextLCD_HelloWorld2 by Wim Huiskamp

Files at this revision

API Documentation at this revision

Comitter:
claraluques
Date:
Tue May 15 16:20:06 2018 +0000
Parent:
20:ccbd80b668ce
Child:
22:22ddb0b21d48
Commit message:
Adicionada fun??o para recebimento de caracteres via serial.

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	Tue May 15 14:35:25 2018 +0000
+++ b/classes.h	Tue May 15 16:20:06 2018 +0000
@@ -113,6 +113,11 @@
     public:
     int linha;
     int func;
+    int points;
+    int pointx;
+    int pointy;
+    int pointz;
+    
     
     void movercursor(int min, int max, int col){ //função para mover cursor de seleção
         linha = min;
@@ -161,6 +166,9 @@
                 lcd.locate(2,3);
                 lcd.printf("%.3f", cz);
                 }
+            if Mach.readable(){
+                readSerial();
+                }
             }          
         }
                        
@@ -375,6 +383,8 @@
         movercursor(2,3,13);
         if (bot_enter!=penter) {
             if (linha==2){
+                machine.kill_jog();
+                wait(0.1);
                 machine.start_program();
                 exec = 1;
                 func = 9;
@@ -494,7 +504,35 @@
         lcd.printf("Conclua seu programa");
         wait(1);
         func = 2;
-        }      
+        }   
+        
+           
+    private:
+    void readSerial(){
+        char recv;
+        
+        while(1){
+            recv = Mach.getc();
+            printf("%c\n\r", recv);
+            if (recv=='p'){
+                points = 1;
+                if (recv=='X'){
+                    pointx = 1;
+                    cx = 
+                    }
+                else if (recv=='Y'){
+                    pointy = 1;
+                    cy =
+                    }
+                else if (recv=='Z'){
+                    pointz = 1;
+                    cz = 
+                else if (recv=='x'){
+                    break;
+                    }
+                }    
+            }
+        }
+    Menu(); //não apagar
     
-    Menu(); //não apagar
 };
\ No newline at end of file
--- a/main.cpp	Tue May 15 14:35:25 2018 +0000
+++ b/main.cpp	Tue May 15 16:20:06 2018 +0000
@@ -3,7 +3,6 @@
 #include "mbed.h"
 #include "TextLCD.h"
 #include "string"
-//#include "classes.h"
 
 // Host PC Communication channels
 Serial pc(USBTX, USBRX); // tx, rx //não apagar
@@ -30,7 +29,6 @@
 int exec;
 int select = 0;
 int pontos = 10;
-int coords;
 
 //variáveis float
 float cx = 120.458;
@@ -52,386 +50,6 @@
 
 #include "classes.h"
 
-//criar classe "menu" (funções para as telas)
-/*class Menu{
-    public:
-    int linha;
-    int func;
-    
-    void movercursor(int min, int max, int col){ //função para mover cursor de seleção
-        linha = min;
-        lcd.locate(col,min);
-        lcd.printf("%c", 0x3E);
-        while (bot_enter==penter){
-            if (bot_cima==1){
-                if (linha==min){
-                    lcd.locate(col,min);
-                    lcd.printf(" ");
-                    linha=max;
-                    lcd.locate(col, linha);
-                    lcd.printf("%c", 0x3E);
-                    } 
-                else {
-                    lcd.locate(col,linha);
-                    lcd.printf(" ");
-                    linha--;
-                    lcd.locate(col, linha);
-                    lcd.printf("%c", 0x3E);
-                    }  
-                bot_cima = 0;
-                }
-            else if (bot_baixo==1){
-                if (linha==max){
-                    lcd.locate(col,max);
-                    lcd.printf(" ");
-                    linha=min;
-                    lcd.locate(col, linha);
-                    lcd.printf("%c", 0x3E);
-                    }
-                else {
-                    lcd.locate(col,linha);
-                    lcd.printf(" ");
-                    linha++;
-                    lcd.locate(col, linha);
-                    lcd.printf("%c", 0x3E);
-                    }
-                bot_baixo = 0;
-                }
-            if (func==2){
-                lcd.locate(2,1);
-                lcd.printf("%.3f", cx);
-                lcd.locate(2,2);
-                lcd.printf("%.3f", cy);
-                lcd.locate(2,3);
-                lcd.printf("%.3f", cz);
-                }
-            //cx = cx + 0.1;
-            //cy = cy + 0.1;
-            //cz = cz + 0.1;
-            }          
-        }
-                       
-    //func 0
-    void inicializar(){ //função tela incial de boas-vindas
-        lcd.cls();
-        lcd.locate(4,0);
-        lcd.printf("Bem-vindo(a)");
-        lcd.locate(0,1);
-        lcd.printf("Utilize seu EPI para operar a maquina.");
-        wait(1);
-        func = 1;
-        }
-    
-    //func 1    
-    void menuprincipal(){ //função menu principal
-        bot_enter = 0;
-        lcd.cls();
-        lcd.locate(1,0);
-        lcd.printf("Modo JOG");
-        lcd.locate(1,1);
-        lcd.printf("Modo Automatico");
-        lcd.locate(1,2);
-        lcd.printf("Config");
-        lcd.locate(1,3);
-        lcd.printf("Zerar");
-        movercursor(0,3,0);
-        if (bot_enter!=penter){
-            if (linha==0){
-                func = 2;
-                }
-            else if (linha==1) {
-                func = 3;
-                }
-            else if (linha==2) {
-                func = 4;
-                }
-            else if (linha==3) {
-                func = 8;
-                }
-            }
-        } 
-        
-    //func 2    
-    void jog(){ //função tela jog
-        bot_enter = 0;
-        coords = 0;
-        lcd.cls();
-        lcd.locate(4,0);
-        lcd.printf("Coordenadas:");
-        lcd.locate(0,1);
-        lcd.printf("X:");
-        lcd.locate(0,2);
-        lcd.printf("Y:");
-        lcd.locate(0,3);
-        lcd.printf("Z:");
-        lcd.locate(11,1);
-        lcd.printf("Salvar");
-        lcd.locate(11,2);
-        lcd.printf("Concluir");
-        lcd.locate(11,3);
-        lcd.printf("Cancelar");        
-        //while (bot_enter==penter){            
-            //lcd.locate(2,1);
-            //lcd.printf("%.3f", cx);
-            //lcd.locate(2,2);
-            //lcd.printf("%.3f", cy);
-            //lcd.locate(2,3);
-            //lcd.printf("%.3f", cz); 
-            movercursor(1,3,10);
-            //cx++;
-            //cy++;
-            //cz++;
-           // }         
-        if (bot_enter!=penter){
-            coords = 1;
-            if (linha==1){                
-                if (pontos>0){
-                    pontos--;
-                    cx_salva = cx;
-                    cy_salva = cy;
-                    cz_salva = cz;
-                    func = 5;
-                    }
-                else if (pontos==0){
-                    func = 16;
-                    }
-                }
-            else if (linha==2) {
-                func = 7;
-                }
-            else if (linha==3) {
-                func = 1;
-                pontos = 10;
-                }
-            }    
-        }
-        
-    //func 3
-    void automatico(){ //tela modo automatico
-        lcd.cls();
-        bot_enter = 0;
-        lcd.printf("Modo automatico");
-        lcd.locate(7,2);
-        lcd.printf("OK");
-        lcd.locate(7,3);
-        lcd.printf("Voltar");
-        movercursor(2,3,6);
-        if (bot_enter!=penter) {
-            if (linha==2){
-                func = 12;
-                }
-            else if (linha==3){
-                func = 1;
-                }
-            }
-        }
-    
-    //func 4
-    void config() {
-        lcd.cls();
-        bot_enter = 0;
-        lcd.locate(1,0);
-        lcd.printf("Definir velocidade");
-        lcd.locate(1,1);
-        lcd.printf("Limpar seringa cola");
-        lcd.locate(1,2);
-        lcd.printf("Desligar a maquina");
-        lcd.locate(1,3);
-        lcd.printf("Voltar");
-        movercursor(0,3,0);
-        if (bot_enter!=penter){
-            if (linha==0) {
-                func = 13;
-                }
-            else if (linha==1) {
-                func = 14;
-                }
-            else if (linha==2) {
-                func = 15;
-                }
-            else if (linha==3) {
-                func = 1;
-                }
-            }        
-        }
-        
-    //func 5
-    void telasalvamento(){ //função para quando salvar um ponto
-        lcd.cls();
-        lcd.locate(0,0);
-        lcd.printf("Voce salvou");
-        lcd.locate(1,1);
-        lcd.printf("X:%.3f", cx_salva);
-        lcd.locate(1,2);
-        lcd.printf("Y:%.3f", cy_salva);
-        lcd.locate(1,3);
-        lcd.printf("Z:%.3f", cz_salva);
-        lcd.locate(13,1);
-        lcd.printf("Pontos");
-        lcd.locate(13,2);
-        lcd.printf("livres");
-        lcd.locate(16,3);
-        lcd.printf("%d", pontos);
-        wait(1);
-        if (pontos>0){
-            func = 6;
-            }
-        else if (pontos==0){
-            func = 2;
-            }
-        }
-        
-    //func 6
-    void telacola(){ //tela para escolher o tipo de sequencia da cola
-        lcd.cls();
-        bot_enter = 0;
-        lcd.printf("P/ o proximo ponto:");
-        lcd.locate(3,1);
-        lcd.printf("Sem cola");
-        lcd.locate(3,2);
-        lcd.printf("Cola no ponto");
-        lcd.locate(3,3);
-        lcd.printf("Cola continua");
-        movercursor(1,3,2);
-        if (bot_enter!=penter){
-            if (linha==1){
-                cola = 0;
-                func = 2;
-                }
-            else if (linha==2) {
-                cola = 1;
-                func = 2;
-                }
-            else if (linha==3) {
-                cola = 2;
-                func = 2;
-                }
-            }
-        }
-    
-    //func 7        
-    void executarprograma() { //tela para selecionar se deseja executar o programa
-        lcd.cls();
-        bot_enter = 0;
-        lcd.locate(2,0);
-        lcd.printf("VOCE CONCLUIU SEU");
-        lcd.locate(5,1);
-        lcd.printf("PROGRAMA.");
-        lcd.locate(0,2);
-        lcd.printf("Deseja");
-        lcd.locate(0,3);
-        lcd.printf("executa-lo?");
-        lcd.locate(14,2);
-        lcd.printf("Sim");
-        lcd.locate(14,3);
-        lcd.printf("Voltar");
-        movercursor(2,3,13);
-        if (bot_enter!=penter) {
-            if (linha==2){
-                exec = 1;
-                func = 9;
-                }
-            else if (linha==3){
-                exec = 0;
-                func = 2;
-                }
-            }
-        }
-    
-    //func 8
-    void telazerar(){ //tela para zerar a máquina
-        lcd.cls();
-        bot_enter = 0;
-        lcd.locate(2,0);
-        lcd.printf("Pressione OK para zerar as coordenadas");
-        lcd.locate(7,2);
-        lcd.printf("OK");
-        lcd.locate(7,3);
-        lcd.printf("Voltar");            
-        movercursor(2,3,6);
-        if (bot_enter!=penter) {
-            if (linha==2){
-                cx = 0;
-                cy = 0;
-                cz = 0;
-                func = 10;
-                }
-            else if (linha==3){
-                func = 1;
-                }
-            }
-        }
-        
-    //func 9
-    void executando(){ //tela de executando
-        lcd.cls();
-        lcd.locate(4,1);
-        lcd.printf("Executando");
-        int contador = 0;
-        while (exec==1){
-            lcd.locate(14,1);
-            lcd.printf(".  ");
-            wait(0.5);
-            lcd.locate(14,1);
-            lcd.printf(".. ");
-            wait(0.5);
-            lcd.locate(14,1);
-            lcd.printf("...");
-            wait(0.5);
-            lcd.locate(14,1);
-            lcd.printf("   ");
-            wait(0.5);
-            contador++;
-            if (contador>=2){
-                exec = 0;
-                func = 11;
-                }
-            }
-        }
-    
-    //func 10
-    void zerado() { //tela avisando que a máquina foi zerada
-        lcd.cls();
-        lcd.locate(5,1);
-        lcd.printf("Voce zerou");
-        lcd.locate(5,2);
-        lcd.printf("a maquina!");
-        wait(1);
-        func = 8;
-        }
-        
-    //func 11
-    void finalizado() { //tela aviso programa finalizado
-        lcd.cls();
-        lcd.locate(6,1);
-        lcd.printf("PROGRAMA");
-        lcd.locate(5,2);
-        lcd.printf("FINALIZADO");
-        wait(1);
-        func = 1;
-        }     
-        
-    //func 12
-    
-    //func 13
-    
-    //func 14
-    
-    //func 15
-    
-    //func 16
-    void limitepontos(){ //tela para quando acabam os pontos
-        lcd.cls();
-        lcd.printf(" Voce atingiu o n%c   maximo de pontos.", 0xDF);
-        lcd.locate(0,3);
-        lcd.printf("Conclua seu programa");
-        wait(1);
-        func = 2;
-        }      
-    
-    Menu(); //não apagar
-};*/
-
 Menu::Menu(){ //não apagar
     func = 0;
     }
@@ -439,7 +57,6 @@
 Machine machine;
 Menu menu;  
 
-
 int main () {
     lcd.setBacklight(TextLCD::LightOn); //liga backlight
     lcd.setCursor(TextLCD::CurOff_BlkOff); //define tipo de cursor
@@ -486,5 +103,4 @@
               pbaixo = bot_baixo;
               bot_baixo = !bot_baixo;
               //printf("baixo high");
-              }   
-                    
\ No newline at end of file
+              }   
\ No newline at end of file