forked from r10r/rcswitch-pi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
send.cpp
126 lines (115 loc) · 3.7 KB
/
send.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
Usage: see printUsage()
*/
#include "RCSwitch.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
void printUsage()
{
std::cout << "Usage for Type A with 10 pole DIP switches \n";
std::cout << " Syntax: sudo ./send <groupCode> <nChannelCode> <command>\n";
std::cout << " sGroup Code of the switch group (refers to DIP switches 1..5\n";
std::cout << " where '1' = on and '0' = off, if all DIP switches\n";
std::cout << " nChannelCode Number of the switch itself (1..4)\n";
std::cout << " command 0 for OFF and 1 for ON\n";
std::cout << " Example: sudo ./send 01011 3 1\n";
std::cout << "\n";
std::cout << "Usage for Type B with two rotary/sliding switches \n";
std::cout << " Syntax: sudo ./send <nAddressCode> <nChannelCode> <command>\n";
std::cout << " nAddressCode Number of the switch group (1..4)\n";
std::cout << " nChannelCode Number of the switch itself (1..4)\n";
std::cout << " command 0 for OFF and 1 for ON\n";
std::cout << " Example: sudo ./send 2 3 1\n";
std::cout << "\n";
std::cout << "Usage for Type C Intertechno \n";
std::cout << " Syntax: sudo ./send <sFamily> <nGroup> <nDevice> <command>\n";
std::cout << " sFamily Familycode (a..f)\n";
std::cout << " nGroup Number of group (1..4)\n";
std::cout << " nDevice Number of device (1..4)\n";
std::cout << " command 0 for OFF and 1 for ON\n";
std::cout << " Example: sudo ./send b 3 1 1\n";
std::cout << "\n";
std::cout << "\n";
std::cout << "See http://code.google.com/p/rc-switch/wiki/HowTo_OperateLowCostOutlets for more information about supported switches\n";
}
int main(int argc, char *argv[]) {
/*
output PIN is hardcoded for testing purposes
see https://projects.drogon.net/raspberry-pi/wiringpi/pins/
for pin mapping of the raspberry pi GPIO connector
*/
int PIN = 3;
if (wiringPiSetup () == -1) return 1;
RCSwitch mySwitch = RCSwitch();
mySwitch.enableTransmit(PIN);
if(argc == 4)
{
char* sGroup = argv[1];
int nSwitchNumber = atoi(argv[2]);
int command = atoi(argv[3]);
if(strlen(sGroup) > 2)
{
//Type A: 10 pole DIP switches
printf("sending [Type A] groupCode[%s] nChannelCode[%i] command[%i]\n", sGroup, nSwitchNumber, command);
switch(command) {
case 1:
mySwitch.switchOn(sGroup, nSwitchNumber);
break;
case 0:
mySwitch.switchOff(sGroup, nSwitchNumber);
break;
default:
printf("command[%i] is unsupported\n", command);
printUsage();
return -1;
}
return 0;
} else {
//Type B: Two rotary/sliding switches
int nGroupNumber = atoi(sGroup);
printf("sending [Type B] nAddressCode[%i] nChannelCode[%i] command[%i]\n", nGroupNumber, nSwitchNumber, command);
switch(command) {
case 1:
mySwitch.switchOn(nGroupNumber, nSwitchNumber);
break;
case 0:
mySwitch.switchOff(nGroupNumber, nSwitchNumber);
break;
default:
printf("command[%i] is unsupported\n", command);
printUsage();
return -1;
}
return 0;
}
}
else if(argc == 5)
{
//Type C: Intertechno
char* sFamily = argv[1];
int nGroup = atoi(argv[2]);
int nDevice = atoi(argv[3]);
int command = atoi(argv[4]);
printf("sending [Type C] sFamily[%s] nGroup[%i] nDevice[%i] command[%i]\n", sFamily, nGroup, nDevice, command);
switch(command) {
case 1:
mySwitch.switchOn(sFamily[0], nGroup, nDevice);
break;
case 0:
mySwitch.switchOff(sFamily[0], nGroup, nDevice);
break;
default:
printf("command[%i] is unsupported\n", command);
printUsage();
return -1;
}
return 0;
}
else
{
printUsage();
}
return 1;
}