Temp supports functions and methods
Extrusion is functional
This commit is contained in:
@@ -36,6 +36,8 @@ class CalibrationtoolsPlugin(
|
||||
"js": ["js/CalibrationTools.js"],
|
||||
"css": ["css/style.css"]
|
||||
}
|
||||
def startExtrusion(self, temps):
|
||||
self._logger.debug("Temperature achieved, extrusion started %s", temps)
|
||||
|
||||
def get_update_information(self):
|
||||
# Define the configuration for your plugin to use with the Software Update
|
||||
|
||||
@@ -4,11 +4,13 @@ from __future__ import absolute_import, division, print_function, unicode_litera
|
||||
import octoprint.plugin
|
||||
import flask
|
||||
|
||||
|
||||
CMD_LOAD_STEPS = "loadSteps"
|
||||
CMD_TEST = "TEST"
|
||||
CMD_START_EXTRUSION = "startExtrusion"
|
||||
|
||||
|
||||
def someTestFunc(self, temps, a, b):
|
||||
self._logger.debug("a ajuns %s, %s, %s", temps, a,b)
|
||||
def someTestFunc(self, temps):
|
||||
self._logger.debug("a ajuns %s", temps)
|
||||
|
||||
|
||||
class API(octoprint.plugin.SimpleApiPlugin):
|
||||
@@ -16,7 +18,8 @@ class API(octoprint.plugin.SimpleApiPlugin):
|
||||
def get_api_commands():
|
||||
return {
|
||||
CMD_LOAD_STEPS: [],
|
||||
"TEST": []
|
||||
CMD_START_EXTRUSION: [],
|
||||
CMD_TEST: []
|
||||
}
|
||||
|
||||
def on_api_get(self, request):
|
||||
@@ -34,6 +37,12 @@ class API(octoprint.plugin.SimpleApiPlugin):
|
||||
return flask.jsonify({
|
||||
"data": self.data["steps"]
|
||||
})
|
||||
if command == "TEST":
|
||||
self.registerEventTemp("T0", 100, someTestFunc, 1,"test")
|
||||
if command == CMD_START_EXTRUSION:
|
||||
self._logger.debug("Heating the tools")
|
||||
self._printer.commands("M104 S180")
|
||||
self.registerEventTemp("T0", 180, self.startExtrusion)
|
||||
|
||||
return
|
||||
if command == CMD_TEST:
|
||||
self.registerEventTemp("T0", 100, someTestFunc)
|
||||
return
|
||||
|
||||
@@ -5,6 +5,8 @@ from ast import arg
|
||||
import re
|
||||
import threading
|
||||
import traceback
|
||||
import types
|
||||
|
||||
|
||||
class Hooks():
|
||||
trackTemp = True
|
||||
@@ -50,27 +52,31 @@ class Hooks():
|
||||
"firmware": firmware_data
|
||||
}
|
||||
|
||||
## Hook for temperature messages
|
||||
## This is active only when there are events registered to temperature changes
|
||||
# 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
|
||||
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
|
||||
# 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()
|
||||
arg = (temps, *event["args"])
|
||||
if isinstance(event["func"], types.FunctionType):
|
||||
arg = (self, *arg)
|
||||
threading.Thread(target=event["func"], args=arg).start()
|
||||
self.events.remove(event)
|
||||
|
||||
## Registering a temp event
|
||||
# Registering a temp event
|
||||
def registerEventTemp(self, tool, targetTemp, func, *arguments):
|
||||
if func is None:
|
||||
self._logger.warn("registerEventTemp: Attempt to register event without a function")
|
||||
|
||||
@@ -53,6 +53,12 @@ $(function () {
|
||||
// });
|
||||
}
|
||||
|
||||
self.startExtrusion = function () {
|
||||
OctoPrint.simpleApiCommand("CalibrationTools","startExtrusion").done(function (response) {
|
||||
console.log(response);
|
||||
})
|
||||
}
|
||||
|
||||
self.tempRestart = function () {
|
||||
OctoPrint.system.executeCommand("core", "restart");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user