Skip to content

Commit

Permalink
Handle nominal input frequency calibration setting change
Browse files Browse the repository at this point in the history
The input frequency calibration preference value used to be stored as the index value of the dropdown box in the preferences window; 0 for 50hz, and 1 for 60hz. The new settings system stores the value literally now, although the rest of WinNUT was not updated to reflect this change.

- WinNUT.vb now passes the Settings value directly to the `UPS_Device` constructor instead of converting it.
- UPS_Device.vb also refers to the value directly when getting parameter info from the UPS.
- Prefs upgrade import procedure now has an edge case to convert the old value to the new one.
  • Loading branch information
gbakeman committed Jan 31, 2024
1 parent 4d9d9bb commit 381ebaa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
10 changes: 9 additions & 1 deletion WinNUT_V2/WinNUT-Client/Models/UpgradePrefsDialogModel.vb
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,15 @@ Namespace Models
Dim pairLookupRes = oldPrefs.PrefSettingsLookup.First(Function(p As OldParams.UpgradableParams.PrefSettingPair)
Return p.OldPreferenceName.Equals(oldPref.Key)
End Function)
My.Settings.Item(pairLookupRes.NewSettingsName) = oldPref.Value

Dim oldValue = oldPref.Value
' Handle special case of converting the default input frequency calibration value
If oldPref.Key = "FrequencySupply" Then
oldValue = (oldValue * 10) + 50
End If

My.Settings.Item(pairLookupRes.NewSettingsName) = oldValue

ReportProgress(percentComplete, "Imported " & oldPref.Key & " into " & pairLookupRes.NewSettingsName,
LogLvl.LOG_NOTICE, Me)

Expand Down
2 changes: 1 addition & 1 deletion WinNUT_V2/WinNUT-Client/WinNUT.vb
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ Public Class WinNUT
My.Settings.NUT_UPSName,
My.Settings.NUT_AutoReconnect)

UPS_Device = New UPS_Device(Nut_Config, LogFile, My.Settings.NUT_PollIntervalMsec, (50 + My.Settings.CAL_FreqInNom * 10))
UPS_Device = New UPS_Device(Nut_Config, LogFile, My.Settings.NUT_PollIntervalMsec, My.Settings.CAL_FreqInNom)
AddHandler UPS_Device.EncounteredNUTException, AddressOf HandleNUTException
UPS_Device.Connect_UPS(retryOnConnFailure)
End Sub
Expand Down
3 changes: 2 additions & 1 deletion WinNUT_V2/WinNUT-Client_Common/UPS_Device.vb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ Public Class UPS_Device
Me.LogFile = LogFile
Me.Nut_Config = Nut_Config
PollingInterval = pollInterval
Freq_Fallback = defaultFrequency
Nut_Socket = New Nut_Socket(Me.Nut_Config, LogFile)

With Reconnect_Nut
Expand Down Expand Up @@ -264,7 +265,7 @@ Public Class UPS_Device

' Other constant values for UPS calibration.
freshData.UPS_Value.Batt_Capacity = Double.Parse(GetUPSVar("battery.capacity", 7), INVARIANT_CULTURE)
Freq_Fallback = Double.Parse(GetUPSVar("output.frequency.nominal", (50 + CInt(Arr_Reg_Key.Item("FrequencySupply")) * 10)), INVARIANT_CULTURE)
Freq_Fallback = Double.Parse(GetUPSVar("output.frequency.nominal", Freq_Fallback), INVARIANT_CULTURE)

LogFile.LogTracing("Completed retrieval of basic UPS product information.", LogLvl.LOG_NOTICE, Me)
Return freshData
Expand Down

0 comments on commit 381ebaa

Please sign in to comment.