MCPcopy Create free account
hub / github.com/SmingHub/Sming / receiveProtocol

Method receiveProtocol

Sming/Libraries/RCSwitch/RCSwitch.cpp:671–703  ·  view source on GitHub ↗

* */

Source from the content-addressed store, hash-verified

669 *
670 */
671bool RCSwitch::receiveProtocol(const int p, unsigned int changeCount) {
672
673 Protocol pro;
674 memcpy(&pro, &proto[p-1], sizeof(Protocol));
675
676 unsigned long code = 0;
677 const unsigned int delay = RCSwitch::timings[0] / pro.syncFactor.low;
678 const unsigned int delayTolerance = delay * RCSwitch::nReceiveTolerance / 100;
679
680 for (unsigned int i = 1; i < changeCount; i += 2) {
681 code <<= 1;
682 if (diff(RCSwitch::timings[i], delay * pro.zero.high) < delayTolerance &&
683 diff(RCSwitch::timings[i + 1], delay * pro.zero.low) < delayTolerance) {
684 // zero
685 } else if (diff(RCSwitch::timings[i], delay * pro.one.high) < delayTolerance &&
686 diff(RCSwitch::timings[i + 1], delay * pro.one.low) < delayTolerance) {
687 // one
688 code |= 1;
689 } else {
690 // Failed
691 return false;
692 }
693 }
694
695 if (changeCount > 6) { // ignore < 4bit values as there are no devices sending 4bit values => noise
696 RCSwitch::nReceivedValue = code;
697 RCSwitch::nReceivedBitlength = changeCount / 2;
698 RCSwitch::nReceivedDelay = delay;
699 RCSwitch::nReceivedProtocol = p;
700 }
701
702 return true;
703}
704
705void RCSwitch::handleInterrupt() {
706

Callers

nothing calls this directly

Calls 1

diffFunction · 0.85

Tested by

no test coverage detected