From 1696cd43c6eadf1949d0d5fb1f274993f4470e37 Mon Sep 17 00:00:00 2001 From: Martin Muehlhaeuser Date: Tue, 23 Jan 2018 17:33:22 +0000 Subject: [PATCH] logging: Basic logging of status response --- octoprint_klipper/__init__.py | 38 ++++++++++++++++---------- octoprint_klipper/static/js/klipper.js | 17 ++++++------ 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/octoprint_klipper/__init__.py b/octoprint_klipper/__init__.py index baba3f2..1e1c296 100644 --- a/octoprint_klipper/__init__.py +++ b/octoprint_klipper/__init__.py @@ -36,26 +36,36 @@ class KlipperPlugin( css=["css/klipper.css"], 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): - if "ok" not in line: - return line - - self._plugin_manager.send_plugin_message(self._identifier, dict(message=line)) - #from octoprint.util.comm import parse_firmware_line - - # Create a dict with all the keys/values returned by the M115 request - #printer_data = parse_firmware_line(line) - self._logger.info("Machine type detected {line}.".format(line=line)) - #self._logger.info("Machine type detected: {machine}.".format(machine=printer_data["MACHINE_TYPE"])) - + if "!!" in line: + self.logError(line.strip('!')) + else: + if "//" in line: + self.parsingReturn = True + self.message = self.message + line.strip('/') + else: + if self.parsingReturn: + self.parsingReturn = False + self.logInfo(self.message) + self.message = "" return line def on_printer_action(self, comm, line, action, *args, **kwargs): #if not action == "custom": # return - - self._logger.info("action recieved:".action) + self._plugin_manager.send_plugin_message(self._identifier, dict(message=line)) + self._plugin_manager.send_plugin_message(self._identifier, dict(message=action)) + #self._logger.info("action recieved:".action) __plugin_name__ = "Klipper" diff --git a/octoprint_klipper/static/js/klipper.js b/octoprint_klipper/static/js/klipper.js index 2ab31e3..6ce7e81 100644 --- a/octoprint_klipper/static/js/klipper.js +++ b/octoprint_klipper/static/js/klipper.js @@ -22,35 +22,34 @@ $(function() { self.onGetStatus = function() { self.shortStatus("Update Status") + OctoPrint.control.sendGcode("Status") } self.onRestartFirmware = function() { - //OctoPrint.control.sendGcode("FIRMWARE_RESTART") + self.logMessage("Restarted Firmware"); self.shortStatus("Restarting Firmware"); - console.log("Restart firmware"); + OctoPrint.control.sendGcode("FIRMWARE_RESTART") }; self.onRestartHost = function() { - - self.shortStatus("Restarting Host"); - console.log("Restart Host"); self.logMessage("Restarted Host"); - //OctoPrint.control.sendGcode("RESTART") + self.shortStatus("Restarting Host"); + OctoPrint.control.sendGcode("RESTART") }; self.onBeforeBinding = function() { - self.connectionState.selectedPort("VIRTUAL"); + //self.connectionState.selectedPort("VIRTUAL"); } self.onAfterBinding = function() { - self.connectionState.selectedPort("VIRTUAL"); + self.connectionState.selectedPort(self.settings.settings.plugins.klipper.serialport()); console.log(self.connectionState.selectedPort()); self.shortStatus("Idle"); } self.onDataUpdaterPluginMessage = function(plugin, message) { //console.log(message); - self.logMessage("plugin: " +plugin+ " message recieved: " + message["message"]); + self.logMessage(message["message"]); } self.logMessage = function(message) {