private async Task FlashHexFileAsync(string filename) { Console.WriteLine($"Preparing to flash {filename}"); var progress = new Progress <string>(); try { LogItems = new ObservableCollection <LogEntry>(); IsBusy = true; var arduboy = new Arduboy(); progress.ProgressChanged += Progress_ProgressChanged; await arduboy.FlashHexFileAsync(filename, progress); } catch (Exception ex) { LogManager.GetCurrentClassLogger() .Error($"Failed to flash hex '{filename}': {ex.Message}"); AddLogEntry(ex.Message, true); Console.WriteLine(ex); } finally { await Task.Delay(3000); IsBusy = false; FlashHexCommand.RaiseCanExecuteChanged(); progress.ProgressChanged -= Progress_ProgressChanged; } }
private async Task UploadHexOrArchive(string filename) { BusyTextLabel.StringValue = ""; UploadArchiveButton.Enabled = false; UploadSelectedHexArchiveButton.Enabled = false; if (!String.IsNullOrWhiteSpace(filename)) { if (filename.EndsWith(("arduboy"), StringComparison.Ordinal)) { var hexArchive = HexArchive.FromFile((filename)); if (hexArchive.HasValue) { var hexData = hexArchive.Value.ExtactHexData(); filename = Path.GetTempFileName(); File.WriteAllBytes(filename, hexData); } } BusyIndicator.StartAnimation(this); BusyTextLabel.StringValue = "Uploading..."; await Task.Run(() => { var arduboy = new Arduboy(); if (arduboy.TryGetBootloader(out var bootloader)) { Debug.WriteLine($"Bootloader found: {bootloader.ComName}"); var avrdude = new AvrDudeInvoker(filename, bootloader.ComName); var progress = new Progress <string>(i => Debug.WriteLine((i))); avrdude.Invoke(progress); InvokeOnMainThread(() => BusyTextLabel.StringValue = "Upload complete."); } else { InvokeOnMainThread(() => BusyTextLabel.StringValue = "Upload failed, Arduboy bootloader not found"); } }); BusyIndicator.StopAnimation(this); UploadArchiveButton.Enabled = true; UploadSelectedHexArchiveButton.Enabled = true; } }