Skip to content

Commit

Permalink
Possible fix for #3 (reset USB device before doing anything)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAirBlow committed Jun 29, 2023
1 parent 9483c9c commit 0ae7cef
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions TheAirBlow.Thor.Library/Platform/Linux.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ public void Initialize(string? id, byte[]? direct = null) {
if ((_deviceFd = Interop.Open(path, Interop.O_RDWR)) < 0)
Interop.HandleError("Failed to open the device for RW");

// Reset USB device
var zeroRef = 0u;
if (Interop.IoCtl(_deviceFd.Value, Interop.USBDEVFS_RESET, ref zeroRef) < 0)
Interop.HandleError("Failed to reset USB device");

// Detach kernel driver if present
var driver = new Interop.GetDriver {
Interface = (int)_interface
Expand Down Expand Up @@ -293,6 +298,7 @@ private static uint _IOW(uint type, uint nr, uint size)
public static uint USBDEVFS_GETDRIVER = _IOW('U', 8, (uint)sizeof(GetDriver));
public static uint USBDEVFS_DISCONNECT = _IO('U', 22);
public static uint USBDEVFS_CONNECT = _IO('U', 23);
public static uint USBDEVFS_RESET = _IO('U', 20);

public struct BulkTransfer {
public uint Endpoint;
Expand Down
2 changes: 1 addition & 1 deletion TheAirBlow.Thor.Library/TheAirBlow.Thor.Library.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Version>1.0.2</Version>
<Version>1.0.3</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion TheAirBlow.Thor.Shell/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
.MinimumLevel.Information()
.WriteTo.Console()
.CreateLogger();
AnsiConsole.MarkupLine("[green]Welcome to Thor Shell v1.0.2![/]");
AnsiConsole.MarkupLine("[green]Welcome to Thor Shell v1.0.3![/]");
if (!USB.TryGetHandler(out var handler)) {
AnsiConsole.MarkupLine("[red]A USB handler wasn't written for your platform![/]");
AnsiConsole.MarkupLine($"[red]Currently supported platforms: {USB.GetSupported()}.[/]");
Expand Down
2 changes: 1 addition & 1 deletion TheAirBlow.Thor.Shell/TheAirBlow.Thor.Shell.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RootNamespace>ThorRewrite.Shell</RootNamespace>
<Version>1.0.2</Version>
<Version>1.0.3</Version>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 0ae7cef

Please sign in to comment.