diff --git a/RPi_utils/send.cpp b/RPi_utils/send.cpp index a291051..575f27e 100644 --- a/RPi_utils/send.cpp +++ b/RPi_utils/send.cpp @@ -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 [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) {