RS232 control for TVOne products
Diff: spk_tvone_mbed.cpp
- Revision:
- 5:4b0bf9a724a4
- Parent:
- 4:3faabbbf0ecf
- Child:
- 6:767acf32fed5
diff -r 3faabbbf0ecf -r 4b0bf9a724a4 spk_tvone_mbed.cpp --- a/spk_tvone_mbed.cpp Sat Oct 06 12:37:05 2012 +0000 +++ b/spk_tvone_mbed.cpp Sun Oct 07 12:47:24 2012 +0000 @@ -43,16 +43,16 @@ bool SPKTVOne::command(uint8_t channel, uint8_t window, int32_t func, int32_t payload) { + if (debug) debug->printf("TVOne command: IN. "); + char i; // TASK: Sign start of serial command write if (writeDO) *writeDO = 1; - - // TASK: discard anything waiting to be read - while (serial->readable()) { - if (debug) - debug->printf("Warning: data waiting on TV One serial bus: %u\n", serial->getc()); - else + + // TASK: Clear buffer. + while (serial->readable()) + { serial->getc(); } @@ -84,7 +84,7 @@ { checksum += cmd[i]; } - + serial->printf("F%02X%02X%02X%02X%02X%02X%02X%02X%02X\r", cmd[0], cmd[1], cmd[2], cmd[3], cmd[4], cmd[5], cmd[6], cmd[7], checksum); // TASK: Check the unit's return string, to enable return to main program as soon as unit is ready @@ -123,7 +123,7 @@ timer.stop(); // TASK: Sign end of write - + if (writeDO) *writeDO = 0; if (!success) { @@ -138,6 +138,7 @@ } }; + if (debug) debug->printf("OUT. Success = %s \r\n", success ? "true" : "false"); return success; }