Skip to content

Commit

Permalink
Add status indicator in settings - closes #3
Browse files Browse the repository at this point in the history
The settings UI now displays the number of Luxafor devices connected.
  • Loading branch information
jschlackman committed Aug 17, 2021
1 parent e7b3271 commit 8dbf2fa
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 9 deletions.
30 changes: 22 additions & 8 deletions LuxOnAir/LFRSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,39 @@ public LFRSettings()
/// <summary>
/// Initilizes the Luxafor hardware
/// </summary>
/// <returns>Debug log message indicating how many devices were found.</returns>
/// <returns>Text message indicating how many devices were found.</returns>
public string InitHardware()
{
string logMsg;

// Now create a new device controller
// Create a new device controller
devices = new DeviceList();
devices.Scan();

return ConnectedDeviceDesc();
}

/// <summary>
/// Gets the number Luxafor devices currently connected.
/// </summary>
/// <returns>Numerical count of devices connected.</returns>
public int ConnectedDeviceCount()
{
return (devices == null ? 0 : devices.Count());
}

/// <summary>
/// Generates a text description of how many Luxafor devices are currently connected.
/// </summary>
/// <returns>User-friendly text describing how many Luxafor devices are connected.</returns>
public string ConnectedDeviceDesc()
{
if (devices.Count() == 0)
{
logMsg = "No Luxafor light available.";
return "No Luxafor light connected.";
}
else
{
logMsg = string.Format("{0} Luxafor light{1} ready.", devices.Count().ToString(), (devices.Count() != 1) ? "s" : "");
return string.Format("{0} Luxafor light{1} connected.", devices.Count().ToString(), (devices.Count() != 1) ? "s" : "");
}

return logMsg;
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions LuxOnAir/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
</TabControl>
<Button x:Name="btnExit" Content="Exit" Margin="0,0,8,10" Height="19" VerticalAlignment="Bottom" Click="ExitMenuItem_Click" HorizontalAlignment="Right" Width="75" ToolTip="Exit the application and turn off lights"/>
<Button x:Name="btnDone" Content="Done" Margin="0,0,88,10" Click="BtnDone_Click" Height="19" VerticalAlignment="Bottom" IsDefault="True" HorizontalAlignment="Right" Width="75" ToolTip="Apply settings and close this window without exiting the application"/>
<Ellipse x:Name="elpStatus" Fill="#FFF4F4F5" Margin="10,0,0,12" Stroke="Black" Height="14" Width="14" VerticalAlignment="Bottom" HorizontalAlignment="Left" StrokeThickness="2"/>
<Label x:Name="lblStatus" Content="Device status" HorizontalAlignment="Left" Margin="26,0,0,6" Height="26" VerticalAlignment="Bottom" IsEnabled="False" Foreground="{DynamicResource {x:Static SystemColors.ControlLightLightBrushKey}}"/>

</Grid>
</Window>
33 changes: 32 additions & 1 deletion LuxOnAir/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Windows.Forms;
using LuxOnAir.Properties;
using System.Management;
using System.Windows.Media;

namespace LuxOnAir
{
Expand Down Expand Up @@ -86,6 +87,9 @@ public MainWindow()
// Initialize Luxafor devices
WriteToDebug(Settings.Default.luxSettings.InitHardware());

// Update the device status UI
UpdateDeviceStatus();

btnMicInUse.Background = Settings.Default.luxSettings.Colors.MicInUse.ToBrush();
btnMicNotInUse.Background = Settings.Default.luxSettings.Colors.MicNotInUse.ToBrush();
btnLocked.Background = Settings.Default.luxSettings.Colors.SessionLocked.ToBrush();
Expand Down Expand Up @@ -160,11 +164,38 @@ private void LFRDevices_Changed(object sender, EventArrivedEventArgs e)
{
WriteToDebug("Hardware change detected.");
WriteToDebug(Settings.Default.luxSettings.InitHardware());


// Update the device status UI
UpdateDeviceStatus();
// Run an icon check now
CheckNotificationIcons();
}

/// <summary>
/// Update the indicator on the mains ettings screen to show how many devices are connected
/// </summary>
private void UpdateDeviceStatus()
{
// Thread-safe UI update
Dispatcher.Invoke(() =>
{
lblStatus.Content = Settings.Default.luxSettings.InitHardware();

if (Settings.Default.luxSettings.ConnectedDeviceCount() == 0)
{
// Red status indicator
elpStatus.Fill = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0x58, 0x58));
elpStatus.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xB7, 0, 0));
}
else
{
// Green status indicator
elpStatus.Fill = new SolidColorBrush(Color.FromArgb(0xFF, 0x55, 0xBB, 0x55));
elpStatus.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0, 0xB6, 0));
}
});
}

/// <summary>
/// Respond to suspend/resume events
/// </summary>
Expand Down

0 comments on commit 8dbf2fa

Please sign in to comment.