2 RCSwitch - Arduino libary for remote control outlet switches
3 Copyright (c) 2011 Suat Özgür. All right reserved.
6 - Andre Koehler / info(at)tomate-online(dot)de
7 - Gordeev Andrey Vladimirovich / gordeev(at)openpyro(dot)com
8 - Skineffect / http://forum.ardumote.com/viewtopic.php?f=2&t=46
9 - Dominik Fischer / dom_fischer(at)web(dot)de
10 - Frank Oltmanns / <first name>.<last name>(at)gmail(dot)com
11 - Max Horn / max(at)quendi(dot)de
12 - Robert ter Vehn / <first name>.<last name>(at)gmail(dot)com
13 - Dmitry Shalnov / <last name>(at)interplaymedium(dot)org
15 Project home: https://github.com/sui77/rc-switch/
17 This library is free software; you can redistribute it and/or
18 modify it under the terms of the GNU Lesser General Public
19 License as published by the Free Software Foundation; either
20 version 2.1 of the License, or (at your option) any later version.
22 This library is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 Lesser General Public License for more details.
27 You should have received a copy of the GNU Lesser General Public
28 License along with this library; if not, write to the Free Software
29 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
35 #if defined(ARDUINO) && ARDUINO >= 100
37 #elif defined(ENERGIA) // LaunchPad, FraunchPad and StellarPad specific
39 #elif defined(RPI) // Raspberry Pi
42 // Include libraries for RPi:
43 #include <string.h> /* memcpy */
44 #include <stdlib.h> /* abs */
53 // At least for the ATTiny X4/X5, receiving has to be disabled due to
54 // missing libm depencies (udivmodhi4)
55 #if defined( __AVR_ATtinyX5__ ) or defined ( __AVR_ATtinyX4__ )
56 #define RCSwitchDisableReceiving
59 // Number of maximum High/Low changes per packet.
60 // We can handle up to (unsigned long) => 32 bit * 2 H/L changes per bit + 2 for sync
61 #define RCSWITCH_MAX_CHANGES 67
68 void switchOn(int nGroupNumber, int nSwitchNumber);
69 void switchOff(int nGroupNumber, int nSwitchNumber);
70 void switchOn(const char* sGroup, int nSwitchNumber);
71 void switchOff(const char* sGroup, int nSwitchNumber);
72 void switchOn(char sFamily, int nGroup, int nDevice);
73 void switchOff(char sFamily, int nGroup, int nDevice);
74 void switchOn(const char* sGroup, const char* sDevice);
75 void switchOff(const char* sGroup, const char* sDevice);
76 void switchOn(char sGroup, int nDevice);
77 void switchOff(char sGroup, int nDevice);
79 void sendTriState(const char* sCodeWord);
80 void send(unsigned long code, unsigned int length);
81 void send(const char* sCodeWord);
83 #if not defined( RCSwitchDisableReceiving )
84 void enableReceive(int interrupt);
86 void disableReceive();
88 void resetAvailable();
90 unsigned long getReceivedValue();
91 unsigned int getReceivedBitlength();
92 unsigned int getReceivedDelay();
93 unsigned int getReceivedProtocol();
94 unsigned int* getReceivedRawdata();
97 void enableTransmit(int nTransmitterPin);
98 void disableTransmit();
99 void setPulseLength(int nPulseLength);
100 void setRepeatTransmit(int nRepeatTransmit);
101 #if not defined( RCSwitchDisableReceiving )
102 void setReceiveTolerance(int nPercent);
117 void setProtocol(Protocol protocol);
118 void setProtocol(int nProtocol);
119 void setProtocol(int nProtocol, int nPulseLength);
121 static void handleNoInterrupt( unsigned char PIN );
124 char* getCodeWordA(const char* sGroup, const char* sDevice, bool bStatus);
125 char* getCodeWordB(int nGroupNumber, int nSwitchNumber, bool bStatus);
126 char* getCodeWordC(char sFamily, int nGroup, int nDevice, bool bStatus);
127 char* getCodeWordD(char group, int nDevice, bool bStatus);
128 void transmit(HighLow pulses);
130 #if not defined( RCSwitchDisableReceiving )
131 static void handleInterrupt();
132 static bool receiveProtocol(const int p, unsigned int changeCount);
133 int nReceiverInterrupt;
140 #if not defined( RCSwitchDisableReceiving )
141 static int nReceiveTolerance;
142 static unsigned long nReceivedValue;
143 static unsigned int nReceivedBitlength;
144 static unsigned int nReceivedDelay;
145 static unsigned int nReceivedProtocol;
146 const static unsigned int nSeparationLimit;
148 * timings[0] contains sync timing, followed by a number of bits
150 static unsigned int timings[RCSWITCH_MAX_CHANGES];