brewco/brewco.c

changeset 434
eb724767860d
parent 419
8a7f8272516c
child 438
7d1ec160d751
equal deleted inserted replaced
433:1421ece29197 434:eb724767860d
22 22
23 #include "rdconfig.h" 23 #include "rdconfig.h"
24 #include "brewco.h" 24 #include "brewco.h"
25 #include "futil.h" 25 #include "futil.h"
26 #include "xutil.h" 26 #include "xutil.h"
27 #include "lcd-pcf8574.h"
28 #include "slcd.h"
29 #include "lock.h"
30 #include "devices.h"
27 31
28 32
29 int my_shutdown = FALSE; 33 int my_shutdown = FALSE;
30 extern int debug; 34 extern int debug;
31 extern sys_config Config; 35 extern sys_config Config;
32 #ifdef HAVE_WIRINGPI_H
33 extern int lcdHandle; 36 extern int lcdHandle;
37 extern int slcdHandle;
38
39 #ifndef HAVE_WIRINGPI_H
40 pthread_t threads[5];
34 #endif 41 #endif
35 42
36 43
37 void help(void); 44 void help(void);
38 void die(int); 45 void die(int);
64 break; 71 break;
65 default: syslog(LOG_NOTICE, "die() on signal %d", onsig); 72 default: syslog(LOG_NOTICE, "die() on signal %d", onsig);
66 } 73 }
67 74
68 my_shutdown = TRUE; 75 my_shutdown = TRUE;
76 }
77
78
79
80 int server(void);
81 int server(void)
82 {
83 int rc = 0;
84 #ifndef HAVE_WIRINGPI_H
85 long t = 0;
86 #endif
87
88 // if (lockprog((char *)"thermferm")) {
89 // syslog(LOG_NOTICE, "Can't lock");
90 // return 1;
91 // }
92
93 if ((rc = devices_detect())) {
94 syslog(LOG_NOTICE, "Detected %d new devices", rc);
95 wrconfig();
96 }
97
98 #ifdef HAVE_WIRINGPI_H
99 rc = piThreadCreate(my_devices_loop);
100 #else
101 rc = pthread_create(&threads[t], NULL, my_devices_loop, (void *)t );
102 #endif
103 if (rc) {
104 fprintf(stderr, "my_devices_loop thread didn't start rc=%d\n", rc);
105 syslog(LOG_NOTICE, "my_devices_loop thread didn't start rc=%d", rc);
106 #ifndef HAVE_WIRINGPI_H
107 } else {
108 t++;
109 #endif
110 }
111
112 /*
113 * Initialize units for processing
114 */
115 // for (unit = Config.units; unit; unit = unit->next) {
116 /*
117 * Safety, turn everything off
118 */
119 // unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->light_state = 0;
120 // unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0;
121 // }
122
123 #ifdef HAVE_WIRINGPI_H
124 piLock(LOCK_LCD);
125 lcdPosition(lcdHandle, 0, 0);
126 lcdPrintf(lcdHandle, " Brewco %s", VERSION);
127 #endif
128 slcdPosition(slcdHandle, 0, 0);
129 slcdPrintf(slcdHandle, " Brewco %s", VERSION);
130 #ifdef HAVE_WIRINGPI_H
131 piUnlock(LOCK_LCD);
132 #endif
133
134 return rc;
69 } 135 }
70 136
71 137
72 138
73 int main(int argc, char *argv[]) 139 int main(int argc, char *argv[])
116 } 182 }
117 183
118 #ifdef HAVE_WIRINGPI_H 184 #ifdef HAVE_WIRINGPI_H
119 if (wiringPiSetup () ) 185 if (wiringPiSetup () )
120 return 1; 186 return 1;
121 187 #endif
122 // if ((rc = initLCD (Config.lcd_cols, Config.lcd_rows))) { 188
123 // fprintf(stderr, "Cannot initialize LCD display, rc=%d\n", rc); 189 if ((rc = initLCD (Config.lcd_cols, Config.lcd_rows))) {
124 // return 1; 190 fprintf(stderr, "Cannot initialize LCD display, rc=%d\n", rc);
125 // } 191 return 1;
126 #endif 192 }
127 193
194 rc = server();
128 195
129 syslog(LOG_NOTICE, "Finished, rc=%d", rc); 196 syslog(LOG_NOTICE, "Finished, rc=%d", rc);
197 if (debug)
198 fprintf(stdout, "Finished, rc=%d\n", rc);
130 return rc; 199 return rc;
131 } 200 }
132 201
133 202
134

mercurial