Commit 400a56d2 authored by Patrick's avatar Patrick

listen to the feedback from send() and return to the user

parent 8c35be75
......@@ -23,6 +23,8 @@ void SOMO_II::begin(uint8_t input_media)
send(SOURCE, 0x00, input_media);
}
setVol(15);
// wait for the SOMO module to boot up
delay(250);
}
s_SomoMessage SOMO_II::send(e_SomoCMD message, uint8_t para1, uint8_t para2)
......@@ -37,8 +39,35 @@ s_SomoMessage SOMO_II::send(e_SomoCMD message, uint8_t para1, uint8_t para2)
_my_serial.write((uint8_t*)&the_message, sizeof(the_message));
_my_serial.flush();
s_SomoMessage empty;
return empty;
delay(50);
s_SomoMessage reply;
bool end_message = false;
uint32_t last_message = millis();
while (_my_serial.available() && end_message == false && millis() - last_message <= SOMO_SERIAL_TIMEOUT) {
uint8_t in = _my_serial.read();
if (in == SOMO_START_BYTE) {
last_message = millis();
reply.cmd = _my_serial.read();
reply.feedback = _my_serial.read();
reply.para1 = _my_serial.read();
reply.para2 = _my_serial.read();
reply.checksum1 = _my_serial.read();
reply.checksum2 = _my_serial.read();
reply._end = _my_serial.read();
}
if (reply._end == SOMO_END_BYTE) {
// assume that the message is valid
// TODO: validate the checksum bytes
end_message = true;
}
}
if (end_message == false) {
s_SomoMessage empty;
return empty;
} else {
return reply;
}
}
uint8_t SOMO_II::reset()
......
......@@ -7,6 +7,10 @@
#ifndef somo_ii_h
#define somo_ii_h
#define SOMO_BAUD 9600 // SOMO-II is requires 9600 baud
#define SOMO_SERIAL_TIMEOUT 300
#define SOMO_NEXT 0x01
#define SOMO_PREV 0x02
#define SOMO_TRACK_NUM 0x03 // send track no. as para2
......@@ -54,15 +58,18 @@
#define SOMO_FINISHED_uSD 0x3D
#define SOMO_PWR_ON 0x3F
#define SOMO_START_BYTE 0x7E
#define SOMO_END_BYTE 0xEF
typedef struct s_SomoMessage {
uint8_t _start = 0x7E; // $$ = 0x7E
uint8_t _start = SOMO_START_BYTE; // $$ = 0x7E
uint8_t cmd = 0x41;
uint8_t feedback = 0x00;
uint8_t para1 = 0x00;
uint8_t para2 = 0x00;
uint8_t checksum1 = 0xFF;
uint8_t checksum2 = 0xBF;
uint8_t _end = 0xEF; // $0 = 0xEF
uint8_t _end = SOMO_END_BYTE; // $0 = 0xEF
};
enum e_SomoCMD {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment