socket_switcher 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.utilsrc +26 -0
- data/Gemfile +8 -0
- data/README.md +0 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/arduino-receiver/receiver/receiver.ino +36 -0
- data/arduino/lib/.holder +0 -0
- data/arduino/lib/RCSwitch/RCSwitch.cpp +823 -0
- data/arduino/lib/RCSwitch/RCSwitch.h +144 -0
- data/arduino/lib/RCSwitch/examples/ReceiveDemo_Advanced/ReceiveDemo_Advanced.pde +24 -0
- data/arduino/lib/RCSwitch/examples/ReceiveDemo_Advanced/helperfunctions.ino +20 -0
- data/arduino/lib/RCSwitch/examples/ReceiveDemo_Advanced/output.ino +52 -0
- data/arduino/lib/RCSwitch/examples/ReceiveDemo_Simple/ReceiveDemo_Simple.pde +35 -0
- data/arduino/lib/RCSwitch/examples/SendDemo/SendDemo.pde +57 -0
- data/arduino/lib/RCSwitch/examples/TypeA_WithDIPSwitches/TypeA_WithDIPSwitches.pde +40 -0
- data/arduino/lib/RCSwitch/examples/TypeA_WithDIPSwitches_Lightweight/TypeA_WithDIPSwitches_Lightweight.ino +43 -0
- data/arduino/lib/RCSwitch/examples/TypeB_WithRotaryOrSlidingSwitches/TypeB_WithRotaryOrSlidingSwitches.pde +40 -0
- data/arduino/lib/RCSwitch/examples/TypeC_Intertechno/TypeC_Intertechno.pde +40 -0
- data/arduino/lib/RCSwitch/examples/TypeD_REV/TypeD_REV.ino +41 -0
- data/arduino/lib/RCSwitch/examples/Webserver/Webserver.pde +154 -0
- data/arduino/lib/RCSwitch/keywords.txt +57 -0
- data/arduino/src/switcher/switcher.ino.erb +79 -0
- data/config/default.yml +11 -0
- data/config/traffic_lights.yml +8 -0
- data/examples/blinkenlights.rb +25 -0
- data/lib/socket_switcher.rb +7 -0
- data/lib/socket_switcher/device.rb +24 -0
- data/lib/socket_switcher/errors.rb +26 -0
- data/lib/socket_switcher/port.rb +134 -0
- data/lib/socket_switcher/version.rb +8 -0
- data/socket_switcher.gemspec +49 -0
- data/spec/socket_switcher/device_spec.rb +37 -0
- data/spec/socket_switcher/port_spec.rb +216 -0
- data/spec/spec_helper.rb +9 -0
- metadata +176 -0
@@ -0,0 +1,144 @@
|
|
1
|
+
/*
|
2
|
+
RCSwitch - Arduino libary for remote control outlet switches
|
3
|
+
Copyright (c) 2011 Suat �zg�r. All right reserved.
|
4
|
+
|
5
|
+
Contributors:
|
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
|
+
|
12
|
+
Project home: http://code.google.com/p/rc-switch/
|
13
|
+
|
14
|
+
This library is free software; you can redistribute it and/or
|
15
|
+
modify it under the terms of the GNU Lesser General Public
|
16
|
+
License as published by the Free Software Foundation; either
|
17
|
+
version 2.1 of the License, or (at your option) any later version.
|
18
|
+
|
19
|
+
This library is distributed in the hope that it will be useful,
|
20
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
21
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
22
|
+
Lesser General Public License for more details.
|
23
|
+
|
24
|
+
You should have received a copy of the GNU Lesser General Public
|
25
|
+
License along with this library; if not, write to the Free Software
|
26
|
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
27
|
+
*/
|
28
|
+
#ifndef _RCSwitch_h
|
29
|
+
#define _RCSwitch_h
|
30
|
+
|
31
|
+
#if defined(ARDUINO) && ARDUINO >= 100
|
32
|
+
#include "Arduino.h"
|
33
|
+
#elif defined(ENERGIA) // LaunchPad, FraunchPad and StellarPad specific
|
34
|
+
#include "Energia.h"
|
35
|
+
#else
|
36
|
+
#include "WProgram.h"
|
37
|
+
#endif
|
38
|
+
|
39
|
+
|
40
|
+
// At least for the ATTiny X4/X5, receiving has to be disabled due to
|
41
|
+
// missing libm depencies (udivmodhi4)
|
42
|
+
#if defined( __AVR_ATtinyX5__ ) or defined ( __AVR_ATtinyX4__ )
|
43
|
+
#define RCSwitchDisableReceiving
|
44
|
+
#endif
|
45
|
+
|
46
|
+
// Number of maximum High/Low changes per packet.
|
47
|
+
// We can handle up to (unsigned long) => 32 bit * 2 H/L changes per bit + 2 for sync
|
48
|
+
#define RCSWITCH_MAX_CHANGES 67
|
49
|
+
|
50
|
+
#define PROTOCOL3_SYNC_FACTOR 71
|
51
|
+
#define PROTOCOL3_0_HIGH_CYCLES 4
|
52
|
+
#define PROTOCOL3_0_LOW_CYCLES 11
|
53
|
+
#define PROTOCOL3_1_HIGH_CYCLES 9
|
54
|
+
#define PROTOCOL3_1_LOW_CYCLES 6
|
55
|
+
|
56
|
+
class RCSwitch {
|
57
|
+
|
58
|
+
public:
|
59
|
+
RCSwitch();
|
60
|
+
|
61
|
+
void switchOn(int nGroupNumber, int nSwitchNumber);
|
62
|
+
void switchOff(int nGroupNumber, int nSwitchNumber);
|
63
|
+
void switchOn(char* sGroup, int nSwitchNumber);
|
64
|
+
void switchOff(char* sGroup, int nSwitchNumber);
|
65
|
+
void switchOn(char sFamily, int nGroup, int nDevice);
|
66
|
+
void switchOff(char sFamily, int nGroup, int nDevice);
|
67
|
+
void switchOn(char* sGroup, char* sDevice);
|
68
|
+
void switchOff(char* sGroup, char* sDevice);
|
69
|
+
void switchOn(char sGroup, int nDevice);
|
70
|
+
void switchOff(char sGroup, int nDevice);
|
71
|
+
|
72
|
+
void sendTriState(char* Code);
|
73
|
+
void send(unsigned long Code, unsigned int length);
|
74
|
+
void send(char* Code);
|
75
|
+
|
76
|
+
#if not defined( RCSwitchDisableReceiving )
|
77
|
+
void enableReceive(int interrupt);
|
78
|
+
void enableReceive();
|
79
|
+
void disableReceive();
|
80
|
+
bool available();
|
81
|
+
void resetAvailable();
|
82
|
+
|
83
|
+
unsigned long getReceivedValue();
|
84
|
+
unsigned int getReceivedBitlength();
|
85
|
+
unsigned int getReceivedDelay();
|
86
|
+
unsigned int getReceivedProtocol();
|
87
|
+
unsigned int* getReceivedRawdata();
|
88
|
+
#endif
|
89
|
+
|
90
|
+
void enableTransmit(int nTransmitterPin);
|
91
|
+
void disableTransmit();
|
92
|
+
void setPulseLength(int nPulseLength);
|
93
|
+
void setRepeatTransmit(int nRepeatTransmit);
|
94
|
+
#if not defined( RCSwitchDisableReceiving )
|
95
|
+
void setReceiveTolerance(int nPercent);
|
96
|
+
#endif
|
97
|
+
void setProtocol(int nProtocol);
|
98
|
+
void setProtocol(int nProtocol, int nPulseLength);
|
99
|
+
|
100
|
+
private:
|
101
|
+
char* getCodeWordB(int nGroupNumber, int nSwitchNumber, boolean bStatus);
|
102
|
+
char* getCodeWordA(char* sGroup, int nSwitchNumber, boolean bStatus);
|
103
|
+
char* getCodeWordA(char* sGroup, char* sDevice, boolean bStatus);
|
104
|
+
char* getCodeWordC(char sFamily, int nGroup, int nDevice, boolean bStatus);
|
105
|
+
char* getCodeWordD(char group, int nDevice, boolean bStatus);
|
106
|
+
void sendT0();
|
107
|
+
void sendT1();
|
108
|
+
void sendTF();
|
109
|
+
void send0();
|
110
|
+
void send1();
|
111
|
+
void sendSync();
|
112
|
+
void transmit(int nHighPulses, int nLowPulses);
|
113
|
+
|
114
|
+
static char* dec2binWzerofill(unsigned long dec, unsigned int length);
|
115
|
+
static char* dec2binWcharfill(unsigned long dec, unsigned int length, char fill);
|
116
|
+
|
117
|
+
#if not defined( RCSwitchDisableReceiving )
|
118
|
+
static void handleInterrupt();
|
119
|
+
static bool receiveProtocol1(unsigned int changeCount);
|
120
|
+
static bool receiveProtocol2(unsigned int changeCount);
|
121
|
+
static bool receiveProtocol3(unsigned int changeCount);
|
122
|
+
int nReceiverInterrupt;
|
123
|
+
#endif
|
124
|
+
int nTransmitterPin;
|
125
|
+
int nPulseLength;
|
126
|
+
int nRepeatTransmit;
|
127
|
+
char nProtocol;
|
128
|
+
|
129
|
+
#if not defined( RCSwitchDisableReceiving )
|
130
|
+
static int nReceiveTolerance;
|
131
|
+
static unsigned long nReceivedValue;
|
132
|
+
static unsigned int nReceivedBitlength;
|
133
|
+
static unsigned int nReceivedDelay;
|
134
|
+
static unsigned int nReceivedProtocol;
|
135
|
+
#endif
|
136
|
+
/*
|
137
|
+
* timings[0] contains sync timing, followed by a number of bits
|
138
|
+
*/
|
139
|
+
static unsigned int timings[RCSWITCH_MAX_CHANGES];
|
140
|
+
|
141
|
+
|
142
|
+
};
|
143
|
+
|
144
|
+
#endif
|
@@ -0,0 +1,24 @@
|
|
1
|
+
/*
|
2
|
+
Example for receiving
|
3
|
+
|
4
|
+
http://code.google.com/p/rc-switch/
|
5
|
+
|
6
|
+
If you want to visualize a telegram copy the raw data and
|
7
|
+
paste it into http://test.sui.li/oszi/
|
8
|
+
*/
|
9
|
+
|
10
|
+
#include <RCSwitch.h>
|
11
|
+
|
12
|
+
RCSwitch mySwitch = RCSwitch();
|
13
|
+
|
14
|
+
void setup() {
|
15
|
+
Serial.begin(9600);
|
16
|
+
mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2
|
17
|
+
}
|
18
|
+
|
19
|
+
void loop() {
|
20
|
+
if (mySwitch.available()) {
|
21
|
+
output(mySwitch.getReceivedValue(), mySwitch.getReceivedBitlength(), mySwitch.getReceivedDelay(), mySwitch.getReceivedRawdata(),mySwitch.getReceivedProtocol());
|
22
|
+
mySwitch.resetAvailable();
|
23
|
+
}
|
24
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
static char * dec2binWzerofill(unsigned long Dec, unsigned int bitLength){
|
2
|
+
static char bin[64];
|
3
|
+
unsigned int i=0;
|
4
|
+
|
5
|
+
while (Dec > 0) {
|
6
|
+
bin[32+i++] = (Dec & 1 > 0) ? '1' : '0';
|
7
|
+
Dec = Dec >> 1;
|
8
|
+
}
|
9
|
+
|
10
|
+
for (unsigned int j = 0; j< bitLength; j++) {
|
11
|
+
if (j >= bitLength - i) {
|
12
|
+
bin[j] = bin[ 31 + i - (j - (bitLength - i)) ];
|
13
|
+
}else {
|
14
|
+
bin[j] = '0';
|
15
|
+
}
|
16
|
+
}
|
17
|
+
bin[bitLength] = '\0';
|
18
|
+
|
19
|
+
return bin;
|
20
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
void output(unsigned long decimal, unsigned int length, unsigned int delay, unsigned int* raw, unsigned int protocol) {
|
2
|
+
|
3
|
+
if (decimal == 0) {
|
4
|
+
Serial.print("Unknown encoding.");
|
5
|
+
} else {
|
6
|
+
char* b = dec2binWzerofill(decimal, length);
|
7
|
+
Serial.print("Decimal: ");
|
8
|
+
Serial.print(decimal);
|
9
|
+
Serial.print(" (");
|
10
|
+
Serial.print( length );
|
11
|
+
Serial.print("Bit) Binary: ");
|
12
|
+
Serial.print( b );
|
13
|
+
Serial.print(" Tri-State: ");
|
14
|
+
Serial.print( bin2tristate( b) );
|
15
|
+
Serial.print(" PulseLength: ");
|
16
|
+
Serial.print(delay);
|
17
|
+
Serial.print(" microseconds");
|
18
|
+
Serial.print(" Protocol: ");
|
19
|
+
Serial.println(protocol);
|
20
|
+
}
|
21
|
+
|
22
|
+
Serial.print("Raw data: ");
|
23
|
+
for (int i=0; i<= length*2; i++) {
|
24
|
+
Serial.print(raw[i]);
|
25
|
+
Serial.print(",");
|
26
|
+
}
|
27
|
+
Serial.println();
|
28
|
+
Serial.println();
|
29
|
+
}
|
30
|
+
|
31
|
+
|
32
|
+
static char* bin2tristate(char* bin) {
|
33
|
+
char returnValue[50];
|
34
|
+
int pos = 0;
|
35
|
+
int pos2 = 0;
|
36
|
+
while (bin[pos]!='\0' && bin[pos+1]!='\0') {
|
37
|
+
if (bin[pos]=='0' && bin[pos+1]=='0') {
|
38
|
+
returnValue[pos2] = '0';
|
39
|
+
} else if (bin[pos]=='1' && bin[pos+1]=='1') {
|
40
|
+
returnValue[pos2] = '1';
|
41
|
+
} else if (bin[pos]=='0' && bin[pos+1]=='1') {
|
42
|
+
returnValue[pos2] = 'F';
|
43
|
+
} else {
|
44
|
+
return "not applicable";
|
45
|
+
}
|
46
|
+
pos = pos+2;
|
47
|
+
pos2++;
|
48
|
+
}
|
49
|
+
returnValue[pos2] = '\0';
|
50
|
+
return returnValue;
|
51
|
+
}
|
52
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
/*
|
2
|
+
Simple example for receiving
|
3
|
+
|
4
|
+
http://code.google.com/p/rc-switch/
|
5
|
+
*/
|
6
|
+
|
7
|
+
#include <RCSwitch.h>
|
8
|
+
|
9
|
+
RCSwitch mySwitch = RCSwitch();
|
10
|
+
|
11
|
+
void setup() {
|
12
|
+
Serial.begin(9600);
|
13
|
+
mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2
|
14
|
+
}
|
15
|
+
|
16
|
+
void loop() {
|
17
|
+
if (mySwitch.available()) {
|
18
|
+
|
19
|
+
int value = mySwitch.getReceivedValue();
|
20
|
+
|
21
|
+
if (value == 0) {
|
22
|
+
Serial.print("Unknown encoding");
|
23
|
+
} else {
|
24
|
+
Serial.print("Received ");
|
25
|
+
Serial.print( mySwitch.getReceivedValue() );
|
26
|
+
Serial.print(" / ");
|
27
|
+
Serial.print( mySwitch.getReceivedBitlength() );
|
28
|
+
Serial.print("bit ");
|
29
|
+
Serial.print("Protocol: ");
|
30
|
+
Serial.println( mySwitch.getReceivedProtocol() );
|
31
|
+
}
|
32
|
+
|
33
|
+
mySwitch.resetAvailable();
|
34
|
+
}
|
35
|
+
}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
/*
|
2
|
+
Example for different sending methods
|
3
|
+
|
4
|
+
http://code.google.com/p/rc-switch/
|
5
|
+
|
6
|
+
*/
|
7
|
+
|
8
|
+
#include <RCSwitch.h>
|
9
|
+
|
10
|
+
RCSwitch mySwitch = RCSwitch();
|
11
|
+
|
12
|
+
void setup() {
|
13
|
+
|
14
|
+
Serial.begin(9600);
|
15
|
+
|
16
|
+
// Transmitter is connected to Arduino Pin #10
|
17
|
+
mySwitch.enableTransmit(10);
|
18
|
+
|
19
|
+
// Optional set pulse length.
|
20
|
+
// mySwitch.setPulseLength(320);
|
21
|
+
|
22
|
+
// Optional set protocol (default is 1, will work for most outlets)
|
23
|
+
// mySwitch.setProtocol(2);
|
24
|
+
|
25
|
+
// Optional set number of transmission repetitions.
|
26
|
+
// mySwitch.setRepeatTransmit(15);
|
27
|
+
|
28
|
+
}
|
29
|
+
|
30
|
+
void loop() {
|
31
|
+
|
32
|
+
/* See Example: TypeA_WithDIPSwitches */
|
33
|
+
mySwitch.switchOn("11111", "00010");
|
34
|
+
delay(1000);
|
35
|
+
mySwitch.switchOn("11111", "00010");
|
36
|
+
delay(1000);
|
37
|
+
|
38
|
+
/* Same switch as above, but using decimal code */
|
39
|
+
mySwitch.send(5393, 24);
|
40
|
+
delay(1000);
|
41
|
+
mySwitch.send(5396, 24);
|
42
|
+
delay(1000);
|
43
|
+
|
44
|
+
/* Same switch as above, but using binary code */
|
45
|
+
mySwitch.send("000000000001010100010001");
|
46
|
+
delay(1000);
|
47
|
+
mySwitch.send("000000000001010100010100");
|
48
|
+
delay(1000);
|
49
|
+
|
50
|
+
/* Same switch as above, but tri-state code */
|
51
|
+
mySwitch.sendTriState("00000FFF0F0F");
|
52
|
+
delay(1000);
|
53
|
+
mySwitch.sendTriState("00000FFF0FF0");
|
54
|
+
delay(1000);
|
55
|
+
|
56
|
+
delay(20000);
|
57
|
+
}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
/*
|
2
|
+
Example for outlets which are configured with a 10 pole DIP switch.
|
3
|
+
|
4
|
+
http://code.google.com/p/rc-switch/
|
5
|
+
*/
|
6
|
+
|
7
|
+
#include <RCSwitch.h>
|
8
|
+
|
9
|
+
RCSwitch mySwitch = RCSwitch();
|
10
|
+
|
11
|
+
void setup() {
|
12
|
+
|
13
|
+
// Transmitter is connected to Arduino Pin #10
|
14
|
+
mySwitch.enableTransmit(10);
|
15
|
+
|
16
|
+
// Optional set pulse length.
|
17
|
+
// mySwitch.setPulseLength(320);
|
18
|
+
|
19
|
+
}
|
20
|
+
|
21
|
+
void loop() {
|
22
|
+
|
23
|
+
// Switch on:
|
24
|
+
// The first parameter represents the setting of the first 5 DIP switches.
|
25
|
+
// In this example it's ON-ON-OFF-OFF-ON.
|
26
|
+
//
|
27
|
+
// The second parameter represents the setting of the last 5 DIP switches.
|
28
|
+
// In this example the last 5 DIP switches are OFF-ON-OFF-ON-OFF.
|
29
|
+
mySwitch.switchOn("11001", "01010");
|
30
|
+
|
31
|
+
// Wait a second
|
32
|
+
delay(1000);
|
33
|
+
|
34
|
+
// Switch off
|
35
|
+
mySwitch.switchOff("11001", "01010");
|
36
|
+
|
37
|
+
// Wait another second
|
38
|
+
delay(1000);
|
39
|
+
|
40
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
/*
|
2
|
+
This is a minimal sketch without using the library at all but only works for
|
3
|
+
the 10 pole dip switch sockets. It saves a lot of memory and thus might be
|
4
|
+
very useful to use with ATTinys :)
|
5
|
+
|
6
|
+
http://code.google.com/p/rc-switch/
|
7
|
+
*/
|
8
|
+
|
9
|
+
int RCLpin = 7;
|
10
|
+
|
11
|
+
void setup() {
|
12
|
+
pinMode(RCLpin, OUTPUT);
|
13
|
+
}
|
14
|
+
|
15
|
+
void loop() {
|
16
|
+
RCLswitch(0b010001000001); // DIPs an Steckdose: 0100010000 An:01
|
17
|
+
delay(2000);
|
18
|
+
|
19
|
+
RCLswitch(0b010001000010); // DIPs an Steckdose: 0100010000 Aus:10
|
20
|
+
delay(2000);
|
21
|
+
}
|
22
|
+
|
23
|
+
void RCLswitch(uint16_t code) {
|
24
|
+
for (int nRepeat=0; nRepeat<6; nRepeat++) {
|
25
|
+
for (int i=4; i<16; i++) {
|
26
|
+
RCLtransmit(1,3);
|
27
|
+
if (((code << (i-4)) & 2048) > 0) {
|
28
|
+
RCLtransmit(1,3);
|
29
|
+
} else {
|
30
|
+
RCLtransmit(3,1);
|
31
|
+
}
|
32
|
+
}
|
33
|
+
RCLtransmit(1,31);
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
void RCLtransmit(int nHighPulses, int nLowPulses) {
|
38
|
+
digitalWrite(RCLpin, HIGH);
|
39
|
+
delayMicroseconds( 350 * nHighPulses);
|
40
|
+
digitalWrite(RCLpin, LOW);
|
41
|
+
delayMicroseconds( 350 * nLowPulses);
|
42
|
+
}
|
43
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
/*
|
2
|
+
Example for outlets which are configured with two rotary/sliding switches.
|
3
|
+
|
4
|
+
http://code.google.com/p/rc-switch/
|
5
|
+
*/
|
6
|
+
|
7
|
+
#include <RCSwitch.h>
|
8
|
+
|
9
|
+
RCSwitch mySwitch = RCSwitch();
|
10
|
+
|
11
|
+
void setup() {
|
12
|
+
|
13
|
+
// Transmitter is connected to Arduino Pin #10
|
14
|
+
mySwitch.enableTransmit(10);
|
15
|
+
|
16
|
+
// Optional set pulse length.
|
17
|
+
// mySwitch.setPulseLength(320);
|
18
|
+
|
19
|
+
}
|
20
|
+
|
21
|
+
void loop() {
|
22
|
+
|
23
|
+
// Switch on:
|
24
|
+
// The first parameter represents the setting of the first rotary switch.
|
25
|
+
// In this example it's switched to "1" or "A" or "I".
|
26
|
+
//
|
27
|
+
// The second parameter represents the setting of the second rotary switch.
|
28
|
+
// In this example it's switched to "4" or "D" or "IV".
|
29
|
+
mySwitch.switchOn(1, 4);
|
30
|
+
|
31
|
+
// Wait a second
|
32
|
+
delay(1000);
|
33
|
+
|
34
|
+
// Switch off
|
35
|
+
mySwitch.switchOff(1, 4);
|
36
|
+
|
37
|
+
// Wait another second
|
38
|
+
delay(1000);
|
39
|
+
|
40
|
+
}
|