2 RCSwitch - Arduino libary for remote control outlet switches
\r
3 Copyright (c) 2011 Suat Özgür. All right reserved.
\r
6 - Andre Koehler / info(at)tomate-online(dot)de
\r
7 - Gordeev Andrey Vladimirovich / gordeev(at)openpyro(dot)com
\r
8 - Dominik Fischer / dom_fischer(at)web(dot)de
\r
10 Project home: http://code.google.com/p/rc-switch/
\r
12 This library is free software; you can redistribute it and/or
\r
13 modify it under the terms of the GNU Lesser General Public
\r
14 License as published by the Free Software Foundation; either
\r
15 version 2.1 of the License, or (at your option) any later version.
\r
17 This library is distributed in the hope that it will be useful,
\r
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
20 Lesser General Public License for more details.
\r
22 You should have received a copy of the GNU Lesser General Public
\r
23 License along with this library; if not, write to the Free Software
\r
24 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\r
29 #if defined(ARDUINO) && ARDUINO >= 100
\r
30 #include "Arduino.h"
\r
32 #include "WProgram.h"
\r
35 // Number of maximum High/Low changes per packet.
\r
36 // We can handle up to (unsigned long) => 32 bit * 2 H/L changes per bit + 2 for sync
\r
37 #define RCSWITCH_MAX_CHANGES 67
\r
45 void switchOn(int nGroupNumber, int nSwitchNumber);
\r
46 void switchOff(int nGroupNumber, int nSwitchNumber);
\r
47 void switchOn(char* sGroup, int nSwitchNumber);
\r
48 void switchOff(char* sGroup, int nSwitchNumber);
\r
49 void switchOn(char sFamily, int nGroup, int nDevice);
\r
50 void switchOff(char sFamily, int nGroup, int nDevice);
\r
51 void switchOn(char* sGroup, char* sDevice);
\r
52 void switchOff(char* sGroup, char* sDevice);
\r
54 void sendTriState(char* Code);
\r
55 void send(unsigned long Code, unsigned int length);
\r
56 void send(char* Code);
\r
58 void enableReceive(int interrupt);
\r
59 void enableReceive();
\r
60 void disableReceive();
\r
62 void resetAvailable();
\r
64 unsigned long getReceivedValue();
\r
65 unsigned int getReceivedBitlength();
\r
66 unsigned int getReceivedDelay();
\r
67 unsigned int getReceivedProtocol();
\r
68 unsigned int* getReceivedRawdata();
\r
70 void enableTransmit(int nTransmitterPin);
\r
71 void disableTransmit();
\r
72 void setPulseLength(int nPulseLength);
\r
73 void setRepeatTransmit(int nRepeatTransmit);
\r
74 void setReceiveTolerance(int nPercent);
\r
75 void setProtocol(int nProtocol);
\r
76 void setProtocol(int nProtocol, int nPulseLength);
\r
79 char* getCodeWordB(int nGroupNumber, int nSwitchNumber, boolean bStatus);
\r
80 char* getCodeWordA(char* sGroup, int nSwitchNumber, boolean bStatus);
\r
81 char* getCodeWordA(char* sGroup, char* sDevice, boolean bStatus);
\r
82 char* getCodeWordC(char sFamily, int nGroup, int nDevice, boolean bStatus);
\r
89 void transmit(int nHighPulses, int nLowPulses);
\r
91 static char* dec2binWzerofill(unsigned long dec, unsigned int length);
\r
93 static void handleInterrupt();
\r
94 static bool receiveProtocol1(unsigned int changeCount);
\r
95 static bool receiveProtocol2(unsigned int changeCount);
\r
96 int nReceiverInterrupt;
\r
97 int nTransmitterPin;
\r
99 int nRepeatTransmit;
\r
102 static int nReceiveTolerance;
\r
103 static unsigned long nReceivedValue;
\r
104 static unsigned int nReceivedBitlength;
\r
105 static unsigned int nReceivedDelay;
\r
106 static unsigned int nReceivedProtocol;
\r
107 static unsigned int timings[RCSWITCH_MAX_CHANGES];
\r