temp trigger working
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
# coding=utf-8
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
import octoprint.plugin
|
import octoprint.plugin
|
||||||
|
|
||||||
@@ -16,13 +16,14 @@ class CalibrationtoolsPlugin(
|
|||||||
models.CalibrationModel
|
models.CalibrationModel
|
||||||
):
|
):
|
||||||
collectCommand = False
|
collectCommand = False
|
||||||
|
data = {}
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
self.collectCommand = False
|
self.collectCommand = False
|
||||||
# self._api = api.API(self)
|
# self._api = api.API(self)
|
||||||
|
|
||||||
def on_after_startup(self):
|
def on_after_startup(self):
|
||||||
self._logger.debug("----------------[CalibrationTools]----------------")
|
self._logger.debug("----------------[ CalibrationTools ]----------------")
|
||||||
self.data = self.getModel()
|
self.data = self.getModel()
|
||||||
self.collectCommand = True
|
self.collectCommand = True
|
||||||
self._printer.commands("M92")
|
self._printer.commands("M92")
|
||||||
@@ -77,7 +78,9 @@ def __plugin_load__():
|
|||||||
global __plugin_hooks__
|
global __plugin_hooks__
|
||||||
__plugin_hooks__ = {
|
__plugin_hooks__ = {
|
||||||
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information,
|
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information,
|
||||||
"octoprint.comm.protocol.gcode.received": __plugin_implementation__.calibrateGCodeReceived,
|
"octoprint.comm.protocol.firmware.info": __plugin_implementation__.firmwareInfo,
|
||||||
"octoprint.comm.protocol.gcode.sending": __plugin_implementation__.calibrateGCodeSending
|
"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
|
# "octoprint.comm.protocol.atcommand.sending": __plugin_implementation__.comm_protocol_atcommand_sending
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 octoprint.plugin
|
||||||
import flask
|
import flask
|
||||||
@@ -6,11 +7,16 @@ import flask
|
|||||||
CMD_LOAD_STEPS = "loadSteps"
|
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):
|
class API(octoprint.plugin.SimpleApiPlugin):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_api_commands():
|
def get_api_commands():
|
||||||
return {
|
return {
|
||||||
CMD_LOAD_STEPS: []
|
CMD_LOAD_STEPS: [],
|
||||||
|
"TEST": []
|
||||||
}
|
}
|
||||||
|
|
||||||
def on_api_get(self, request):
|
def on_api_get(self, request):
|
||||||
@@ -28,3 +34,6 @@ class API(octoprint.plugin.SimpleApiPlugin):
|
|||||||
return flask.jsonify({
|
return flask.jsonify({
|
||||||
"data": self.data["steps"]
|
"data": self.data["steps"]
|
||||||
})
|
})
|
||||||
|
if command == "TEST":
|
||||||
|
self.registerEventTemp("T0", 100, someTestFunc, 1,"test")
|
||||||
|
return
|
||||||
|
|||||||
@@ -1,8 +1,18 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
from ast import arg
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
import threading
|
||||||
|
import traceback
|
||||||
|
|
||||||
class Hooks():
|
class Hooks():
|
||||||
##~~ Softwareupdate hook
|
trackTemp = True
|
||||||
def calibrateGCodeReceived(self, comm, line, *args, **kwargs):
|
events = []
|
||||||
if not self.collectCommand: return line
|
|
||||||
|
def gCodeReceived(self, comm, line, *args, **kwargs):
|
||||||
|
if not self.collectCommand:
|
||||||
|
return line
|
||||||
self._logger.debug("collectCommand is true, collecting info")
|
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}))")
|
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
|
self.collectCommand = False
|
||||||
return line
|
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)
|
self._logger.debug("Sending GCODE [%s]", gcode)
|
||||||
if cmd == "M92":
|
if cmd == "M92":
|
||||||
self.collectCommand = True
|
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)
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
class CalibrationModel():
|
class CalibrationModel():
|
||||||
def getModel(self):
|
def getModel(self):
|
||||||
self._logger.debug("getModel")
|
self._logger.debug("getModel")
|
||||||
steps = self.getSteps()
|
steps = self.getSteps()
|
||||||
|
temps = self.getTemps()
|
||||||
return {
|
return {
|
||||||
"steps": steps
|
"steps": steps,
|
||||||
|
"temps": temps
|
||||||
}
|
}
|
||||||
|
|
||||||
def getSteps(self):
|
def getSteps(self):
|
||||||
@@ -14,3 +19,7 @@ class CalibrationModel():
|
|||||||
"Z": 0,
|
"Z": 0,
|
||||||
"E": 0
|
"E": 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def getTemps(self):
|
||||||
|
return {'B': (), 'T0': ()}
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,13 @@ $(function () {
|
|||||||
self.from_json(response);
|
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
|
// 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">
|
<!-- <button class="btn" data-bind="click: $root.tempRestart">
|
||||||
RESTART
|
RESTART
|
||||||
</button> -->
|
</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>  
|
||||||
|
TEST
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="span1 icon">
|
<div class="span1 icon">
|
||||||
<a data-bind="click: $root.openCalibrationSettings">
|
<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
|
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.
|
reliable.
|
||||||
", "text-warning" ) }}
|
", "text-warning" ) }}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user