shithub: m8c

Download patch

ref: bbedaf64feaa36c5263c4212ae120eb0d8f899e5
parent: 786f78c671e3920db63ceb7690e585d7ae6103be
author: Jonne Kokkonen <jonne.kokkonen@gmail.com>
date: Sun Sep 21 06:04:58 EDT 2025

force device detection / fix overlays when using integer scaling (#211)

* force device detection result when device is specified on command line

* fix integer scaling render logic: address render target misassignment and ensure proper texture rendering

--- a/README.md
+++ b/README.md
@@ -151,11 +151,13 @@
 2024-02-25 18:39:27.807 m8c[99838:4295527] INFO: Found M8 device: /dev/cu.usbmodem121136001
 ```
 
-And you can specify the preferred device by using
+You can specify the preferred device by using the `--dev` option:
 
 ```sh
 ./m8c --dev /dev/cu.usbmodem124709801
 ```
+
+**Note:** The `--dev` option can force detection of any serial device by name. This is useful if libserialport cannot get the correct USB identifiers, like on some Windows 11 setups for example. You may need to look up the correct device name from Device Manager for example if `--list` does not give you any results.
 
 -----------
 
--- a/src/backends/m8_libserialport.c
+++ b/src/backends/m8_libserialport.c
@@ -65,11 +65,19 @@
   return result;
 }
 
-static int detect_m8_serial_device(const struct sp_port *m8_port) {
+static int detect_m8_serial_device(const struct sp_port *m8_port, const char *preferred_device) {
   // Check the connection method - we want USB serial devices
   const enum sp_transport transport = sp_get_port_transport(m8_port);
-
+ 
   if (transport == SP_TRANSPORT_USB) {
+    // If a preferred device is specified, check if this port matches it
+    if (preferred_device != NULL) {
+      const char *port_name = sp_get_port_name(m8_port);
+      if (strcmp(preferred_device, port_name) == 0) {
+        return 1;  // Force return 1 for preferred device
+      }
+    }
+    
     // Get the USB vendor and product IDs.
     int usb_vid, usb_pid;
     sp_get_port_usb_vid_pid(m8_port, &usb_vid, &usb_pid);
@@ -98,7 +106,7 @@
   for (int i = 0; port_list[i] != NULL; i++) {
     const struct sp_port *port = port_list[i];
 
-    if (detect_m8_serial_device(port)) {
+    if (detect_m8_serial_device(port, NULL)) {
       if (strcmp(sp_get_port_name(port), sp_get_port_name(m8_port)) == 0)
         device_found = 1;
     }
@@ -213,7 +221,7 @@
   for (int i = 0; port_list[i] != NULL; i++) {
     const struct sp_port *port = port_list[i];
 
-    if (detect_m8_serial_device(port)) {
+    if (detect_m8_serial_device(port, preferred_device)) {
       char *port_name = sp_get_port_name(port);
       SDL_Log("Found M8 in %s", port_name);
       sp_copy_port(port, &m8_port);
@@ -318,12 +326,18 @@
     return 1;
   }
 
+  int devices_found = 0;
   for (int i = 0; port_list[i] != NULL; i++) {
     const struct sp_port *port = port_list[i];
 
-    if (detect_m8_serial_device(port)) {
+    if (detect_m8_serial_device(port, NULL)) {
       SDL_Log("Found M8 device: %s", sp_get_port_name(port));
+      devices_found++;
     }
+  }
+  if (devices_found == 0) {
+    SDL_LogInfo(SDL_LOG_CATEGORY_SYSTEM, "No M8 devices found");
+    return 0;
   }
 
   sp_free_port_list(port_list);
--- a/src/render.c
+++ b/src/render.c
@@ -476,7 +476,13 @@
   }
 
   if (conf->integer_scaling) {
-    SDL_SetRenderTarget(rend, main_texture);
+    SDL_SetRenderTarget(rend, NULL);
+
+    // Direct rendering with integer scaling
+    if (!SDL_RenderTexture(rend, main_texture, NULL, NULL)) {
+      SDL_LogCritical(SDL_LOG_CATEGORY_RENDER, "Couldn't render texture: %s", SDL_GetError());
+    }
+
     // Render log overlay (composites if visible)
     log_overlay_render(rend, texture_width, texture_height, texture_scaling_mode, font_mode);
 
@@ -485,12 +491,6 @@
       settings_render_overlay(rend, conf, texture_width, texture_height);
     }
 
-    SDL_SetRenderTarget(rend, NULL);
-
-    // Direct rendering with integer scaling
-    if (!SDL_RenderTexture(rend, main_texture, NULL, NULL)) {
-      SDL_LogCritical(SDL_LOG_CATEGORY_RENDER, "Couldn't render texture: %s", SDL_GetError());
-    }
   } else {
     int window_width, window_height;
     if (!SDL_GetWindowSizeInPixels(win, &window_width, &window_height)) {
--