Skip to content

Commit

Permalink
made send more flexible to accept unitCode as number as well as bit c…
Browse files Browse the repository at this point in the history
…ode, added help output
  • Loading branch information
hmueller01 committed Mar 9, 2017
1 parent e29912d commit 76620e6
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions RPi_utils/send.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,33 @@ int main(int argc, char *argv[]) {
for pin mapping of the raspberry pi GPIO connector
*/
int PIN = 0;
const char* code[6] = { "00000", "10000", "01000", "00100", "00010", "00001" };

char* systemCode = argv[1];
int unitCode = atoi(argv[2]);
const char* unitCode;
if (strlen(argv[2]) == 5) {
unitCode = argv[2];
} else if (atoi(argv[2]) > 0 and atoi(argv[2]) < 6) {
unitCode = code[atoi(argv[2])];
} else {
return -1;
}
int command = atoi(argv[3]);

if (argv[1] == NULL) {
printf("Sending 433 MHz remote plug control codes, hardcoded on wiringpi pin %d.\n", PIN);
printf("Usage: %s <systemCode> <unitCode> <command> [pulseLength]\n", argv[0]);
printf("systemCode - First five settings of Type A 10 pole DIP switch, e.g. 11111\n");
printf("unitCode - Switch number [1 .. 5] or [10000 .. 00001]\n");
printf("command - 0 for OFF and 1 for ON\n");
printf("pulseLength - optional pulse length\n");
return -1;
}
if (wiringPiSetup () == -1) return 1;
printf("sending systemCode[%s] unitCode[%i] command[%i]\n", systemCode, unitCode, command);
printf("sending systemCode[%s] unitCode[%s] command[%i]\n", systemCode, unitCode, command);
RCSwitch mySwitch = RCSwitch();
if (argv[4] != NULL) mySwitch.setPulseLength(atoi(argv[4]));
if (argv[4] != NULL)
mySwitch.setPulseLength(atoi(argv[4]));
mySwitch.enableTransmit(PIN);

switch(command) {
Expand Down

0 comments on commit 76620e6

Please sign in to comment.