28 int tempB = 80; |
28 int tempB = 80; |
29 |
29 |
30 key_t key = 5680; /* key to be passed to shmget() */ |
30 key_t key = 5680; /* key to be passed to shmget() */ |
31 int shmid; |
31 int shmid; |
32 |
32 |
33 bool my_shutdown = false; |
33 int my_shutdown = FALSE; |
34 static pid_t pgrp, mypid; |
34 static pid_t pgrp, mypid; |
35 |
35 |
36 extern bool debug; |
36 extern int debug; |
37 extern sys_config Config; |
37 extern sys_config Config; |
38 #ifdef HAVE_WIRINGPI_H |
38 #ifdef HAVE_WIRINGPI_H |
39 extern int lcdHandle; |
39 extern int lcdHandle; |
40 extern unsigned char lcdbuf[MAX_LCDS][20][4]; |
40 extern unsigned char lcdbuf[MAX_LCDS][20][4]; |
41 #endif |
41 #endif |
75 case SIGTERM: syslog(LOG_NOTICE, "Got SIGTERM, shutting down"); |
75 case SIGTERM: syslog(LOG_NOTICE, "Got SIGTERM, shutting down"); |
76 break; |
76 break; |
77 default: syslog(LOG_NOTICE, "die() on signal %d", onsig); |
77 default: syslog(LOG_NOTICE, "die() on signal %d", onsig); |
78 } |
78 } |
79 |
79 |
80 my_shutdown = true; |
80 my_shutdown = TRUE; |
81 } |
81 } |
82 |
82 |
83 |
83 |
84 |
84 |
85 #ifdef HAVE_WIRINGPI_H |
85 #ifdef HAVE_WIRINGPI_H |
240 } |
240 } |
241 |
241 |
242 #ifdef HAVE_WIRINGPI_H |
242 #ifdef HAVE_WIRINGPI_H |
243 rc = piThreadCreate(my_sensors_loop); |
243 rc = piThreadCreate(my_sensors_loop); |
244 #else |
244 #else |
245 rc = pthread_create(&threads[0], NULL, my_sensors_loop, (void *)t ); |
245 rc = pthread_create(&threads[t], NULL, my_sensors_loop, (void *)t ); |
246 #endif |
246 #endif |
247 if (rc) { |
247 if (rc) { |
248 fprintf(stderr, "my_sensors_loop thread didn't start rc=%d\n", rc); |
248 fprintf(stderr, "my_sensors_loop thread didn't start rc=%d\n", rc); |
249 syslog(LOG_NOTICE, "my_sensors_loop thread didn't start rc=%d", rc); |
249 syslog(LOG_NOTICE, "my_sensors_loop thread didn't start rc=%d", rc); |
|
250 #ifndef HAVE_WIRINGPI_H |
|
251 } else { |
|
252 t++; |
|
253 #endif |
250 } |
254 } |
251 |
255 |
252 #ifdef HAVE_WIRINGPI_H |
256 #ifdef HAVE_WIRINGPI_H |
253 rc = piThreadCreate(my_server_loop); |
257 rc = piThreadCreate(my_server_loop); |
254 #else |
258 #else |
255 rc = pthread_create(&threads[1], NULL, my_server_loop, (void *)t ); |
259 rc = pthread_create(&threads[t], NULL, my_server_loop, (void *)t ); |
256 #endif |
260 #endif |
257 if (rc) { |
261 if (rc) { |
258 fprintf(stderr, "my_server_loop thread didn't start rc=%d\n", rc); |
262 fprintf(stderr, "my_server_loop thread didn't start rc=%d\n", rc); |
259 syslog(LOG_NOTICE, "my_server_loop thread didn't start rc=%d", rc); |
263 syslog(LOG_NOTICE, "my_server_loop thread didn't start rc=%d", rc); |
|
264 #ifndef HAVE_WIRINGPI_H |
|
265 } else { |
|
266 t++; |
|
267 #endif |
260 } |
268 } |
261 |
269 |
262 snprintf(buf, 1023, "tempA,tempB"); |
270 snprintf(buf, 1023, "tempA,tempB"); |
263 logger((char *)"thermferm.log", (char *)"thermferm", buf); |
271 logger((char *)"thermferm.log", (char *)"thermferm", buf); |
264 |
272 |
266 lcdupdate = FALSE; |
274 lcdupdate = FALSE; |
267 |
275 |
268 if (my_shutdown) |
276 if (my_shutdown) |
269 run = 0; |
277 run = 0; |
270 |
278 |
271 tmp1 = Config.w1therms; |
279 for (tmp1 = Config.w1therms; tmp1; tmp1 = tmp1->next) { |
272 if (tmp1->update) { |
280 if (tmp1->update) { |
273 tmp1->update = FALSE; |
281 tmp1->update = FALSE; |
274 lcdupdate = TRUE; |
282 lcdupdate = TRUE; |
275 } |
283 } |
276 tmp1 = tmp1->next; |
|
277 if (tmp1->update) { |
|
278 tmp1->update = FALSE; |
|
279 lcdupdate = TRUE; |
|
280 } |
284 } |
281 |
285 |
282 #ifdef HAVE_WIRINGPI_H |
286 #ifdef HAVE_WIRINGPI_H |
283 if (run && lcdupdate) { |
287 if (run && lcdupdate) { |
284 lcdPosition(lcdHandle, 0, 0); |
288 lcdPosition(lcdHandle, 0, 0); |
294 #endif |
298 #endif |
295 |
299 |
296 now = time(NULL); |
300 now = time(NULL); |
297 if (((int)now - (int)last) > 60) { |
301 if (((int)now - (int)last) > 60) { |
298 last = now; |
302 last = now; |
299 tmp1 = Config.w1therms; |
303 if (Config.w1therms) { |
300 temp = tmp1->lastval; |
304 tmp1 = Config.w1therms; |
301 tmp1 = tmp1->next; |
305 temp = tmp1->lastval; |
302 if (temp && tmp1->lastval && run) { |
306 tmp1 = tmp1->next; |
303 snprintf(buf, 1023, "%.2f,%.2f", temp / 1000.0, tmp1->lastval / 1000.0); |
307 if (temp && tmp1->lastval && run) { |
304 logger((char *)"thermferm.log", (char *)"thermferm", buf); |
308 snprintf(buf, 1023, "%.2f,%.2f", temp / 1000.0, tmp1->lastval / 1000.0); |
|
309 logger((char *)"thermferm.log", (char *)"thermferm", buf); |
|
310 } |
305 } |
311 } |
306 } |
312 } |
307 usleep(100000); |
313 usleep(100000); |
308 |
314 |
309 } while (run); |
315 } while (run); |