thermferm/thermferm.c

changeset 418
0bfe08c7ba6e
parent 406
44566f986f76
child 420
644a6106d712
equal deleted inserted replaced
417:9943f49fdb98 418:0bfe08c7ba6e
40 int run_pause = FALSE; 40 int run_pause = FALSE;
41 int run_hold = FALSE; 41 int run_hold = FALSE;
42 42
43 extern int debug; 43 extern int debug;
44 extern sys_config Config; 44 extern sys_config Config;
45 #ifdef HAVE_WIRINGPI_H
46 extern int lcdHandle; 45 extern int lcdHandle;
47 int setupmenu = MENU_NONE; 46 int setupmenu = MENU_NONE;
48 units_list *current_unit = NULL; /* In panel editor this points to the current unit. */ 47 units_list *current_unit = NULL; /* In panel editor this points to the current unit. */
49 profiles_list *current_profile = NULL; 48 profiles_list *current_profile = NULL;
50 float temp_temp = 20.0; 49 float temp_temp = 20.0;
51 #endif
52 50
53 #ifndef HAVE_WIRINGPI_H 51 #ifndef HAVE_WIRINGPI_H
54 pthread_t threads[5]; 52 pthread_t threads[5];
55 #endif 53 #endif
56 extern const char UNITMODE[5][8]; 54 extern const char UNITMODE[5][8];
58 56
59 57
60 int server(void); 58 int server(void);
61 void help(void); 59 void help(void);
62 void die(int); 60 void die(int);
61 void stopLCD(void);
63 #ifdef HAVE_WIRINGPI_H 62 #ifdef HAVE_WIRINGPI_H
64 void sendRCswitch(char *, int); 63 void sendRCswitch(char *, int);
65 void stopLCD(void);
66 void stopRCswitch(void); 64 void stopRCswitch(void);
67 #endif 65 #endif
68 66
69 67
70 68
97 my_shutdown = TRUE; 95 my_shutdown = TRUE;
98 } 96 }
99 97
100 98
101 99
102 #ifdef HAVE_WIRINGPI_H
103 void show_mode(void) 100 void show_mode(void)
104 { 101 {
105 char buf[21]; 102 char buf[21];
106 103
107 snprintf(buf, 20, "Old mode %s", UNITMODE[current_unit->mode]); 104 snprintf(buf, 20, "Old mode %s", UNITMODE[current_unit->mode]);
105 #ifdef HAVE_WIRINGPI_H
108 lcdPuts(lcdHandle, buf); 106 lcdPuts(lcdHandle, buf);
109 lcdPosition(lcdHandle, 0, 1); 107 lcdPosition(lcdHandle, 0, 1);
108 #endif
110 } 109 }
111 110
112 111
113 112
114 void go_menu(int menu) 113 void go_menu(int menu)
115 { 114 {
116 char buf[21]; 115 char buf[21];
117 116
117 #ifdef HAVE_WIRINGPI_H
118 piLock(LOCK_LCD); 118 piLock(LOCK_LCD);
119 piLock(LOCK_MENU); 119 piLock(LOCK_MENU);
120 lcdClear(lcdHandle); 120 lcdClear(lcdHandle);
121 lcdPosition(lcdHandle, 0, 0); 121 lcdPosition(lcdHandle, 0, 0);
122 #endif
122 syslog(LOG_NOTICE, "from menu %d to menu %d", setupmenu, menu); 123 syslog(LOG_NOTICE, "from menu %d to menu %d", setupmenu, menu);
123 setupmenu = menu; 124 setupmenu = menu;
124 125
125 switch (menu) { 126 switch (menu) {
126 case MENU_NONE: lcd_buf_show(); 127 case MENU_NONE:
128 #ifdef HAVE_WIRINGPI_H
129 lcd_buf_show();
130 #endif
127 break; 131 break;
128 132
129 case MENU_TOP_DEFAULT: lcdPuts(lcdHandle, "Setup mode."); 133 case MENU_TOP_DEFAULT:
134 #ifdef HAVE_WIRINGPI_H
135 lcdPuts(lcdHandle, "Setup mode.");
130 lcdPosition(lcdHandle, 0, 1); 136 lcdPosition(lcdHandle, 0, 1);
131 lcdPuts(lcdHandle, "Up&Down = Escape"); 137 lcdPuts(lcdHandle, "Up&Down = Escape");
138 #endif
132 break; 139 break;
133 140
134 case MENU_TOP_UNITS: lcdPuts(lcdHandle, "Select units"); 141 case MENU_TOP_UNITS:
142 #ifdef HAVE_WIRINGPI_H
143 lcdPuts(lcdHandle, "Select units");
144 #endif
135 break; 145 break;
136 146
137 case MENU_UNITS: lcdPuts(lcdHandle, "Choose unit:"); 147 case MENU_UNITS:
148 #ifdef HAVE_WIRINGPI_H
149 lcdPuts(lcdHandle, "Choose unit:");
138 lcdPosition(lcdHandle, 0, 1); 150 lcdPosition(lcdHandle, 0, 1);
139 lcdPuts(lcdHandle, current_unit->name); 151 lcdPuts(lcdHandle, current_unit->name);
152 #endif
140 break; 153 break;
141 154
142 case MENU_MODE_OFF: show_mode(); 155 case MENU_MODE_OFF: show_mode();
156 #ifdef HAVE_WIRINGPI_H
143 lcdPuts(lcdHandle, "New mode OFF"); 157 lcdPuts(lcdHandle, "New mode OFF");
158 #endif
144 break; 159 break;
145 160
146 case MENU_MODE_NONE: show_mode(); 161 case MENU_MODE_NONE: show_mode();
162 #ifdef HAVE_WIRINGPI_H
147 lcdPuts(lcdHandle, "New mode NONE"); 163 lcdPuts(lcdHandle, "New mode NONE");
164 #endif
148 break; 165 break;
149 166
150 case MENU_NONE_HEAT: snprintf(buf, Config.lcd_cols, "Set heater %s", current_unit->heater_state ? "OFF":"ON"); 167 case MENU_NONE_HEAT: snprintf(buf, Config.lcd_cols, "Set heater %s", current_unit->heater_state ? "OFF":"ON");
168 #ifdef HAVE_WIRINGPI_H
151 lcdPuts(lcdHandle, buf); 169 lcdPuts(lcdHandle, buf);
170 #endif
152 break; 171 break;
153 172
154 case MENU_NONE_COOL: snprintf(buf, Config.lcd_cols, "Set cooler %s", current_unit->cooler_state ? "OFF":"ON"); 173 case MENU_NONE_COOL: snprintf(buf, Config.lcd_cols, "Set cooler %s", current_unit->cooler_state ? "OFF":"ON");
174 #ifdef HAVE_WIRINGPI_H
155 lcdPuts(lcdHandle, buf); 175 lcdPuts(lcdHandle, buf);
176 #endif
156 break; 177 break;
157 178
158 case MENU_NONE_FAN: snprintf(buf, Config.lcd_cols, "Set fan %s", current_unit->fan_state ? "OFF":"ON"); 179 case MENU_NONE_FAN: snprintf(buf, Config.lcd_cols, "Set fan %s", current_unit->fan_state ? "OFF":"ON");
180 #ifdef HAVE_WIRINGPI_H
159 lcdPuts(lcdHandle, buf); 181 lcdPuts(lcdHandle, buf);
182 #endif
160 break; 183 break;
161 184
162 case MENU_MODE_BEER: show_mode(); 185 case MENU_MODE_BEER: show_mode();
186 #ifdef HAVE_WIRINGPI_H
163 lcdPuts(lcdHandle, "New mode BEER"); 187 lcdPuts(lcdHandle, "New mode BEER");
188 #endif
164 break; 189 break;
165 190
166 case MENU_BEER_TEMP: lcdPuts(lcdHandle, "Set beer temp"); 191 case MENU_BEER_TEMP:
192 #ifdef HAVE_WIRINGPI_H
193 lcdPuts(lcdHandle, "Set beer temp");
167 lcdPosition(lcdHandle, 0, 1); 194 lcdPosition(lcdHandle, 0, 1);
195 #endif
168 snprintf(buf, Config.lcd_cols, "Set %.1f", temp_temp); 196 snprintf(buf, Config.lcd_cols, "Set %.1f", temp_temp);
197 #ifdef HAVE_WIRINGPI_H
169 lcdPuts(lcdHandle, buf); 198 lcdPuts(lcdHandle, buf);
199 #endif
170 break; 200 break;
171 201
172 case MENU_MODE_FRIDGE: show_mode(); 202 case MENU_MODE_FRIDGE: show_mode();
203 #ifdef HAVE_WIRINGPI_H
173 lcdPuts(lcdHandle, "New mode FRIDGE"); 204 lcdPuts(lcdHandle, "New mode FRIDGE");
205 #endif
174 break; 206 break;
175 207
176 case MENU_FRIDGE_TEMP: lcdPuts(lcdHandle, "Set fridge temp"); 208 case MENU_FRIDGE_TEMP:
209 #ifdef HAVE_WIRINGPI_H
210 lcdPuts(lcdHandle, "Set fridge temp");
177 lcdPosition(lcdHandle, 0, 1); 211 lcdPosition(lcdHandle, 0, 1);
212 #endif
178 snprintf(buf, Config.lcd_cols, "Set %.1f", temp_temp); 213 snprintf(buf, Config.lcd_cols, "Set %.1f", temp_temp);
214 #ifdef HAVE_WIRINGPI_H
179 lcdPuts(lcdHandle, buf); 215 lcdPuts(lcdHandle, buf);
216 #endif
180 break; 217 break;
181 218
182 case MENU_MODE_PROFILE: show_mode(); 219 case MENU_MODE_PROFILE: show_mode();
220 #ifdef HAVE_WIRINGPI_H
183 lcdPuts(lcdHandle, "New mode PROFILE"); 221 lcdPuts(lcdHandle, "New mode PROFILE");
222 #endif
184 break; 223 break;
185 224
186 case MENU_PROFILE_SELECT: snprintf(buf, Config.lcd_cols, "%s", current_profile->name); 225 case MENU_PROFILE_SELECT: snprintf(buf, Config.lcd_cols, "%s", current_profile->name);
226 #ifdef HAVE_WIRINGPI_H
187 lcdPuts(lcdHandle, buf); 227 lcdPuts(lcdHandle, buf);
188 lcdPosition(lcdHandle, 0, 1); 228 lcdPosition(lcdHandle, 0, 1);
189 lcdPuts(lcdHandle, "Select profile"); 229 lcdPuts(lcdHandle, "Select profile");
230 #endif
190 break; 231 break;
191 232
192 case MENU_PROFILE_START: snprintf(buf, Config.lcd_cols, "%s", current_profile->name); 233 case MENU_PROFILE_START: snprintf(buf, Config.lcd_cols, "%s", current_profile->name);
234 #ifdef HAVE_WIRINGPI_H
193 lcdPuts(lcdHandle, buf); 235 lcdPuts(lcdHandle, buf);
194 lcdPosition(lcdHandle, 0, 1); 236 lcdPosition(lcdHandle, 0, 1);
195 lcdPuts(lcdHandle, "Start profile"); 237 lcdPuts(lcdHandle, "Start profile");
238 #endif
196 break; 239 break;
197 240
198 case MENU_PROFILE_PAUSE: snprintf(buf, Config.lcd_cols, "%s", current_profile->name); 241 case MENU_PROFILE_PAUSE: snprintf(buf, Config.lcd_cols, "%s", current_profile->name);
242 #ifdef HAVE_WIRINGPI_H
199 lcdPuts(lcdHandle, buf); 243 lcdPuts(lcdHandle, buf);
200 lcdPosition(lcdHandle, 0, 1); 244 lcdPosition(lcdHandle, 0, 1);
201 lcdPuts(lcdHandle, "Pause profile"); 245 lcdPuts(lcdHandle, "Pause profile");
246 #endif
202 break; 247 break;
203 248
204 case MENU_PROFILE_ABORT: snprintf(buf, Config.lcd_cols, "%s", current_profile->name); 249 case MENU_PROFILE_ABORT: snprintf(buf, Config.lcd_cols, "%s", current_profile->name);
250 #ifdef HAVE_WIRINGPI_H
205 lcdPuts(lcdHandle, buf); 251 lcdPuts(lcdHandle, buf);
206 lcdPosition(lcdHandle, 0, 1); 252 lcdPosition(lcdHandle, 0, 1);
207 lcdPuts(lcdHandle, "Abort profile"); 253 lcdPuts(lcdHandle, "Abort profile");
254 #endif
208 break; 255 break;
209 256
210 case MENU_PROFILE_RESUME: snprintf(buf, Config.lcd_cols, "%s", current_profile->name); 257 case MENU_PROFILE_RESUME: snprintf(buf, Config.lcd_cols, "%s", current_profile->name);
258 #ifdef HAVE_WIRINGPI_H
211 lcdPuts(lcdHandle, buf); 259 lcdPuts(lcdHandle, buf);
212 lcdPosition(lcdHandle, 0, 1); 260 lcdPosition(lcdHandle, 0, 1);
213 lcdPuts(lcdHandle, "Resume profile"); 261 lcdPuts(lcdHandle, "Resume profile");
262 #endif
214 break; 263 break;
215 264
216 case MENU_PROFILE_GOOFF: snprintf(buf, Config.lcd_cols, "%s", current_profile->name); 265 case MENU_PROFILE_GOOFF: snprintf(buf, Config.lcd_cols, "%s", current_profile->name);
266 #ifdef HAVE_WIRINGPI_H
217 lcdPuts(lcdHandle, buf); 267 lcdPuts(lcdHandle, buf);
218 lcdPosition(lcdHandle, 0, 1); 268 lcdPosition(lcdHandle, 0, 1);
219 lcdPuts(lcdHandle, "Set profile OFF"); 269 lcdPuts(lcdHandle, "Set profile OFF");
270 #endif
220 break; 271 break;
221 272
222 case MENU_TOP_SYS: lcdPuts(lcdHandle, "System menu"); 273 case MENU_TOP_SYS:
274 #ifdef HAVE_WIRINGPI_H
275 lcdPuts(lcdHandle, "System menu");
276 #endif
223 break; 277 break;
224 278
225 case MENU_SYS_HALT: lcdPuts(lcdHandle, "Halt system"); 279 case MENU_SYS_HALT:
280 #ifdef HAVE_WIRINGPI_H
281 lcdPuts(lcdHandle, "Halt system");
282 #endif
226 break; 283 break;
227 284
228 case MENU_SYS_REBOOT: lcdPuts(lcdHandle, "Reboot system"); 285 case MENU_SYS_REBOOT:
286 #ifdef HAVE_WIRINGPI_H
287 lcdPuts(lcdHandle, "Reboot system");
288 #endif
229 break; 289 break;
230 } 290 }
231 291
292 #ifdef HAVE_WIRINGPI_H
232 piUnlock(LOCK_MENU); 293 piUnlock(LOCK_MENU);
233 piUnlock(LOCK_LCD); 294 piUnlock(LOCK_LCD);
295 #endif
234 } 296 }
235 297
236 298
237 299
238 void stopLCD(void) 300 void stopLCD(void)
239 { 301 {
302 #ifdef HAVE_WIRINGPI_H
240 piLock(LOCK_LCD); 303 piLock(LOCK_LCD);
241 lcdClear(lcdHandle); 304 lcdClear(lcdHandle);
242 setBacklight(0); 305 setBacklight(0);
243 piUnlock(LOCK_LCD); 306 piUnlock(LOCK_LCD);
307 #endif
244 } 308 }
245 309
246 310
247 311
248 /* 312 /*
273 current_unit->prof_fridge_mode = 0; 337 current_unit->prof_fridge_mode = 0;
274 } 338 }
275 } 339 }
276 340
277 341
278 #endif
279
280
281 342
282 /* 343 /*
283 * Handle panel key events 344 * Handle panel key events
284 */ 345 */
285 #ifdef HAVE_WIRINGPI_H 346 #ifdef HAVE_WIRINGPI_H
767 828
768 frk = fork(); 829 frk = fork();
769 switch (frk) { 830 switch (frk) {
770 case -1: 831 case -1:
771 syslog(LOG_NOTICE, "Daemon fork failed: %s", strerror(errno)); 832 syslog(LOG_NOTICE, "Daemon fork failed: %s", strerror(errno));
772 #ifdef HAVE_WIRINGPI_H
773 stopLCD(); 833 stopLCD();
774 #endif
775 exit(1); 834 exit(1);
776 case 0: /* 835 case 0: /*
777 * Run the daemon 836 * Run the daemon
778 */ 837 */
779 fclose(stdin); 838 fclose(stdin);
817 char use_heater[40], use_cooler[40], use_fan[40], room_temp[40]; 876 char use_heater[40], use_cooler[40], use_fan[40], room_temp[40];
818 time_t now, last = (time_t)0; 877 time_t now, last = (time_t)0;
819 units_list *unit; 878 units_list *unit;
820 profiles_list *profile; 879 profiles_list *profile;
821 prof_step *step; 880 prof_step *step;
822 int rc, run = 1, seconds = 0, minutes = 0, temp, deviation; 881 int row, rc, run = 1, seconds = 0, minutes = 0, temp, deviation;
823 int run_seconds, run_minutes, run_hours, tot_minutes; 882 int run_seconds, run_minutes, run_hours, tot_minutes;
824 #ifdef HAVE_WIRINGPI_H
825 struct tm *tm; 883 struct tm *tm;
826 int row, key; 884 #ifdef HAVE_WIRINGPI_H
885 int key;
827 #else 886 #else
828 long t = 0; 887 long t = 0;
829 #endif 888 #endif
830 int current_step, valid_step, time_until_now, previous_fridge_mode; 889 int current_step, valid_step, time_until_now, previous_fridge_mode;
831 float previous_target_lo, previous_target_hi; 890 float previous_target_lo, previous_target_hi;
918 } 977 }
919 } 978 }
920 979
921 #ifdef HAVE_WIRINGPI_H 980 #ifdef HAVE_WIRINGPI_H
922 piLock(LOCK_LCD); 981 piLock(LOCK_LCD);
982 #endif
923 lcd_buf_write(1, (char *)" ThermFerm "); 983 lcd_buf_write(1, (char *)" ThermFerm ");
924 lcd_buf_write(2, (char *)" Version %s ", VERSION); 984 lcd_buf_write(2, (char *)" Version %s ", VERSION);
985 #ifdef HAVE_WIRINGPI_H
925 piUnlock(LOCK_LCD); 986 piUnlock(LOCK_LCD);
926 #endif 987 #endif
927 988
928 /* 989 /*
929 * Initialize logfiles for each unit 990 * Initialize logfiles for each unit
955 #ifdef HAVE_WIRINGPI_H 1016 #ifdef HAVE_WIRINGPI_H
956 /* 1017 /*
957 * In case the LCD buffers were cleared, setup the first page. 1018 * In case the LCD buffers were cleared, setup the first page.
958 */ 1019 */
959 piLock(LOCK_LCD); 1020 piLock(LOCK_LCD);
1021 #endif
960 lcd_buf_write(1, (char *)" ThermFerm "); 1022 lcd_buf_write(1, (char *)" ThermFerm ");
961 lcd_buf_write(2, (char *)" Version %s ", VERSION); 1023 lcd_buf_write(2, (char *)" Version %s ", VERSION);
1024 #ifdef HAVE_WIRINGPI_H
962 piUnlock(LOCK_LCD); 1025 piUnlock(LOCK_LCD);
963 #endif 1026 #endif
964 } 1027 }
965 1028
966 now = time(NULL); 1029 now = time(NULL);
969 * Each second 1032 * Each second
970 */ 1033 */
971 last = now; 1034 last = now;
972 seconds++; 1035 seconds++;
973 1036
974 #ifdef HAVE_WIRINGPI_H
975 row = 3; 1037 row = 3;
976 tm = localtime(&now); 1038 tm = localtime(&now);
1039 #ifdef HAVE_WIRINGPI_H
977 piLock(LOCK_LCD); 1040 piLock(LOCK_LCD);
1041 #endif
978 lcd_buf_write(row++, " %02d-%02d-%04d ", tm->tm_mday, tm->tm_mon + 1, tm->tm_year + 1900); 1042 lcd_buf_write(row++, " %02d-%02d-%04d ", tm->tm_mday, tm->tm_mon + 1, tm->tm_year + 1900);
979 lcd_buf_write(row++, " %02d:%02d:%02d ", tm->tm_hour, tm->tm_min, tm->tm_sec); 1043 lcd_buf_write(row++, " %02d:%02d:%02d ", tm->tm_hour, tm->tm_min, tm->tm_sec);
1044 #ifdef HAVE_WIRINGPI_H
980 piUnlock(LOCK_LCD); 1045 piUnlock(LOCK_LCD);
981 #endif 1046 #endif
982 1047
983 if (Config.temp_address) { 1048 if (Config.temp_address) {
984 rc = device_in(Config.temp_address, &temp); 1049 rc = device_in(Config.temp_address, &temp);
985 if (rc == DEVPRESENT_YES) { 1050 if (rc == DEVPRESENT_YES) {
986 Config.temp_value = temp; 1051 Config.temp_value = temp;
987 Config.temp_state = 0; 1052 Config.temp_state = 0;
988 #ifdef HAVE_WIRINGPI_H 1053 #ifdef HAVE_WIRINGPI_H
989 piLock(LOCK_LCD); 1054 piLock(LOCK_LCD);
1055 #endif
990 lcd_buf_write(row++, "Room temp %.1f %cC ", Config.temp_value / 1000.0, 0xdf); 1056 lcd_buf_write(row++, "Room temp %.1f %cC ", Config.temp_value / 1000.0, 0xdf);
1057 #ifdef HAVE_WIRINGPI_H
991 piUnlock(LOCK_LCD); 1058 piUnlock(LOCK_LCD);
992 #endif 1059 #endif
993 } else if (rc == DEVPRESENT_ERROR) { 1060 } else if (rc == DEVPRESENT_ERROR) {
994 Config.temp_state = 1; 1061 Config.temp_state = 1;
995 } else { 1062 } else {
1002 if (rc == DEVPRESENT_YES) { 1069 if (rc == DEVPRESENT_YES) {
1003 Config.hum_value = temp; 1070 Config.hum_value = temp;
1004 Config.hum_state = 0; 1071 Config.hum_state = 0;
1005 #ifdef HAVE_WIRINGPI_H 1072 #ifdef HAVE_WIRINGPI_H
1006 piLock(LOCK_LCD); 1073 piLock(LOCK_LCD);
1074 #endif
1007 lcd_buf_write(row++, " Humidity %.1f %% ", Config.hum_value / 1000.0, 0xdf); 1075 lcd_buf_write(row++, " Humidity %.1f %% ", Config.hum_value / 1000.0, 0xdf);
1076 #ifdef HAVE_WIRINGPI_H
1008 piUnlock(LOCK_LCD); 1077 piUnlock(LOCK_LCD);
1009 #endif 1078 #endif
1010 } else if (rc == DEVPRESENT_ERROR) { 1079 } else if (rc == DEVPRESENT_ERROR) {
1011 Config.hum_state = 1; 1080 Config.hum_state = 1;
1012 } else { 1081 } else {
1015 } 1084 }
1016 1085
1017 for (unit = Config.units; unit; unit = unit->next) { 1086 for (unit = Config.units; unit; unit = unit->next) {
1018 #ifdef HAVE_WIRINGPI_H 1087 #ifdef HAVE_WIRINGPI_H
1019 piLock(LOCK_LCD); 1088 piLock(LOCK_LCD);
1089 #endif
1020 lcd_buf_write(row++, "Unit %s ", unit->name); 1090 lcd_buf_write(row++, "Unit %s ", unit->name);
1021 lcd_buf_write(row++, "Mode %s ", UNITMODE[unit->mode]); 1091 lcd_buf_write(row++, "Mode %s ", UNITMODE[unit->mode]);
1092 #ifdef HAVE_WIRINGPI_H
1022 piUnlock(LOCK_LCD); 1093 piUnlock(LOCK_LCD);
1023 #endif 1094 #endif
1024 1095
1025 if (unit->air_address) { 1096 if (unit->air_address) {
1026 rc = device_in(unit->air_address, &temp); 1097 rc = device_in(unit->air_address, &temp);
1038 (unit->air_temperature && (temp > (int)unit->air_temperature - deviation) && (temp < ((int)unit->air_temperature + deviation)))) { 1109 (unit->air_temperature && (temp > (int)unit->air_temperature - deviation) && (temp < ((int)unit->air_temperature + deviation)))) {
1039 unit->air_temperature = temp; 1110 unit->air_temperature = temp;
1040 unit->air_state = 0; 1111 unit->air_state = 0;
1041 #ifdef HAVE_WIRINGPI_H 1112 #ifdef HAVE_WIRINGPI_H
1042 piLock(LOCK_LCD); 1113 piLock(LOCK_LCD);
1114 #endif
1043 lcd_buf_write(row++, " Air %.3f %cC ", unit->air_temperature / 1000.0, 0xdf); 1115 lcd_buf_write(row++, " Air %.3f %cC ", unit->air_temperature / 1000.0, 0xdf);
1116 #ifdef HAVE_WIRINGPI_H
1044 piUnlock(LOCK_LCD); 1117 piUnlock(LOCK_LCD);
1045 #endif 1118 #endif
1046 } else { 1119 } else {
1047 syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->air_temperature, temp); 1120 syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->air_temperature, temp);
1048 if (debug) { 1121 if (debug) {
1064 (unit->beer_temperature && (temp > (int)unit->beer_temperature - deviation) && (temp < ((int)unit->beer_temperature + deviation)))) { 1137 (unit->beer_temperature && (temp > (int)unit->beer_temperature - deviation) && (temp < ((int)unit->beer_temperature + deviation)))) {
1065 unit->beer_temperature = temp; 1138 unit->beer_temperature = temp;
1066 unit->beer_state = 0; 1139 unit->beer_state = 0;
1067 #ifdef HAVE_WIRINGPI_H 1140 #ifdef HAVE_WIRINGPI_H
1068 piLock(LOCK_LCD); 1141 piLock(LOCK_LCD);
1142 #endif
1069 lcd_buf_write(row++, "Beer %.3f %cC ", unit->beer_temperature / 1000.0, 0xdf); 1143 lcd_buf_write(row++, "Beer %.3f %cC ", unit->beer_temperature / 1000.0, 0xdf);
1144 #ifdef HAVE_WIRINGPI_H
1070 piUnlock(LOCK_LCD); 1145 piUnlock(LOCK_LCD);
1071 #endif 1146 #endif
1072 } else { 1147 } else {
1073 syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->beer_temperature, temp); 1148 syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->beer_temperature, temp);
1074 if (debug) { 1149 if (debug) {
1333 if (unit->fan_address && unit->fan_state) 1408 if (unit->fan_address && unit->fan_state)
1334 unit->fan_usage++; 1409 unit->fan_usage++;
1335 if (unit->light_address && unit->light_state) 1410 if (unit->light_address && unit->light_state)
1336 unit->light_usage++; 1411 unit->light_usage++;
1337 1412
1338 #ifdef HAVE_WIRINGPI_H
1339 if (unit->heater_address && unit->cooler_address) { 1413 if (unit->heater_address && unit->cooler_address) {
1340 piLock(LOCK_LCD); 1414 #ifdef HAVE_WIRINGPI_H
1341 if (unit->heater_state) { 1415 piLock(LOCK_LCD);
1416 #endif
1417 if (unit->heater_state) {
1342 lcd_buf_write(row++, "Heater On "); 1418 lcd_buf_write(row++, "Heater On ");
1343 } else if (unit->cooler_state) { 1419 } else if (unit->cooler_state) {
1344 lcd_buf_write(row++, "Cooler On "); 1420 lcd_buf_write(row++, "Cooler On ");
1345 } else { 1421 } else {
1346 lcd_buf_write(row++, "Standby "); 1422 lcd_buf_write(row++, "Standby ");
1347 } 1423 }
1424 #ifdef HAVE_WIRINGPI_H
1348 piUnlock(LOCK_LCD); 1425 piUnlock(LOCK_LCD);
1349 piLock(LOCK_LCD); 1426 piLock(LOCK_LCD);
1427 #endif
1350 switch (unit->mode) { 1428 switch (unit->mode) {
1351 case UNITMODE_BEER: lcd_buf_write(row++, "Target %.1f %cC ", unit->beer_set, 0xdf); 1429 case UNITMODE_BEER: lcd_buf_write(row++, "Target %.1f %cC ", unit->beer_set, 0xdf);
1352 break; 1430 break;
1353 case UNITMODE_FRIDGE: lcd_buf_write(row++, "Target %.1f %cC ", unit->fridge_set, 0xdf); 1431 case UNITMODE_FRIDGE: lcd_buf_write(row++, "Target %.1f %cC ", unit->fridge_set, 0xdf);
1354 break; 1432 break;
1357 else 1435 else
1358 lcd_buf_write(row++, "Target not set "); 1436 lcd_buf_write(row++, "Target not set ");
1359 break; 1437 break;
1360 default: lcd_buf_write(row++, "Target not set "); 1438 default: lcd_buf_write(row++, "Target not set ");
1361 } 1439 }
1440 #ifdef HAVE_WIRINGPI_H
1362 piUnlock(LOCK_LCD); 1441 piUnlock(LOCK_LCD);
1442 #endif
1363 } else { 1443 } else {
1364 piLock(LOCK_LCD); 1444 #ifdef HAVE_WIRINGPI_H
1445 piLock(LOCK_LCD);
1446 #endif
1365 if (unit->heater_address) { 1447 if (unit->heater_address) {
1366 lcd_buf_write(row++, "Heat %s ", unit->heater_state ? "On ":"Off"); 1448 lcd_buf_write(row++, "Heat %s ", unit->heater_state ? "On ":"Off");
1367 } 1449 }
1368 if (unit->cooler_address) { 1450 if (unit->cooler_address) {
1369 lcd_buf_write(row++, "Cool %s ", unit->cooler_state ? "On ":"Off"); 1451 lcd_buf_write(row++, "Cool %s ", unit->cooler_state ? "On ":"Off");
1370 } 1452 }
1453 #ifdef HAVE_WIRINGPI_H
1371 piUnlock(LOCK_LCD); 1454 piUnlock(LOCK_LCD);
1455 #endif
1372 } 1456 }
1373 #endif
1374 1457
1375 /* 1458 /*
1376 * Interior lights 1459 * Interior lights
1377 */ 1460 */
1378 if (unit->light_address) { 1461 if (unit->light_address) {
1551 } /* fridge beer or profile mode */ 1634 } /* fridge beer or profile mode */
1552 } /* for units */ 1635 } /* for units */
1553 1636
1554 #ifdef HAVE_WIRINGPI_H 1637 #ifdef HAVE_WIRINGPI_H
1555 piLock(LOCK_MENU); 1638 piLock(LOCK_MENU);
1639 #endif
1556 if (setupmenu == MENU_NONE) { 1640 if (setupmenu == MENU_NONE) {
1557 piLock(LOCK_LCD); 1641 #ifdef HAVE_WIRINGPI_H
1642 piLock(LOCK_LCD);
1643 #endif
1558 lcd_buf_show(); 1644 lcd_buf_show();
1645 #ifdef HAVE_WIRINGPI_H
1559 piUnlock(LOCK_LCD); 1646 piUnlock(LOCK_LCD);
1647 #endif
1560 } 1648 }
1649 #ifdef HAVE_WIRINGPI_H
1561 piUnlock(LOCK_MENU); 1650 piUnlock(LOCK_MENU);
1562 #endif 1651 #endif
1563 1652
1564 if (seconds == 60) { 1653 if (seconds == 60) {
1565 seconds = 0; 1654 seconds = 0;
1674 /* 1763 /*
1675 * Give threads time to cleanup 1764 * Give threads time to cleanup
1676 */ 1765 */
1677 usleep(1500000); 1766 usleep(1500000);
1678 1767
1679 #ifdef HAVE_WIRINGPI_H
1680 stopLCD(); 1768 stopLCD();
1681 #endif
1682
1683 wrconfig(); 1769 wrconfig();
1684 ulockprog((char *)"thermferm"); 1770 ulockprog((char *)"thermferm");
1685 return 0; 1771 return 0;
1686 } 1772 }
1687 1773

mercurial