sebastian martinez / Mbed 2 deprecated Movimiento_8Servos

Dependencies:   mbed

Fork of 01-04_Primer_Avance by sebastian martinez

main.cpp

Committer:
sebasmartinez
Date:
2018-09-06
Revision:
2:10956b8ceffb
Parent:
1:526bdd5faa37
Child:
3:60722da62531

File content as of revision 2:10956b8ceffb:

#include "mbed.h"

#include "main.h"

#define MEM_SIZE 10
#define MEM_TYPE char
MEM_TYPE buffer[MEM_SIZE];


Serial command(USBTX, USBRX);



int main() {
    init_servo();
    init_serial();
    debug_m("inicio \n");
    
    
    uint32_t read_cc;
    while(1)
    {
        read_cc=read_command();
        debug_m("Entrando TC...\n");

        switch (read_cc) {

            case  0x01: 
            debug_m("Tc1\n");
            
            moving();
            debug_m("FTc1\n");
            break;
            case  0x02: 
            debug_m("Tc2 :) \n");
            //moving();
            debug_m("FTc2\n");
            break;
            default: debug_m("error de comando. \nSe espera  0x01 - 0x08 \n");break ;      
        }
    }
}



uint32_t read_command()
{
   // retorna los byte recibidos concatenados en un entero, 
   
    //char intc=command.getc();
    buffer[0] = command.getc();
    buffer[1] = command.getc();
    buffer[2] = command.getc();
    buffer[3] = command.getc();
    buffer[4] = command.getc();
    
    char intc = buffer[0];
    while(intc != 0xFF){
    
        intc=command.getc();
        
        debug_m("comando inicio invalido \n");
        }
        
        printf("encontrado: %c \n",  buffer[0] ); 
        //intc=command.getc();
        int tele = buffer[1];
        printf("dato siguente: %c \n",  tele ); 


    return tele;
 
}


void init_serial()
{
    command.baud(9600);
    debug_m("Serial 9600 \n");    
}


void moving(){
    debug_m("se inicia el comado mover..\n");    
    
    char nmotor = buffer[2];
    printf("Motor: %c \n",  nmotor ); 
    char grados = buffer[3];
    printf("Grados: %c \n",  grados ); 
    char endc = buffer[4];
    printf("Cierre: %c \n",  endc ); 
    mover_ser(nmotor,grados); 
    
    debug_m("fin del comado mover..\n");    
    
}

void debug_m(char *s , ... ){
    #if DEBUG
    command.printf(s);
    #endif  
}