Skip to content

Commit 8bba765

Browse files
committed
2.2.3rc1 prep
1 parent 9c0b046 commit 8bba765

File tree

3 files changed

+188
-174
lines changed

3 files changed

+188
-174
lines changed

octoprint_bettergrblsupport/__init__.py

+2-172
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def __init__(self):
171171
self.bgsFilters = self.bgs_filters
172172

173173
self.settingsVersion = 6
174-
self.wizardVersion = 10
174+
self.wizardVersion = 11
175175

176176
self.whenConnected = time.time()
177177
self.handshakeSent = False
@@ -552,177 +552,7 @@ def get_template_configs(self):
552552

553553
# #-- EventHandlerPlugin mix-in
554554
def on_event(self, event, payload):
555-
subscribed_events = (Events.FILE_SELECTED, Events.FILE_ADDED, Events.PRINT_STARTED, Events.PRINT_CANCELLED, Events.PRINT_CANCELLING,
556-
Events.PRINT_PAUSED, Events.PRINT_RESUMED, Events.PRINT_DONE, Events.PRINT_FAILED,
557-
Events.PLUGIN_PLUGINMANAGER_UNINSTALL_PLUGIN, Events.PLUGIN_PLUGINMANAGER_DISABLE_PLUGIN, Events.UPLOAD,
558-
Events.CONNECTING, Events.CONNECTED, Events.DISCONNECTING, Events.DISCONNECTED, Events.STARTUP, Events.SHUTDOWN)
559-
560-
if event not in subscribed_events and payload is not None and payload.get("state_id") not in ("PAUSING", "STARTING"):
561-
self._logger.debug('event [{}] received but not subscribed - discarding'.format(event))
562-
return
563-
564-
self._logger.debug("__init__: on_event event=[{}] payload=[{}]".format(event, payload))
565-
566-
# our plugin is being uninstalled
567-
if event in (Events.PLUGIN_PLUGINMANAGER_UNINSTALL_PLUGIN, Events.PLUGIN_PLUGINMANAGER_DISABLE_PLUGIN) and payload["id"] == self._identifier:
568-
self._logger.debug('we are being uninstalled/disabled :(')
569-
_bgs.cleanup_due_to_uninstall(self)
570-
self._logger.debug('plugin cleanup completed (this house is clean)')
571-
return
572-
573-
if self._printer_profile_manager.get_current_or_default()["id"] != "_bgs":
574-
return
575-
576-
# - CONNECTING
577-
if event == Events.CONNECTING:
578-
self.connectionState = event
579-
# let's make sure we don't have any commands queued up
580-
self.grblCmdQueue.clear()
581-
582-
# - CONNECTED
583-
if event == Events.CONNECTED:
584-
self._logger.debug('machine connected')
585-
586-
self.connectionState = event
587-
self.whenConnected = time.time()
588-
self.autoSleepTimer = time.time()
589-
590-
self.is_operational = True
591-
self._settings.set_boolean(["is_operational"], self.is_operational)
592-
593-
_bgs.queue_cmds_and_send(self, ["$I", "$G"])
594-
self._printer.fake_ack()
595-
596-
# Disconnecting & Disconnected
597-
if event in (Events.DISCONNECTING, Events.DISCONNECTED):
598-
self.connectionState = event
599-
self.handshakeSent = False
600-
self.grblState = "N/A"
601-
self._plugin_manager.send_plugin_message(self._identifier, dict(type="grbl_state", state="N/A"))
602-
603-
self.is_operational = False
604-
self._settings.set_boolean(["is_operational"], self.is_operational)
605-
606-
# Print Starting
607-
if payload is not None and payload.get("state_id") == "STARTING":
608-
_bgs.add_to_notify_queue(self, ["Pgm Begin"])
609-
# threading.Thread(target=_bgs.send_command_now, args=(self._printer, self._logger, "?")).start()
610-
self._printer.commands("?", force=True)
611-
return
612-
613-
# 'PrintStarted'
614-
if event == Events.PRINT_STARTED:
615-
if "HOLD" in self.grblState.upper():
616-
self._printer.commands(["~"], force=True)
617-
elif not self.grblState.upper() in ("IDLE", "CHECK"):
618-
# we have to stop This
619-
self._printer.cancel_print()
620-
return
621-
622-
# reset our rate overrides
623-
self.feedRate = 0
624-
self.plungeRate = 0
625-
self.powerRate = 0
626-
627-
self.grblState = "Run"
628-
self._plugin_manager.send_plugin_message(self._identifier, dict(type="grbl_state", state="Run"))
629-
630-
self.is_printing = True
631-
self._settings.set_boolean(["is_printing"], self.is_printing)
632-
633-
if self.autoCooldown:
634-
_bgs.activate_auto_cooldown(self)
635-
636-
return
637-
638-
# Print ended (finished / failed / cancelled)
639-
if event in (Events.PRINT_CANCELLED, Events.PRINT_DONE, Events.PRINT_FAILED):
640-
self.grblState = "Idle"
641-
self._plugin_manager.send_plugin_message(self._identifier, dict(type="grbl_state", state="Idle"))
642-
643-
self.is_printing = False
644-
self._settings.set_boolean(["is_printing"], self.is_printing)
645-
646-
return
647-
648-
# Print Cancelling
649-
if event == Events.PRINT_CANCELLING:
650-
self._logger.debug("cancelling job")
651-
652-
if "HOLD" in self.grblState.upper():
653-
self._printer.commands(["~", "M5"], force=True)
654-
else:
655-
self._printer.commands(["M5"], force=True)
656-
657-
# Print Pausing
658-
if payload is not None and payload.get("state_id") == "PAUSING":
659-
self._logger.debug("pausing job")
660-
661-
self.pausedPower = self.grblPowerLevel
662-
self.pausedPositioning = self.positioning
663-
664-
self._printer.fake_ack()
665-
666-
# retract Z 5 if not laser mode
667-
if not _bgs.is_laser_mode(self):
668-
self._printer.commands(["G91 G0 Z5"], force=True)
669-
670-
self._printer.commands(["M5", "?"], force=True)
671-
672-
# Print Paused
673-
if event == Events.PRINT_PAUSED:
674-
self._logger.debug("paused job")
675-
self._printer.commands(["M5", "?", "!", "?"], force=True)
676-
677-
# Print Resumed
678-
if event == Events.PRINT_RESUMED:
679-
self._logger.debug("resuming job")
680-
self._printer.commands(["~", "M3"], force=True)
681-
682-
# move our spindle back down 5
683-
if not _bgs.is_laser_mode(self):
684-
self._printer.commands(["G4 P10", "G91 G0 Z-5"], force=True)
685-
686-
# make sure we are using whatever positioning mode was active before we paused
687-
self._printer.commands(["G91" if self.pausedPositioning == 1 else "G90"], force=True)
688-
689-
self.grblState = "Run"
690-
self._plugin_manager.send_plugin_message(self._identifier, dict(type="grbl_state", state="Run"))
691-
692-
# starting up
693-
if event == Events.STARTUP:
694-
self._logger.info("starting up")
695-
696-
# shutting down
697-
if event == Events.SHUTDOWN:
698-
self._logger.info("shutting down")
699-
self._settings.save()
700-
701-
# File uploaded
702-
if event == Events.UPLOAD:
703-
if payload["path"].endswith(".gc") or payload["path"].endswith(".nc"):
704-
renamed_file = payload["path"][:len(payload["path"]) - 2] + "gcode"
705-
706-
self._logger.debug("renaming [%s] to [%s]", payload["path"], renamed_file)
707-
708-
self._file_manager.remove_file(payload["target"], renamed_file)
709-
self._file_manager.move_file(payload["target"], payload["path"], renamed_file)
710-
711-
_bgs.generate_metadata_for_file(self, renamed_file, notify=False, force=True)
712-
713-
# 'FileAdded'
714-
if event == Events.FILE_ADDED:
715-
_bgs.generate_metadata_for_file(self, payload["path"], notify=False, force=True)
716-
717-
# 'FileSelected'
718-
if event == Events.FILE_SELECTED:
719-
_bgs.generate_metadata_for_file(self, payload["path"], notify=True)
720-
return
721-
722-
if event == Events.FILE_DESELECTED:
723-
return
724-
725-
return
555+
_bgs.on_event(self, event, payload)
726556

727557

728558
def on_plugin_pending_uninstall(self): # this will work in some next release of octoprint

octoprint_bettergrblsupport/_bgs.py

+177-1
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@
3131
import math
3232

3333
import re
34-
import requests
34+
# import requests
3535
import threading
3636

3737
from timeit import default_timer as timer
38+
from octoprint.events import Events
39+
3840
from .zprobe import ZProbe
3941
from .xyprobe import XyProbe
4042

@@ -214,6 +216,180 @@ def cleanup_due_to_uninstall(_plugin, remove_profile=True):
214216

215217
_plugin._settings.save()
216218

219+
# #-- EventHandlerPlugin mix-in
220+
def on_event(_plugin, event, payload):
221+
subscribed_events = (Events.FILE_SELECTED, Events.FILE_ADDED, Events.PRINT_STARTED, Events.PRINT_CANCELLED, Events.PRINT_CANCELLING,
222+
Events.PRINT_PAUSED, Events.PRINT_RESUMED, Events.PRINT_DONE, Events.PRINT_FAILED,
223+
Events.PLUGIN_PLUGINMANAGER_UNINSTALL_PLUGIN, Events.PLUGIN_PLUGINMANAGER_DISABLE_PLUGIN, Events.UPLOAD,
224+
Events.CONNECTING, Events.CONNECTED, Events.DISCONNECTING, Events.DISCONNECTED, Events.STARTUP, Events.SHUTDOWN)
225+
226+
if event not in subscribed_events and payload is not None and payload.get("state_id") not in ("PAUSING", "STARTING"):
227+
_plugin._logger.debug('event [{}] received but not subscribed - discarding'.format(event))
228+
return
229+
230+
_plugin._logger.debug("_bgs: on_event event=[{}] payload=[{}]".format(event, payload))
231+
232+
# our plugin is being uninstalled
233+
if event in (Events.PLUGIN_PLUGINMANAGER_UNINSTALL_PLUGIN, Events.PLUGIN_PLUGINMANAGER_DISABLE_PLUGIN) and payload["id"] == _plugin._identifier:
234+
_plugin._logger.debug('we are being uninstalled/disabled :(')
235+
cleanup_due_to_uninstall(_plugin)
236+
_plugin._logger.debug('plugin cleanup completed (this house is clean)')
237+
return
238+
239+
if _plugin._printer_profile_manager.get_current_or_default()["id"] != "_bgs":
240+
return
241+
242+
# - CONNECTING
243+
if event == Events.CONNECTING:
244+
_plugin.connectionState = event
245+
# let's make sure we don't have any commands queued up
246+
_plugin.grblCmdQueue.clear()
247+
248+
# - CONNECTED
249+
if event == Events.CONNECTED:
250+
_plugin._logger.debug('machine connected')
251+
252+
_plugin.connectionState = event
253+
_plugin.whenConnected = time.time()
254+
_plugin.autoSleepTimer = time.time()
255+
256+
_plugin.is_operational = True
257+
_plugin._settings.set_boolean(["is_operational"], _plugin.is_operational)
258+
259+
queue_cmds_and_send(_plugin, ["$I", "$G"])
260+
_plugin._printer.fake_ack()
261+
262+
# Disconnecting & Disconnected
263+
if event in (Events.DISCONNECTING, Events.DISCONNECTED):
264+
_plugin.connectionState = event
265+
_plugin.handshakeSent = False
266+
_plugin.grblState = "N/A"
267+
_plugin._plugin_manager.send_plugin_message(_plugin._identifier, dict(type="grbl_state", state="N/A"))
268+
269+
_plugin.is_operational = False
270+
_plugin._settings.set_boolean(["is_operational"], _plugin.is_operational)
271+
272+
# Print Starting
273+
if payload is not None and payload.get("state_id") == "STARTING":
274+
add_to_notify_queue(_plugin, ["Pgm Begin"])
275+
# threading.Thread(target=send_command_now, args=(_plugin._printer, _plugin._logger, "?")).start()
276+
_plugin._printer.commands("?", force=True)
277+
return
278+
279+
# 'PrintStarted'
280+
if event == Events.PRINT_STARTED:
281+
if "HOLD" in _plugin.grblState.upper():
282+
_plugin._printer.commands(["~"], force=True)
283+
elif not _plugin.grblState.upper() in ("IDLE", "CHECK"):
284+
# we have to stop This
285+
_plugin._printer.cancel_print()
286+
return
287+
288+
# reset our rate overrides
289+
_plugin.feedRate = 0
290+
_plugin.plungeRate = 0
291+
_plugin.powerRate = 0
292+
293+
_plugin.grblState = "Run"
294+
_plugin._plugin_manager.send_plugin_message(_plugin._identifier, dict(type="grbl_state", state="Run"))
295+
296+
_plugin.is_printing = True
297+
_plugin._settings.set_boolean(["is_printing"], _plugin.is_printing)
298+
299+
if _plugin.autoCooldown:
300+
activate_auto_cooldown(_plugin)
301+
302+
return
303+
304+
# Print ended (finished / failed / cancelled)
305+
if event in (Events.PRINT_CANCELLED, Events.PRINT_DONE, Events.PRINT_FAILED):
306+
_plugin.grblState = "Idle"
307+
_plugin._plugin_manager.send_plugin_message(_plugin._identifier, dict(type="grbl_state", state="Idle"))
308+
309+
_plugin.is_printing = False
310+
_plugin._settings.set_boolean(["is_printing"], _plugin.is_printing)
311+
312+
return
313+
314+
# Print Cancelling
315+
if event == Events.PRINT_CANCELLING:
316+
_plugin._logger.debug("cancelling job")
317+
318+
if "HOLD" in _plugin.grblState.upper():
319+
_plugin._printer.commands(["~", "M5"], force=True)
320+
else:
321+
_plugin._printer.commands(["M5"], force=True)
322+
323+
# Print Pausing
324+
if payload is not None and payload.get("state_id") == "PAUSING":
325+
_plugin._logger.debug("pausing job")
326+
327+
_plugin.pausedPower = _plugin.grblPowerLevel
328+
_plugin.pausedPositioning = _plugin.positioning
329+
330+
_plugin._printer.fake_ack()
331+
332+
# retract Z 5 if not laser mode
333+
if not is_laser_mode(_plugin):
334+
_plugin._printer.commands(["G91 G0 Z5"], force=True)
335+
336+
_plugin._printer.commands(["M5", "?"], force=True)
337+
338+
# Print Paused
339+
if event == Events.PRINT_PAUSED:
340+
_plugin._logger.debug("paused job")
341+
_plugin._printer.commands(["M5", "?", "!", "?"], force=True)
342+
343+
# Print Resumed
344+
if event == Events.PRINT_RESUMED:
345+
_plugin._logger.debug("resuming job")
346+
_plugin._printer.commands(["~", "M3"], force=True)
347+
348+
# move our spindle back down 5
349+
if not is_laser_mode(_plugin):
350+
_plugin._printer.commands(["G4 P10", "G91 G0 Z-5"], force=True)
351+
352+
# make sure we are using whatever positioning mode was active before we paused
353+
_plugin._printer.commands(["G91" if _plugin.pausedPositioning == 1 else "G90"], force=True)
354+
355+
_plugin.grblState = "Run"
356+
_plugin._plugin_manager.send_plugin_message(_plugin._identifier, dict(type="grbl_state", state="Run"))
357+
358+
# starting up
359+
if event == Events.STARTUP:
360+
_plugin._logger.info("starting up")
361+
362+
# shutting down
363+
if event == Events.SHUTDOWN:
364+
_plugin._logger.info("shutting down")
365+
_plugin._settings.save()
366+
367+
# File uploaded
368+
if event == Events.UPLOAD:
369+
if payload["path"].endswith(".gc") or payload["path"].endswith(".nc"):
370+
renamed_file = payload["path"][:len(payload["path"]) - 2] + "gcode"
371+
372+
_plugin._logger.debug("renaming [%s] to [%s]", payload["path"], renamed_file)
373+
374+
_plugin._file_manager.remove_file(payload["target"], renamed_file)
375+
_plugin._file_manager.move_file(payload["target"], payload["path"], renamed_file)
376+
377+
generate_metadata_for_file(_plugin, renamed_file, notify=False, force=True)
378+
379+
# 'FileAdded'
380+
if event == Events.FILE_ADDED:
381+
generate_metadata_for_file(_plugin, payload["path"], notify=False, force=True)
382+
383+
# 'FileSelected'
384+
if event == Events.FILE_SELECTED:
385+
generate_metadata_for_file(_plugin, payload["path"], notify=True)
386+
return
387+
388+
if event == Events.FILE_DESELECTED:
389+
return
390+
391+
return
392+
217393

218394
def do_framing(_plugin, data):
219395
_plugin._logger.debug("_bgs: do_framing data=[{}]".format(data))

octoprint_bettergrblsupport/templates/bettergrblsupport_wizard.jinja2

+9-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@
1212
If this is your first time using Better Grbl Support or it has been a while since you've used it, be sure to visit the
1313
<a href="https://github.com/synman/Octoprint-Bettergrblsupport/wiki" target="_blank">Better Grbl Support Wiki</a> to learn about its features and how they work.
1414
<br>
15-
<h4>Release Notes - 2.2.2</h4>
15+
<h4>Release Notes - 2.2.3</h4>
16+
<ul>
17+
<li>Grbl ESP32 Settings Supported via Plugin Settings</li>
18+
<li>Fixed an issue causing xPro V5 Grbl ESP32 controller to panic on connect</li>
19+
<li>Grbl Terminal Filters!</li>
20+
<li>Replaced more UI references to print / printer with job / machine</li>
21+
</ul>
22+
<br>
23+
<h5>Release Notes - 2.2.2</h4>
1624
<ul>
1725
<li>Added A/B/C axis descriptions to grbl_settings.txt</li>
1826
<li>Fixed bug preventing USB / Bluetooth gamepads from jogging</li>

0 commit comments

Comments
 (0)