Skip to content

Commit

Permalink
Merge pull request #59 from t3knomanzer/fwinstaller-bootloader-selection
Browse files Browse the repository at this point in the history
Adding option to use old or new bootloader
  • Loading branch information
t3knomanzer authored Jul 12, 2020
2 parents 68a855c + 60e8a63 commit 36f49b7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
11 changes: 9 additions & 2 deletions Desktop/FirmwareInstaller/FirmwareInstaller/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

Expand All @@ -34,12 +35,18 @@
ItemsSource="{Binding Ports}" SelectedValue="{Binding SelectedPort}"
IsEnabled="{Binding IsBusy, Converter={StaticResource Cnv_BoolNegate}}"/>

<!-- Bootloader -->
<Label Grid.Column="0" Grid.Row="2" Content="Old bootloader" Margin="0,5,0,0"/>
<CheckBox Grid.Column="1" Grid.Row="2" Margin="0,5,15,0"
IsChecked="{Binding UseOldBootloader}"
IsEnabled="{Binding IsBusy, Converter={StaticResource Cnv_BoolNegate}}"/>

<!-- Install -->
<Button Grid.Column="1" Grid.Row="2" Content="Install" Margin="0,5,15,0" MinWidth="150" HorizontalAlignment="Right"
<Button Grid.Column="1" Grid.Row="3" Content="Install" Margin="0,5,15,0" MinWidth="150" HorizontalAlignment="Right"
Command="{Binding InstallCommand}"/>

<!-- Log -->
<ScrollViewer x:Name="Ctrl_LogScroll" Grid.ColumnSpan="2" Grid.Row="3" Margin="0,25,0,0">
<ScrollViewer x:Name="Ctrl_LogScroll" Grid.ColumnSpan="2" Grid.Row="4" Margin="0,25,0,0">
<TextBox x:Name="Ctrl_Log" IsReadOnly="True" Text="{Binding Log, Mode=OneWay}" />
</ScrollViewer>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ public InstallService()
/// <param name="filePath">The absolute local file path to the .hex firmware file.</param>
/// <param name="port">The COM port where the maxmix device is plugged in.</param>
/// <returns></returns>
public Task InstallAsync(string filePath, string port)
public Task InstallAsync(string filePath, string port, bool useOldBootloader)
{
return Task.Run(() =>
{
var baudRate = useOldBootloader ? "57600" : "115200";

var processInfo = new ProcessStartInfo
{
FileName = _exeFilePath,
Arguments = $"-C\"{_configFilePath}\" -v -patmega328p -carduino -P{port} -b57600 -D -U\"flash:w:{filePath}:i\"",
Arguments = $"-C\"{_configFilePath}\" -v -patmega328p -carduino -P{port} -b{baudRate} -D -U\"flash:w:{filePath}:i\"",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ internal class MainViewModel : BaseViewModel
#region Constructor
public MainViewModel()
{
_logLock = new object();

_discoveryService = new DiscoveryService();
_discoveryService.Error += OnServiceError;

Expand All @@ -45,8 +47,9 @@ public MainViewModel()
#endregion

#region Consts
private readonly object _logLock;
#endregion

#region Fields
private DiscoveryService _discoveryService;
private DownloadService _downloadService;
Expand All @@ -60,6 +63,7 @@ public MainViewModel()
private IList<string> _logList;
private string _log;
private bool _isBusy = false;
private bool _useOldBootloader = true;
#endregion

#region Properties
Expand Down Expand Up @@ -104,6 +108,21 @@ public string SelectedVersion
}
}

/// <summary>
/// Indicates wether if the connected board is using
/// the new or old bootloader. This is determines the baudrate
/// used to upload the sketch.
/// </summary>
public bool UseOldBootloader
{
get => _useOldBootloader;
set
{
_useOldBootloader = value;
RaisePropertyChanged();
}
}

/// <summary>
/// List of available COM ports.
/// </summary>
Expand Down Expand Up @@ -192,22 +211,28 @@ private async void InitVersions()

private void InitLog()
{
_logList = new List<string>();
lock(_logLock)
_logList = new List<string>();
}

private void ClearLog()
{
_logList.Clear();
lock (_logLock)
_logList.Clear();

Log = string.Empty;
}

private void SendLog(string message)
{
_logList.Add(message);
lock (_logLock)
_logList.Add(message);

var logString = string.Empty;

foreach (var item in _logList)
logString += $"{item}\n";
lock (_logLock)
foreach (var item in _logList)
logString += $"{item}\n";

Log = logString;
}
Expand All @@ -233,7 +258,7 @@ private async void Install()
}

SendLog($"Installing file {versionFilePath} to {_selectedPort}");
await _installService.InstallAsync(versionFilePath, _selectedPort);
await _installService.InstallAsync(versionFilePath, _selectedPort, _useOldBootloader);

IsBusy = false;
}
Expand Down

0 comments on commit 36f49b7

Please sign in to comment.