Skip to content

Commit

Permalink
Merge pull request #95 from simonhyde/silvercrest-extra-remotes
Browse files Browse the repository at this point in the history
Add support for extra SilverCrest remotes/sockets
  • Loading branch information
cpainchaud authored Nov 8, 2023
2 parents 5c95681 + 88e207e commit 14b9023
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 19 deletions.
2 changes: 1 addition & 1 deletion RFLink/4_Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion RFLink/4_Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion RFLink/Plugins/Plugin_004.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
56 changes: 40 additions & 16 deletions RFLink/Plugins/Plugin_016.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand All @@ -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++;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 14b9023

Please sign in to comment.