Skip to content

Commit

Permalink
✨ Add device ID reporting feature to Eaton UPS driver.
Browse files Browse the repository at this point in the history
  • Loading branch information
hexawyz committed May 4, 2024
1 parent 1e4ae31 commit 3611fc9
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Exo.Devices.Eaton.Ups/UninterruptiblePowerSupplyDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public sealed class UninterruptiblePowerSupplyDriver :
Driver,
IDeviceDriver<IGenericDeviceFeature>,
IDeviceDriver<ISensorDeviceFeature>,
IDeviceIdFeature,
ISensorsFeature,
//ISensorsGroupedQueryFeature,
IBatteryStateDeviceFeature
Expand All @@ -29,6 +30,8 @@ public static async ValueTask<DriverCreationResult<SystemDevicePath>?> CreateAsy
(
ILogger<UninterruptiblePowerSupplyDriver> logger,
ImmutableArray<SystemDevicePath> keys,
ushort productId,
ushort version,
ImmutableArray<DeviceObjectInformation> deviceInterfaces,
ImmutableArray<DeviceObjectInformation> devices,
string friendlyName,
Expand Down Expand Up @@ -157,6 +160,8 @@ CancellationToken cancellationToken
logger,
hidStream,
batteryState,
productId,
version,
friendlyName,
new("EatonUPS", topLevelDeviceName, $"{EatonVendorId:X4}:FFFF", null)
),
Expand All @@ -183,6 +188,8 @@ CancellationToken cancellationToken
private readonly IDeviceFeatureSet<IGenericDeviceFeature> _genericFeatures;
private CancellationTokenSource? _cancellationTokenSource;
private readonly Task _readTask;
private readonly ushort _productId;
private readonly ushort _versionNumber;

ImmutableArray<ISensor> ISensorsFeature.Sensors => _sensors;

Expand All @@ -198,11 +205,15 @@ event Action<Driver, BatteryState> IBatteryStateDeviceFeature.BatteryStateChange

BatteryState IBatteryStateDeviceFeature.BatteryState => BuildBatteryState(Volatile.Read(ref _batteryState));

DeviceId IDeviceIdFeature.DeviceId => DeviceId.ForUsb(EatonVendorId, _productId, _versionNumber);

private UninterruptiblePowerSupplyDriver
(
ILogger<UninterruptiblePowerSupplyDriver> logger,
HidFullDuplexStream stream,
uint batteryState,
ushort productId,
ushort versionNumber,
string friendlyName,
DeviceConfigurationKey configurationKey
) : base(friendlyName, configurationKey)
Expand All @@ -211,13 +222,15 @@ DeviceConfigurationKey configurationKey
_stream = stream;
_buffer = GC.AllocateUninitializedArray<byte>(256, true);
_batteryState = batteryState;
_productId = productId;
_versionNumber = versionNumber;
_sensors =
[
new GroupedSensor<byte>(this, 0x07, 8, 10, 6, PercentLoadSensorId, SensorUnit.Percent, 0, 100),
new SimpleSensor<ushort>(this, 0x0E, 7, OutputVoltageSensorId, SensorUnit.Volts, 0, null),
];
_sensorFeatures = FeatureSet.Create<ISensorDeviceFeature, UninterruptiblePowerSupplyDriver, ISensorsFeature>(this);
_genericFeatures = FeatureSet.Create<IGenericDeviceFeature, UninterruptiblePowerSupplyDriver, IBatteryStateDeviceFeature>(this);
_genericFeatures = FeatureSet.Create<IGenericDeviceFeature, UninterruptiblePowerSupplyDriver, IDeviceIdFeature, IBatteryStateDeviceFeature>(this);
_cancellationTokenSource = new();
_readTask = ReadAsync(_cancellationTokenSource.Token);
}
Expand Down

0 comments on commit 3611fc9

Please sign in to comment.