lib/rc-switch.c

changeset 29
ac763b87ee25
parent 28
32ed1ea4d0b6
child 32
3bac8fd4173d
equal deleted inserted replaced
28:32ed1ea4d0b6 29:ac763b87ee25
26 #include "../config.h" 26 #include "../config.h"
27 #include "mbselib.h" 27 #include "mbselib.h"
28 28
29 #ifdef HAVE_WIRINGPI_H 29 #ifdef HAVE_WIRINGPI_H
30 30
31
32 #define TYPE_UNDEF 0
33 #define TYPE_MINIMUM 0
34 #define TYPE_A 1
35 #define TYPE_B 2
36 #define TYPE_C 3
37 #define TYPE_D 4
38 #define TYPE_E 3 // TODO: Which Protocol does REV use?
39 #define TYPE_MAXIMUM 4
40
41 // Number of maximum High/Low changes per packet.
42 // We can handle up to (unsigned long) => 32 bit * 2 H/L changes per bit + 2 for sync
43 #define RCSWITCH_MAX_CHANGES 67
44
45 // i.e. ProtocolCount + 1 (for TYPE_UNDEF)
46 #define MAX_PROTOCOLS 5
47
48 #define PROTOCOL_A_SYNC_FACTOR 31
49 #define PROTOCOL_A_ZERO_FIRST_CYCLES 1
50 #define PROTOCOL_A_ZERO_SECOND_CYCLES 3
51 #define PROTOCOL_A_ONE_FIRST_CYCLES 3
52 #define PROTOCOL_A_ONE_SECOND_CYCLES 1
53 #define PROTOCOL_A_HIGH_FIRST true
54
55 #define PROTOCOL_B_SYNC_FACTOR 10
56 #define PROTOCOL_B_ZERO_FIRST_CYCLES 1
57 #define PROTOCOL_B_ZERO_SECOND_CYCLES 2
58 #define PROTOCOL_B_ONE_FIRST_CYCLES 2
59 #define PROTOCOL_B_ONE_SECOND_CYCLES 1
60 #define PROTOCOL_B_HIGH_FIRST true
61
62 #define PROTOCOL_C_SYNC_FACTOR 71
63 #define PROTOCOL_C_ZERO_FIRST_CYCLES 4
64 #define PROTOCOL_C_ZERO_SECOND_CYCLES 11
65 #define PROTOCOL_C_ONE_FIRST_CYCLES 9
66 #define PROTOCOL_C_ONE_SECOND_CYCLES 6
67 #define PROTOCOL_C_HIGH_FIRST true
68
69 // I think, this will work for receive, however, I haven't tested, as I don't own a receiver...
70 // As Type D doesn't sync acc. to https://github.com/d-a-n/433-codes/blob/master/database.md#quigg
71 // the sync factor is totally undetermined.
72 // Malte Diers, 22.11.2013
73 #define PROTOCOL_D_SYNC_FACTOR 1
74 #define PROTOCOL_D_ZERO_FIRST_CYCLES 1
75 #define PROTOCOL_D_ZERO_SECOND_CYCLES 2
76 #define PROTOCOL_D_ONE_FIRST_CYCLES 2
77 #define PROTOCOL_D_ONE_SECOND_CYCLES 1
78 #define PROTOCOL_D_HIGH_FIRST false
79
80
81 #define PROTOCOL3_SYNC_FACTOR 71
82 #define PROTOCOL3_0_HIGH_CYCLES 4
83 #define PROTOCOL3_0_LOW_CYCLES 11
84 #define PROTOCOL3_1_HIGH_CYCLES 9
85 #define PROTOCOL3_1_LOW_CYCLES 6
86
87
88
31 unsigned long rcReceivedValue = 0; 89 unsigned long rcReceivedValue = 0;
32 unsigned int rcReceivedBitlength = 0; 90 unsigned int rcReceivedBitlength = 0;
33 unsigned int rcReceivedDelay = 0; 91 unsigned int rcReceivedDelay = 0;
34 unsigned int rcReceivedProtocol = 0; 92 unsigned int rcReceivedProtocol = 0;
35 int rcReceiveTolerance = 60; 93 int rcReceiveTolerance = 60;
36 int rcReceiverInterruptPin = -1; 94 int rcReceiverInterruptPin = -1;
37 95
38 unsigned int timings[RCSWITCH_MAX_CHANGES]; 96 unsigned int timings[RCSWITCH_MAX_CHANGES];
39 int rcTransmitterPin = -1; 97 int rcTransmitterPin = -1;
40 int rcPulseLength = 350; 98 int rcPulseLength = 350; // thermometers 2.4 msec = 2400
41 int rcRepeatTransmit = 10; 99 int rcRepeatTransmit = 10;
42 int rcProtocol = 1; 100 int rcProtocol = 1;
101
102 int backupProtocol;
103 int backupPulseLength;
104 int backupRepeatTransmit;
105
43 106
44 //const char TYPE_A_CODE[ 6][6] = { "00000", "10000", "01000", "00100", "00010", "00001"}; 107 //const char TYPE_A_CODE[ 6][6] = { "00000", "10000", "01000", "00100", "00010", "00001"};
45 const char TYPE_B_CODE[ 5][5] = { "FFFF", "0FFF", "F0FF", "FF0F", "FFF0" }; 108 const char TYPE_B_CODE[ 5][5] = { "FFFF", "0FFF", "F0FF", "FF0F", "FFF0" };
46 const char TYPE_C_CODE[16][5] = { "0000", "F000", "0F00", "FF00", "00F0", "F0F0", "0FF0", "FFF0", 109 const char TYPE_C_CODE[16][5] = { "0000", "F000", "0F00", "FF00", "00F0", "F0F0", "0FF0", "FFF0",
47 "000F", "F00F", "0F0F", "FF0F", "00FF", "F0FF", "0FFF", "FFFF" }; 110 "000F", "F00F", "0F0F", "FF0F", "00FF", "F0FF", "0FFF", "FFFF" };
48 const char TYPE_D_CODE[5][2][9] = { { "11100001", "11110000" }, { "00000000", "00010001" }, { "10000010", "10010011" }, 111 const char TYPE_D_CODE[5][2][9] = { { "11100001", "11110000" }, { "00000000", "00010001" }, { "10000010", "10010011" },
49 { "11000011", "11010010" }, { "01000001", "01010000" } }; 112 { "11000011", "11010010" }, { "01000001", "01010000" } };
113 /* Type A Type D */
114 const int PULSE_LENGTH[MAX_PROTOCOLS] = { 0, 350, 650, 100, 666, };
115 const int REPEAT_TRANSMIT[MAX_PROTOCOLS] = { 0, 10, 10, 10, 4, };
116 const int SYNC_FACTOR[MAX_PROTOCOLS] = { 0, PROTOCOL_A_SYNC_FACTOR, PROTOCOL_B_SYNC_FACTOR, PROTOCOL_C_SYNC_FACTOR, PROTOCOL_D_SYNC_FACTOR, };
117 const int ZERO_FIRST_CYCLES[MAX_PROTOCOLS] = { 0, PROTOCOL_A_ZERO_FIRST_CYCLES, PROTOCOL_B_ZERO_FIRST_CYCLES, PROTOCOL_C_ZERO_FIRST_CYCLES, PROTOCOL_D_ZERO_FIRST_CYCLES, };
118 const int ZERO_SECOND_CYCLES[MAX_PROTOCOLS] = { 0, PROTOCOL_A_ZERO_SECOND_CYCLES, PROTOCOL_B_ZERO_SECOND_CYCLES, PROTOCOL_C_ZERO_SECOND_CYCLES, PROTOCOL_D_ZERO_SECOND_CYCLES, };
119 const int ONE_FIRST_CYCLES[MAX_PROTOCOLS] = { 0, PROTOCOL_A_ONE_FIRST_CYCLES, PROTOCOL_B_ONE_FIRST_CYCLES, PROTOCOL_C_ONE_FIRST_CYCLES, PROTOCOL_D_ONE_FIRST_CYCLES, };
120 const int ONE_SECOND_CYCLES[MAX_PROTOCOLS] = { 0, PROTOCOL_A_ONE_SECOND_CYCLES, PROTOCOL_B_ONE_SECOND_CYCLES, PROTOCOL_C_ONE_SECOND_CYCLES, PROTOCOL_D_ONE_SECOND_CYCLES, };
121 const bool HIGH_FIRST[MAX_PROTOCOLS] = { 0, PROTOCOL_A_HIGH_FIRST, PROTOCOL_B_HIGH_FIRST, PROTOCOL_C_HIGH_FIRST, PROTOCOL_D_HIGH_FIRST, };
50 122
51 123
52 char *getCodeWordA(char*, char*, bool); 124 char *getCodeWordA(char*, char*, bool);
53 char *getCodeWordB(int, int, bool); 125 char *getCodeWordB(int, int, bool);
54 char *getCodeWordC(char, int, int, bool); 126 char *getCodeWordC(char, int, int, bool);
55 127
56 char *getCodeWordE(char, int, bool); 128 char *getCodeWordE(char, int, bool);
57 void sendTriState(char*); 129 void sendTriState(char*);
58 void transmit(int, int); 130 void transmit(int, int, bool);
59 void send0(void); 131 void send0(void);
60 void send1(void); 132 void send1(void);
61 void sendT0(void); 133 void sendT0(void);
62 void sendT1(void); 134 void sendT1(void);
63 void sendTF(void); 135 void sendTF(void);
64 void sendSync(void); 136 void sendSync(void);
65 bool receiveProtocol1(unsigned int); 137 bool receiveProtocol1(unsigned int);
66 bool receiveProtocol2(unsigned int); 138 bool receiveProtocol2(unsigned int);
67 bool receiveProtocol3(unsigned int); 139 bool receiveProtocol3(unsigned int);
68 void handleInterrupt(void); 140 void handleInterrupt(void);
69 char *dec2binWzerofill(unsigned long, unsigned int);
70 char *dec2binWcharfill(unsigned long, unsigned int, char); 141 char *dec2binWcharfill(unsigned long, unsigned int, char);
71 142
143 void setReceiveTolerance(int);
144 void setProtocol(int);
145
146 void saveProtocol(int);
147 void loadProtocol(void);
72 148
73 149
74 150
75 /* 151 /*
76 * Sets the protocol to send. 152 * Sets the protocol to send.
77 */ 153 */
78 void setProtocol(int nProtocol) { 154 void setProtocol(int nProtocol) {
79 rcProtocol = nProtocol; 155
80 if (nProtocol == 1){ 156 if ((nProtocol < TYPE_MINIMUM) || (nProtocol > TYPE_MAXIMUM)) {
81 setPulseLength(350); 157 return;
82 } 158 }
83 else if (nProtocol == 2) { 159
84 setPulseLength(650); 160 rcProtocol = nProtocol;
85 } 161 rcPulseLength = PULSE_LENGTH[nProtocol];
86 else if (nProtocol == 3) { 162 rcRepeatTransmit = REPEAT_TRANSMIT[nProtocol];
87 setPulseLength(100);
88 }
89 }
90
91
92
93 /**
94 * Sets the protocol to send with pulse length in microseconds.
95 */
96 /*void RCSwitch::setProtocol(int nProtocol, int nPulseLength) {
97 this->nProtocol = nProtocol;
98 this->setPulseLength(nPulseLength);
99 }*/
100
101
102
103 /*
104 * Sets pulse length in microseconds
105 */
106 void setPulseLength(int nPulseLength) {
107 rcPulseLength = nPulseLength;
108 }
109
110
111
112 /*
113 * Sets Repeat Transmits
114 */
115 void setRepeatTransmit(int nRepeatTransmit) {
116 rcRepeatTransmit = nRepeatTransmit;
117 } 163 }
118 164
119 165
120 166
121 /* 167 /*
122 * Set Receiving Tolerance 168 * Set Receiving Tolerance
123 */ 169 */
124 void setReceiveTolerance(int nPercent) { 170 void setReceiveTolerance(int nPercent) {
125 rcReceiveTolerance = nPercent; 171 rcReceiveTolerance = nPercent;
126 } 172 }
173
127 174
128 175
129 /* 176 /*
130 * Enable transmissions 177 * Enable transmissions
131 * 178 *
207 * @param nGroup Number of group (1..4) 254 * @param nGroup Number of group (1..4)
208 * @param nDevice Number of device (1..4) 255 * @param nDevice Number of device (1..4)
209 * @param bStatus Status to toggle to 256 * @param bStatus Status to toggle to
210 */ 257 */
211 int toggleTypeC(char sFamily, int nGroup, int nDevice, bool bStatus) { 258 int toggleTypeC(char sFamily, int nGroup, int nDevice, bool bStatus) {
212 sendTriState( getCodeWordC(sFamily, nGroup, nDevice, bStatus) ); 259 char *str = xstrcpy(getCodeWordC(sFamily, nGroup, nDevice, bStatus));
260
261 if (strlen(str) == 0)
262 return 1;
263
264 saveProtocol(TYPE_A); // ???
265 sendTriState( str );
266 loadProtocol();
267 free(str);
213 return 0; 268 return 0;
214 } 269 }
215 270
216 271
217 272
227 char *str = xstrcpy(getCodeWordB(iGroup, iDevice, bStatus)); 282 char *str = xstrcpy(getCodeWordB(iGroup, iDevice, bStatus));
228 283
229 if (strlen(str) == 0) 284 if (strlen(str) == 0)
230 return 1; 285 return 1;
231 286
232 // save(TYPE_B); 287 saveProtocol(TYPE_A); // They do better with protocol A timings.
233 sendTriState( str ); 288 sendTriState( str );
234 // load(); 289 loadProtocol();
235 free(str); 290 free(str);
236 return 0; 291 return 0;
237 } 292 }
238 293
239 294
244 * @param sGroup Code of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111") 299 * @param sGroup Code of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111")
245 * @param sDevice Code of the switch device (refers to DIP switches 6..10 (A..E) where "1" = on and "0" = off, if all DIP switches are on it's "11111") 300 * @param sDevice Code of the switch device (refers to DIP switches 6..10 (A..E) where "1" = on and "0" = off, if all DIP switches are on it's "11111")
246 * @param bStatus Status to toggle to 301 * @param bStatus Status to toggle to
247 */ 302 */
248 int toggleTypeA(char* sGroup, char* sDevice, bool bStatus) { 303 int toggleTypeA(char* sGroup, char* sDevice, bool bStatus) {
249 sendTriState( getCodeWordA(sGroup, sDevice, bStatus) ); 304 char *str = xstrcpy(getCodeWordA(sGroup, sDevice, bStatus));
305
306 if (strlen(str) == 0)
307 return 1;
308
309 saveProtocol(TYPE_A);
310 sendTriState( str );
311 loadProtocol();
312 free(str);
250 return 0; 313 return 0;
251 } 314 }
252 315
253 316
254 317
544 } 607 }
545 } 608 }
546 */ 609 */
547 610
548 611
549 void transmit(int nHighPulses, int nLowPulses) 612 void transmit(int nFirstPulses, int nSecondPulses, bool bHighFirst)
550 { 613 {
551 bool disabled_Receive = false; 614 bool disabled_Receive = false;
552 int nReceiverInterrupt_backup = rcReceiverInterruptPin; 615 int nReceiverInterrupt_backup = rcReceiverInterruptPin;
553 616
554 if (rcTransmitterPin != -1) { 617 if (rcTransmitterPin != -1) {
555 if (rcReceiverInterruptPin != -1) { 618 if (rcReceiverInterruptPin != -1) {
556 disableReceive(); 619 disableReceive();
557 disabled_Receive = true; 620 disabled_Receive = true;
558 } 621 }
559 digitalWrite(rcTransmitterPin, HIGH); 622 digitalWrite(rcTransmitterPin, bHighFirst ? HIGH : LOW);
560 delayMicroseconds( rcPulseLength * nHighPulses); 623 delayMicroseconds( rcPulseLength * nFirstPulses);
561 digitalWrite(rcTransmitterPin, LOW); 624 digitalWrite(rcTransmitterPin, bHighFirst ? LOW : HIGH);
562 delayMicroseconds( rcPulseLength * nLowPulses); 625 delayMicroseconds( rcPulseLength * nSecondPulses);
563 626
564 if (disabled_Receive) { 627 if (disabled_Receive) {
565 enableReceiveIRQ(nReceiverInterrupt_backup); 628 enableReceiveIRQ(nReceiverInterrupt_backup);
566 } 629 }
567 } 630 }
576 * _ 639 * _
577 * Waveform Protocol 2: | |__ 640 * Waveform Protocol 2: | |__
578 * ____ 641 * ____
579 * Waveform Protocol 3: | |___________ 642 * Waveform Protocol 3: | |___________
580 */ 643 */
581 void send0(void) { 644 //void send0(void) {
582 if (rcProtocol == 1){ 645 // if (rcProtocol == 1){
583 transmit(1,3); 646 // transmit(1,3);
584 } 647 // }
585 else if (rcProtocol == 2) { 648 // else if (rcProtocol == 2) {
586 transmit(1,2); 649 // transmit(1,2);
587 } 650 // }
588 else if (rcProtocol == 3) { 651 // else if (rcProtocol == 3) {
589 transmit(4,11); 652 // transmit(4,11);
590 } 653 // }
591 } 654 //}
592 655
593 656
594 657
595 /* 658 /*
596 * Sends a "1" Bit 659 * Sends a "1" Bit
599 * __ 662 * __
600 * Waveform Protocol 2: | |_ 663 * Waveform Protocol 2: | |_
601 * _________ 664 * _________
602 * Waveform Protocol 3: | |______ 665 * Waveform Protocol 3: | |______
603 */ 666 */
604 void send1(void) { 667 //void send1(void) {
605 if (rcProtocol == 1){ 668 // if (rcProtocol == 1){
606 transmit(3,1); 669 // transmit(3,1);
607 } 670 // }
608 else if (rcProtocol == 2) { 671 // else if (rcProtocol == 2) {
609 transmit(2,1); 672 // transmit(2,1);
610 } 673 // }
611 else if (rcProtocol == 3) { 674 // else if (rcProtocol == 3) {
612 transmit(9,6); 675 // transmit(9,6);
613 } 676 // }
614 } 677 //}
615 678
616 679
617 680
618 /* 681 /*
619 * Sends a Tri-State "0" Bit 682 * Sends a Tri-State "0" Bit
620 * _ _ 683 * _ _
621 * Waveform: | |___| |___ 684 * Waveform: | |___| |___
622 */ 685 */
623 void sendT0(void) { 686 void sendT0(void) {
624 transmit(1,3); 687 transmit(ZERO_FIRST_CYCLES[rcProtocol], ZERO_SECOND_CYCLES[rcProtocol], HIGH_FIRST[rcProtocol]);
625 transmit(1,3); 688 transmit(ZERO_FIRST_CYCLES[rcProtocol], ZERO_SECOND_CYCLES[rcProtocol], HIGH_FIRST[rcProtocol]);
689 // transmit(1,3,true);
690 // transmit(1,3,true);
626 } 691 }
627 692
628 693
629 694
630 /* 695 /*
631 * Sends a Tri-State "1" Bit 696 * Sends a Tri-State "1" Bit
632 * ___ ___ 697 * ___ ___
633 * Waveform: | |_| |_ 698 * Waveform: | |_| |_
634 */ 699 */
635 void sendT1(void) { 700 void sendT1(void) {
636 transmit(3,1); 701 transmit(ONE_FIRST_CYCLES[rcProtocol], ONE_SECOND_CYCLES[rcProtocol], HIGH_FIRST[rcProtocol]);
637 transmit(3,1); 702 transmit(ONE_FIRST_CYCLES[rcProtocol], ONE_SECOND_CYCLES[rcProtocol], HIGH_FIRST[rcProtocol]);
703 // transmit(3,1,true);
704 // transmit(3,1,true);
638 } 705 }
639 706
640 707
641 708
642 /* 709 /*
643 * Sends a Tri-State "F" Bit 710 * Sends a Tri-State "F" Bit
644 * _ ___ 711 * _ ___
645 * Waveform: | |___| |_ 712 * Waveform: | |___| |_
646 */ 713 */
647 void sendTF(void) { 714 void sendTF(void) {
648 transmit(1,3); 715 transmit(ZERO_FIRST_CYCLES[rcProtocol], ZERO_SECOND_CYCLES[rcProtocol], HIGH_FIRST[rcProtocol]);
649 transmit(3,1); 716 transmit(ONE_FIRST_CYCLES[rcProtocol], ONE_SECOND_CYCLES[rcProtocol], HIGH_FIRST[rcProtocol]);
717 // transmit(1,3,true);
718 // transmit(3,1,true);
650 } 719 }
651 720
652 721
653 722
654 /* 723 /*
655 * Sends a "Sync" Bit 724 * Sends a "Sync" Bit
656 * _ 725 * _
657 * Waveform Protocol 1: | |_______________________________ 726 * Waveform Protocol 1: | |_______________________________
658 * _ 727 * _
659 * Waveform Protocol 2: | |__________ 728 * Waveform Protocol 2: | |__________
660 * _ 729 * ____
661 * Waveform Protocol 3: | |_______________________________________________________________________ 730 * Waveform Protocol 3: | |_______________________________________________________________________
731 *
732 * Waveform Protocol D: (none, just pause 80 msecs)
662 */ 733 */
663 void sendSync(void) { 734 void sendSync(void) {
664 735
665 if (rcProtocol == 1){ 736 if (rcProtocol == TYPE_A) {
666 transmit(1,31); 737 transmit(1,31,true);
667 } 738 } else if (rcProtocol == TYPE_B) {
668 else if (rcProtocol == 2) { 739 transmit(1,10,true);
669 transmit(1,10); 740 } else if (rcProtocol == TYPE_C) {
670 } 741 transmit(4,71,true);
671 else if (rcProtocol == 3) { 742 } else if (rcProtocol == TYPE_D) {
672 transmit(1,71); 743 transmit(0,1,false);
744 delayMicroseconds(80000);
673 } 745 }
674 } 746 }
675 747
676 748
677 749
746 818
747 819
748 /* 820 /*
749 * ASK protool 1 821 * ASK protool 1
750 */ 822 */
751 bool receiveProtocol1(unsigned int changeCount) 823 bool receiveProtocol(int prot, unsigned int changeCount)
752 { 824 {
753 unsigned long code = 0; 825 unsigned long code = 0;
754 unsigned long ldelay = timings[0] / 31; 826 unsigned long ldelay = timings[0] / SYNC_FACTOR[prot];
755 unsigned long delayTolerance = ldelay * rcReceiveTolerance * 0.01; 827 unsigned long delayTolerance = ldelay * rcReceiveTolerance * 0.01;
756 int i; 828 int i;
757 829
830 if (prot < TYPE_MINIMUM || prot > TYPE_MAXIMUM) {
831 return false;
832 }
833
758 for (i = 1; i<changeCount ; i=i+2) { 834 for (i = 1; i<changeCount ; i=i+2) {
759 835
760 if (timings[i] > ldelay-delayTolerance && 836 if (timings[i] > ldelay * ZERO_FIRST_CYCLES[prot] - delayTolerance &&
761 timings[i] < ldelay+delayTolerance && 837 timings[i] < ldelay * ZERO_FIRST_CYCLES[prot] + delayTolerance &&
762 timings[i+1] > ldelay*3-delayTolerance && 838 timings[i+1] > ldelay * ZERO_SECOND_CYCLES[prot] - delayTolerance &&
763 timings[i+1] < ldelay*3+delayTolerance) { 839 timings[i+1] < ldelay * ZERO_SECOND_CYCLES[prot] + delayTolerance) {
764 code = code << 1; 840 code = code << 1;
765 } else if (timings[i] > ldelay*3-delayTolerance && 841 } else if (timings[i] > ldelay * ONE_FIRST_CYCLES[prot] - delayTolerance &&
766 timings[i] < ldelay*3+delayTolerance && 842 timings[i] < ldelay * ONE_FIRST_CYCLES[prot] + delayTolerance &&
767 timings[i+1] > ldelay-delayTolerance && 843 timings[i+1] > ldelay * ONE_SECOND_CYCLES[prot] - delayTolerance &&
768 timings[i+1] < ldelay+delayTolerance) { 844 timings[i+1] < ldelay * ONE_SECOND_CYCLES[prot] + delayTolerance) {
769 code+=1; 845 code+=1;
770 code = code << 1; 846 code = code << 1;
771 } else { 847 } else {
772 // Failed 848 // Failed
773 i = changeCount; 849 i = changeCount;
777 code = code >> 1; 853 code = code >> 1;
778 if (changeCount > 6) { // ignore < 4bit values as there are no devices sending 4bit values => noise 854 if (changeCount > 6) { // ignore < 4bit values as there are no devices sending 4bit values => noise
779 rcReceivedValue = code; 855 rcReceivedValue = code;
780 rcReceivedBitlength = changeCount / 2; 856 rcReceivedBitlength = changeCount / 2;
781 rcReceivedDelay = ldelay; 857 rcReceivedDelay = ldelay;
782 rcReceivedProtocol = 1; 858 rcReceivedProtocol = prot;
783 } 859 }
784 860
785 if (code == 0) { 861 return (code != 0);
786 return false;
787 }
788 return true;
789 } 862 }
790 863
791 864
792 865
793 bool receiveProtocol2(unsigned int changeCount) 866 bool receiveProtocol2(unsigned int changeCount)
890 963
891 if (duration > 5000 && duration > timings[0] - 200 && duration < timings[0] + 200) { 964 if (duration > 5000 && duration > timings[0] - 200 && duration < timings[0] + 200) {
892 repeatCount++; 965 repeatCount++;
893 changeCount--; 966 changeCount--;
894 if (repeatCount == 2) { 967 if (repeatCount == 2) {
895 if (receiveProtocol1(changeCount) == false){ 968 if (receiveProtocol(TYPE_A, changeCount) == false){
896 if (receiveProtocol2(changeCount) == false){ 969 if (receiveProtocol(TYPE_B, changeCount) == false){
897 if (receiveProtocol3(changeCount) == false){ 970 if (receiveProtocol(TYPE_C, changeCount) == false){
898 //failed 971 //failed
899 } 972 }
900 } 973 }
901 } 974 }
902 repeatCount = 0; 975 repeatCount = 0;
945 1018
946 return bin; 1019 return bin;
947 } 1020 }
948 1021
949 1022
1023 void saveProtocol(int prot)
1024 {
1025 backupProtocol = rcProtocol;
1026 backupPulseLength = rcPulseLength;
1027 backupRepeatTransmit = rcRepeatTransmit;
1028
1029 setProtocol(prot);
1030 }
1031
1032
1033
1034 void loadProtocol(void)
1035 {
1036 rcProtocol = backupProtocol;
1037 rcPulseLength = backupPulseLength;
1038 rcRepeatTransmit = backupRepeatTransmit;
1039 }
1040
1041
950 #endif 1042 #endif
951 1043

mercurial