Skip to content

Commit

Permalink
Changing logger options to increase log file size. Fixing dial value …
Browse files Browse the repository at this point in the history
…scaling.
  • Loading branch information
SasaKaranovic committed Feb 6, 2024
1 parent bd2cf87 commit dace999
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
6 changes: 4 additions & 2 deletions VU1WPF/ClassConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -295,6 +296,7 @@ private void LoadConfigFile()
public void SaveConfigFile()
{
string path = pathConfigFile + pathFileName;
Log.Debug("Saving config file.");

try
{
Expand Down
27 changes: 14 additions & 13 deletions VU1WPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dace999

Please sign in to comment.