Browse Source

adding better checks for diu_fd

* checks for >= 0
* ttyDIU maybe should just be deprecated
Abram Connelly 5 years ago
parent
commit
3b86e166b8
1 changed files with 20 additions and 6 deletions
  1. 20 6
      busunit/DIUv2/diu_main.c

+ 20 - 6
busunit/DIUv2/diu_main.c

@@ -556,7 +556,9 @@ message_callback_return handle_status_request(struct message_record *msg, void *
 }
 
 message_callback_return handle_vault_drop(struct message_record *msg, void *param) {
-  if(diu_fd >= 0) { write(diu_fd, "/V:\r", 4); }
+  if(diu_fd >= 0) {
+    write(diu_fd, "/V:\r", 4);
+  }
   return MESSAGE_HANDLED_CONT;
 }
 
@@ -1391,6 +1393,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
 
 
 //DEBUG
+//
 void _test_ws(struct mg_mgr *mgr) {
   struct mg_connection *conn;
   char buf[_SLEN];
@@ -1531,7 +1534,7 @@ int main(int argc, char **argv) {
     //
     if((now - last_diu_clock) > 0) {
 
-      if(diu_fd) {
+      if (diu_fd>=0) {
         set_diu_clock(diu_fd, now);
         last_diu_clock = now;
       }
@@ -1592,8 +1595,15 @@ int main(int argc, char **argv) {
       //draw_menu(mt);
       //
       #ifdef TOUCHSCREEN_QUIET
-        write(diu_fd, "/Q:t\r", 5);    //Un-Quiet the touch screen, now that we've responded to the user we want
-      #endif                    //to hear if they have any further input to give us...
+
+      // to hear if they have any further input to give us...
+      // Un-Quiet the touch screen, now that we've responded to the user we want
+      //
+      if (diu_fd >= 0) {
+        write(diu_fd, "/Q:t\r", 5);
+      }
+
+      #endif
 
     }
 
@@ -1666,7 +1676,9 @@ int main(int argc, char **argv) {
         if(fds[i].revents & (POLLHUP | POLLERR | POLLNVAL)) {
           fprintf(stderr, "This is very odd... Poll returned flags %d on our serial port...\n", fds[i].revents);
 
-          close(diu_fd);
+          if (diu_fd >= 0) {
+            close(diu_fd);
+          }
           diu_fd = -1;
           break;
         }
@@ -1810,7 +1822,9 @@ int main(int argc, char **argv) {
           else {
             fprintf(stderr, "Read from %s returned %d!\n", DRIVER_UI_PORT, read_return);
 
-            close(diu_fd);
+            if (diu_fd >= 0) {
+              close(diu_fd);
+            }
             diu_fd = -1;
             break;
           }