brewco/devices.c

changeset 436
4df9ae3095f8
parent 435
4b1ed6897d80
child 438
7d1ec160d751
equal deleted inserted replaced
435:4b1ed6897d80 436:4df9ae3095f8
21 *****************************************************************************/ 21 *****************************************************************************/
22 22
23 #include "brewco.h" 23 #include "brewco.h"
24 #include "devices.h" 24 #include "devices.h"
25 #include "xutil.h" 25 #include "xutil.h"
26 #include "keyboard.h"
26 27
27 28
28 extern int debug; 29 extern int debug;
29 extern sys_config Config; 30 extern sys_config Config;
30 extern int my_shutdown; 31 extern int my_shutdown;
134 int device_out(char *uuid, int value) 135 int device_out(char *uuid, int value)
135 { 136 {
136 devices_list *device; 137 devices_list *device;
137 time_t now, my_timestamp; 138 time_t now, my_timestamp;
138 int rc, my_value, test_value; 139 int rc, my_value, test_value;
139 #ifdef HAVE_WIRINGPI_H
140 int i;
141 char buf[40];
142 #endif
143 140
144 if (uuid == NULL) 141 if (uuid == NULL)
145 return 0; 142 return 0;
146 143
147 now = time(NULL); 144 now = time(NULL);
168 165
169 if ((test_value != my_value) || (((int)now - (int)my_timestamp) >= 120)) { 166 if ((test_value != my_value) || (((int)now - (int)my_timestamp) >= 120)) {
170 167
171 #ifdef HAVE_WIRINGPI_H 168 #ifdef HAVE_WIRINGPI_H
172 rc = 0; 169 rc = 0;
173 if ((device->type == DEVTYPE_RC433) && (device->gpiopin != -1) && (device->present == DEVPRESENT_YES)) {
174 snprintf(buf, 39, "%s,%d", device->address, value ? 1:0);
175 for (i = 0; i < strlen(buf); i++)
176 if (buf[i] == '-')
177 buf[i] = ',';
178 piUnlock(LOCK_DEVICES);
179 enableTransmit(device->gpiopin);
180 rc = toggleSwitch(buf);
181 disableTransmit();
182 piLock(LOCK_DEVICES);
183 syslog(LOG_NOTICE, "RC433 command %s rc=%d", buf, rc);
184 if (debug)
185 fprintf(stdout, "RC433 command %s rc=%d\n", buf, rc);
186 device->value = value;
187 device->timestamp = time(NULL);
188 piUnlock(LOCK_DEVICES);
189 return rc;
190 }
191
192 if ((device->type == DEVTYPE_GPIO) && (device->gpiopin != -1) && (device->present == DEVPRESENT_YES)) { 170 if ((device->type == DEVTYPE_GPIO) && (device->gpiopin != -1) && (device->present == DEVPRESENT_YES)) {
193 171
194 } 172 }
195 #endif 173 #endif
196 if ((device->type == DEVTYPE_W1) && (device->direction == DEVDIR_OUT_BIN) && (device->present == DEVPRESENT_YES)) { 174 if ((device->type == DEVTYPE_W1) && (device->direction == DEVDIR_OUT_BIN) && (device->present == DEVPRESENT_YES)) {
591 simulator_list *simulator; 569 simulator_list *simulator;
592 #endif 570 #endif
593 char *addr = NULL, line[60], *p = NULL; 571 char *addr = NULL, line[60], *p = NULL;
594 FILE *fp; 572 FILE *fp;
595 int temp, rc; 573 int temp, rc;
596 #ifdef HAVE_WIRINGPI_H
597 time_t now;
598 #endif
599 574
600 syslog(LOG_NOTICE, "Thread my_devices_loop started"); 575 syslog(LOG_NOTICE, "Thread my_devices_loop started");
601 576
602 #ifdef HAVE_WIRINGPI_H 577 #ifdef HAVE_WIRINGPI_H
603 if ((rc = piHiPri(10))) 578 if ((rc = piHiPri(10)))

mercurial