thermferm/thermferm.c

changeset 104
5e538c4e1ecb
parent 93
b759f814469d
child 105
a5a964148e34
equal deleted inserted replaced
103:99c47a8a61cb 104:5e538c4e1ecb
41 #endif 41 #endif
42 int lcdupdate; 42 int lcdupdate;
43 #ifndef HAVE_WIRINGPI_H 43 #ifndef HAVE_WIRINGPI_H
44 pthread_t threads[3]; 44 pthread_t threads[3];
45 #endif 45 #endif
46 extern const char UNITMODE[5][8];
47
46 48
47 int server(void); 49 int server(void);
48 void help(void); 50 void help(void);
49 void die(int); 51 void die(int);
50 #ifdef HAVE_WIRINGPI_H 52 #ifdef HAVE_WIRINGPI_H
224 226
225 227
226 228
227 int server(void) 229 int server(void)
228 { 230 {
229 char buf[1024]; 231 char buf[1024], *filename;
230 time_t now, last = (time_t)0; 232 time_t now, last = (time_t)0;
231 w1_therm *tmp1; 233 w1_therm *tmp1;
232 int rc, run = 1, temp; 234 units_list *unit;
235 int rc, run = 1, temp, seconds = 0;
233 #ifndef HAVE_WIRINGPI_H 236 #ifndef HAVE_WIRINGPI_H
234 long t = 0; 237 long t = 0;
235 #endif 238 #endif
236 239
237 if (lockprog((char *)"thermferm")) { 240 if (lockprog((char *)"thermferm")) {
280 t++; 283 t++;
281 #endif 284 #endif
282 } 285 }
283 286
284 snprintf(buf, 1023, "tempA,tempB"); 287 snprintf(buf, 1023, "tempA,tempB");
285 logger((char *)"thermferm.log", (char *)"thermferm", buf); 288 logger((char *)"thermferm.log", buf);
289
290 for (unit = Config.units; unit; unit = unit->next) {
291 if (unit->mode != UNITMODE_OFF) {
292 snprintf(buf, 1023, "Mode,Air,Beer,Target,Heater,Cooler,Fan,Door");
293 filename = xstrcpy(unit->name);
294 filename = xstrcat(filename, (char *)".log");
295 logger(filename, buf);
296 free(filename);
297 filename = NULL;
298 }
299 }
286 300
287 do { 301 do {
288 lcdupdate = FALSE; 302 lcdupdate = FALSE;
289 303
290 if (my_shutdown) 304 if (my_shutdown)
309 snprintf(buf, 16, "%5.2f %cC %s ", tmp1->lastval / 1000.0, 0xdf, tmp1->alias); 323 snprintf(buf, 16, "%5.2f %cC %s ", tmp1->lastval / 1000.0, 0xdf, tmp1->alias);
310 mb_lcdPuts(lcdHandle, buf); 324 mb_lcdPuts(lcdHandle, buf);
311 } 325 }
312 #endif 326 #endif
313 327
328 /*
329 * Timed schedulers
330 */
314 now = time(NULL); 331 now = time(NULL);
315 if (((int)now - (int)last) > 60) { 332 if (now != last) {
316 last = now; 333 last = now;
317 if (Config.w1therms) { 334 seconds++;
318 tmp1 = Config.w1therms; 335
319 temp = tmp1->lastval; 336 if (seconds == 60) {
320 tmp1 = tmp1->next; 337 seconds = 0;
321 if (temp && tmp1->lastval && run) { 338
322 snprintf(buf, 1023, "%.2f,%.2f", temp / 1000.0, tmp1->lastval / 1000.0); 339 if (Config.w1therms) {
323 logger((char *)"thermferm.log", (char *)"thermferm", buf); 340 tmp1 = Config.w1therms;
341 temp = tmp1->lastval;
342 tmp1 = tmp1->next;
343 if (temp && tmp1->lastval && run) {
344 snprintf(buf, 1023, "%.2f,%.2f", temp / 1000.0, tmp1->lastval / 1000.0);
345 logger((char *)"thermferm.log", buf);
346 }
324 } 347 }
348
349 for (unit = Config.units; unit; unit = unit->next) {
350 if (unit->mode != UNITMODE_OFF) {
351 snprintf(buf, 1023, "%s,%.3f,%.3f,Target,Heater,Cooler,Fan,Door",
352 UNITMODE[unit->mode], unit->air_temperature / 1000.0, unit->beer_temperature / 1000.0);
353 filename = xstrcpy(unit->name);
354 filename = xstrcat(filename, (char *)".log");
355 logger(filename, buf);
356 free(filename);
357 filename = NULL;
358 }
359 }
325 } 360 }
326 } 361 }
327 usleep(100000); 362 usleep(100000);
328 363
329 } while (run); 364 } while (run);

mercurial