temp trigger working

This commit is contained in:
sergiuToporjinschi
2022-01-30 10:23:21 +02:00
parent 599d3d5f9d
commit 34d20cc80f
7 changed files with 103 additions and 14 deletions
+8 -5
View File
@@ -1,5 +1,5 @@
# coding=utf-8
from __future__ import absolute_import
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
import octoprint.plugin
@@ -16,13 +16,14 @@ class CalibrationtoolsPlugin(
models.CalibrationModel
):
collectCommand = False
data = {}
def initialize(self):
self.collectCommand = False
# self._api = api.API(self)
def on_after_startup(self):
self._logger.debug("----------------[CalibrationTools]----------------")
self._logger.debug("----------------[ CalibrationTools ]----------------")
self.data = self.getModel()
self.collectCommand = True
self._printer.commands("M92")
@@ -77,7 +78,9 @@ def __plugin_load__():
global __plugin_hooks__
__plugin_hooks__ = {
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information,
"octoprint.comm.protocol.gcode.received": __plugin_implementation__.calibrateGCodeReceived,
"octoprint.comm.protocol.gcode.sending": __plugin_implementation__.calibrateGCodeSending
"octoprint.comm.protocol.firmware.info": __plugin_implementation__.firmwareInfo,
"octoprint.comm.protocol.gcode.received": __plugin_implementation__.gCodeReceived,
"octoprint.comm.protocol.gcode.sending": __plugin_implementation__.gCodeSending,
"octoprint.comm.protocol.temperatures.received": __plugin_implementation__.processTemp
# "octoprint.comm.protocol.atcommand.sending": __plugin_implementation__.comm_protocol_atcommand_sending
}
+11 -2
View File
@@ -1,4 +1,5 @@
from __future__ import absolute_import, division, unicode_literals
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
import octoprint.plugin
import flask
@@ -6,11 +7,16 @@ import flask
CMD_LOAD_STEPS = "loadSteps"
def someTestFunc(self, temps, a, b):
self._logger.debug("a ajuns %s, %s, %s", temps, a,b)
class API(octoprint.plugin.SimpleApiPlugin):
@staticmethod
def get_api_commands():
return {
CMD_LOAD_STEPS: []
CMD_LOAD_STEPS: [],
"TEST": []
}
def on_api_get(self, request):
@@ -28,3 +34,6 @@ class API(octoprint.plugin.SimpleApiPlugin):
return flask.jsonify({
"data": self.data["steps"]
})
if command == "TEST":
self.registerEventTemp("T0", 100, someTestFunc, 1,"test")
return
+53 -4
View File
@@ -1,8 +1,18 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
from ast import arg
import re
import threading
import traceback
class Hooks():
##~~ Softwareupdate hook
def calibrateGCodeReceived(self, comm, line, *args, **kwargs):
if not self.collectCommand: return line
trackTemp = True
events = []
def gCodeReceived(self, comm, line, *args, **kwargs):
if not self.collectCommand:
return line
self._logger.debug("collectCommand is true, collecting info")
reg = re.compile("echo:\s*(?P<command>(?P<gCode>M\d{1,3}) X(?P<xVal>\d{1,3}.\d{1,3}) Y(?P<yVal>\d{1,3}.\d{1,3}) Z(?P<zVal>\d{1,3}.\d{1,3}) E(?P<eVal>\d{1,3}.\d{1,3}))")
@@ -30,7 +40,46 @@ class Hooks():
self.collectCommand = False
return line
def calibrateGCodeSending(self, comm, phase, cmd, cmd_type, gcode, subcode=None, tags=None, *args, **kwargs):
def gCodeSending(self, comm, phase, cmd, cmd_type, gcode, subcode=None, tags=None, *args, **kwargs):
self._logger.debug("Sending GCODE [%s]", gcode)
if cmd == "M92":
self.collectCommand = True
def firmwareInfo(self, comm_instance, firmware_name, firmware_data, *args, **kwargs):
self.data["info"] = {
"firmware": firmware_data
}
## Hook for temperature messages
## This is active only when there are events registered to temperature changes
def processTemp(self, comm_instance, parsed_temperatures, *args, **kwargs):
if len(self.events) <= 0: return parsed_temperatures
try:
self.checkAndTriggerEvent(parsed_temperatures.copy())
except Exception as e:
self._logger.error(traceback.format_exc())
return parsed_temperatures
## Check if the current message contains changes concerning registered tool
## if the criteria is meat then the execution function is called
def checkAndTriggerEvent(self, temps):
for tool, values in temps.items():
(curTemp, trgTemp) = values
for event in self.events:
if event["tool"] == tool and curTemp >= event["targetTemp"]:
threading.Thread(target=event["func"], args=(self, temps, *event["args"])).start()
self.events.remove(event)
def registerEventTemp(self, tool, targetTemp, func, *arguments):
if func is None:
self._logger.warn("registerEventTemp: Attempt to register event without a function")
return
event = {
"tool": tool,
"targetTemp": targetTemp,
"func": func,
"args": arguments
}
self._logger.debug("Registering event [%s]", event)
self.events.append(event)
+10 -1
View File
@@ -1,9 +1,14 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
class CalibrationModel():
def getModel(self):
self._logger.debug("getModel")
steps = self.getSteps()
temps = self.getTemps()
return {
"steps": steps
"steps": steps,
"temps": temps
}
def getSteps(self):
@@ -14,3 +19,7 @@ class CalibrationModel():
"Z": 0,
"E": 0
}
def getTemps(self):
return {'B': (), 'T0': ()}
@@ -66,6 +66,13 @@ $(function () {
self.from_json(response);
});
}
self.test = function () {
OctoPrint.simpleApiCommand("CalibrationTools","TEST").done(function (response) {
console.log(response)
})
}
}
// This is how our plugin registers itself with the application, by adding some configuration
@@ -7,6 +7,16 @@
<!-- <button class="btn" data-bind="click: $root.tempRestart">
RESTART
</button> -->
<div class="row-fluid">
<div class="span6"></div>
<div class="span6">
<button class="btn btn-primary" data-bind="click: $root.test"
title="BTN for testing">
<i class="fas fa-save" data-color="#000000"></i>&nbsp&nbsp
TEST
</button>
</div>
</div>
</div>
<div class="span1 icon">
<a data-bind="click: $root.openCalibrationSettings">
@@ -49,3 +49,5 @@ This calibration is best done with the extruder detached from the hot end, so no
open and the filament exits in free air. If this is inconvenient, the process below aims to minimize restrictions by extruding very slowly and with a slightly higher temperature. The results from this should still be
reliable.
", "text-warning" ) }}