thermferm/thermferm.c

changeset 108
50d2187fdb74
parent 106
1bd9a16f5061
child 111
bdf3c5278a24
equal deleted inserted replaced
107:f2f201b7cb48 108:50d2187fdb74
106 106
107 int main(int argc, char *argv[]) 107 int main(int argc, char *argv[])
108 { 108 {
109 int rc, c, i; 109 int rc, c, i;
110 pid_t frk; 110 pid_t frk;
111 #ifdef HAVE_WIRINGPI_H
112 char buf[80];
113 #endif
114 111
115 while (1) { 112 while (1) {
116 int option_index = 0; 113 int option_index = 0;
117 static struct option long_options[] = { 114 static struct option long_options[] = {
118 {"debug", 0, 0, 'c'}, 115 {"debug", 0, 0, 'c'},
155 152
156 #ifdef HAVE_WIRINGPI_H 153 #ifdef HAVE_WIRINGPI_H
157 if (wiringPiSetup () ) 154 if (wiringPiSetup () )
158 return 1; 155 return 1;
159 156
160 if ((rc = initLCD (16, 2))) { 157 if ((rc = initLCD (Config.lcd_cols, Config.lcd_rows))) {
161 fprintf(stderr, "Cannot initialize LCD display, rc=%d\n", rc); 158 fprintf(stderr, "Cannot initialize LCD display, rc=%d\n", rc);
162 return 1; 159 return 1;
163 } 160 }
164
165 lcdPosition(lcdHandle, 0, 0);
166 sprintf(buf, " Thermferm");
167 mb_lcdPuts(lcdHandle, buf);
168 lcdPosition(lcdHandle, 0, 1);
169 sprintf(buf, " Version %s", VERSION);
170 mb_lcdPuts(lcdHandle, buf);
171 #endif 161 #endif
172 162
173 if (debug) { 163 if (debug) {
174 /* 164 /*
175 * For debugging run in foreground. 165 * For debugging run in foreground.
242 time_t now, last = (time_t)0; 232 time_t now, last = (time_t)0;
243 w1_therm *tmp1; 233 w1_therm *tmp1;
244 units_list *unit; 234 units_list *unit;
245 int rc, run = 1, temp, seconds = 0; 235 int rc, run = 1, temp, seconds = 0;
246 #ifdef HAVE_WIRINGPI_H 236 #ifdef HAVE_WIRINGPI_H
247 int lcdshow = 0;
248 struct tm *tm; 237 struct tm *tm;
238 int row;
249 #else 239 #else
250 long t = 0; 240 long t = 0;
251 #endif 241 #endif
252 242
253 if (lockprog((char *)"thermferm")) { 243 if (lockprog((char *)"thermferm")) {
294 #ifndef HAVE_WIRINGPI_H 284 #ifndef HAVE_WIRINGPI_H
295 } else { 285 } else {
296 t++; 286 t++;
297 #endif 287 #endif
298 } 288 }
289
290 lcd_buf_write(1, (char *)" ThermFerm ");
291 lcd_buf_write(2, (char *)" Version %s ", VERSION);
299 292
300 snprintf(buf, 1023, "tempA,tempB"); 293 snprintf(buf, 1023, "tempA,tempB");
301 logger((char *)"thermferm.log", buf); 294 logger((char *)"thermferm.log", buf);
302 295
303 for (unit = Config.units; unit; unit = unit->next) { 296 for (unit = Config.units; unit; unit = unit->next) {
331 if (now != last) { 324 if (now != last) {
332 last = now; 325 last = now;
333 seconds++; 326 seconds++;
334 327
335 #ifdef HAVE_WIRINGPI_H 328 #ifdef HAVE_WIRINGPI_H
336 if ((seconds % 5) == 0) { 329 row = 3;
337 330 tm = localtime(&now);
338 if (lcdshow == 0) { 331 lcd_buf_write(row++, " %02d-%02d-%04d ", tm->tm_mday, tm->tm_mon + 1, tm->tm_year + 1900);
339 lcdPosition(lcdHandle, 0, 0); 332 lcd_buf_write(row++, " %02d:%02d:%02d ", tm->tm_hour, tm->tm_min, tm->tm_sec);
340 snprintf(buf, 17, " ThermFerm "); 333
341 mb_lcdPuts(lcdHandle, buf); 334 for (unit = Config.units; unit; unit = unit->next) {
342 lcdPosition(lcdHandle, 0, 1); 335 if (unit->mode != UNITMODE_OFF) {
343 snprintf(buf, 17, " Version %s ", VERSION); 336 lcd_buf_write(row++, "Unit %s ", unit->name);
344 mb_lcdPuts(lcdHandle, buf); 337 lcd_buf_write(row++, "Mode %s ", UNITMODE[unit->mode]);
345 lcdshow++; 338 if (unit->air_address) {
346 } else if (lcdshow == 1) { 339 lcd_buf_write(row++, " Air %.3f %cC ", unit->air_temperature / 1000.0, 0xdf);
347 tm = localtime(&now); 340 }
348 lcdPosition(lcdHandle, 0, 0); 341 if (unit->beer_address) {
349 snprintf(buf, 17, " %02d-%02d-%04d ", tm->tm_mday, tm->tm_mon + 1, tm->tm_year + 1900); 342 lcd_buf_write(row++, "Beer %.3f %cC ", unit->beer_temperature / 1000.0, 0xdf);
350 mb_lcdPuts(lcdHandle, buf); 343 }
351 lcdPosition(lcdHandle, 0, 1);
352 snprintf(buf, 17, " %02d:%02d:%02d ", tm->tm_hour, tm->tm_min, tm->tm_sec);
353 mb_lcdPuts(lcdHandle, buf);
354 lcdshow++;
355 } else {
356 lcdPosition(lcdHandle, 0, 0);
357 tmp1 = Config.w1therms;
358 snprintf(buf, 17, "%5.2f %cC %s ", tmp1->lastval / 1000.0, 0xdf, tmp1->alias);
359 mb_lcdPuts(lcdHandle, buf);
360 temp = tmp1->lastval;
361 tmp1 = tmp1->next;
362 lcdPosition(lcdHandle, 0, 1);
363 snprintf(buf, 17, "%5.2f %cC %s ", tmp1->lastval / 1000.0, 0xdf, tmp1->alias);
364 mb_lcdPuts(lcdHandle, buf);
365 lcdshow = 0;
366 } 344 }
367 } 345 }
346
347 lcd_buf_show();
368 #endif 348 #endif
369 349
370 if (seconds == 60) { 350 if (seconds == 60) {
371 seconds = 0; 351 seconds = 0;
372 352

mercurial