thermferm/thermferm.c

changeset 207
8d2ba4126519
parent 206
78fb6f99e473
child 209
c5b1dfd83e81
equal deleted inserted replaced
206:78fb6f99e473 207:8d2ba4126519
101 } 101 }
102 #endif 102 #endif
103 103
104 104
105 105
106 int read_w1_28(char *address, int *val) 106 int read_sensor(char *address, int *val)
107 { 107 {
108 devices_list *device; 108 devices_list *device;
109 int tmp; 109 int tmp;
110 110
111 for (device = Config.devices; device; device = device->next) { 111 for (device = Config.devices; device; device = device->next) {
362 tm = localtime(&now); 362 tm = localtime(&now);
363 lcd_buf_write(row++, " %02d-%02d-%04d ", tm->tm_mday, tm->tm_mon + 1, tm->tm_year + 1900); 363 lcd_buf_write(row++, " %02d-%02d-%04d ", tm->tm_mday, tm->tm_mon + 1, tm->tm_year + 1900);
364 lcd_buf_write(row++, " %02d:%02d:%02d ", tm->tm_hour, tm->tm_min, tm->tm_sec); 364 lcd_buf_write(row++, " %02d:%02d:%02d ", tm->tm_hour, tm->tm_min, tm->tm_sec);
365 #endif 365 #endif
366 366
367 if (Config.temp_address) {
368 rc = read_sensor(Config.temp_address, &temp);
369 if (rc == DEVPRESENT_YES) {
370 Config.temp_value = temp;
371 Config.temp_state = 0;
372 #ifdef HAVE_WIRINGPI_H
373 lcd_buf_write(row++, "Room temp %.1f %cC ", Config.temp_value / 1000.0, 0xdf);
374 #endif
375 } else if (rc == DEVPRESENT_ERROR) {
376 Config.temp_state = 1;
377 } else {
378 Config.temp_state = 2;
379 }
380 }
381
382 if (Config.hum_address) {
383 rc = read_sensor(Config.hum_address, &temp);
384 if (rc == DEVPRESENT_YES) {
385 Config.hum_value = temp;
386 Config.hum_state = 0;
387 #ifdef HAVE_WIRINGPI_H
388 lcd_buf_write(row++, " Humidity %.1f %% ", Config.hum_value / 1000.0, 0xdf);
389 #endif
390 } else if (rc == DEVPRESENT_ERROR) {
391 Config.hum_state = 1;
392 } else {
393 Config.hum_state = 2;
394 }
395 }
396
367 for (unit = Config.units; unit; unit = unit->next) { 397 for (unit = Config.units; unit; unit = unit->next) {
368 #ifdef HAVE_WIRINGPI_H 398 #ifdef HAVE_WIRINGPI_H
369 lcd_buf_write(row++, "Unit %s ", unit->name); 399 lcd_buf_write(row++, "Unit %s ", unit->name);
370 lcd_buf_write(row++, "Mode %s ", UNITMODE[unit->mode]); 400 lcd_buf_write(row++, "Mode %s ", UNITMODE[unit->mode]);
371 #endif 401 #endif
372 402
373 if (unit->air_address) { 403 if (unit->air_address) {
374 rc = read_w1_28(unit->air_address, &temp); 404 rc = read_sensor(unit->air_address, &temp);
375 if (rc == DEVPRESENT_YES) { 405 if (rc == DEVPRESENT_YES) {
376 /* 406 /*
377 * It is possible to have read errors or extreme values. 407 * It is possible to have read errors or extreme values.
378 * This can happen with bad connections so we compare the 408 * This can happen with bad connections so we compare the
379 * value with the previous one. If the difference is too 409 * value with the previous one. If the difference is too
401 unit->air_state = 2; 431 unit->air_state = 2;
402 } 432 }
403 } 433 }
404 434
405 if (unit->beer_address) { 435 if (unit->beer_address) {
406 rc = read_w1_28(unit->beer_address, &temp); 436 rc = read_sensor(unit->beer_address, &temp);
407 if (rc == DEVPRESENT_YES) { 437 if (rc == DEVPRESENT_YES) {
408 deviation = 40000; 438 deviation = 40000;
409 if ((unit->beer_temperature == 0) || 439 if ((unit->beer_temperature == 0) ||
410 (unit->beer_temperature && (temp > (int)unit->beer_temperature - deviation) && (temp < ((int)unit->beer_temperature + deviation)))) { 440 (unit->beer_temperature && (temp > (int)unit->beer_temperature - deviation) && (temp < ((int)unit->beer_temperature + deviation)))) {
411 unit->beer_temperature = temp; 441 unit->beer_temperature = temp;

mercurial