@@ -16,22 +16,38 @@ public ButtonManager(ui.main.MainMenu form1)
1616 _ui = form1 ;
1717 }
1818
19+ private bool Check ( )
20+ {
21+ if ( ! _ui . isConnected )
22+ {
23+ MessageBox . Show ( "Connect to a printer first!" , "Not connected" ) ;
24+ return false ;
25+ }
26+
27+ return true ;
28+ }
29+
30+
31+
1932 // LEDs
2033 public async Task LedOn ( )
2134 {
35+ if ( ! Check ( ) ) return ;
2236 await _ui . printerClient . Control . SetLedOn ( ) ;
2337 _ui . AppendLog ( "LED turned on." ) ;
2438 }
2539
2640 public async Task LedOff ( )
2741 {
42+ if ( ! Check ( ) ) return ;
2843 await _ui . printerClient . Control . SetLedOff ( ) ;
2944 _ui . AppendLog ( "LED turned off." ) ;
3045 }
3146
3247
3348 public void TogglePreview ( )
3449 {
50+ if ( ! Check ( ) ) return ;
3551 if ( _ui . printerClient == null ) return ;
3652 if ( ! _ui . printerClient . IsPro && ! _ui . config . CustomCamera ) // check for webcam or custom setup
3753 {
@@ -56,6 +72,7 @@ public void TogglePreview()
5672 // Filtration
5773 public async Task FilteringOff ( )
5874 {
75+ if ( ! Check ( ) ) return ;
5976 // todo this needs to be coded into the webUI, this is a lazy fix for now since it will invoke this (indirectly) anyways
6077 if ( ! _ui . printerClient . IsPro )
6178 {
@@ -68,6 +85,7 @@ public async Task FilteringOff()
6885
6986 public async Task ExternalFilterOn ( )
7087 {
88+ if ( ! Check ( ) ) return ;
7189 // todo same for here
7290 if ( ! _ui . printerClient . IsPro )
7391 {
@@ -83,6 +101,7 @@ public async Task ExternalFilterOn()
83101
84102 public async Task InternalFilterOn ( )
85103 {
104+ if ( ! Check ( ) ) return ;
86105 // todo also same for here
87106 if ( ! _ui . printerClient . IsPro )
88107 {
@@ -99,13 +118,15 @@ public async Task InternalFilterOn()
99118 // Fans
100119 public async Task SetCoolingFanSpeed ( )
101120 {
121+ if ( ! Check ( ) ) return ;
102122 var input = Interaction . InputBox ( "Fan speed (0-100)" , "Set Cooling Fan Speed" , "0" ) ;
103123 if ( int . TryParse ( input , out var speed ) ) await _ui . printerClient . Control . SetCoolingFanSpeed ( speed ) ;
104124 else _ui . AppendLog ( "Setting cooling fan speed cancelled." ) ;
105125 }
106126
107127 public async Task SetChamberFanSpeed ( )
108128 {
129+ if ( ! Check ( ) ) return ;
109130 // todo this also needs to be coded into the web ui
110131 if ( ! _ui . printerClient . IsPro )
111132 {
@@ -121,6 +142,7 @@ public async Task SetChamberFanSpeed()
121142
122143 public async Task PauseJob ( )
123144 {
145+ if ( ! Check ( ) ) return ;
124146 await _ui . CmdWait ( ) ;
125147 if ( ! await _ui . printerClient . Info . IsPrinting ( ) ) _ui . AppendLog ( "No job to pause..." ) ;
126148 else if ( ! await _ui . printerClient . JobControl . PausePrintJob ( ) ) _ui . AppendLog ( "(Error) Unable to pause current job" ) ;
@@ -130,6 +152,7 @@ public async Task PauseJob()
130152
131153 public async Task ResumeJob ( )
132154 {
155+ if ( ! Check ( ) ) return ;
133156 await _ui . CmdWait ( ) ;
134157 // need to see what "state" is when paused, could be exactly that lol
135158 if ( ! await _ui . printerClient . JobControl . ResumePrintJob ( ) ) _ui . AppendLog ( "(Error) Unable to resume current job" ) ;
@@ -139,6 +162,7 @@ public async Task ResumeJob()
139162
140163 public async Task StopJob ( )
141164 {
165+ if ( ! Check ( ) ) return ;
142166 await _ui . CmdWait ( ) ;
143167 if ( ! await _ui . printerClient . Info . IsPrinting ( ) ) _ui . AppendLog ( "No job to stop..." ) ;
144168 else if ( ! await _ui . printerClient . JobControl . CancelPrintJob ( ) ) _ui . AppendLog ( "(Error) Unable to cancel current job" ) ;
@@ -148,6 +172,7 @@ public async Task StopJob()
148172
149173 public async Task ClearPlatform ( )
150174 {
175+ if ( ! Check ( ) ) return ;
151176 if ( ! Compat . Is313OrAbove ( _ui . printerClient . FirmVer ) ) return ; // not supported below fw 3.13.3
152177 await _ui . CmdWait ( ) ;
153178 var state = await _ui . printerClient . Info . GetState ( ) ;
@@ -166,6 +191,7 @@ public async Task ClearPlatform()
166191 // Upload (and start) job/start local/recent (last 10) jobs
167192 public async Task < bool > SelectAndUploadGCodeFile ( )
168193 {
194+ if ( ! Check ( ) ) return false ;
169195 using ( var form = new GCodeFilePicker ( ) )
170196 {
171197 // todo this needs to be tested (the ReaLTaiizor refactor)
@@ -187,6 +213,7 @@ public async Task<bool> SelectAndUploadGCodeFile()
187213
188214 public async Task SelectRecentJob ( )
189215 {
216+ if ( ! Check ( ) ) return ;
190217 var localFileList = new GCodeListWindow ( _ui . printerClient ) ; // get recent (last 10 files) list
191218 var result = localFileList . ShowDialog ( ) ;
192219 localFileList . Dispose ( ) ;
@@ -196,6 +223,7 @@ public async Task SelectRecentJob()
196223
197224 public async Task SelectLocalJob ( )
198225 {
226+ if ( ! Check ( ) ) return ;
199227 var localFileList = new GCodeListWindow ( _ui . printerClient , true ) ; // get full list
200228 var result = localFileList . ShowDialog ( ) ;
201229 localFileList . Dispose ( ) ;
@@ -205,13 +233,22 @@ public async Task SelectLocalJob()
205233
206234 private async Task StartLocalJob ( GCodeListWindow localFileListWindow )
207235 { // get selected file from list and start the print
236+ if ( ! Check ( ) ) return ;
208237 if ( await _ui . printerClient . JobControl . PrintLocalFile ( localFileListWindow . SelectedFileName ,
209238 localFileListWindow . AutoLevel ) )
210239 {
211240 _ui . AppendLog ( $ "Starting job { localFileListWindow . SelectedFileName } ") ;
212241 }
213242 else _ui . AppendLog ( $ "Error starting recent job { localFileListWindow . SelectedFileName } ") ;
214243 }
215-
244+
245+ public void OpenSettings ( )
246+ {
247+ //if (!Check()) return;
248+ using ( var form = new SettingsWindow ( _ui ) )
249+ {
250+ form . ShowDialog ( ) ;
251+ }
252+ }
216253 }
217254}
0 commit comments