Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move HID console output to separate window #388

Merged
merged 5 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions macos/QMK Toolbox.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
3A8DE01A284636780012063A /* HIDConsoleDevice.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A8DE019284636780012063A /* HIDConsoleDevice.swift */; };
3A8F9EFF26E75012007480A7 /* KeyTesterWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3A8F9F0126E75012007480A7 /* KeyTesterWindow.xib */; };
3A8F9F0226E7501E007480A7 /* KeyView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3A8F9F0426E7501E007480A7 /* KeyView.xib */; };
3A928718292CA8770015D961 /* HIDConsoleWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3A928717292CA8770015D961 /* HIDConsoleWindow.xib */; };
3A92871A292CAAC70015D961 /* HIDConsoleWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A928719292CAAC70015D961 /* HIDConsoleWindow.swift */; };
3AA5D3472803FCE1008121E4 /* Colors.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3AA5D3462803FCE1008121E4 /* Colors.xcassets */; };
3AA7F96B283BCD2E009FFDD5 /* BootloaderType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AA7F96A283BCD2E009FFDD5 /* BootloaderType.swift */; };
3AAB20AB283BEEC700029ABD /* LogTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AAB20AA283BEEC700029ABD /* LogTextView.swift */; };
Expand Down Expand Up @@ -121,6 +123,8 @@
3A8DE019284636780012063A /* HIDConsoleDevice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIDConsoleDevice.swift; sourceTree = "<group>"; };
3A8F9F0026E75012007480A7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/KeyTesterWindow.xib; sourceTree = "<group>"; };
3A8F9F0326E7501E007480A7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/KeyView.xib; sourceTree = "<group>"; };
3A928717292CA8770015D961 /* HIDConsoleWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = HIDConsoleWindow.xib; sourceTree = "<group>"; };
3A928719292CAAC70015D961 /* HIDConsoleWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIDConsoleWindow.swift; sourceTree = "<group>"; };
3AA5D3462803FCE1008121E4 /* Colors.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Colors.xcassets; sourceTree = "<group>"; };
3AA7F96A283BCD2E009FFDD5 /* BootloaderType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BootloaderType.swift; sourceTree = "<group>"; };
3AAB20AA283BEEC700029ABD /* LogTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogTextView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -196,6 +200,8 @@
children = (
3A8DE019284636780012063A /* HIDConsoleDevice.swift */,
3A708D99284901F500394E52 /* HIDConsoleListener.swift */,
3A928719292CAAC70015D961 /* HIDConsoleWindow.swift */,
3A928717292CA8770015D961 /* HIDConsoleWindow.xib */,
);
path = HIDConsole;
sourceTree = "<group>";
Expand Down Expand Up @@ -333,6 +339,7 @@
092964021F5C8B2C004F2D3F /* Assets.xcassets in Resources */,
3AA5D3472803FCE1008121E4 /* Colors.xcassets in Resources */,
3A8F9EFF26E75012007480A7 /* KeyTesterWindow.xib in Resources */,
3A928718292CA8770015D961 /* HIDConsoleWindow.xib in Resources */,
3A8F9F0226E7501E007480A7 /* KeyView.xib in Resources */,
092964051F5C8B2C004F2D3F /* MainMenu.xib in Resources */,
09522BBB1F6216BA00AEBC5E /* avrdude.conf in Resources */,
Expand Down Expand Up @@ -365,6 +372,7 @@
3A32CF59284141D60016D7B7 /* APM32DFUDevice.swift in Sources */,
3A32CF55284140E30016D7B7 /* AtmelDFUDevice.swift in Sources */,
3A32CF532841409B0016D7B7 /* AtmelSAMBADevice.swift in Sources */,
3A92871A292CAAC70015D961 /* HIDConsoleWindow.swift in Sources */,
3A32CF57284141680016D7B7 /* AVRISPDevice.swift in Sources */,
3A32CF4B28412C420016D7B7 /* BootloaderDevice.swift in Sources */,
3A32CF512841403B0016D7B7 /* BootloadHIDDevice.swift in Sources */,
Expand Down
64 changes: 12 additions & 52 deletions macos/QMK Toolbox/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import Cocoa

@main
class AppDelegate: NSObject, NSApplicationDelegate, HIDConsoleListenerDelegate, USBListenerDelegate {
class AppDelegate: NSObject, NSApplicationDelegate, USBListenerDelegate {
@IBOutlet var window: QMKWindow!
@IBOutlet var filepathBox: NSComboBox!
@IBOutlet var mcuBox: MicrocontrollerSelector!
@IBOutlet var logTextView: LogTextView!
@IBOutlet var clearMenuItem: NSMenuItem!
@IBOutlet var consoleListBox: NSComboBox!

var keyTesterWindowController: NSWindowController!
var hidConsoleWindowController: NSWindowController!

@objc dynamic var autoFlashEnabled: Bool = false {
didSet {
Expand Down Expand Up @@ -73,10 +73,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, HIDConsoleListenerDelegate,
usbListener = USBListener()
usbListener.delegate = self
usbListener.start()

consoleListener = HIDConsoleListener()
consoleListener.delegate = self
consoleListener.start()
}

func loadRecentDocuments() {
Expand All @@ -102,50 +98,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, HIDConsoleListenerDelegate,

func applicationWillTerminate(_ notification: Notification) {
usbListener.stop()
consoleListener.stop()
}

// MARK: HID Console

var consoleListener: HIDConsoleListener!
var lastReportedDevice: HIDConsoleDevice?

func consoleDeviceDidConnect(_ device: HIDConsoleDevice) {
lastReportedDevice = device
updateConsoleList()
logTextView.logHID("HID console connected: \(device)")
}

func consoleDeviceDidDisconnect(_ 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 lastReportedDevice != device {
logTextView.logHID("\(device.manufacturer ?? "") \(device.product ?? "")")
lastReportedDevice = device
}
}
logTextView.logHIDOutput(report)
}

func updateConsoleList() {
let selectedItem = consoleListBox.indexOfSelectedItem >= 0 ? consoleListBox.indexOfSelectedItem : 0
consoleListBox.deselectItem(at: selectedItem)
consoleListBox.removeAllItems()

consoleListener.devices.forEach { device in
consoleListBox.addItem(withObjectValue: device.description)
}

if consoleListBox.numberOfItems > 0 {
consoleListBox.insertItem(withObjectValue: "(All connected devices)", at: 0)
consoleListBox.selectItem(at: consoleListBox.numberOfItems > selectedItem ? selectedItem : 0)
}
}

// MARK: USB Devices & Bootloaders
Expand Down Expand Up @@ -391,6 +343,11 @@ class AppDelegate: NSObject, NSApplicationDelegate, HIDConsoleListenerDelegate,
canClearEEPROM = false
}

@IBAction
func clearButtonClick(_ sender: Any) {
logTextView.string = ""
}

@IBAction
func keyTesterButtonClick(_ sender: Any) {
if keyTesterWindowController == nil {
Expand All @@ -400,7 +357,10 @@ class AppDelegate: NSObject, NSApplicationDelegate, HIDConsoleListenerDelegate,
}

@IBAction
func clearButtonClick(_ sender: Any) {
logTextView.string = ""
func hidConsoleButtonClick(_ sender: Any) {
if hidConsoleWindowController == nil {
hidConsoleWindowController = NSWindowController(windowNibName: "HIDConsoleWindow")
}
hidConsoleWindowController.showWindow(self)
}
}
Loading