thermferm/devices.c

changeset 323
608592f74b10
parent 268
dda91dfa4aa8
child 324
940a668e568f
equal deleted inserted replaced
322:1dc57faf5ab5 323:608592f74b10
164 164
165 165
166 int device_out(char *uuid, int value) 166 int device_out(char *uuid, int value)
167 { 167 {
168 devices_list *device; 168 devices_list *device;
169 time_t now; 169 time_t now, my_timestamp;
170 int my_value;
170 #ifdef HAVE_WIRINGPI_H 171 #ifdef HAVE_WIRINGPI_H
171 int i, rc; 172 int i, rc;
172 char buf[40]; 173 char buf[40];
173 #endif 174 #endif
174 175
182 /* 183 /*
183 * Execute command if different then the old value. But also 184 * Execute command if different then the old value. But also
184 * every 2 minutes because commands can have temporary 185 * every 2 minutes because commands can have temporary
185 * disconnects, or have radio problems. 186 * disconnects, or have radio problems.
186 */ 187 */
187 if ((value != device->value) || (((int)now - (int)device->timestamp) > 120)) { 188 #ifdef HAVE_WIRINGPI_H
189 piLock(LOCK_DEVICES);
190 #endif
191 my_timestamp = device->timestamp;
192 my_value = device->value;
193 #ifdef HAVE_WIRINGPI_H
194 piUnlock(LOCK_DEVICES);
195 #endif
196 if ((value != my_value) || (((int)now - (int)my_timestamp) > 120)) {
188 197
189 #ifdef HAVE_WIRINGPI_H 198 #ifdef HAVE_WIRINGPI_H
190 rc = 0; 199 rc = 0;
191 if ((device->type == DEVTYPE_RC433) && (device->gpiopin != -1) && (device->present == DEVPRESENT_YES)) { 200 if ((device->type == DEVTYPE_RC433) && (device->gpiopin != -1) && (device->present == DEVPRESENT_YES)) {
192 snprintf(buf, 39, "%s,%d", device->address, value ? 1:0); 201 snprintf(buf, 39, "%s,%d", device->address, value ? 1:0);

mercurial