Major refactor
This commit is contained in:
parent
36955f76fd
commit
41491ffbe8
octoprint_klipper
|
@ -14,99 +14,178 @@ class KlipperPlugin(
|
|||
octoprint.plugin.AssetPlugin,
|
||||
octoprint.plugin.EventHandlerPlugin):
|
||||
|
||||
_parsingResponse = False
|
||||
_parsing_response = False
|
||||
_message = ""
|
||||
|
||||
#-- Startup Plugin
|
||||
|
||||
def on_after_startup(self):
|
||||
klipperPort = self._settings.get(["serialport"])
|
||||
additionalPorts = self._settings.global_get(["serial", "additionalPorts"])
|
||||
klipper_port = self._settings.get(["connection", "port"])
|
||||
additional_ports = self._settings.global_get(["serial", "additionalPorts"])
|
||||
|
||||
if klipperPort not in additionalPorts:
|
||||
additionalPorts.append(klipperPort)
|
||||
self._settings.global_set(["serial", "additionalPorts"], additionalPorts)
|
||||
if klipper_port not in additional_ports:
|
||||
additional_ports.append(klipper_port)
|
||||
self._settings.global_set(["serial", "additionalPorts"], additional_ports)
|
||||
self._settings.save()
|
||||
self._logger.info("Added klipper serial port {} to list of additional ports.".format(klipperPort))
|
||||
self._logger.info("Added klipper serial port {} to list of additional ports.".format(klipper_port))
|
||||
|
||||
#-- Settings Plugin
|
||||
|
||||
def get_settings_defaults(self):
|
||||
return dict(
|
||||
serialport="/tmp/printer",
|
||||
replace_connection_panel=True,
|
||||
macros=[{'name':"E-Stop", 'macro':"M112", 'sidebar':True, 'tab':True}],
|
||||
probeHeight=0,
|
||||
probeLift=5,
|
||||
probeSpeedXy=1500,
|
||||
probeSpeedZ=500,
|
||||
probePoints=[{'x':0, 'y':0}],
|
||||
configPath="/home/pi/printer.cfg"
|
||||
connection = dict(
|
||||
port="/tmp/printer",
|
||||
replace_connection_panel=True
|
||||
),
|
||||
macros = [dict(
|
||||
name="E-Stop",
|
||||
macro="M112",
|
||||
sidebar=True,
|
||||
tab=True
|
||||
)],
|
||||
probe = dict(
|
||||
height=0,
|
||||
lift=5,
|
||||
speed_xy=1500,
|
||||
speed_z=500,
|
||||
points=[dict(
|
||||
name="point-1",
|
||||
x=0,
|
||||
y=0
|
||||
)]
|
||||
),
|
||||
configuration = dict(
|
||||
path="/home/pi/printer.cfg"
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def on_settings_load(self):
|
||||
data = octoprint.plugin.SettingsPlugin.on_settings_load(self)
|
||||
f = open(self._settings.get(["configPath"]), "r")
|
||||
f = open(self._settings.get(["configuration", "path"]), "r")
|
||||
if f:
|
||||
data["config"] = f.read()
|
||||
f.close()
|
||||
else:
|
||||
self._logger.info(
|
||||
"Error: Klipper config file not found at: {}".format(self._settings.get(["configPath"]))
|
||||
"Error: Klipper config file not found at: {}".format(self._settings.get(["config_path"]))
|
||||
)
|
||||
return data
|
||||
|
||||
def on_settings_save(self, data):
|
||||
if "config" in data:
|
||||
f = open(self._settings.get(["configPath"]), "w")
|
||||
f = open(self._settings.get(["configuration", "path"]), "w")
|
||||
if f:
|
||||
f.write(data["config"])
|
||||
f.close()
|
||||
self._logger.info(
|
||||
"Write Klipper config to {}".format(self._settings.get(["configPath"]))
|
||||
"Write Klipper config to {}".format(self._settings.get(["config_path"]))
|
||||
)
|
||||
# Restart klipply to reload config
|
||||
self._printer.commands("RESTART")
|
||||
self.logInfo("Reloading Klipper Configuration.")
|
||||
else:
|
||||
self._logger.info(
|
||||
"Error: Couldn't write Klipper config file: {}".format(self._settings.get(["configPath"]))
|
||||
"Error: Couldn't write Klipper config file: {}".format(self._settings.get(["config_path"]))
|
||||
)
|
||||
data.pop('config', None) # we dont want to write the klipper conf to the octoprint settings
|
||||
data.pop("config", None) # we dont want to write the klipper conf to the octoprint settings
|
||||
else:
|
||||
octoprint.plugin.SettingsPlugin.on_settings_save(self, data)
|
||||
|
||||
def get_settings_restricted_paths(self):
|
||||
return dict(
|
||||
admin=[
|
||||
["serialport"],
|
||||
["configPath"],
|
||||
["replace_connection_panel"]
|
||||
["connection", "port"],
|
||||
["configuration", "path"],
|
||||
["configuration", "replace_connection_panel"]
|
||||
],
|
||||
user=[
|
||||
["macros"],
|
||||
["probeHeight"],
|
||||
["probeLift"],
|
||||
["probeSpeedXy"],
|
||||
["probeSpeedZ"],
|
||||
["probePoints"]
|
||||
["probe"]
|
||||
]
|
||||
)
|
||||
|
||||
def get_settings_version(self):
|
||||
return 2
|
||||
|
||||
def on_settings_migrate(self, target, current):
|
||||
if current is None:
|
||||
settings = self._settings
|
||||
|
||||
if settings.has(["serialport"]):
|
||||
settings.set(["connection", "port"], settings.get(["serialport"]) )
|
||||
settings.remove(["serialport"])
|
||||
|
||||
if settings.has(["replace_connection_panel"]):
|
||||
settings.set(
|
||||
["connection", "replace_connection_panel"],
|
||||
settings.get(["replace_connection_panel"])
|
||||
)
|
||||
settings.remove(["replace_connection_panel"])
|
||||
|
||||
if settings.has(["probeHeight"]):
|
||||
settings.set(["probe", "height"], settings.get(["probeHeight"]))
|
||||
settings.remove(["probeHeight"])
|
||||
|
||||
if settings.has(["probeLift"]):
|
||||
settings.set(["probe", "lift"], settings.get(["probeLift"]))
|
||||
settings.remove(["probeLift"])
|
||||
|
||||
if settings.has(["probeSpeedXy"]):
|
||||
settings.set(["probe", "speed_xy"], settings.get(["probeSpeedXy"]))
|
||||
settings.remove(["probeSpeedXy"])
|
||||
|
||||
if settings.has(["probeSpeedZ"]):
|
||||
settings.set(["probe", "speed_z"], settings.get(["probeSpeedZ"]))
|
||||
settings.remove(["probeSpeedZ"])
|
||||
|
||||
if settings.has(["probePoints"]):
|
||||
points = settings.get(["probePoints"])
|
||||
points_new = []
|
||||
for p in points:
|
||||
points_new.append(dict(name="", x=int(p["x"]), y=int(p["y"]), z=0))
|
||||
settings.set(["probe", "points"], points_new)
|
||||
settings.remove(["probePoints"])
|
||||
|
||||
if settings.has(["configPath"]):
|
||||
settings.set(["config_path"], settings.get(["configPath"]))
|
||||
settings.remove(["configPath"])
|
||||
|
||||
#-- Template Plugin
|
||||
|
||||
def get_template_configs(self):
|
||||
return [
|
||||
dict(type="navbar", custom_bindings=True),
|
||||
dict(type="settings", custom_bindings=True),
|
||||
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="generic", name="Coordinate Offset", template="klipper_offset_dialog.jinja2", custom_bindings=True),
|
||||
dict(type="tab", name="Klipper", template="klipper_tab_main.jinja2", suffix="_main", custom_bindings=True),
|
||||
dict(type="sidebar",
|
||||
custom_bindings=True,
|
||||
icon="rocket",
|
||||
replaces= "connection" if self._settings.get_boolean(["replace_connection_panel"]) else "")
|
||||
dict(type="navbar", custom_bindings=True),
|
||||
dict(type="settings", custom_bindings=True),
|
||||
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="generic",
|
||||
name="Coordinate Offset",
|
||||
template="klipper_offset_dialog.jinja2",
|
||||
custom_bindings=True
|
||||
),
|
||||
dict(
|
||||
type="tab",
|
||||
name="Klipper",
|
||||
template="klipper_tab_main.jinja2",
|
||||
suffix="_main",
|
||||
custom_bindings=True
|
||||
),
|
||||
dict(type="sidebar",
|
||||
custom_bindings=True,
|
||||
icon="rocket",
|
||||
replaces= "connection" if self._settings.get_boolean(["connection", "replace_connection_panel"]) else ""
|
||||
)
|
||||
]
|
||||
|
||||
#-- Asset Plugin
|
||||
|
@ -145,12 +224,12 @@ class KlipperPlugin(
|
|||
self.logInfo("Firmware version: {}".format(printerInfo["FIRMWARE_VERSION"]))
|
||||
elif "//" in line:
|
||||
self._message = self._message + line.strip('/')
|
||||
if not self._parsingResponse:
|
||||
if not self._parsing_response:
|
||||
self.updateStatus("info", self._message)
|
||||
self._parsingResponse = True
|
||||
self._parsing_response = True
|
||||
else:
|
||||
if self._parsingResponse:
|
||||
self._parsingResponse = False
|
||||
if self._parsing_response:
|
||||
self._parsing_response = False
|
||||
self.logInfo(self._message)
|
||||
self._message = ""
|
||||
if "!!" in line:
|
||||
|
@ -161,25 +240,26 @@ class KlipperPlugin(
|
|||
|
||||
#-- Helpers
|
||||
def sendMessage(self, type, subtype, payload):
|
||||
self._plugin_manager.send_plugin_message(
|
||||
self._identifier,
|
||||
dict(
|
||||
time=datetime.datetime.now().strftime("%H:%M:%S"),
|
||||
type=type, payload=payload)
|
||||
)
|
||||
self._plugin_manager.send_plugin_message(
|
||||
self._identifier,
|
||||
dict(
|
||||
time=datetime.datetime.now().strftime("%H:%M:%S"),
|
||||
type=type,
|
||||
payload=payload
|
||||
)
|
||||
)
|
||||
|
||||
def pollStatus(self):
|
||||
self._printer.commands("STATUS")
|
||||
|
||||
self._printer.commands("STATUS")
|
||||
|
||||
def updateStatus(self, type, status):
|
||||
self.sendMessage("status", type, status)
|
||||
self.sendMessage("status", type, status)
|
||||
|
||||
def logInfo(self, message):
|
||||
self.sendMessage("log", "info", message)
|
||||
self.sendMessage("log", "info", message)
|
||||
|
||||
def logError(self, error):
|
||||
self.sendMessage("log", "error", error)
|
||||
|
||||
self.sendMessage("log", "error", error)
|
||||
|
||||
|
||||
|
||||
|
@ -188,7 +268,7 @@ __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
|
||||
|
|
|
@ -34,4 +34,8 @@
|
|||
|
||||
.clear-btn {
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
#plugin-klipper-config {
|
||||
font-family: monospace;
|
||||
}
|
|
@ -53,7 +53,7 @@ $(function() {
|
|||
};
|
||||
|
||||
self.onAfterBinding = function() {
|
||||
self.connectionState.selectedPort(self.settings.settings.plugins.klipper.serialport());
|
||||
self.connectionState.selectedPort(self.settings.settings.plugins.klipper.connection.port());
|
||||
}
|
||||
|
||||
self.onDataUpdaterPluginMessage = function(plugin, message) {
|
||||
|
|
|
@ -18,8 +18,8 @@ $(function() {
|
|||
|
||||
self.stopLeveling = function() {
|
||||
OctoPrint.control.sendGcode("G1 Z" +
|
||||
(self.settings.settings.plugins.klipper.probeHeight()*1 +
|
||||
self.settings.settings.plugins.klipper.probeLift()*1)
|
||||
(self.settings.settings.plugins.klipper.probe.height()*1 +
|
||||
self.settings.settings.plugins.klipper.probe.lift()*1)
|
||||
);
|
||||
self.gotoHome();
|
||||
}
|
||||
|
@ -39,32 +39,32 @@ $(function() {
|
|||
|
||||
self.jumpToPoint = function(item) {
|
||||
self.moveToPoint(
|
||||
self.settings.settings.plugins.klipper.probePoints().indexOf(item)
|
||||
self.settings.settings.plugins.klipper.probe.points().indexOf(item)
|
||||
);
|
||||
}
|
||||
|
||||
self.pointCount = function() {
|
||||
return self.settings.settings.plugins.klipper.probePoints().length;
|
||||
return self.settings.settings.plugins.klipper.probe.points().length;
|
||||
}
|
||||
|
||||
self.moveToPosition = function(x, y) {
|
||||
OctoPrint.control.sendGcode(
|
||||
"G1 Z" + (self.settings.settings.plugins.klipper.probeHeight() * 1 +
|
||||
self.settings.settings.plugins.klipper.probeLift()*1) +
|
||||
" F" + self.settings.settings.plugins.klipper.probeSpeedZ()
|
||||
"G1 Z" + (self.settings.settings.plugins.klipper.probe.height() * 1 +
|
||||
self.settings.settings.plugins.klipper.probe.lift()*1) +
|
||||
" F" + self.settings.settings.plugins.klipper.probe.speed_z()
|
||||
);
|
||||
OctoPrint.control.sendGcode(
|
||||
"G1 X" + x + " Y" + y +
|
||||
" F" + self.settings.settings.plugins.klipper.probeSpeedXy()
|
||||
" F" + self.settings.settings.plugins.klipper.probe.speed_xy()
|
||||
);
|
||||
OctoPrint.control.sendGcode(
|
||||
"G1 Z" + self.settings.settings.plugins.klipper.probeHeight() +
|
||||
" F" + self.settings.settings.plugins.klipper.probeSpeedZ()
|
||||
"G1 Z" + self.settings.settings.plugins.klipper.probe.height() +
|
||||
" F" + self.settings.settings.plugins.klipper.probe.speed_z()
|
||||
);
|
||||
}
|
||||
|
||||
self.moveToPoint = function(index) {
|
||||
var point = self.settings.settings.plugins.klipper.probePoints()[index];
|
||||
var point = self.settings.settings.plugins.klipper.probe.points()[index];
|
||||
|
||||
self.moveToPosition(point.x(), point.y());
|
||||
self.activePoint(index);
|
||||
|
|
|
@ -27,19 +27,24 @@ $(function() {
|
|||
}
|
||||
|
||||
self.addProbePoint = function() {
|
||||
self.settings.settings.plugins.klipper.probePoints.push({x: 0, y:0, z:0});
|
||||
self.settings.settings.plugins.klipper.probe.points.push(
|
||||
{
|
||||
name: 'point-#',
|
||||
x:0, y:0, z:0
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
self.removeProbePoint = function(point) {
|
||||
self.settings.settings.plugins.klipper.probePoints.remove(point);
|
||||
self.settings.settings.plugins.klipper.probe.points.remove(point);
|
||||
}
|
||||
|
||||
self.moveProbePointUp = function(macro) {
|
||||
self.moveItemUp(self.settings.settings.plugins.klipper.probePoints, macro)
|
||||
self.moveItemUp(self.settings.settings.plugins.klipper.probe.points, macro)
|
||||
}
|
||||
|
||||
self.moveProbePointDown = function(macro) {
|
||||
self.moveItemDown(self.settings.settings.plugins.klipper.probePoints, macro)
|
||||
self.moveItemDown(self.settings.settings.plugins.klipper.probe.points, macro)
|
||||
}
|
||||
|
||||
self.moveItemDown = function(list, item) {
|
||||
|
@ -57,36 +62,6 @@ $(function() {
|
|||
list.splice(i-1, 2, rawList[i], rawList[i-1]);
|
||||
}
|
||||
}
|
||||
|
||||
self.loadKlipperConfig = function() {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/api/plugin/klipper",
|
||||
headers: {'X-Api-Key': '2CE2F6BA87244897B7F3A1BED3B1A3ED'}
|
||||
})
|
||||
.done(function( msg ) {
|
||||
self.klipperConfig(msg)
|
||||
});
|
||||
}
|
||||
|
||||
self.saveKlipperConfig = function() {
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: "/api/plugin/klipper",
|
||||
headers: {
|
||||
"x-api-key": "2CE2F6BA87244897B7F3A1BED3B1A3ED",
|
||||
"content-type": "application/json",
|
||||
"cache-control": "no-cache"
|
||||
},
|
||||
data: {
|
||||
command: "save_config",
|
||||
text: encodeURI(self.klipperConfig)
|
||||
}
|
||||
})
|
||||
.done(function( msg ) {
|
||||
console.log(msg);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
OCTOPRINT_VIEWMODELS.push({
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
</div>
|
||||
<div class="span7"> </div>
|
||||
</div>
|
||||
<div data-bind="foreach: settings.settings.plugins.klipper.probePoints">
|
||||
<div data-bind="foreach: settings.settings.plugins.klipper.probe.points">
|
||||
<div class="row-fluid">
|
||||
<div class="span1">
|
||||
<i class="fa fa-arrow-right pull-right" data-bind="visible: ($index()==$parent.activePoint())"></i>
|
||||
|
@ -24,7 +24,12 @@
|
|||
<div data-bind="text: $index" class="span1"></div>
|
||||
<div class="span3">
|
||||
<button class="btn btn-mini btn-info btn-block" data-bind="click: $parent.jumpToPoint">
|
||||
<!-- ko if: name -->
|
||||
<span data-bind="text: name"></span>
|
||||
<!-- /ko -->
|
||||
<!-- ko ifnot: name -->
|
||||
( <span data-bind="text: x"></span>, <span data-bind="text: y"></span> )
|
||||
<!-- /ko -->
|
||||
</button>
|
||||
</div>
|
||||
<div class="span7"> </div>
|
||||
|
|
|
@ -10,19 +10,19 @@
|
|||
<div class="control-group">
|
||||
<label class="control-label">{{ _('Serial Port') }}</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="input-block-level" data-bind="value: settings.settings.plugins.klipper.serialport">
|
||||
<input type="text" class="input-block-level" data-bind="value: settings.settings.plugins.klipper.connection.port">
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">{{ _('Replace Connection Panel') }}</label>
|
||||
<div class="controls">
|
||||
<input type="checkbox" class="input-block-level" data-bind="checked: settings.settings.plugins.klipper.replace_connection_panel">
|
||||
<input type="checkbox" class="input-block-level" data-bind="checked: settings.settings.plugins.klipper.connection.replace_connection_panel">
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">{{ _('Klipper Config Path') }}</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="input-block-level" data-bind="value: settings.settings.plugins.klipper.configPath">
|
||||
<input type="text" class="input-block-level" data-bind="value: settings.settings.plugins.klipper.configuration.path">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -80,7 +80,7 @@
|
|||
<label class="control-label">{{ _('Probe Height') }}</label>
|
||||
<div class="controls">
|
||||
<div class="input-append">
|
||||
<input type="text" class="input-block-level span3" data-bind="value: settings.settings.plugins.klipper.probeHeight">
|
||||
<input type="text" class="input-block-level span3" data-bind="value: settings.settings.plugins.klipper.probe.height">
|
||||
<span class="add-on">mm</span>
|
||||
</div>
|
||||
<span class="help-inline">{{ _('Z-height to probe at.') }}</span>
|
||||
|
@ -90,7 +90,7 @@
|
|||
<label class="control-label">{{ _('Probe Lift') }}</label>
|
||||
<div class="controls">
|
||||
<div class="input-append">
|
||||
<input type="text" class="input-block-level span3" data-bind="value: settings.settings.plugins.klipper.probeLift">
|
||||
<input type="text" class="input-block-level span3" data-bind="value: settings.settings.plugins.klipper.probe.lift">
|
||||
<span class="add-on">mm</span>
|
||||
</div>
|
||||
<span class="help-inline">{{ _('Lift Z before moving to next point.') }}</span>
|
||||
|
@ -100,7 +100,7 @@
|
|||
<label class="control-label">{{ _('Probe Feedrate Z') }}</label>
|
||||
<div class="controls">
|
||||
<div class="input-append">
|
||||
<input type="text" class="input-block-level span3" data-bind="value: settings.settings.plugins.klipper.probeSpeedZ">
|
||||
<input type="text" class="input-block-level span3" data-bind="value: settings.settings.plugins.klipper.probe.speed_z">
|
||||
<span class="add-on">mm/min</span>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -109,7 +109,7 @@
|
|||
<label class="control-label">{{ _('Feedrate X/Y') }}</label>
|
||||
<div class="controls">
|
||||
<div class="input-append">
|
||||
<input type="text" class="input-block-level span3" data-bind="value: settings.settings.plugins.klipper.probeSpeedXy">
|
||||
<input type="text" class="input-block-level span3" data-bind="value: settings.settings.plugins.klipper.probe.speed_xy">
|
||||
<span class="add-on">mm/min</span>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -118,16 +118,18 @@
|
|||
<h5>{{ _('Probe Points') }}</h5>
|
||||
<div class="controls">
|
||||
<div class="row-fluid">
|
||||
<div class="span3">X(mm)</div>
|
||||
<div class="span3">Y(mm)</div>
|
||||
<div class="span3">name</div>
|
||||
<div class="span3">x(mm)</div>
|
||||
<div class="span3">y(mm)</div>
|
||||
<div class="span3"> </div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div data-bind="foreach: settings.settings.plugins.klipper.probePoints" class="control-group">
|
||||
<div data-bind="foreach: settings.settings.plugins.klipper.probe.points" class="control-group">
|
||||
<label class="control-label" data-bind="text: $index"></label>
|
||||
<div class="controls">
|
||||
<div class="row-fluid">
|
||||
<div class="span3"><input type="text" class="input-block-level" data-bind="value: name"></div>
|
||||
<div class="span3"><input type="text" class="input-block-level" data-bind="value: x"></div>
|
||||
<div class="span3"><input type="text" class="input-block-level" data-bind="value: y"></div>
|
||||
<div class="span3">
|
||||
|
@ -146,7 +148,7 @@
|
|||
</div>
|
||||
<div class="tab-pane" id="conf">
|
||||
<div class="control-group">
|
||||
<textarea rows="32" class="block" data-bind="value: settings.settings.plugins.klipper.config"></textarea>
|
||||
<textarea id="plugin-klipper-config" rows="31" class="block" data-bind="value: settings.settings.plugins.klipper.config"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue