Skip to content

Commit

Permalink
Merge pull request #370 from WildernessLabs/v2
Browse files Browse the repository at this point in the history
V2
  • Loading branch information
jorgedevs authored Oct 5, 2023
2 parents 65c611d + 188d84c commit e501bb4
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions Source/v2/Meadow.UsbLib/LibUsbDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,26 @@ public class LibUsbProvider : ILibUsbProvider
// public const string UsbStmName = "STM32 BOOTLOADER";
private const int UsbBootLoaderVendorID = 1155;

internal static UsbContext _context;
internal static List<ILibUsbDevice>? _devices;
static LibUsbProvider()
{
// only ever create one of these - there's a bug in the LibUsbDotNet library and when this disposes, things go sideways
_context = new UsbContext();
}

public List<ILibUsbDevice> GetDevicesInBootloaderMode()
{
UsbContext context = new UsbContext();
return context
.List()
.Where(d => d.Info.VendorId == UsbBootLoaderVendorID)
.Select(d => new LibUsbDevice(d))
.ToList<ILibUsbDevice>();
if (_devices == null)
{
_devices = _context
.List()
.Where(d => d.Info.VendorId == UsbBootLoaderVendorID)
.Select(d => new LibUsbDevice(d))
.ToList<ILibUsbDevice>();
}

return _devices;
}

public class LibUsbDevice : ILibUsbDevice
Expand Down

0 comments on commit e501bb4

Please sign in to comment.