diff --git a/Makefile b/Makefile index 28fe0f3..54d0334 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,13 @@ -all: send +all: send sendTriState sendRev send: RCSwitch.o send.o $(CXX) $(CXXFLAGS) $(LDFLAGS) $+ -o $@ -lwiringPi +sendTriState: RCSwitch.o sendTriState.o + $(CXX) $(CXXFLAGS) $(LDFLAGS) $+ -o $@ -lwiringPi + +sendRev: RCSwitch.o sendRev.o + $(CXX) $(CXXFLAGS) $(LDFLAGS) $+ -o $@ -lwiringPi + clean: - $(RM) *.o send + $(RM) *.o send sendTriState sendRev diff --git a/RCSwitch.cpp b/RCSwitch.cpp index 4ce4df9..bf4a354 100644 --- a/RCSwitch.cpp +++ b/RCSwitch.cpp @@ -1,12 +1,12 @@ /* RCSwitch - Arduino libary for remote control outlet switches - Copyright (c) 2011 Suat Özgür. All right reserved. - + Copyright (c) 2011 Suat …zgŸr. All right reserved. + Contributors: - Andre Koehler / info(at)tomate-online(dot)de - Gordeev Andrey Vladimirovich / gordeev(at)openpyro(dot)com - Skineffect / http://forum.ardumote.com/viewtopic.php?f=2&t=48 - + Project home: http://code.google.com/p/rc-switch/ This library is free software; you can redistribute it and/or @@ -49,10 +49,10 @@ RCSwitch::RCSwitch() { void RCSwitch::setProtocol(int nProtocol) { this->nProtocol = nProtocol; if (nProtocol == 1){ - this->setPulseLength(350); + this->setPulseLength(350); } else if (nProtocol == 2) { - this->setPulseLength(650); + this->setPulseLength(650); } } @@ -62,10 +62,10 @@ void RCSwitch::setProtocol(int nProtocol) { void RCSwitch::setProtocol(int nProtocol, int nPulseLength) { this->nProtocol = nProtocol; if (nProtocol == 1){ - this->setPulseLength(nPulseLength); + this->setPulseLength(nPulseLength); } else if (nProtocol == 2) { - this->setPulseLength(nPulseLength); + this->setPulseLength(nPulseLength); } } @@ -90,7 +90,7 @@ void RCSwitch::setRepeatTransmit(int nRepeatTransmit) { void RCSwitch::setReceiveTolerance(int nPercent) { RCSwitch::nReceiveTolerance = nPercent; } - + /** * Enable transmissions @@ -109,6 +109,26 @@ void RCSwitch::disableTransmit() { this->nTransmitterPin = -1; } +/** + * Switch a remote switch on (Type D REV) + * + * @param sGroup Code of the switch group (A,B,C,D) + * @param nDevice Number of the switch itself (1..3) + */ +void RCSwitch::switchOn(char sGroup, int nDevice) { + this->sendTriState( this->getCodeWordD(sGroup, nDevice, true) ); +} + +/** + * Switch a remote switch off (Type D REV) + * + * @param sGroup Code of the switch group (A,B,C,D) + * @param nDevice Number of the switch itself (1..3) + */ +void RCSwitch::switchOff(char sGroup, int nDevice) { + this->sendTriState( this->getCodeWordD(sGroup, nDevice, false) ); +} + /** * Switch a remote switch on (Type C Intertechno) * @@ -152,23 +172,47 @@ void RCSwitch::switchOff(int nAddressCode, int nChannelCode) { } /** + * Deprecated, use switchOn(char* sGroup, char* sDevice) instead! * Switch a remote switch on (Type A with 10 pole DIP switches) * * @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") - * @param nChannelCode Number of the switch itself (1..4) + * @param nChannelCode Number of the switch itself (1..5) */ void RCSwitch::switchOn(char* sGroup, int nChannel) { - this->sendTriState( this->getCodeWordA(sGroup, nChannel, true) ); + char* code[6] = { "00000", "10000", "01000", "00100", "00010", "00001" }; + this->switchOn(sGroup, code[nChannel]); } /** + * Deprecated, use switchOff(char* sGroup, char* sDevice) instead! * Switch a remote switch off (Type A with 10 pole DIP switches) * * @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") - * @param nChannelCode Number of the switch itself (1..4) + * @param nChannelCode Number of the switch itself (1..5) */ void RCSwitch::switchOff(char* sGroup, int nChannel) { - this->sendTriState( this->getCodeWordA(sGroup, nChannel, false) ); + char* code[6] = { "00000", "10000", "01000", "00100", "00010", "00001" }; + this->switchOff(sGroup, code[nChannel]); +} + +/** + * Switch a remote switch on (Type A with 10 pole DIP switches) + * + * @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") + * @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") + */ +void RCSwitch::switchOn(char* sGroup, char* sDevice) { + this->sendTriState( this->getCodeWordA(sGroup, sDevice, true) ); +} + +/** + * Switch a remote switch off (Type A with 10 pole DIP switches) + * + * @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") + * @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") + */ +void RCSwitch::switchOff(char* sGroup, char* sDevice) { + this->sendTriState( this->getCodeWordA(sGroup, sDevice, false) ); } /** @@ -190,7 +234,7 @@ void RCSwitch::switchOff(char* sGroup, int nChannel) { char* RCSwitch::getCodeWordB(int nAddressCode, int nChannelCode, boolean bStatus) { int nReturnPos = 0; static char sReturn[13]; - + char* code[5] = { "FFFF", "0FFF", "F0FF", "FF0F", "FFF0" }; if (nAddressCode < 1 || nAddressCode > 4 || nChannelCode < 1 || nChannelCode > 4) { return '\0'; @@ -202,60 +246,60 @@ char* RCSwitch::getCodeWordB(int nAddressCode, int nChannelCode, boolean bStatus for (int i = 0; i<4; i++) { sReturn[nReturnPos++] = code[nChannelCode][i]; } - + sReturn[nReturnPos++] = 'F'; sReturn[nReturnPos++] = 'F'; sReturn[nReturnPos++] = 'F'; - + if (bStatus) { sReturn[nReturnPos++] = 'F'; } else { sReturn[nReturnPos++] = '0'; } - + sReturn[nReturnPos] = '\0'; - + return sReturn; } - /** - * Like getCodeWord (Type A) + * Returns a char[13], representing the Code Word to be send. + * + * getCodeWordA(char*, char*) + * */ -char* RCSwitch::getCodeWordA(char* sGroup, int nChannelCode, boolean bStatus) { - int nReturnPos = 0; - static char sReturn[13]; +char* RCSwitch::getCodeWordA(char* sGroup, char* sDevice, boolean bOn) { + static char sDipSwitches[13]; + int i = 0; + int j = 0; - char* code[6] = { "FFFFF", "0FFFF", "F0FFF", "FF0FF", "FFF0F", "FFFF0" }; + for (i=0; i < 5; i++) { + if (sGroup[i] == '0') { + sDipSwitches[j++] = 'F'; + } else { + sDipSwitches[j++] = '0'; + } + } - if (nChannelCode < 1 || nChannelCode > 5) { - return '\0'; - } - - for (int i = 0; i<5; i++) { - if (sGroup[i] == '0') { - sReturn[nReturnPos++] = 'F'; - } else if (sGroup[i] == '1') { - sReturn[nReturnPos++] = '0'; + for (i=0; i < 5; i++) { + if (sDevice[i] == '0') { + sDipSwitches[j++] = 'F'; + } else { + sDipSwitches[j++] = '0'; + } + } + + if ( bOn ) { + sDipSwitches[j++] = '0'; + sDipSwitches[j++] = 'F'; } else { - return '\0'; + sDipSwitches[j++] = 'F'; + sDipSwitches[j++] = '0'; } - } - - for (int i = 0; i<5; i++) { - sReturn[nReturnPos++] = code[ nChannelCode ][i]; - } - - if (bStatus) { - sReturn[nReturnPos++] = '0'; - sReturn[nReturnPos++] = 'F'; - } else { - sReturn[nReturnPos++] = 'F'; - sReturn[nReturnPos++] = '0'; - } - sReturn[nReturnPos] = '\0'; - return sReturn; + sDipSwitches[j] = '\0'; + + return sDipSwitches; } /** @@ -264,11 +308,11 @@ char* RCSwitch::getCodeWordA(char* sGroup, int nChannelCode, boolean bStatus) { char* RCSwitch::getCodeWordC(char sFamily, int nGroup, int nDevice, boolean bStatus) { static char sReturn[13]; int nReturnPos = 0; - + if ( (byte)sFamily < 97 || (byte)sFamily > 112 || nGroup < 1 || nGroup > 4 || nDevice < 1 || nDevice > 4) { return '\0'; } - + char* sDeviceGroupCode = dec2binWzerofill( (nDevice-1) + (nGroup-1)*4, 4 ); char familycode[16][5] = { "0000", "F000", "0F00", "FF00", "00F0", "F0F0", "0FF0", "FFF0", "000F", "F00F", "0F0F", "FF0F", "00FF", "F0FF", "0FFF", "FFFF" }; for (int i = 0; i<4; i++) { @@ -290,7 +334,90 @@ char* RCSwitch::getCodeWordC(char sFamily, int nGroup, int nDevice, boolean bSta } /** - * Sends a Code Word + * Decoding for the REV Switch Type + * + * Returns a char[13], representing the Tristate to be send. + * A Code Word consists of 7 address bits and 5 command data bits. + * A Code Bit can have 3 different states: "F" (floating), "0" (low), "1" (high) + * + * +-------------------------------+--------------------------------+-----------------------+ + * | 4 bits address (switch group) | 3 bits address (device number) | 5 bits (command data) | + * | A=1FFF B=F1FF C=FF1F D=FFF1 | 1=0FFF 2=F0FF 3=FF0F 4=FFF0 | on=00010 off=00001 | + * +-------------------------------+--------------------------------+-----------------------+ + * + * Source: http://www.the-intruder.net/funksteckdosen-von-rev-uber-arduino-ansteuern/ + * + * @param sGroup Name of the switch group (A..D, resp. a..d) + * @param nDevice Number of the switch itself (1..3) + * @param bStatus Wether to switch on (true) or off (false) + * + * @return char[13] + */ + +char* RCSwitch::getCodeWordD(char sGroup, int nDevice, boolean bStatus){ + static char sReturn[13]; + int nReturnPos = 0; + + // Building 4 bits address + // (Potential problem if dec2binWcharfill not returning correct string) + char *sGroupCode; + switch(sGroup){ + case 'a': + case 'A': + sGroupCode = dec2binWcharfill(8, 4, 'F'); break; + case 'b': + case 'B': + sGroupCode = dec2binWcharfill(4, 4, 'F'); break; + case 'c': + case 'C': + sGroupCode = dec2binWcharfill(2, 4, 'F'); break; + case 'd': + case 'D': + sGroupCode = dec2binWcharfill(1, 4, 'F'); break; + default: + return '\0'; + } + + for (int i = 0; i<4; i++) + { + sReturn[nReturnPos++] = sGroupCode[i]; + } + + + // Building 3 bits address + // (Potential problem if dec2binWcharfill not returning correct string) + char *sDevice; + switch(nDevice) { + case 1: + sDevice = dec2binWcharfill(4, 3, 'F'); break; + case 2: + sDevice = dec2binWcharfill(2, 3, 'F'); break; + case 3: + sDevice = dec2binWcharfill(1, 3, 'F'); break; + default: + return '\0'; + } + + for (int i = 0; i<3; i++) + sReturn[nReturnPos++] = sDevice[i]; + + // fill up rest with zeros + for (int i = 0; i<5; i++) + sReturn[nReturnPos++] = '0'; + + // encode on or off + if (bStatus) + sReturn[10] = '1'; + else + sReturn[11] = '1'; + + // last position terminate string + sReturn[12] = '\0'; + return sReturn; + +} + +/** * @param sCodeWord /^[10FS]*$/ -> see getCodeWord */ void RCSwitch::sendTriState(char* sCodeWord) { @@ -310,7 +437,7 @@ void RCSwitch::sendTriState(char* sCodeWord) { } i++; } - this->sendSync(); + this->sendSync(); } } @@ -355,34 +482,40 @@ void RCSwitch::transmit(int nHighPulses, int nLowPulses) { } /** * Sends a "0" Bit - * _ + * _ * Waveform Protocol 1: | |___ - * _ + * _ * Waveform Protocol 2: | |__ */ void RCSwitch::send0() { - if (this->nProtocol == 1){ - this->transmit(1,3); - } - else if (this->nProtocol == 2) { - this->transmit(1,2); - } + if (this->nProtocol == 1){ + this->transmit(1,3); + } + else if (this->nProtocol == 2) { + this->transmit(1,2); + } + else if (this->nProtocol == 3) { + this->transmit(4,11); + } } /** * Sends a "1" Bit - * ___ + * ___ * Waveform Protocol 1: | |_ - * __ + * __ * Waveform Protocol 2: | |_ */ void RCSwitch::send1() { - if (this->nProtocol == 1){ - this->transmit(3,1); - } - else if (this->nProtocol == 2) { - this->transmit(2,1); - } + if (this->nProtocol == 1){ + this->transmit(3,1); + } + else if (this->nProtocol == 2) { + this->transmit(2,1); + } + else if (this->nProtocol == 3) { + this->transmit(9,6); + } } @@ -426,11 +559,14 @@ void RCSwitch::sendTF() { void RCSwitch::sendSync() { if (this->nProtocol == 1){ - this->transmit(1,31); - } - else if (this->nProtocol == 2) { - this->transmit(1,10); - } + this->transmit(1,31); + } + else if (this->nProtocol == 2) { + this->transmit(1,10); + } + else if (this->nProtocol == 3) { + this->transmit(1,71); + } } /** @@ -487,13 +623,13 @@ unsigned int* RCSwitch::getReceivedRawdata() { * */ bool RCSwitch::receiveProtocol1(unsigned int changeCount){ - - unsigned long code = 0; + + unsigned long code = 0; unsigned long delay = RCSwitch::timings[0] / 31; - unsigned long delayTolerance = delay * RCSwitch::nReceiveTolerance * 0.01; + unsigned long delayTolerance = delay * RCSwitch::nReceiveTolerance * 0.01; for (int i = 1; i delay-delayTolerance && RCSwitch::timings[i] < delay+delayTolerance && RCSwitch::timings[i+1] > delay*3-delayTolerance && RCSwitch::timings[i+1] < delay*3+delayTolerance) { code = code << 1; } 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) { @@ -504,32 +640,32 @@ bool RCSwitch::receiveProtocol1(unsigned int changeCount){ i = changeCount; code = 0; } - } + } code = code >> 1; if (changeCount > 6) { // ignore < 4bit values as there are no devices sending 4bit values => noise RCSwitch::nReceivedValue = code; RCSwitch::nReceivedBitlength = changeCount / 2; RCSwitch::nReceivedDelay = delay; - RCSwitch::nReceivedProtocol = 1; + RCSwitch::nReceivedProtocol = 1; } - if (code == 0){ - return false; - }else if (code != 0){ - return true; - } - + if (code == 0){ + return false; + }else if (code != 0){ + return true; + } + } bool RCSwitch::receiveProtocol2(unsigned int changeCount){ - - unsigned long code = 0; + + unsigned long code = 0; unsigned long delay = RCSwitch::timings[0] / 10; - unsigned long delayTolerance = delay * RCSwitch::nReceiveTolerance * 0.01; + unsigned long delayTolerance = delay * RCSwitch::nReceiveTolerance * 0.01; for (int i = 1; i delay-delayTolerance && RCSwitch::timings[i] < delay+delayTolerance && RCSwitch::timings[i+1] > delay*2-delayTolerance && RCSwitch::timings[i+1] < delay*2+delayTolerance) { code = code << 1; } 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) { @@ -540,32 +676,79 @@ bool RCSwitch::receiveProtocol2(unsigned int changeCount){ i = changeCount; code = 0; } - } + } code = code >> 1; if (changeCount > 6) { // ignore < 4bit values as there are no devices sending 4bit values => noise RCSwitch::nReceivedValue = code; RCSwitch::nReceivedBitlength = changeCount / 2; RCSwitch::nReceivedDelay = delay; - RCSwitch::nReceivedProtocol = 2; + RCSwitch::nReceivedProtocol = 2; } - if (code == 0){ - return false; - }else if (code != 0){ - return true; - } + if (code == 0){ + return false; + }else if (code != 0){ + return true; + } } +/** Protocol 3 is used by BL35P02. + * + */ +bool RCSwitch::receiveProtocol3(unsigned int changeCount){ + + unsigned long code = 0; + unsigned long delay = RCSwitch::timings[0] / PROTOCOL3_SYNC_FACTOR; + unsigned long delayTolerance = delay * RCSwitch::nReceiveTolerance * 0.01; + + for (int i = 1; i delay*PROTOCOL3_0_HIGH_CYCLES - delayTolerance + && RCSwitch::timings[i] < delay*PROTOCOL3_0_HIGH_CYCLES + delayTolerance + && RCSwitch::timings[i+1] > delay*PROTOCOL3_0_LOW_CYCLES - delayTolerance + && RCSwitch::timings[i+1] < delay*PROTOCOL3_0_LOW_CYCLES + delayTolerance) { + code = code << 1; + } else if (RCSwitch::timings[i] > delay*PROTOCOL3_1_HIGH_CYCLES - delayTolerance + && RCSwitch::timings[i] < delay*PROTOCOL3_1_HIGH_CYCLES + delayTolerance + && RCSwitch::timings[i+1] > delay*PROTOCOL3_1_LOW_CYCLES - delayTolerance + && RCSwitch::timings[i+1] < delay*PROTOCOL3_1_LOW_CYCLES + delayTolerance) { + code+=1; + code = code << 1; + } else { + // Failed + i = changeCount; + code = 0; + } + } + code = code >> 1; + if (changeCount > 6) { // ignore < 4bit values as there are no devices sending 4bit values => noise + RCSwitch::nReceivedValue = code; + RCSwitch::nReceivedBitlength = changeCount / 2; + RCSwitch::nReceivedDelay = delay; + RCSwitch::nReceivedProtocol = 3; + } + + if (code == 0){ + return false; + }else if (code != 0){ + return true; + } +} + /** * Turns a decimal value to its binary representation */ char* RCSwitch::dec2binWzerofill(unsigned long Dec, unsigned int bitLength){ + return dec2binWcharfill(Dec, bitLength, '0'); +} + +char* RCSwitch::dec2binWcharfill(unsigned long Dec, unsigned int bitLength, char fill){ static char bin[64]; unsigned int i=0; while (Dec > 0) { - bin[32+i++] = ((Dec & 1) > 0) ? '1' : '0'; + bin[32+i++] = ((Dec & 1) > 0) ? '1' : fill; Dec = Dec >> 1; } @@ -573,11 +756,10 @@ char* RCSwitch::dec2binWzerofill(unsigned long Dec, unsigned int bitLength){ if (j >= bitLength - i) { bin[j] = bin[ 31 + i - (j - (bitLength - i)) ]; }else { - bin[j] = '0'; + bin[j] = fill; } } bin[bitLength] = '\0'; - - return bin; -} + return bin; +} \ No newline at end of file diff --git a/RCSwitch.h b/RCSwitch.h index f762ebc..3e73411 100644 --- a/RCSwitch.h +++ b/RCSwitch.h @@ -1,6 +1,6 @@ /* RCSwitch - Arduino libary for remote control outlet switches - Copyright (c) 2011 Suat Özgür. All right reserved. + Copyright (c) 2011 Suat …zgŸr. All right reserved. Contributors: - Andre Koehler / info(at)tomate-online(dot)de @@ -50,6 +50,11 @@ typedef uint8_t byte; // We can handle up to (unsigned long) => 32 bit * 2 H/L changes per bit + 2 for sync #define RCSWITCH_MAX_CHANGES 67 +#define PROTOCOL3_SYNC_FACTOR 71 +#define PROTOCOL3_0_HIGH_CYCLES 4 +#define PROTOCOL3_0_LOW_CYCLES 11 +#define PROTOCOL3_1_HIGH_CYCLES 9 +#define PROTOCOL3_1_LOW_CYCLES 6 class RCSwitch { @@ -62,7 +67,11 @@ class RCSwitch { void switchOff(char* sGroup, int nSwitchNumber); void switchOn(char sFamily, int nGroup, int nDevice); void switchOff(char sFamily, int nGroup, int nDevice); - + void switchOn(char* sGroup, char* sDevice); + void switchOff(char* sGroup, char* sDevice); + void switchOn(char sGroup, int nDevice); + void switchOff(char sGroup, int nDevice); + void sendTriState(char* Code); void send(unsigned long Code, unsigned int length); void send(char* Code); @@ -71,12 +80,12 @@ class RCSwitch { void enableReceive(); void disableReceive(); bool available(); - void resetAvailable(); - + void resetAvailable(); + unsigned long getReceivedValue(); unsigned int getReceivedBitlength(); unsigned int getReceivedDelay(); - unsigned int getReceivedProtocol(); + unsigned int getReceivedProtocol(); unsigned int* getReceivedRawdata(); void enableTransmit(int nTransmitterPin); @@ -84,13 +93,15 @@ class RCSwitch { void setPulseLength(int nPulseLength); void setRepeatTransmit(int nRepeatTransmit); void setReceiveTolerance(int nPercent); - void setProtocol(int nProtocol); - void setProtocol(int nProtocol, int nPulseLength); + void setProtocol(int nProtocol); + void setProtocol(int nProtocol, int nPulseLength); private: char* getCodeWordB(int nGroupNumber, int nSwitchNumber, boolean bStatus); char* getCodeWordA(char* sGroup, int nSwitchNumber, boolean bStatus); + char* getCodeWordA(char* sGroup, char* sDevice, boolean bStatus); char* getCodeWordC(char sFamily, int nGroup, int nDevice, boolean bStatus); + char* getCodeWordD(char group, int nDevice, boolean bStatus); void sendT0(); void sendT1(); void sendTF(); @@ -100,24 +111,26 @@ class RCSwitch { void transmit(int nHighPulses, int nLowPulses); static char* dec2binWzerofill(unsigned long dec, unsigned int length); - + static char* dec2binWcharfill(unsigned long dec, unsigned int length, char fill); + static void handleInterrupt(); - static bool receiveProtocol1(unsigned int changeCount); - static bool receiveProtocol2(unsigned int changeCount); + static bool receiveProtocol1(unsigned int changeCount); + static bool receiveProtocol2(unsigned int changeCount); + static bool receiveProtocol3(unsigned int changeCount); int nReceiverInterrupt; int nTransmitterPin; int nPulseLength; int nRepeatTransmit; - char nProtocol; + char nProtocol; - static int nReceiveTolerance; + static int nReceiveTolerance; static unsigned long nReceivedValue; static unsigned int nReceivedBitlength; - static unsigned int nReceivedDelay; - static unsigned int nReceivedProtocol; + static unsigned int nReceivedDelay; + static unsigned int nReceivedProtocol; static unsigned int timings[RCSWITCH_MAX_CHANGES]; }; -#endif +#endif \ No newline at end of file diff --git a/sendRev.cpp b/sendRev.cpp new file mode 100644 index 0000000..8028651 --- /dev/null +++ b/sendRev.cpp @@ -0,0 +1,40 @@ +/* + Usage: ./send + Command is 0 for OFF and 1 for ON + */ + +#include "RCSwitch.h" +#include +#include + +int main(int argc, char *argv[]) { + + /* + output PIN is hardcoded for testing purposes + see https://projects.drogon.net/raspberry-pi/wiringpi/pins/ + for pin mapping of the raspberry pi GPIO connector + */ + int PIN = 0; + char* sGroup = argv[1]; + int nDevice = atoi(argv[2]); + int command = atoi(argv[3]); + + if (wiringPiSetup () == -1) return 1; + printf("sending sGroup[%s] nDevice[%i] command[%i]\n", sGroup, nDevice, command); + RCSwitch mySwitch = RCSwitch(); + mySwitch.enableTransmit(PIN); + //mySwitch.setPulseLength(360); + + switch(command) { + case 1: + mySwitch.switchOn(sGroup[0], nDevice); + break; + case 0: + mySwitch.switchOff(sGroup[0], nDevice); + break; + default: + printf("command[%i] is unsupported\n", command); + return -1; + } + return 0; +} diff --git a/sendTriState.cpp b/sendTriState.cpp new file mode 100644 index 0000000..9e9f702 --- /dev/null +++ b/sendTriState.cpp @@ -0,0 +1,29 @@ +/* + Usage: ./send + Command is 0 for OFF and 1 for ON + */ + +#include "RCSwitch.h" +#include +#include + +int main(int argc, char *argv[]) { + + /* + output PIN is hardcoded for testing purposes + see https://projects.drogon.net/raspberry-pi/wiringpi/pins/ + for pin mapping of the raspberry pi GPIO connector + */ + int PIN = 0; + char* tristate = argv[1]; + + if (wiringPiSetup () == -1) return 1; + printf("sending tristate[%s] \n", tristate); + RCSwitch mySwitch = RCSwitch(); + mySwitch.enableTransmit(PIN); + mySwitch.setPulseLength(360); + + mySwitch.sendTriState(tristate); + + return 0; +} diff --git a/startTest.sh b/startTest.sh new file mode 100755 index 0000000..983b840 --- /dev/null +++ b/startTest.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# +# + +#Rev Typ B: +#sudo ./sendTriState F1FF1FF00001 +sudo ./sendRev B 1 0 +sleep 1 +#sudo ./sendTriState F1FF1FF00010 +sudo ./sendRev B 1 1 +sleep 1 + +#sudo ./sendTriState F1FFF1F00001 +sudo ./sendRev B 2 0 +sleep 1 +#sudo ./sendTriState F1FFF1F00010 +sudo ./sendRev B 2 1 +sleep 1 + +#sudo ./sendTriState F1FFFF100001 +sudo ./sendRev B 3 0 +sleep 1 +#sudo ./sendTriState F1FFFF100010 +sudo ./sendRev B 3 1 +sleep 1 +