-
-
Save cesarvandevelde/6e4b54ce1977cb89ffa875d095c550af to your computer and use it in GitHub Desktop.
OctoPrint-AckAckAck
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
from __future__ import absolute_import | |
import octoprint.plugin | |
import logging | |
from collections import deque | |
class AckAckAckPlugin(octoprint.plugin.StartupPlugin, | |
octoprint.plugin.SettingsPlugin): | |
def __init__(self): | |
super(AckAckAckPlugin, self).__init__() | |
self._comm_tail = deque(maxlen=10) # Buffer 10 lines | |
def on_startup(self, host, port): | |
from octoprint.logging.handlers import CleaningTimedRotatingFileHandler | |
path = self._settings.get_plugin_logfile_path() | |
logging_handler = CleaningTimedRotatingFileHandler(path, | |
when="D", | |
backupCount=10) | |
formatter = logging.Formatter("%(asctime)s %(message)s") | |
logging_handler.setFormatter(formatter) | |
logging_handler.setLevel(logging.DEBUG) | |
self._logger.addHandler(logging_handler) | |
self._logger.setLevel(logging.DEBUG) | |
self._logger.propagate = False | |
def on_gcode_received(self, comm, line, *args, **kwargs): | |
self._comm_tail.append("Recv: {}".format(line)) | |
if "o\\x00k" in line or "o\x00k" in line: | |
self._logger.error("Garbled OK detected:") | |
self._logger.error("-" * 80) | |
for l in self._comm_tail: | |
self._logger.error(l) | |
self._logger.error("-" * 80) | |
return "ok" | |
elif "\x00" in line: | |
self._logger.error("Potential garble detected:") | |
self._logger.error("-" * 80) | |
for l in self._comm_tail: | |
self._logger.error(l) | |
self._logger.error("-" * 80) | |
return line | |
def on_gcode_sent(self, comm_instance, phase, cmd, cmd_type, gcode, | |
*args, **kwargs): | |
self._comm_tail.append("Send: {}".format(cmd)) | |
def get_update_information(self): | |
return dict( | |
ackackack=dict( | |
displayName="Ackackack Plugin", | |
displayVersion=self._plugin_version, | |
# version check: github repository | |
type="github_release", | |
user="cesarvandevelde", | |
repo="OctoPrint-AckAckAck", | |
current=self._plugin_version, | |
# update method: pip | |
pip="https://github.com/cesarvandevelde/OctoPrint-AckAckAck/archive/{target_version}.zip" | |
) | |
) | |
__plugin_name__ = "OctoPrint-AckAckAck" | |
def __plugin_load__(): | |
global __plugin_implementation__ | |
__plugin_implementation__ = AckAckAckPlugin() | |
global __plugin_hooks__ | |
__plugin_hooks__ = { | |
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information, | |
"octoprint.comm.protocol.gcode.received": __plugin_implementation__.on_gcode_received, | |
"octoprint.comm.protocol.gcode.sent": __plugin_implementation__.on_gcode_sent | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment