Skip to content
This repository has been archived by the owner on Feb 4, 2025. It is now read-only.

Commit

Permalink
Merge pull request #55 from jcsmook/master
Browse files Browse the repository at this point in the history
Shutdown bug fix, and a frequency source selection feature
  • Loading branch information
gawindx authored Jan 25, 2021
2 parents 6ed0f38 + 4f6a9b5 commit a7768f8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
8 changes: 7 additions & 1 deletion WinNUT_V2/WinNUT_GUI/Pref_Gui.vb
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,14 @@
Tb_Delay_Stop.Enabled = False
Else
Tb_Delay_Stop.Enabled = True
Number_Validating(Tb_Delay_Stop, New System.ComponentModel.CancelEventArgs())
End If
End Sub

Private Sub Cb_ExtendTime_CheckedChanged(sender As Object, e As EventArgs) Handles Cb_ExtendTime.CheckedChanged
If Cb_ExtendTime.Checked Then
Tb_GraceTime.Enabled = True
Number_Validating(Tb_GraceTime, New System.ComponentModel.CancelEventArgs())
Else
Tb_GraceTime.Enabled = False
End If
Expand Down Expand Up @@ -211,9 +213,13 @@
Case "Tb_Load_Min", "Tb_Load_Max", "Tb_InF_Min", "Tb_InF_Max", "Tb_BattLimit_Load"
MinValue = 0
MaxValue = 100
Case "Tb_GraceTime", "Tb_Delay_Stop", "Tb_BattLimit_Time"
Case "Tb_BattLimit_Time"
MinValue = 0
MaxValue = 3600
'Min value has to be 1 as 0 can't be assigned to a timer interval (used in Shutdown_Gui)
Case "Tb_GraceTime", "Tb_Delay_Stop"
MinValue = 1
MaxValue = 3600
End Select

If Integer.TryParse(sender.Text, Result) Then
Expand Down
11 changes: 10 additions & 1 deletion WinNUT_V2/WinNUT_GUI/Shutdown_Gui.vb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,21 @@
LogFile.LogTracing("Load ShutDown Gui", LogLvl.LOG_DEBUG, Me)
Me.Grace_Timer.Enabled = False
Me.Grace_Timer.Stop()
Me.Grace_Timer.Interval = (WinNUT_Params.Arr_Reg_Key.Item("ExtendedShutdownDelay") * 1000)
'If ExtendedShutdownDelay = 0 (the default value), the next line fails and the whole shutdown sequence fails - Thus no shutdown
'Moved next line lower down
'Me.Grace_Timer.Interval = (WinNUT_Params.Arr_Reg_Key.Item("ExtendedShutdownDelay") * 1000)
Shutdown_Timer.Interval = (WinNUT_Params.Arr_Reg_Key.Item("DelayToShutdown") * 1000)
Me.STimer = WinNUT_Params.Arr_Reg_Key.Item("DelayToShutdown")
Me.Remained = Me.STimer
If WinNUT_Params.Arr_Reg_Key.Item("AllowExtendedShutdownDelay") Then
Grace_Button.Enabled = True
'Moved here so it is only used if grace period is allowed
Try
Me.Grace_Timer.Interval = (WinNUT_Params.Arr_Reg_Key.Item("ExtendedShutdownDelay") * 1000)
Catch ex As Exception
'Disable Grace peroid option if Interval is set to 0
Grace_Button.Enabled = False
End Try
Else
Grace_Button.Enabled = False
End If
Expand Down
4 changes: 2 additions & 2 deletions WinNUT_V2/WinNUT_GUI/ToastPopup.vb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
Public Sub SendToast(ByVal ToastParts As String())
'Get a toast XML template
Dim TemplateToast As Windows.UI.Notifications.ToastTemplateType
If ToastParts.Count = 3 Then
If ToastParts.Count >= 3 Then
TemplateToast = Windows.UI.Notifications.ToastTemplateType.ToastText04
Else
TemplateToast = Windows.UI.Notifications.ToastTemplateType.ToastText02
Expand All @@ -31,7 +31,7 @@

'Fill in the text elements
Dim stringElements As Windows.Data.Xml.Dom.XmlNodeList = toastXml.GetElementsByTagName("text")
For i = 0 To ((ToastParts.Count - 1) Or (stringElements.Count - 1)) Step 1
For i = 0 To ((ToastParts.Count - 1) And (stringElements.Count - 1)) Step 1
stringElements.Item(i).InnerText = ToastParts.ElementAt(i)
Next

Expand Down
4 changes: 4 additions & 0 deletions WinNUT_V2/WinNUT_GUI/UPS_Network.vb
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,10 @@ Public Class UPS_Network
Me.BattCh = Math.Floor((Me.BattV - (11.6 * nBatt)) / (0.02 * nBatt))
End If
If Me.BattRuntime >= 86400 Then
'If Load is 0, the calculation results in infinity. This causes an exception in DataUpdated(), causing Me.Disconnect to run in the exception handler below.
'Thus a connection is established, but is forcefully disconneced almost immediately. This cycle repeats on each connect until load is <> 0
'(Example: I have a 0% load if only Pi, Microtik Router, Wifi AP and switches are running)
Me.Load = If(Me.Load <> 0, Me.Load, 0.1)
Dim BattInstantCurrent = (Me.OutputV * Me.Load) / (Me.BattV * 100)
Me.BattRuntime = Math.Floor(Me.BattCapacity * 0.6 * Me.BattCh * (1 - PowerDivider) * 3600 / (BattInstantCurrent * 100))
End If
Expand Down
12 changes: 6 additions & 6 deletions WinNUT_V2/WinNUT_GUI/WinNUT.vb
Original file line number Diff line number Diff line change
Expand Up @@ -521,12 +521,6 @@ Public Class WinNUT
Lbl_VSerial.Text = Me.UPS_Serial
Lbl_VFirmware.Text = Me.UPS_Firmware
End If
If Me.UPS_Status = "OL" And UPS_Network.UPS_Status = "OB" Then
RaiseEvent On_Battery()
End If
If Me.UPS_Status = "OB" And UPS_Network.UPS_Status = "OL" Then
RaiseEvent On_Line()
End If
Me.UPS_BattCh = UPS_Network.UPS_BattCh
Me.UPS_BattV = UPS_Network.UPS_BattV
Me.UPS_BattRuntime = UPS_Network.UPS_BattRuntime
Expand Down Expand Up @@ -601,6 +595,12 @@ Public Class WinNUT
LogFile.LogTracing("Update Icon", LogLvl.LOG_DEBUG, Me)
UpdateIcon_NotifyIcon()
RaiseEvent UpdateNotifyIconStr("Update Data", Nothing)
If Me.UPS_Status = "OL" And UPS_Network.UPS_Status = "OB" Then
RaiseEvent On_Battery()
End If
If Me.UPS_Status = "OB" And UPS_Network.UPS_Status = "OL" Then
RaiseEvent On_Line()
End If
End Sub

Private Sub Menu_Disconnect_Click(sender As Object, e As EventArgs) Handles Menu_Disconnect.Click
Expand Down

0 comments on commit a7768f8

Please sign in to comment.