Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ca956f207b | ||
|
|
ad212e7416 | ||
|
|
8c63b93d09 |
+13
-11
@@ -3,7 +3,6 @@ using NAudio.CoreAudioApi.Interfaces;
|
|||||||
using Serilog;
|
using Serilog;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
|
|
||||||
@@ -12,8 +11,7 @@ namespace WorkIndicator;
|
|||||||
internal class AudioDevice : IAudioSessionEventsHandler
|
internal class AudioDevice : IAudioSessionEventsHandler
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly MMDevice _device;
|
private readonly string _friendlyName;
|
||||||
private readonly Dispatcher _dispatcher;
|
|
||||||
private readonly Dictionary<string, AudioSessionControl> _sessions = new();
|
private readonly Dictionary<string, AudioSessionControl> _sessions = new();
|
||||||
|
|
||||||
public delegate void AudioSessionsChangedDelegate();
|
public delegate void AudioSessionsChangedDelegate();
|
||||||
@@ -24,15 +22,14 @@ internal class AudioDevice : IAudioSessionEventsHandler
|
|||||||
{
|
{
|
||||||
_logger = Log.ForContext<AudioDevice>();
|
_logger = Log.ForContext<AudioDevice>();
|
||||||
|
|
||||||
_dispatcher = Dispatcher.CurrentDispatcher;
|
_friendlyName = device.DeviceFriendlyName;
|
||||||
|
|
||||||
_device = device;
|
device.AudioEndpointVolume.OnVolumeNotification += AudioEndpointVolume_OnVolumeNotification;
|
||||||
|
device.AudioSessionManager.AudioSessionControl.RegisterEventClient(this);
|
||||||
|
device.AudioSessionManager.OnSessionCreated += AudioSessionManager_OnSessionCreated;
|
||||||
|
|
||||||
_device.AudioSessionManager.AudioSessionControl.RegisterEventClient(this);
|
device.AudioSessionManager.RefreshSessions();
|
||||||
_device.AudioSessionManager.OnSessionCreated += AudioSessionManager_OnSessionCreated;
|
var sessions = device.AudioSessionManager.Sessions;
|
||||||
|
|
||||||
_device.AudioSessionManager.RefreshSessions();
|
|
||||||
var sessions = _device.AudioSessionManager.Sessions;
|
|
||||||
|
|
||||||
for (var i = 0; i < sessions.Count; i++)
|
for (var i = 0; i < sessions.Count; i++)
|
||||||
{
|
{
|
||||||
@@ -40,6 +37,11 @@ internal class AudioDevice : IAudioSessionEventsHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AudioEndpointVolume_OnVolumeNotification(AudioVolumeNotificationData data)
|
||||||
|
{
|
||||||
|
_logger.Information("AudioEndpointVolume_OnVolumeNotification: {name} {muted}", _friendlyName, data.Muted);
|
||||||
|
}
|
||||||
|
|
||||||
private void AudioSessionManager_OnSessionCreated(object sender, IAudioSessionControl newSession)
|
private void AudioSessionManager_OnSessionCreated(object sender, IAudioSessionControl newSession)
|
||||||
{
|
{
|
||||||
var session = new AudioSessionControl(newSession);
|
var session = new AudioSessionControl(newSession);
|
||||||
@@ -63,7 +65,7 @@ internal class AudioDevice : IAudioSessionEventsHandler
|
|||||||
|
|
||||||
void IAudioSessionEventsHandler.OnVolumeChanged(float volume, bool isMuted)
|
void IAudioSessionEventsHandler.OnVolumeChanged(float volume, bool isMuted)
|
||||||
{
|
{
|
||||||
_dispatcher.Invoke(() => { Debug.WriteLine($"{_device.DeviceFriendlyName}: {volume} {isMuted} {_device.AudioEndpointVolume.Mute}"); });
|
_logger.Information("OnVolumeChanged: {name} {volume} {isMuted}", _friendlyName, volume, isMuted);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IAudioSessionEventsHandler.OnDisplayNameChanged(string displayName)
|
void IAudioSessionEventsHandler.OnDisplayNameChanged(string displayName)
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
namespace WorkIndicator.Delcom
|
namespace WorkIndicator.Delcom
|
||||||
{
|
{
|
||||||
public class StoplightIndicator : IDisposable
|
public class StoplightIndicator : IDisposable
|
||||||
{
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
public enum Light
|
public enum Light
|
||||||
{
|
{
|
||||||
Green,
|
Green,
|
||||||
@@ -25,6 +28,8 @@ namespace WorkIndicator.Delcom
|
|||||||
|
|
||||||
public StoplightIndicator()
|
public StoplightIndicator()
|
||||||
{
|
{
|
||||||
|
_logger = Log.ForContext<StoplightIndicator>();
|
||||||
|
|
||||||
Device = new Delcom();
|
Device = new Delcom();
|
||||||
Device.Open();
|
Device.Open();
|
||||||
|
|
||||||
@@ -74,7 +79,7 @@ namespace WorkIndicator.Delcom
|
|||||||
_yellow = yellow;
|
_yellow = yellow;
|
||||||
_green = green;
|
_green = green;
|
||||||
|
|
||||||
Debug.WriteLine($"Red: {_red}, Yellow: {_yellow}, Green: {_green}");
|
_logger.Information("Red: {red}, Yellow: {yellow}, Green: {green}", _red, _yellow, _green);
|
||||||
|
|
||||||
port1 = port1.SetBitValue((int) Light.Green, green == LightState.Off);
|
port1 = port1.SetBitValue((int) Light.Green, green == LightState.Off);
|
||||||
port1 = port1.SetBitValue((int) Light.Yellow, yellow == LightState.Off);
|
port1 = port1.SetBitValue((int) Light.Yellow, yellow == LightState.Off);
|
||||||
|
|||||||
Generated
+1
-1
@@ -188,7 +188,7 @@ namespace WorkIndicator.Properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Settings.
|
/// Looks up a localized string similar to Settings....
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string NotificationIconContextMenuSettings {
|
public static string NotificationIconContextMenuSettings {
|
||||||
get {
|
get {
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ Would you like to download and install it now?</value>
|
|||||||
<value>Talking</value>
|
<value>Talking</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="NotificationIconContextMenuSettings" xml:space="preserve">
|
<data name="NotificationIconContextMenuSettings" xml:space="preserve">
|
||||||
<value>Settings</value>
|
<value>Settings...</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="StatusFree" xml:space="preserve">
|
<data name="StatusFree" xml:space="preserve">
|
||||||
<value>Free</value>
|
<value>Free</value>
|
||||||
|
|||||||
Reference in New Issue
Block a user