Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 #367

Merged
merged 5 commits into from
Oct 4, 2023
Merged

V2 #367

Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
libusb bug workaround
ctacke committed Oct 4, 2023
commit 2399e23d83179118ebda931a0b91c6130516628b
Original file line number Diff line number Diff line change
@@ -76,17 +76,18 @@ protected override async ValueTask ExecuteCommand()
var initialPorts = await MeadowConnectionManager.GetSerialPorts();

// get the device's serial number via DFU - we'll need it to find the device after it resets
ILibUsbDevice libUsbDevice;
try
{
_libUsbDevice = GetLibUsbDeviceForCurrentEnvironment();
libUsbDevice = GetLibUsbDeviceForCurrentEnvironment();
}
catch (Exception ex)
{
Logger?.LogError(ex.Message);
return;
}

var serial = _libUsbDevice.GetDeviceSerialNumber();
var serial = libUsbDevice.GetDeviceSerialNumber();

// no connection is required here - in fact one won't exist
// unless maybe we add a "DFUConnection"?
@@ -161,30 +162,36 @@ protected override async ValueTask ExecuteCommand()

private ILibUsbDevice GetLibUsbDeviceForCurrentEnvironment()
{
ILibUsbProvider provider;

// TODO: read the settings manager to decide which provider to use (default to non-classic)
var setting = Settings.GetAppSetting(SettingsManager.PublicSettings.LibUsb);
if (setting == "classic")
{
provider = new ClassicLibUsbProvider();
}
else
if (_libUsbDevice == null)
{
provider = new LibUsbProvider();
}
ILibUsbProvider provider;

var devices = provider.GetDevicesInBootloaderMode();
// TODO: read the settings manager to decide which provider to use (default to non-classic)
var setting = Settings.GetAppSetting(SettingsManager.PublicSettings.LibUsb);
if (setting == "classic")
{
provider = new ClassicLibUsbProvider();
}
else
{
provider = new LibUsbProvider();
}

switch (devices.Count)
{
case 0:
throw new Exception("No device found in bootloader mode");
case 1:
return devices[0];
default:
throw new Exception("Multiple devices found in bootloader mode. Disconnect all but one");
var devices = provider.GetDevicesInBootloaderMode();

switch (devices.Count)
{
case 0:
throw new Exception("No device found in bootloader mode");
case 1:
_libUsbDevice = devices[0];
break;
default:
throw new Exception("Multiple devices found in bootloader mode. Disconnect all but one");
}
}

return _libUsbDevice;
}

private async Task<FirmwarePackage?> GetSelectedPackage()
Loading