Files
OctoPrint-CalibrationTools/octoprint_CalibrationTools/static/js/PIDTuneViewModel.js
T
Sergiu Toporjinschi 29ff606e33 Fix issue #7 (#10)
* Fix save 0 steps/mm- now it shows an error if steps<-0
2022-02-14 22:57:26 +02:00

100 lines
4.8 KiB
JavaScript

$(function () {
function CalibrationToolsPIDTuneViewModel(parameters) {
var self = this;
self.loginStateViewModel = parameters[0];
self.settingsViewModel = parameters[1];
self.controlViewModel = parameters[2];
self.generalVM = parameters[5];
self.columnLabelCls = ko.computed(function () {
return self.generalVM.isSmall() ? "span3" : "span3";
});
self.columnFieldCls = ko.computed(function () {
return self.generalVM.isSmall() ? "span9" : "span9";
});
self.pidCurrentValues = {
"hotEnd": {
"P": ko.observable(0),
"I": ko.observable(0),
"D": ko.observable(0)
},
"bed": {
"P": ko.observable(0),
"I": ko.observable(0),
"D": ko.observable(0)
}
};
self.isAdmin = ko.observable(false);
self.pid = {
"hotEnd": {
fanSpeed: ko.observable(255),
noCycles: ko.observable(8),
hotEndIndex: ko.observable(0),
targetTemp: ko.observable(200)
},
"bed": {
fanSpeed: ko.observable(255),
noCycles: ko.observable(8),
index: ko.observable(-1),
targetTemp: ko.observable(200)
}
};
/**
* Get current PIDs settings for bed and hotEnd
*/
self.getCurrentValues = function () {
OctoPrint.simpleApiCommand("CalibrationTools", "pid_getCurrentValues").done(function (response) {
self.pidCurrentValues.hotEnd.P(response.data.hotEnd.P);
self.pidCurrentValues.hotEnd.I(response.data.hotEnd.I);
self.pidCurrentValues.hotEnd.D(response.data.hotEnd.D);
self.pidCurrentValues.bed.P(response.data.bed.P);
self.pidCurrentValues.bed.I(response.data.bed.I);
self.pidCurrentValues.bed.D(response.data.bed.D);
}).fail(self.generalVM.failFunction);
};
self.onBeforeBinding = self.onUserLoggedIn = self.onUserLoggedOut = function () {
self.pid.hotEnd.fanSpeed(self.settingsViewModel.settings.plugins.CalibrationTools.pid.hotEnd.fanSpeed());
self.pid.hotEnd.hotEndIndex(self.settingsViewModel.settings.plugins.CalibrationTools.pid.hotEnd.hotEndIndex());
self.pid.hotEnd.noCycles(self.settingsViewModel.settings.plugins.CalibrationTools.pid.hotEnd.noCycles());
self.pid.hotEnd.targetTemp(self.settingsViewModel.settings.plugins.CalibrationTools.pid.hotEnd.targetTemp());
self.pid.bed.index(-1);
self.pid.bed.noCycles(self.settingsViewModel.settings.plugins.CalibrationTools.pid.bed.noCycles());
self.pid.bed.targetTemp(self.settingsViewModel.settings.plugins.CalibrationTools.pid.bed.targetTemp());
}
self.startPidHotEnd = function () {
OctoPrint.simpleApiCommand("CalibrationTools", "pid_start", {
"heater": "hotEnd",
"fanSpeed": Number(self.pid.hotEnd.fanSpeed()),
"noCycles": Number(self.pid.hotEnd.noCycles()),
"hotEndIndex": Number(self.pid.hotEnd.hotEndIndex()),
"targetTemp": Number(self.pid.hotEnd.targetTemp())
}).done(function (response) {
self.generalVM.notifyWarning("PID HotEnd tuning has started", "In progress");
}).fail(self.generalVM.failFunction);
}
self.startPidBed = function () {
OctoPrint.simpleApiCommand("CalibrationTools", "pid_start", {
"heater": "bed",
"fanSpeed": self.pid.bed.fanSpeed(),
"noCycles": self.pid.bed.noCycles(),
"hotEndIndex": -1,
"targetTemp": self.pid.bed.targetTemp()
}).done(function (response) {
self.generalVM.notifyWarning("PID Heated bed tuning has started", "In progress");
}).fail(self.generalVM.failFunction);
}
}
OCTOPRINT_VIEWMODELS.push({
// This is the constructor to call for instantiating the plugin
construct: CalibrationToolsPIDTuneViewModel,
// This is a list of dependencies to inject into the plugin, the order which you request
// here is the order in which the dependencies will be injected into your view model upon
// instantiation via the parameters argument
dependencies: ["loginStateViewModel", "settingsViewModel", "controlViewModel", "terminalViewModel", "accessViewModel", "calibrationToolsGeneralViewModel"],
// Finally, this is the list of selectors for all elements we want this view model to be bound to.
elements: ["#calibration_pid"]
});
});