Skip to content

Commit

Permalink
fix for refreshing connection after DFU
Browse files Browse the repository at this point in the history
  • Loading branch information
ctacke committed Oct 4, 2023
1 parent 2ebf890 commit 2360d40
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
11 changes: 8 additions & 3 deletions Source/v2/Meadow.Cli/Commands/Current/BaseDeviceCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ public BaseDeviceCommand(MeadowConnectionManager connectionManager, ILoggerFacto
ConnectionManager = connectionManager;
}

public override async ValueTask ExecuteAsync(IConsole console)
protected async Task RefreshConnection()
{
SetConsole(console);

CurrentConnection = ConnectionManager.GetCurrentConnection();

if (CurrentConnection != null)
Expand Down Expand Up @@ -61,4 +59,11 @@ public override async ValueTask ExecuteAsync(IConsole console)
Logger?.LogError("Current Connnection Unavailable");
}
}

public override async ValueTask ExecuteAsync(IConsole console)
{
SetConsole(console);

await RefreshConnection();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using CliFx.Infrastructure;
using Meadow.Cli;
using Meadow.CLI.Core.Internals.Dfu;
using Meadow.Hcom;
using Meadow.LibUsb;
using Meadow.Software;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -84,7 +83,7 @@ public override async ValueTask ExecuteAsync(IConsole console)
}
catch (Exception ex)
{
Logger.LogError(ex.Message);
Logger?.LogError(ex.Message);
return;
}

Expand All @@ -99,13 +98,13 @@ public override async ValueTask ExecuteAsync(IConsole console)
}
catch (Exception ex)
{
Logger.LogError($"Exception type: {ex.GetType().Name}");
Logger?.LogError($"Exception type: {ex.GetType().Name}");

// TODO: scope this to the right exception type for Win 10 access violation thing
// TODO: catch the Win10 DFU error here and change the global provider configuration to "classic"
Settings.SaveSetting(SettingsManager.PublicSettings.LibUsb, "classic");

Logger.LogWarning("This machine requires an older version of libusb. Not to worry, I'll make the change for you, but you will have to re-run this 'firmware write' command.");
Logger?.LogWarning("This machine requires an older version of libusb. Not to worry, I'll make the change for you, but you will have to re-run this 'firmware write' command.");
return;
}

Expand All @@ -125,9 +124,13 @@ public override async ValueTask ExecuteAsync(IConsole console)
newPort = ports.Except(initialPorts).FirstOrDefault();
}

Logger?.LogInformation($"Meadow found at {newPort}");

// configure the route to that port for the user
Settings.SaveSetting(SettingsManager.PublicSettings.Route, newPort);

await RefreshConnection();

if (CurrentConnection == null)
{
Logger?.LogError($"No connection path is defined");
Expand Down

0 comments on commit 2360d40

Please sign in to comment.