Temp supports functions and methods
Extrusion is functional
This commit is contained in:
@@ -36,6 +36,8 @@ class CalibrationtoolsPlugin(
|
|||||||
"js": ["js/CalibrationTools.js"],
|
"js": ["js/CalibrationTools.js"],
|
||||||
"css": ["css/style.css"]
|
"css": ["css/style.css"]
|
||||||
}
|
}
|
||||||
|
def startExtrusion(self, temps):
|
||||||
|
self._logger.debug("Temperature achieved, extrusion started %s", temps)
|
||||||
|
|
||||||
def get_update_information(self):
|
def get_update_information(self):
|
||||||
# Define the configuration for your plugin to use with the Software Update
|
# 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 octoprint.plugin
|
||||||
import flask
|
import flask
|
||||||
|
|
||||||
|
|
||||||
CMD_LOAD_STEPS = "loadSteps"
|
CMD_LOAD_STEPS = "loadSteps"
|
||||||
|
CMD_TEST = "TEST"
|
||||||
|
CMD_START_EXTRUSION = "startExtrusion"
|
||||||
|
|
||||||
|
def someTestFunc(self, temps):
|
||||||
def someTestFunc(self, temps, a, b):
|
self._logger.debug("a ajuns %s", temps)
|
||||||
self._logger.debug("a ajuns %s, %s, %s", temps, a,b)
|
|
||||||
|
|
||||||
|
|
||||||
class API(octoprint.plugin.SimpleApiPlugin):
|
class API(octoprint.plugin.SimpleApiPlugin):
|
||||||
@@ -16,7 +18,8 @@ class API(octoprint.plugin.SimpleApiPlugin):
|
|||||||
def get_api_commands():
|
def get_api_commands():
|
||||||
return {
|
return {
|
||||||
CMD_LOAD_STEPS: [],
|
CMD_LOAD_STEPS: [],
|
||||||
"TEST": []
|
CMD_START_EXTRUSION: [],
|
||||||
|
CMD_TEST: []
|
||||||
}
|
}
|
||||||
|
|
||||||
def on_api_get(self, request):
|
def on_api_get(self, request):
|
||||||
@@ -34,6 +37,12 @@ class API(octoprint.plugin.SimpleApiPlugin):
|
|||||||
return flask.jsonify({
|
return flask.jsonify({
|
||||||
"data": self.data["steps"]
|
"data": self.data["steps"]
|
||||||
})
|
})
|
||||||
if command == "TEST":
|
if command == CMD_START_EXTRUSION:
|
||||||
self.registerEventTemp("T0", 100, someTestFunc, 1,"test")
|
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
|
return
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ from ast import arg
|
|||||||
import re
|
import re
|
||||||
import threading
|
import threading
|
||||||
import traceback
|
import traceback
|
||||||
|
import types
|
||||||
|
|
||||||
|
|
||||||
class Hooks():
|
class Hooks():
|
||||||
trackTemp = True
|
trackTemp = True
|
||||||
@@ -50,27 +52,31 @@ class Hooks():
|
|||||||
"firmware": firmware_data
|
"firmware": firmware_data
|
||||||
}
|
}
|
||||||
|
|
||||||
## Hook for temperature messages
|
# Hook for temperature messages
|
||||||
## This is active only when there are events registered to temperature changes
|
# This is active only when there are events registered to temperature changes
|
||||||
def processTemp(self, comm_instance, parsed_temperatures, *args, **kwargs):
|
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:
|
try:
|
||||||
self.checkAndTriggerEvent(parsed_temperatures.copy())
|
self.checkAndTriggerEvent(parsed_temperatures.copy())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._logger.error(traceback.format_exc())
|
self._logger.error(traceback.format_exc())
|
||||||
return parsed_temperatures
|
return parsed_temperatures
|
||||||
|
|
||||||
## Check if the current message contains changes concerning registered tool
|
# Check if the current message contains changes concerning registered tool
|
||||||
## if the criteria is meat then the execution function is called
|
# if the criteria is meat then the execution function is called
|
||||||
def checkAndTriggerEvent(self, temps):
|
def checkAndTriggerEvent(self, temps):
|
||||||
for tool, values in temps.items():
|
for tool, values in temps.items():
|
||||||
(curTemp, trgTemp) = values
|
(curTemp, trgTemp) = values
|
||||||
for event in self.events:
|
for event in self.events:
|
||||||
if event["tool"] == tool and curTemp >= event["targetTemp"]:
|
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)
|
self.events.remove(event)
|
||||||
|
|
||||||
## Registering a temp event
|
# Registering a temp event
|
||||||
def registerEventTemp(self, tool, targetTemp, func, *arguments):
|
def registerEventTemp(self, tool, targetTemp, func, *arguments):
|
||||||
if func is None:
|
if func is None:
|
||||||
self._logger.warn("registerEventTemp: Attempt to register event without a function")
|
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 () {
|
self.tempRestart = function () {
|
||||||
OctoPrint.system.executeCommand("core", "restart");
|
OctoPrint.system.executeCommand("core", "restart");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user