lib/rc-switch.c

changeset 28
32ed1ea4d0b6
parent 25
5e0695f6add5
child 29
ac763b87ee25
equal deleted inserted replaced
27:4703cc10b99a 28:32ed1ea4d0b6
146 } 146 }
147 147
148 148
149 149
150 /* 150 /*
151 * Toggle switch, a command looks like B,3,2,1 which means switch type B,
152 * group 3, device 2, status on.
153 */
154 int toggleSwitch(char *command)
155 {
156 static char *cmd = NULL;
157 char *s, cType;
158 int rc, iGroup, iDevice, iState;
159
160 cmd = xstrcpy(command);
161 s = strtok(cmd, ",\0");
162 cType = s[0];
163
164 if (cType == 'A') {
165
166 } else if (cType == 'B') {
167 s = strtok(NULL, ",\0");
168 rc = sscanf(s, "%d", &iGroup);
169 if (rc != 1)
170 return 1;
171 s = strtok(NULL, ",\0");
172 rc = sscanf(s, "%d", &iDevice);
173 if (rc != 1)
174 return 1;
175 s = strtok(NULL, ",\0");
176 rc = sscanf(s, "%d", &iState);
177 if (rc != 1)
178 return 1;
179 free(cmd);
180 return toggleTypeB(iGroup, iDevice, iState);
181 }
182
183 free(cmd);
184 return 1;
185 }
186
187
188
189 /*
151 * Switch a remote switch on (Type E REV) 190 * Switch a remote switch on (Type E REV)
152 * 191 *
153 * @param sGroup Code of the switch group (A,B,C,D) 192 * @param sGroup Code of the switch group (A,B,C,D)
154 * @param nDevice Number of the switch itself (1..3) 193 * @param nDevice Number of the switch itself (1..3)
155 * @param bStatus Status to toggle to 194 * @param bStatus Status to toggle to
156 */ 195 */
157 void toggleTypeE(char sGroup, int nDevice, bool bStatus) { 196 int toggleTypeE(char sGroup, int nDevice, bool bStatus) {
158 sendTriState( getCodeWordE(sGroup, nDevice, bStatus) ); 197 sendTriState( getCodeWordE(sGroup, nDevice, bStatus) );
198 return 0;
159 } 199 }
160 200
161 201
162 202
163 /* 203 /*
166 * @param sFamily Familycode (a..f) 206 * @param sFamily Familycode (a..f)
167 * @param nGroup Number of group (1..4) 207 * @param nGroup Number of group (1..4)
168 * @param nDevice Number of device (1..4) 208 * @param nDevice Number of device (1..4)
169 * @param bStatus Status to toggle to 209 * @param bStatus Status to toggle to
170 */ 210 */
171 void toggleTypeC(char sFamily, int nGroup, int nDevice, bool bStatus) { 211 int toggleTypeC(char sFamily, int nGroup, int nDevice, bool bStatus) {
172 sendTriState( getCodeWordC(sFamily, nGroup, nDevice, bStatus) ); 212 sendTriState( getCodeWordC(sFamily, nGroup, nDevice, bStatus) );
213 return 0;
173 } 214 }
174 215
175 216
176 217
177 /* 218 /*
179 * 220 *
180 * @param iGroup Number of the switch group (1..4) 221 * @param iGroup Number of the switch group (1..4)
181 * @param iDevice Number of the switch itself (1..4) 222 * @param iDevice Number of the switch itself (1..4)
182 * @param bStatus Status to toggle to 223 * @param bStatus Status to toggle to
183 */ 224 */
184 void toggleTypeB(int iGroup, int iDevice, bool bStatus) 225 int toggleTypeB(int iGroup, int iDevice, bool bStatus)
185 { 226 {
186 char *str = xstrcpy(getCodeWordB(iGroup, iDevice, bStatus)); 227 char *str = xstrcpy(getCodeWordB(iGroup, iDevice, bStatus));
228
229 if (strlen(str) == 0)
230 return 1;
187 231
188 // save(TYPE_B); 232 // save(TYPE_B);
189 sendTriState( str ); 233 sendTriState( str );
190 // load(); 234 // load();
191 free(str); 235 free(str);
236 return 0;
192 } 237 }
193 238
194 239
195 240
196 /* 241 /*
198 * 243 *
199 * @param sGroup Code of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111") 244 * @param sGroup Code of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111")
200 * @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") 245 * @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")
201 * @param bStatus Status to toggle to 246 * @param bStatus Status to toggle to
202 */ 247 */
203 void toggleTypeA(char* sGroup, char* sDevice, bool bStatus) { 248 int toggleTypeA(char* sGroup, char* sDevice, bool bStatus) {
204 sendTriState( getCodeWordA(sGroup, sDevice, bStatus) ); 249 sendTriState( getCodeWordA(sGroup, sDevice, bStatus) );
250 return 0;
205 } 251 }
206 252
207 253
208 254
209 /* 255 /*

mercurial