From ef2a29b68aa80cb01d89e36dc46450199a82dce7 Mon Sep 17 00:00:00 2001 From: Simon Hyde Date: Tue, 7 Nov 2023 09:43:41 +0000 Subject: [PATCH 1/2] Add support for remote 0x5 and 0xD The command codes seem to be different for every different remote number, and I can't spot the pattern used to generate them. This adds support for remotes 0x5 and 0xD, leaving the default at the old 0xB codes --- RFLink/Plugins/Plugin_016.c | 56 ++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/RFLink/Plugins/Plugin_016.c b/RFLink/Plugins/Plugin_016.c index ce9776ae..67b9bef8 100644 --- a/RFLink/Plugins/Plugin_016.c +++ b/RFLink/Plugins/Plugin_016.c @@ -12,8 +12,27 @@ const int SLVCR_BitCount = 24; const int8_t SLVCR_CodeCount = 8; -const uint16_t SLVCR_OnCodes[SLVCR_CodeCount] = {0xf756, 0x7441, 0xd9c5, 0xe3aa, 0x6af3, 0x453f, 0x0f6e, 0xc170}; -const uint16_t SLVCR_OffCodes[SLVCR_CodeCount] = {0x20e7, 0x5212, 0x9d88, 0x8c0b, 0x16bc, 0x3b99, 0xb8dd, 0xae24}; +//There are no buttons for which the first bit is high on these remotes, so just copy the first 4 values to the last 4 too... +const uint16_t SLVCR_OnCodes_D[SLVCR_CodeCount] = {0xcd63, 0xf7b4, 0xb4f7, 0x4ceb, 0xcd63, 0xf7b4, 0xb4f7, 0x4ceb}; +const uint16_t SLVCR_OffCodes_D[SLVCR_CodeCount] = {0xae81, 0x8159, 0x782a, 0x9292, 0xae81, 0x8159, 0x782a, 0x9292}; +const uint16_t SLVCR_OnCodes_5[SLVCR_CodeCount] = {0xfa1b, 0x3da3, 0x0254, 0x8c27, 0xfa1b, 0x3da3, 0x0254, 0x8c27}; +const uint16_t SLVCR_OffCodes_5[SLVCR_CodeCount] = {0x6e41, 0x1bb9, 0xa3fa, 0xc002, 0x6e41, 0x1bb9, 0xa3fa, 0xc002}; +//These codes are known to work with remote 0xB, and are the default +const uint16_t SLVCR_OnCodes_default[SLVCR_CodeCount] = {0xf756, 0x7441, 0xd9c5, 0xe3aa, 0x6af3, 0x453f, 0x0f6e, 0xc170}; +const uint16_t SLVCR_OffCodes_default[SLVCR_CodeCount] = {0x20e7, 0x5212, 0x9d88, 0x8c0b, 0x16bc, 0x3b99, 0xb8dd, 0xae24}; + +static const uint16_t * SLVCR_Codes(int remoteId, boolean bOn) +{ + switch(remoteId) + { + case 0xD: + return bOn? SLVCR_OnCodes_D: SLVCR_OffCodes_D; + case 0x5: + return bOn? SLVCR_OnCodes_5: SLVCR_OffCodes_5; + default: + return bOn? SLVCR_OnCodes_default: SLVCR_OffCodes_default; + } +} boolean Plugin_016(byte function, const char *string) { @@ -55,16 +74,18 @@ boolean Plugin_016(byte function, const char *string) return false; } - SerialDebugPrint(F(PLUGIN_016_ID ": packet = ")); - SerialDebugPrint(packet[0], 16); - SerialDebugPrint(packet[1], 16); - SerialDebugPrintln(packet[2], 16); + { + const size_t buflen = sizeof(PLUGIN_016_ID ": packet = ") + 7; + char printbuf[buflen]; + snprintf(printbuf, buflen, "%s%02x%02x%02x", PLUGIN_016_ID ": packet = ", packet[0], packet[1], packet[2]); + SerialDebugPrintln(printbuf); + } - // The button Id is in the second nibble of the last byte - uint8_t buttonId = packet[2] & 0x0F; + // The button Id is in the second nibble of the last byte + uint8_t buttonId = packet[2] & 0x0F; - SerialDebugPrint("buttonId ="); - SerialDebugPrintln(buttonId, 16); + SerialDebugPrint(PLUGIN_016_ID ": buttonId ="); + SerialDebugPrintln(buttonId, 16); // If button Id has bit 1 set, then invert the command enum CMD_OnOff effectiveCommandOn = CMD_On; @@ -81,11 +102,13 @@ boolean Plugin_016(byte function, const char *string) uint16_t commandBits = ((uint16_t)(packet[0] & 0x0F) << 12)| ((uint16_t)packet[1]) << 4 | (packet[2] & 0xF0) >> 4; //(packet >> 4) & 0xFFFF; enum CMD_OnOff command = CMD_Unknown; byte commandCodeIndex = 0; + const uint16_t* OnCodes = SLVCR_Codes(remoteId, 1); + const uint16_t* OffCodes = SLVCR_Codes(remoteId, 0); while (commandCodeIndex < SLVCR_CodeCount && command == CMD_Unknown) { - if (commandBits == SLVCR_OnCodes[commandCodeIndex]) + if (commandBits == OnCodes[commandCodeIndex]) command = effectiveCommandOn; - else if (commandBits == SLVCR_OffCodes[commandCodeIndex]) + else if (commandBits == OffCodes[commandCodeIndex]) command = effectiveCommandOff; commandCodeIndex++; @@ -171,12 +194,13 @@ boolean PluginTX_016(byte function, const char *string) uint16_t commandCode = 0; byte codeIndex = 1 << ((buttonId & 0x1) << 1); // one of the first 4, or one of the last four, depending on the first bit of the buttonId - const uint16_t* OnCommandArray = SLVCR_OnCodes; - const uint16_t* OffCommandArray = SLVCR_OffCodes; + const uint16_t* OnCommandArray = SLVCR_Codes(remoteId, 1); + const uint16_t* OffCommandArray = SLVCR_Codes(remoteId, 0); if (buttonId & 2) // invert if second bit is set { - OnCommandArray = SLVCR_OffCodes; - OffCommandArray = SLVCR_OnCodes; + const uint16_t* tmp = OnCommandArray; + OnCommandArray = OffCommandArray; + OffCommandArray = tmp; } switch(buttonCommand) From 88e207e137b04ec2d0f80745d850e117a796c819 Mon Sep 17 00:00:00 2001 From: Simon Hyde Date: Tue, 7 Nov 2023 12:52:13 +0000 Subject: [PATCH 2/2] retrieve_Switch accept values from display_SWITCH display_SWITCH prints with %02X, so retrieve_Switch ought to accept values made of 2 nibbles too, so make retrieve_Switch call retrieve_byte --- RFLink/4_Display.cpp | 2 +- RFLink/4_Display.h | 2 +- RFLink/Plugins/Plugin_004.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/RFLink/4_Display.cpp b/RFLink/4_Display.cpp index fa629f7a..3916cce8 100644 --- a/RFLink/4_Display.cpp +++ b/RFLink/4_Display.cpp @@ -512,7 +512,7 @@ boolean retrieve_ID(unsigned long &ul_ID) boolean retrieve_Switch(byte &b_Switch) { - return retrieve_nibble(b_Switch, "SWITCH="); + return retrieve_byte(b_Switch, "SWITCH="); } boolean retrieve_Command(byte &b_Cmd) diff --git a/RFLink/4_Display.h b/RFLink/4_Display.h index 42e6e762..0adef1a8 100644 --- a/RFLink/4_Display.h +++ b/RFLink/4_Display.h @@ -106,7 +106,7 @@ boolean retrieve_byte(byte &, const char* = NULL); // calls retrieve_hexNumber( boolean retrieve_nibble(byte &, const char* = NULL); // calls retrieve_hexNumber(, 1, ) boolean retrieve_ID(unsigned long &); // calls retrieve_long(, "ID=") and limits the value to 0x03FFFFFF (26 bits) -boolean retrieve_Switch(byte &); // calls retrieve_nibble(, "SWITCH=") +boolean retrieve_Switch(byte &); // calls retrieve_byte(, "SWITCH=") boolean retrieve_Command(byte &); // calls retrieve_command(, "CMD=") boolean retrieve_End(); // returns true if the token "pointer" is at the end of the input string diff --git a/RFLink/Plugins/Plugin_004.c b/RFLink/Plugins/Plugin_004.c index 78204fc2..1e501699 100644 --- a/RFLink/Plugins/Plugin_004.c +++ b/RFLink/Plugins/Plugin_004.c @@ -198,7 +198,7 @@ boolean PluginTX_004(byte function, const char *string) bitstream = (ID_bitstream << 6); // 26 bits on top - bitstream |= Switch_bitstream; // Complete transmitted address + bitstream |= Switch_bitstream & 0xF; // Complete transmitted address // bitstream &= 0xFFFFFFCF; // Bit 4 and 5 are left for cmd bitstream |= (Cmd_bitstream << 4);