Skip to content

Commit

Permalink
2.2.3rc1 prep
Browse files Browse the repository at this point in the history
  • Loading branch information
synman committed Dec 5, 2022
1 parent 9c0b046 commit 8bba765
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 174 deletions.
174 changes: 2 additions & 172 deletions octoprint_bettergrblsupport/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def __init__(self):
self.bgsFilters = self.bgs_filters

self.settingsVersion = 6
self.wizardVersion = 10
self.wizardVersion = 11

self.whenConnected = time.time()
self.handshakeSent = False
Expand Down Expand Up @@ -552,177 +552,7 @@ def get_template_configs(self):

# #-- EventHandlerPlugin mix-in
def on_event(self, event, payload):
subscribed_events = (Events.FILE_SELECTED, Events.FILE_ADDED, Events.PRINT_STARTED, Events.PRINT_CANCELLED, Events.PRINT_CANCELLING,
Events.PRINT_PAUSED, Events.PRINT_RESUMED, Events.PRINT_DONE, Events.PRINT_FAILED,
Events.PLUGIN_PLUGINMANAGER_UNINSTALL_PLUGIN, Events.PLUGIN_PLUGINMANAGER_DISABLE_PLUGIN, Events.UPLOAD,
Events.CONNECTING, Events.CONNECTED, Events.DISCONNECTING, Events.DISCONNECTED, Events.STARTUP, Events.SHUTDOWN)

if event not in subscribed_events and payload is not None and payload.get("state_id") not in ("PAUSING", "STARTING"):
self._logger.debug('event [{}] received but not subscribed - discarding'.format(event))
return

self._logger.debug("__init__: on_event event=[{}] payload=[{}]".format(event, payload))

# our plugin is being uninstalled
if event in (Events.PLUGIN_PLUGINMANAGER_UNINSTALL_PLUGIN, Events.PLUGIN_PLUGINMANAGER_DISABLE_PLUGIN) and payload["id"] == self._identifier:
self._logger.debug('we are being uninstalled/disabled :(')
_bgs.cleanup_due_to_uninstall(self)
self._logger.debug('plugin cleanup completed (this house is clean)')
return

if self._printer_profile_manager.get_current_or_default()["id"] != "_bgs":
return

# - CONNECTING
if event == Events.CONNECTING:
self.connectionState = event
# let's make sure we don't have any commands queued up
self.grblCmdQueue.clear()

# - CONNECTED
if event == Events.CONNECTED:
self._logger.debug('machine connected')

self.connectionState = event
self.whenConnected = time.time()
self.autoSleepTimer = time.time()

self.is_operational = True
self._settings.set_boolean(["is_operational"], self.is_operational)

_bgs.queue_cmds_and_send(self, ["$I", "$G"])
self._printer.fake_ack()

# Disconnecting & Disconnected
if event in (Events.DISCONNECTING, Events.DISCONNECTED):
self.connectionState = event
self.handshakeSent = False
self.grblState = "N/A"
self._plugin_manager.send_plugin_message(self._identifier, dict(type="grbl_state", state="N/A"))

self.is_operational = False
self._settings.set_boolean(["is_operational"], self.is_operational)

# Print Starting
if payload is not None and payload.get("state_id") == "STARTING":
_bgs.add_to_notify_queue(self, ["Pgm Begin"])
# threading.Thread(target=_bgs.send_command_now, args=(self._printer, self._logger, "?")).start()
self._printer.commands("?", force=True)
return

# 'PrintStarted'
if event == Events.PRINT_STARTED:
if "HOLD" in self.grblState.upper():
self._printer.commands(["~"], force=True)
elif not self.grblState.upper() in ("IDLE", "CHECK"):
# we have to stop This
self._printer.cancel_print()
return

# reset our rate overrides
self.feedRate = 0
self.plungeRate = 0
self.powerRate = 0

self.grblState = "Run"
self._plugin_manager.send_plugin_message(self._identifier, dict(type="grbl_state", state="Run"))

self.is_printing = True
self._settings.set_boolean(["is_printing"], self.is_printing)

if self.autoCooldown:
_bgs.activate_auto_cooldown(self)

return

# Print ended (finished / failed / cancelled)
if event in (Events.PRINT_CANCELLED, Events.PRINT_DONE, Events.PRINT_FAILED):
self.grblState = "Idle"
self._plugin_manager.send_plugin_message(self._identifier, dict(type="grbl_state", state="Idle"))

self.is_printing = False
self._settings.set_boolean(["is_printing"], self.is_printing)

return

# Print Cancelling
if event == Events.PRINT_CANCELLING:
self._logger.debug("cancelling job")

if "HOLD" in self.grblState.upper():
self._printer.commands(["~", "M5"], force=True)
else:
self._printer.commands(["M5"], force=True)

# Print Pausing
if payload is not None and payload.get("state_id") == "PAUSING":
self._logger.debug("pausing job")

self.pausedPower = self.grblPowerLevel
self.pausedPositioning = self.positioning

self._printer.fake_ack()

# retract Z 5 if not laser mode
if not _bgs.is_laser_mode(self):
self._printer.commands(["G91 G0 Z5"], force=True)

self._printer.commands(["M5", "?"], force=True)

# Print Paused
if event == Events.PRINT_PAUSED:
self._logger.debug("paused job")
self._printer.commands(["M5", "?", "!", "?"], force=True)

# Print Resumed
if event == Events.PRINT_RESUMED:
self._logger.debug("resuming job")
self._printer.commands(["~", "M3"], force=True)

# move our spindle back down 5
if not _bgs.is_laser_mode(self):
self._printer.commands(["G4 P10", "G91 G0 Z-5"], force=True)

# make sure we are using whatever positioning mode was active before we paused
self._printer.commands(["G91" if self.pausedPositioning == 1 else "G90"], force=True)

self.grblState = "Run"
self._plugin_manager.send_plugin_message(self._identifier, dict(type="grbl_state", state="Run"))

# starting up
if event == Events.STARTUP:
self._logger.info("starting up")

# shutting down
if event == Events.SHUTDOWN:
self._logger.info("shutting down")
self._settings.save()

# File uploaded
if event == Events.UPLOAD:
if payload["path"].endswith(".gc") or payload["path"].endswith(".nc"):
renamed_file = payload["path"][:len(payload["path"]) - 2] + "gcode"

self._logger.debug("renaming [%s] to [%s]", payload["path"], renamed_file)

self._file_manager.remove_file(payload["target"], renamed_file)
self._file_manager.move_file(payload["target"], payload["path"], renamed_file)

_bgs.generate_metadata_for_file(self, renamed_file, notify=False, force=True)

# 'FileAdded'
if event == Events.FILE_ADDED:
_bgs.generate_metadata_for_file(self, payload["path"], notify=False, force=True)

# 'FileSelected'
if event == Events.FILE_SELECTED:
_bgs.generate_metadata_for_file(self, payload["path"], notify=True)
return

if event == Events.FILE_DESELECTED:
return

return
_bgs.on_event(self, event, payload)


def on_plugin_pending_uninstall(self): # this will work in some next release of octoprint
Expand Down
178 changes: 177 additions & 1 deletion octoprint_bettergrblsupport/_bgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@
import math

import re
import requests
# import requests
import threading

from timeit import default_timer as timer
from octoprint.events import Events

from .zprobe import ZProbe
from .xyprobe import XyProbe

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

_plugin._settings.save()

# #-- EventHandlerPlugin mix-in
def on_event(_plugin, event, payload):
subscribed_events = (Events.FILE_SELECTED, Events.FILE_ADDED, Events.PRINT_STARTED, Events.PRINT_CANCELLED, Events.PRINT_CANCELLING,
Events.PRINT_PAUSED, Events.PRINT_RESUMED, Events.PRINT_DONE, Events.PRINT_FAILED,
Events.PLUGIN_PLUGINMANAGER_UNINSTALL_PLUGIN, Events.PLUGIN_PLUGINMANAGER_DISABLE_PLUGIN, Events.UPLOAD,
Events.CONNECTING, Events.CONNECTED, Events.DISCONNECTING, Events.DISCONNECTED, Events.STARTUP, Events.SHUTDOWN)

if event not in subscribed_events and payload is not None and payload.get("state_id") not in ("PAUSING", "STARTING"):
_plugin._logger.debug('event [{}] received but not subscribed - discarding'.format(event))
return

_plugin._logger.debug("_bgs: on_event event=[{}] payload=[{}]".format(event, payload))

# our plugin is being uninstalled
if event in (Events.PLUGIN_PLUGINMANAGER_UNINSTALL_PLUGIN, Events.PLUGIN_PLUGINMANAGER_DISABLE_PLUGIN) and payload["id"] == _plugin._identifier:
_plugin._logger.debug('we are being uninstalled/disabled :(')
cleanup_due_to_uninstall(_plugin)
_plugin._logger.debug('plugin cleanup completed (this house is clean)')
return

if _plugin._printer_profile_manager.get_current_or_default()["id"] != "_bgs":
return

# - CONNECTING
if event == Events.CONNECTING:
_plugin.connectionState = event
# let's make sure we don't have any commands queued up
_plugin.grblCmdQueue.clear()

# - CONNECTED
if event == Events.CONNECTED:
_plugin._logger.debug('machine connected')

_plugin.connectionState = event
_plugin.whenConnected = time.time()
_plugin.autoSleepTimer = time.time()

_plugin.is_operational = True
_plugin._settings.set_boolean(["is_operational"], _plugin.is_operational)

queue_cmds_and_send(_plugin, ["$I", "$G"])
_plugin._printer.fake_ack()

# Disconnecting & Disconnected
if event in (Events.DISCONNECTING, Events.DISCONNECTED):
_plugin.connectionState = event
_plugin.handshakeSent = False
_plugin.grblState = "N/A"
_plugin._plugin_manager.send_plugin_message(_plugin._identifier, dict(type="grbl_state", state="N/A"))

_plugin.is_operational = False
_plugin._settings.set_boolean(["is_operational"], _plugin.is_operational)

# Print Starting
if payload is not None and payload.get("state_id") == "STARTING":
add_to_notify_queue(_plugin, ["Pgm Begin"])
# threading.Thread(target=send_command_now, args=(_plugin._printer, _plugin._logger, "?")).start()
_plugin._printer.commands("?", force=True)
return

# 'PrintStarted'
if event == Events.PRINT_STARTED:
if "HOLD" in _plugin.grblState.upper():
_plugin._printer.commands(["~"], force=True)
elif not _plugin.grblState.upper() in ("IDLE", "CHECK"):
# we have to stop This
_plugin._printer.cancel_print()
return

# reset our rate overrides
_plugin.feedRate = 0
_plugin.plungeRate = 0
_plugin.powerRate = 0

_plugin.grblState = "Run"
_plugin._plugin_manager.send_plugin_message(_plugin._identifier, dict(type="grbl_state", state="Run"))

_plugin.is_printing = True
_plugin._settings.set_boolean(["is_printing"], _plugin.is_printing)

if _plugin.autoCooldown:
activate_auto_cooldown(_plugin)

return

# Print ended (finished / failed / cancelled)
if event in (Events.PRINT_CANCELLED, Events.PRINT_DONE, Events.PRINT_FAILED):
_plugin.grblState = "Idle"
_plugin._plugin_manager.send_plugin_message(_plugin._identifier, dict(type="grbl_state", state="Idle"))

_plugin.is_printing = False
_plugin._settings.set_boolean(["is_printing"], _plugin.is_printing)

return

# Print Cancelling
if event == Events.PRINT_CANCELLING:
_plugin._logger.debug("cancelling job")

if "HOLD" in _plugin.grblState.upper():
_plugin._printer.commands(["~", "M5"], force=True)
else:
_plugin._printer.commands(["M5"], force=True)

# Print Pausing
if payload is not None and payload.get("state_id") == "PAUSING":
_plugin._logger.debug("pausing job")

_plugin.pausedPower = _plugin.grblPowerLevel
_plugin.pausedPositioning = _plugin.positioning

_plugin._printer.fake_ack()

# retract Z 5 if not laser mode
if not is_laser_mode(_plugin):
_plugin._printer.commands(["G91 G0 Z5"], force=True)

_plugin._printer.commands(["M5", "?"], force=True)

# Print Paused
if event == Events.PRINT_PAUSED:
_plugin._logger.debug("paused job")
_plugin._printer.commands(["M5", "?", "!", "?"], force=True)

# Print Resumed
if event == Events.PRINT_RESUMED:
_plugin._logger.debug("resuming job")
_plugin._printer.commands(["~", "M3"], force=True)

# move our spindle back down 5
if not is_laser_mode(_plugin):
_plugin._printer.commands(["G4 P10", "G91 G0 Z-5"], force=True)

# make sure we are using whatever positioning mode was active before we paused
_plugin._printer.commands(["G91" if _plugin.pausedPositioning == 1 else "G90"], force=True)

_plugin.grblState = "Run"
_plugin._plugin_manager.send_plugin_message(_plugin._identifier, dict(type="grbl_state", state="Run"))

# starting up
if event == Events.STARTUP:
_plugin._logger.info("starting up")

# shutting down
if event == Events.SHUTDOWN:
_plugin._logger.info("shutting down")
_plugin._settings.save()

# File uploaded
if event == Events.UPLOAD:
if payload["path"].endswith(".gc") or payload["path"].endswith(".nc"):
renamed_file = payload["path"][:len(payload["path"]) - 2] + "gcode"

_plugin._logger.debug("renaming [%s] to [%s]", payload["path"], renamed_file)

_plugin._file_manager.remove_file(payload["target"], renamed_file)
_plugin._file_manager.move_file(payload["target"], payload["path"], renamed_file)

generate_metadata_for_file(_plugin, renamed_file, notify=False, force=True)

# 'FileAdded'
if event == Events.FILE_ADDED:
generate_metadata_for_file(_plugin, payload["path"], notify=False, force=True)

# 'FileSelected'
if event == Events.FILE_SELECTED:
generate_metadata_for_file(_plugin, payload["path"], notify=True)
return

if event == Events.FILE_DESELECTED:
return

return


def do_framing(_plugin, data):
_plugin._logger.debug("_bgs: do_framing data=[{}]".format(data))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@
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
<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.
<br>
<h4>Release Notes - 2.2.2</h4>
<h4>Release Notes - 2.2.3</h4>
<ul>
<li>Grbl ESP32 Settings Supported via Plugin Settings</li>
<li>Fixed an issue causing xPro V5 Grbl ESP32 controller to panic on connect</li>
<li>Grbl Terminal Filters!</li>
<li>Replaced more UI references to print / printer with job / machine</li>
</ul>
<br>
<h5>Release Notes - 2.2.2</h4>
<ul>
<li>Added A/B/C axis descriptions to grbl_settings.txt</li>
<li>Fixed bug preventing USB / Bluetooth gamepads from jogging</li>
Expand Down

0 comments on commit 8bba765

Please sign in to comment.