shithub: m8c

Download patch

ref: 36022d5c2f243bebe75dda91cb12591393f87a15
parent: 505fdd155f56a29277bb242b04f6e0c4d4619b69
author: smootalicious <smootalicious@gmail.com>
date: Thu Jun 16 00:21:51 EDT 2022

Bug fix for automatic disconnect detection.  Either disconnectedor if wait_for_device=true, would repeatedly reset the device in the Effects Help screen.

--- a/config.c
+++ b/config.c
@@ -26,6 +26,7 @@
   c.init_use_gpu = 1;    // default to use hardware acceleration
   c.idle_ms = 10;        // default to high performance
   c.wait_for_device = 0; // default to exit if device disconnected
+  c.wait_packets = 1500;   // default zero-byte attempts to disconnect (about 15 sec for default idle_ms)
 
   c.key_up = SDL_SCANCODE_UP;
   c.key_left = SDL_SCANCODE_LEFT;
@@ -76,7 +77,7 @@
 
   SDL_Log("Writing config file to %s", config_path);
 
-  const unsigned int INI_LINE_COUNT = 39;
+  const unsigned int INI_LINE_COUNT = 40;
   const unsigned int LINELEN = 50;
 
   // Entries for the config file
@@ -90,6 +91,7 @@
   snprintf(ini_values[initPointer++], LINELEN, "idle_ms=%d\n", conf->idle_ms);
   snprintf(ini_values[initPointer++], LINELEN, "wait_for_device=%s\n",
            conf->wait_for_device ? "true" : "false");
+  snprintf(ini_values[initPointer++], LINELEN, "wait_packets=%d\n", conf->wait_packets);
   snprintf(ini_values[initPointer++], LINELEN, "[keyboard]\n");
   snprintf(ini_values[initPointer++], LINELEN, "key_up=%d\n", conf->key_up);
   snprintf(ini_values[initPointer++], LINELEN, "key_left=%d\n", conf->key_left);
@@ -204,6 +206,7 @@
   const char *param_gpu = ini_get(ini, "graphics", "use_gpu");
   const char *idle_ms = ini_get(ini, "graphics", "idle_ms");
   const char *param_wait = ini_get(ini, "graphics", "wait_for_device");
+  const char *wait_packets = ini_get(ini, "graphics", "wait_packets");
 
   if (strcmpci(param_fs, "true") == 0) {
     conf->init_fullscreen = 1;
@@ -227,6 +230,8 @@
       conf->wait_for_device = 0;
     }
   }
+  if (wait_packets != NULL)
+    conf->wait_packets = SDL_atoi(wait_packets);
 }
 
 void read_key_config(ini_t *ini, config_params_s *conf) {
--- a/config.h
+++ b/config.h
@@ -12,6 +12,7 @@
   int init_use_gpu;
   int idle_ms;
   int wait_for_device;
+  int wait_packets;
 
   int key_up;
   int key_left;
--- a/main.c
+++ b/main.c
@@ -99,6 +99,7 @@
       if (result == 1) {
         run = RUN;
       } else {
+        SDL_LogCritical(SDL_LOG_CATEGORY_ERROR,"Device not detected on begin loop.");
         run = QUIT;
       }
     }
@@ -115,6 +116,7 @@
         // get current inputs
         input_msg_s input = get_input_msg(&conf);
         if (input.type == special && input.value == msg_quit) {
+          SDL_LogCritical(SDL_LOG_CATEGORY_ERROR,"Input message QUIT.");
           run = QUIT;
         }
 
@@ -136,6 +138,7 @@
               run = RUN;
               screensaver_destroy();
             } else {
+              SDL_LogCritical(SDL_LOG_CATEGORY_ERROR,"Device not detected.");
               run = QUIT;
               screensaver_destroy();
             }
@@ -185,6 +188,7 @@
           prev_input = input.value;
           switch (input.value) {
           case msg_quit:
+            SDL_Log("Received msg_quit from input device.");
             run = 0;
             break;
           case msg_reset_display:
@@ -226,14 +230,16 @@
         } else {
           // zero byte packet, increment counter
           zerobyte_packets++;
-          if (zerobyte_packets > 128) {
+          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;
             }
           }
--