|
|
@ -12,9 +12,11 @@ namespace hass_workstation_service.Domain.Sensors
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class CurrentVolumeSensor : AbstractSensor
|
|
|
|
public class CurrentVolumeSensor : AbstractSensor
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private MMDeviceEnumerator DevEnum;
|
|
|
|
private MMDeviceEnumerator deviceEnumerator;
|
|
|
|
|
|
|
|
private MMDeviceCollection devices;
|
|
|
|
public CurrentVolumeSensor(MqttPublisher publisher, int? updateInterval = null, string name = "CurrentVolume", Guid id = default(Guid)) : base(publisher, name ?? "CurrentVolume", updateInterval ?? 10, id) {
|
|
|
|
public CurrentVolumeSensor(MqttPublisher publisher, int? updateInterval = null, string name = "CurrentVolume", Guid id = default(Guid)) : base(publisher, name ?? "CurrentVolume", updateInterval ?? 10, id) {
|
|
|
|
this.DevEnum = new MMDeviceEnumerator();
|
|
|
|
this.deviceEnumerator = new MMDeviceEnumerator();
|
|
|
|
|
|
|
|
this.devices = deviceEnumerator.EnumerateAudioEndPoints(EDataFlow.eRender, DEVICE_STATE.DEVICE_STATE_ACTIVE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public override SensorDiscoveryConfigModel GetAutoDiscoveryConfig()
|
|
|
|
public override SensorDiscoveryConfigModel GetAutoDiscoveryConfig()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -30,17 +32,11 @@ namespace hass_workstation_service.Domain.Sensors
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[DllImport("winmm.dll")]
|
|
|
|
|
|
|
|
public static extern int waveOutGetVolume(IntPtr hwo, out uint dwVolume);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override string GetState()
|
|
|
|
public override string GetState()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var collection = DevEnum.EnumerateAudioEndPoints(EDataFlow.eRender, DEVICE_STATE.DEVICE_STATE_ACTIVE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<float> peaks = new List<float>();
|
|
|
|
List<float> peaks = new List<float>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (MMDevice device in devices)
|
|
|
|
foreach (MMDevice device in collection)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
peaks.Add(device.AudioMeterInformation.PeakValues[0]);
|
|
|
|
peaks.Add(device.AudioMeterInformation.PeakValues[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|