shithub: m8c

Download patch

ref: a449d9d5a24fbeeaf3e6fcde2d6af93f59eee32f
parent: e5df91377545372b1481a8d65777d665054140d9
author: smootalicious <smootalicious@gmail.com>
date: Thu Jun 30 21:49:24 EDT 2022

Make zerobyte detection work for hardware M8. Removed check for buttons and check for conf. wait_for_device and just let the port init handle the disconnect.

--- a/main.c
+++ b/main.c
@@ -165,7 +165,6 @@
       // get current inputs
       input_msg_s input = get_input_msg(&conf);
 
-      if (input.value != 0) zerobyte_packets = 0; // don't try to detect disconnect until user stops pressing buttons 
       switch (input.type) {
       case normal:
         if (input.value != prev_input) {
@@ -233,16 +232,12 @@
           zerobyte_packets++;
           if (zerobyte_packets > conf.wait_packets) {
             // i guess it can be assumed that the device has been disconnected
-            if (conf.wait_for_device) {
-              zerobyte_packets = 0; // reset so we dont constantly reset the device if waiting
-              run = WAIT_FOR_DEVICE;
-              close_serial_port(port);
-              port = NULL;
-              break;
-            } else {
-              SDL_LogCritical(SDL_LOG_CATEGORY_ERROR,"Device disconnect detected.");
-              run = QUIT;
-            }
+            zerobyte_packets = 0; // reset so we dont constantly reset the device if waiting
+            run = WAIT_FOR_DEVICE;
+            close_serial_port(port);
+            port = NULL;
+            // we'll make one more loop to see if the device is still there but just sending zero bytes
+            // if it doesn't get detected when resetting the port, it will disconnect
           }
           break;
         }
--