From dace999511d2c11439aaa4b883a6adf434d9b536 Mon Sep 17 00:00:00 2001 From: Sasa Karanovic Date: Mon, 5 Feb 2024 23:58:51 -0500 Subject: [PATCH] Changing logger options to increase log file size. Fixing dial value scaling. --- VU1WPF/ClassConfigurationManager.cs | 6 ++++-- VU1WPF/MainWindow.xaml.cs | 27 ++++++++++++++------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/VU1WPF/ClassConfigurationManager.cs b/VU1WPF/ClassConfigurationManager.cs index 83637b6..73471c6 100644 --- a/VU1WPF/ClassConfigurationManager.cs +++ b/VU1WPF/ClassConfigurationManager.cs @@ -31,17 +31,18 @@ public ClassConfigurationManager() LoadConfigFile(); - Log.Information(String.Format("Dial update period: {0}", localConfig.dialUpdatePeriod)); + Log.Information(String.Format("Dial update period: {0} seconds", localConfig.dialUpdatePeriod)); // Check update period if (localConfig.dialUpdatePeriod == 0 || localConfig.dialUpdatePeriod < 0.2F) { - Log.Error("Dial update period set to `{0}`. Limiting to 0.2 seconds.", localConfig.dialUpdatePeriod); + Log.Error("Config reqests invalid dial update period of `{0}`. Limiting to 0.2 seconds.", localConfig.dialUpdatePeriod); localConfig.dialUpdatePeriod = 0.2F; } if (localConfig.masterKey == null || localConfig.masterKey == String.Empty) { + Log.Error("Invalid master key `{0}` found in config. Resetting to default key.", localConfig.masterKey); localConfig.masterKey = default_master_key; } @@ -295,6 +296,7 @@ private void LoadConfigFile() public void SaveConfigFile() { string path = pathConfigFile + pathFileName; + Log.Debug("Saving config file."); try { diff --git a/VU1WPF/MainWindow.xaml.cs b/VU1WPF/MainWindow.xaml.cs index 579fb70..5e96413 100644 --- a/VU1WPF/MainWindow.xaml.cs +++ b/VU1WPF/MainWindow.xaml.cs @@ -46,9 +46,8 @@ public MainWindow() .WriteTo.Console() .WriteTo.File( Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\KaranovicResearch\VU1-DemoApp\log.txt", - rollingInterval: RollingInterval.Day, rollOnFileSizeLimit: true, - fileSizeLimitBytes: 10000, + fileSizeLimitBytes: 1048576, retainedFileCountLimit: 10) .CreateLogger(); Log.Logger = log; @@ -469,25 +468,27 @@ private void RefreshDialMetric(ClassDialGUI dial) { dialValue = 100; } + // Avoid division by zero + else if (dial.ScaleMax == 0) + { + dialValue = 100; + } // Value is in between scale min and max. Convert to appropriate percent value else { - float mult = (dial.ScaleMax - dial.ScaleMin) / 100; - if (mult <= 0) + float scaledValue = ((fSensorValue - dial.ScaleMin) / (dial.ScaleMax - dial.ScaleMin)) * 100; + if (scaledValue < 0) { - Log.Verbose(String.Format("Scale multiplier calculated as {0}. Clipping to 0.001", mult)); - mult = 0.001f; + Log.Verbose("Clipping scaled value to 0"); + scaledValue = 0; } - - dialValue = ((int)((int)Math.Round(fSensorValue - dial.ScaleMin) / mult)); - - // Clip dial value - if (dialValue <0 ) + else if (scaledValue > 100) { - Log.Verbose(String.Format("Sensor value {0}. Clipping to 0.", dial)); - dialValue = 0; + Log.Verbose("Clipping scaled value to 100"); + scaledValue = 100; } + dialValue = (int)Math.Round(scaledValue); } // Update backlight based on defined thresholds