brewco/brewco.c

changeset 434
eb724767860d
parent 419
8a7f8272516c
child 438
7d1ec160d751
--- a/brewco/brewco.c	Wed Nov 25 16:39:25 2015 +0100
+++ b/brewco/brewco.c	Wed Nov 25 22:49:35 2015 +0100
@@ -24,13 +24,20 @@
 #include "brewco.h"
 #include "futil.h"
 #include "xutil.h"
+#include "lcd-pcf8574.h"
+#include "slcd.h"
+#include "lock.h"
+#include "devices.h"
 
 
 int			my_shutdown = FALSE;
 extern int              debug;
 extern sys_config       Config;
-#ifdef HAVE_WIRINGPI_H
 extern int              lcdHandle;
+extern int		slcdHandle;
+
+#ifndef HAVE_WIRINGPI_H
+pthread_t               threads[5];
 #endif
 
 
@@ -70,6 +77,65 @@
 
 
 
+int server(void);
+int server(void)
+{
+    int 	rc = 0;
+#ifndef HAVE_WIRINGPI_H
+    long	t = 0;
+#endif
+
+//    if (lockprog((char *)"thermferm")) {
+//	syslog(LOG_NOTICE, "Can't lock");
+//	return 1;
+//    }
+
+    if ((rc = devices_detect())) {
+	syslog(LOG_NOTICE, "Detected %d new devices", rc);
+	wrconfig();
+    }
+
+#ifdef HAVE_WIRINGPI_H
+    rc = piThreadCreate(my_devices_loop);
+#else
+    rc = pthread_create(&threads[t], NULL, my_devices_loop, (void *)t );
+#endif
+    if (rc) {
+	fprintf(stderr, "my_devices_loop thread didn't start rc=%d\n", rc);
+	syslog(LOG_NOTICE, "my_devices_loop thread didn't start rc=%d", rc);
+#ifndef HAVE_WIRINGPI_H
+    } else {
+	t++;
+#endif
+    }
+
+    /*
+     * Initialize units for processing
+     */
+//    for (unit = Config.units; unit; unit = unit->next) {
+	/*
+	 * Safety, turn everything off
+	 */
+//	unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->light_state = 0;
+//	unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0;
+//    }
+
+#ifdef HAVE_WIRINGPI_H
+        piLock(LOCK_LCD);
+	lcdPosition(lcdHandle, 0, 0);
+        lcdPrintf(lcdHandle, "    Brewco %s", VERSION);
+#endif
+	slcdPosition(slcdHandle, 0, 0);
+	slcdPrintf(slcdHandle, "    Brewco %s", VERSION);
+#ifdef HAVE_WIRINGPI_H
+	piUnlock(LOCK_LCD);
+#endif
+
+    return rc;
+}
+
+
+
 int main(int argc, char *argv[])
 {
     int		rc = 0, c, i;
@@ -118,17 +184,19 @@
 #ifdef HAVE_WIRINGPI_H
     if (wiringPiSetup () )
 	return 1;
-
-//    if ((rc = initLCD (Config.lcd_cols, Config.lcd_rows))) {
-//	fprintf(stderr, "Cannot initialize LCD display, rc=%d\n", rc);
-//	return 1;
-//    }
 #endif
 
+    if ((rc = initLCD (Config.lcd_cols, Config.lcd_rows))) {
+	fprintf(stderr, "Cannot initialize LCD display, rc=%d\n", rc);
+	return 1;
+    }
+
+    rc = server();
 
     syslog(LOG_NOTICE, "Finished, rc=%d", rc);
+    if (debug)
+	fprintf(stdout, "Finished, rc=%d\n", rc);
     return rc;
 }
 
 
-

mercurial