Skip to content

Commit 0ae7cef

Browse files
committed
Possible fix for #3 (reset USB device before doing anything)
1 parent 9483c9c commit 0ae7cef

4 files changed

Lines changed: 9 additions & 3 deletions

File tree

TheAirBlow.Thor.Library/Platform/Linux.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ public void Initialize(string? id, byte[]? direct = null) {
150150
if ((_deviceFd = Interop.Open(path, Interop.O_RDWR)) < 0)
151151
Interop.HandleError("Failed to open the device for RW");
152152

153+
// Reset USB device
154+
var zeroRef = 0u;
155+
if (Interop.IoCtl(_deviceFd.Value, Interop.USBDEVFS_RESET, ref zeroRef) < 0)
156+
Interop.HandleError("Failed to reset USB device");
157+
153158
// Detach kernel driver if present
154159
var driver = new Interop.GetDriver {
155160
Interface = (int)_interface
@@ -293,6 +298,7 @@ private static uint _IOW(uint type, uint nr, uint size)
293298
public static uint USBDEVFS_GETDRIVER = _IOW('U', 8, (uint)sizeof(GetDriver));
294299
public static uint USBDEVFS_DISCONNECT = _IO('U', 22);
295300
public static uint USBDEVFS_CONNECT = _IO('U', 23);
301+
public static uint USBDEVFS_RESET = _IO('U', 20);
296302

297303
public struct BulkTransfer {
298304
public uint Endpoint;

TheAirBlow.Thor.Library/TheAirBlow.Thor.Library.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
8-
<Version>1.0.2</Version>
8+
<Version>1.0.3</Version>
99
</PropertyGroup>
1010

1111
<ItemGroup>

TheAirBlow.Thor.Shell/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
.MinimumLevel.Information()
1414
.WriteTo.Console()
1515
.CreateLogger();
16-
AnsiConsole.MarkupLine("[green]Welcome to Thor Shell v1.0.2![/]");
16+
AnsiConsole.MarkupLine("[green]Welcome to Thor Shell v1.0.3![/]");
1717
if (!USB.TryGetHandler(out var handler)) {
1818
AnsiConsole.MarkupLine("[red]A USB handler wasn't written for your platform![/]");
1919
AnsiConsole.MarkupLine($"[red]Currently supported platforms: {USB.GetSupported()}.[/]");

TheAirBlow.Thor.Shell/TheAirBlow.Thor.Shell.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<Nullable>enable</Nullable>
88
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
99
<RootNamespace>ThorRewrite.Shell</RootNamespace>
10-
<Version>1.0.2</Version>
10+
<Version>1.0.3</Version>
1111
</PropertyGroup>
1212

1313
<ItemGroup>

0 commit comments

Comments
 (0)