lib/rc-switch.c

Tue, 06 May 2014 21:37:06 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 06 May 2014 21:37:06 +0200
changeset 28
32ed1ea4d0b6
parent 25
5e0695f6add5
child 29
ac763b87ee25
permissions
-rw-r--r--

Coolers working with a hardcode reference

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;
24
873786a20a61 Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
36 int rcReceiverInterruptPin = -1;
20
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
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
44 //const char TYPE_A_CODE[ 6][6] = { "00000", "10000", "01000", "00100", "00010", "00001"};
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
45 const char TYPE_B_CODE[ 5][5] = { "FFFF", "0FFF", "F0FF", "FF0F", "FFF0" };
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
46 const char TYPE_C_CODE[16][5] = { "0000", "F000", "0F00", "FF00", "00F0", "F0F0", "0FF0", "FFF0",
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
47 "000F", "F00F", "0F0F", "FF0F", "00FF", "F0FF", "0FFF", "FFFF" };
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
48 const char TYPE_D_CODE[5][2][9] = { { "11100001", "11110000" }, { "00000000", "00010001" }, { "10000010", "10010011" },
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
49 { "11000011", "11010010" }, { "01000001", "01010000" } };
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
50
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 char *getCodeWordA(char*, char*, bool);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 char *getCodeWordB(int, int, bool);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 char *getCodeWordC(char, int, int, bool);
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
55
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
56 char *getCodeWordE(char, int, bool);
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 void sendTriState(char*);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 void transmit(int, int);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 void send0(void);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 void send1(void);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 void sendT0(void);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 void sendT1(void);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 void sendTF(void);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 void sendSync(void);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 bool receiveProtocol1(unsigned int);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 bool receiveProtocol2(unsigned int);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 bool receiveProtocol3(unsigned int);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 void handleInterrupt(void);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 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
70 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
71
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73
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 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 * Sets the protocol to send.
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 void setProtocol(int nProtocol) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 rcProtocol = nProtocol;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 if (nProtocol == 1){
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 setPulseLength(350);
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 else if (nProtocol == 2) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84 setPulseLength(650);
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 else if (nProtocol == 3) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 setPulseLength(100);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90
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 * 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
95 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96 /*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
97 this->nProtocol = nProtocol;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
98 this->setPulseLength(nPulseLength);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99 }*/
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 * Sets pulse length in microseconds
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
105 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
106 void setPulseLength(int nPulseLength) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107 rcPulseLength = nPulseLength;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108 }
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 * Sets Repeat Transmits
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
115 void setRepeatTransmit(int nRepeatTransmit) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116 rcRepeatTransmit = nRepeatTransmit;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
117 }
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 * Set Receiving Tolerance
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 void setReceiveTolerance(int nPercent) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
125 rcReceiveTolerance = nPercent;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
127
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
128
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 * Enable transmissions
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 * @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
133 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
134 void enableTransmit(int nTransmitterPin) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
135 rcTransmitterPin = nTransmitterPin;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136 pinMode(rcTransmitterPin, OUTPUT);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
137 }
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 * Disable transmissions
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
144 void disableTransmit(void) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
145 rcTransmitterPin = -1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146 }
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
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150 /*
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
151 * Toggle switch, a command looks like B,3,2,1 which means switch type B,
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
152 * group 3, device 2, status on.
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
153 */
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
154 int toggleSwitch(char *command)
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
155 {
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
156 static char *cmd = NULL;
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
157 char *s, cType;
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
158 int rc, iGroup, iDevice, iState;
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
159
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
160 cmd = xstrcpy(command);
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
161 s = strtok(cmd, ",\0");
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
162 cType = s[0];
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
163
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
164 if (cType == 'A') {
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
165
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
166 } else if (cType == 'B') {
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
167 s = strtok(NULL, ",\0");
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
168 rc = sscanf(s, "%d", &iGroup);
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
169 if (rc != 1)
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
170 return 1;
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
171 s = strtok(NULL, ",\0");
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
172 rc = sscanf(s, "%d", &iDevice);
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
173 if (rc != 1)
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
174 return 1;
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
175 s = strtok(NULL, ",\0");
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
176 rc = sscanf(s, "%d", &iState);
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
177 if (rc != 1)
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
178 return 1;
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
179 free(cmd);
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
180 return toggleTypeB(iGroup, iDevice, iState);
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
181 }
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
182
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
183 free(cmd);
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
184 return 1;
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
185 }
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
186
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
187
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
188
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
189 /*
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
190 * Switch a remote switch on (Type E REV)
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
191 *
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
192 * @param sGroup Code of the switch group (A,B,C,D)
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
193 * @param nDevice Number of the switch itself (1..3)
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
194 * @param bStatus Status to toggle to
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
195 */
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
196 int toggleTypeE(char sGroup, int nDevice, bool bStatus) {
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
197 sendTriState( getCodeWordE(sGroup, nDevice, bStatus) );
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
198 return 0;
22
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
199 }
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
200
22
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
201
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
202
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
203 /*
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
204 * 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
205 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
206 * @param sFamily Familycode (a..f)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
207 * @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
208 * @param nDevice Number of device (1..4)
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
209 * @param bStatus Status to toggle to
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
210 */
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
211 int toggleTypeC(char sFamily, int nGroup, int nDevice, bool bStatus) {
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
212 sendTriState( getCodeWordC(sFamily, nGroup, nDevice, bStatus) );
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
213 return 0;
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
214 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
215
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
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
218 /*
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
219 * Switch a remote switch on/off (Type B with two rotary/sliding switches)
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
220 *
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
221 * @param iGroup Number of the switch group (1..4)
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
222 * @param iDevice Number of the switch itself (1..4)
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
223 * @param bStatus Status to toggle to
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
224 */
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
225 int toggleTypeB(int iGroup, int iDevice, bool bStatus)
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
226 {
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
227 char *str = xstrcpy(getCodeWordB(iGroup, iDevice, bStatus));
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
228
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
229 if (strlen(str) == 0)
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
230 return 1;
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
231
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
232 // save(TYPE_B);
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
233 sendTriState( str );
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
234 // load();
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
235 free(str);
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
236 return 0;
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
237 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
238
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
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
241 /*
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
242 * 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
243 *
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
244 * @param sGroup Code of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111")
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
245 * @param sDevice Code of the switch device (refers to DIP switches 6..10 (A..E) where "1" = on and "0" = off, if all DIP switches are on it's "11111")
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
246 * @param bStatus Status to toggle to
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
247 */
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
248 int toggleTypeA(char* sGroup, char* sDevice, bool bStatus) {
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
249 sendTriState( getCodeWordA(sGroup, sDevice, bStatus) );
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
250 return 0;
22
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
251 }
20
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 * 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
257 * 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
258 * 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
259 *
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 * | 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
262 * | 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
263 * +-------------------------------+--------------------------------+-----------------------------------------+-----------------------------------------+----------------------+------------+
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 * @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
266 * @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
267 * @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
268 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
269 * @return char[13]
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
270 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
271 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
272 {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
273 int i, nReturnPos = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
274 static char sReturn[13];
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
275
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
276 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
277 return '\0';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
278 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
279 for (i = 0; i<4; i++) {
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
280 sReturn[nReturnPos++] = TYPE_B_CODE[nAddressCode][i];
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
281 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
282
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
283 for (i = 0; i<4; i++) {
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
284 sReturn[nReturnPos++] = TYPE_B_CODE[nChannelCode][i];
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
285 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
286
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
287 sReturn[nReturnPos++] = 'F';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
288 sReturn[nReturnPos++] = 'F';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
289 sReturn[nReturnPos++] = 'F';
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
290 sReturn[nReturnPos++] = bStatus ? 'F' : '0';
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
291 sReturn[nReturnPos] = '\0';
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
292
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
293 return sReturn;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
294 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
295
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
296
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 * 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
300 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
301 * getCodeWordA(char*, char*)
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 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
305 {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
306 static char sDipSwitches[13];
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
307 int i, j = 0;
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
308
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
309 for (i=0; i < 5; i++) {
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
310 sDipSwitches[j++] = (sGroup[i] == '0') ? 'F' : '0';
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
311 }
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 for (i=0; i < 5; i++) {
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
314 sDipSwitches[j++] = (sDevice[i] == '0') ? 'F' : '0';
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
315 }
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
316
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
317 if ( bOn ) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
318 sDipSwitches[j++] = '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++] = 'F';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
322 sDipSwitches[j++] = '0';
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 sDipSwitches[j] = '\0';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
326 return sDipSwitches;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
327 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
328
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
329
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 * Like getCodeWord (Type C = Intertechno)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
333 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
334 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
335 {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
336 static char sReturn[13];
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
337 int i, nReturnPos = 0;
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
338
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
339 if (sFamily < 'a') {
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
340 // To also enable capital 'A' to 'F'
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
341 sFamily += 32;
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
342 }
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
343
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
344 if ( sFamily < 'a' || sFamily > 'f' || nGroup < 1 || nGroup > 4 || nDevice < 1 || nDevice > 4) {
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
345 return '\0';
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 for (i = 0; i<4; i++) {
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
349 sReturn[nReturnPos++] = TYPE_C_CODE[ sFamily - 'a' ][i];
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
350 }
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
351
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
352 char *sDeviceGroupCode = dec2binWzerofill( (nDevice-1) + (nGroup-1)*4, 4 );
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
353 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
354 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
355 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
356
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
357 sReturn[nReturnPos++] = '0';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
358 sReturn[nReturnPos++] = 'F';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
359 sReturn[nReturnPos++] = 'F';
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
360 sReturn[nReturnPos++] = bStatus ? 'F' : '0';
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
361 sReturn[nReturnPos] = '\0';
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
362
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
363 return sReturn;
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
364 }
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
365
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
366
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
367
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
368 /*
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
369 * Decoding for the Quigg Switch Type
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
370 *
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
371 * Returns a char[22], representing the States to be send.
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
372 * A Code Word consists of 1 start bit, 12 address bits and 8 command data bits.
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
373 * A Code Bit can have 2 different states: "0" (low), "1" (high)
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
374 *
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
375 * +--------------+--------------------------------+------------------------------+
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
376 * | 1 bits start | 12 bits address (device group) | 8 bits (command/switch data) |
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
377 * | 1 | 110011001100 | 00010001 |
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
378 * +--------------+--------------------------------+------------------------------+
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
379 *
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
380 * Source: https://github.com/d-a-n/433-codes/blob/master/database.md#quigg
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
381 *
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
382 * @param sGroup 12-bit Binary ID of the Device Group
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
383 * @param nDevice Number of the switch itself (1..4, or 0 to switch the entire Group)
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
384 * @param bStatus Wether to switch on (true) or off (false)
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
385 *
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
386 * @return char[22]
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
387 */
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
388 char *getCodeWordD(char *sGroup, int nDevice, bool bStatus)
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
389 {
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
390 static char sReturn[22];
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
391 int i, nReturnPos = 0;
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
392
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
393 /* Startbit */
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
394 sReturn[nReturnPos++] = '1';
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
395
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
396 /* 12 bit Group */
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
397 for (i = 0; i < 12; ++i) {
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
398 sReturn[nReturnPos++] = sGroup[i];
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
399 }
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
400
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
401 /* 8 Bit Device Identifier + Status (undividable!) */
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
402 for (i = 0; i < 8; ++i) {
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
403 sReturn[nReturnPos++] = TYPE_D_CODE[nDevice][bStatus][i];
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
404 }
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
405 sReturn[nReturnPos] = 0;
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
406
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
407 return sReturn;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
408 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
409
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
410
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
411
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
412 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
413 * 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
414 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
415 * 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
416 * 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
417 * 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
418 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
419 * +-------------------------------+--------------------------------+-----------------------+
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
420 * | 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
421 * | 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
422 * +-------------------------------+--------------------------------+-----------------------+
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
423 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
424 * 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
425 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
426 * @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
427 * @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
428 * @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
429 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
430 * @return char[13]
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
431 */
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
432 char *getCodeWordE(char sGroup, int nDevice, bool bStatus){
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
433 static char sReturn[13];
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
434 int i, nReturnPos = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
435
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
436 // Building 4 bits address
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
437 // (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
438 char *sGroupCode;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
439 switch(sGroup){
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
440 case 'a':
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
441 case 'A':
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
442 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
443 case 'b':
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
444 case 'B':
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
445 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
446 case 'c':
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
447 case 'C':
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
448 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
449 case 'd':
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
450 case 'D':
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
451 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
452 default:
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
453 return '\0';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
454 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
455
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
456 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
457 sReturn[nReturnPos++] = sGroupCode[i];
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
458 }
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
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
461 // Building 3 bits address
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
462 // (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
463 char *sDevice;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
464 switch(nDevice) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
465 case 1:
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
466 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
467 case 2:
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
468 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
469 case 3:
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
470 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
471 default:
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
472 return '\0';
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
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
475 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
476 sReturn[nReturnPos++] = sDevice[i];
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
477
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
478 // fill up rest with zeros
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
479 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
480 sReturn[nReturnPos++] = '0';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
481
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
482 // encode on or off
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
483 if (bStatus)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
484 sReturn[10] = '1';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
485 else
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
486 sReturn[11] = '1';
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 // last position terminate string
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
489 sReturn[12] = '\0';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
490 return sReturn;
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 * @param sCodeWord /^[10FS]*$/ -> see getCodeWord
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
498 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
499 void sendTriState(char* sCodeWord) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
500 int nRepeat;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
501
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
502 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
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 sendT0();
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 'F':
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
510 sendTF();
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 case '1':
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
513 sendT1();
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
514 break;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
515 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
516 i++;
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 sendSync();
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
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
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
524 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
525 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
526 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
527 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
528
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
529 void RCSwitch::send(char* sCodeWord) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
530 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
531 int i = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
532 while (sCodeWord[i] != '\0') {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
533 switch(sCodeWord[i]) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
534 case '0':
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
535 this->send0();
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
536 break;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
537 case '1':
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
538 this->send1();
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
539 break;
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 i++;
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 this->sendSync();
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 }
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
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 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
550 {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
551 bool disabled_Receive = false;
24
873786a20a61 Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
552 int nReceiverInterrupt_backup = rcReceiverInterruptPin;
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
553
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
554 if (rcTransmitterPin != -1) {
24
873786a20a61 Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
555 if (rcReceiverInterruptPin != -1) {
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
556 disableReceive();
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
557 disabled_Receive = true;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
558 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
559 digitalWrite(rcTransmitterPin, HIGH);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
560 delayMicroseconds( rcPulseLength * nHighPulses);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
561 digitalWrite(rcTransmitterPin, LOW);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
562 delayMicroseconds( rcPulseLength * nLowPulses);
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 if (disabled_Receive) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
565 enableReceiveIRQ(nReceiverInterrupt_backup);
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 }
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
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 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
573 * Sends a "0" Bit
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
574 * _
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
575 * Waveform Protocol 1: | |___
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
576 * _
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
577 * Waveform Protocol 2: | |__
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
578 * ____
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
579 * Waveform Protocol 3: | |___________
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
580 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
581 void send0(void) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
582 if (rcProtocol == 1){
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
583 transmit(1,3);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
584 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
585 else if (rcProtocol == 2) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
586 transmit(1,2);
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 else if (rcProtocol == 3) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
589 transmit(4,11);
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 }
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
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 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
596 * Sends a "1" Bit
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
597 * ___
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
598 * Waveform Protocol 1: | |_
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 * Waveform Protocol 2: | |_
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 * Waveform Protocol 3: | |______
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
603 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
604 void send1(void) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
605 if (rcProtocol == 1){
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
606 transmit(3,1);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
607 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
608 else if (rcProtocol == 2) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
609 transmit(2,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 else if (rcProtocol == 3) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
612 transmit(9,6);
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
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
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 * 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
620 * _ _
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
621 * Waveform: | |___| |___
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 void sendT0(void) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
624 transmit(1,3);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
625 transmit(1,3);
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
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
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 * 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
632 * ___ ___
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
633 * Waveform: | |_| |_
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 sendT1(void) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
636 transmit(3,1);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
637 transmit(3,1);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
638 }
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
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
641
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 * 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
644 * _ ___
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
645 * Waveform: | |___| |_
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 void sendTF(void) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
648 transmit(1,3);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
649 transmit(3,1);
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
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
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
654 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
655 * Sends a "Sync" Bit
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 * Waveform Protocol 1: | |_______________________________
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
658 * _
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
659 * Waveform Protocol 2: | |__________
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
660 * _
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
661 * Waveform Protocol 3: | |_______________________________________________________________________
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
662 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
663 void sendSync(void) {
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 if (rcProtocol == 1){
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
666 transmit(1,31);
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 else if (rcProtocol == 2) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
669 transmit(1,10);
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 else if (rcProtocol == 3) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
672 transmit(1,71);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
673 }
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 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
679 * Enable receiving data
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
680 */
24
873786a20a61 Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
681 void enableReceiveIRQ(int Pin) {
873786a20a61 Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
682 rcReceiverInterruptPin = Pin;
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
683 enableReceive();
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
684 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
685
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
686 void enableReceive(void) {
24
873786a20a61 Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
687 if (rcReceiverInterruptPin != -1) {
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
688 rcReceivedValue = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
689 rcReceivedBitlength = 0;
24
873786a20a61 Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
690 wiringPiISR(rcReceiverInterruptPin, INT_EDGE_BOTH, &handleInterrupt);
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
691 }
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 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
697 * Disable receiving data
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 void disableReceive() {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
700 // wiringPi disable interrupts ???
24
873786a20a61 Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
701 rcReceiverInterruptPin = -1;
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
702 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
703
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 bool available(void) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
707 return rcReceivedValue != 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
708 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
709
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 void resetAvailable(void) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
713 rcReceivedValue = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
714 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
715
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 unsigned long getReceivedValue(void) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
719 return rcReceivedValue;
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
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
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
724 unsigned int getReceivedBitlength(void) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
725 return rcReceivedBitlength;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
726 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
727
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
728
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 unsigned int getReceivedDelay(void) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
731 return rcReceivedDelay;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
732 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
733
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
734
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
735
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
736 unsigned int getReceivedProtocol(void) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
737 return rcReceivedProtocol;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
738 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
739
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
740
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
741
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
742 unsigned int* getReceivedRawdata(void) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
743 return timings;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
744 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
745
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
746
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 * ASK protool 1
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
750 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
751 bool receiveProtocol1(unsigned int changeCount)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
752 {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
753 unsigned long code = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
754 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
755 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
756 int i;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
757
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
758 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
759
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
760 if (timings[i] > ldelay-delayTolerance &&
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
761 timings[i] < ldelay+delayTolerance &&
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
762 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
763 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
764 code = code << 1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
765 } 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
766 timings[i] < ldelay*3+delayTolerance &&
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
767 timings[i+1] > ldelay-delayTolerance &&
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
768 timings[i+1] < ldelay+delayTolerance) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
769 code+=1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
770 code = code << 1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
771 } else {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
772 // Failed
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
773 i = changeCount;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
774 code = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
775 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
776 }
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 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
779 rcReceivedValue = code;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
780 rcReceivedBitlength = changeCount / 2;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
781 rcReceivedDelay = ldelay;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
782 rcReceivedProtocol = 1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
783 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
784
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
785 if (code == 0) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
786 return false;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
787 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
788 return true;
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
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
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
793 bool receiveProtocol2(unsigned int changeCount)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
794 {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
795 unsigned long code = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
796 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
797 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
798 int i;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
799
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
800 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
801 if (timings[i] > ldelay-delayTolerance &&
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
802 timings[i] < ldelay+delayTolerance &&
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
803 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
804 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
805 code = code << 1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
806 } 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
807 timings[i] < ldelay*2+delayTolerance &&
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
808 timings[i+1] > ldelay-delayTolerance &&
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
809 timings[i+1] < ldelay+delayTolerance) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
810 code+=1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
811 code = code << 1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
812 } else {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
813 // Failed
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
814 i = changeCount;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
815 code = 0;
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 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
818 code = code >> 1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
819
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
820 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
821 rcReceivedValue = code;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
822 rcReceivedBitlength = changeCount / 2;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
823 rcReceivedDelay = ldelay;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
824 rcReceivedProtocol = 2;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
825 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
826
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
827 if (code == 0) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
828 return false;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
829 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
830 return true;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
831 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
832
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
833
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 * 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
837 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
838 bool receiveProtocol3(unsigned int changeCount)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
839 {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
840 unsigned long code = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
841 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
842 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
843 int i;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
844
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
845 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
846
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
847 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
848 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
849 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
850 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
851 code = code << 1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
852 } 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
853 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
854 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
855 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
856 code+=1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
857 code = code << 1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
858 } else {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
859 // Failed
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
860 i = changeCount;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
861 code = 0;
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 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
864 code = code >> 1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
865 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
866 rcReceivedValue = code;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
867 rcReceivedBitlength = changeCount / 2;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
868 rcReceivedDelay = ldelay;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
869 rcReceivedProtocol = 3;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
870 }
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 if (code == 0) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
873 return false;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
874 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
875 return true;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
876 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
877
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
878
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 void handleInterrupt() {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
881
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
882 static unsigned int duration;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
883 static unsigned int changeCount;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
884 static unsigned long lastTime;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
885 static unsigned int repeatCount;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
886
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 long time = micros();
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
889 duration = time - lastTime;
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 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
892 repeatCount++;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
893 changeCount--;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
894 if (repeatCount == 2) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
895 if (receiveProtocol1(changeCount) == false){
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
896 if (receiveProtocol2(changeCount) == false){
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
897 if (receiveProtocol3(changeCount) == false){
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
898 //failed
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
899 }
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 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
902 repeatCount = 0;
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 changeCount = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
905 } else if (duration > 5000) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
906 changeCount = 0;
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 if (changeCount >= RCSWITCH_MAX_CHANGES) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
910 changeCount = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
911 repeatCount = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
912 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
913 timings[changeCount++] = duration;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
914 lastTime = time;
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
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
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 * 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
921 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
922 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
923 {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
924 return dec2binWcharfill(Dec, bitLength, '0');
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
925 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
926
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
927 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
928 {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
929 static char bin[64];
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
930 unsigned int i = 0, j;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
931
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
932 while (Dec > 0) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
933 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
934 Dec = Dec >> 1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
935 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
936
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
937 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
938 if (j >= bitLength - i) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
939 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
940 } else {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
941 bin[j] = fill;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
942 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
943 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
944 bin[bitLength] = '\0';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
945
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
946 return bin;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
947 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
948
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
949
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
950 #endif
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
951

mercurial