88 my_shutdown = TRUE; |
88 my_shutdown = TRUE; |
89 } |
89 } |
90 |
90 |
91 |
91 |
92 |
92 |
|
93 #ifdef HAVE_WIRINGPI_H |
93 void show_mode(void) |
94 void show_mode(void) |
94 { |
95 { |
95 char buf[21]; |
96 char buf[21]; |
96 |
97 |
97 snprintf(buf, 20, "Old mode %s", UNITMODE[current_unit->mode]); |
98 snprintf(buf, 20, "Old mode %s", UNITMODE[current_unit->mode]); |
|
99 piLock(LOCK_LCD); |
98 lcdPuts(lcdHandle, buf); |
100 lcdPuts(lcdHandle, buf); |
99 lcdPosition(lcdHandle, 0, 1); |
101 lcdPosition(lcdHandle, 0, 1); |
|
102 piUnlock(LOCK_LCD); |
100 } |
103 } |
101 |
104 |
102 |
105 |
103 |
106 |
104 #ifdef HAVE_WIRINGPI_H |
|
105 void go_menu(int menu) |
107 void go_menu(int menu) |
106 { |
108 { |
107 char buf[21]; |
109 char buf[21]; |
108 |
110 |
|
111 piLock(LOCK_LCD); |
109 lcdClear(lcdHandle); |
112 lcdClear(lcdHandle); |
110 lcdPosition(lcdHandle, 0, 0); |
113 lcdPosition(lcdHandle, 0, 0); |
|
114 piUnlock(LOCK_LCD); |
111 setupmenu = menu; |
115 setupmenu = menu; |
112 |
116 |
113 switch (menu) { |
117 switch (menu) { |
114 case MENU_NONE: lcd_buf_show(); |
118 case MENU_NONE: lcd_buf_show(); |
115 break; |
119 break; |
480 } |
486 } |
481 } |
487 } |
482 |
488 |
483 |
489 |
484 #ifdef HAVE_WIRINGPI_H |
490 #ifdef HAVE_WIRINGPI_H |
|
491 piLock(LOCK_LCD); |
485 lcd_buf_write(1, (char *)" ThermFerm "); |
492 lcd_buf_write(1, (char *)" ThermFerm "); |
486 lcd_buf_write(2, (char *)" Version %s ", VERSION); |
493 lcd_buf_write(2, (char *)" Version %s ", VERSION); |
|
494 piUnlock(LOCK_LCD); |
487 #endif |
495 #endif |
488 |
496 |
489 for (unit = Config.units; unit; unit = unit->next) { |
497 for (unit = Config.units; unit; unit = unit->next) { |
490 if (unit->mode != UNITMODE_OFF) { |
498 if (unit->mode != UNITMODE_OFF) { |
491 initlog(unit->name); |
499 initlog(unit->name); |
505 seconds++; |
513 seconds++; |
506 |
514 |
507 #ifdef HAVE_WIRINGPI_H |
515 #ifdef HAVE_WIRINGPI_H |
508 row = 3; |
516 row = 3; |
509 tm = localtime(&now); |
517 tm = localtime(&now); |
|
518 piLock(LOCK_LCD); |
510 lcd_buf_write(row++, " %02d-%02d-%04d ", tm->tm_mday, tm->tm_mon + 1, tm->tm_year + 1900); |
519 lcd_buf_write(row++, " %02d-%02d-%04d ", tm->tm_mday, tm->tm_mon + 1, tm->tm_year + 1900); |
511 lcd_buf_write(row++, " %02d:%02d:%02d ", tm->tm_hour, tm->tm_min, tm->tm_sec); |
520 lcd_buf_write(row++, " %02d:%02d:%02d ", tm->tm_hour, tm->tm_min, tm->tm_sec); |
|
521 piUnlock(LOCK_LCD); |
512 #endif |
522 #endif |
513 |
523 |
514 if (Config.temp_address) { |
524 if (Config.temp_address) { |
515 rc = read_sensor(Config.temp_address, &temp); |
525 rc = read_sensor(Config.temp_address, &temp); |
516 if (rc == DEVPRESENT_YES) { |
526 if (rc == DEVPRESENT_YES) { |
517 Config.temp_value = temp; |
527 Config.temp_value = temp; |
518 Config.temp_state = 0; |
528 Config.temp_state = 0; |
519 #ifdef HAVE_WIRINGPI_H |
529 #ifdef HAVE_WIRINGPI_H |
|
530 piLock(LOCK_LCD); |
520 lcd_buf_write(row++, "Room temp %.1f %cC ", Config.temp_value / 1000.0, 0xdf); |
531 lcd_buf_write(row++, "Room temp %.1f %cC ", Config.temp_value / 1000.0, 0xdf); |
|
532 piUnlock(LOCK_LCD); |
521 #endif |
533 #endif |
522 } else if (rc == DEVPRESENT_ERROR) { |
534 } else if (rc == DEVPRESENT_ERROR) { |
523 Config.temp_state = 1; |
535 Config.temp_state = 1; |
524 } else { |
536 } else { |
525 Config.temp_state = 2; |
537 Config.temp_state = 2; |
530 rc = read_sensor(Config.hum_address, &temp); |
542 rc = read_sensor(Config.hum_address, &temp); |
531 if (rc == DEVPRESENT_YES) { |
543 if (rc == DEVPRESENT_YES) { |
532 Config.hum_value = temp; |
544 Config.hum_value = temp; |
533 Config.hum_state = 0; |
545 Config.hum_state = 0; |
534 #ifdef HAVE_WIRINGPI_H |
546 #ifdef HAVE_WIRINGPI_H |
|
547 piLock(LOCK_LCD); |
535 lcd_buf_write(row++, " Humidity %.1f %% ", Config.hum_value / 1000.0, 0xdf); |
548 lcd_buf_write(row++, " Humidity %.1f %% ", Config.hum_value / 1000.0, 0xdf); |
|
549 piUnlock(LOCK_LCD); |
536 #endif |
550 #endif |
537 } else if (rc == DEVPRESENT_ERROR) { |
551 } else if (rc == DEVPRESENT_ERROR) { |
538 Config.hum_state = 1; |
552 Config.hum_state = 1; |
539 } else { |
553 } else { |
540 Config.hum_state = 2; |
554 Config.hum_state = 2; |
541 } |
555 } |
542 } |
556 } |
543 |
557 |
544 for (unit = Config.units; unit; unit = unit->next) { |
558 for (unit = Config.units; unit; unit = unit->next) { |
545 #ifdef HAVE_WIRINGPI_H |
559 #ifdef HAVE_WIRINGPI_H |
|
560 piLock(LOCK_LCD); |
546 lcd_buf_write(row++, "Unit %s ", unit->name); |
561 lcd_buf_write(row++, "Unit %s ", unit->name); |
547 lcd_buf_write(row++, "Mode %s ", UNITMODE[unit->mode]); |
562 lcd_buf_write(row++, "Mode %s ", UNITMODE[unit->mode]); |
|
563 piUnlock(LOCK_LCD); |
548 #endif |
564 #endif |
549 |
565 |
550 if (unit->air_address) { |
566 if (unit->air_address) { |
551 rc = read_sensor(unit->air_address, &temp); |
567 rc = read_sensor(unit->air_address, &temp); |
552 if (rc == DEVPRESENT_YES) { |
568 if (rc == DEVPRESENT_YES) { |
562 if ((unit->air_temperature == 0) || |
578 if ((unit->air_temperature == 0) || |
563 (unit->air_temperature && (temp > (int)unit->air_temperature - deviation) && (temp < ((int)unit->air_temperature + deviation)))) { |
579 (unit->air_temperature && (temp > (int)unit->air_temperature - deviation) && (temp < ((int)unit->air_temperature + deviation)))) { |
564 unit->air_temperature = temp; |
580 unit->air_temperature = temp; |
565 unit->air_state = 0; |
581 unit->air_state = 0; |
566 #ifdef HAVE_WIRINGPI_H |
582 #ifdef HAVE_WIRINGPI_H |
|
583 piLock(LOCK_LCD); |
567 lcd_buf_write(row++, " Air %.3f %cC ", unit->air_temperature / 1000.0, 0xdf); |
584 lcd_buf_write(row++, " Air %.3f %cC ", unit->air_temperature / 1000.0, 0xdf); |
|
585 piUnlock(LOCK_LCD); |
568 #endif |
586 #endif |
569 } else { |
587 } else { |
570 syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->air_temperature, temp); |
588 syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->air_temperature, temp); |
571 if (debug) { |
589 if (debug) { |
572 fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->air_temperature, temp); |
590 fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->air_temperature, temp); |
586 if ((unit->beer_temperature == 0) || |
604 if ((unit->beer_temperature == 0) || |
587 (unit->beer_temperature && (temp > (int)unit->beer_temperature - deviation) && (temp < ((int)unit->beer_temperature + deviation)))) { |
605 (unit->beer_temperature && (temp > (int)unit->beer_temperature - deviation) && (temp < ((int)unit->beer_temperature + deviation)))) { |
588 unit->beer_temperature = temp; |
606 unit->beer_temperature = temp; |
589 unit->beer_state = 0; |
607 unit->beer_state = 0; |
590 #ifdef HAVE_WIRINGPI_H |
608 #ifdef HAVE_WIRINGPI_H |
|
609 piLock(LOCK_LCD); |
591 lcd_buf_write(row++, "Beer %.3f %cC ", unit->beer_temperature / 1000.0, 0xdf); |
610 lcd_buf_write(row++, "Beer %.3f %cC ", unit->beer_temperature / 1000.0, 0xdf); |
|
611 piUnlock(LOCK_LCD); |
592 #endif |
612 #endif |
593 } else { |
613 } else { |
594 syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->beer_temperature, temp); |
614 syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->beer_temperature, temp); |
595 if (debug) { |
615 if (debug) { |
596 fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->beer_temperature, temp); |
616 fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->beer_temperature, temp); |
710 device_out(unit->cooler_address, unit->cooler_state); |
730 device_out(unit->cooler_address, unit->cooler_state); |
711 device_out(unit->fan_address, unit->fan_state); |
731 device_out(unit->fan_address, unit->fan_state); |
712 } |
732 } |
713 #ifdef HAVE_WIRINGPI_H |
733 #ifdef HAVE_WIRINGPI_H |
714 if (unit->heater_address && unit->cooler_address) { |
734 if (unit->heater_address && unit->cooler_address) { |
715 if (unit->heater_state) |
735 piLock(LOCK_LCD); |
|
736 if (unit->heater_state) { |
716 lcd_buf_write(row++, "Heater On "); |
737 lcd_buf_write(row++, "Heater On "); |
717 else if (unit->cooler_state) |
738 } else if (unit->cooler_state) { |
718 lcd_buf_write(row++, "Cooler On "); |
739 lcd_buf_write(row++, "Cooler On "); |
719 else |
740 } else { |
720 lcd_buf_write(row++, "Standby "); |
741 lcd_buf_write(row++, "Standby "); |
|
742 } |
|
743 piUnlock(LOCK_LCD); |
|
744 piLock(LOCK_LCD); |
721 switch (unit->mode) { |
745 switch (unit->mode) { |
722 case UNITMODE_BEER: lcd_buf_write(row++, "Target %.1f %cC ", unit->beer_set, 0xdf); |
746 case UNITMODE_BEER: lcd_buf_write(row++, "Target %.1f %cC ", unit->beer_set, 0xdf); |
723 break; |
747 break; |
724 case UNITMODE_FRIDGE: lcd_buf_write(row++, "Target %.1f %cC ", unit->fridge_set, 0xdf); |
748 case UNITMODE_FRIDGE: lcd_buf_write(row++, "Target %.1f %cC ", unit->fridge_set, 0xdf); |
725 break; |
749 break; |
728 else |
752 else |
729 lcd_buf_write(row++, "Target not set "); |
753 lcd_buf_write(row++, "Target not set "); |
730 break; |
754 break; |
731 default: lcd_buf_write(row++, "Target not set "); |
755 default: lcd_buf_write(row++, "Target not set "); |
732 } |
756 } |
|
757 piUnlock(LOCK_LCD); |
733 } else { |
758 } else { |
|
759 piLock(LOCK_LCD); |
734 if (unit->heater_address) { |
760 if (unit->heater_address) { |
735 lcd_buf_write(row++, "Heat %s ", unit->heater_state ? "On ":"Off"); |
761 lcd_buf_write(row++, "Heat %s ", unit->heater_state ? "On ":"Off"); |
736 } |
762 } |
737 if (unit->cooler_address) { |
763 if (unit->cooler_address) { |
738 lcd_buf_write(row++, "Cool %s ", unit->cooler_state ? "On ":"Off"); |
764 lcd_buf_write(row++, "Cool %s ", unit->cooler_state ? "On ":"Off"); |
739 } |
765 } |
|
766 piUnlock(LOCK_LCD); |
740 } |
767 } |
741 #endif |
768 #endif |
742 } |
769 } |
743 |
770 |
744 piddelay++; |
771 piddelay++; |
940 if (key == KEY_DOWN) { |
970 if (key == KEY_DOWN) { |
941 for (unit = Config.units; unit; unit = unit->next) { |
971 for (unit = Config.units; unit; unit = unit->next) { |
942 if (strcmp(unit->uuid, current_unit->uuid) == 0) { /* Current unit */ |
972 if (strcmp(unit->uuid, current_unit->uuid) == 0) { /* Current unit */ |
943 if (unit->next) { /* Is there a next */ |
973 if (unit->next) { /* Is there a next */ |
944 unit = unit->next; /* Select that */ |
974 unit = unit->next; /* Select that */ |
|
975 piLock(LOCK_LCD); |
945 lcdPosition(lcdHandle, 0, 1); |
976 lcdPosition(lcdHandle, 0, 1); |
946 lcdPuts(lcdHandle, Config.units->name); |
977 lcdPuts(lcdHandle, Config.units->name); |
|
978 piUnlock(LOCK_LCD); |
947 } |
979 } |
948 } |
980 } |
949 } |
981 } |
950 } |
982 } |
951 if (key == KEY_ENTER) { |
983 if (key == KEY_ENTER) { |