OctoprintKlipperPlugin/octoprint_klipper/__init__.py

98 lines
3.1 KiB
Python
Raw Normal View History

2018-01-23 17:01:58 +03:00
# coding=utf-8
from __future__ import absolute_import
import datetime
2018-01-23 17:01:58 +03:00
import logging
import octoprint.plugin
import octoprint.plugin.core
class KlipperPlugin(
octoprint.plugin.StartupPlugin,
octoprint.plugin.TemplatePlugin,
octoprint.plugin.SettingsPlugin,
2018-01-24 19:15:48 +03:00
octoprint.plugin.AssetPlugin,
octoprint.plugin.WizardPlugin):
2018-01-23 17:01:58 +03:00
def on_after_startup(self):
2018-01-23 21:14:28 +03:00
pass
2018-01-23 17:01:58 +03:00
def get_settings_defaults(self):
return dict(
serialport="/tmp/printer",
replace_connection_panel=True,
2018-01-25 01:49:11 +03:00
macros=[{'name':"E-Stop", 'macro':"M112", 'sidebar':True, 'tab':True}],
2018-01-23 23:31:43 +03:00
probeHeight=0,
2018-01-24 19:15:48 +03:00
probeLift=5,
2018-01-24 22:54:13 +03:00
probeSpeedXy=1500,
probeSpeedZ=500,
2018-01-23 23:31:43 +03:00
probePoints=[{'x':0, 'y':0}])
2018-01-23 17:01:58 +03:00
def get_template_configs(self):
return [
# dict(type="navbar", custom_bindings=True),
2018-01-23 17:01:58 +03:00
dict(type="settings", custom_bindings=True),
2018-01-24 19:15:48 +03:00
dict(type="generic", name="Assisted Bed Leveling", template="klipper_leveling_dialog.jinja2", custom_bindings=True),
dict(type="generic", name="PID Tuning", template="klipper_pid_tuning_dialog.jinja2", custom_bindings=True),
dict(type="tab", name="Klipper", template="klipper_tab_main.jinja2", suffix="_main", custom_bindings=True),
2018-01-23 17:01:58 +03:00
dict(type="sidebar",
custom_bindings=True,
replaces= "connection" if self._settings.get(["replace_connection_panel"]) else "")
]
def get_assets(self):
return dict(
2018-01-24 19:15:48 +03:00
js=["js/klipper.js",
"js/klipper_settings.js",
"js/klipper_leveling.js",
"js/klipper_pid_tuning.js"],
2018-01-23 17:01:58 +03:00
css=["css/klipper.css"],
less=["css/klipper.less"]
)
parsingReturn = False
message = ""
def logInfo(self, message):
self._plugin_manager.send_plugin_message(
self._identifier,
dict(
time=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
type="info", message=message)
)
def logError(self, error):
self._plugin_manager.send_plugin_message(
self._identifier,
dict(
time=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
type="error",
message=error)
)
2018-01-23 17:01:58 +03:00
def on_parse_gcode(self, comm, line, *args, **kwargs):
2018-01-23 21:14:28 +03:00
if "//" in line:
self.parsingReturn = True
self.message = self.message + line.strip('/')
else:
2018-01-23 21:14:28 +03:00
if self.parsingReturn:
self.parsingReturn = False
self.logInfo(self.message)
self.message = ""
2018-01-23 21:14:28 +03:00
if "!!" in line:
self.logError(line.strip('!'))
2018-01-23 17:01:58 +03:00
return line
2018-01-24 19:15:48 +03:00
def is_wizard_required(self):
return True;
2018-01-23 17:01:58 +03:00
__plugin_name__ = "Klipper"
def __plugin_load__():
global __plugin_implementation__
global __plugin_hooks__
__plugin_implementation__ = KlipperPlugin()
__plugin_hooks__ = {
"octoprint.comm.protocol.gcode.received": __plugin_implementation__.on_parse_gcode,
}