From 28b3466aa633eb5c62092208da9a3591acc96ab4 Mon Sep 17 00:00:00 2001 From: fauxpark Date: Mon, 25 Mar 2024 17:24:02 +1100 Subject: [PATCH] [macOS] Rename console listener to HID listener --- macos/QMK Toolbox.xcodeproj/project.pbxproj | 14 ++++++------- .../HIDConsoleDevice.swift | 0 .../HIDConsoleViewController.swift | 20 +++++++++---------- .../HIDListener.swift} | 18 ++++++++--------- 4 files changed, 26 insertions(+), 26 deletions(-) rename macos/QMK Toolbox/{HIDConsole => HID}/HIDConsoleDevice.swift (100%) rename macos/QMK Toolbox/{HIDConsole => HID}/HIDConsoleViewController.swift (74%) rename macos/QMK Toolbox/{HIDConsole/HIDConsoleListener.swift => HID/HIDListener.swift} (79%) diff --git a/macos/QMK Toolbox.xcodeproj/project.pbxproj b/macos/QMK Toolbox.xcodeproj/project.pbxproj index e6382e80cb..d105b48cc8 100644 --- a/macos/QMK Toolbox.xcodeproj/project.pbxproj +++ b/macos/QMK Toolbox.xcodeproj/project.pbxproj @@ -42,7 +42,7 @@ 3A62C86526A96AED001C655A /* reset_right.eep in Resources */ = {isa = PBXBuildFile; fileRef = 3A62C86326A96AED001C655A /* reset_right.eep */; }; 3A62C86626A96AED001C655A /* reset_left.eep in Resources */ = {isa = PBXBuildFile; fileRef = 3A62C86426A96AED001C655A /* reset_left.eep */; }; 3A708D982848A23300394E52 /* USBListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A708D972848A23300394E52 /* USBListener.swift */; }; - 3A708D9A284901F500394E52 /* HIDConsoleListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A708D99284901F500394E52 /* HIDConsoleListener.swift */; }; + 3A708D9A284901F500394E52 /* HIDListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A708D99284901F500394E52 /* HIDListener.swift */; }; 3A708D9C284916F700394E52 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A708D9B284916F700394E52 /* AppDelegate.swift */; }; 3A7492CC27DF96BF0073A5A0 /* hid_bootloader_cli in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3A7492CB27DF96BF0073A5A0 /* hid_bootloader_cli */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; }; 3A8DE01A284636780012063A /* HIDConsoleDevice.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A8DE019284636780012063A /* HIDConsoleDevice.swift */; }; @@ -134,7 +134,7 @@ 3A62C86326A96AED001C655A /* reset_right.eep */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = reset_right.eep; path = ../../../common/reset_right.eep; sourceTree = ""; }; 3A62C86426A96AED001C655A /* reset_left.eep */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = reset_left.eep; path = ../../../common/reset_left.eep; sourceTree = ""; }; 3A708D972848A23300394E52 /* USBListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = USBListener.swift; sourceTree = ""; }; - 3A708D99284901F500394E52 /* HIDConsoleListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIDConsoleListener.swift; sourceTree = ""; }; + 3A708D99284901F500394E52 /* HIDListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIDListener.swift; sourceTree = ""; }; 3A708D9B284916F700394E52 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 3A7492CB27DF96BF0073A5A0 /* hid_bootloader_cli */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; path = hid_bootloader_cli; sourceTree = ""; }; 3A7770D822BD3B8200398C40 /* libftdi1.2.5.0.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; path = libftdi1.2.5.0.dylib; sourceTree = ""; }; @@ -187,7 +187,7 @@ 092963FA1F5C8B2C004F2D3F /* QMK Toolbox */ = { isa = PBXGroup; children = ( - 3A3DDC4C26AE27F600A04A99 /* HIDConsole */, + 3A3DDC4C26AE27F600A04A99 /* HID */, 3AC739EB26E23A9800D8B258 /* KeyTester */, 3AC7BE4B27254FB800FED7DB /* USB */, 3A708D9B284916F700394E52 /* AppDelegate.swift */, @@ -214,14 +214,14 @@ name = "Supporting Files"; sourceTree = ""; }; - 3A3DDC4C26AE27F600A04A99 /* HIDConsole */ = { + 3A3DDC4C26AE27F600A04A99 /* HID */ = { isa = PBXGroup; children = ( 3A8DE019284636780012063A /* HIDConsoleDevice.swift */, - 3A708D99284901F500394E52 /* HIDConsoleListener.swift */, + 3A708D99284901F500394E52 /* HIDListener.swift */, 3A92873C292CF7A10015D961 /* HIDConsoleViewController.swift */, ); - path = HIDConsole; + path = HID; sourceTree = ""; }; 3A53FB5B268A33F10020BAB0 /* Resources */ = { @@ -375,7 +375,7 @@ buildActionMask = 2147483647; files = ( 3A8DE01A284636780012063A /* HIDConsoleDevice.swift in Sources */, - 3A708D9A284901F500394E52 /* HIDConsoleListener.swift in Sources */, + 3A708D9A284901F500394E52 /* HIDListener.swift in Sources */, 3A92873D292CF7A10015D961 /* HIDConsoleViewController.swift in Sources */, 3A37607A283E769300C19B3F /* KeyView.swift in Sources */, 3A32CF59284141D60016D7B7 /* APM32DFUDevice.swift in Sources */, diff --git a/macos/QMK Toolbox/HIDConsole/HIDConsoleDevice.swift b/macos/QMK Toolbox/HID/HIDConsoleDevice.swift similarity index 100% rename from macos/QMK Toolbox/HIDConsole/HIDConsoleDevice.swift rename to macos/QMK Toolbox/HID/HIDConsoleDevice.swift diff --git a/macos/QMK Toolbox/HIDConsole/HIDConsoleViewController.swift b/macos/QMK Toolbox/HID/HIDConsoleViewController.swift similarity index 74% rename from macos/QMK Toolbox/HIDConsole/HIDConsoleViewController.swift rename to macos/QMK Toolbox/HID/HIDConsoleViewController.swift index 80b4b32695..101dca4182 100644 --- a/macos/QMK Toolbox/HIDConsole/HIDConsoleViewController.swift +++ b/macos/QMK Toolbox/HID/HIDConsoleViewController.swift @@ -1,18 +1,18 @@ import Cocoa -class HIDConsoleViewController: NSViewController, HIDConsoleListenerDelegate { +class HIDConsoleViewController: NSViewController, HIDListenerDelegate { @IBOutlet var consoleListBox: NSComboBox! @IBOutlet var logTextView: LogTextView! override func viewDidLoad() { - consoleListener = HIDConsoleListener() - consoleListener.delegate = self - consoleListener.start() + hidListener = HIDListener() + hidListener.delegate = self + hidListener.start() } override func viewWillDisappear() { - consoleListener.stop() + hidListener.stop() } @IBAction @@ -22,16 +22,16 @@ class HIDConsoleViewController: NSViewController, HIDConsoleListenerDelegate { // MARK: HID Console Devices - var consoleListener: HIDConsoleListener! + var hidListener: HIDListener! var lastReportedDevice: HIDConsoleDevice? - func consoleDeviceDidConnect(_ device: HIDConsoleDevice) { + func hidDeviceDidConnect(_ device: HIDConsoleDevice) { lastReportedDevice = device updateConsoleList() logTextView.logHID("HID console connected: \(device)") } - func consoleDeviceDidDisconnect(_ device: HIDConsoleDevice) { + func hidDeviceDidDisconnect(_ device: HIDConsoleDevice) { lastReportedDevice = nil updateConsoleList() logTextView.logHID("HID console disconnected: \(device)") @@ -39,7 +39,7 @@ class HIDConsoleViewController: NSViewController, HIDConsoleListenerDelegate { func consoleDevice(_ device: HIDConsoleDevice, didReceiveReport report: String) { let selectedDevice = consoleListBox.indexOfSelectedItem - if selectedDevice == 0 || consoleListener.devices[selectedDevice - 1] == device { + if selectedDevice == 0 || hidListener.devices[selectedDevice - 1] == device { if lastReportedDevice != device { logTextView.logHID("\(device.manufacturer ?? "") \(device.product ?? "")") lastReportedDevice = device @@ -53,7 +53,7 @@ class HIDConsoleViewController: NSViewController, HIDConsoleListenerDelegate { consoleListBox.deselectItem(at: selectedItem) consoleListBox.removeAllItems() - consoleListener.devices.forEach { device in + hidListener.devices.forEach { device in consoleListBox.addItem(withObjectValue: device.description) } diff --git a/macos/QMK Toolbox/HIDConsole/HIDConsoleListener.swift b/macos/QMK Toolbox/HID/HIDListener.swift similarity index 79% rename from macos/QMK Toolbox/HIDConsole/HIDConsoleListener.swift rename to macos/QMK Toolbox/HID/HIDListener.swift index 9f26dd99ca..3c0c7ceb40 100644 --- a/macos/QMK Toolbox/HIDConsole/HIDConsoleListener.swift +++ b/macos/QMK Toolbox/HID/HIDListener.swift @@ -4,16 +4,16 @@ import IOKit.hid let CONSOLE_USAGE_PAGE: UInt16 = 0xFF31 let CONSOLE_USAGE: UInt16 = 0x0074 -protocol HIDConsoleListenerDelegate: AnyObject { - func consoleDeviceDidConnect(_ device: HIDConsoleDevice) +protocol HIDListenerDelegate: AnyObject { + func hidDeviceDidConnect(_ device: HIDConsoleDevice) - func consoleDeviceDidDisconnect(_ device: HIDConsoleDevice) + func hidDeviceDidDisconnect(_ device: HIDConsoleDevice) func consoleDevice(_ device: HIDConsoleDevice, didReceiveReport report: String) } -class HIDConsoleListener: HIDConsoleDeviceDelegate { - weak var delegate: HIDConsoleListenerDelegate? +class HIDListener: HIDConsoleDeviceDelegate { + weak var delegate: HIDListenerDelegate? private var hidManager: IOHIDManager @@ -30,12 +30,12 @@ class HIDConsoleListener: HIDConsoleDeviceDelegate { IOHIDManagerOpen(hidManager, IOOptionBits(kIOHIDOptionsTypeNone)) let matchingCallback: IOHIDDeviceCallback = { context, result, sender, device in - let listener: HIDConsoleListener = Unmanaged.fromOpaque(context!).takeUnretainedValue() + let listener: HIDListener = Unmanaged.fromOpaque(context!).takeUnretainedValue() listener.deviceConnected(device) } let removalCallback: IOHIDDeviceCallback = { context, result, sender, device in - let listener: HIDConsoleListener = Unmanaged.fromOpaque(context!).takeUnretainedValue() + let listener: HIDListener = Unmanaged.fromOpaque(context!).takeUnretainedValue() listener.deviceDisconnected(device) } @@ -52,7 +52,7 @@ class HIDConsoleListener: HIDConsoleDeviceDelegate { let consoleDevice = HIDConsoleDevice(device) consoleDevice.delegate = self devices.append(consoleDevice) - delegate?.consoleDeviceDidConnect(consoleDevice) + delegate?.hidDeviceDidConnect(consoleDevice) } func deviceDisconnected(_ device: IOHIDDevice) { @@ -60,7 +60,7 @@ class HIDConsoleListener: HIDConsoleDeviceDelegate { devices = devices.filter { !discardedItems.contains($0) } for d in discardedItems { - delegate?.consoleDeviceDidDisconnect(d) + delegate?.hidDeviceDidDisconnect(d) } }