Skip to content

Commit

Permalink
Do First Run check and Margin sanity check
Browse files Browse the repository at this point in the history
  • Loading branch information
PartierSP committed Dec 25, 2021
1 parent d0663ec commit c33b2ff
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .project
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Title=Bed Leveller
Startup=FMain
Icon=icon.png
Version=2.0.3
Version=2.0.4
Component=gb.image
Component=gb.gui
Component=gb.form
Expand Down
81 changes: 45 additions & 36 deletions .src/FMain.class
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Public iCleanHeight As Integer
Public sCleanLoc As String
Public sConfigLoc As String = User.Home &/ ".config/leveller"
Public sConfigName As String = "config.conf"
Public bFirstRun As Boolean

Public Sub SerialPort3D_Read()

Expand Down Expand Up @@ -72,9 +73,9 @@ Public Sub Form_Open()
'Load settings
hSettings = New Settings(sConfigLoc &/ sConfigName)

iBedSizeX = hSettings["BedSize/BedSizeX", 220]
iBedSizeY = hSettings["BedSize/BedSizeY", 220]
'
iBedSizeX = hSettings["BedSize/BedSizeX", 0]
iBedSizeY = hSettings["BedSize/BedSizeY", 0]

sInitialization[1] = hSettings["Post/Init1", "G21 G90 T0"]
sInitialization[2] = hSettings["Post/Init2", "M155 S2"]
sInitialization[3] = hSettings["Post/Init3", "G92 E0"]
Expand Down Expand Up @@ -104,43 +105,51 @@ Public Sub Form_Open()
hSettings.Read(Me, "MainForm")
hSettings.Read(vsMain, "MainFormVSMain")

With SerialPort3D
.PortName = sPort
.Speed = iBaud
.DataBits = iDataBits
.StopBits = iStopBits
Select sParity
Case "None"
.Parity = SerialPort.None
Case "Odd"
.Parity = SerialPort.Odd
Case "Event"
.Parity = SerialPort.Even
End Select
Select sFlowControl
Case "None"
.FlowControl = SerialPort.None
Case "Hardware"
.FlowControl = SerialPort.Hardware
Case "Software"
.FlowControl = SerialPort.Software
Case "Both"
.FlowControl = SerialPort.Both
End Select
End With

'Update Location button names
UpdateButtonNames
bFirstRun = hSettings["System/FirstRun", True] 'If this setting isn't found, set First Run to True until OK is clicked on fSettings.

Try serialPort3D.Open()
If Error Then
If bFirstRun = True Then
btnHome.Enabled = False
Message.Warning("Printer not found. Check settings/connection and try again.")
Message.Warning("Welcome to Bed Leveller. Please configure all settings before continuing.")
FSettings.Show
FSettings.TabStrip1.Index = 2
Else
btnHome.Enabled = True
Endif
With SerialPort3D
.PortName = sPort
.Speed = iBaud
.DataBits = iDataBits
.StopBits = iStopBits
Select sParity
Case "None"
.Parity = SerialPort.None
Case "Odd"
.Parity = SerialPort.Odd
Case "Event"
.Parity = SerialPort.Even
End Select
Select sFlowControl
Case "None"
.FlowControl = SerialPort.None
Case "Hardware"
.FlowControl = SerialPort.Hardware
Case "Software"
.FlowControl = SerialPort.Software
Case "Both"
.FlowControl = SerialPort.Both
End Select
End With

'Update Location button names
UpdateButtonNames

Try serialPort3D.Open()
If Error Then
btnHome.Enabled = False
Message.Warning("Printer not found. Check settings/connection and try again.")
FSettings.Show
FSettings.TabStrip1.Index = 2
Else
btnHome.Enabled = True
Endif
Endif

End

Expand Down
23 changes: 21 additions & 2 deletions .src/FSettings.class
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Public Sub btOK_Click()

Dim hSettings As Settings

'Check if Margin value is sane
If (sbMargin.Value >= sbBedDepth.Value) Or (sbMargin.Value >= sbBedWidth.Value) Then
Message("Margin must be smaller then Bed Width and Bed Depth")
Goto EndSub
Endif

With FMain
'Set settings
.iBedSizeX = sbBedWidth.Value
Expand Down Expand Up @@ -40,10 +46,10 @@ Public Sub btOK_Click()

'Save settings to config
hSettings = New Settings(.sConfigLoc &/ .sConfigName)

hSettings["BedSize/BedSizeX"] = .iBedSizeX
hSettings["BedSize/BedSizeY"] = .iBedSizeY

hSettings["Post/Init1"] = .sInitialization[1]
hSettings["Post/Init2"] = .sInitialization[2]
hSettings["Post/Init3"] = .sInitialization[3]
Expand All @@ -70,13 +76,26 @@ Public Sub btOK_Click()
hSettings["Communications/Parity"] = .sParity
hSettings["Communications/FlowControl"] = .sFlowControl

hSettings["System/FirstRun"] = False

'Write settings to disk early in case this is a First Run.
hSettings.Save

'Update location button text
.UpdateButtonNames

'Check if this is a First Run. If so, re-initialize start up to get communitations working.
If .bFirstRun = True Then
.bFirstRun = False
.Form_Open()
Endif

End With

Me.Close

EndSub:

End

Public Sub btCancel_Click()
Expand Down
2 changes: 1 addition & 1 deletion .src/FSettings.form
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
}
{ sbMargin SpinBox
MoveScaled(2,9,19,4)
ToolTip = ("Distance from bed edge to make calibrations")
ToolTip = ("Distance from bed edge to make calibrations (must be less then bed width/depth)")
}
{ sbRapidPlane SpinBox
MoveScaled(2,13,19,4)
Expand Down

0 comments on commit c33b2ff

Please sign in to comment.