Skip to content

Commit

Permalink
[macOS] Rename console listener to HID listener
Browse files Browse the repository at this point in the history
  • Loading branch information
fauxpark committed Mar 25, 2024
1 parent d9b256f commit 28b3466
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
14 changes: 7 additions & 7 deletions macos/QMK Toolbox.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -134,7 +134,7 @@
3A62C86326A96AED001C655A /* reset_right.eep */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = reset_right.eep; path = ../../../common/reset_right.eep; sourceTree = "<group>"; };
3A62C86426A96AED001C655A /* reset_left.eep */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = reset_left.eep; path = ../../../common/reset_left.eep; sourceTree = "<group>"; };
3A708D972848A23300394E52 /* USBListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = USBListener.swift; sourceTree = "<group>"; };
3A708D99284901F500394E52 /* HIDConsoleListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIDConsoleListener.swift; sourceTree = "<group>"; };
3A708D99284901F500394E52 /* HIDListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIDListener.swift; sourceTree = "<group>"; };
3A708D9B284916F700394E52 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
3A7492CB27DF96BF0073A5A0 /* hid_bootloader_cli */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; path = hid_bootloader_cli; sourceTree = "<group>"; };
3A7770D822BD3B8200398C40 /* libftdi1.2.5.0.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; path = libftdi1.2.5.0.dylib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -187,7 +187,7 @@
092963FA1F5C8B2C004F2D3F /* QMK Toolbox */ = {
isa = PBXGroup;
children = (
3A3DDC4C26AE27F600A04A99 /* HIDConsole */,
3A3DDC4C26AE27F600A04A99 /* HID */,
3AC739EB26E23A9800D8B258 /* KeyTester */,
3AC7BE4B27254FB800FED7DB /* USB */,
3A708D9B284916F700394E52 /* AppDelegate.swift */,
Expand All @@ -214,14 +214,14 @@
name = "Supporting Files";
sourceTree = "<group>";
};
3A3DDC4C26AE27F600A04A99 /* HIDConsole */ = {
3A3DDC4C26AE27F600A04A99 /* HID */ = {
isa = PBXGroup;
children = (
3A8DE019284636780012063A /* HIDConsoleDevice.swift */,
3A708D99284901F500394E52 /* HIDConsoleListener.swift */,
3A708D99284901F500394E52 /* HIDListener.swift */,
3A92873C292CF7A10015D961 /* HIDConsoleViewController.swift */,
);
path = HIDConsole;
path = HID;
sourceTree = "<group>";
};
3A53FB5B268A33F10020BAB0 /* Resources */ = {
Expand Down Expand Up @@ -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 */,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -22,24 +22,24 @@ 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)")
}

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
Expand All @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -30,12 +30,12 @@ class HIDConsoleListener: HIDConsoleDeviceDelegate {
IOHIDManagerOpen(hidManager, IOOptionBits(kIOHIDOptionsTypeNone))

let matchingCallback: IOHIDDeviceCallback = { context, result, sender, device in
let listener: HIDConsoleListener = Unmanaged<HIDConsoleListener>.fromOpaque(context!).takeUnretainedValue()
let listener: HIDListener = Unmanaged<HIDListener>.fromOpaque(context!).takeUnretainedValue()
listener.deviceConnected(device)
}

let removalCallback: IOHIDDeviceCallback = { context, result, sender, device in
let listener: HIDConsoleListener = Unmanaged<HIDConsoleListener>.fromOpaque(context!).takeUnretainedValue()
let listener: HIDListener = Unmanaged<HIDListener>.fromOpaque(context!).takeUnretainedValue()
listener.deviceDisconnected(device)
}

Expand All @@ -52,15 +52,15 @@ class HIDConsoleListener: HIDConsoleDeviceDelegate {
let consoleDevice = HIDConsoleDevice(device)
consoleDevice.delegate = self
devices.append(consoleDevice)
delegate?.consoleDeviceDidConnect(consoleDevice)
delegate?.hidDeviceDidConnect(consoleDevice)
}

func deviceDisconnected(_ device: IOHIDDevice) {
let discardedItems = devices.filter { $0.hidDevice === device }
devices = devices.filter { !discardedItems.contains($0) }

for d in discardedItems {
delegate?.consoleDeviceDidDisconnect(d)
delegate?.hidDeviceDidDisconnect(d)
}
}

Expand Down

0 comments on commit 28b3466

Please sign in to comment.