Skip to content

Commit

Permalink
Added config option to smooth out the hw values
Browse files Browse the repository at this point in the history
  • Loading branch information
diogotr7 committed Jun 7, 2020
1 parent c743e6a commit 99eb35d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Project-Aurora/Project-Aurora/Settings/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,9 @@ public class Configuration : INotifyPropertyChanged
public float idle_frequency;

//Hardware Monitor
public int HardwareMonitorUpdateRate;
public int HardwareMonitorUpdateRate { get; set; } = 300;
public bool HardwareMonitorUseAverageValues { get; set; } = false;


public VariableRegistry VarRegistry;

Expand Down Expand Up @@ -579,8 +581,6 @@ public Configuration()
idle_amount = 5;
idle_frequency = 2.5f;

HardwareMonitorUpdateRate = 200;

//Debug
BitmapDebugTopMost = false;
HttpDebugTopMost = false;
Expand Down
5 changes: 5 additions & 0 deletions Project-Aurora/Project-Aurora/Settings/Control_Settings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@
<TextBlock Text="GSI Recording Device:" Margin="511,89,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" />
<ComboBox SelectedValue="{Binding Path=GSIAudioCaptureDevice, Mode=TwoWay}" ItemsSource="{x:Static u:AudioDeviceProxy.RecordingDevices}" DisplayMemberPath="Value" SelectedValuePath="Key" Margin="632,86,0,0" Width="185" HorizontalAlignment="Left" VerticalAlignment="Top" />
<TextBlock Text="?" TextDecorations="Underline" ToolTip="The audio recording device that will be used for the local PC information state values. Does not affect visualizer layer." ToolTipService.InitialShowDelay="0" Margin="822,89,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" />

<CheckBox Content="Use average CPU/GPU usage values instead of instant values" ToolTip="This is used to smoothen the harware sensor values, in case the changes are too sudden" HorizontalAlignment="Left" Margin="12,278,0,0" VerticalAlignment="Top" IsChecked="{Binding HardwareMonitorUseAverageValues}" />
<TextBlock HorizontalAlignment="Left" Margin="12,300,0,0" TextWrapping="Wrap" Text="Hardware sensors update rate:" VerticalAlignment="Top" />
<xctk:IntegerUpDown HorizontalAlignment="Left" Height="24" Margin="180,300,0,0" VerticalAlignment="Top" Width="50" Value="{Binding HardwareMonitorUpdateRate}" Maximum="2000" Minimum="100" MouseWheelActiveOnFocus="True" />

</Grid>
</TabItem>
<TabItem Header="Away Effects">
Expand Down
12 changes: 9 additions & 3 deletions Project-Aurora/Project-Aurora/Utils/HardwareMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,25 @@ public static bool TryDump()

private static ISensor FindSensor(this IHardware hardware, string identifier)
{
var result = Array.Find(hardware.Sensors, s => s.Identifier.ToString().Contains(identifier));
var result = hardware.Sensors.OrderBy(s => s.Identifier).FirstOrDefault(s => s.Identifier.ToString().Contains(identifier));
if (result is null)
{
Global.logger.Error(
$"[HardwareMonitor] Failed to find sensor \"{identifier}\" in {hardware.Name} of type {hardware.HardwareType}.");
}
result.ValuesTimeWindow = TimeSpan.FromSeconds(2);
return result;
}

private static ISensor FindSensor(this IHardware hardware, SensorType type)
{
var result = Array.Find(hardware.Sensors, s => s.SensorType == type);
var result = hardware.Sensors.OrderBy(s => s.Identifier).FirstOrDefault(s => s.SensorType == type);
if (result is null)
{
Global.logger.Error(
$"[HardwareMonitor] Failed to find sensor of type \"{type}\" in {hardware.Name} of type {hardware.HardwareType}.");
}
result.ValuesTimeWindow = TimeSpan.FromSeconds(2);
return result;
}

Expand All @@ -119,7 +121,9 @@ protected HardwareUpdater()
_updateTimer.Elapsed += (a, b) =>
{
if (inUse)
hw.Update();
hw?.Update();
if (_updateTimer.Interval != Global.Configuration.HardwareMonitorUpdateRate)
_updateTimer.Interval = Global.Configuration.HardwareMonitorUpdateRate;
};
_updateTimer.Start();
}
Expand All @@ -129,6 +133,8 @@ protected float GetValue(ISensor sensor)
inUse = true;
_useTimer.Stop();
_useTimer.Start();
if (sensor.Values.Any() && Global.Configuration.HardwareMonitorUseAverageValues)
return sensor?.Values?.Average(v => v.Value) ?? 0;
return sensor?.Value ?? 0;
}

Expand Down

0 comments on commit 99eb35d

Please sign in to comment.