| 676 | } |
| 677 | |
| 678 | bool RCSwitch::receiveProtocol2(unsigned int changeCount){ |
| 679 | |
| 680 | unsigned long code = 0; |
| 681 | unsigned long delay = RCSwitch::timings[0] / 10; |
| 682 | unsigned long delayTolerance = delay * RCSwitch::nReceiveTolerance * 0.01; |
| 683 | |
| 684 | for (int i = 1; i<changeCount ; i=i+2) { |
| 685 | |
| 686 | if (RCSwitch::timings[i] > delay-delayTolerance && RCSwitch::timings[i] < delay+delayTolerance && RCSwitch::timings[i+1] > delay*2-delayTolerance && RCSwitch::timings[i+1] < delay*2+delayTolerance) { |
| 687 | code = code << 1; |
| 688 | } else if (RCSwitch::timings[i] > delay*2-delayTolerance && RCSwitch::timings[i] < delay*2+delayTolerance && RCSwitch::timings[i+1] > delay-delayTolerance && RCSwitch::timings[i+1] < delay+delayTolerance) { |
| 689 | code+=1; |
| 690 | code = code << 1; |
| 691 | } else { |
| 692 | // Failed |
| 693 | i = changeCount; |
| 694 | code = 0; |
| 695 | } |
| 696 | } |
| 697 | code = code >> 1; |
| 698 | if (changeCount > 6) { // ignore < 4bit values as there are no devices sending 4bit values => noise |
| 699 | RCSwitch::nReceivedValue = code; |
| 700 | RCSwitch::nReceivedBitlength = changeCount / 2; |
| 701 | RCSwitch::nReceivedDelay = delay; |
| 702 | RCSwitch::nReceivedProtocol = 2; |
| 703 | } |
| 704 | |
| 705 | if (code == 0){ |
| 706 | return false; |
| 707 | }else if (code != 0){ |
| 708 | return true; |
| 709 | } |
| 710 | |
| 711 | } |
| 712 | |
| 713 | /** Protocol 3 is used by BL35P02. |
| 714 | * |
nothing calls this directly
no outgoing calls
no test coverage detected