Browse Source

simplify rc-switch reader

mcspr-patch-1
Maxim Prokhorov 4 years ago
parent
commit
22924cfd0a
1 changed files with 16 additions and 5 deletions
  1. +16
    -5
      code/espurna/rfbridge.cpp

+ 16
- 5
code/espurna/rfbridge.cpp View File

@ -798,15 +798,26 @@ void _rfbLearnFromReceived(std::unique_ptr<RfbLearn>& learn, const char* buffer)
void _rfbReceiveImpl() { void _rfbReceiveImpl() {
if (!_rfb_receive) return; if (!_rfb_receive) return;
if (!_rfb_modem->available()) return;
// TODO: rc-switch isr handler sets 4 variables at the same time and never checks their existence before overwriting them
// thus, we can't *really* trust that all 4 are from the same reading :/
// TODO: in theory, we may also expirience memory tearing while doing 2 separate 32bit reads on the 64bit code value,
// while isr handler *may* write into it at the same time
auto rf_code = _rfb_modem->getReceivedValue();
if (!rf_code) {
return;
}
#if RFB_RECEIVE_DELAY
static unsigned long last = 0; static unsigned long last = 0;
if (millis() - last < RFB_RECEIVE_DELAY) return;
if (millis() - last < RFB_RECEIVE_DELAY) {
_rfb_modem->resetAvailable();
return;
}
last = millis(); last = millis();
auto rf_code = _rfb_modem->getReceivedValue();
if (!rf_code) return;
#endif
uint8_t message[RfbMessage::BufferSize]; uint8_t message[RfbMessage::BufferSize];
auto real_msgsize = _rfbModemPack( auto real_msgsize = _rfbModemPack(


Loading…
Cancel
Save