Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of 01-04EntregaPrimerCorte by
main.cpp
- Committer:
- sebasmartinez
- Date:
- 2018-09-07
- Revision:
- 4:ba51736778e1
- Parent:
- 3:60722da62531
File content as of revision 4:ba51736778e1:
#include "mbed.h"
#include "main.h"
#define MEM_SIZE 5
#define MEM_TYPE char
MEM_TYPE buffer[MEM_SIZE];
Serial command(USBTX, USBRX);
DigitalIn button(USER_BUTTON);
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("Tc 1 Iniciado..\n");
moving();
debug_m("Tc 1 Finalizado\n");
break;
case 0x02:
debug_m("Tc 2 Iniciado.. \n");
pares();
debug_m("Tc 2 Finalizado\n");
break;
default: debug_m("Error de comando. \nSe espera entre 0x01 - 0x08 \n");break ;
}
}
}
uint32_t read_command()
{
// retorna los byte recibidos concatenados en un entero,
// Formato | FF | TC | NM | GR | FD
// Datos | Inicio | Tele-comando | Numero Motor | Grados | Cierre
//char intc=command.getc();
buffer[0] = command.getc();
inicio:
while(buffer[0] != 0xFF ){
buffer[0] = command.getc();
debug_m("comando inicio invalido \n");
}
printf("inicio encontrado: %c \n", buffer[0] );
buffer[1] = command.getc();
if (buffer[1] != 0xFF && buffer[1] != 0xFD){
buffer[2] = command.getc();
}else{
buffer[0] = buffer[1];
goto inicio;
}
if (buffer[2] != 0xFF && buffer[2] != 0xFD){
buffer[3] = command.getc();
}else{
buffer[0] = buffer[2];
goto inicio;
}
if (buffer[3] != 0xFF && buffer[3] != 0xFD){
buffer[4] = command.getc();
}else{
buffer[0] = buffer[3];
goto inicio;
}
//para que evalue el cierre
if (buffer[4] != 0xFF && buffer[4] == 0xFD){
debug_m("comando Cierre valido \n");
}else{
buffer[0] = buffer[4];
goto inicio;
}
//intc=command.getc();
int tele = buffer[1];
printf("Tele 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 pares(){
debug_m("se inicia el comado pares..\n");
char par = buffer[2];
printf("Par: %c \n", par );
char dire = buffer[3];
printf("Dir: %c \n", dire );
char endcc = buffer[4];
printf("Cierre: %c \n", endcc );
while(button == 0) {
mover_par(par,dire);
}
centro(par);
debug_m("fin del comado pares..\n");
}
void debug_m(char *s , ... ){
#if DEBUG
command.printf(s);
#endif
}
