Skip to content

Commit

Permalink
fixes #46
Browse files Browse the repository at this point in the history
  • Loading branch information
synman committed Dec 13, 2021
1 parent 46f0e41 commit a1a9778
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 26 deletions.
73 changes: 48 additions & 25 deletions octoprint_bettergrblsupport/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def __init__(self):

self.customControlsJson = r'[{"layout": "horizontal", "children": [{"commands": ["$10=0", "G28.1", "G92 X0 Y0 Z0"], "name": "Set Origin", "confirm": null}, {"command": "M999", "name": "Reset", "confirm": null}, {"commands": ["G1 F4000 S0", "M5", "$SLP"], "name": "Sleep", "confirm": null}, {"command": "$X", "name": "Unlock", "confirm": null}, {"commands": ["$32=0", "M4 S1"], "name": "Weak Laser", "confirm": null}, {"commands": ["$32=1", "M5"], "name": "Laser Off", "confirm": null}], "name": "Laser Commands"}, {"layout": "vertical", "type": "section", "children": [{"regex": "<([^,]+)[,|][WM]Pos:([+\\-\\d.]+,[+\\-\\d.]+,[+\\-\\d.]+)", "name": "State", "default": "", "template": "State: {0} - Position: {1}", "type": "feedback"}, {"regex": "F([\\d.]+) S([\\d.]+)", "name": "GCode State", "default": "", "template": "Speed: {0} Power: {1}", "type": "feedback"}], "name": "Realtime State"}]'


# #~~ SettingsPlugin mixin
def get_settings_defaults(self):
self.loadGrblDescriptions()
Expand Down Expand Up @@ -112,14 +113,15 @@ def get_settings_defaults(self):
ignoreErrors = False,
doSmoothie = False
)
# def on_settings_initialized(self):
# self.hideTempTab = self._settings.get_boolean(["hideTempTab"])
# self._logger.info("hideTempTab: %s" % self.hideTempTab)
#
# self.hideGCodeTab = self._settings.get_boolean(["hideGCodeTab"])
# self._logger.info("hideGCodeTab: %s" % self.hideGCodeTab)


def on_after_startup(self):

# establish initial state for printer status
self._settings.set_boolean(["is_printing"], self._printer.is_printing())
self._settings.set_boolean(["is_operational"], self._printer.is_operational())

# initialize all of our settings
self.hideTempTab = self._settings.get_boolean(["hideTempTab"])
self.hideControlTab = self._settings.get_boolean(["hideControlTab"])
self.hideGCodeTab = self._settings.get_boolean(["hideGCodeTab"])
Expand Down Expand Up @@ -158,20 +160,28 @@ def on_after_startup(self):
if self.neverSendChecksum:
self._settings.global_set(["serial", "checksumRequiringCommands"], [])

# load a map of disabled plugins
disabledPlugins = self._settings.global_get(["plugins", "_disabled"])
if disabledPlugins == None:
disabledPlugins = []

# disable the printer safety check plugin
if self.disablePrinterSafety:
disabledPlugins = self._settings.global_get(["plugins", "_disabled"])
if disabledPlugins == None:
disabledPlugins = []

if "printer_safety_check" not in disabledPlugins:
disabledPlugins.append("printer_safety_check")
else:
if "printer_safety_check" in disabledPlugins:
disabledPlugins.remove("printer_safety_check")

self._settings.global_set(["plugins", "_disabled"], disabledPlugins)
# disable the gcodeviewer plugin
if self.hideGCodeTab:
if "plugin_gcodeviewer" not in disabledPlugins:
disabledPlugins.append("plugin_gcodeviewer")
else:
if "plugin_gcodeviewer" in disabledPlugins:
disabledPlugins.remove("plugin_gcodeviewer")

# establish initial state for printer status
self._settings.set_boolean(["is_printing"], self._printer.is_printing())
self._settings.set_boolean(["is_operational"], self._printer.is_operational())
self._settings.global_set(["plugins", "_disabled"], disabledPlugins)

# process tabs marked as disabled
disabledTabs = self._settings.global_get(["appearance", "components", "disabled", "tab"])
Expand All @@ -196,13 +206,6 @@ def on_after_startup(self):
if "gcodeviewer" in disabledTabs:
disabledTabs.remove("gcodeviewer")

if self.hideGCodeTab:
if "plugin_gcodeviewer" not in disabledTabs:
disabledTabs.append("plugin_gcodeviewer")
else:
if "plugin_gcodeviewer" in disabledTabs:
disabledTabs.remove("plugin_gcodeviewer")

self._settings.global_set(["appearance", "components", "disabled", "tab"], disabledTabs)

if not self.hideControlTab:
Expand All @@ -216,9 +219,9 @@ def on_after_startup(self):
self._logger.info("clearing custom controls")
self._settings.global_set(["controls"], [])

orderedTabs = self._settings.global_get(["appearance", "components", "order", "tab"])

# clean up old versions since octoprint renamed gcodeviewer to plugin_gcodeviewer
orderedTabs = self._settings.global_get(["appearance", "components", "order", "tab"])
if "gcodeviewer" in orderedTabs:
orderedTabs.remove("gcodeviewer")
self._settings.global_set(["appearance", "components", "order", "tab"], orderedTabs)
Expand All @@ -237,6 +240,7 @@ def on_after_startup(self):

self.deSerializeGrblSettings()


def loadGrblDescriptions(self):
path = os.path.dirname(os.path.realpath(__file__)) + os.path.sep + "static" + os.path.sep + "txt" + os.path.sep

Expand Down Expand Up @@ -268,6 +272,7 @@ def loadGrblDescriptions(self):
# for k, v in self.grblAlarms.items():
# self._logger.info("alarm id={} desc={}".format(k, v))


def deSerializeGrblSettings(self):
settings = self._settings.get(["grblSettingsText"])

Expand All @@ -279,6 +284,7 @@ def deSerializeGrblSettings(self):
self.grblSettings.update({int(set[0]): [set[1], self.grblSettingsNames.get(int(set[0]))]})
return


def serializeGrblSettings(self):
ret = ""
for id, data in sorted(self.grblSettings.items(), key=lambda x: int(x[0])):
Expand All @@ -287,6 +293,7 @@ def serializeGrblSettings(self):
# self._logger.info("serializeGrblSettings=[\n{}\n]".format(ret))
return ret


def on_settings_save(self, data):
self._logger.info("saving settings")
octoprint.plugin.SettingsPlugin.on_settings_save(self, data)
Expand All @@ -300,6 +307,7 @@ def on_settings_save(self, data):
else:
self._printer.commands("$$")


# #~~ AssetPlugin mixin
def get_assets(self):
# Define your plugin's asset files to automatically include in the
Expand All @@ -308,6 +316,7 @@ def get_assets(self):
css=['css/bettergrblsupport.css', 'css/bettergrblsupport_settings.css'],
less=['less/bettergrblsupport.less', "less/bettergrblsupport.less"])


# #~~ TemplatePlugin mixin
def get_template_configs(self):
return [
Expand All @@ -317,6 +326,7 @@ def get_template_configs(self):
# def get_template_vars(self):
# return dict(grblSettingsText=self.serializeGrblSettings())


# #-- EventHandlerPlugin mix-in
def on_event(self, event, payload):
subscribed_events = Events.FILE_SELECTED + Events.PRINT_STARTED + Events.PRINT_CANCELLED + Events.PRINT_DONE + Events.PRINT_FAILED
Expand Down Expand Up @@ -410,6 +420,7 @@ def on_event(self, event, payload):

return


# #-- gcode sending hook
def hook_gcode_sending(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwargs):

Expand Down Expand Up @@ -559,6 +570,7 @@ def hook_gcode_sending(self, comm_instance, phase, cmd, cmd_type, gcode, *args,

return (command, )


# #-- gcode received hook (
# original author: https://github.com/mic159
# source: https://github.com/mic159/octoprint-grbl-plugin)
Expand Down Expand Up @@ -703,6 +715,7 @@ def send_frame_init_gcode(self):
self._printer.commands("G91")
# self._printer.commands("M8")


def send_frame_end_gcode(self):
# self._printer.commands("M9")
self._printer.commands("G1S0")
Expand All @@ -713,32 +726,37 @@ def send_frame_end_gcode(self):
self._printer.commands("G4 P0")
self._printer.commands("$32=1")


def send_bounding_box_upper_left(self, y, x):
self._printer.commands("G0 X{:f} F2000 S{}".format(x, self.weakLaserValue))
self._printer.commands("G0 Y{:f} F2000 S{}".format(y * -1, self.weakLaserValue))
self._printer.commands("G0 X{:f} F2000 S{}".format(x * -1, self.weakLaserValue))
self._printer.commands("G0 Y{:f} F2000 S{}".format(y, self.weakLaserValue))


def send_bounding_box_upper_center(self, y, x):
self._printer.commands("G0 X{:f} F2000 S{}".format(x / 2, self.weakLaserValue))
self._printer.commands("G0 Y{:f} F2000 S{}".format(y * -1, self.weakLaserValue))
self._printer.commands("G0 X{:f} F2000 S{}".format(x * -1, self.weakLaserValue))
self._printer.commands("G0 Y{:f} F2000 S{}".format(y, self.weakLaserValue))
self._printer.commands("G0 X{:f} F2000 S{}".format(x / 2, self.weakLaserValue))


def send_bounding_box_upper_right(self, y, x):
self._printer.commands("G0 Y{:f} F2000 S{}".format(y * -1, self.weakLaserValue))
self._printer.commands("G0 X{:f} F2000 S{}".format(x * -1, self.weakLaserValue))
self._printer.commands("G0 Y{:f} F2000 S{}".format(y, self.weakLaserValue))
self._printer.commands("G0 X{:f} F2000 S{}".format(x, self.weakLaserValue))


def send_bounding_box_center_left(self, y, x):
self._printer.commands("G0 Y{:f} F2000 S{}".format(y / 2, self.weakLaserValue))
self._printer.commands("G0 X{:f} F2000 S{}".format(x, self.weakLaserValue))
self._printer.commands("G0 Y{:f} F2000 S{}".format(y * -1, self.weakLaserValue))
self._printer.commands("G0 X{:f} F2000 S{}".format(x * -1, self.weakLaserValue))
self._printer.commands("G0 Y{:f} F2000 S{}".format(y / 2, self.weakLaserValue))


def send_bounding_box_center(self, y, x):
self._printer.commands("G0 X{:f} Y{:f} F4000".format(x / 2 * -1, y / 2))
self._printer.commands("G0 X{} F2000 S{}".format(x, self.weakLaserValue))
Expand All @@ -747,19 +765,22 @@ def send_bounding_box_center(self, y, x):
self._printer.commands("G0 Y{} S{}".format(y, self.weakLaserValue))
self._printer.commands("G0 X{:f} Y{:f} F4000".format(x / 2, y / 2 * -1))


def send_bounding_box_center_right(self, y, x):
self._printer.commands("G0 Y{:f} F2000 S{}".format(y / 2 * -1, self.weakLaserValue))
self._printer.commands("G0 X{:f} F2000 S{}".format(x * -1, self.weakLaserValue))
self._printer.commands("G0 Y{:f} F2000 S{}".format(y, self.weakLaserValue))
self._printer.commands("G0 X{:f} F2000 S{}".format(x, self.weakLaserValue))
self._printer.commands("G0 Y{:f} F2000 S{}".format(y / 2 * -1, self.weakLaserValue))


def send_bounding_box_lower_left(self, y, x):
self._printer.commands("G0 Y{:f} F2000 S{}".format(y, self.weakLaserValue))
self._printer.commands("G0 X{:f} F2000 S{}".format(x, self.weakLaserValue))
self._printer.commands("G0 Y{:f} F2000 S{}".format(y * -1, self.weakLaserValue))
self._printer.commands("G0 X{:f} F2000 S{}".format(x * -1, self.weakLaserValue))


def send_bounding_box_lower_center(self, y, x):
self._printer.commands("G0 X{:f} F2000 S{}".format(x / 2 * -1, self.weakLaserValue))
self._printer.commands("G0 Y{:f} F2000 S{}".format(y, self.weakLaserValue))
Expand All @@ -774,6 +795,7 @@ def send_bounding_box_lower_right(self, y, x):
self._printer.commands("G0 X{:f} F2000 S{}".format(x, self.weakLaserValue))
self._printer.commands("G0 Y{:f} F2000 S{}".format(y * -1, self.weakLaserValue))


def get_api_commands(self):
return dict(
frame=[],
Expand All @@ -790,6 +812,7 @@ def get_api_commands(self):
restoreGrblSettings=[]
)


def on_api_command(self, command, data):
if command == "sleep":
self._printer.commands("$SLP")
Expand Down Expand Up @@ -933,7 +956,6 @@ def on_api_command(self, command, data):
self._printer.commands("G0 Z{}".format(distance * -1))
self._printer.commands("G90")


return

if command == "originxy":
Expand Down Expand Up @@ -979,6 +1001,7 @@ def on_api_command(self, command, data):
if command == "toggleWeak":
return flask.jsonify({'res' : self.toggleWeak()})


def toggleWeak(self):
# do laser stuff
powerLevel = self.grblPowerLevel
Expand Down Expand Up @@ -1018,7 +1041,7 @@ def get_update_information(self):
"branch": "master",
"commitish": ["master"],
},
prerelease_branches=[
prerelease_branches=[
{
"name": "Release Candidate",
"branch": "rc",
Expand All @@ -1029,10 +1052,10 @@ def get_update_information(self):
"branch": "devel",
"commitish": ["devel", "rc", "master"],
}

],
pip='https://github.com/synman/OctoPrint-Bettergrblsupport/archive/{target_version}.zip'))


# If you want your plugin to be registered within OctoPrint under a different name than what you defined in setup.py
# ("OctoPrint-PluginSkeleton"), you may define that here. Same goes for the other metadata derived from setup.py that
# can be overwritten via __plugin_xyz__ control properties. See the documentation for that.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
plugin_name = "Better Grbl Support"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "1.7.6dev2"
plugin_version = "1.7.6dev3"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down

0 comments on commit a1a9778

Please sign in to comment.