From ca8394a661e717fa685f01188610312c5db76a09 Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 9 May 2022 10:52:49 +1000 Subject: [PATCH] Wire up auto-flash again (#365) --- macos/QMK Toolbox/AppDelegate.m | 38 ++++++++++++++++++++----- windows/QMK Toolbox/MainWindow.cs | 46 ++++++++++++++++++++++++++----- 2 files changed, 70 insertions(+), 14 deletions(-) diff --git a/macos/QMK Toolbox/AppDelegate.m b/macos/QMK Toolbox/AppDelegate.m index 2267db461e..fe9720a15f 100644 --- a/macos/QMK Toolbox/AppDelegate.m +++ b/macos/QMK Toolbox/AppDelegate.m @@ -146,12 +146,20 @@ - (void)updateConsoleList { #pragma mark USB Devices & Bootloaders - (void)bootloaderDeviceDidConnect:(BootloaderDevice *)device { [self.logTextView logBootloader:[NSString stringWithFormat:@"%@ device connected: %@", device.name, device]]; - [self enableUI]; + + if (self.autoFlashEnabled) { + [self flashAll]; + } else { + [self enableUI]; + } } - (void)bootloaderDeviceDidDisconnect:(BootloaderDevice *)device { [self.logTextView logBootloader:[NSString stringWithFormat:@"%@ device disconnnected: %@", device.name, device]]; - [self enableUI]; + + if (!self.autoFlashEnabled) { + [self enableUI]; + } } -(void)bootloaderDevice:(BootloaderDevice *)device didReceiveCommandOutput:(NSString *)data messageType:(MessageType)type { @@ -201,7 +209,7 @@ - (void)setShowAllDevices:(BOOL)showAllDevices { [[NSUserDefaults standardUserDefaults] setBool:showAllDevices forKey:kShowAllDevices]; } -- (IBAction)flashButtonClick:(id)sender { +- (void)flashAll { NSString *file = [self.filepathBox stringValue]; if ([file length] > 0) { @@ -237,7 +245,7 @@ - (IBAction)flashButtonClick:(id)sender { } } -- (IBAction)resetButtonClick:(id)sender { +- (void)resetAll { if ([self.mcuBox indexOfSelectedItem] >= 0) { NSString *mcu = [self.mcuBox keyForSelectedItem]; @@ -265,7 +273,7 @@ - (IBAction)resetButtonClick:(id)sender { } } -- (IBAction)clearEEPROMButtonClick:(id)sender { +- (void)clearEEPROMAll { if ([self.mcuBox indexOfSelectedItem] >= 0) { NSString *mcu = [self.mcuBox keyForSelectedItem]; @@ -297,10 +305,10 @@ - (IBAction)clearEEPROMButtonClick:(id)sender { } } -- (IBAction)setHandednessButtonClick:(id)sender { +- (void)setHandednessAll:(BOOL)left { if ([self.mcuBox indexOfSelectedItem] >= 0) { NSString *mcu = [self.mcuBox keyForSelectedItem]; - NSString *file = [sender tag] == 0 ? @"reset_left.eep" : @"reset_right.eep"; + NSString *file = left ? @"reset_left.eep" : @"reset_right.eep"; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_sync(dispatch_get_main_queue(), ^{ @@ -330,6 +338,22 @@ - (IBAction)setHandednessButtonClick:(id)sender { } } +- (IBAction)flashButtonClick:(id)sender { + [self flashAll]; +} + +- (IBAction)resetButtonClick:(id)sender { + [self resetAll]; +} + +- (IBAction)clearEEPROMButtonClick:(id)sender { + [self clearEEPROMAll]; +} + +- (IBAction)setHandednessButtonClick:(id)sender { + [self setHandednessAll:[sender tag] == 0]; +} + -(NSMutableArray *)findBootloaders { NSMutableArray *bootloaders = [[NSMutableArray alloc] init]; diff --git a/windows/QMK Toolbox/MainWindow.cs b/windows/QMK Toolbox/MainWindow.cs index 6b88c4c2e9..17d4706e6b 100644 --- a/windows/QMK Toolbox/MainWindow.cs +++ b/windows/QMK Toolbox/MainWindow.cs @@ -248,7 +248,15 @@ private void BootloaderDeviceConnected(BootloaderDevice device) Invoke(new Action(() => { logTextBox.LogBootloader($"{device.Name} device connected ({device.Driver}): {device}"); - EnableUI(); + + if (windowState.AutoFlashEnabled) + { + FlashAllAsync(); + } + else + { + EnableUI(); + } })); } @@ -257,7 +265,11 @@ private void BootloaderDeviceDisconnected(BootloaderDevice device) Invoke(new Action(() => { logTextBox.LogBootloader($"{device.Name} device disconnected ({device.Driver}): {device}"); - EnableUI(); + + if (!windowState.AutoFlashEnabled) + { + EnableUI(); + } })); } @@ -318,7 +330,7 @@ private void ShowAllDevicesEnabledChanged(object sender, PropertyChangedEventArg } } - private async void FlashButton_Click(object sender, EventArgs e) + private async void FlashAllAsync() { string selectedMcu = (string)mcuBox.SelectedValue; string filePath = filepathBox.Text; @@ -347,7 +359,7 @@ private async void FlashButton_Click(object sender, EventArgs e) } } - private async void ResetButton_Click(object sender, EventArgs e) + private async void ResetAllAsync() { string selectedMcu = (string)mcuBox.SelectedValue; @@ -370,7 +382,7 @@ private async void ResetButton_Click(object sender, EventArgs e) } } - private async void ClearEepromButton_Click(object sender, EventArgs e) + private async void ClearEepromAllAsync() { string selectedMcu = (string)mcuBox.SelectedValue; @@ -395,10 +407,10 @@ private async void ClearEepromButton_Click(object sender, EventArgs e) } } - private async void SetHandednessButton_Click(object sender, EventArgs e) + private async void SetHandednessAllAsync(bool left) { string selectedMcu = (string)mcuBox.SelectedValue; - string file = sender == eepromLeftToolStripMenuItem ? "reset_left.eep" : "reset_right.eep"; + string file = left ? "reset_left.eep" : "reset_right.eep"; if (!windowState.AutoFlashEnabled) { @@ -421,6 +433,26 @@ private async void SetHandednessButton_Click(object sender, EventArgs e) } } + private void FlashButton_Click(object sender, EventArgs e) + { + FlashAllAsync(); + } + + private void ResetButton_Click(object sender, EventArgs e) + { + ResetAllAsync(); + } + + private void ClearEepromButton_Click(object sender, EventArgs e) + { + ClearEepromAllAsync(); + } + + private void SetHandednessButton_Click(object sender, EventArgs e) + { + SetHandednessAllAsync(sender == eepromLeftToolStripMenuItem); + } + private List FindBootloaders() { return usbListener.Devices.Where(d => d is BootloaderDevice).Select(b => b as BootloaderDevice).ToList();