Skip to content

Commit

Permalink
Fix issue #7 (#10)
Browse files Browse the repository at this point in the history
* Fix save 0 steps/mm- now it shows an error if steps<-0
  • Loading branch information
SergiuToporjinschi authored Feb 14, 2022
1 parent 6a02270 commit 29ff606
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 216 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ Before start using this plugin I strongly recommend reading some documentation a

## Screens

![E-Steps](assets/eSteps.png)
![X-Y-Z Steps](assets/XYZSteps.png)
![PID Autotune](assets/PID-autotune.png)
![E-Steps](extras/assets/img/plugins/CalibrationTools/eSteps.png)
![X-Y-Z Steps](extras/assets/img/plugins/CalibrationTools/featuredimage.png)
![PID Autotune](extras/assets/img/plugins/CalibrationTools/PID-autotune.png)

## Setup

Expand Down
102 changes: 0 additions & 102 deletions extras/CalibrationTools.md

This file was deleted.

8 changes: 0 additions & 8 deletions extras/README.txt

This file was deleted.

File renamed without changes
File renamed without changes
File renamed without changes
21 changes: 9 additions & 12 deletions octoprint_CalibrationTools/EStepsApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ def apiGateWay(self, command, data):
self._logger.debug("Load steps from EEPROM")
if not self._printer.is_ready():
self._logger.warning("Printer not ready, operation canceled")
return flask.abort(503, {
"msg": "Printer not ready, operation canceled"
})
return flask.abort(503, 'Printer not ready, operation canceled')

# Register listener waiting response for M92 command
m92Event = Event()
Expand All @@ -46,21 +44,20 @@ def apiGateWay(self, command, data):
self._logger.debug("Heating the extruder [%s]", data)
if not self._printer.is_ready():
self._logger.warning("Printer not ready, operation canceled")
return flask.abort(503, {
"msg": "Printer not ready, operation canceled"
})
return flask.abort(503,"Printer not ready, operation canceled")

# Register event to be trigger when temp is achieved
self.registerEventTemp("T0", int(data["extrudeTemp"]), self.startExtrusion, data["extrudeLength"], data["extrudeSpeed"])
# Heating HotEnd
self._printer.commands("M104 S%(extrudeTemp)s" % data)

if command == CMD_ESTEPS_SAVE:
if "newESteps" not in data and ("newXSteps" not in data and "newYSteps" not in data and "newZSteps" not in data):
return flask.abort(400, {
"msg": "Invalid arguments. No value provided for X,Y, Z or E steps"
})

if (("newESteps" not in data or data["newESteps"] <= 0)
and
(("newXSteps" not in data or data["newXSteps"] <= 0) or
("newYSteps" not in data or data["newYSteps"] <= 0) or
("newZSteps" not in data or data["newZSteps"] <= 0))):
return flask.abort(400, "Invalid arguments. No value provided for X,Y, Z or E steps")
stopHeater = []
if "newESteps" in data:
eStepsSettings = self._settings.get(['eSteps'])
Expand Down Expand Up @@ -90,7 +87,7 @@ def startExtrusion(self, temps, extrudeLength, extrudeSpeed, *args):

@staticmethod
def m92GCodeResponse(self, line, regex, event):
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}))")
isM92command = reg.match(line)
if isM92command:
command = isM92command.group("command")
Expand Down
14 changes: 8 additions & 6 deletions octoprint_CalibrationTools/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import traceback

import flask
from werkzeug.exceptions import HTTPException

from octoprint_CalibrationTools import EStepsApi, PIDAutoTune

Expand Down Expand Up @@ -35,9 +36,7 @@ def on_api_get(self, request):
)
except Exception as e:
self._logger.error(traceback.format_exc())
return flask.abort(500, {
"msg": "An error curred"
})
return flask.abort(500, "An error curred")

def on_api_command(self, command, data):
try:
Expand All @@ -47,6 +46,9 @@ def on_api_command(self, command, data):
return api["cls"].apiGateWay(self, command, data)
except Exception as e:
self._logger.error(traceback.format_exc())
return flask.abort(500, {
"msg": "An error curred"
})
exCode = 500
exMessage = "An error curred"
if isinstance(e, HTTPException):
exCode = e.code
exMessage = e.description
return flask.abort(exCode, exMessage)
31 changes: 9 additions & 22 deletions octoprint_CalibrationTools/static/js/EStepsViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ $(function () {
self.results = {};
self.results["remainedLength"] = ko.observable(20);
self.results["actualExtrusion"] = ko.computed(function () {
return (self.testParam.markLength() - self.results.remainedLength()).toFixed(3);
return self.generalVM.round(self.testParam.markLength() - self.results.remainedLength());
});
self.results["newSteps"] = ko.computed(function () {
return (self.steps.E() / self.results.actualExtrusion() * 100).toFixed(3);
});
self.results["newStepsDisplay"] = ko.computed(function () {
return "M92 E" + self.results.newSteps();
return self.generalVM.round(self.steps.E() / self.results.actualExtrusion() * 100);
});
// self.results["newStepsDisplay"] = ko.computed(function () {
// return "M92 E" + self.results.newSteps();
// });

self.onBeforeBinding = self.onUserLoggedIn = self.onUserLoggedOut = function () {
self.testParam.extrudeTemp(self.settingsViewModel.settings.plugins.CalibrationTools.eSteps.extrudeTemp());
Expand Down Expand Up @@ -70,18 +70,9 @@ $(function () {
"extrudeLength": self.testParam.extrudeLength(),
"extrudeSpeed": self.testParam.extrudeSpeed()
}).done(function (response) {
new PNotify({
title: "E axe calibration started",
text: "<span style='font-weight:bold; color: red;'>Heating nuzzle has started!!!</span><br> When extrusion stops you have to fulfil <b>Length after extrusion</b> and save the new value ",
type: "warning"
});
self.generalVM.notifyWarning("E axe calibration started", "<span style='font-weight:bold; color: red;'>Heating nuzzle has started!!!</span><br> When extrusion stops you have to fulfil <b>Length after extrusion</b> and save the new value ")
}).fail(function (response) {
new PNotify({
title: "Error on starting extrusion ",
text: response.responseJSON.error,
type: "error",
hide: false
});
self.generalVM.notifyError("Error on starting extrusion ", response.responseJSON.error);
}).always(function (response) {
self.startExtrusionActive(false);
});
Expand All @@ -91,12 +82,8 @@ $(function () {
OctoPrint.simpleApiCommand("CalibrationTools", "eSteps_save", {
"newESteps": self.results.newSteps()
}).done(function () {
new PNotify({
title: "Saved",
text: self.results.newSteps() + " steps/mm had been set for E axe",
type: "info"
});
});
self.generalVM.notifyInfo("Saved", self.results.newSteps() + " steps/mm had been set for E axe");
}).fail(self.generalVM.failedFunction);
}

self.onAllBound = self.onEventConnected = function () {
Expand Down
31 changes: 28 additions & 3 deletions octoprint_CalibrationTools/static/js/GeneralViewModel.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
$(function () {
function CalibrationToolsGeneralViewModel(parameters) {
this.loginState = parameters[0];
this.decimal3 = function (defaultVal) {
var self = this;
self.decimal3 = function (defaultVal) {
return {
numeric: {
decimals: 3,
default: defaultVal
}
}
}
this.isSmall = ko.observable($("#tab_plugin_CalibrationTools").width() < 800);
self.isSmall = ko.observable($("#tab_plugin_CalibrationTools").width() < 800);
ko.extenders.numeric = function (target, options) {
var returnObs = ko.pureComputed({
read: target,
Expand All @@ -24,9 +25,33 @@ $(function () {
return returnObs;
};

this.onStartupComplete = function () {
self.onStartupComplete = function () {
this.isSmall($("#tabs_content").width() < 800);
}
self.notify = function (title, message, type, hide) {
new PNotify({
title: title,
text: message,
type: type,
hide: hide
});
}
self.notifyError = function (title, message) {
self.notify(title, message, 'error', false);
}
self.notifyInfo = function (title, message) {
self.notify(title, message, 'info', true);
}
self.notifyWarning = function (title, message) {
self.notify(title, message, 'warning', false);
}
self.failedFunction = function (response) {
self.notifyError("Error", response.responseJSON.error);
}
self.round = function (number, decimals) {
decimals = decimals ? decimals : 3;
return +(Math.round(number + ("e+" + decimals)) + ("e-" + decimals));
}
}
OCTOPRINT_VIEWMODELS.push({
// This is the constructor to call for instantiating the plugin
Expand Down
39 changes: 5 additions & 34 deletions octoprint_CalibrationTools/static/js/PIDTuneViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,7 @@ $(function () {
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(function (response) {
new PNotify({
title: "Error on getting current PID values ",
text: response.responseJSON.error,
type: "error",
hide: false
});
});
}).fail(self.generalVM.failFunction);
};

self.onBeforeBinding = self.onUserLoggedIn = self.onUserLoggedOut = function () {
Expand All @@ -79,19 +72,8 @@ $(function () {
"hotEndIndex": Number(self.pid.hotEnd.hotEndIndex()),
"targetTemp": Number(self.pid.hotEnd.targetTemp())
}).done(function (response) {
new PNotify({
title: "PID HotEnd tuning has started",
text: "In progress",
type: "info"
});
}).fail(function (response) {
new PNotify({
title: "Error on starting PID autotune ",
text: response.responseJSON.error,
type: "error",
hide: false
});
});
self.generalVM.notifyWarning("PID HotEnd tuning has started", "In progress");
}).fail(self.generalVM.failFunction);
}
self.startPidBed = function () {
OctoPrint.simpleApiCommand("CalibrationTools", "pid_start", {
Expand All @@ -101,19 +83,8 @@ $(function () {
"hotEndIndex": -1,
"targetTemp": self.pid.bed.targetTemp()
}).done(function (response) {
new PNotify({
title: "PID HotEnd tuning has started",
text: "In progress",
type: "info"
});
}).fail(function (response) {
new PNotify({
title: "Error on starting PID autotune ",
text: response.responseJSON.error,
type: "error",
hide: false
});
});
self.generalVM.notifyWarning("PID Heated bed tuning has started", "In progress");
}).fail(self.generalVM.failFunction);
}
}
OCTOPRINT_VIEWMODELS.push({
Expand Down
Loading

0 comments on commit 29ff606

Please sign in to comment.