-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hydro-asetek] initial asetek hydro aio support
- Loading branch information
1 parent
0e4000b
commit f4f46ca
Showing
16 changed files
with
1,062 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using CorsairLink.SiUsbXpress; | ||
using System; | ||
|
||
namespace CorsairLink.Asetek; | ||
|
||
public class AsetekCoolerProtocol : IAsetekDeviceProxy, IDisposable | ||
{ | ||
private bool _disposedValue; | ||
|
||
public AsetekCoolerProtocol(ISiUsbXpressDevice device) | ||
{ | ||
Device = device; | ||
} | ||
|
||
protected ISiUsbXpressDevice Device { get; } | ||
|
||
protected virtual void Dispose(bool disposing) | ||
{ | ||
if (!_disposedValue) | ||
{ | ||
if (disposing) | ||
{ | ||
Device?.Dispose(); | ||
} | ||
|
||
_disposedValue = true; | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Dispose(disposing: true); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
public virtual AsetekDeviceInfo GetDeviceInfo() | ||
{ | ||
return new AsetekDeviceInfo( | ||
Device.DeviceInfo.DevicePath, | ||
Device.DeviceInfo.VendorId, | ||
Device.DeviceInfo.ProductId, | ||
Device.DeviceInfo.Name, | ||
Device.DeviceInfo.SerialNumber); | ||
} | ||
|
||
public virtual (bool Opened, Exception? Exception) Open() | ||
{ | ||
try | ||
{ | ||
Device.Open(); | ||
return (true, default); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return (false, ex); | ||
} | ||
} | ||
|
||
public virtual void Close() | ||
{ | ||
Device.Close(); | ||
} | ||
|
||
public virtual byte[] WriteAndRead(byte[] buffer) | ||
{ | ||
return Device.WriteAndRead(buffer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace CorsairLink.Asetek; | ||
|
||
public sealed class AsetekDeviceInfo | ||
{ | ||
public AsetekDeviceInfo(string devicePath, int vendorId, int productId, string productName, string serialNumber) | ||
{ | ||
DevicePath = devicePath; | ||
VendorId = vendorId; | ||
ProductId = productId; | ||
ProductName = productName; | ||
SerialNumber = serialNumber; | ||
} | ||
|
||
public string DevicePath { get; } | ||
public int VendorId { get; } | ||
public int ProductId { get; } | ||
public string ProductName { get; } | ||
public string SerialNumber { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<LangVersion>Latest</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\CorsairLink.Abstractions\CorsairLink.Abstractions.csproj" /> | ||
<ProjectReference Include="..\CorsairLink.SiUsbXpress\CorsairLink.SiUsbXpress.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
|
||
namespace CorsairLink.Asetek; | ||
|
||
public interface IAsetekDeviceProxy | ||
{ | ||
AsetekDeviceInfo GetDeviceInfo(); | ||
(bool Opened, Exception? Exception) Open(); | ||
void Close(); | ||
byte[] WriteAndRead(byte[] buffer); | ||
} |
22 changes: 22 additions & 0 deletions
22
src/CorsairLink.SiUsbXpress.Driver/AsetekSiUsbXpressDevice.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace CorsairLink.SiUsbXpress.Driver; | ||
|
||
public class AsetekSiUsbXpressDevice : SiUsbXpressDevice | ||
{ | ||
private const uint DEFAULT_TIMEOUT = 500U; | ||
private const uint READ_BUFFER_SIZE = 32; | ||
|
||
public AsetekSiUsbXpressDevice(SiUsbXpressDeviceInfo deviceInfo) | ||
: base(deviceInfo) | ||
{ | ||
} | ||
|
||
protected override uint ReadBufferSize { get; } = READ_BUFFER_SIZE; | ||
|
||
public override void Open() | ||
{ | ||
base.Open(); | ||
|
||
_ = SiUsbXpressDriver.SI_SetTimeouts(DEFAULT_TIMEOUT, DEFAULT_TIMEOUT); | ||
FlushBuffers(); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/CorsairLink.SiUsbXpress.Driver/FlexSiUsbXpressDevice.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
namespace CorsairLink.SiUsbXpress.Driver; | ||
|
||
public sealed class FlexSiUsbXpressDevice : SiUsbXpressDevice | ||
{ | ||
private const uint MAX_BAUD_RATE = 115200U; | ||
private const uint DEFAULT_TIMEOUT = 200U; | ||
private const uint READ_BUFFER_SIZE = 16; | ||
|
||
public FlexSiUsbXpressDevice(SiUsbXpressDeviceInfo deviceInfo) | ||
: base(deviceInfo) | ||
{ | ||
} | ||
|
||
protected override uint ReadBufferSize { get; } = READ_BUFFER_SIZE; | ||
|
||
public override void Open() | ||
{ | ||
base.Open(); | ||
|
||
_ = SiUsbXpressDriver.SI_SetTimeouts(DEFAULT_TIMEOUT, DEFAULT_TIMEOUT); | ||
FlushBuffers(); | ||
_ = SiUsbXpressDriver.SI_SetBaudRate(DeviceHandle!.DangerousGetHandle(), MAX_BAUD_RATE); | ||
} | ||
|
||
protected override byte[] GetReadBuffer(byte[] originalBuffer) | ||
{ | ||
var buffer = base.GetReadBuffer(originalBuffer); | ||
return !EncodingHelper.HasError(buffer) | ||
? EncodingHelper.DecodeData(buffer) | ||
: throw new SiUsbXpressException("Failed to read - data error."); | ||
} | ||
|
||
protected override byte[] GetWriteBuffer(byte[] originalBuffer) | ||
{ | ||
var buffer = base.GetWriteBuffer(originalBuffer); | ||
return EncodingHelper.EncodeData(buffer); | ||
} | ||
|
||
private AckStatus ReadAckStatus() | ||
=> AckParser.Parse(Read()); | ||
|
||
public override void WriteAndValidate(byte[] buffer) | ||
{ | ||
ThrowIfDeviceNotReady(); | ||
|
||
Write(buffer); | ||
AckStatus ackStatus = ReadAckStatus(); | ||
if (ackStatus != AckStatus.Ok) | ||
throw new SiUsbXpressDeviceAckException(ackStatus); | ||
} | ||
|
||
public override void WriteWhileBusy(byte[] buffer) | ||
{ | ||
ThrowIfDeviceNotReady(); | ||
|
||
AckStatus ackStatus; | ||
do | ||
{ | ||
Write(buffer); | ||
ackStatus = ReadAckStatus(); | ||
} | ||
while (ackStatus == AckStatus.Busy); | ||
if (ackStatus != AckStatus.Ok) | ||
throw new SiUsbXpressDeviceAckException(ackStatus); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.