Skip to content

Commit

Permalink
Turned specific some Plugin TX 004 code into generic "retrieve_XXX" f…
Browse files Browse the repository at this point in the history
…uncs
  • Loading branch information
couin3 committed Apr 25, 2020
1 parent 2264d22 commit 9862c03
Show file tree
Hide file tree
Showing 3 changed files with 241 additions and 184 deletions.
190 changes: 180 additions & 10 deletions RFLink/4_Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// ************************************* //

#include <Arduino.h>
#include "3_Serial.h"
#include "4_Display.h"

byte PKSequenceNumber = 0; // 1 byte packet counter
Expand Down Expand Up @@ -335,6 +336,175 @@ void display_RGBW(unsigned int input)
strcat(pbuffer, dbuffer);
}

// --------------------- //
// get label shared func //
// --------------------- //

char *ptr;
const char c_delim[2] = ";";
char c_label[10];

boolean retrieve_Init10()
{
// 10
ptr = strtok(InputBuffer_Serial, c_delim);
if (ptr != NULL)
{
if (strncasecmp(ptr, "10", strlen("10")) != 0)
return false;
return true;
}
else
return false;
}

boolean retrieve_Name(const char *c_Name)
{
// Newkaku
ptr = strtok(NULL, c_delim);
if (ptr != NULL)
{
if (strncasecmp(ptr, c_Name, strlen(c_Name)) != 0)
return false;
return true;
}
else
return false;
}

boolean retrieve_ID(unsigned long &ul_ID)
{
// ID
char c_ID[10];

ptr = strtok(NULL, c_delim);
if (ptr != NULL)
{
strcpy(c_label, "ID=");
if (strncasecmp(ptr, c_label, strlen(c_label)) == 0)
ptr += strlen(c_label);

if (strlen(ptr) > 8)
return false;

for (byte i = 0; i < strlen(ptr); i++)
if (!isxdigit(ptr[i]))
return false;

strcpy(c_ID, ptr);
c_ID[8] = 0;

ul_ID = strtoul(c_ID, NULL, HEX);
ul_ID &= 0x03FFFFFF;

return true;
}
else
return false;
}

boolean retrieve_Switch(byte &b_Switch)
{
// Switch
char c_Switch[10];

ptr = strtok(NULL, c_delim);
if (ptr != NULL)
{
strcpy(c_label, "SWITCH=");
if (strncasecmp(ptr, c_label, strlen(c_label)) == 0)
ptr += strlen(c_label);

if (strlen(ptr) > 1)
return false;

for (byte i = 0; i < strlen(ptr); i++)
if (!isxdigit(ptr[i]))
return false;

strcpy(c_Switch, ptr);

b_Switch = (byte)strtoul(c_Switch, NULL, HEX);
b_Switch--; // 1 to 16 -> 0 to 15 (displayed value is one more)
if (b_Switch > 0xF)
return false; // invalid address

return true;
}
else
return false;
}

boolean retrieve_Command(byte &b_Cmd, byte &b_Cmd2)
{
// Command
char c_Cmd[10];

ptr = strtok(NULL, c_delim);
if (ptr != NULL)
{
strcpy(c_label, "SET_LEVEL=");
if (strncasecmp(ptr, c_label, strlen(c_label)) == 0)
ptr += strlen(c_label);

strcpy(c_label, "CMD=");
if (strncasecmp(ptr, c_label, strlen(c_label)) == 0)
ptr += strlen(c_label);

if (strlen(ptr) > 7)
return false;

for (byte i = 0; i < strlen(ptr); i++)
if (!isalnum(ptr[i]))
return false;

strcpy(c_Cmd, ptr);

b_Cmd2 = str2cmd(c_Cmd); // Get ON/OFF etc. command
if (b_Cmd2 == false) // Not a valid command received? ON/OFF/ALLON/ALLOFF
b_Cmd2 = (byte)strtoul(c_Cmd, NULL, HEX);
// ON
switch (b_Cmd2)
{
case VALUE_ON:
case VALUE_ALLON:
b_Cmd |= B01;
break;
}
// Group
switch (b_Cmd2)
{
case VALUE_ALLON:
case VALUE_ALLOFF:
b_Cmd |= B10;
break;
}
// Dimmer
switch (b_Cmd2)
{
case VALUE_ON:
case VALUE_OFF:
case VALUE_ALLON:
case VALUE_ALLOFF:
b_Cmd2 = 0xFF;
break;
}

return true;
}
else
return false;
}

boolean retrieve_End()
{
// End
ptr = strtok(NULL, c_delim);
if (ptr != NULL)
return false;
return true;
}

/*********************************************************************************************\
Convert string to command code
\*********************************************************************************************/
Expand Down Expand Up @@ -367,13 +537,13 @@ int str2cmd(char *command)
return false;
}

void replacechar(char *str, char orig, char rep)
{
char *ix = str;
int n = 0;
while ((ix = strchr(ix, orig)) != NULL)
{
*ix++ = rep;
n++;
}
}
// void replacechar(char *str, char orig, char rep)
// {
// char *ix = str;
// int n = 0;
// while ((ix = strchr(ix, orig)) != NULL)
// {
// *ix++ = rep;
// n++;
// }
// }
66 changes: 48 additions & 18 deletions RFLink/4_Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,27 @@ void display_IDn(unsigned int, byte);
void display_IDc(const char *);
void display_SWITCH(byte);
void display_SWITCHc(const char *);
enum CMD_Group {CMD_Single, CMD_All};
enum CMD_OnOff {CMD_Off, CMD_On, CMD_Bright, CMD_Dim, CMD_Unknown};
enum CMD_Group
{
CMD_Single,
CMD_All
};
enum CMD_OnOff
{
CMD_Off,
CMD_On,
CMD_Bright,
CMD_Dim,
CMD_Unknown
};
void display_CMD(boolean, byte);
void display_SET_LEVEL(byte);
void display_TEMP(unsigned int);
enum HUM_Type {HUM_HEX, HUM_BCD};
enum HUM_Type
{
HUM_HEX,
HUM_BCD
};
void display_HUM(byte, boolean);
void display_BARO(unsigned int);
void display_HSTATUS(byte);
Expand All @@ -44,9 +59,17 @@ void display_WINDIR(unsigned int);
void display_WINCHL(unsigned int);
void display_WINTMP(unsigned int);
void display_CHIME(unsigned int);
enum SMOKE_OnOff {SMOKE_Off, SMOKE_On};
enum SMOKE_OnOff
{
SMOKE_Off,
SMOKE_On
};
void display_SMOKEALERT(boolean);
enum PIR_OnOff {PIR_Off, PIR_On};
enum PIR_OnOff
{
PIR_Off,
PIR_On
};
void display_PIR(boolean);
void display_CO2(unsigned int);
void display_SOUND(unsigned int);
Expand All @@ -58,20 +81,27 @@ void display_METER(unsigned int);
void display_VOLT(unsigned int);
void display_RGBW(unsigned int);

#define VALUE_PAIR 44
#define VALUE_ALLOFF 55
#define VALUE_OFF 74
#define VALUE_ON 75
#define VALUE_DIM 76
#define VALUE_BRIGHT 77
#define VALUE_UP 78
#define VALUE_DOWN 79
#define VALUE_STOP 80
#define VALUE_CONFIRM 81
#define VALUE_LIMIT 82
#define VALUE_ALLON 141
boolean retrieve_Init10();
boolean retrieve_Name(const char *);
boolean retrieve_ID(unsigned long &);
boolean retrieve_Switch(byte &);
boolean retrieve_Command(byte &, byte &);
boolean retrieve_End();

#define VALUE_PAIR 44
#define VALUE_ALLOFF 55
#define VALUE_OFF 74
#define VALUE_ON 75
#define VALUE_DIM 76
#define VALUE_BRIGHT 77
#define VALUE_UP 78
#define VALUE_DOWN 79
#define VALUE_STOP 80
#define VALUE_CONFIRM 81
#define VALUE_LIMIT 82
#define VALUE_ALLON 141

int str2cmd(char *);
void replacechar(char *, char, char);
// void replacechar(char *, char, char);

#endif
Loading

0 comments on commit 9862c03

Please sign in to comment.