diff -r 4703cc10b99a -r 32ed1ea4d0b6 lib/rc-switch.c --- a/lib/rc-switch.c Tue May 06 13:24:25 2014 +0200 +++ b/lib/rc-switch.c Tue May 06 21:37:06 2014 +0200 @@ -148,14 +148,54 @@ /* + * Toggle switch, a command looks like B,3,2,1 which means switch type B, + * group 3, device 2, status on. + */ +int toggleSwitch(char *command) +{ + static char *cmd = NULL; + char *s, cType; + int rc, iGroup, iDevice, iState; + + cmd = xstrcpy(command); + s = strtok(cmd, ",\0"); + cType = s[0]; + + if (cType == 'A') { + + } else if (cType == 'B') { + s = strtok(NULL, ",\0"); + rc = sscanf(s, "%d", &iGroup); + if (rc != 1) + return 1; + s = strtok(NULL, ",\0"); + rc = sscanf(s, "%d", &iDevice); + if (rc != 1) + return 1; + s = strtok(NULL, ",\0"); + rc = sscanf(s, "%d", &iState); + if (rc != 1) + return 1; + free(cmd); + return toggleTypeB(iGroup, iDevice, iState); + } + + free(cmd); + return 1; +} + + + +/* * Switch a remote switch on (Type E REV) * * @param sGroup Code of the switch group (A,B,C,D) * @param nDevice Number of the switch itself (1..3) * @param bStatus Status to toggle to */ -void toggleTypeE(char sGroup, int nDevice, bool bStatus) { +int toggleTypeE(char sGroup, int nDevice, bool bStatus) { sendTriState( getCodeWordE(sGroup, nDevice, bStatus) ); + return 0; } @@ -168,8 +208,9 @@ * @param nDevice Number of device (1..4) * @param bStatus Status to toggle to */ -void toggleTypeC(char sFamily, int nGroup, int nDevice, bool bStatus) { +int toggleTypeC(char sFamily, int nGroup, int nDevice, bool bStatus) { sendTriState( getCodeWordC(sFamily, nGroup, nDevice, bStatus) ); + return 0; } @@ -181,14 +222,18 @@ * @param iDevice Number of the switch itself (1..4) * @param bStatus Status to toggle to */ -void toggleTypeB(int iGroup, int iDevice, bool bStatus) +int toggleTypeB(int iGroup, int iDevice, bool bStatus) { char *str = xstrcpy(getCodeWordB(iGroup, iDevice, bStatus)); + if (strlen(str) == 0) + return 1; + // save(TYPE_B); sendTriState( str ); // load(); free(str); + return 0; } @@ -200,8 +245,9 @@ * @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") * @param bStatus Status to toggle to */ -void toggleTypeA(char* sGroup, char* sDevice, bool bStatus) { +int toggleTypeA(char* sGroup, char* sDevice, bool bStatus) { sendTriState( getCodeWordA(sGroup, sDevice, bStatus) ); + return 0; }