Fri, 20 Jun 2014 17:42:36 +0200
Compiles with 1-wire bus on PC hardware
20
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | /***************************************************************************** |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | * Copyright (C) 2014 |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
3 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
4 | * Michiel Broek <mbroek at mbse dot eu> |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
5 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
6 | * This file is part of the mbsePi-apps |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
7 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
8 | * This is free software; you can redistribute it and/or modify it |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
9 | * under the terms of the GNU General Public License as published by the |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
10 | * Free Software Foundation; either version 2, or (at your option) any |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
11 | * later version. |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
12 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
13 | * mbsePi-apps is distributed in the hope that it will be useful, but |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
16 | * General Public License for more details. |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
17 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
18 | * You should have received a copy of the GNU General Public License |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
19 | * along with EC-65K; see the file COPYING. If not, write to the Free |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
20 | * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
21 | *****************************************************************************/ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
22 | |
58
e8e7b46b705b
Fixed compilation without wiringpi
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
23 | #include "rc433.h" |
20
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
24 | |
23
d820a6f3ec16
Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
25 | #ifdef HAVE_WIRINGPI_H |
22
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
26 | |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
27 | void help(void) |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
28 | { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
29 | fprintf(stdout, "mbsePi-apps send v%s\n\n", VERSION); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
30 | fprintf(stdout, "Usage: send [-t type ] [-f family ] [-g group ] [-d device] [-s state ] [-h]\n"); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
31 | fprintf(stdout, " send -t A -g 00001 -d 00001 -s 1\n"); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
32 | fprintf(stdout, " send -t B -g 2 -d 2 -s 0\n"); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
33 | fprintf(stdout, " send -t C -f c -g 3 -d 3 -s 1\n"); |
25
5e0695f6add5
Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
34 | fprintf(stdout, "\n"); |
5e0695f6add5
Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
35 | fprintf(stdout, " send -t E -g A -d 2 -s 0\n"); |
22
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
36 | } |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
37 | |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
38 | |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
39 | |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
40 | int isAcode(char *s) |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
41 | { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
42 | int i; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
43 | |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
44 | if (strlen(s) != 5) |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
45 | return FALSE; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
46 | for (i = 0; i < 5; i++) { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
47 | if ((s[i] < '0') || (s[i] > '1')) |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
48 | return FALSE; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
49 | } |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
50 | |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
51 | return TRUE; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
52 | } |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
53 | |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
54 | |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
55 | |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
56 | /* |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
57 | * A - char group, char device (2 x 5 binary) |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
58 | * B - int system, int unit |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
59 | * C - char family, int group, int device |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
60 | * D - char group, int device |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
61 | */ |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
62 | |
20
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
63 | int main(int argc, char *argv[]) { |
22
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
64 | char buf[127], *endptr; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
65 | int c; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
66 | char cType = '0', *sGroup = NULL, *sDevice = NULL, cFamily = '0', cGroup = '0'; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
67 | int iState = -1, iGroup = -1, iDevice = -1; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
68 | |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
69 | while (1) { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
70 | int option_index = 0; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
71 | static struct option long_options[] = { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
72 | {"device", 1, 0, 'd'}, |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
73 | {"family", 1, 0, 'f'}, |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
74 | {"group", 1, 0, 'g'}, |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
75 | {"help", 0, 0, 'h'}, |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
76 | {"state", 1, 0, 's'}, |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
77 | {"type", 1, 0, 't'}, |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
78 | {0, 0, 0, 0} |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
79 | }; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
80 | |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
81 | c = getopt_long(argc, argv, "d:f:g:hs:t:", long_options, &option_index); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
82 | if (c == -1) |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
83 | break; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
84 | |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
85 | switch (c) { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
86 | case 'd': snprintf(buf, 127, "%s", optarg); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
87 | if (cType == 'A') { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
88 | sDevice = xstrcpy(buf); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
89 | } else { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
90 | iDevice = strtol(buf, &endptr, 10); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
91 | } |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
92 | break; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
93 | case 'f': snprintf(buf, 127, "%s", optarg); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
94 | if (cType == 'C') { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
95 | cFamily = tolower(buf[0]); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
96 | } |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
97 | break; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
98 | case 'g': snprintf(buf, 127, "%s", optarg); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
99 | if (cType == 'A') { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
100 | sGroup = xstrcpy(buf); |
29
ac763b87ee25
Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents:
25
diff
changeset
|
101 | } else if (cType == 'E') { |
22
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
102 | cGroup = toupper(buf[0]); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
103 | } else { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
104 | iGroup = strtol(buf, &endptr, 10); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
105 | } |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
106 | break; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
107 | case 'h': help(); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
108 | return 1; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
109 | case 's': snprintf(buf, 127, "%s", optarg); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
110 | iState = strtol(buf, &endptr, 10); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
111 | break; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
112 | case 't': snprintf(buf, 127, "%s", optarg); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
113 | cType = toupper(buf[0]); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
114 | break; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
115 | } |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
116 | } |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
117 | |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
118 | /* |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
119 | * Check all option and combinations |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
120 | */ |
25
5e0695f6add5
Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
121 | if ((cType < 'A') || (cType > 'E')) { |
5e0695f6add5
Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
122 | fprintf(stderr, "Type must be A, B, C or E\n"); |
22
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
123 | return 1; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
124 | } |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
125 | if ((iState < 0) || (iState > 1)) { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
126 | fprintf(stderr, "State must be 0 or 1\n"); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
127 | return 1; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
128 | } |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
129 | if (cType == 'A') { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
130 | if (sGroup == NULL) { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
131 | fprintf(stderr, "Group not set\n"); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
132 | return 1; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
133 | } |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
134 | if (sDevice == NULL) { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
135 | fprintf(stderr, "Device not set\n"); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
136 | return 1; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
137 | } |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
138 | if (isAcode(sGroup) == FALSE) { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
139 | fprintf(stderr, "Group must be 5 binary digits like 10000\n"); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
140 | return 1; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
141 | } |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
142 | if (isAcode(sDevice) == FALSE) { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
143 | fprintf(stderr, "Device must be 5 binary digits like 10000\n"); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
144 | return 1; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
145 | } |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
146 | } else { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
147 | if (iDevice == -1) { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
148 | fprintf(stderr, "Device not set\n"); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
149 | return 1; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
150 | } |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
151 | } |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
152 | if ((cType == 'B') || (cType == 'C')) { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
153 | if (iGroup == -1) { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
154 | fprintf(stderr, "Group not set\n"); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
155 | return 1; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
156 | } |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
157 | if ((iGroup < 1) || (iGroup > 4)) { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
158 | fprintf(stderr, "Group must be 1..4\n"); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
159 | return 1; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
160 | } |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
161 | if ((iDevice < 1) || (iDevice > 4)) { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
162 | fprintf(stderr, "Device must be 1..4\n"); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
163 | return 1; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
164 | } |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
165 | } |
25
5e0695f6add5
Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
166 | if (cType == 'E') { |
22
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
167 | if ((iDevice < 1) || (iDevice > 3)) { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
168 | fprintf(stderr, "Device must be 1..3\n"); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
169 | return 1; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
170 | } |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
171 | if ((cGroup < 'A') || (cGroup > 'D')) { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
172 | fprintf(stderr, "Group must be A..D\n"); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
173 | return 1; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
174 | } |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
175 | } |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
176 | if (cType == 'C') { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
177 | if ((cFamily < 'a') || (cFamily > 'f')) { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
178 | fprintf(stderr, "Family must be a..f\n"); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
179 | return 1; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
180 | } |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
181 | } |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
182 | |
20
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
183 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
184 | output PIN is hardcoded for testing purposes |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
185 | see https://projects.drogon.net/raspberry-pi/wiringpi/pins/ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
186 | for pin mapping of the raspberry pi GPIO connector |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
187 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
188 | int PIN = 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
189 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
190 | if (wiringPiSetup () ) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
191 | return 1; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
192 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
193 | enableTransmit(PIN); |
22
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
194 | switch (cType) { |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
195 | case 'A': |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
196 | printf("Type A sending group[%s] device[%s] command[%d]\n", sGroup, sDevice, iState); |
25
5e0695f6add5
Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
197 | toggleTypeA(sGroup, sDevice, iState); |
22
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
198 | break; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
199 | case 'B': |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
200 | printf("Type B sending group[%d] device[%i] command[%i]\n", iGroup, iDevice, iState); |
25
5e0695f6add5
Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
201 | toggleTypeB(iGroup, iDevice, iState); |
22
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
202 | break; |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
203 | case 'C': |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
204 | printf("Type C sending family[%c] group[%d] device[%i] command[%i]\n", cFamily, iGroup, iDevice, iState); |
25
5e0695f6add5
Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
205 | toggleTypeC(cFamily, iGroup, iDevice, iState); |
22
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
206 | break; |
25
5e0695f6add5
Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
207 | case 'E': |
5e0695f6add5
Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
208 | printf("Type E sending group[%c] device[%i] command[%i]\n", cGroup, iDevice, iState); |
5e0695f6add5
Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
209 | toggleTypeE(cGroup, iDevice, iState); |
22
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
210 | break; |
20
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
211 | } |
22
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
212 | disableTransmit(); |
a3b058c67289
All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
213 | |
20
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
214 | return 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
215 | } |
23
d820a6f3ec16
Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
216 | |
d820a6f3ec16
Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
217 | #else |
d820a6f3ec16
Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
218 | |
d820a6f3ec16
Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
219 | int main(int argc, char *argv[]) { |
d820a6f3ec16
Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
220 | fprintf(stderr, "This program does nothing without the wiringPi library\n"); |
d820a6f3ec16
Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
221 | return 0; |
d820a6f3ec16
Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
222 | } |
d820a6f3ec16
Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
223 | |
d820a6f3ec16
Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
224 | #endif |
d820a6f3ec16
Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
225 |