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 02_LAB_serial_protocol by
Diff: main.cpp
- Revision:
- 1:0bcd96e56022
- Parent:
- 0:55d11eeb0faf
- Child:
- 2:200a9507b696
diff -r 55d11eeb0faf -r 0bcd96e56022 main.cpp --- a/main.cpp Wed Apr 26 18:04:57 2017 +0000 +++ b/main.cpp Wed Apr 26 18:22:36 2017 +0000 @@ -25,6 +25,25 @@ uint8_t buffer_command[BUFF_SIZE]={0,0,0,0}; + +void print_num(uint8_t val) + +{ +if (val <10) + command.putc(val+0x30); + else + command.putc(val-10+0x40); + +} +void print_bin2hex (uint8_t val) +{ + command.printf(" 0x"); + print_num(val>>4); + print_num(val&0x0f); + + +} + // TODO : TIMEOUT UART SERIAL void Read_command() { @@ -36,7 +55,7 @@ void echo_command() { for (uint8_t i=0; i<BUFF_SIZE;i++) - command.putc(buffer_command[i]); + print_bin2hex(buffer_command[i]); } @@ -46,15 +65,15 @@ if (buffer_command[BUFF_SIZE-1]== '>' && buffer_command[COMM_SEPARADOR]==','){ #if DEBUG - command.printf("Mover Motor:"); - command.putc(buffer_command[COMM_NUM_MOTOR]+0x30); - command.printf("->"); - command.putc(buffer_command[COMM_GRADOS_MOTOR]); + command.printf("\nMover Motor:"); + print_bin2hex(buffer_command[COMM_NUM_MOTOR]); + command.printf(" -> "); + print_bin2hex(buffer_command[COMM_GRADOS_MOTOR]); command.printf(" grados \n"); #endif }else{ #if DEBUG - command.printf("ERROR COMANDO -> "); + command.printf("\n ERROR COMANDO -> "); echo_command(); #endif @@ -72,9 +91,6 @@ val=command.getc(); if (val== '<'){ Read_command(); - #if DEBUG - echo_command(); - #endif check_command(); }