From b51493e498b69fb0264e791df8b580b9a95fbd32 Mon Sep 17 00:00:00 2001 From: John Shojaei Date: Wed, 24 Jun 2026 00:00:32 -0700 Subject: [PATCH] Fix intermittent "Cannot find footswitch" on macOS On macOS the device was opened with hid_open(vid, pid, NULL), which opens whichever HID interface hidapi enumerates first. The pedal is a composite device: interface 0 is the keyboard (which macOS refuses to let an unprivileged process open) and interface 1 carries the config protocol. When the keyboard interface enumerated first, the open was denied and the tool printed "Cannot find footswitch ..." -- intermittently, until a reboot reshuffled the enumeration order. Select interface 1 explicitly on all platforms, which is what the non-OSX path already did. Keep a macOS-only fallback to hid_open() for older hidapi (<0.14) that doesn't report interface_number on macOS, so existing setups keep working. Tested on macOS 26.4.1 (arm64) with hidapi 0.15.0: footswitch -r now reads reliably across unplug/replug cycles that previously triggered the failure. --- src/footswitch.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/footswitch.c b/src/footswitch.c index 5b1ba13..bc5195e 100644 --- a/src/footswitch.c +++ b/src/footswitch.c @@ -73,12 +73,10 @@ void usage() { } void init_pid(unsigned short vid, unsigned short pid) { -#ifdef OSX - hid_init(); - dev = hid_open(vid, pid, NULL); -#else struct hid_device_info *info = NULL, *ptr = NULL; hid_init(); + // Config protocol is on interface 1. Interface 0 is the keyboard, which + // macOS won't open, so we can't just hid_open() by vid/pid here. info = hid_enumerate(vid, pid); ptr = info; while (ptr != NULL) { @@ -89,6 +87,12 @@ void init_pid(unsigned short vid, unsigned short pid) { ptr = ptr->next; } hid_free_enumeration(info); +#ifdef OSX + // Older hidapi (<0.14) doesn't report interface_number on macOS, so the + // loop finds nothing -- fall back to opening by vid/pid. + if (dev == NULL) { + dev = hid_open(vid, pid, NULL); + } #endif }