OctoprintKlipperPlugin/octoprint_klipper/static/js/klipper_leveling.js

98 lines
3.3 KiB
JavaScript
Raw Normal View History

// <Octoprint Klipper Plugin>
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-08-19 14:49:24 +03:00
2018-01-24 19:12:57 +03:00
$(function() {
function KlipperLevelingViewModel(parameters) {
var self = this;
self.settings = parameters[0];
self.loginState = parameters[1];
2018-08-18 15:44:11 +03:00
self.activePoint = ko.observable(-1);
self.pointCount = ko.observable();
self.points = ko.observableArray();
2018-01-24 19:12:57 +03:00
2018-08-18 15:44:11 +03:00
self.initView = function() {
self.points(self.settings.settings.plugins.klipper.probe.points());
self.pointCount(
self.points().length
);
2018-01-24 19:12:57 +03:00
}
2018-08-18 15:44:11 +03:00
2018-01-24 19:12:57 +03:00
self.startLeveling = function() {
OctoPrint.control.sendGcode("G28")
2018-02-02 18:57:29 +03:00
self.moveToPoint(0);
2018-01-24 19:12:57 +03:00
}
self.stopLeveling = function() {
2018-02-02 18:57:29 +03:00
OctoPrint.control.sendGcode("G1 Z" +
2018-08-09 10:25:05 +03:00
(self.settings.settings.plugins.klipper.probe.height()*1 +
self.settings.settings.plugins.klipper.probe.lift()*1)
2018-02-02 18:57:29 +03:00
);
self.gotoHome();
}
self.gotoHome = function() {
OctoPrint.control.sendGcode("G28");
self.activePoint(-1);
2018-01-24 19:12:57 +03:00
}
self.nextPoint = function() {
2018-02-02 18:57:29 +03:00
self.moveToPoint(self.activePoint()+1);
2018-01-24 19:12:57 +03:00
}
self.previousPoint = function() {
2018-02-02 18:57:29 +03:00
self.moveToPoint(self.activePoint()-1);
}
self.jumpToPoint = function(item) {
self.moveToPoint(
2018-08-18 15:44:11 +03:00
self.points().indexOf(item)
2018-02-02 18:57:29 +03:00
);
2018-01-24 19:12:57 +03:00
}
2018-08-18 15:44:11 +03:00
/*
2018-01-24 19:12:57 +03:00
self.pointCount = function() {
2018-08-09 10:25:05 +03:00
return self.settings.settings.plugins.klipper.probe.points().length;
2018-01-24 19:12:57 +03:00
}
2018-08-18 15:44:11 +03:00
*/
2018-02-02 18:57:29 +03:00
self.moveToPosition = function(x, y) {
OctoPrint.control.sendGcode([
// Move Z up
2018-08-09 10:25:05 +03:00
"G1 Z" + (self.settings.settings.plugins.klipper.probe.height() * 1 +
self.settings.settings.plugins.klipper.probe.lift()*1) +
" F" + self.settings.settings.plugins.klipper.probe.speed_z() ,
// Move XY
2018-02-02 18:57:29 +03:00
"G1 X" + x + " Y" + y +
" F" + self.settings.settings.plugins.klipper.probe.speed_xy() ,
// Move Z down
2018-08-09 10:25:05 +03:00
"G1 Z" + self.settings.settings.plugins.klipper.probe.height() +
" F" + self.settings.settings.plugins.klipper.probe.speed_z()
]);
2018-01-24 19:12:57 +03:00
}
2018-02-02 18:57:29 +03:00
self.moveToPoint = function(index) {
2018-08-18 15:44:11 +03:00
var point = self.points()[index];
2018-02-02 18:57:29 +03:00
self.moveToPosition(point.x(), point.y());
self.activePoint(index);
}
2018-01-24 19:12:57 +03:00
}
OCTOPRINT_VIEWMODELS.push({
construct: KlipperLevelingViewModel,
2018-08-18 15:44:11 +03:00
dependencies: ["settingsViewModel", "loginStateViewModel"],
elements: ["#klipper_leveling_dialog"]
2018-01-24 19:12:57 +03:00
});
});