Skip to content

Commit

Permalink
Various cosmetic updates
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornekelund committed Aug 31, 2023
1 parent c77fbca commit a6e2824
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 23 deletions.
15 changes: 8 additions & 7 deletions ACOM Controller/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
mc:Ignorable="d"
Title="ACOM Controller" Height="122" Width="510" ResizeMode="CanMinimize" ScrollViewer.VerticalScrollBarVisibility="Disabled" WindowStartupLocation="Manual" Closing="MainWindow_Closed" Closed="MainWindow_Closed" Topmost="True">
<Grid Margin="0,0,0,-1">

<Button x:Name="standbyButton" Content="Standby" HorizontalAlignment="Left" Margin="10,7,0,0" VerticalAlignment="Top" Width="84" Click="StandbyClick" ClickMode="Press" Background="#FF5AADFF" Height="28" FontSize="14" BorderBrush="#FF5AADFF" Foreground="#FF303030" MouseRightButtonDown="StandbyButton_MouseRightButtonDown" Focusable="False"/>
<Button x:Name="operateButton" Content="Operate" HorizontalAlignment="Left" Margin="103,7,0,0" VerticalAlignment="Top" Width="84" ClickMode="Press" Click="DismissErrorClick" Height="28" FontSize="14" BorderBrush="#FF58F049" Foreground="#FF303030" Background="#FF58F049" Focusable="False"/>
<Button x:Name="offButton" Content="Off" HorizontalAlignment="Left" Margin="196,7,0,0" VerticalAlignment="Top" Width="84" Click="OffClick" Background="#FFCCCDCC" Height="28" FontSize="14" BorderBrush="#FFCCCDCC" Foreground="#FF303030" Focusable="False"/>
Expand All @@ -16,20 +17,20 @@
<GroupBox Header="Band" HorizontalAlignment="Left" Height="42" Margin="138,46,0,0" VerticalAlignment="Top" Width="65">
<Label x:Name="bandLabel" Content="--m" HorizontalAlignment="Center" Height="27" Margin="-3,-6,-3,-2" VerticalAlignment="Center" Width="59" Foreground="#FF5A5A5A" HorizontalContentAlignment="Center" FontSize="14"/>
</GroupBox>
<ProgressBar x:Name="tempBar" HorizontalAlignment="Left" Height="20" Margin="294,66,0,0" VerticalAlignment="Top" Width="160" Foreground="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" BorderBrush="#FFE6E6E6"/>
<ProgressBar x:Name="pwrBar" HorizontalAlignment="Left" Height="26" Margin="294,7,0,0" VerticalAlignment="Top" Width="138" Maximum="600" UseLayoutRounding="False" Foreground="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" BorderBrush="#FFE6E6E6"/>
<ProgressBar x:Name="tempBar" HorizontalAlignment="Left" Height="20" Margin="294,66,0,0" VerticalAlignment="Top" Width="160" Foreground="{x:Null}" BorderBrush="#FFE6E6E6"/>
<ProgressBar x:Name="pwrBar" HorizontalAlignment="Left" Height="26" Margin="294,7,0,0" VerticalAlignment="Top" Width="138" Maximum="600" UseLayoutRounding="False" Foreground="{x:Null}" BorderBrush="#FFE6E6E6"/>
<Label x:Name="tempLabel" Content="--C" HorizontalAlignment="Left" Margin="454,63,0,0" VerticalAlignment="Top" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Width="42" Foreground="#FF5A5A5A"/>
<Label x:Name="pwrLabel" Content="--W" HorizontalAlignment="Left" Margin="454,7,0,0" VerticalAlignment="Top" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Width="42" Foreground="#FF5A5A5A"/>
<Label x:Name="fanLabel" Content="" HorizontalAlignment="Left" Height="19" Margin="394,66,0,0" VerticalAlignment="Top" Width="56" FontSize="11" Padding="1" Foreground="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" FontWeight="Bold"/>
<GroupBox Header="Drive" HorizontalAlignment="Left" Height="42" Margin="208,46,0,0" VerticalAlignment="Top" Width="72">
<Label x:Name="driveLabel" Content="--W" HorizontalAlignment="Center" Height="28" Margin="0,-6,1,-2" VerticalAlignment="Center" Width="59" Foreground="#FF5A5A5A" HorizontalContentAlignment="Center" FontSize="14"/>
</GroupBox>
<ProgressBar x:Name="pwrBar_Peak" HorizontalAlignment="Left" Height="26" Margin="431,7,0,0" VerticalAlignment="Top" Width="23" UseLayoutRounding="False" Foreground="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" BorderBrush="#FFE6E6E6"/>
<ProgressBar x:Name="reflBar" HorizontalAlignment="Left" Height="20" Margin="294,39,0,0" VerticalAlignment="Top" Width="122" Foreground="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" BorderBrush="#FFE6E6E6"/>
<ProgressBar x:Name="pwrBar_Red" HorizontalAlignment="Left" Height="26" Margin="431,7,0,0" VerticalAlignment="Top" Width="23" UseLayoutRounding="False" Foreground="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" BorderBrush="#FFE6E6E6"/>
<ProgressBar x:Name="reflBar" HorizontalAlignment="Left" Height="20" Margin="294,39,0,0" VerticalAlignment="Top" Width="122" Foreground="{x:Null}" BorderBrush="#FFE6E6E6"/>
<Label x:Name="reflLabel" Content="---R" HorizontalAlignment="Left" Margin="454,36,0,0" VerticalAlignment="Top" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Width="42" Foreground="#FF5A5A5A"/>
<ProgressBar x:Name="reflBar_Peak" HorizontalAlignment="Left" Height="20" Margin="415,39,0,0" VerticalAlignment="Top" Width="39" UseLayoutRounding="False" Foreground="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" BorderBrush="#FFE6E6E6"/>
<ProgressBar x:Name="reflBar_Red" HorizontalAlignment="Left" Height="20" Margin="415,39,0,0" VerticalAlignment="Top" Width="39" UseLayoutRounding="False" Foreground="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" BorderBrush="#FFE6E6E6"/>
<Label x:Name="swrLabel" Content="" HorizontalAlignment="Left" Height="19" Margin="395,39,0,0" VerticalAlignment="Top" Width="55" FontSize="11" Padding="1" Foreground="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" HorizontalContentAlignment="Right" VerticalContentAlignment="Center"/>
<Button x:Name="errorTextButton" Content="Drive power at wrong time" HorizontalAlignment="Left" Margin="287,28,0,0" VerticalAlignment="Top" Width="206" ClickMode="Press" Click="OperateClick" Height="40" BorderBrush="Black" Foreground="#FF303030" Background="Yellow" BorderThickness="2" FontWeight="Bold" FontSize="14" Visibility="Visible"/>
<Button x:Name="errorTextButton" Content="Drive power at wrong time" HorizontalAlignment="Left" Margin="129,29,0,0" VerticalAlignment="Top" Width="206" ClickMode="Press" Click="OperateClick" Height="40" BorderBrush="Black" Foreground="#FF303030" Background="Yellow" BorderThickness="2" FontWeight="Bold" FontSize="14" Visibility="Visible"/>
<Label x:Name="fanLabel" Content="" HorizontalAlignment="Left" Height="19" Margin="395,67,0,0" VerticalAlignment="Top" Width="55" FontSize="11" Padding="1" Foreground="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" FontWeight="Bold"/>

</Grid>
</Window>
64 changes: 48 additions & 16 deletions ACOM Controller/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public partial class MainWindow : Window
int TemperatureOffset; // For calculating real temperature
bool ShowTemperature; // Whether PA shows temperature in digits
int WarningTemperature; // Temperature at which bar turns red
Brush TempLabelColor;

int errorCode; // Code for error message shown on PA's display

Expand Down Expand Up @@ -111,6 +112,8 @@ public MainWindow()
dispatcherTimer.Tick += new EventHandler(OnTimer);
dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 200);
dispatcherTimer.Start();

TempLabelColor = tempLabel.Foreground;
}

// Clean up and housekeeping at program shutdown
Expand Down Expand Up @@ -219,10 +222,19 @@ public void Configuration(string comPort, string ampModel, bool alwaysontop, boo
{
ProgramWindow.Title = programTitle;
ProgramWindow.Topmost = alwaysontop;
pwrBar.Maximum = NominalForwardPower;
pwrBar_Peak.Maximum = MaxForwardPower - NominalForwardPower;
reflBar.Maximum = NominalReversePower;
reflBar_Peak.Maximum = MaxReversePower - NominalReversePower;

pwrBar.Maximum = NominalForwardPower + 1;
pwrBar.Minimum = 0;
pwrBar_Red.Maximum = MaxForwardPower;
pwrBar_Red.Minimum = NominalForwardPower;

reflBar.Maximum = NominalReversePower - 1;
reflBar.Minimum = 0;
reflBar_Red.Maximum = MaxReversePower;
reflBar_Red.Minimum = NominalReversePower;

tempBar.Minimum = 0;
tempBar.Maximum = 100;
}));

// Send enable telemetry command to PA if port successfully opened
Expand Down Expand Up @@ -338,30 +350,48 @@ private void Port_OnReceiveData(object sender, SerialDataReceivedEventArgs e)
PAtemp = messageBytes[16] + messageBytes[17] * 256 - TemperatureOffset; // extract data from message
PAfan = (messageBytes[69] & 0xf0) >> 4;

PAtemp = 66;

if (PAstatus != 10) // PAstatus 10 means in powering down mode
{
tempBar.Value = PAtemp;
tempLabel.Content = ShowTemperature ? PAtemp.ToString() + "C" : "";

tempBar.Foreground = PAtemp > WarningTemperature ? Brushes.Red : Brushes.Green;
tempBar.Foreground = Brushes.Green;

if (PAtemp < WarningTemperature)
{
tempBar.Foreground = Brushes.Green;
tempLabel.Foreground = TempLabelColor;
tempLabel.FontWeight = FontWeights.Normal;
}
else
{
tempBar.Foreground = Brushes.Red;
tempLabel.Foreground = Brushes.Crimson;
tempLabel.FontWeight = FontWeights.Bold;
}

// Change color on temp bar and label at higher fan speeds
switch (PAfan)
{
case 1:
fanLabel.Content = "Fan";
fanLabel.FontWeight = FontWeights.Normal;
fanLabel.Foreground = Brushes.Gray;
break;
case 2:
fanLabel.Content = "Fan 2";
fanLabel.FontWeight = FontWeights.Bold;
fanLabel.Foreground = Brushes.Gray;
break;
case 3:
fanLabel.Content = "Fan 3";
fanLabel.FontWeight = FontWeights.Bold;
fanLabel.Foreground = Brushes.Black;
break;
case 4:
fanLabel.Content = "FAN 4";
fanLabel.FontWeight = FontWeights.Bold;
fanLabel.Foreground = Brushes.Black;
break;
default:
Expand All @@ -381,15 +411,17 @@ private void Port_OnReceiveData(object sender, SerialDataReceivedEventArgs e)
ReflectedPower[ReflectedPowerPeakIndex++ % ReflectedPowerPeakMemory] = ReflectedPowerCurrent; // save current power in fifo
ReflectedPowerDisplay = ReflectedPower.Max();

//ReflectedPowerDisplay = 150; // For debug

reflLabel.Content = ReflectedPowerDisplay.ToString("0") + "R";

// Lower part of the reflected bar in gray
reflBar.Value = (ReflectedPowerDisplay > NominalReversePower) ? NominalReversePower : ReflectedPowerDisplay;
reflBar.Value = ReflectedPowerDisplay;
reflBar.Foreground = Brushes.Gray;

// Upper part of the reflected bar in red
reflBar_Peak.Value = (ReflectedPowerDisplay > NominalReversePower) ? PApowerDisplay - NominalReversePower : 0;
reflBar_Peak.Foreground = Brushes.Crimson;
reflBar_Red.Value = ReflectedPowerDisplay;
reflBar_Red.Foreground = Brushes.Red;

// Filter and display SWR data
swrCurrent = (messageBytes[26] + messageBytes[27] * 256) / 100.0;
Expand All @@ -405,12 +437,12 @@ private void Port_OnReceiveData(object sender, SerialDataReceivedEventArgs e)
pwrLabel.Content = PApowerDisplay.ToString("0") + "W";

// Lower part of the bar in blue
pwrBar.Value = (PApowerDisplayBar > NominalForwardPower) ? NominalForwardPower : PApowerDisplayBar;
pwrBar.Value = PApowerDisplayBar;
pwrBar.Foreground = Brushes.RoyalBlue;

// Upper part of the bar in red
pwrBar_Peak.Value = (PApowerDisplayBar > NominalForwardPower) ? PApowerDisplayBar - NominalForwardPower : 0.0;
pwrBar_Peak.Foreground = Brushes.Crimson;
pwrBar_Red.Value = PApowerDisplayBar;
pwrBar_Red.Foreground = Brushes.Crimson;

// Calculate average of recent non-zero SWR reports
double swrAverageSum = 0.0;
Expand Down Expand Up @@ -496,14 +528,14 @@ private void Port_OnReceiveData(object sender, SerialDataReceivedEventArgs e)

reflLabel.Content = "--R";
reflBar.Value = 0.0;
reflBar_Peak.Value = 0.0;
reflBar_Red.Value = 0.0;

tempLabel.Content = "--C";
tempBar.Value = 0.0;

pwrLabel.Content = "--W";
pwrBar.Value = 0.0;
pwrBar_Peak.Value = 0.0;
pwrBar_Red.Value = 0.0;
}
}));
}
Expand Down Expand Up @@ -563,14 +595,14 @@ private void OnTimer(object sender, EventArgs e)

reflLabel.Content = "--R";
reflBar.Value = 0.0;
reflBar_Peak.Value = 0.0;
reflBar_Red.Value = 0.0;

tempLabel.Content = "--C";
tempBar.Value = 0.0;

pwrLabel.Content = "--W";
pwrBar.Value = 0.0;
pwrBar_Peak.Value = 0.0;
pwrBar_Red.Value = 0.0;

statusLabel.Foreground = Brushes.Gray;
statusLabel.Content = "OFF";
Expand Down

0 comments on commit a6e2824

Please sign in to comment.