From b07b121f053afc9f41957694cd05b85707208851 Mon Sep 17 00:00:00 2001 From: ksmith3036 <44052735+ksmith3036@users.noreply.github.com> Date: Sat, 16 Jan 2021 20:01:24 +0100 Subject: [PATCH 1/3] Added support for Nexa/Proove simple (not self-learning), Hyttevokteren and Everspring B002R remote controls. --- RCSwitch.cpp | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++-- RCSwitch.h | 3 ++ 2 files changed, 86 insertions(+), 2 deletions(-) diff --git a/RCSwitch.cpp b/RCSwitch.cpp index 6c821cb..edda163 100644 --- a/RCSwitch.cpp +++ b/RCSwitch.cpp @@ -15,6 +15,7 @@ - Vlad Gheorghe / .(at)gmail(dot)com https://github.com/vgheo - Matias Cuenca-Acuna + - Kaare Smith / https://github.com/ksmith3036 Project home: https://github.com/sui77/rc-switch/ This library is free software; you can redistribute it and/or @@ -192,6 +193,26 @@ void RCSwitch::disableTransmit() { this->nTransmitterPin = -1; } +/** + * Switch a remote switch on (Nexa/Proove simple (not self-learning), Hyttevokteren, Everspring B002R) + * + * @param nSwitchNumber Switch 1 - 16 + * @param sHomeCode Home code A - P + */ +void RCSwitch::switchOn(int nSwitchNumber, char sHomeCode) { + this->sendTriState(this->getCodeWordE(sHomeCode, nSwitchNumber, true)); +} + +/** + * Switch a remote switch off (Nexa/Proove simple (not self-learning), Hyttevokteren, Everspring B002R) + * + * @param nSwitchNumber Switch 1 - 16 + * @param sHomeCode Home code A - P + */ +void RCSwitch::switchOff(int nSwitchNumber, char sHomeCode) { + this->sendTriState(this->getCodeWordE(sHomeCode, nSwitchNumber, false)); +} + /** * Switch a remote switch on (Type D REV) * @@ -213,7 +234,7 @@ void RCSwitch::switchOff(char sGroup, int nDevice) { } /** - * Switch a remote switch on (Type C Intertechno) + * Switch a remote switch on (Type C Intertechno and Nexa self-learning) * * @param sFamily Familycode (a..f) * @param nGroup Number of group (1..4) @@ -224,7 +245,7 @@ void RCSwitch::switchOn(char sFamily, int nGroup, int nDevice) { } /** - * Switch a remote switch off (Type C Intertechno) + * Switch a remote switch off (Type C Intertechno and Nexa self-learning) * * @param sFamily Familycode (a..f) * @param nGroup Number of group (1..4) @@ -447,6 +468,66 @@ char* RCSwitch::getCodeWordD(char sGroup, int nDevice, bool bStatus) { return sReturn; } +/** + * Returns a char[13], representing the Code Word to be send. + * A Code Word consists of 8 address bits, 2 data bits and one sync bit but in our case only the first 8 address bits and the last 2 data bits were used. + * A Code Bit can have 4 different states: "F" (floating), "0" (low), "1" (high), "S" (synchronous bit) + * + * +-----------------------------+---------------------------------+-----------------------------------------+----------------------+------------+ + * | 4 bits address (home code) | 4 bits address (switch number) | 2 bit unknown (not used, so never mind) | 2 data bits (on|off) | 1 sync bit | + * | A=0000 B=F000 C=0F00 D=FF00 | 1=0000 2=F000 3=0F00 4=FF00 | FF | on=FF off=F0 | S | + * | E=00F0 F=F0F0 G=0FF0 H=FFF0 | 5=00F0 6=F0F0 7=0FF0 8=FFF0 | | | | + * | I=000F J=F00F K=0F0F L=FF0F | 9=000F 10=F00F 11=0F0F 12=FF0F | | | | + * | M=00FF N=F0FF O=0FFF P=FFFF | 13=00FF 14=F0FF 15=0FFF 16=FFFF | | | | + * +-----------------------------+---------------------------------+-----------------------------------------+----------------------+------------+ + * + * @param sHomeCode Number of the switch group (A..P) + * @param nChannelCode Number of the switch itself (1..16) + * @param bStatus Wether to switch on (true) or off (false) + * + * @return char[13] + */ +char* RCSwitch::getCodeWordE(char sHomeCode, int nChannelCode, bool bStatus) { + int nReturnPos = 0; + static char sReturn[13]; + int nAddressCode; + if (sHomeCode >= 'a') { + nAddressCode = (sHomeCode - 'a') + 1; + } + else { + nAddressCode = (sHomeCode - 'A') + 1; + } + + // Map 16 values into tri-state codes. Used both for sHomeCode and nChannelCode + char* code[16] = { "0000", "F000", "0F00", "FF00", "00F0", "F0F0", "0FF0", "FFF0", "000F", "F00F", "0F0F", "FF0F", "00FF", "F0FF", "0FFF", "FFFF" }; + + if (nAddressCode < 1 || nAddressCode > 16 || nChannelCode < 1 || nChannelCode > 16) { + return nullptr; + } + for (int i = 0; i < 4; i++) { + sReturn[nReturnPos++] = code[nAddressCode - 1][i]; + } + + for (int i = 0; i < 4; i++) { + sReturn[nReturnPos++] = code[nChannelCode - 1][i]; + } + + sReturn[nReturnPos++] = 'F'; + sReturn[nReturnPos++] = 'F'; + sReturn[nReturnPos++] = 'F'; + + if (bStatus) { + sReturn[nReturnPos++] = 'F'; + } + else { + sReturn[nReturnPos++] = '0'; + } + + sReturn[nReturnPos] = '\0'; + + return sReturn; +} + /** * @param sCodeWord a tristate code word consisting of the letter 0, 1, F */ diff --git a/RCSwitch.h b/RCSwitch.h index b7755e0..efbed5f 100644 --- a/RCSwitch.h +++ b/RCSwitch.h @@ -75,6 +75,8 @@ class RCSwitch { void switchOff(const char* sGroup, const char* sDevice); void switchOn(char sGroup, int nDevice); void switchOff(char sGroup, int nDevice); + void switchOn(int nSwitchNumber, char sHomeCode); + void switchOff(int nSwitchNumber, char sHomeCode); void sendTriState(const char* sCodeWord); void send(unsigned long code, unsigned int length); @@ -153,6 +155,7 @@ class RCSwitch { char* getCodeWordB(int nGroupNumber, int nSwitchNumber, bool bStatus); char* getCodeWordC(char sFamily, int nGroup, int nDevice, bool bStatus); char* getCodeWordD(char group, int nDevice, bool bStatus); + char* getCodeWordE(char sHomeCode, int nChannelCode, bool bStatus); void transmit(HighLow pulses); #if not defined( RCSwitchDisableReceiving ) From 7dd698af334d5af63d3ca124f25c4bbe72a92976 Mon Sep 17 00:00:00 2001 From: ksmith3036 <44052735+ksmith3036@users.noreply.github.com> Date: Sat, 16 Jan 2021 20:01:54 +0100 Subject: [PATCH 2/3] Added example for Hyttevokteren control --- examples/Hyttevokteren/Hyttevokteren.ino | 76 ++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 examples/Hyttevokteren/Hyttevokteren.ino diff --git a/examples/Hyttevokteren/Hyttevokteren.ino b/examples/Hyttevokteren/Hyttevokteren.ino new file mode 100644 index 0000000..8650399 --- /dev/null +++ b/examples/Hyttevokteren/Hyttevokteren.ino @@ -0,0 +1,76 @@ +/* + Example for Hyttevokteren outlets. + + Created by: Kåre Smith, https://github.com/ksmith3036 +*/ + +#include + +RCSwitch mySwitch = RCSwitch(); + +void flash() { + for (int i = 0; i < 5; i++) { + digitalWrite(LED_BUILTIN, HIGH); + delay(100); + digitalWrite(LED_BUILTIN, LOW); + delay(100); + } +} + +void setup() { + + Serial.begin(115200); + while (!Serial); + + // Receiver is connected to Arduino Pin #0 + int recvInterupt = digitalPinToInterrupt(0); + Serial.print("Recv int: "); + Serial.println(recvInterupt); + + // Transmitter is connected to Arduino Pin #7 + mySwitch.enableTransmit(7); + mySwitch.setProtocol(1); // Hyttevokter kontakt og hyttrevokter fjernkontroll + mySwitch.setPulseLength(250); // Hyttevokter kontakt + //mySwitch.setPulseLength(316); // Hyttevokter remote control B002R + + + pinMode(LED_BUILTIN, OUTPUT); + + delay(2000); + Serial.println(); + Serial.print("on or off? "); +} + + +void loop() { + + // Switch on/off: + // The first parameter represents the switch number + // The second parameter represents the familycode (a, b, c, ... f) + + static int lastKey = LOW; + static bool setOn = false; + + if (Serial) { + if (Serial.available()) { + String key = Serial.readString(); + key.trim(); + + setOn = key == "on"; + flash(); + if (setOn) { + Serial.print("set on ..."); + digitalWrite(LED_BUILTIN, HIGH); + mySwitch.switchOn(4, 'G'); + digitalWrite(LED_BUILTIN, HIGH); + } + else { + Serial.print("off ..."); + digitalWrite(LED_BUILTIN, LOW); + mySwitch.switchOff(4, 'G'); + digitalWrite(LED_BUILTIN, LOW); + } + Serial.print("\non or off? "); + } + } +} From e0b0effa0e2d44d417770b00e7fec0569864c9d3 Mon Sep 17 00:00:00 2001 From: K Smith <44052735+ksmith3036@users.noreply.github.com> Date: Sat, 16 Jan 2021 23:04:08 +0100 Subject: [PATCH 3/3] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f6a679c..bfc455f 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ or more devices with one of the supported chipsets: - EV1527 / RT1527 / FP1527 / HS1527 - Intertechno outlets - HT6P20X + - Hyttevokteren, Everspring B002R, old Nexa/Proove ### Receive and decode RC codes