Skip to content

Commit

Permalink
Wire up auto-flash again (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
fauxpark authored May 9, 2022
1 parent a25b7c8 commit ca8394a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 14 deletions.
38 changes: 31 additions & 7 deletions macos/QMK Toolbox/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -237,7 +245,7 @@ - (IBAction)flashButtonClick:(id)sender {
}
}

- (IBAction)resetButtonClick:(id)sender {
- (void)resetAll {
if ([self.mcuBox indexOfSelectedItem] >= 0) {
NSString *mcu = [self.mcuBox keyForSelectedItem];

Expand Down Expand Up @@ -265,7 +273,7 @@ - (IBAction)resetButtonClick:(id)sender {
}
}

- (IBAction)clearEEPROMButtonClick:(id)sender {
- (void)clearEEPROMAll {
if ([self.mcuBox indexOfSelectedItem] >= 0) {
NSString *mcu = [self.mcuBox keyForSelectedItem];

Expand Down Expand Up @@ -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(), ^{
Expand Down Expand Up @@ -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<BootloaderDevice *> *)findBootloaders {
NSMutableArray<BootloaderDevice *> *bootloaders = [[NSMutableArray alloc] init];

Expand Down
46 changes: 39 additions & 7 deletions windows/QMK Toolbox/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}));
}

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

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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)
{
Expand All @@ -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<BootloaderDevice> FindBootloaders()
{
return usbListener.Devices.Where(d => d is BootloaderDevice).Select(b => b as BootloaderDevice).ToList();
Expand Down

0 comments on commit ca8394a

Please sign in to comment.