Sun, 04 May 2014 17:18:27 +0200
Added 433 MHz transmitter and receiver library and demo programs
20
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | /***************************************************************************** |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | * Copyright (C) 2014 |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
3 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
4 | * Michiel Broek <mbroek at mbse dot eu> |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
5 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
6 | * This file is part of the mbsePi-apps |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
7 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
8 | * Based on the Arduino libary for remote control outlet switches. |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
9 | * Project home: http://code.google.com/p/rc-switch/ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
10 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
11 | * This is free software; you can redistribute it and/or modify it |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
12 | * under the terms of the GNU General Public License as published by the |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
13 | * Free Software Foundation; either version 2, or (at your option) any |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
14 | * later version. |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
15 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
16 | * mbsePi-apps is distributed in the hope that it will be useful, but |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
19 | * General Public License for more details. |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
20 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
21 | * You should have received a copy of the GNU General Public License |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
22 | * along with EC-65K; see the file COPYING. If not, write to the Free |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
23 | * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
24 | *****************************************************************************/ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
25 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
26 | #include "../config.h" |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
27 | #include "mbselib.h" |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
28 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
29 | #ifdef HAVE_WIRINGPI_H |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
30 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
31 | unsigned long rcReceivedValue = 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
32 | unsigned int rcReceivedBitlength = 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
33 | unsigned int rcReceivedDelay = 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
34 | unsigned int rcReceivedProtocol = 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
35 | int rcReceiveTolerance = 60; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
36 | int rcReceiverInterrupt = -1; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
37 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
38 | unsigned int timings[RCSWITCH_MAX_CHANGES]; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
39 | int rcTransmitterPin = -1; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
40 | int rcPulseLength = 350; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
41 | int rcRepeatTransmit = 10; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
42 | int rcProtocol = 1; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
43 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
44 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
45 | char *getCodeWordA(char*, char*, bool); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
46 | char *getCodeWordB(int, int, bool); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
47 | char *getCodeWordC(char, int, int, bool); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
48 | char *getCodeWordD(char, int, bool); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
49 | void sendTriState(char*); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
50 | void transmit(int, int); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
51 | void send0(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
52 | void send1(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
53 | void sendT0(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
54 | void sendT1(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
55 | void sendTF(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
56 | void sendSync(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
57 | bool receiveProtocol1(unsigned int); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
58 | bool receiveProtocol2(unsigned int); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
59 | bool receiveProtocol3(unsigned int); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
60 | void handleInterrupt(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
61 | char *dec2binWzerofill(unsigned long, unsigned int); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
62 | char *dec2binWcharfill(unsigned long, unsigned int, char); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
63 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
64 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
65 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
66 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
67 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
68 | * Sets the protocol to send. |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
69 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
70 | void setProtocol(int nProtocol) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
71 | rcProtocol = nProtocol; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
72 | if (nProtocol == 1){ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
73 | setPulseLength(350); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
74 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
75 | else if (nProtocol == 2) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
76 | setPulseLength(650); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
77 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
78 | else if (nProtocol == 3) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
79 | setPulseLength(100); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
80 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
81 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
82 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
83 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
84 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
85 | /** |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
86 | * Sets the protocol to send with pulse length in microseconds. |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
87 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
88 | /*void RCSwitch::setProtocol(int nProtocol, int nPulseLength) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
89 | this->nProtocol = nProtocol; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
90 | this->setPulseLength(nPulseLength); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
91 | }*/ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
92 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
93 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
94 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
95 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
96 | * Sets pulse length in microseconds |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
97 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
98 | void setPulseLength(int nPulseLength) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
99 | rcPulseLength = nPulseLength; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
100 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
101 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
102 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
103 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
104 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
105 | * Sets Repeat Transmits |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
106 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
107 | void setRepeatTransmit(int nRepeatTransmit) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
108 | rcRepeatTransmit = nRepeatTransmit; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
109 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
110 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
111 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
112 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
113 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
114 | * Set Receiving Tolerance |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
115 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
116 | void setReceiveTolerance(int nPercent) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
117 | rcReceiveTolerance = nPercent; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
118 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
119 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
120 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
121 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
122 | * Enable transmissions |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
123 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
124 | * @param nTransmitterPin Pin to which the sender is connected to |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
125 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
126 | void enableTransmit(int nTransmitterPin) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
127 | rcTransmitterPin = nTransmitterPin; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
128 | pinMode(rcTransmitterPin, OUTPUT); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
129 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
130 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
131 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
132 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
133 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
134 | * Disable transmissions |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
135 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
136 | void disableTransmit(void) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
137 | rcTransmitterPin = -1; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
138 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
139 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
140 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
141 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
142 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
143 | * Switch a remote switch on (Type D REV) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
144 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
145 | * @param sGroup Code of the switch group (A,B,C,D) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
146 | * @param nDevice Number of the switch itself (1..3) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
147 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
148 | /*void RCSwitch::switchOn(char sGroup, int nDevice) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
149 | this->sendTriState( this->getCodeWordD(sGroup, nDevice, true) ); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
150 | }*/ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
151 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
152 | /** |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
153 | * Switch a remote switch off (Type D REV) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
154 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
155 | * @param sGroup Code of the switch group (A,B,C,D) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
156 | * @param nDevice Number of the switch itself (1..3) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
157 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
158 | /*void RCSwitch::switchOff(char sGroup, int nDevice) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
159 | this->sendTriState( this->getCodeWordD(sGroup, nDevice, false) ); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
160 | }*/ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
161 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
162 | /** |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
163 | * Switch a remote switch on (Type C Intertechno) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
164 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
165 | * @param sFamily Familycode (a..f) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
166 | * @param nGroup Number of group (1..4) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
167 | * @param nDevice Number of device (1..4) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
168 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
169 | /*void RCSwitch::switchOn(char sFamily, int nGroup, int nDevice) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
170 | this->sendTriState( this->getCodeWordC(sFamily, nGroup, nDevice, true) ); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
171 | }*/ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
172 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
173 | /** |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
174 | * Switch a remote switch off (Type C Intertechno) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
175 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
176 | * @param sFamily Familycode (a..f) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
177 | * @param nGroup Number of group (1..4) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
178 | * @param nDevice Number of device (1..4) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
179 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
180 | /*void RCSwitch::switchOff(char sFamily, int nGroup, int nDevice) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
181 | this->sendTriState( this->getCodeWordC(sFamily, nGroup, nDevice, false) ); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
182 | }*/ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
183 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
184 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
185 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
186 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
187 | * Switch a remote switch on (Type B with two rotary/sliding switches) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
188 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
189 | * @param nAddressCode Number of the switch group (1..4) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
190 | * @param nChannelCode Number of the switch itself (1..4) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
191 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
192 | void switchOn(int nAddressCode, int nChannelCode) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
193 | sendTriState( getCodeWordB(nAddressCode, nChannelCode, true) ); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
194 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
195 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
196 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
197 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
198 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
199 | * Switch a remote switch off (Type B with two rotary/sliding switches) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
200 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
201 | * @param nAddressCode Number of the switch group (1..4) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
202 | * @param nChannelCode Number of the switch itself (1..4) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
203 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
204 | void switchOff(int nAddressCode, int nChannelCode) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
205 | sendTriState( getCodeWordB(nAddressCode, nChannelCode, false) ); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
206 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
207 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
208 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
209 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
210 | /** |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
211 | * Deprecated, use switchOn(char* sGroup, char* sDevice) instead! |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
212 | * Switch a remote switch on (Type A with 10 pole DIP switches) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
213 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
214 | * @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") |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
215 | * @param nChannelCode Number of the switch itself (1..5) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
216 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
217 | /*void RCSwitch::switchOn(char* sGroup, int nChannel) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
218 | char* code[6] = { (char *)"00000", (char *)"10000", (char *)"01000", (char *)"00100", (char *)"00010", (char *)"00001" }; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
219 | this->switchOn(sGroup, code[nChannel]); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
220 | }*/ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
221 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
222 | /** |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
223 | * Deprecated, use switchOff(char* sGroup, char* sDevice) instead! |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
224 | * Switch a remote switch off (Type A with 10 pole DIP switches) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
225 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
226 | * @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") |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
227 | * @param nChannelCode Number of the switch itself (1..5) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
228 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
229 | /*void RCSwitch::switchOff(char* sGroup, int nChannel) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
230 | char* code[6] = { (char *)"00000", (char *)"10000", (char *)"01000", (char *)"00100", (char *)"00010", (char *)"00001" }; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
231 | this->switchOff(sGroup, code[nChannel]); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
232 | }*/ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
233 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
234 | /** |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
235 | * Switch a remote switch on (Type A with 10 pole DIP switches) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
236 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
237 | * @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") |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
238 | * @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") |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
239 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
240 | /*void RCSwitch::switchOn(char* sGroup, char* sDevice) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
241 | this->sendTriState( this->getCodeWordA(sGroup, sDevice, true) ); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
242 | }*/ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
243 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
244 | /** |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
245 | * Switch a remote switch off (Type A with 10 pole DIP switches) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
246 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
247 | * @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") |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
248 | * @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") |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
249 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
250 | /*void RCSwitch::switchOff(char* sGroup, char* sDevice) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
251 | this->sendTriState( this->getCodeWordA(sGroup, sDevice, false) ); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
252 | }*/ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
253 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
254 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
255 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
256 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
257 | * Returns a char[13], representing the Code Word to be send. |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
258 | * A Code Word consists of 9 address bits, 3 data bits and one sync bit but in our case only the first 8 address bits and the last 2 data bits were used. |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
259 | * A Code Bit can have 4 different states: "F" (floating), "0" (low), "1" (high), "S" (synchronous bit) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
260 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
261 | * +-------------------------------+--------------------------------+-----------------------------------------+-----------------------------------------+----------------------+------------+ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
262 | * | 4 bits address (switch group) | 4 bits address (switch number) | 1 bit address (not used, so never mind) | 1 bit address (not used, so never mind) | 2 data bits (on|off) | 1 sync bit | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
263 | * | 1=0FFF 2=F0FF 3=FF0F 4=FFF0 | 1=0FFF 2=F0FF 3=FF0F 4=FFF0 | F | F | on=FF off=F0 | S | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
264 | * +-------------------------------+--------------------------------+-----------------------------------------+-----------------------------------------+----------------------+------------+ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
265 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
266 | * @param nAddressCode Number of the switch group (1..4) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
267 | * @param nChannelCode Number of the switch itself (1..4) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
268 | * @param bStatus Wether to switch on (true) or off (false) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
269 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
270 | * @return char[13] |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
271 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
272 | char *getCodeWordB(int nAddressCode, int nChannelCode, bool bStatus) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
273 | { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
274 | int i, nReturnPos = 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
275 | static char sReturn[13]; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
276 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
277 | char* code[5] = { (char *)"FFFF", (char *)"0FFF", (char *)"F0FF", (char *)"FF0F", (char *)"FFF0" }; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
278 | if (nAddressCode < 1 || nAddressCode > 4 || nChannelCode < 1 || nChannelCode > 4) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
279 | return '\0'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
280 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
281 | for (i = 0; i<4; i++) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
282 | sReturn[nReturnPos++] = code[nAddressCode][i]; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
283 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
284 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
285 | for (i = 0; i<4; i++) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
286 | sReturn[nReturnPos++] = code[nChannelCode][i]; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
287 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
288 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
289 | sReturn[nReturnPos++] = 'F'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
290 | sReturn[nReturnPos++] = 'F'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
291 | sReturn[nReturnPos++] = 'F'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
292 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
293 | if (bStatus) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
294 | sReturn[nReturnPos++] = 'F'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
295 | } else { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
296 | sReturn[nReturnPos++] = '0'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
297 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
298 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
299 | sReturn[nReturnPos] = '\0'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
300 | return sReturn; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
301 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
302 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
303 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
304 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
305 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
306 | * Returns a char[13], representing the Code Word to be send. |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
307 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
308 | * getCodeWordA(char*, char*) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
309 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
310 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
311 | char *getCodeWordA(char* sGroup, char* sDevice, bool bOn) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
312 | { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
313 | static char sDipSwitches[13]; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
314 | int i = 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
315 | int j = 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
316 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
317 | for (i=0; i < 5; i++) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
318 | if (sGroup[i] == '0') { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
319 | sDipSwitches[j++] = 'F'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
320 | } else { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
321 | sDipSwitches[j++] = '0'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
322 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
323 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
324 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
325 | for (i=0; i < 5; i++) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
326 | if (sDevice[i] == '0') { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
327 | sDipSwitches[j++] = 'F'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
328 | } else { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
329 | sDipSwitches[j++] = '0'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
330 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
331 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
332 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
333 | if ( bOn ) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
334 | sDipSwitches[j++] = '0'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
335 | sDipSwitches[j++] = 'F'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
336 | } else { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
337 | sDipSwitches[j++] = 'F'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
338 | sDipSwitches[j++] = '0'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
339 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
340 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
341 | sDipSwitches[j] = '\0'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
342 | return sDipSwitches; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
343 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
344 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
345 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
346 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
347 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
348 | * Like getCodeWord (Type C = Intertechno) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
349 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
350 | char *getCodeWordC(char sFamily, int nGroup, int nDevice, bool bStatus) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
351 | { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
352 | static char sReturn[13]; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
353 | int i, nReturnPos = 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
354 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
355 | if ( (uint8_t)sFamily < 97 || (uint8_t)sFamily > 112 || nGroup < 1 || nGroup > 4 || nDevice < 1 || nDevice > 4) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
356 | return '\0'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
357 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
358 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
359 | char* sDeviceGroupCode = dec2binWzerofill( (nDevice-1) + (nGroup-1)*4, 4 ); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
360 | char familycode[16][5] = { "0000", "F000", "0F00", "FF00", "00F0", "F0F0", "0FF0", "FFF0", "000F", "F00F", "0F0F", "FF0F", "00FF", "F0FF", "0FFF", "FFFF" }; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
361 | for (i = 0; i<4; i++) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
362 | sReturn[nReturnPos++] = familycode[ (int)sFamily - 97 ][i]; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
363 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
364 | for (i = 0; i<4; i++) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
365 | sReturn[nReturnPos++] = (sDeviceGroupCode[3-i] == '1' ? 'F' : '0'); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
366 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
367 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
368 | sReturn[nReturnPos++] = '0'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
369 | sReturn[nReturnPos++] = 'F'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
370 | sReturn[nReturnPos++] = 'F'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
371 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
372 | if (bStatus) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
373 | sReturn[nReturnPos++] = 'F'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
374 | } else { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
375 | sReturn[nReturnPos++] = '0'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
376 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
377 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
378 | sReturn[nReturnPos] = '\0'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
379 | return sReturn; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
380 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
381 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
382 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
383 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
384 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
385 | * Decoding for the REV Switch Type |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
386 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
387 | * Returns a char[13], representing the Tristate to be send. |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
388 | * A Code Word consists of 7 address bits and 5 command data bits. |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
389 | * A Code Bit can have 3 different states: "F" (floating), "0" (low), "1" (high) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
390 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
391 | * +-------------------------------+--------------------------------+-----------------------+ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
392 | * | 4 bits address (switch group) | 3 bits address (device number) | 5 bits (command data) | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
393 | * | A=1FFF B=F1FF C=FF1F D=FFF1 | 1=0FFF 2=F0FF 3=FF0F 4=FFF0 | on=00010 off=00001 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
394 | * +-------------------------------+--------------------------------+-----------------------+ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
395 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
396 | * Source: http://www.the-intruder.net/funksteckdosen-von-rev-uber-arduino-ansteuern/ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
397 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
398 | * @param sGroup Name of the switch group (A..D, resp. a..d) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
399 | * @param nDevice Number of the switch itself (1..3) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
400 | * @param bStatus Wether to switch on (true) or off (false) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
401 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
402 | * @return char[13] |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
403 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
404 | char *getCodeWordD(char sGroup, int nDevice, bool bStatus){ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
405 | static char sReturn[13]; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
406 | int i, nReturnPos = 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
407 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
408 | // Building 4 bits address |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
409 | // (Potential problem if dec2binWcharfill not returning correct string) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
410 | char *sGroupCode; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
411 | switch(sGroup){ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
412 | case 'a': |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
413 | case 'A': |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
414 | sGroupCode = dec2binWcharfill(8, 4, 'F'); break; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
415 | case 'b': |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
416 | case 'B': |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
417 | sGroupCode = dec2binWcharfill(4, 4, 'F'); break; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
418 | case 'c': |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
419 | case 'C': |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
420 | sGroupCode = dec2binWcharfill(2, 4, 'F'); break; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
421 | case 'd': |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
422 | case 'D': |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
423 | sGroupCode = dec2binWcharfill(1, 4, 'F'); break; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
424 | default: |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
425 | return '\0'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
426 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
427 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
428 | for (i = 0; i<4; i++) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
429 | sReturn[nReturnPos++] = sGroupCode[i]; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
430 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
431 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
432 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
433 | // Building 3 bits address |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
434 | // (Potential problem if dec2binWcharfill not returning correct string) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
435 | char *sDevice; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
436 | switch(nDevice) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
437 | case 1: |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
438 | sDevice = dec2binWcharfill(4, 3, 'F'); break; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
439 | case 2: |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
440 | sDevice = dec2binWcharfill(2, 3, 'F'); break; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
441 | case 3: |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
442 | sDevice = dec2binWcharfill(1, 3, 'F'); break; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
443 | default: |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
444 | return '\0'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
445 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
446 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
447 | for (i = 0; i<3; i++) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
448 | sReturn[nReturnPos++] = sDevice[i]; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
449 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
450 | // fill up rest with zeros |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
451 | for (i = 0; i<5; i++) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
452 | sReturn[nReturnPos++] = '0'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
453 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
454 | // encode on or off |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
455 | if (bStatus) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
456 | sReturn[10] = '1'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
457 | else |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
458 | sReturn[11] = '1'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
459 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
460 | // last position terminate string |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
461 | sReturn[12] = '\0'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
462 | return sReturn; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
463 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
464 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
465 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
466 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
467 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
468 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
469 | * @param sCodeWord /^[10FS]*$/ -> see getCodeWord |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
470 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
471 | void sendTriState(char* sCodeWord) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
472 | int nRepeat; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
473 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
474 | for (nRepeat = 0; nRepeat < rcRepeatTransmit; nRepeat++) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
475 | int i = 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
476 | while (sCodeWord[i] != '\0') { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
477 | switch(sCodeWord[i]) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
478 | case '0': |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
479 | sendT0(); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
480 | break; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
481 | case 'F': |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
482 | sendTF(); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
483 | break; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
484 | case '1': |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
485 | sendT1(); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
486 | break; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
487 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
488 | i++; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
489 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
490 | sendSync(); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
491 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
492 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
493 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
494 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
495 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
496 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
497 | void RCSwitch::send(unsigned long Code, unsigned int length) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
498 | this->send( this->dec2binWzerofill(Code, length) ); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
499 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
500 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
501 | void RCSwitch::send(char* sCodeWord) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
502 | for (int nRepeat=0; nRepeat<nRepeatTransmit; nRepeat++) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
503 | int i = 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
504 | while (sCodeWord[i] != '\0') { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
505 | switch(sCodeWord[i]) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
506 | case '0': |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
507 | this->send0(); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
508 | break; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
509 | case '1': |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
510 | this->send1(); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
511 | break; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
512 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
513 | i++; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
514 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
515 | this->sendSync(); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
516 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
517 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
518 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
519 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
520 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
521 | void transmit(int nHighPulses, int nLowPulses) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
522 | { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
523 | bool disabled_Receive = false; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
524 | int nReceiverInterrupt_backup = rcReceiverInterrupt; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
525 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
526 | if (rcTransmitterPin != -1) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
527 | if (rcReceiverInterrupt != -1) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
528 | disableReceive(); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
529 | disabled_Receive = true; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
530 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
531 | digitalWrite(rcTransmitterPin, HIGH); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
532 | delayMicroseconds( rcPulseLength * nHighPulses); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
533 | digitalWrite(rcTransmitterPin, LOW); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
534 | delayMicroseconds( rcPulseLength * nLowPulses); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
535 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
536 | if (disabled_Receive) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
537 | enableReceiveIRQ(nReceiverInterrupt_backup); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
538 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
539 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
540 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
541 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
542 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
543 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
544 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
545 | * Sends a "0" Bit |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
546 | * _ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
547 | * Waveform Protocol 1: | |___ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
548 | * _ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
549 | * Waveform Protocol 2: | |__ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
550 | * ____ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
551 | * Waveform Protocol 3: | |___________ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
552 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
553 | void send0(void) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
554 | if (rcProtocol == 1){ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
555 | transmit(1,3); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
556 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
557 | else if (rcProtocol == 2) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
558 | transmit(1,2); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
559 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
560 | else if (rcProtocol == 3) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
561 | transmit(4,11); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
562 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
563 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
564 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
565 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
566 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
567 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
568 | * Sends a "1" Bit |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
569 | * ___ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
570 | * Waveform Protocol 1: | |_ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
571 | * __ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
572 | * Waveform Protocol 2: | |_ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
573 | * _________ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
574 | * Waveform Protocol 3: | |______ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
575 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
576 | void send1(void) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
577 | if (rcProtocol == 1){ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
578 | transmit(3,1); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
579 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
580 | else if (rcProtocol == 2) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
581 | transmit(2,1); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
582 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
583 | else if (rcProtocol == 3) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
584 | transmit(9,6); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
585 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
586 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
587 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
588 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
589 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
590 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
591 | * Sends a Tri-State "0" Bit |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
592 | * _ _ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
593 | * Waveform: | |___| |___ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
594 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
595 | void sendT0(void) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
596 | transmit(1,3); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
597 | transmit(1,3); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
598 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
599 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
600 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
601 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
602 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
603 | * Sends a Tri-State "1" Bit |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
604 | * ___ ___ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
605 | * Waveform: | |_| |_ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
606 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
607 | void sendT1(void) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
608 | transmit(3,1); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
609 | transmit(3,1); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
610 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
611 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
612 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
613 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
614 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
615 | * Sends a Tri-State "F" Bit |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
616 | * _ ___ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
617 | * Waveform: | |___| |_ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
618 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
619 | void sendTF(void) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
620 | transmit(1,3); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
621 | transmit(3,1); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
622 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
623 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
624 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
625 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
626 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
627 | * Sends a "Sync" Bit |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
628 | * _ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
629 | * Waveform Protocol 1: | |_______________________________ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
630 | * _ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
631 | * Waveform Protocol 2: | |__________ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
632 | * _ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
633 | * Waveform Protocol 3: | |_______________________________________________________________________ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
634 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
635 | void sendSync(void) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
636 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
637 | if (rcProtocol == 1){ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
638 | transmit(1,31); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
639 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
640 | else if (rcProtocol == 2) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
641 | transmit(1,10); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
642 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
643 | else if (rcProtocol == 3) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
644 | transmit(1,71); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
645 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
646 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
647 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
648 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
649 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
650 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
651 | * Enable receiving data |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
652 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
653 | void enableReceiveIRQ(int interrupt) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
654 | rcReceiverInterrupt = interrupt; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
655 | enableReceive(); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
656 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
657 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
658 | void enableReceive(void) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
659 | if (rcReceiverInterrupt != -1) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
660 | rcReceivedValue = 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
661 | rcReceivedBitlength = 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
662 | wiringPiISR(rcReceiverInterrupt, INT_EDGE_BOTH, &handleInterrupt); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
663 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
664 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
665 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
666 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
667 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
668 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
669 | * Disable receiving data |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
670 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
671 | void disableReceive() { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
672 | // wiringPi disable interrupts ??? |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
673 | rcReceiverInterrupt = -1; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
674 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
675 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
676 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
677 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
678 | bool available(void) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
679 | return rcReceivedValue != 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
680 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
681 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
682 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
683 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
684 | void resetAvailable(void) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
685 | rcReceivedValue = 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
686 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
687 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
688 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
689 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
690 | unsigned long getReceivedValue(void) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
691 | return rcReceivedValue; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
692 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
693 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
694 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
695 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
696 | unsigned int getReceivedBitlength(void) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
697 | return rcReceivedBitlength; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
698 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
699 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
700 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
701 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
702 | unsigned int getReceivedDelay(void) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
703 | return rcReceivedDelay; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
704 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
705 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
706 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
707 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
708 | unsigned int getReceivedProtocol(void) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
709 | return rcReceivedProtocol; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
710 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
711 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
712 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
713 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
714 | unsigned int* getReceivedRawdata(void) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
715 | return timings; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
716 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
717 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
718 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
719 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
720 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
721 | * ASK protool 1 |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
722 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
723 | bool receiveProtocol1(unsigned int changeCount) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
724 | { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
725 | unsigned long code = 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
726 | unsigned long ldelay = timings[0] / 31; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
727 | unsigned long delayTolerance = ldelay * rcReceiveTolerance * 0.01; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
728 | int i; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
729 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
730 | for (i = 1; i<changeCount ; i=i+2) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
731 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
732 | if (timings[i] > ldelay-delayTolerance && |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
733 | timings[i] < ldelay+delayTolerance && |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
734 | timings[i+1] > ldelay*3-delayTolerance && |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
735 | timings[i+1] < ldelay*3+delayTolerance) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
736 | code = code << 1; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
737 | } else if (timings[i] > ldelay*3-delayTolerance && |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
738 | timings[i] < ldelay*3+delayTolerance && |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
739 | timings[i+1] > ldelay-delayTolerance && |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
740 | timings[i+1] < ldelay+delayTolerance) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
741 | code+=1; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
742 | code = code << 1; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
743 | } else { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
744 | // Failed |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
745 | i = changeCount; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
746 | code = 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
747 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
748 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
749 | code = code >> 1; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
750 | if (changeCount > 6) { // ignore < 4bit values as there are no devices sending 4bit values => noise |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
751 | rcReceivedValue = code; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
752 | rcReceivedBitlength = changeCount / 2; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
753 | rcReceivedDelay = ldelay; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
754 | rcReceivedProtocol = 1; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
755 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
756 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
757 | if (code == 0) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
758 | return false; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
759 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
760 | return true; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
761 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
762 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
763 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
764 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
765 | bool receiveProtocol2(unsigned int changeCount) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
766 | { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
767 | unsigned long code = 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
768 | unsigned long ldelay = timings[0] / 10; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
769 | unsigned long delayTolerance = ldelay * rcReceiveTolerance * 0.01; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
770 | int i; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
771 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
772 | for (i = 1; i<changeCount ; i=i+2) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
773 | if (timings[i] > ldelay-delayTolerance && |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
774 | timings[i] < ldelay+delayTolerance && |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
775 | timings[i+1] > ldelay*2-delayTolerance && |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
776 | timings[i+1] < ldelay*2+delayTolerance) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
777 | code = code << 1; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
778 | } else if (timings[i] > ldelay*2-delayTolerance && |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
779 | timings[i] < ldelay*2+delayTolerance && |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
780 | timings[i+1] > ldelay-delayTolerance && |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
781 | timings[i+1] < ldelay+delayTolerance) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
782 | code+=1; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
783 | code = code << 1; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
784 | } else { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
785 | // Failed |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
786 | i = changeCount; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
787 | code = 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
788 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
789 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
790 | code = code >> 1; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
791 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
792 | if (changeCount > 6) { // ignore < 4bit values as there are no devices sending 4bit values => noise |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
793 | rcReceivedValue = code; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
794 | rcReceivedBitlength = changeCount / 2; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
795 | rcReceivedDelay = ldelay; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
796 | rcReceivedProtocol = 2; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
797 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
798 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
799 | if (code == 0) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
800 | return false; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
801 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
802 | return true; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
803 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
804 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
805 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
806 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
807 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
808 | * Protocol 3 is used by BL35P02. |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
809 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
810 | bool receiveProtocol3(unsigned int changeCount) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
811 | { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
812 | unsigned long code = 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
813 | unsigned long ldelay = timings[0] / PROTOCOL3_SYNC_FACTOR; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
814 | unsigned long delayTolerance = ldelay * rcReceiveTolerance * 0.01; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
815 | int i; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
816 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
817 | for (i = 1; i<changeCount ; i=i+2) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
818 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
819 | if (timings[i] > ldelay*PROTOCOL3_0_HIGH_CYCLES - delayTolerance && |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
820 | timings[i] < ldelay*PROTOCOL3_0_HIGH_CYCLES + delayTolerance && |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
821 | timings[i+1] > ldelay*PROTOCOL3_0_LOW_CYCLES - delayTolerance && |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
822 | timings[i+1] < ldelay*PROTOCOL3_0_LOW_CYCLES + delayTolerance) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
823 | code = code << 1; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
824 | } else if (timings[i] > ldelay*PROTOCOL3_1_HIGH_CYCLES - delayTolerance && |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
825 | timings[i] < ldelay*PROTOCOL3_1_HIGH_CYCLES + delayTolerance && |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
826 | timings[i+1] > ldelay*PROTOCOL3_1_LOW_CYCLES - delayTolerance && |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
827 | timings[i+1] < ldelay*PROTOCOL3_1_LOW_CYCLES + delayTolerance) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
828 | code+=1; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
829 | code = code << 1; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
830 | } else { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
831 | // Failed |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
832 | i = changeCount; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
833 | code = 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
834 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
835 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
836 | code = code >> 1; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
837 | if (changeCount > 6) { // ignore < 4bit values as there are no devices sending 4bit values => noise |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
838 | rcReceivedValue = code; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
839 | rcReceivedBitlength = changeCount / 2; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
840 | rcReceivedDelay = ldelay; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
841 | rcReceivedProtocol = 3; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
842 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
843 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
844 | if (code == 0) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
845 | return false; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
846 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
847 | return true; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
848 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
849 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
850 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
851 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
852 | void handleInterrupt() { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
853 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
854 | static unsigned int duration; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
855 | static unsigned int changeCount; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
856 | static unsigned long lastTime; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
857 | static unsigned int repeatCount; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
858 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
859 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
860 | long time = micros(); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
861 | duration = time - lastTime; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
862 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
863 | if (duration > 5000 && duration > timings[0] - 200 && duration < timings[0] + 200) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
864 | repeatCount++; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
865 | changeCount--; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
866 | if (repeatCount == 2) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
867 | if (receiveProtocol1(changeCount) == false){ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
868 | if (receiveProtocol2(changeCount) == false){ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
869 | if (receiveProtocol3(changeCount) == false){ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
870 | //failed |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
871 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
872 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
873 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
874 | repeatCount = 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
875 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
876 | changeCount = 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
877 | } else if (duration > 5000) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
878 | changeCount = 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
879 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
880 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
881 | if (changeCount >= RCSWITCH_MAX_CHANGES) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
882 | changeCount = 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
883 | repeatCount = 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
884 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
885 | timings[changeCount++] = duration; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
886 | lastTime = time; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
887 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
888 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
889 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
890 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
891 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
892 | * Turns a decimal value to its binary representation |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
893 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
894 | char *dec2binWzerofill(unsigned long Dec, unsigned int bitLength) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
895 | { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
896 | return dec2binWcharfill(Dec, bitLength, '0'); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
897 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
898 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
899 | char *dec2binWcharfill(unsigned long Dec, unsigned int bitLength, char fill) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
900 | { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
901 | static char bin[64]; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
902 | unsigned int i = 0, j; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
903 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
904 | while (Dec > 0) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
905 | bin[32+i++] = ((Dec & 1) > 0) ? '1' : fill; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
906 | Dec = Dec >> 1; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
907 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
908 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
909 | for (j = 0; j< bitLength; j++) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
910 | if (j >= bitLength - i) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
911 | bin[j] = bin[ 31 + i - (j - (bitLength - i)) ]; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
912 | } else { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
913 | bin[j] = fill; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
914 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
915 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
916 | bin[bitLength] = '\0'; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
917 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
918 | return bin; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
919 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
920 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
921 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
922 | #endif |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
923 |