![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Código para o menu no LCD
Dependencies: mbed SDFileSystemSD TextLCD
Fork of TextLCD_HelloWorld2 by
classes.h
- Committer:
- claraluques
- Date:
- 2018-05-15
- Revision:
- 25:af1f99666ca9
- Parent:
- 24:46c3be0e8273
- Child:
- 26:59081efdce79
File content as of revision 25:af1f99666ca9:
#define tx PC_10 #define rx PC_11 Serial Mach(tx, rx); //SDFileSystem sd(PB_5, PB_4, PB_3, PB_10, "sd"); //MOSI - D4, MISO - D5, SCLK - D3, CS - D6 class Machine { int n; string buffer; char buffer_char[2]; 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); } void save_point(int mode, float pct_speed){ buffer = ""; buffer.append("s"); n = sprintf(buffer_char, "M%d", mode); buffer.append(buffer_char); n = sprintf(buffer_char, "F%.2f", pct_speed); buffer.append(buffer_char); send(buffer); } void start_program(void){ send("b"); printf("b\n\r"); } void cancel_program(void){ send("c"); } void get_status(void){ send("s"); } void machine_zero(void){ send("mz"); } void set_zero(string axis){ buffer = ""; buffer.append("z"); buffer+=axis; send(buffer); } void jog(void){ send("j"); printf("j\n\r"); } void kill_jog(void){ send("jk"); printf("jk\n\r"); } private: // PRIVATE FUNCTIONS ---------------------------------------------------------------------------------------------------------------------------------------- void send(string msg){ msg.append("x"); for(int i = 0; i < msg.length(); i++){ Mach.putc(msg[i]); wait_ms(20); } } }; //criar classe "menu" (funções para as telas) class Menu{ Machine machine; 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; } else if (func==2 || func==8){ if (cx<0){ if (cx<=-1){ lcd.locate(2,1); lcd.printf(" %.2f", cx); } if (cx<=-10 && cx>=-99){ lcd.locate(2,1); lcd.printf(" %.2f", cx); } if (cx<=-100){ lcd.locate(2,1); lcd.printf("%.2f", cx); } } if (cx<=9){ lcd.locate(2,1); lcd.printf(" %.2f", cx); } if (cx>=10 && cx<=99){ lcd.locate(2,1); lcd.printf(" %.2f", cx); } if (cx>=100){ lcd.locate(2,1); lcd.printf(" %.2f", cx); } if (cy<0){ if (cy<=-1){ lcd.locate(2,2); lcd.printf(" %.2f", cy); } if (cy<=-10 && cx>=-99){ lcd.locate(2,2); lcd.printf(" %.2f", cy); } if (cy<=-100){ lcd.locate(2,2); lcd.printf("%.2f", cy); } } if (cy<=9){ lcd.locate(2,2); lcd.printf(" %.2f", cy); } if (cy>=10 && cx<=99){ lcd.locate(2,2); lcd.printf(" %.2f", cy); } if (cy>=100){ lcd.locate(2,2); lcd.printf(" %.2f", cy); } if (cz<0){ if (cz<=-1){ lcd.locate(2,3); lcd.printf(" %.2f", cz); } if (cz<=-10 && cx>=-99){ lcd.locate(2,3); lcd.printf(" %.2f", cz); } if (cz<=-100){ lcd.locate(2,3); lcd.printf("%.2f", cz); } } if (cz<=9){ lcd.locate(2,3); lcd.printf(" %.2f", cz); } if (cz>=10 && cx<=99){ lcd.locate(2,3); lcd.printf(" %.2f", cz); } if (cz>=100){ lcd.locate(2,3); lcd.printf(" %.2f", cz); } } /*} lcd.locate(2,2); lcd.printf("%.2f", cy); lcd.locate(2,3); lcd.printf("%.2f", cz); }*/ if (Mach.readable()){ readSerial(); } } } //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; machine.kill_jog(); wait(0.1); machine.jog(); 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"); movercursor(1,3,10); if (bot_enter!=penter){ 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) { machine.kill_jog(); 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:%.2f ", cx_salva); lcd.locate(1,2); lcd.printf("Y:%.2f ", cy_salva); lcd.locate(1,3); lcd.printf("Z:%.2f ", 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; } machine.save_point(cola,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){ machine.kill_jog(); wait(0.1); machine.start_program(); 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("Zerar:"); lcd.locate(0,1); lcd.printf("X:"); lcd.locate(0,2); lcd.printf("Y:"); lcd.locate(0,3); lcd.printf("Z:"); lcd.locate(13,0); lcd.printf("X"); lcd.locate(13,1); lcd.printf("Y"); lcd.locate(13,2); lcd.printf("Z"); lcd.locate(13,3); lcd.printf("Voltar"); movercursor(0,3,12); if (bot_enter!=penter) { if (linha==0){ cx = 0; func = 10; machine.set_zero("X"); } else if (linha==1){ cy = 0; func = 10; machine.set_zero("Y"); } else if (linha==2){ cz = 0; func = 10; machine.set_zero("Z"); } 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(6,2); lcd.printf("o eixo!"); 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; } void readSerial(){ char recv; int points = 0; int pointx = 0; int pointy = 0; int pointz = 0; string coordx = ""; string coordy = ""; string coordz = ""; while(1){ recv = Mach.getc(); //printf("%c\n\r", recv); if (recv == 'p'){ points = 1; } if (points){ if (recv == 'X'){ pointx = 1; pointy = 0; pointz = 0; } else if (recv == 'Y'){ pointy = 1; pointx = 0; pointz = 0; } else if (recv == 'Z'){ pointz = 1; pointx = 0; pointy = 0; } else if (recv == 'x'){ cx = atof(coordx.c_str()); cy = atof(coordy.c_str()); cz = atof(coordz.c_str()); printf("%s,%s,%s\n\r", coordx, coordy, coordz); break; } } if (pointx){ if (recv!='X'){ coordx.push_back(recv); } } if (pointy){ if (recv!='Y'){ coordy.push_back(recv); } } if (pointz){ if (recv!='Z'){ coordz.push_back(recv); } } } } Menu(); //não apagar };