thermferm/thermferm.c

changeset 64
2431965e8a8c
parent 63
07802719f63d
child 66
805f1d285acd
equal deleted inserted replaced
63:07802719f63d 64:2431965e8a8c
261 261
262 262
263 int server(void) 263 int server(void)
264 { 264 {
265 char buf[1024]; 265 char buf[1024];
266 w1_therm *tmp1, *old1; 266 time_t now, last = (time_t)0;
267 rc_switch *tmp2, *old2; 267 w1_therm *tmp1;
268 rc_switch *tmp2;
268 int rc, run = 1, temp; 269 int rc, run = 1, temp;
269 270
270 if (lockprog((char *)"thermferm")) { 271 if (lockprog((char *)"thermferm")) {
271 syslog(LOG_NOTICE, "Can't lock"); 272 syslog(LOG_NOTICE, "Can't lock");
272 return 1; 273 return 1;
309 } 310 }
310 if (tmp1->update) { 311 if (tmp1->update) {
311 tmp1->update = FALSE; 312 tmp1->update = FALSE;
312 lcdupdate = TRUE; 313 lcdupdate = TRUE;
313 } 314 }
314 old1 = tmp1->next; 315 tmp1 = tmp1->next;
315 tmp1 = old1; 316 tmp2 = tmp2->next;
316 old2 = tmp2->next;
317 tmp2 = old2;
318 if (((tmp1->lastval / 100) < (tempB - 5)) && (coolerB == 1)) { 317 if (((tmp1->lastval / 100) < (tempB - 5)) && (coolerB == 1)) {
319 coolerB = 0; 318 coolerB = 0;
320 syslog(LOG_NOTICE, "Temperature B is %.1f, switched cooler off", (tmp1->lastval / 1000.0)); 319 syslog(LOG_NOTICE, "Temperature B is %.1f, switched cooler off", (tmp1->lastval / 1000.0));
321 sendRCswitch(tmp2->address, 0); 320 sendRCswitch(tmp2->address, 0);
322 lcdupdate = TRUE; 321 lcdupdate = TRUE;
336 lcdPosition(lcdHandle, 0, 0); 335 lcdPosition(lcdHandle, 0, 0);
337 tmp1 = Config.w1therms; 336 tmp1 = Config.w1therms;
338 snprintf(buf, 16, "%5.2f %cC %c %s ", tmp1->lastval / 1000.0, 0xdf, coolerA ? '-' : ' ', tmp1->alias); 337 snprintf(buf, 16, "%5.2f %cC %c %s ", tmp1->lastval / 1000.0, 0xdf, coolerA ? '-' : ' ', tmp1->alias);
339 mb_lcdPuts(lcdHandle, buf); 338 mb_lcdPuts(lcdHandle, buf);
340 temp = tmp1->lastval; 339 temp = tmp1->lastval;
341 old1 = tmp1->next; 340 tmp1 = tmp1->next;
342 tmp1 = old1;
343 lcdPosition(lcdHandle, 0, 1); 341 lcdPosition(lcdHandle, 0, 1);
344 snprintf(buf, 16, "%5.2f %cC %c %s ", tmp1->lastval / 1000.0, 0xdf, coolerB ? '-' : ' ', tmp1->alias); 342 snprintf(buf, 16, "%5.2f %cC %c %s ", tmp1->lastval / 1000.0, 0xdf, coolerB ? '-' : ' ', tmp1->alias);
345 mb_lcdPuts(lcdHandle, buf); 343 mb_lcdPuts(lcdHandle, buf);
346 snprintf(buf, 1023, "%.2f,%s,%.2f,%s", temp / 1000.0, coolerA ? (char *)"on" : (char *)"off", 344 }
345
346 now = time(NULL);
347 if (((int)now - (int)last) > 60) {
348 last = now;
349 tmp1 = Config.w1therms;
350 temp = tmp1->lastval;
351 tmp1 = tmp1->next;
352 if (temp && tmp1->lastval && run) {
353 snprintf(buf, 1023, "%.2f,%s,%.2f,%s", temp / 1000.0, coolerA ? (char *)"on" : (char *)"off",
347 tmp1->lastval / 1000.0, coolerB ? (char *)"on" : (char *)"off"); 354 tmp1->lastval / 1000.0, coolerB ? (char *)"on" : (char *)"off");
348 logger((char *)"thermferm.log", (char *)"thermferm", buf); 355 logger((char *)"thermferm.log", (char *)"thermferm", buf);
356 }
349 } 357 }
350 usleep(100000); 358 usleep(100000);
351 359
352 } while (run); 360 } while (run);
353 361

mercurial