nicolas rojas
/
segundo_copy
pausa
Fork of primercorte by
main.cpp
- Committer:
- nicolasrojas
- Date:
- 2018-06-06
- Revision:
- 4:244a242e0428
- Parent:
- 2:c457572a9bb2
- Child:
- 5:9187685429b3
File content as of revision 4:244a242e0428:
#include "mbed.h" #include "main.h" #include "stepmotor.h" Serial command(USBTX, USBRX); stepmotor smotor1(D9,D10,D11,D12); stepmotor smotor2(D2,D3,D14,D15); int main() { init_servo(); init_serial(); draw(); nodraw(); home(); debug_m("inicio \n"); uint32_t read_cc; while(1) { read_cc=read_command(); switch (read_cc) { case CM_DRAWING: drawing(); break; case CM_SAVING: saving(); break; default: debug_m("error de comando. \nSe espera 0xFEF0 o 0xfff0 \n");break ; } } } uint32_t read_command() { uint32_t val=0; uint8_t cnt=0; char endc=command.getc(); while(endc != CM_END && cnt <4) { if(endc!=CM_END) val=((val<<8) +endc); endc=command.getc(); cnt++; } if(endc==CM_END) return val; return 0; } void init_serial(){ command.baud(9600); } void drawing(){ debug_m("se esta ejecutando el dibujo... \n"); uint8_t error=0; MEM_TYPE dato; tail_reset(); while(error==0){ error = mem_get(&dato); if (error==0) { switch (dato) { case CM_DRAW: debug_m("-> Baja Z\n"); draw(); break ; case CM_NODRAW: debug_m("-> Sube Z\n"); nodraw(); break ; default: int y = (uint8_t)(dato); int x = (uint8_t)(dato>>8); char ncomm = (uint8_t)(dato>>16); if (ncomm == CM_VERTEX2D) { debug_m("-> Mover piccolo x a %d y y a %d \n",x,x, y); vertex2d(x,y); }else if (ncomm == CM_MOTOR){ debug_m("-> mover motor paso a paso en x \n"); smotor1.step(x*4096,(bool) y); } else if(ncomn == CM_PAUSA) { debug_m("didujo en pausa\n"); pause(); } debug_m("-> ERROR DE COMMANDO: %d %d %d \n " ,ncomm,x,y,y); } } } debug_m("fin del comando dibujar..\n"); } void saving(){ debug_m("se inicia el comando guardar..\n"); MEM_TYPE dato=0; mem_free(); while(dato !=CM_STOP){ dato = read_command(); if (dato !=CM_STOP) mem_put(dato); } debug_m("fin del comado guardar..\n"); } void pause(){ char d=command.getc(); if(d==CM_PAUSA){ command.attach(0,Serial::RxIrq); debug_m("interrumpe\n"); while(command.getc()!=CM_PLAY){} command.attach(&pause,Serial::RxIrq); return;} } void debug_m(char *s , ... ){ #if DEBUG command.printf(s); #endif }