Report status using LEDs
authorvolpol <volpol@packet-gain.de>
Thu, 23 Aug 2018 17:13:19 +0000 (19:13 +0200)
committervolpol <volpol@packet-gain.de>
Thu, 23 Aug 2018 17:13:19 +0000 (19:13 +0200)
main.c

diff --git a/main.c b/main.c
index c023ec70857d72c44c851e7e20ce0e0698c4bb79..52924d5552e99fe78177ffccd9aa81d45a90bd70 100644 (file)
--- a/main.c
+++ b/main.c
@@ -18,6 +18,7 @@
 #include "hx711.h"
 #include "net.h"
 #include "log.h"
+#include "led.h"
 
 static volatile int force_quit;
 
@@ -126,8 +127,12 @@ static void *deal( void *p ){
 
     net_close( fd );
     //don't touch mix_state if it set to error by receive / mix
-    if (mix_state > 0)
+    if (mix_state > 0){
+        status_ready();
         mix_state  = 0;
+    } else {
+       status_error();
+    }
     return p;
 }
 
@@ -142,6 +147,7 @@ int bbd(void){
                goto DONE;
        }
     mgmt_init();
+    status_ready();
     while (!force_quit){
         if ((as = net_accept( ss )) > 0){
             switch (mix_state){
@@ -149,6 +155,7 @@ int bbd(void){
                     pthread_join( dealer, NULL);
                     dealer = 0;
                     mix_state = as;
+                    status_busy();
                     err = pthread_create( &dealer, NULL, deal, NULL);
                     if (0 != err)
                         EPRINT( "pthread_create failed!\n" );
@@ -156,6 +163,7 @@ int bbd(void){
                         DPRINT ("PID: %lX\n", dealer);
                     break;
                 case -1:
+
                     write (as, "ERROR\n", 6);
                     net_close (as);
                     break;
@@ -182,7 +190,9 @@ int main(void){
 
     //initialize gpio susbsystem
     if (SETUP_OK == (err = setup())){
+        led_init();
         err = bbd();
+        led_deinit();
         cleanup();
     } else {
         fprintf (stderr, "setup: %d\n", err);