thermferm/devices.c

changeset 685
819553a2b97e
parent 684
b2265c7e5707
child 687
f5d05b420732
equal deleted inserted replaced
684:b2265c7e5707 685:819553a2b97e
49 extern int SIMlight; 49 extern int SIMlight;
50 50
51 #endif 51 #endif
52 52
53 53
54 void devices_ws(void);
55
56
54 /* 57 /*
55 * Since kernel version 4 there is a module, and a dtoverlay so that the 58 * Since kernel version 4 there is a module, and a dtoverlay so that the
56 * temperature and humidity can simply read from the /sys filesystem. 59 * temperature and humidity can simply read from the /sys filesystem.
57 */ 60 */
58 int dht11_temperature = -1; 61 int dht11_temperature = -1;
285 disableTransmit(); 288 disableTransmit();
286 // pthread_mutex_lock(&mutexes[LOCK_DEVICES]); 289 // pthread_mutex_lock(&mutexes[LOCK_DEVICES]);
287 syslog(LOG_NOTICE, "RC433 command %s rc=%d", buf, rc); 290 syslog(LOG_NOTICE, "RC433 command %s rc=%d", buf, rc);
288 device->value = value; 291 device->value = value;
289 device->timestamp = time(NULL); 292 device->timestamp = time(NULL);
293 devices_ws();
290 // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); 294 // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]);
291 return rc; 295 return rc;
292 } 296 }
293 297
294 if ((device->type == DEVTYPE_GPIO) && (device->gpiopin != -1) && (device->present == DEVPRESENT_YES)) { 298 if ((device->type == DEVTYPE_GPIO) && (device->gpiopin != -1) && (device->present == DEVPRESENT_YES)) {
297 #endif 301 #endif
298 if ((device->type == DEVTYPE_W1) && (device->direction == DEVDIR_OUT_BIN) && (device->present == DEVPRESENT_YES)) { 302 if ((device->type == DEVTYPE_W1) && (device->direction == DEVDIR_OUT_BIN) && (device->present == DEVPRESENT_YES)) {
299 if (strncmp(device->address, (char *)"3a", 2) == 0) { 303 if (strncmp(device->address, (char *)"3a", 2) == 0) {
300 syslog(LOG_NOTICE, "DS2413 PIO%c value=%d (%s)", (device->subdevice == 0) ? 'A' : 'B', (value == 0) ? 0 : 1, device->comment); 304 syslog(LOG_NOTICE, "DS2413 PIO%c value=%d (%s)", (device->subdevice == 0) ? 'A' : 'B', (value == 0) ? 0 : 1, device->comment);
301 // pthread_mutex_lock(&mutexes[LOCK_DEVICES]); 305 // pthread_mutex_lock(&mutexes[LOCK_DEVICES]);
302 device->value = (value == 0) ? 0 : 1; 306 if (device->value != (value == 0) ? 0 : 1) {
303 device->timestamp = time(NULL); 307 device->value = (value == 0) ? 0 : 1;
308 device->timestamp = time(NULL);
309 devices_ws();
310 }
304 // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); 311 // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]);
305 } 312 }
306 } 313 }
307 314
308 #ifdef USE_SIMULATOR 315 #ifdef USE_SIMULATOR
309 if ((device->type == DEVTYPE_SIM) && (device->direction == DEVDIR_OUT_BIN) && (device->present == DEVPRESENT_YES)) { 316 if ((device->type == DEVTYPE_SIM) && (device->direction == DEVDIR_OUT_BIN) && (device->present == DEVPRESENT_YES)) {
310 if ((strcmp((char *)"SimCooler", device->address) == 0) || (strcmp((char *)"SimHeater", device->address) == 0) || 317 if ((strcmp((char *)"SimCooler", device->address) == 0) || (strcmp((char *)"SimHeater", device->address) == 0) ||
311 (strcmp((char *)"SimFan" , device->address) == 0) || (strcmp((char *)"SimLight" , device->address) == 0)) { 318 (strcmp((char *)"SimFan" , device->address) == 0) || (strcmp((char *)"SimLight" , device->address) == 0)) {
312 if (value != device->value) { 319 if (value != device->value) {
313 syslog(LOG_NOTICE, "SIM %s value=%d", device->address, value); 320 syslog(LOG_NOTICE, "SIM %s value=%d", device->address, value);
321 device->value = value;
322 device->timestamp = time(NULL);
323 if (strcmp((char *)"SimCooler", device->address) == 0)
324 SIMcooling = value;
325 if (strcmp((char *)"SimHeater", device->address) == 0)
326 SIMheating = value;
327 if (strcmp((char *)"SimFan", device->address) == 0)
328 SIMfan = value;
329 if (strcmp((char *)"SimLight", device->address) == 0)
330 SIMlight = value;
331 devices_ws();
314 } 332 }
315 device->value = value;
316 device->timestamp = time(NULL);
317 if (strcmp((char *)"SimCooler", device->address) == 0)
318 SIMcooling = value;
319 if (strcmp((char *)"SimHeater", device->address) == 0)
320 SIMheating = value;
321 if (strcmp((char *)"SimFan", device->address) == 0)
322 SIMfan = value;
323 if (strcmp((char *)"SimLight", device->address) == 0)
324 SIMlight = value;
325 } 333 }
326 } 334 }
327 #endif 335 #endif
328 } else { 336 } else {
329 // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); 337 // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]);

mercurial