Skip to content

Commit

Permalink
Improve queue in RFBridge messages
Browse files Browse the repository at this point in the history
  • Loading branch information
xoseperez committed Jan 21, 2018
1 parent a845d96 commit b51ffc2
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions code/espurna/rfbridge.ino
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ typedef struct {
byte times;
} rfb_message_t;
static std::queue<rfb_message_t> _rfb_message_queue;
Ticker _rfbTicker;
Ticker _rfb_ticker;
bool _rfb_ticker_active = false;

// -----------------------------------------------------------------------------
// PRIVATES
Expand Down Expand Up @@ -166,29 +167,35 @@ void _rfbSend() {
}

// if there are still messages in the queue...
if (!_rfb_message_queue.empty()) {
_rfbTicker.once_ms(RF_SEND_DELAY, _rfbSend);
if (_rfb_message_queue.empty()) {
_rfb_ticker.detach();
_rfb_ticker_active = false;
}

}

void _rfbSend(byte * code, int times) {
void _rfbSend(byte * code, unsigned char times) {

char buffer[RF_MESSAGE_SIZE];
_rfbToChar(code, buffer);
DEBUG_MSG_P(PSTR("[RFBRIDGE] Sending MESSAGE '%s' %d time(s)\n"), buffer, times);
DEBUG_MSG_P(PSTR("[RFBRIDGE] Enqueuing MESSAGE '%s' %d time(s)\n"), buffer, times);

rfb_message_t message;
memcpy(message.code, code, RF_MESSAGE_SIZE);
message.times = times;
_rfb_message_queue.push(message);
_rfbSend();

// Enable the ticker if not running
if (!_rfb_ticker_active) {
_rfb_ticker_active = true;
_rfb_ticker.attach_ms(RF_SEND_DELAY, _rfbSend);
}

}

#if RF_RAW_SUPPORT

void _rfbSendRawOnce(byte *code, int length) {
void _rfbSendRawOnce(byte *code, unsigned char length) {
char buffer[length*2];
_rfbToChar(code, buffer, length);
DEBUG_MSG_P(PSTR("[RFBRIDGE] Sending RAW MESSAGE '%s'\n"), buffer);
Expand Down

0 comments on commit b51ffc2

Please sign in to comment.