http://code.google.com/p/rc-switch/
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 23 Sep 2013 10:10:30 +0000 (12:10 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 23 Sep 2013 10:10:30 +0000 (12:10 +0200)
27 files changed:
libraries/RCSwitch/.svn/entries [new file with mode: 0644]
libraries/RCSwitch/.svn/format [new file with mode: 0644]
libraries/RCSwitch/.svn/pristine/1c/1c50762172d017904d728470fbb6468880bade84.svn-base [new file with mode: 0644]
libraries/RCSwitch/.svn/pristine/24/24b223b281ee9d97c46a6eb5b92fc3c4a260b9f0.svn-base [new file with mode: 0644]
libraries/RCSwitch/.svn/pristine/45/45e3fb0a5fd02ce1715d36d335867a271a141d6b.svn-base [new file with mode: 0644]
libraries/RCSwitch/.svn/pristine/4b/4baac92a9e8fe4a31210c864f750421bbf0dbea8.svn-base [new file with mode: 0644]
libraries/RCSwitch/.svn/pristine/50/503aafee886428ea0c5f0a9e9ed7831481ff2e27.svn-base [new file with mode: 0644]
libraries/RCSwitch/.svn/pristine/52/52bb6be5f9e9fdc8c658c15a9f4010c6d92f820b.svn-base [new file with mode: 0644]
libraries/RCSwitch/.svn/pristine/66/66df6b64da2e53c6da047bf7df391bf8f2fa6fd7.svn-base [new file with mode: 0644]
libraries/RCSwitch/.svn/pristine/75/756bc7eb517eddd36a448c99f3d7732e6e981d22.svn-base [new file with mode: 0644]
libraries/RCSwitch/.svn/pristine/75/75df3171883cc93983f79cd08b94fcb53dcff0e0.svn-base [new file with mode: 0644]
libraries/RCSwitch/.svn/pristine/a4/a4a6ee265abde6f5e1d436cd6358844c8dea39e6.svn-base [new file with mode: 0644]
libraries/RCSwitch/.svn/pristine/ac/acf69a2f35cc168b8898022f94d5d5b59101ed7d.svn-base [new file with mode: 0644]
libraries/RCSwitch/.svn/pristine/ae/aece6aa44d8b1e030c91d82ed836e9d7b07781cb.svn-base [new file with mode: 0644]
libraries/RCSwitch/.svn/wc.db [new file with mode: 0644]
libraries/RCSwitch/RCSwitch.cpp [new file with mode: 0644]
libraries/RCSwitch/RCSwitch.h [new file with mode: 0644]
libraries/RCSwitch/examples/ReceiveDemo_Advanced/ReceiveDemo_Advanced.pde [new file with mode: 0644]
libraries/RCSwitch/examples/ReceiveDemo_Advanced/helperfunctions.ino [new file with mode: 0644]
libraries/RCSwitch/examples/ReceiveDemo_Advanced/output.ino [new file with mode: 0644]
libraries/RCSwitch/examples/ReceiveDemo_Simple/ReceiveDemo_Simple.pde [new file with mode: 0644]
libraries/RCSwitch/examples/SendDemo/SendDemo.pde [new file with mode: 0644]
libraries/RCSwitch/examples/TypeA_WithDIPSwitches/TypeA_WithDIPSwitches.pde [new file with mode: 0644]
libraries/RCSwitch/examples/TypeB_WithRotaryOrSlidingSwitches/TypeB_WithRotaryOrSlidingSwitches.pde [new file with mode: 0644]
libraries/RCSwitch/examples/TypeC_Intertechno/TypeC_Intertechno.pde [new file with mode: 0644]
libraries/RCSwitch/examples/Webserver/Webserver.pde [new file with mode: 0644]
libraries/RCSwitch/keywords.txt [new file with mode: 0644]

diff --git a/libraries/RCSwitch/.svn/entries b/libraries/RCSwitch/.svn/entries
new file mode 100644 (file)
index 0000000..48082f7
--- /dev/null
@@ -0,0 +1 @@
+12
diff --git a/libraries/RCSwitch/.svn/format b/libraries/RCSwitch/.svn/format
new file mode 100644 (file)
index 0000000..48082f7
--- /dev/null
@@ -0,0 +1 @@
+12
diff --git a/libraries/RCSwitch/.svn/pristine/1c/1c50762172d017904d728470fbb6468880bade84.svn-base b/libraries/RCSwitch/.svn/pristine/1c/1c50762172d017904d728470fbb6468880bade84.svn-base
new file mode 100644 (file)
index 0000000..d12db43
--- /dev/null
@@ -0,0 +1,20 @@
+static char * dec2binWzerofill(unsigned long Dec, unsigned int bitLength){
+  static char bin[64]; 
+  unsigned int i=0;
+
+  while (Dec > 0) {
+    bin[32+i++] = (Dec & 1 > 0) ? '1' : '0';
+    Dec = Dec >> 1;
+  }
+
+  for (unsigned int j = 0; j< bitLength; j++) {
+    if (j >= bitLength - i) {
+      bin[j] = bin[ 31 + i - (j - (bitLength - i)) ];
+    }else {
+      bin[j] = '0';
+    }
+  }
+  bin[bitLength] = '\0';
+  
+  return bin;
+}\r
diff --git a/libraries/RCSwitch/.svn/pristine/24/24b223b281ee9d97c46a6eb5b92fc3c4a260b9f0.svn-base b/libraries/RCSwitch/.svn/pristine/24/24b223b281ee9d97c46a6eb5b92fc3c4a260b9f0.svn-base
new file mode 100644 (file)
index 0000000..ee2c74a
--- /dev/null
@@ -0,0 +1,154 @@
+/*
+  A simple RCSwitch/Ethernet/Webserver demo
+  
+  http://code.google.com/p/rc-switch/
+*/
+
+#include <SPI.h>
+#include <Ethernet.h>
+#include <RCSwitch.h>
+
+// Ethernet configuration
+byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC Address
+byte ip[] = { 192,168,0, 2 };                        // IP Address
+EthernetServer server(80);                           // Server Port 80
+
+// RCSwitch configuration
+RCSwitch mySwitch = RCSwitch();
+int RCTransmissionPin = 7;
+
+// More to do...
+// You should also modify the processCommand() and 
+// httpResponseHome() functions to fit your needs.
+
+
+
+/**
+ * Setup
+ */
+void setup() {
+  Ethernet.begin(mac, ip);
+  server.begin();
+  mySwitch.enableTransmit( RCTransmissionPin );
+}
+
+/**
+ * Loop
+ */
+void loop() {
+  char* command = httpServer();
+}
+
+/**
+ * Command dispatcher
+ */
+void processCommand(char* command) {
+  if        (strcmp(command, "1-on") == 0) {
+    mySwitch.switchOn(1,1);
+  } else if (strcmp(command, "1-off") == 0) {
+    mySwitch.switchOff(1,1);
+  } else if (strcmp(command, "2-on") == 0) {
+    mySwitch.switchOn(1,2);
+  } else if (strcmp(command, "2-off") == 0) {
+    mySwitch.switchOff(1,2);
+  }
+}
+
+/**
+ * HTTP Response with homepage
+ */
+void httpResponseHome(EthernetClient c) {
+  c.println("HTTP/1.1 200 OK");
+  c.println("Content-Type: text/html");
+  c.println();
+  c.println("<html>");
+  c.println("<head>");
+  c.println(    "<title>RCSwitch Webserver Demo</title>");
+  c.println(    "<style>");
+  c.println(        "body { font-family: Arial, sans-serif; font-size:12px; }");
+  c.println(    "</style>");
+  c.println("</head>");
+  c.println("<body>");
+  c.println(    "<h1>RCSwitch Webserver Demo</h1>");
+  c.println(    "<ul>");
+  c.println(        "<li><a href=\"./?1-on\">Switch #1 on</a></li>");
+  c.println(        "<li><a href=\"./?1-off\">Switch #1 off</a></li>");
+  c.println(    "</ul>");
+  c.println(    "<ul>");
+  c.println(        "<li><a href=\"./?2-on\">Switch #2 on</a></li>");
+  c.println(        "<li><a href=\"./?2-off\">Switch #2 off</a></li>");
+  c.println(    "</ul>");
+  c.println(    "<hr>");
+  c.println(    "<a href=\"http://code.google.com/p/rc-switch/\">http://code.google.com/p/rc-switch/</a>");
+  c.println("</body>");
+  c.println("</html>");
+}
+
+/**
+ * HTTP Redirect to homepage
+ */
+void httpResponseRedirect(EthernetClient c) {
+  c.println("HTTP/1.1 301 Found");
+  c.println("Location: /");
+  c.println();
+}
+
+/**
+ * HTTP Response 414 error
+ * Command must not be longer than 30 characters
+ **/
+void httpResponse414(EthernetClient c) {
+  c.println("HTTP/1.1 414 Request URI too long");
+  c.println("Content-Type: text/plain");
+  c.println();
+  c.println("414 Request URI too long");
+}
+
+/**
+ * Process HTTP requests, parse first request header line and 
+ * call processCommand with GET query string (everything after
+ * the ? question mark in the URL).
+ */
+char*  httpServer() {
+  EthernetClient client = server.available();
+  if (client) {
+    char sReturnCommand[32];
+    int nCommandPos=-1;
+    sReturnCommand[0] = '\0';
+    while (client.connected()) {
+      if (client.available()) {
+        char c = client.read();
+        if ((c == '\n') || (c == ' ' && nCommandPos>-1)) {
+          sReturnCommand[nCommandPos] = '\0';
+          if (strcmp(sReturnCommand, "\0") == 0) {
+            httpResponseHome(client);
+          } else {
+            processCommand(sReturnCommand);
+            httpResponseRedirect(client);
+          }
+          break;
+        }
+        if (nCommandPos>-1) {
+          sReturnCommand[nCommandPos++] = c;
+        }
+        if (c == '?' && nCommandPos == -1) {
+          nCommandPos = 0;
+        }
+      }
+      if (nCommandPos > 30) {
+        httpResponse414(client);
+        sReturnCommand[0] = '\0';
+        break;
+      }
+    }
+    if (nCommandPos!=-1) {
+      sReturnCommand[nCommandPos] = '\0';
+    }
+    // give the web browser time to receive the data
+    delay(1);
+    client.stop();
+    
+    return sReturnCommand;
+  }
+  return '\0';
+}
\ No newline at end of file
diff --git a/libraries/RCSwitch/.svn/pristine/45/45e3fb0a5fd02ce1715d36d335867a271a141d6b.svn-base b/libraries/RCSwitch/.svn/pristine/45/45e3fb0a5fd02ce1715d36d335867a271a141d6b.svn-base
new file mode 100644 (file)
index 0000000..05596d8
--- /dev/null
@@ -0,0 +1,40 @@
+/*\r
+  Example for Intertechno outlets\r
+  \r
+  http://code.google.com/p/rc-switch/\r
+*/\r
+\r
+#include <RCSwitch.h>\r
+\r
+RCSwitch mySwitch = RCSwitch();\r
+\r
+void setup() {\r
+\r
+  // Transmitter is connected to Arduino Pin #10  \r
+  mySwitch.enableTransmit(10);\r
+  \r
+  // Optional set pulse length.\r
+  // mySwitch.setPulseLength(320);\r
+  \r
+}\r
+\r
+void loop() {\r
+\r
+  // Switch on:\r
+  // The first parameter represents the familycode (a, b, c, ... f)\r
+  // The second parameter represents the group number\r
+  // The third parameter represents the device number\r
+  // \r
+  // In this example it's family 'b', group #3, device #2 \r
+  mySwitch.switchOn('b', 3, 2);\r
+\r
+  // Wait a second\r
+  delay(1000);\r
+  \r
+  // Switch off\r
+  mySwitch.switchOff('b', 3, 2);\r
+  \r
+  // Wait another second\r
+  delay(1000);\r
+  \r
+}
\ No newline at end of file
diff --git a/libraries/RCSwitch/.svn/pristine/4b/4baac92a9e8fe4a31210c864f750421bbf0dbea8.svn-base b/libraries/RCSwitch/.svn/pristine/4b/4baac92a9e8fe4a31210c864f750421bbf0dbea8.svn-base
new file mode 100644 (file)
index 0000000..a345535
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+  Example for receiving
+  
+  http://code.google.com/p/rc-switch/
+  
+  If you want to visualize a telegram copy the raw data and 
+  paste it into http://test.sui.li/oszi/
+*/
+
+#include <RCSwitch.h>
+
+RCSwitch mySwitch = RCSwitch();
+
+void setup() {
+  Serial.begin(9600);
+  mySwitch.enableReceive(0);  // Receiver on inerrupt 0 => that is pin #2
+}
+
+void loop() {
+  if (mySwitch.available()) {
+    output(mySwitch.getReceivedValue(), mySwitch.getReceivedBitlength(), mySwitch.getReceivedDelay(), mySwitch.getReceivedRawdata(),mySwitch.getReceivedProtocol());
+    mySwitch.resetAvailable();
+  }
+}\r
diff --git a/libraries/RCSwitch/.svn/pristine/50/503aafee886428ea0c5f0a9e9ed7831481ff2e27.svn-base b/libraries/RCSwitch/.svn/pristine/50/503aafee886428ea0c5f0a9e9ed7831481ff2e27.svn-base
new file mode 100644 (file)
index 0000000..6cfb9cd
--- /dev/null
@@ -0,0 +1,644 @@
+/*\r
+  RCSwitch - Arduino libary for remote control outlet switches\r
+  Copyright (c) 2011 Suat Özgür.  All right reserved.\r
+  \r
+  Contributors:\r
+  - Andre Koehler / info(at)tomate-online(dot)de\r
+  - Gordeev Andrey Vladimirovich / gordeev(at)openpyro(dot)com\r
+  - Skineffect / http://forum.ardumote.com/viewtopic.php?f=2&t=46\r
+  - Dominik Fischer / dom_fischer(at)web(dot)de\r
+  \r
+  Project home: http://code.google.com/p/rc-switch/\r
+\r
+  This library is free software; you can redistribute it and/or\r
+  modify it under the terms of the GNU Lesser General Public\r
+  License as published by the Free Software Foundation; either\r
+  version 2.1 of the License, or (at your option) any later version.\r
+\r
+  This library is distributed in the hope that it will be useful,\r
+  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+  Lesser General Public License for more details.\r
+\r
+  You should have received a copy of the GNU Lesser General Public\r
+  License along with this library; if not, write to the Free Software\r
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
+*/\r
+\r
+#include "RCSwitch.h"\r
+\r
+unsigned long RCSwitch::nReceivedValue = NULL;\r
+unsigned int RCSwitch::nReceivedBitlength = 0;\r
+unsigned int RCSwitch::nReceivedDelay = 0;\r
+unsigned int RCSwitch::nReceivedProtocol = 0;\r
+unsigned int RCSwitch::timings[RCSWITCH_MAX_CHANGES];\r
+int RCSwitch::nReceiveTolerance = 60;\r
+\r
+RCSwitch::RCSwitch() {\r
+  this->nReceiverInterrupt = -1;\r
+  this->nTransmitterPin = -1;\r
+  RCSwitch::nReceivedValue = NULL;\r
+  this->setPulseLength(350);\r
+  this->setRepeatTransmit(10);\r
+  this->setReceiveTolerance(60);\r
+  this->setProtocol(1);\r
+}\r
+\r
+/**\r
+  * Sets the protocol to send.\r
+  */\r
+void RCSwitch::setProtocol(int nProtocol) {\r
+  this->nProtocol = nProtocol;\r
+  if (nProtocol == 1){\r
+         this->setPulseLength(350);\r
+  }\r
+  else if (nProtocol == 2) {\r
+         this->setPulseLength(650);\r
+  }\r
+}\r
+\r
+/**\r
+  * Sets the protocol to send with pulse length in microseconds.\r
+  */\r
+void RCSwitch::setProtocol(int nProtocol, int nPulseLength) {\r
+  this->nProtocol = nProtocol;\r
+  if (nProtocol == 1){\r
+         this->setPulseLength(nPulseLength);\r
+  }\r
+  else if (nProtocol == 2) {\r
+         this->setPulseLength(nPulseLength);\r
+  }\r
+}\r
+\r
+\r
+/**\r
+  * Sets pulse length in microseconds\r
+  */\r
+void RCSwitch::setPulseLength(int nPulseLength) {\r
+  this->nPulseLength = nPulseLength;\r
+}\r
+\r
+/**\r
+ * Sets Repeat Transmits\r
+ */\r
+void RCSwitch::setRepeatTransmit(int nRepeatTransmit) {\r
+  this->nRepeatTransmit = nRepeatTransmit;\r
+}\r
+\r
+/**\r
+ * Set Receiving Tolerance\r
+ */\r
+void RCSwitch::setReceiveTolerance(int nPercent) {\r
+  RCSwitch::nReceiveTolerance = nPercent;\r
+}\r
+  \r
+\r
+/**\r
+ * Enable transmissions\r
+ *\r
+ * @param nTransmitterPin    Arduino Pin to which the sender is connected to\r
+ */\r
+void RCSwitch::enableTransmit(int nTransmitterPin) {\r
+  this->nTransmitterPin = nTransmitterPin;\r
+  pinMode(this->nTransmitterPin, OUTPUT);\r
+}\r
+\r
+/**\r
+  * Disable transmissions\r
+  */\r
+void RCSwitch::disableTransmit() {\r
+  this->nTransmitterPin = -1;\r
+}\r
+\r
+/**\r
+ * Switch a remote switch on (Type C Intertechno)\r
+ *\r
+ * @param sFamily  Familycode (a..f)\r
+ * @param nGroup   Number of group (1..4)\r
+ * @param nDevice  Number of device (1..4)\r
+  */\r
+void RCSwitch::switchOn(char sFamily, int nGroup, int nDevice) {\r
+  this->sendTriState( this->getCodeWordC(sFamily, nGroup, nDevice, true) );\r
+}\r
+\r
+/**\r
+ * Switch a remote switch off (Type C Intertechno)\r
+ *\r
+ * @param sFamily  Familycode (a..f)\r
+ * @param nGroup   Number of group (1..4)\r
+ * @param nDevice  Number of device (1..4)\r
+ */\r
+void RCSwitch::switchOff(char sFamily, int nGroup, int nDevice) {\r
+  this->sendTriState( this->getCodeWordC(sFamily, nGroup, nDevice, false) );\r
+}\r
+\r
+/**\r
+ * Switch a remote switch on (Type B with two rotary/sliding switches)\r
+ *\r
+ * @param nAddressCode  Number of the switch group (1..4)\r
+ * @param nChannelCode  Number of the switch itself (1..4)\r
+ */\r
+void RCSwitch::switchOn(int nAddressCode, int nChannelCode) {\r
+  this->sendTriState( this->getCodeWordB(nAddressCode, nChannelCode, true) );\r
+}\r
+\r
+/**\r
+ * Switch a remote switch off (Type B with two rotary/sliding switches)\r
+ *\r
+ * @param nAddressCode  Number of the switch group (1..4)\r
+ * @param nChannelCode  Number of the switch itself (1..4)\r
+ */\r
+void RCSwitch::switchOff(int nAddressCode, int nChannelCode) {\r
+  this->sendTriState( this->getCodeWordB(nAddressCode, nChannelCode, false) );\r
+}\r
+\r
+/**\r
+ * Deprecated, use switchOn(char* sGroup, char* sDevice) instead!\r
+ * Switch a remote switch on (Type A with 10 pole DIP switches)\r
+ *\r
+ * @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")\r
+ * @param nChannelCode  Number of the switch itself (1..5)\r
+ */\r
+void RCSwitch::switchOn(char* sGroup, int nChannel) {\r
+  char* code[6] = { "00000", "10000", "01000", "00100", "00010", "00001" };\r
+  this->switchOn(sGroup, code[nChannel]);\r
+}\r
+\r
+/**\r
+ * Deprecated, use switchOff(char* sGroup, char* sDevice) instead!\r
+ * Switch a remote switch off (Type A with 10 pole DIP switches)\r
+ *\r
+ * @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")\r
+ * @param nChannelCode  Number of the switch itself (1..5)\r
+ */\r
+void RCSwitch::switchOff(char* sGroup, int nChannel) {\r
+  char* code[6] = { "00000", "10000", "01000", "00100", "00010", "00001" };\r
+  this->switchOff(sGroup, code[nChannel]);\r
+}\r
+\r
+/**\r
+ * Switch a remote switch on (Type A with 10 pole DIP switches)\r
+ *\r
+ * @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")\r
+ * @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")\r
+ */\r
+void RCSwitch::switchOn(char* sGroup, char* sDevice) {\r
+       this->sendTriState( this->getCodeWordA(sGroup, sDevice, true) );\r
+}\r
+\r
+/**\r
+ * Switch a remote switch off (Type A with 10 pole DIP switches)\r
+ *\r
+ * @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")\r
+ * @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")\r
+ */\r
+void RCSwitch::switchOff(char* sGroup, char* sDevice) {\r
+       this->sendTriState( this->getCodeWordA(sGroup, sDevice, false) );\r
+}\r
+\r
+/**\r
+ * Returns a char[13], representing the Code Word to be send.\r
+ * 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.\r
+ * A Code Bit can have 4 different states: "F" (floating), "0" (low), "1" (high), "S" (synchronous bit)\r
+ *\r
+ * +-------------------------------+--------------------------------+-----------------------------------------+-----------------------------------------+----------------------+------------+\r
+ * | 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 |\r
+ * | 1=0FFF 2=F0FF 3=FF0F 4=FFF0   | 1=0FFF 2=F0FF 3=FF0F 4=FFF0    | F                                       | F                                       | on=FF off=F0         | S          |\r
+ * +-------------------------------+--------------------------------+-----------------------------------------+-----------------------------------------+----------------------+------------+\r
+ *\r
+ * @param nAddressCode  Number of the switch group (1..4)\r
+ * @param nChannelCode  Number of the switch itself (1..4)\r
+ * @param bStatus       Wether to switch on (true) or off (false)\r
+ *\r
+ * @return char[13]\r
+ */\r
+char* RCSwitch::getCodeWordB(int nAddressCode, int nChannelCode, boolean bStatus) {\r
+   int nReturnPos = 0;\r
+   static char sReturn[13];\r
+   \r
+   char* code[5] = { "FFFF", "0FFF", "F0FF", "FF0F", "FFF0" };\r
+   if (nAddressCode < 1 || nAddressCode > 4 || nChannelCode < 1 || nChannelCode > 4) {\r
+    return '\0';\r
+   }\r
+   for (int i = 0; i<4; i++) {\r
+     sReturn[nReturnPos++] = code[nAddressCode][i];\r
+   }\r
+\r
+   for (int i = 0; i<4; i++) {\r
+     sReturn[nReturnPos++] = code[nChannelCode][i];\r
+   }\r
+   \r
+   sReturn[nReturnPos++] = 'F';\r
+   sReturn[nReturnPos++] = 'F';\r
+   sReturn[nReturnPos++] = 'F';\r
+   \r
+   if (bStatus) {\r
+      sReturn[nReturnPos++] = 'F';\r
+   } else {\r
+      sReturn[nReturnPos++] = '0';\r
+   }\r
+   \r
+   sReturn[nReturnPos] = '\0';\r
+   \r
+   return sReturn;\r
+}\r
+\r
+/**\r
+ * Returns a char[13], representing the Code Word to be send.\r
+ *\r
+ * getCodeWordA(char*, char*)\r
+ *\r
+ */\r
+char* RCSwitch::getCodeWordA(char* sGroup, char* sDevice, boolean bOn) {\r
+       static char sDipSwitches[13];\r
+    int i = 0;\r
+       int j = 0;\r
+       \r
+       for (i=0; i < 5; i++) {\r
+               if (sGroup[i] == '0') {\r
+                       sDipSwitches[j++] = 'F';\r
+               } else {\r
+                       sDipSwitches[j++] = '0';\r
+               }\r
+       }\r
+\r
+       for (i=0; i < 5; i++) {\r
+               if (sDevice[i] == '0') {\r
+                       sDipSwitches[j++] = 'F';\r
+               } else {\r
+                       sDipSwitches[j++] = '0';\r
+               }\r
+       }\r
+\r
+       if ( bOn ) {\r
+               sDipSwitches[j++] = '0';\r
+               sDipSwitches[j++] = 'F';\r
+       } else {\r
+               sDipSwitches[j++] = 'F';\r
+               sDipSwitches[j++] = '0';\r
+       }\r
+\r
+       sDipSwitches[j] = '\0';\r
+\r
+       return sDipSwitches;\r
+}\r
+\r
+/**\r
+ * Like getCodeWord (Type C = Intertechno)\r
+ */\r
+char* RCSwitch::getCodeWordC(char sFamily, int nGroup, int nDevice, boolean bStatus) {\r
+  static char sReturn[13];\r
+  int nReturnPos = 0;\r
+  \r
+  if ( (byte)sFamily < 97 || (byte)sFamily > 112 || nGroup < 1 || nGroup > 4 || nDevice < 1 || nDevice > 4) {\r
+    return '\0';\r
+  }\r
+  \r
+  char* sDeviceGroupCode =  dec2binWzerofill(  (nDevice-1) + (nGroup-1)*4, 4  );\r
+  char familycode[16][5] = { "0000", "F000", "0F00", "FF00", "00F0", "F0F0", "0FF0", "FFF0", "000F", "F00F", "0F0F", "FF0F", "00FF", "F0FF", "0FFF", "FFFF" };\r
+  for (int i = 0; i<4; i++) {\r
+    sReturn[nReturnPos++] = familycode[ (int)sFamily - 97 ][i];\r
+  }\r
+  for (int i = 0; i<4; i++) {\r
+    sReturn[nReturnPos++] = (sDeviceGroupCode[3-i] == '1' ? 'F' : '0');\r
+  }\r
+  sReturn[nReturnPos++] = '0';\r
+  sReturn[nReturnPos++] = 'F';\r
+  sReturn[nReturnPos++] = 'F';\r
+  if (bStatus) {\r
+    sReturn[nReturnPos++] = 'F';\r
+  } else {\r
+    sReturn[nReturnPos++] = '0';\r
+  }\r
+  sReturn[nReturnPos] = '\0';\r
+  return sReturn;\r
+}\r
+\r
+/**\r
+ * Sends a Code Word\r
+ * @param sCodeWord   /^[10FS]*$/  -> see getCodeWord\r
+ */\r
+void RCSwitch::sendTriState(char* sCodeWord) {\r
+  for (int nRepeat=0; nRepeat<nRepeatTransmit; nRepeat++) {\r
+    int i = 0;\r
+    while (sCodeWord[i] != '\0') {\r
+      switch(sCodeWord[i]) {\r
+        case '0':\r
+          this->sendT0();\r
+        break;\r
+        case 'F':\r
+          this->sendTF();\r
+        break;\r
+        case '1':\r
+          this->sendT1();\r
+        break;\r
+      }\r
+      i++;\r
+    }\r
+    this->sendSync();    \r
+  }\r
+}\r
+\r
+void RCSwitch::send(unsigned long Code, unsigned int length) {\r
+  this->send( this->dec2binWzerofill(Code, length) );\r
+}\r
+\r
+void RCSwitch::send(char* sCodeWord) {\r
+  for (int nRepeat=0; nRepeat<nRepeatTransmit; nRepeat++) {\r
+    int i = 0;\r
+    while (sCodeWord[i] != '\0') {\r
+      switch(sCodeWord[i]) {\r
+        case '0':\r
+          this->send0();\r
+        break;\r
+        case '1':\r
+          this->send1();\r
+        break;\r
+      }\r
+      i++;\r
+    }\r
+    this->sendSync();\r
+  }\r
+}\r
+\r
+void RCSwitch::transmit(int nHighPulses, int nLowPulses) {\r
+    boolean disabled_Receive = false;\r
+    int nReceiverInterrupt_backup = nReceiverInterrupt;\r
+    if (this->nTransmitterPin != -1) {\r
+        if (this->nReceiverInterrupt != -1) {\r
+            this->disableReceive();\r
+            disabled_Receive = true;\r
+        }\r
+        digitalWrite(this->nTransmitterPin, HIGH);\r
+        delayMicroseconds( this->nPulseLength * nHighPulses);\r
+        digitalWrite(this->nTransmitterPin, LOW);\r
+        delayMicroseconds( this->nPulseLength * nLowPulses);\r
+        if(disabled_Receive){\r
+            this->enableReceive(nReceiverInterrupt_backup);\r
+        }\r
+    }\r
+}\r
+/**\r
+ * Sends a "0" Bit\r
+ *                       _    \r
+ * Waveform Protocol 1: | |___\r
+ *                       _  \r
+ * Waveform Protocol 2: | |__\r
+ */\r
+void RCSwitch::send0() {\r
+       if (this->nProtocol == 1){\r
+               this->transmit(1,3);\r
+       }\r
+       else if (this->nProtocol == 2) {\r
+               this->transmit(1,2);\r
+       }\r
+}\r
+\r
+/**\r
+ * Sends a "1" Bit\r
+ *                       ___  \r
+ * Waveform Protocol 1: |   |_\r
+ *                       __  \r
+ * Waveform Protocol 2: |  |_\r
+ */\r
+void RCSwitch::send1() {\r
+       if (this->nProtocol == 1){\r
+               this->transmit(3,1);\r
+       }\r
+       else if (this->nProtocol == 2) {\r
+               this->transmit(2,1);\r
+       }\r
+}\r
+\r
+\r
+/**\r
+ * Sends a Tri-State "0" Bit\r
+ *            _     _\r
+ * Waveform: | |___| |___\r
+ */\r
+void RCSwitch::sendT0() {\r
+  this->transmit(1,3);\r
+  this->transmit(1,3);\r
+}\r
+\r
+/**\r
+ * Sends a Tri-State "1" Bit\r
+ *            ___   ___\r
+ * Waveform: |   |_|   |_\r
+ */\r
+void RCSwitch::sendT1() {\r
+  this->transmit(3,1);\r
+  this->transmit(3,1);\r
+}\r
+\r
+/**\r
+ * Sends a Tri-State "F" Bit\r
+ *            _     ___\r
+ * Waveform: | |___|   |_\r
+ */\r
+void RCSwitch::sendTF() {\r
+  this->transmit(1,3);\r
+  this->transmit(3,1);\r
+}\r
+\r
+/**\r
+ * Sends a "Sync" Bit\r
+ *                       _\r
+ * Waveform Protocol 1: | |_______________________________\r
+ *                       _\r
+ * Waveform Protocol 2: | |__________\r
+ */\r
+void RCSwitch::sendSync() {\r
+\r
+    if (this->nProtocol == 1){\r
+               this->transmit(1,31);\r
+       }\r
+       else if (this->nProtocol == 2) {\r
+               this->transmit(1,10);\r
+       }\r
+}\r
+\r
+/**\r
+ * Enable receiving data\r
+ */\r
+void RCSwitch::enableReceive(int interrupt) {\r
+  this->nReceiverInterrupt = interrupt;\r
+  this->enableReceive();\r
+}\r
+\r
+void RCSwitch::enableReceive() {\r
+  if (this->nReceiverInterrupt != -1) {\r
+    RCSwitch::nReceivedValue = NULL;\r
+    RCSwitch::nReceivedBitlength = NULL;\r
+    attachInterrupt(this->nReceiverInterrupt, handleInterrupt, CHANGE);\r
+  }\r
+}\r
+\r
+/**\r
+ * Disable receiving data\r
+ */\r
+void RCSwitch::disableReceive() {\r
+  detachInterrupt(this->nReceiverInterrupt);\r
+  this->nReceiverInterrupt = -1;\r
+}\r
+\r
+bool RCSwitch::available() {\r
+  return RCSwitch::nReceivedValue != NULL;\r
+}\r
+\r
+void RCSwitch::resetAvailable() {\r
+  RCSwitch::nReceivedValue = NULL;\r
+}\r
+\r
+unsigned long RCSwitch::getReceivedValue() {\r
+    return RCSwitch::nReceivedValue;\r
+}\r
+\r
+unsigned int RCSwitch::getReceivedBitlength() {\r
+  return RCSwitch::nReceivedBitlength;\r
+}\r
+\r
+unsigned int RCSwitch::getReceivedDelay() {\r
+  return RCSwitch::nReceivedDelay;\r
+}\r
+\r
+unsigned int RCSwitch::getReceivedProtocol() {\r
+  return RCSwitch::nReceivedProtocol;\r
+}\r
+\r
+unsigned int* RCSwitch::getReceivedRawdata() {\r
+    return RCSwitch::timings;\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+bool RCSwitch::receiveProtocol1(unsigned int changeCount){\r
+    \r
+         unsigned long code = 0;\r
+      unsigned long delay = RCSwitch::timings[0] / 31;\r
+      unsigned long delayTolerance = delay * RCSwitch::nReceiveTolerance * 0.01;    \r
+\r
+      for (int i = 1; i<changeCount ; i=i+2) {\r
+      \r
+          if (RCSwitch::timings[i] > delay-delayTolerance && RCSwitch::timings[i] < delay+delayTolerance && RCSwitch::timings[i+1] > delay*3-delayTolerance && RCSwitch::timings[i+1] < delay*3+delayTolerance) {\r
+            code = code << 1;\r
+          } else if (RCSwitch::timings[i] > delay*3-delayTolerance && RCSwitch::timings[i] < delay*3+delayTolerance && RCSwitch::timings[i+1] > delay-delayTolerance && RCSwitch::timings[i+1] < delay+delayTolerance) {\r
+            code+=1;\r
+            code = code << 1;\r
+          } else {\r
+            // Failed\r
+            i = changeCount;\r
+            code = 0;\r
+          }\r
+      }      \r
+      code = code >> 1;\r
+    if (changeCount > 6) {    // ignore < 4bit values as there are no devices sending 4bit values => noise\r
+      RCSwitch::nReceivedValue = code;\r
+      RCSwitch::nReceivedBitlength = changeCount / 2;\r
+      RCSwitch::nReceivedDelay = delay;\r
+         RCSwitch::nReceivedProtocol = 1;\r
+    }\r
+\r
+       if (code == 0){\r
+               return false;\r
+       }else if (code != 0){\r
+               return true;\r
+       }\r
+       \r
+\r
+}\r
+\r
+bool RCSwitch::receiveProtocol2(unsigned int changeCount){\r
+    \r
+         unsigned long code = 0;\r
+      unsigned long delay = RCSwitch::timings[0] / 10;\r
+      unsigned long delayTolerance = delay * RCSwitch::nReceiveTolerance * 0.01;    \r
+\r
+      for (int i = 1; i<changeCount ; i=i+2) {\r
+      \r
+          if (RCSwitch::timings[i] > delay-delayTolerance && RCSwitch::timings[i] < delay+delayTolerance && RCSwitch::timings[i+1] > delay*2-delayTolerance && RCSwitch::timings[i+1] < delay*2+delayTolerance) {\r
+            code = code << 1;\r
+          } else if (RCSwitch::timings[i] > delay*2-delayTolerance && RCSwitch::timings[i] < delay*2+delayTolerance && RCSwitch::timings[i+1] > delay-delayTolerance && RCSwitch::timings[i+1] < delay+delayTolerance) {\r
+            code+=1;\r
+            code = code << 1;\r
+          } else {\r
+            // Failed\r
+            i = changeCount;\r
+            code = 0;\r
+          }\r
+      }      \r
+      code = code >> 1;\r
+    if (changeCount > 6) {    // ignore < 4bit values as there are no devices sending 4bit values => noise\r
+      RCSwitch::nReceivedValue = code;\r
+      RCSwitch::nReceivedBitlength = changeCount / 2;\r
+      RCSwitch::nReceivedDelay = delay;\r
+         RCSwitch::nReceivedProtocol = 2;\r
+    }\r
+\r
+       if (code == 0){\r
+               return false;\r
+       }else if (code != 0){\r
+               return true;\r
+       }\r
+\r
+}\r
+void RCSwitch::handleInterrupt() {\r
+\r
+  static unsigned int duration;\r
+  static unsigned int changeCount;\r
+  static unsigned long lastTime;\r
+  static unsigned int repeatCount;\r
+  \r
+\r
+  long time = micros();\r
+  duration = time - lastTime;\r
\r
+  if (duration > 5000 && duration > RCSwitch::timings[0] - 200 && duration < RCSwitch::timings[0] + 200) {\r
+    repeatCount++;\r
+    changeCount--;\r
+    if (repeatCount == 2) {\r
+               if (receiveProtocol1(changeCount) == false){\r
+                       if (receiveProtocol2(changeCount) == false){\r
+                               //failed\r
+                       }\r
+               }\r
+      repeatCount = 0;\r
+    }\r
+    changeCount = 0;\r
+  } else if (duration > 5000) {\r
+    changeCount = 0;\r
+  }\r
\r
+  if (changeCount >= RCSWITCH_MAX_CHANGES) {\r
+    changeCount = 0;\r
+    repeatCount = 0;\r
+  }\r
+  RCSwitch::timings[changeCount++] = duration;\r
+  lastTime = time;  \r
+}\r
+\r
+/**\r
+  * Turns a decimal value to its binary representation\r
+  */\r
+char* RCSwitch::dec2binWzerofill(unsigned long Dec, unsigned int bitLength){\r
+  static char bin[64];\r
+  unsigned int i=0;\r
+\r
+  while (Dec > 0) {\r
+    bin[32+i++] = ((Dec & 1) > 0) ? '1' : '0';\r
+    Dec = Dec >> 1;\r
+  }\r
+\r
+  for (unsigned int j = 0; j< bitLength; j++) {\r
+    if (j >= bitLength - i) {\r
+      bin[j] = bin[ 31 + i - (j - (bitLength - i)) ];\r
+    }else {\r
+      bin[j] = '0';\r
+    }\r
+  }\r
+  bin[bitLength] = '\0';\r
+  \r
+  return bin;\r
+}\r
+\r
diff --git a/libraries/RCSwitch/.svn/pristine/52/52bb6be5f9e9fdc8c658c15a9f4010c6d92f820b.svn-base b/libraries/RCSwitch/.svn/pristine/52/52bb6be5f9e9fdc8c658c15a9f4010c6d92f820b.svn-base
new file mode 100644 (file)
index 0000000..61e0d76
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+  Example for outlets which are configured with two rotary/sliding switches.
+  
+  http://code.google.com/p/rc-switch/
+*/
+
+#include <RCSwitch.h>
+
+RCSwitch mySwitch = RCSwitch();
+
+void setup() {
+
+  // Transmitter is connected to Arduino Pin #10  
+  mySwitch.enableTransmit(10);
+  
+  // Optional set pulse length.
+  // mySwitch.setPulseLength(320);
+  
+}
+
+void loop() {
+
+  // Switch on:
+  // The first parameter represents the setting of the first rotary switch. 
+  // In this example it's switched to "1" or "A" or "I". 
+  // 
+  // The second parameter represents the setting of the second rotary switch. 
+  // In this example it's switched to "4" or "D" or "IV". 
+  mySwitch.switchOn(1, 4);
+
+  // Wait a second
+  delay(1000);
+  
+  // Switch off
+  mySwitch.switchOff(1, 4);
+  
+  // Wait another second
+  delay(1000);
+  
+}
diff --git a/libraries/RCSwitch/.svn/pristine/66/66df6b64da2e53c6da047bf7df391bf8f2fa6fd7.svn-base b/libraries/RCSwitch/.svn/pristine/66/66df6b64da2e53c6da047bf7df391bf8f2fa6fd7.svn-base
new file mode 100644 (file)
index 0000000..0441276
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+  Example for different sending methods
+  
+  http://code.google.com/p/rc-switch/
+*/
+
+#include <RCSwitch.h>
+
+RCSwitch mySwitch = RCSwitch();
+
+void setup() {
+
+  Serial.begin(9600);
+  
+  // Transmitter is connected to Arduino Pin #10  
+  mySwitch.enableTransmit(10);
+
+  // Optional set pulse length.
+  // mySwitch.setPulseLength(320);
+  
+  // Optional set protocol (default is 1, will work for most outlets)
+  // mySwitch.setProtocol(2);
+  
+  // Optional set number of transmission repetitions.
+  // mySwitch.setRepeatTransmit(15);
+  
+}
+
+void loop() {
+
+  /* See Example: TypeA_WithDIPSwitches */
+  mySwitch.switchOn("11111", "00010")
+  delay(1000);
+  mySwitch.switchOn("11111", "00010")
+  deleay(1000);
+
+  /* Same switch as above, but using decimal code */
+  mySwitch.send(5393, 24);
+  delay(1000);  
+  mySwitch.send(5396, 24);
+  delay(1000);  
+
+  /* Same switch as above, but using binary code */
+  mySwitch.send("000000000001010100010001");
+  delay(1000);  
+  mySwitch.send("000000000001010100010100");
+  delay(1000);
+
+  /* Same switch as above, but tri-state code */ 
+  mySwitch.sendTriState("00000FFF0F0F");
+  delay(1000);  
+  mySwitch.sendTriState("00000FFF0FF0");
+  delay(1000);
+
+  delay(20000);
+}
diff --git a/libraries/RCSwitch/.svn/pristine/75/756bc7eb517eddd36a448c99f3d7732e6e981d22.svn-base b/libraries/RCSwitch/.svn/pristine/75/756bc7eb517eddd36a448c99f3d7732e6e981d22.svn-base
new file mode 100644 (file)
index 0000000..dfa49cc
--- /dev/null
@@ -0,0 +1,52 @@
+void output(unsigned long decimal, unsigned int length, unsigned int delay, unsigned int* raw, unsigned int protocol) {
+
+  if (decimal == 0) {
+    Serial.print("Unknown encoding.");
+  } else {
+    char* b = dec2binWzerofill(decimal, length);
+    Serial.print("Decimal: ");
+    Serial.print(decimal);
+    Serial.print(" (");
+    Serial.print( length );
+    Serial.print("Bit) Binary: ");
+    Serial.print( b );
+    Serial.print(" Tri-State: ");
+    Serial.print( bin2tristate( b) );
+    Serial.print(" PulseLength: ");
+    Serial.print(delay);
+    Serial.print(" microseconds");
+    Serial.print(" Protocol: ");
+    Serial.println(protocol);
+  }
+  
+  Serial.print("Raw data: ");
+  for (int i=0; i<= length*2; i++) {
+    Serial.print(raw[i]);
+    Serial.print(",");
+  }
+  Serial.println();
+  Serial.println();
+}
+
+
+static char* bin2tristate(char* bin) {
+  char returnValue[50];
+  int pos = 0;
+  int pos2 = 0;
+  while (bin[pos]!='\0' && bin[pos+1]!='\0') {
+    if (bin[pos]=='0' && bin[pos+1]=='0') {
+      returnValue[pos2] = '0';
+    } else if (bin[pos]=='1' && bin[pos+1]=='1') {
+      returnValue[pos2] = '1';
+    } else if (bin[pos]=='0' && bin[pos+1]=='1') {
+      returnValue[pos2] = 'F';
+    } else {
+      return "not applicable";
+    }
+    pos = pos+2;
+    pos2++;
+  }
+  returnValue[pos2] = '\0';
+  return returnValue;
+}
+\r
diff --git a/libraries/RCSwitch/.svn/pristine/75/75df3171883cc93983f79cd08b94fcb53dcff0e0.svn-base b/libraries/RCSwitch/.svn/pristine/75/75df3171883cc93983f79cd08b94fcb53dcff0e0.svn-base
new file mode 100644 (file)
index 0000000..ebd5a25
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+  Simple example for receiving
+  
+  http://code.google.com/p/rc-switch/
+*/
+
+#include <RCSwitch.h>
+
+RCSwitch mySwitch = RCSwitch();
+
+void setup() {
+  Serial.begin(9600);
+  mySwitch.enableReceive(0);  // Receiver on inerrupt 0 => that is pin #2
+}
+
+void loop() {
+  if (mySwitch.available()) {
+    
+    int value = mySwitch.getReceivedValue();
+    
+    if (value == 0) {
+      Serial.print("Unknown encoding");
+    } else {
+      Serial.print("Received ");
+      Serial.print( mySwitch.getReceivedValue() );
+      Serial.print(" / ");
+      Serial.print( mySwitch.getReceivedBitlength() );
+      Serial.print("bit ");
+      Serial.print("Protocol: ");
+      Serial.println( mySwitch.getReceivedProtocol() );
+    }
+
+    mySwitch.resetAvailable();
+  }
+}\r
diff --git a/libraries/RCSwitch/.svn/pristine/a4/a4a6ee265abde6f5e1d436cd6358844c8dea39e6.svn-base b/libraries/RCSwitch/.svn/pristine/a4/a4a6ee265abde6f5e1d436cd6358844c8dea39e6.svn-base
new file mode 100644 (file)
index 0000000..48fd797
--- /dev/null
@@ -0,0 +1,57 @@
+#######################################\r
+# Syntax Coloring Map For RCSwitch\r
+#######################################\r
+\r
+#######################################\r
+# Datatypes (KEYWORD1)\r
+#######################################\r
+\r
+RCSwitch       KEYWORD1\r
+\r
+#######################################\r
+# Methods and Functions (KEYWORD2)\r
+#######################################\r
+\r
+##########\r
+#SENDS Begin\r
+##########\r
+switchOn               KEYWORD2\r
+switchOff              KEYWORD2\r
+sendTriState           KEYWORD2\r
+send                   KEYWORD2\r
+##########\r
+#SENDS End\r
+##########\r
+\r
+##########\r
+#RECEIVE Begin\r
+##########\r
+enableReceive          KEYWORD2\r
+disableReceive         KEYWORD2\r
+available              KEYWORD2        \r
+resetAvailable         KEYWORD2\r
+setReceiveTolerance    KEYWORD2\r
+getReceivedValue       KEYWORD2\r
+getReceivedBitlength   KEYWORD2\r
+getReceivedDelay       KEYWORD2\r
+getReceivedProtocol    KEYWORD2\r
+getReceivedRawdata     KEYWORD2\r
+##########\r
+#RECEIVE End\r
+##########\r
+\r
+##########\r
+#OTHERS Begin\r
+##########\r
+enableTransmit         KEYWORD2\r
+disableTransmit                KEYWORD2\r
+setPulseLength         KEYWORD2\r
+setProtocol            KEYWORD2\r
+setRepeatTransmit      KEYWORD2\r
+##########\r
+#OTHERS End\r
+##########\r
+\r
+#######################################\r
+# Constants (LITERAL1)\r
+#######################################\r
diff --git a/libraries/RCSwitch/.svn/pristine/ac/acf69a2f35cc168b8898022f94d5d5b59101ed7d.svn-base b/libraries/RCSwitch/.svn/pristine/ac/acf69a2f35cc168b8898022f94d5d5b59101ed7d.svn-base
new file mode 100644 (file)
index 0000000..c5b7b57
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+  Example for outlets which are configured with a 10 pole DIP switch.
+  
+  http://code.google.com/p/rc-switch/
+*/
+
+#include <RCSwitch.h>
+
+RCSwitch mySwitch = RCSwitch();
+
+void setup() {
+
+  // Transmitter is connected to Arduino Pin #10  
+  mySwitch.enableTransmit(10);
+
+  // Optional set pulse length.
+  // mySwitch.setPulseLength(320);
+  
+}
+
+void loop() {
+
+  // Switch on:
+  // The first parameter represents the setting of the first 5 DIP switches. 
+  // In this example it's ON-ON-OFF-OFF-ON.
+  // 
+  // The second parameter represents the setting of the last 5 DIP switches. 
+  // In this example the last 5 DIP switches are OFF-ON-OFF-ON-OFF.  
+  mySwitch.switchOn("11001", "01010");
+
+  // Wait a second
+  delay(1000);
+  
+  // Switch off
+  mySwitch.switchOff("11001", "01010");
+  
+  // Wait another second
+  delay(1000);
+  
+}\r
diff --git a/libraries/RCSwitch/.svn/pristine/ae/aece6aa44d8b1e030c91d82ed836e9d7b07781cb.svn-base b/libraries/RCSwitch/.svn/pristine/ae/aece6aa44d8b1e030c91d82ed836e9d7b07781cb.svn-base
new file mode 100644 (file)
index 0000000..6105a78
--- /dev/null
@@ -0,0 +1,112 @@
+/*\r
+  RCSwitch - Arduino libary for remote control outlet switches\r
+  Copyright (c) 2011 Suat Özgür.  All right reserved.\r
+\r
+  Contributors:\r
+  - Andre Koehler / info(at)tomate-online(dot)de\r
+  - Gordeev Andrey Vladimirovich / gordeev(at)openpyro(dot)com\r
+  - Dominik Fischer / dom_fischer(at)web(dot)de\r
+  \r
+  Project home: http://code.google.com/p/rc-switch/\r
+\r
+  This library is free software; you can redistribute it and/or\r
+  modify it under the terms of the GNU Lesser General Public\r
+  License as published by the Free Software Foundation; either\r
+  version 2.1 of the License, or (at your option) any later version.\r
+\r
+  This library is distributed in the hope that it will be useful,\r
+  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+  Lesser General Public License for more details.\r
+\r
+  You should have received a copy of the GNU Lesser General Public\r
+  License along with this library; if not, write to the Free Software\r
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
+*/\r
+#ifndef _RCSwitch_h\r
+#define _RCSwitch_h\r
+\r
+#if defined(ARDUINO) && ARDUINO >= 100\r
+    #include "Arduino.h"\r
+#else\r
+    #include "WProgram.h"\r
+#endif\r
+\r
+// Number of maximum High/Low changes per packet.\r
+// We can handle up to (unsigned long) => 32 bit * 2 H/L changes per bit + 2 for sync\r
+#define RCSWITCH_MAX_CHANGES 67\r
+\r
+\r
+class RCSwitch {\r
+\r
+  public:\r
+    RCSwitch();\r
+    \r
+    void switchOn(int nGroupNumber, int nSwitchNumber);\r
+    void switchOff(int nGroupNumber, int nSwitchNumber);\r
+    void switchOn(char* sGroup, int nSwitchNumber);\r
+    void switchOff(char* sGroup, int nSwitchNumber);\r
+    void switchOn(char sFamily, int nGroup, int nDevice);\r
+    void switchOff(char sFamily, int nGroup, int nDevice);\r
+       void switchOn(char* sGroup, char* sDevice);\r
+       void switchOff(char* sGroup, char* sDevice);\r
+\r
+    void sendTriState(char* Code);\r
+    void send(unsigned long Code, unsigned int length);\r
+    void send(char* Code);\r
+    \r
+    void enableReceive(int interrupt);\r
+    void enableReceive();\r
+    void disableReceive();\r
+    bool available();\r
+       void resetAvailable();\r
+       \r
+    unsigned long getReceivedValue();\r
+    unsigned int getReceivedBitlength();\r
+    unsigned int getReceivedDelay();\r
+       unsigned int getReceivedProtocol();\r
+    unsigned int* getReceivedRawdata();\r
+  \r
+    void enableTransmit(int nTransmitterPin);\r
+    void disableTransmit();\r
+    void setPulseLength(int nPulseLength);\r
+    void setRepeatTransmit(int nRepeatTransmit);\r
+    void setReceiveTolerance(int nPercent);\r
+       void setProtocol(int nProtocol);\r
+       void setProtocol(int nProtocol, int nPulseLength);\r
+  \r
+  private:\r
+    char* getCodeWordB(int nGroupNumber, int nSwitchNumber, boolean bStatus);\r
+    char* getCodeWordA(char* sGroup, int nSwitchNumber, boolean bStatus);\r
+    char* getCodeWordA(char* sGroup, char* sDevice, boolean bStatus);\r
+    char* getCodeWordC(char sFamily, int nGroup, int nDevice, boolean bStatus);\r
+    void sendT0();\r
+    void sendT1();\r
+    void sendTF();\r
+    void send0();\r
+    void send1();\r
+    void sendSync();\r
+    void transmit(int nHighPulses, int nLowPulses);\r
+\r
+    static char* dec2binWzerofill(unsigned long dec, unsigned int length);\r
+    \r
+    static void handleInterrupt();\r
+       static bool receiveProtocol1(unsigned int changeCount);\r
+       static bool receiveProtocol2(unsigned int changeCount);\r
+    int nReceiverInterrupt;\r
+    int nTransmitterPin;\r
+    int nPulseLength;\r
+    int nRepeatTransmit;\r
+       char nProtocol;\r
+\r
+       static int nReceiveTolerance;\r
+    static unsigned long nReceivedValue;\r
+    static unsigned int nReceivedBitlength;\r
+       static unsigned int nReceivedDelay;\r
+       static unsigned int nReceivedProtocol;\r
+    static unsigned int timings[RCSWITCH_MAX_CHANGES];\r
+\r
+    \r
+};\r
+\r
+#endif\r
diff --git a/libraries/RCSwitch/.svn/wc.db b/libraries/RCSwitch/.svn/wc.db
new file mode 100644 (file)
index 0000000..6074d06
Binary files /dev/null and b/libraries/RCSwitch/.svn/wc.db differ
diff --git a/libraries/RCSwitch/RCSwitch.cpp b/libraries/RCSwitch/RCSwitch.cpp
new file mode 100644 (file)
index 0000000..6cfb9cd
--- /dev/null
@@ -0,0 +1,644 @@
+/*\r
+  RCSwitch - Arduino libary for remote control outlet switches\r
+  Copyright (c) 2011 Suat Özgür.  All right reserved.\r
+  \r
+  Contributors:\r
+  - Andre Koehler / info(at)tomate-online(dot)de\r
+  - Gordeev Andrey Vladimirovich / gordeev(at)openpyro(dot)com\r
+  - Skineffect / http://forum.ardumote.com/viewtopic.php?f=2&t=46\r
+  - Dominik Fischer / dom_fischer(at)web(dot)de\r
+  \r
+  Project home: http://code.google.com/p/rc-switch/\r
+\r
+  This library is free software; you can redistribute it and/or\r
+  modify it under the terms of the GNU Lesser General Public\r
+  License as published by the Free Software Foundation; either\r
+  version 2.1 of the License, or (at your option) any later version.\r
+\r
+  This library is distributed in the hope that it will be useful,\r
+  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+  Lesser General Public License for more details.\r
+\r
+  You should have received a copy of the GNU Lesser General Public\r
+  License along with this library; if not, write to the Free Software\r
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
+*/\r
+\r
+#include "RCSwitch.h"\r
+\r
+unsigned long RCSwitch::nReceivedValue = NULL;\r
+unsigned int RCSwitch::nReceivedBitlength = 0;\r
+unsigned int RCSwitch::nReceivedDelay = 0;\r
+unsigned int RCSwitch::nReceivedProtocol = 0;\r
+unsigned int RCSwitch::timings[RCSWITCH_MAX_CHANGES];\r
+int RCSwitch::nReceiveTolerance = 60;\r
+\r
+RCSwitch::RCSwitch() {\r
+  this->nReceiverInterrupt = -1;\r
+  this->nTransmitterPin = -1;\r
+  RCSwitch::nReceivedValue = NULL;\r
+  this->setPulseLength(350);\r
+  this->setRepeatTransmit(10);\r
+  this->setReceiveTolerance(60);\r
+  this->setProtocol(1);\r
+}\r
+\r
+/**\r
+  * Sets the protocol to send.\r
+  */\r
+void RCSwitch::setProtocol(int nProtocol) {\r
+  this->nProtocol = nProtocol;\r
+  if (nProtocol == 1){\r
+         this->setPulseLength(350);\r
+  }\r
+  else if (nProtocol == 2) {\r
+         this->setPulseLength(650);\r
+  }\r
+}\r
+\r
+/**\r
+  * Sets the protocol to send with pulse length in microseconds.\r
+  */\r
+void RCSwitch::setProtocol(int nProtocol, int nPulseLength) {\r
+  this->nProtocol = nProtocol;\r
+  if (nProtocol == 1){\r
+         this->setPulseLength(nPulseLength);\r
+  }\r
+  else if (nProtocol == 2) {\r
+         this->setPulseLength(nPulseLength);\r
+  }\r
+}\r
+\r
+\r
+/**\r
+  * Sets pulse length in microseconds\r
+  */\r
+void RCSwitch::setPulseLength(int nPulseLength) {\r
+  this->nPulseLength = nPulseLength;\r
+}\r
+\r
+/**\r
+ * Sets Repeat Transmits\r
+ */\r
+void RCSwitch::setRepeatTransmit(int nRepeatTransmit) {\r
+  this->nRepeatTransmit = nRepeatTransmit;\r
+}\r
+\r
+/**\r
+ * Set Receiving Tolerance\r
+ */\r
+void RCSwitch::setReceiveTolerance(int nPercent) {\r
+  RCSwitch::nReceiveTolerance = nPercent;\r
+}\r
+  \r
+\r
+/**\r
+ * Enable transmissions\r
+ *\r
+ * @param nTransmitterPin    Arduino Pin to which the sender is connected to\r
+ */\r
+void RCSwitch::enableTransmit(int nTransmitterPin) {\r
+  this->nTransmitterPin = nTransmitterPin;\r
+  pinMode(this->nTransmitterPin, OUTPUT);\r
+}\r
+\r
+/**\r
+  * Disable transmissions\r
+  */\r
+void RCSwitch::disableTransmit() {\r
+  this->nTransmitterPin = -1;\r
+}\r
+\r
+/**\r
+ * Switch a remote switch on (Type C Intertechno)\r
+ *\r
+ * @param sFamily  Familycode (a..f)\r
+ * @param nGroup   Number of group (1..4)\r
+ * @param nDevice  Number of device (1..4)\r
+  */\r
+void RCSwitch::switchOn(char sFamily, int nGroup, int nDevice) {\r
+  this->sendTriState( this->getCodeWordC(sFamily, nGroup, nDevice, true) );\r
+}\r
+\r
+/**\r
+ * Switch a remote switch off (Type C Intertechno)\r
+ *\r
+ * @param sFamily  Familycode (a..f)\r
+ * @param nGroup   Number of group (1..4)\r
+ * @param nDevice  Number of device (1..4)\r
+ */\r
+void RCSwitch::switchOff(char sFamily, int nGroup, int nDevice) {\r
+  this->sendTriState( this->getCodeWordC(sFamily, nGroup, nDevice, false) );\r
+}\r
+\r
+/**\r
+ * Switch a remote switch on (Type B with two rotary/sliding switches)\r
+ *\r
+ * @param nAddressCode  Number of the switch group (1..4)\r
+ * @param nChannelCode  Number of the switch itself (1..4)\r
+ */\r
+void RCSwitch::switchOn(int nAddressCode, int nChannelCode) {\r
+  this->sendTriState( this->getCodeWordB(nAddressCode, nChannelCode, true) );\r
+}\r
+\r
+/**\r
+ * Switch a remote switch off (Type B with two rotary/sliding switches)\r
+ *\r
+ * @param nAddressCode  Number of the switch group (1..4)\r
+ * @param nChannelCode  Number of the switch itself (1..4)\r
+ */\r
+void RCSwitch::switchOff(int nAddressCode, int nChannelCode) {\r
+  this->sendTriState( this->getCodeWordB(nAddressCode, nChannelCode, false) );\r
+}\r
+\r
+/**\r
+ * Deprecated, use switchOn(char* sGroup, char* sDevice) instead!\r
+ * Switch a remote switch on (Type A with 10 pole DIP switches)\r
+ *\r
+ * @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")\r
+ * @param nChannelCode  Number of the switch itself (1..5)\r
+ */\r
+void RCSwitch::switchOn(char* sGroup, int nChannel) {\r
+  char* code[6] = { "00000", "10000", "01000", "00100", "00010", "00001" };\r
+  this->switchOn(sGroup, code[nChannel]);\r
+}\r
+\r
+/**\r
+ * Deprecated, use switchOff(char* sGroup, char* sDevice) instead!\r
+ * Switch a remote switch off (Type A with 10 pole DIP switches)\r
+ *\r
+ * @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")\r
+ * @param nChannelCode  Number of the switch itself (1..5)\r
+ */\r
+void RCSwitch::switchOff(char* sGroup, int nChannel) {\r
+  char* code[6] = { "00000", "10000", "01000", "00100", "00010", "00001" };\r
+  this->switchOff(sGroup, code[nChannel]);\r
+}\r
+\r
+/**\r
+ * Switch a remote switch on (Type A with 10 pole DIP switches)\r
+ *\r
+ * @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")\r
+ * @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")\r
+ */\r
+void RCSwitch::switchOn(char* sGroup, char* sDevice) {\r
+       this->sendTriState( this->getCodeWordA(sGroup, sDevice, true) );\r
+}\r
+\r
+/**\r
+ * Switch a remote switch off (Type A with 10 pole DIP switches)\r
+ *\r
+ * @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")\r
+ * @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")\r
+ */\r
+void RCSwitch::switchOff(char* sGroup, char* sDevice) {\r
+       this->sendTriState( this->getCodeWordA(sGroup, sDevice, false) );\r
+}\r
+\r
+/**\r
+ * Returns a char[13], representing the Code Word to be send.\r
+ * 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.\r
+ * A Code Bit can have 4 different states: "F" (floating), "0" (low), "1" (high), "S" (synchronous bit)\r
+ *\r
+ * +-------------------------------+--------------------------------+-----------------------------------------+-----------------------------------------+----------------------+------------+\r
+ * | 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 |\r
+ * | 1=0FFF 2=F0FF 3=FF0F 4=FFF0   | 1=0FFF 2=F0FF 3=FF0F 4=FFF0    | F                                       | F                                       | on=FF off=F0         | S          |\r
+ * +-------------------------------+--------------------------------+-----------------------------------------+-----------------------------------------+----------------------+------------+\r
+ *\r
+ * @param nAddressCode  Number of the switch group (1..4)\r
+ * @param nChannelCode  Number of the switch itself (1..4)\r
+ * @param bStatus       Wether to switch on (true) or off (false)\r
+ *\r
+ * @return char[13]\r
+ */\r
+char* RCSwitch::getCodeWordB(int nAddressCode, int nChannelCode, boolean bStatus) {\r
+   int nReturnPos = 0;\r
+   static char sReturn[13];\r
+   \r
+   char* code[5] = { "FFFF", "0FFF", "F0FF", "FF0F", "FFF0" };\r
+   if (nAddressCode < 1 || nAddressCode > 4 || nChannelCode < 1 || nChannelCode > 4) {\r
+    return '\0';\r
+   }\r
+   for (int i = 0; i<4; i++) {\r
+     sReturn[nReturnPos++] = code[nAddressCode][i];\r
+   }\r
+\r
+   for (int i = 0; i<4; i++) {\r
+     sReturn[nReturnPos++] = code[nChannelCode][i];\r
+   }\r
+   \r
+   sReturn[nReturnPos++] = 'F';\r
+   sReturn[nReturnPos++] = 'F';\r
+   sReturn[nReturnPos++] = 'F';\r
+   \r
+   if (bStatus) {\r
+      sReturn[nReturnPos++] = 'F';\r
+   } else {\r
+      sReturn[nReturnPos++] = '0';\r
+   }\r
+   \r
+   sReturn[nReturnPos] = '\0';\r
+   \r
+   return sReturn;\r
+}\r
+\r
+/**\r
+ * Returns a char[13], representing the Code Word to be send.\r
+ *\r
+ * getCodeWordA(char*, char*)\r
+ *\r
+ */\r
+char* RCSwitch::getCodeWordA(char* sGroup, char* sDevice, boolean bOn) {\r
+       static char sDipSwitches[13];\r
+    int i = 0;\r
+       int j = 0;\r
+       \r
+       for (i=0; i < 5; i++) {\r
+               if (sGroup[i] == '0') {\r
+                       sDipSwitches[j++] = 'F';\r
+               } else {\r
+                       sDipSwitches[j++] = '0';\r
+               }\r
+       }\r
+\r
+       for (i=0; i < 5; i++) {\r
+               if (sDevice[i] == '0') {\r
+                       sDipSwitches[j++] = 'F';\r
+               } else {\r
+                       sDipSwitches[j++] = '0';\r
+               }\r
+       }\r
+\r
+       if ( bOn ) {\r
+               sDipSwitches[j++] = '0';\r
+               sDipSwitches[j++] = 'F';\r
+       } else {\r
+               sDipSwitches[j++] = 'F';\r
+               sDipSwitches[j++] = '0';\r
+       }\r
+\r
+       sDipSwitches[j] = '\0';\r
+\r
+       return sDipSwitches;\r
+}\r
+\r
+/**\r
+ * Like getCodeWord (Type C = Intertechno)\r
+ */\r
+char* RCSwitch::getCodeWordC(char sFamily, int nGroup, int nDevice, boolean bStatus) {\r
+  static char sReturn[13];\r
+  int nReturnPos = 0;\r
+  \r
+  if ( (byte)sFamily < 97 || (byte)sFamily > 112 || nGroup < 1 || nGroup > 4 || nDevice < 1 || nDevice > 4) {\r
+    return '\0';\r
+  }\r
+  \r
+  char* sDeviceGroupCode =  dec2binWzerofill(  (nDevice-1) + (nGroup-1)*4, 4  );\r
+  char familycode[16][5] = { "0000", "F000", "0F00", "FF00", "00F0", "F0F0", "0FF0", "FFF0", "000F", "F00F", "0F0F", "FF0F", "00FF", "F0FF", "0FFF", "FFFF" };\r
+  for (int i = 0; i<4; i++) {\r
+    sReturn[nReturnPos++] = familycode[ (int)sFamily - 97 ][i];\r
+  }\r
+  for (int i = 0; i<4; i++) {\r
+    sReturn[nReturnPos++] = (sDeviceGroupCode[3-i] == '1' ? 'F' : '0');\r
+  }\r
+  sReturn[nReturnPos++] = '0';\r
+  sReturn[nReturnPos++] = 'F';\r
+  sReturn[nReturnPos++] = 'F';\r
+  if (bStatus) {\r
+    sReturn[nReturnPos++] = 'F';\r
+  } else {\r
+    sReturn[nReturnPos++] = '0';\r
+  }\r
+  sReturn[nReturnPos] = '\0';\r
+  return sReturn;\r
+}\r
+\r
+/**\r
+ * Sends a Code Word\r
+ * @param sCodeWord   /^[10FS]*$/  -> see getCodeWord\r
+ */\r
+void RCSwitch::sendTriState(char* sCodeWord) {\r
+  for (int nRepeat=0; nRepeat<nRepeatTransmit; nRepeat++) {\r
+    int i = 0;\r
+    while (sCodeWord[i] != '\0') {\r
+      switch(sCodeWord[i]) {\r
+        case '0':\r
+          this->sendT0();\r
+        break;\r
+        case 'F':\r
+          this->sendTF();\r
+        break;\r
+        case '1':\r
+          this->sendT1();\r
+        break;\r
+      }\r
+      i++;\r
+    }\r
+    this->sendSync();    \r
+  }\r
+}\r
+\r
+void RCSwitch::send(unsigned long Code, unsigned int length) {\r
+  this->send( this->dec2binWzerofill(Code, length) );\r
+}\r
+\r
+void RCSwitch::send(char* sCodeWord) {\r
+  for (int nRepeat=0; nRepeat<nRepeatTransmit; nRepeat++) {\r
+    int i = 0;\r
+    while (sCodeWord[i] != '\0') {\r
+      switch(sCodeWord[i]) {\r
+        case '0':\r
+          this->send0();\r
+        break;\r
+        case '1':\r
+          this->send1();\r
+        break;\r
+      }\r
+      i++;\r
+    }\r
+    this->sendSync();\r
+  }\r
+}\r
+\r
+void RCSwitch::transmit(int nHighPulses, int nLowPulses) {\r
+    boolean disabled_Receive = false;\r
+    int nReceiverInterrupt_backup = nReceiverInterrupt;\r
+    if (this->nTransmitterPin != -1) {\r
+        if (this->nReceiverInterrupt != -1) {\r
+            this->disableReceive();\r
+            disabled_Receive = true;\r
+        }\r
+        digitalWrite(this->nTransmitterPin, HIGH);\r
+        delayMicroseconds( this->nPulseLength * nHighPulses);\r
+        digitalWrite(this->nTransmitterPin, LOW);\r
+        delayMicroseconds( this->nPulseLength * nLowPulses);\r
+        if(disabled_Receive){\r
+            this->enableReceive(nReceiverInterrupt_backup);\r
+        }\r
+    }\r
+}\r
+/**\r
+ * Sends a "0" Bit\r
+ *                       _    \r
+ * Waveform Protocol 1: | |___\r
+ *                       _  \r
+ * Waveform Protocol 2: | |__\r
+ */\r
+void RCSwitch::send0() {\r
+       if (this->nProtocol == 1){\r
+               this->transmit(1,3);\r
+       }\r
+       else if (this->nProtocol == 2) {\r
+               this->transmit(1,2);\r
+       }\r
+}\r
+\r
+/**\r
+ * Sends a "1" Bit\r
+ *                       ___  \r
+ * Waveform Protocol 1: |   |_\r
+ *                       __  \r
+ * Waveform Protocol 2: |  |_\r
+ */\r
+void RCSwitch::send1() {\r
+       if (this->nProtocol == 1){\r
+               this->transmit(3,1);\r
+       }\r
+       else if (this->nProtocol == 2) {\r
+               this->transmit(2,1);\r
+       }\r
+}\r
+\r
+\r
+/**\r
+ * Sends a Tri-State "0" Bit\r
+ *            _     _\r
+ * Waveform: | |___| |___\r
+ */\r
+void RCSwitch::sendT0() {\r
+  this->transmit(1,3);\r
+  this->transmit(1,3);\r
+}\r
+\r
+/**\r
+ * Sends a Tri-State "1" Bit\r
+ *            ___   ___\r
+ * Waveform: |   |_|   |_\r
+ */\r
+void RCSwitch::sendT1() {\r
+  this->transmit(3,1);\r
+  this->transmit(3,1);\r
+}\r
+\r
+/**\r
+ * Sends a Tri-State "F" Bit\r
+ *            _     ___\r
+ * Waveform: | |___|   |_\r
+ */\r
+void RCSwitch::sendTF() {\r
+  this->transmit(1,3);\r
+  this->transmit(3,1);\r
+}\r
+\r
+/**\r
+ * Sends a "Sync" Bit\r
+ *                       _\r
+ * Waveform Protocol 1: | |_______________________________\r
+ *                       _\r
+ * Waveform Protocol 2: | |__________\r
+ */\r
+void RCSwitch::sendSync() {\r
+\r
+    if (this->nProtocol == 1){\r
+               this->transmit(1,31);\r
+       }\r
+       else if (this->nProtocol == 2) {\r
+               this->transmit(1,10);\r
+       }\r
+}\r
+\r
+/**\r
+ * Enable receiving data\r
+ */\r
+void RCSwitch::enableReceive(int interrupt) {\r
+  this->nReceiverInterrupt = interrupt;\r
+  this->enableReceive();\r
+}\r
+\r
+void RCSwitch::enableReceive() {\r
+  if (this->nReceiverInterrupt != -1) {\r
+    RCSwitch::nReceivedValue = NULL;\r
+    RCSwitch::nReceivedBitlength = NULL;\r
+    attachInterrupt(this->nReceiverInterrupt, handleInterrupt, CHANGE);\r
+  }\r
+}\r
+\r
+/**\r
+ * Disable receiving data\r
+ */\r
+void RCSwitch::disableReceive() {\r
+  detachInterrupt(this->nReceiverInterrupt);\r
+  this->nReceiverInterrupt = -1;\r
+}\r
+\r
+bool RCSwitch::available() {\r
+  return RCSwitch::nReceivedValue != NULL;\r
+}\r
+\r
+void RCSwitch::resetAvailable() {\r
+  RCSwitch::nReceivedValue = NULL;\r
+}\r
+\r
+unsigned long RCSwitch::getReceivedValue() {\r
+    return RCSwitch::nReceivedValue;\r
+}\r
+\r
+unsigned int RCSwitch::getReceivedBitlength() {\r
+  return RCSwitch::nReceivedBitlength;\r
+}\r
+\r
+unsigned int RCSwitch::getReceivedDelay() {\r
+  return RCSwitch::nReceivedDelay;\r
+}\r
+\r
+unsigned int RCSwitch::getReceivedProtocol() {\r
+  return RCSwitch::nReceivedProtocol;\r
+}\r
+\r
+unsigned int* RCSwitch::getReceivedRawdata() {\r
+    return RCSwitch::timings;\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+bool RCSwitch::receiveProtocol1(unsigned int changeCount){\r
+    \r
+         unsigned long code = 0;\r
+      unsigned long delay = RCSwitch::timings[0] / 31;\r
+      unsigned long delayTolerance = delay * RCSwitch::nReceiveTolerance * 0.01;    \r
+\r
+      for (int i = 1; i<changeCount ; i=i+2) {\r
+      \r
+          if (RCSwitch::timings[i] > delay-delayTolerance && RCSwitch::timings[i] < delay+delayTolerance && RCSwitch::timings[i+1] > delay*3-delayTolerance && RCSwitch::timings[i+1] < delay*3+delayTolerance) {\r
+            code = code << 1;\r
+          } else if (RCSwitch::timings[i] > delay*3-delayTolerance && RCSwitch::timings[i] < delay*3+delayTolerance && RCSwitch::timings[i+1] > delay-delayTolerance && RCSwitch::timings[i+1] < delay+delayTolerance) {\r
+            code+=1;\r
+            code = code << 1;\r
+          } else {\r
+            // Failed\r
+            i = changeCount;\r
+            code = 0;\r
+          }\r
+      }      \r
+      code = code >> 1;\r
+    if (changeCount > 6) {    // ignore < 4bit values as there are no devices sending 4bit values => noise\r
+      RCSwitch::nReceivedValue = code;\r
+      RCSwitch::nReceivedBitlength = changeCount / 2;\r
+      RCSwitch::nReceivedDelay = delay;\r
+         RCSwitch::nReceivedProtocol = 1;\r
+    }\r
+\r
+       if (code == 0){\r
+               return false;\r
+       }else if (code != 0){\r
+               return true;\r
+       }\r
+       \r
+\r
+}\r
+\r
+bool RCSwitch::receiveProtocol2(unsigned int changeCount){\r
+    \r
+         unsigned long code = 0;\r
+      unsigned long delay = RCSwitch::timings[0] / 10;\r
+      unsigned long delayTolerance = delay * RCSwitch::nReceiveTolerance * 0.01;    \r
+\r
+      for (int i = 1; i<changeCount ; i=i+2) {\r
+      \r
+          if (RCSwitch::timings[i] > delay-delayTolerance && RCSwitch::timings[i] < delay+delayTolerance && RCSwitch::timings[i+1] > delay*2-delayTolerance && RCSwitch::timings[i+1] < delay*2+delayTolerance) {\r
+            code = code << 1;\r
+          } else if (RCSwitch::timings[i] > delay*2-delayTolerance && RCSwitch::timings[i] < delay*2+delayTolerance && RCSwitch::timings[i+1] > delay-delayTolerance && RCSwitch::timings[i+1] < delay+delayTolerance) {\r
+            code+=1;\r
+            code = code << 1;\r
+          } else {\r
+            // Failed\r
+            i = changeCount;\r
+            code = 0;\r
+          }\r
+      }      \r
+      code = code >> 1;\r
+    if (changeCount > 6) {    // ignore < 4bit values as there are no devices sending 4bit values => noise\r
+      RCSwitch::nReceivedValue = code;\r
+      RCSwitch::nReceivedBitlength = changeCount / 2;\r
+      RCSwitch::nReceivedDelay = delay;\r
+         RCSwitch::nReceivedProtocol = 2;\r
+    }\r
+\r
+       if (code == 0){\r
+               return false;\r
+       }else if (code != 0){\r
+               return true;\r
+       }\r
+\r
+}\r
+void RCSwitch::handleInterrupt() {\r
+\r
+  static unsigned int duration;\r
+  static unsigned int changeCount;\r
+  static unsigned long lastTime;\r
+  static unsigned int repeatCount;\r
+  \r
+\r
+  long time = micros();\r
+  duration = time - lastTime;\r
\r
+  if (duration > 5000 && duration > RCSwitch::timings[0] - 200 && duration < RCSwitch::timings[0] + 200) {\r
+    repeatCount++;\r
+    changeCount--;\r
+    if (repeatCount == 2) {\r
+               if (receiveProtocol1(changeCount) == false){\r
+                       if (receiveProtocol2(changeCount) == false){\r
+                               //failed\r
+                       }\r
+               }\r
+      repeatCount = 0;\r
+    }\r
+    changeCount = 0;\r
+  } else if (duration > 5000) {\r
+    changeCount = 0;\r
+  }\r
\r
+  if (changeCount >= RCSWITCH_MAX_CHANGES) {\r
+    changeCount = 0;\r
+    repeatCount = 0;\r
+  }\r
+  RCSwitch::timings[changeCount++] = duration;\r
+  lastTime = time;  \r
+}\r
+\r
+/**\r
+  * Turns a decimal value to its binary representation\r
+  */\r
+char* RCSwitch::dec2binWzerofill(unsigned long Dec, unsigned int bitLength){\r
+  static char bin[64];\r
+  unsigned int i=0;\r
+\r
+  while (Dec > 0) {\r
+    bin[32+i++] = ((Dec & 1) > 0) ? '1' : '0';\r
+    Dec = Dec >> 1;\r
+  }\r
+\r
+  for (unsigned int j = 0; j< bitLength; j++) {\r
+    if (j >= bitLength - i) {\r
+      bin[j] = bin[ 31 + i - (j - (bitLength - i)) ];\r
+    }else {\r
+      bin[j] = '0';\r
+    }\r
+  }\r
+  bin[bitLength] = '\0';\r
+  \r
+  return bin;\r
+}\r
+\r
diff --git a/libraries/RCSwitch/RCSwitch.h b/libraries/RCSwitch/RCSwitch.h
new file mode 100644 (file)
index 0000000..6105a78
--- /dev/null
@@ -0,0 +1,112 @@
+/*\r
+  RCSwitch - Arduino libary for remote control outlet switches\r
+  Copyright (c) 2011 Suat Özgür.  All right reserved.\r
+\r
+  Contributors:\r
+  - Andre Koehler / info(at)tomate-online(dot)de\r
+  - Gordeev Andrey Vladimirovich / gordeev(at)openpyro(dot)com\r
+  - Dominik Fischer / dom_fischer(at)web(dot)de\r
+  \r
+  Project home: http://code.google.com/p/rc-switch/\r
+\r
+  This library is free software; you can redistribute it and/or\r
+  modify it under the terms of the GNU Lesser General Public\r
+  License as published by the Free Software Foundation; either\r
+  version 2.1 of the License, or (at your option) any later version.\r
+\r
+  This library is distributed in the hope that it will be useful,\r
+  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+  Lesser General Public License for more details.\r
+\r
+  You should have received a copy of the GNU Lesser General Public\r
+  License along with this library; if not, write to the Free Software\r
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
+*/\r
+#ifndef _RCSwitch_h\r
+#define _RCSwitch_h\r
+\r
+#if defined(ARDUINO) && ARDUINO >= 100\r
+    #include "Arduino.h"\r
+#else\r
+    #include "WProgram.h"\r
+#endif\r
+\r
+// Number of maximum High/Low changes per packet.\r
+// We can handle up to (unsigned long) => 32 bit * 2 H/L changes per bit + 2 for sync\r
+#define RCSWITCH_MAX_CHANGES 67\r
+\r
+\r
+class RCSwitch {\r
+\r
+  public:\r
+    RCSwitch();\r
+    \r
+    void switchOn(int nGroupNumber, int nSwitchNumber);\r
+    void switchOff(int nGroupNumber, int nSwitchNumber);\r
+    void switchOn(char* sGroup, int nSwitchNumber);\r
+    void switchOff(char* sGroup, int nSwitchNumber);\r
+    void switchOn(char sFamily, int nGroup, int nDevice);\r
+    void switchOff(char sFamily, int nGroup, int nDevice);\r
+       void switchOn(char* sGroup, char* sDevice);\r
+       void switchOff(char* sGroup, char* sDevice);\r
+\r
+    void sendTriState(char* Code);\r
+    void send(unsigned long Code, unsigned int length);\r
+    void send(char* Code);\r
+    \r
+    void enableReceive(int interrupt);\r
+    void enableReceive();\r
+    void disableReceive();\r
+    bool available();\r
+       void resetAvailable();\r
+       \r
+    unsigned long getReceivedValue();\r
+    unsigned int getReceivedBitlength();\r
+    unsigned int getReceivedDelay();\r
+       unsigned int getReceivedProtocol();\r
+    unsigned int* getReceivedRawdata();\r
+  \r
+    void enableTransmit(int nTransmitterPin);\r
+    void disableTransmit();\r
+    void setPulseLength(int nPulseLength);\r
+    void setRepeatTransmit(int nRepeatTransmit);\r
+    void setReceiveTolerance(int nPercent);\r
+       void setProtocol(int nProtocol);\r
+       void setProtocol(int nProtocol, int nPulseLength);\r
+  \r
+  private:\r
+    char* getCodeWordB(int nGroupNumber, int nSwitchNumber, boolean bStatus);\r
+    char* getCodeWordA(char* sGroup, int nSwitchNumber, boolean bStatus);\r
+    char* getCodeWordA(char* sGroup, char* sDevice, boolean bStatus);\r
+    char* getCodeWordC(char sFamily, int nGroup, int nDevice, boolean bStatus);\r
+    void sendT0();\r
+    void sendT1();\r
+    void sendTF();\r
+    void send0();\r
+    void send1();\r
+    void sendSync();\r
+    void transmit(int nHighPulses, int nLowPulses);\r
+\r
+    static char* dec2binWzerofill(unsigned long dec, unsigned int length);\r
+    \r
+    static void handleInterrupt();\r
+       static bool receiveProtocol1(unsigned int changeCount);\r
+       static bool receiveProtocol2(unsigned int changeCount);\r
+    int nReceiverInterrupt;\r
+    int nTransmitterPin;\r
+    int nPulseLength;\r
+    int nRepeatTransmit;\r
+       char nProtocol;\r
+\r
+       static int nReceiveTolerance;\r
+    static unsigned long nReceivedValue;\r
+    static unsigned int nReceivedBitlength;\r
+       static unsigned int nReceivedDelay;\r
+       static unsigned int nReceivedProtocol;\r
+    static unsigned int timings[RCSWITCH_MAX_CHANGES];\r
+\r
+    \r
+};\r
+\r
+#endif\r
diff --git a/libraries/RCSwitch/examples/ReceiveDemo_Advanced/ReceiveDemo_Advanced.pde b/libraries/RCSwitch/examples/ReceiveDemo_Advanced/ReceiveDemo_Advanced.pde
new file mode 100644 (file)
index 0000000..a345535
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+  Example for receiving
+  
+  http://code.google.com/p/rc-switch/
+  
+  If you want to visualize a telegram copy the raw data and 
+  paste it into http://test.sui.li/oszi/
+*/
+
+#include <RCSwitch.h>
+
+RCSwitch mySwitch = RCSwitch();
+
+void setup() {
+  Serial.begin(9600);
+  mySwitch.enableReceive(0);  // Receiver on inerrupt 0 => that is pin #2
+}
+
+void loop() {
+  if (mySwitch.available()) {
+    output(mySwitch.getReceivedValue(), mySwitch.getReceivedBitlength(), mySwitch.getReceivedDelay(), mySwitch.getReceivedRawdata(),mySwitch.getReceivedProtocol());
+    mySwitch.resetAvailable();
+  }
+}\r
diff --git a/libraries/RCSwitch/examples/ReceiveDemo_Advanced/helperfunctions.ino b/libraries/RCSwitch/examples/ReceiveDemo_Advanced/helperfunctions.ino
new file mode 100644 (file)
index 0000000..d12db43
--- /dev/null
@@ -0,0 +1,20 @@
+static char * dec2binWzerofill(unsigned long Dec, unsigned int bitLength){
+  static char bin[64]; 
+  unsigned int i=0;
+
+  while (Dec > 0) {
+    bin[32+i++] = (Dec & 1 > 0) ? '1' : '0';
+    Dec = Dec >> 1;
+  }
+
+  for (unsigned int j = 0; j< bitLength; j++) {
+    if (j >= bitLength - i) {
+      bin[j] = bin[ 31 + i - (j - (bitLength - i)) ];
+    }else {
+      bin[j] = '0';
+    }
+  }
+  bin[bitLength] = '\0';
+  
+  return bin;
+}\r
diff --git a/libraries/RCSwitch/examples/ReceiveDemo_Advanced/output.ino b/libraries/RCSwitch/examples/ReceiveDemo_Advanced/output.ino
new file mode 100644 (file)
index 0000000..dfa49cc
--- /dev/null
@@ -0,0 +1,52 @@
+void output(unsigned long decimal, unsigned int length, unsigned int delay, unsigned int* raw, unsigned int protocol) {
+
+  if (decimal == 0) {
+    Serial.print("Unknown encoding.");
+  } else {
+    char* b = dec2binWzerofill(decimal, length);
+    Serial.print("Decimal: ");
+    Serial.print(decimal);
+    Serial.print(" (");
+    Serial.print( length );
+    Serial.print("Bit) Binary: ");
+    Serial.print( b );
+    Serial.print(" Tri-State: ");
+    Serial.print( bin2tristate( b) );
+    Serial.print(" PulseLength: ");
+    Serial.print(delay);
+    Serial.print(" microseconds");
+    Serial.print(" Protocol: ");
+    Serial.println(protocol);
+  }
+  
+  Serial.print("Raw data: ");
+  for (int i=0; i<= length*2; i++) {
+    Serial.print(raw[i]);
+    Serial.print(",");
+  }
+  Serial.println();
+  Serial.println();
+}
+
+
+static char* bin2tristate(char* bin) {
+  char returnValue[50];
+  int pos = 0;
+  int pos2 = 0;
+  while (bin[pos]!='\0' && bin[pos+1]!='\0') {
+    if (bin[pos]=='0' && bin[pos+1]=='0') {
+      returnValue[pos2] = '0';
+    } else if (bin[pos]=='1' && bin[pos+1]=='1') {
+      returnValue[pos2] = '1';
+    } else if (bin[pos]=='0' && bin[pos+1]=='1') {
+      returnValue[pos2] = 'F';
+    } else {
+      return "not applicable";
+    }
+    pos = pos+2;
+    pos2++;
+  }
+  returnValue[pos2] = '\0';
+  return returnValue;
+}
+\r
diff --git a/libraries/RCSwitch/examples/ReceiveDemo_Simple/ReceiveDemo_Simple.pde b/libraries/RCSwitch/examples/ReceiveDemo_Simple/ReceiveDemo_Simple.pde
new file mode 100644 (file)
index 0000000..ebd5a25
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+  Simple example for receiving
+  
+  http://code.google.com/p/rc-switch/
+*/
+
+#include <RCSwitch.h>
+
+RCSwitch mySwitch = RCSwitch();
+
+void setup() {
+  Serial.begin(9600);
+  mySwitch.enableReceive(0);  // Receiver on inerrupt 0 => that is pin #2
+}
+
+void loop() {
+  if (mySwitch.available()) {
+    
+    int value = mySwitch.getReceivedValue();
+    
+    if (value == 0) {
+      Serial.print("Unknown encoding");
+    } else {
+      Serial.print("Received ");
+      Serial.print( mySwitch.getReceivedValue() );
+      Serial.print(" / ");
+      Serial.print( mySwitch.getReceivedBitlength() );
+      Serial.print("bit ");
+      Serial.print("Protocol: ");
+      Serial.println( mySwitch.getReceivedProtocol() );
+    }
+
+    mySwitch.resetAvailable();
+  }
+}\r
diff --git a/libraries/RCSwitch/examples/SendDemo/SendDemo.pde b/libraries/RCSwitch/examples/SendDemo/SendDemo.pde
new file mode 100644 (file)
index 0000000..0441276
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+  Example for different sending methods
+  
+  http://code.google.com/p/rc-switch/
+*/
+
+#include <RCSwitch.h>
+
+RCSwitch mySwitch = RCSwitch();
+
+void setup() {
+
+  Serial.begin(9600);
+  
+  // Transmitter is connected to Arduino Pin #10  
+  mySwitch.enableTransmit(10);
+
+  // Optional set pulse length.
+  // mySwitch.setPulseLength(320);
+  
+  // Optional set protocol (default is 1, will work for most outlets)
+  // mySwitch.setProtocol(2);
+  
+  // Optional set number of transmission repetitions.
+  // mySwitch.setRepeatTransmit(15);
+  
+}
+
+void loop() {
+
+  /* See Example: TypeA_WithDIPSwitches */
+  mySwitch.switchOn("11111", "00010")
+  delay(1000);
+  mySwitch.switchOn("11111", "00010")
+  deleay(1000);
+
+  /* Same switch as above, but using decimal code */
+  mySwitch.send(5393, 24);
+  delay(1000);  
+  mySwitch.send(5396, 24);
+  delay(1000);  
+
+  /* Same switch as above, but using binary code */
+  mySwitch.send("000000000001010100010001");
+  delay(1000);  
+  mySwitch.send("000000000001010100010100");
+  delay(1000);
+
+  /* Same switch as above, but tri-state code */ 
+  mySwitch.sendTriState("00000FFF0F0F");
+  delay(1000);  
+  mySwitch.sendTriState("00000FFF0FF0");
+  delay(1000);
+
+  delay(20000);
+}
diff --git a/libraries/RCSwitch/examples/TypeA_WithDIPSwitches/TypeA_WithDIPSwitches.pde b/libraries/RCSwitch/examples/TypeA_WithDIPSwitches/TypeA_WithDIPSwitches.pde
new file mode 100644 (file)
index 0000000..c5b7b57
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+  Example for outlets which are configured with a 10 pole DIP switch.
+  
+  http://code.google.com/p/rc-switch/
+*/
+
+#include <RCSwitch.h>
+
+RCSwitch mySwitch = RCSwitch();
+
+void setup() {
+
+  // Transmitter is connected to Arduino Pin #10  
+  mySwitch.enableTransmit(10);
+
+  // Optional set pulse length.
+  // mySwitch.setPulseLength(320);
+  
+}
+
+void loop() {
+
+  // Switch on:
+  // The first parameter represents the setting of the first 5 DIP switches. 
+  // In this example it's ON-ON-OFF-OFF-ON.
+  // 
+  // The second parameter represents the setting of the last 5 DIP switches. 
+  // In this example the last 5 DIP switches are OFF-ON-OFF-ON-OFF.  
+  mySwitch.switchOn("11001", "01010");
+
+  // Wait a second
+  delay(1000);
+  
+  // Switch off
+  mySwitch.switchOff("11001", "01010");
+  
+  // Wait another second
+  delay(1000);
+  
+}\r
diff --git a/libraries/RCSwitch/examples/TypeB_WithRotaryOrSlidingSwitches/TypeB_WithRotaryOrSlidingSwitches.pde b/libraries/RCSwitch/examples/TypeB_WithRotaryOrSlidingSwitches/TypeB_WithRotaryOrSlidingSwitches.pde
new file mode 100644 (file)
index 0000000..61e0d76
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+  Example for outlets which are configured with two rotary/sliding switches.
+  
+  http://code.google.com/p/rc-switch/
+*/
+
+#include <RCSwitch.h>
+
+RCSwitch mySwitch = RCSwitch();
+
+void setup() {
+
+  // Transmitter is connected to Arduino Pin #10  
+  mySwitch.enableTransmit(10);
+  
+  // Optional set pulse length.
+  // mySwitch.setPulseLength(320);
+  
+}
+
+void loop() {
+
+  // Switch on:
+  // The first parameter represents the setting of the first rotary switch. 
+  // In this example it's switched to "1" or "A" or "I". 
+  // 
+  // The second parameter represents the setting of the second rotary switch. 
+  // In this example it's switched to "4" or "D" or "IV". 
+  mySwitch.switchOn(1, 4);
+
+  // Wait a second
+  delay(1000);
+  
+  // Switch off
+  mySwitch.switchOff(1, 4);
+  
+  // Wait another second
+  delay(1000);
+  
+}
diff --git a/libraries/RCSwitch/examples/TypeC_Intertechno/TypeC_Intertechno.pde b/libraries/RCSwitch/examples/TypeC_Intertechno/TypeC_Intertechno.pde
new file mode 100644 (file)
index 0000000..05596d8
--- /dev/null
@@ -0,0 +1,40 @@
+/*\r
+  Example for Intertechno outlets\r
+  \r
+  http://code.google.com/p/rc-switch/\r
+*/\r
+\r
+#include <RCSwitch.h>\r
+\r
+RCSwitch mySwitch = RCSwitch();\r
+\r
+void setup() {\r
+\r
+  // Transmitter is connected to Arduino Pin #10  \r
+  mySwitch.enableTransmit(10);\r
+  \r
+  // Optional set pulse length.\r
+  // mySwitch.setPulseLength(320);\r
+  \r
+}\r
+\r
+void loop() {\r
+\r
+  // Switch on:\r
+  // The first parameter represents the familycode (a, b, c, ... f)\r
+  // The second parameter represents the group number\r
+  // The third parameter represents the device number\r
+  // \r
+  // In this example it's family 'b', group #3, device #2 \r
+  mySwitch.switchOn('b', 3, 2);\r
+\r
+  // Wait a second\r
+  delay(1000);\r
+  \r
+  // Switch off\r
+  mySwitch.switchOff('b', 3, 2);\r
+  \r
+  // Wait another second\r
+  delay(1000);\r
+  \r
+}
\ No newline at end of file
diff --git a/libraries/RCSwitch/examples/Webserver/Webserver.pde b/libraries/RCSwitch/examples/Webserver/Webserver.pde
new file mode 100644 (file)
index 0000000..ee2c74a
--- /dev/null
@@ -0,0 +1,154 @@
+/*
+  A simple RCSwitch/Ethernet/Webserver demo
+  
+  http://code.google.com/p/rc-switch/
+*/
+
+#include <SPI.h>
+#include <Ethernet.h>
+#include <RCSwitch.h>
+
+// Ethernet configuration
+byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC Address
+byte ip[] = { 192,168,0, 2 };                        // IP Address
+EthernetServer server(80);                           // Server Port 80
+
+// RCSwitch configuration
+RCSwitch mySwitch = RCSwitch();
+int RCTransmissionPin = 7;
+
+// More to do...
+// You should also modify the processCommand() and 
+// httpResponseHome() functions to fit your needs.
+
+
+
+/**
+ * Setup
+ */
+void setup() {
+  Ethernet.begin(mac, ip);
+  server.begin();
+  mySwitch.enableTransmit( RCTransmissionPin );
+}
+
+/**
+ * Loop
+ */
+void loop() {
+  char* command = httpServer();
+}
+
+/**
+ * Command dispatcher
+ */
+void processCommand(char* command) {
+  if        (strcmp(command, "1-on") == 0) {
+    mySwitch.switchOn(1,1);
+  } else if (strcmp(command, "1-off") == 0) {
+    mySwitch.switchOff(1,1);
+  } else if (strcmp(command, "2-on") == 0) {
+    mySwitch.switchOn(1,2);
+  } else if (strcmp(command, "2-off") == 0) {
+    mySwitch.switchOff(1,2);
+  }
+}
+
+/**
+ * HTTP Response with homepage
+ */
+void httpResponseHome(EthernetClient c) {
+  c.println("HTTP/1.1 200 OK");
+  c.println("Content-Type: text/html");
+  c.println();
+  c.println("<html>");
+  c.println("<head>");
+  c.println(    "<title>RCSwitch Webserver Demo</title>");
+  c.println(    "<style>");
+  c.println(        "body { font-family: Arial, sans-serif; font-size:12px; }");
+  c.println(    "</style>");
+  c.println("</head>");
+  c.println("<body>");
+  c.println(    "<h1>RCSwitch Webserver Demo</h1>");
+  c.println(    "<ul>");
+  c.println(        "<li><a href=\"./?1-on\">Switch #1 on</a></li>");
+  c.println(        "<li><a href=\"./?1-off\">Switch #1 off</a></li>");
+  c.println(    "</ul>");
+  c.println(    "<ul>");
+  c.println(        "<li><a href=\"./?2-on\">Switch #2 on</a></li>");
+  c.println(        "<li><a href=\"./?2-off\">Switch #2 off</a></li>");
+  c.println(    "</ul>");
+  c.println(    "<hr>");
+  c.println(    "<a href=\"http://code.google.com/p/rc-switch/\">http://code.google.com/p/rc-switch/</a>");
+  c.println("</body>");
+  c.println("</html>");
+}
+
+/**
+ * HTTP Redirect to homepage
+ */
+void httpResponseRedirect(EthernetClient c) {
+  c.println("HTTP/1.1 301 Found");
+  c.println("Location: /");
+  c.println();
+}
+
+/**
+ * HTTP Response 414 error
+ * Command must not be longer than 30 characters
+ **/
+void httpResponse414(EthernetClient c) {
+  c.println("HTTP/1.1 414 Request URI too long");
+  c.println("Content-Type: text/plain");
+  c.println();
+  c.println("414 Request URI too long");
+}
+
+/**
+ * Process HTTP requests, parse first request header line and 
+ * call processCommand with GET query string (everything after
+ * the ? question mark in the URL).
+ */
+char*  httpServer() {
+  EthernetClient client = server.available();
+  if (client) {
+    char sReturnCommand[32];
+    int nCommandPos=-1;
+    sReturnCommand[0] = '\0';
+    while (client.connected()) {
+      if (client.available()) {
+        char c = client.read();
+        if ((c == '\n') || (c == ' ' && nCommandPos>-1)) {
+          sReturnCommand[nCommandPos] = '\0';
+          if (strcmp(sReturnCommand, "\0") == 0) {
+            httpResponseHome(client);
+          } else {
+            processCommand(sReturnCommand);
+            httpResponseRedirect(client);
+          }
+          break;
+        }
+        if (nCommandPos>-1) {
+          sReturnCommand[nCommandPos++] = c;
+        }
+        if (c == '?' && nCommandPos == -1) {
+          nCommandPos = 0;
+        }
+      }
+      if (nCommandPos > 30) {
+        httpResponse414(client);
+        sReturnCommand[0] = '\0';
+        break;
+      }
+    }
+    if (nCommandPos!=-1) {
+      sReturnCommand[nCommandPos] = '\0';
+    }
+    // give the web browser time to receive the data
+    delay(1);
+    client.stop();
+    
+    return sReturnCommand;
+  }
+  return '\0';
+}
\ No newline at end of file
diff --git a/libraries/RCSwitch/keywords.txt b/libraries/RCSwitch/keywords.txt
new file mode 100644 (file)
index 0000000..48fd797
--- /dev/null
@@ -0,0 +1,57 @@
+#######################################\r
+# Syntax Coloring Map For RCSwitch\r
+#######################################\r
+\r
+#######################################\r
+# Datatypes (KEYWORD1)\r
+#######################################\r
+\r
+RCSwitch       KEYWORD1\r
+\r
+#######################################\r
+# Methods and Functions (KEYWORD2)\r
+#######################################\r
+\r
+##########\r
+#SENDS Begin\r
+##########\r
+switchOn               KEYWORD2\r
+switchOff              KEYWORD2\r
+sendTriState           KEYWORD2\r
+send                   KEYWORD2\r
+##########\r
+#SENDS End\r
+##########\r
+\r
+##########\r
+#RECEIVE Begin\r
+##########\r
+enableReceive          KEYWORD2\r
+disableReceive         KEYWORD2\r
+available              KEYWORD2        \r
+resetAvailable         KEYWORD2\r
+setReceiveTolerance    KEYWORD2\r
+getReceivedValue       KEYWORD2\r
+getReceivedBitlength   KEYWORD2\r
+getReceivedDelay       KEYWORD2\r
+getReceivedProtocol    KEYWORD2\r
+getReceivedRawdata     KEYWORD2\r
+##########\r
+#RECEIVE End\r
+##########\r
+\r
+##########\r
+#OTHERS Begin\r
+##########\r
+enableTransmit         KEYWORD2\r
+disableTransmit                KEYWORD2\r
+setPulseLength         KEYWORD2\r
+setProtocol            KEYWORD2\r
+setRepeatTransmit      KEYWORD2\r
+##########\r
+#OTHERS End\r
+##########\r
+\r
+#######################################\r
+# Constants (LITERAL1)\r
+#######################################\r