Skip to content
This repository has been archived by the owner on Mar 20, 2023. It is now read-only.

Commit

Permalink
Removed static size definition
Browse files Browse the repository at this point in the history
  • Loading branch information
nefarius committed Aug 30, 2015
1 parent 9054514 commit 8398397
Showing 1 changed file with 39 additions and 9 deletions.
48 changes: 39 additions & 9 deletions ScpControl/Driver/LibusbKWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,30 @@ public enum UsbKPowerPolicy : uint
SuspendDelay = 0x83
}

[StructLayout(LayoutKind.Sequential)]
public struct KISO_PACKET
{
public uint Offset;
public ushort Length;
public ushort Status;
}

public enum KISO_FLAG
{
KISO_FLAG_SET_START_FRAME
}

[StructLayout(LayoutKind.Sequential)]
public struct KISO_CONTEXT
{
public KISO_FLAG Flags;
public uint StartFrame;
public short ErrorCount;
public short NumberOfPackets;
public uint UrbHdrStatus;
public KISO_PACKET IsoPackets;
}

public class LibusbKWrapper : NativeLibraryWrapper<LibusbKWrapper>
{
/// <summary>
Expand All @@ -23,23 +47,26 @@ public bool SetPowerPolicyAutoSuspend(IntPtr handle, bool on = true)
{
var value = Marshal.AllocHGlobal(1);

Marshal.WriteByte(value, (byte) ((on) ? 0x01 : 0x00));

var retval = SetPowerPolicy(handle, UsbKPowerPolicy.AutoSuspend,
1, value);
try
{
Marshal.WriteByte(value, (byte) ((on) ? 0x01 : 0x00));

Marshal.FreeHGlobal(value);

return retval;
return SetPowerPolicy(handle, UsbKPowerPolicy.AutoSuspend,
(uint) Marshal.SizeOf(typeof (byte)), value);
}
finally
{
Marshal.FreeHGlobal(value);
}
}

public bool GetPowerPolicy(IntPtr InterfaceHandle, UsbKPowerPolicy PolicyType, ref uint ValueLength,
private bool GetPowerPolicy(IntPtr InterfaceHandle, UsbKPowerPolicy PolicyType, ref uint ValueLength,
IntPtr Value)
{
return UsbK_GetPowerPolicy(InterfaceHandle, PolicyType, ref ValueLength, Value);
}

public bool SetPowerPolicy(IntPtr InterfaceHandle, UsbKPowerPolicy PolicyType, uint ValueLength,
private bool SetPowerPolicy(IntPtr InterfaceHandle, UsbKPowerPolicy PolicyType, uint ValueLength,
IntPtr Value)
{
return UsbK_SetPowerPolicy(InterfaceHandle, PolicyType, ValueLength, Value);
Expand All @@ -54,5 +81,8 @@ private static extern bool UsbK_GetPowerPolicy(IntPtr InterfaceHandle,
private static extern bool UsbK_SetPowerPolicy(IntPtr InterfaceHandle,
[MarshalAs(UnmanagedType.U4)] UsbKPowerPolicy PolicyType, uint ValueLength,
IntPtr Value);

[DllImport("libusbK.dll", SetLastError = true)]
private static extern bool IsoK_Init(IntPtr IsoContext, int NumberOfPackets, int StartFrame);
}
}

0 comments on commit 8398397

Please sign in to comment.