abrayan

Dependencies:   mbed

main.cpp

Committer:
fabeltranm
Date:
2018-09-07
Revision:
4:6fff0b259d65
Parent:
3:3936d249a67c
Child:
5:66f0a55f249d

File content as of revision 4:6fff0b259d65:

#include "mbed.h"

#include "main.h"




Serial command(USBTX, USBRX);

#define MAXDAT 3
#define TIPO_COMM 0
#define NUM_MOTOR 1
#define NUM_GRADOS 2 


uint8_t dat[MAXDAT]={0,0,0};

  

int main() {
    init_servo();
    init_serial();

    debug_m("inicio \n");
    uint32_t read_cc;
    while(1)
    {
        while(read_command()==0);
        switch (dat[TIPO_COMM]) {
            case  0x01: moving(); break;
            default: debug_m("error de comando. ");break ;      
        }
    }
}



uint32_t read_command()
{
   // retorna los byte recibidos concatenados en un entero, 
   

    
    char intc=command.getc();
    
    while(intc != '<')
        intc=command.getc();
        
    for (int i =0;i>MAXDAT;i++)
        dat[i]=command.getc();
    
    intc=command.getc();
    
    while(intc != '>')
        return 0;
    return 1;
}


void init_serial()
{
    command.baud(9600);    
}


void moving(){
    debug_m("se inicia el comado mover..\n");    
    
    char nmotor=dat[NUM_MOTOR];
    char grados=dat[NUM_GRADOS];
    mover_ser(nmotor,grados); 
    debug_m("fin del comado ..\n");    
    
}

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