Skip to content

Commit

Permalink
Merge pull request ninjablocks#37 from hmueller01/master
Browse files Browse the repository at this point in the history
improved send command
  • Loading branch information
☃ Elliot Shepherd authored Jun 7, 2018
2 parents 0f969ef + f04653b commit 05a400e
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions RPi_utils/send.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,34 @@ 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" };

if (argc < 4) {
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;
}

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 (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 05a400e

Please sign in to comment.