logging: Basic logging of status response

This commit is contained in:
Martin Muehlhaeuser 2018-01-23 17:33:22 +00:00
parent 7b9331d271
commit 1696cd43c6
2 changed files with 32 additions and 23 deletions

View File

@ -36,26 +36,36 @@ class KlipperPlugin(
css=["css/klipper.css"], css=["css/klipper.css"],
less=["css/klipper.less"] less=["css/klipper.less"]
) )
parsingReturn = False
message = ""
def logInfo(self, message):
self._plugin_manager.send_plugin_message(self._identifier, dict(type="info", message=message))
def logError(self, error):
self._plugin_manager.send_plugin_message(self._identifier, dict(type="error", message=error))
def on_parse_gcode(self, comm, line, *args, **kwargs): def on_parse_gcode(self, comm, line, *args, **kwargs):
if "ok" not in line: if "!!" in line:
return line self.logError(line.strip('!'))
else:
self._plugin_manager.send_plugin_message(self._identifier, dict(message=line)) if "//" in line:
#from octoprint.util.comm import parse_firmware_line self.parsingReturn = True
self.message = self.message + line.strip('/')
# Create a dict with all the keys/values returned by the M115 request else:
#printer_data = parse_firmware_line(line) if self.parsingReturn:
self._logger.info("Machine type detected {line}.".format(line=line)) self.parsingReturn = False
#self._logger.info("Machine type detected: {machine}.".format(machine=printer_data["MACHINE_TYPE"])) self.logInfo(self.message)
self.message = ""
return line return line
def on_printer_action(self, comm, line, action, *args, **kwargs): def on_printer_action(self, comm, line, action, *args, **kwargs):
#if not action == "custom": #if not action == "custom":
# return # return
self._plugin_manager.send_plugin_message(self._identifier, dict(message=line))
self._logger.info("action recieved:".action) self._plugin_manager.send_plugin_message(self._identifier, dict(message=action))
#self._logger.info("action recieved:".action)
__plugin_name__ = "Klipper" __plugin_name__ = "Klipper"

View File

@ -22,35 +22,34 @@ $(function() {
self.onGetStatus = function() { self.onGetStatus = function() {
self.shortStatus("Update Status") self.shortStatus("Update Status")
OctoPrint.control.sendGcode("Status")
} }
self.onRestartFirmware = function() { self.onRestartFirmware = function() {
//OctoPrint.control.sendGcode("FIRMWARE_RESTART") self.logMessage("Restarted Firmware");
self.shortStatus("Restarting Firmware"); self.shortStatus("Restarting Firmware");
console.log("Restart firmware"); OctoPrint.control.sendGcode("FIRMWARE_RESTART")
}; };
self.onRestartHost = function() { self.onRestartHost = function() {
self.shortStatus("Restarting Host");
console.log("Restart Host");
self.logMessage("Restarted Host"); self.logMessage("Restarted Host");
//OctoPrint.control.sendGcode("RESTART") self.shortStatus("Restarting Host");
OctoPrint.control.sendGcode("RESTART")
}; };
self.onBeforeBinding = function() { self.onBeforeBinding = function() {
self.connectionState.selectedPort("VIRTUAL"); //self.connectionState.selectedPort("VIRTUAL");
} }
self.onAfterBinding = function() { self.onAfterBinding = function() {
self.connectionState.selectedPort("VIRTUAL"); self.connectionState.selectedPort(self.settings.settings.plugins.klipper.serialport());
console.log(self.connectionState.selectedPort()); console.log(self.connectionState.selectedPort());
self.shortStatus("Idle"); self.shortStatus("Idle");
} }
self.onDataUpdaterPluginMessage = function(plugin, message) { self.onDataUpdaterPluginMessage = function(plugin, message) {
//console.log(message); //console.log(message);
self.logMessage("plugin: " +plugin+ " message recieved: " + message["message"]); self.logMessage(message["message"]);
} }
self.logMessage = function(message) { self.logMessage = function(message) {