From fe0b2afdc97d4c2b01cf33cc7619a223df11c406 Mon Sep 17 00:00:00 2001 From: cp2004 <31997505+cp2004@users.noreply.github.com> Date: Sat, 2 Jan 2021 18:24:04 +0000 Subject: [PATCH 1/7] :bug: Additional None check for sending a command Closes #22 --- octoprint_eeprom_marlin/util.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/octoprint_eeprom_marlin/util.py b/octoprint_eeprom_marlin/util.py index 09e0e1a..ed0a969 100644 --- a/octoprint_eeprom_marlin/util.py +++ b/octoprint_eeprom_marlin/util.py @@ -11,6 +11,9 @@ def build_backup_name(): def construct_command(data): command = data["command"] for param, value in data["params"].items(): + # Check that the value exists, avoid M205 [...] JNone + if value is None: + continue value = str(value) if command != "M145" and param != "S" else str(int(value)) command = command + " " + param + value return command From f4fd29a9e6ddcc0b784cb990d94a0b803073de50 Mon Sep 17 00:00:00 2001 From: cp2004 <31997505+cp2004@users.noreply.github.com> Date: Sat, 2 Jan 2021 18:37:42 +0000 Subject: [PATCH 2/7] :art: Prettier has done its thing --- .github/pull_request_template.md | 14 ++++++++------ CONTRIBUTING.md | 18 +++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 009e32f..bd56b55 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -2,6 +2,7 @@ as accurately as possible. If this template is not filled out the pull request may be closed Thank you for your cooperation! --> + #### What does this PR do and why is it necessary? #### How was it tested? How can it be tested by the reviewer? @@ -9,9 +10,10 @@ #### Relevant issues/discussion (if any) #### Please make sure your PR ticks all the boxes below: -* [ ] If your changes are large or otherwise disruptive: You have discussed these changes by opening an issue first -* [ ] Your PR targets the `devel` branch (No PRs to master please!) -* [ ] If your changes include stylesheets: You have modified the SCSS source (**Not the compiled CSS**) -* [ ] You have run the existing unit tests against your plugin and nothing broke -* [ ] You have read the [Contribution Guidelines](https://github.com/cp2004/OctoPrint-EEPROM-Marlin/blob/master/CONTRIBUTING.md) -* [ ] You have added yourself to the contributors section :) (see `supporters-contributors.py`) + +- [ ] If your changes are large or otherwise disruptive: You have discussed these changes by opening an issue first +- [ ] Your PR targets the `devel` branch (No PRs to master please!) +- [ ] If your changes include stylesheets: You have modified the SCSS source (**Not the compiled CSS**) +- [ ] You have run the existing unit tests against your plugin and nothing broke +- [ ] You have read the [Contribution Guidelines](https://github.com/cp2004/OctoPrint-EEPROM-Marlin/blob/master/CONTRIBUTING.md) +- [ ] You have added yourself to the contributors section :) (see `supporters-contributors.py`) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b882c41..74ad9bd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,11 +10,11 @@ Otherwise your changes would be overwritten as soon as I clone the repository by To compile the CSS (Assuming project root, adjust the path otherwise): -* Install [Sass](https://sass-lang.com/install) using `npm install -g sass` +- Install [Sass](https://sass-lang.com/install) using `npm install -g sass` -* Run `sass octoprint_eeprom_marlin/static/scss/eeprom_marlin.scss octoprint_eeprom_marlin/static/css/eeprom_marlin.css` to compile the CSS. +- Run `sass octoprint_eeprom_marlin/static/scss/eeprom_marlin.scss octoprint_eeprom_marlin/static/css/eeprom_marlin.css` to compile the CSS. -Then you can commit *both* changes to ensure they are not overriden. +Then you can commit _both_ changes to ensure they are not overriden. #### Pre-commit @@ -22,9 +22,9 @@ There's a pre-commit suite ready in this plugin that keeps an eye on code style, It is recommended you install it, but it can also be run as a one-off or as a file watcher too. There is PR check that will validate this, and will complain if it does not pass. -* To install: `pre-commit install` -* To run against the entire codebase: `pre-commit run --hook-stage manual --all-files` -* For details of how to set this up with PyCharm Pro, please see the 'File Watcher/Pre-commit' section [OctoPrint documentation](https://docs.octoprint.org/en/master/development/environment.html#pycharm) +- To install: `pre-commit install` +- To run against the entire codebase: `pre-commit run --hook-stage manual --all-files` +- For details of how to set this up with PyCharm Pro, please see the 'File Watcher/Pre-commit' section [OctoPrint documentation](https://docs.octoprint.org/en/master/development/environment.html#pycharm) #### Adding yourself to the contributors section of the plugin @@ -39,6 +39,7 @@ CONTRIBUTORS = [ ``` Add your name as another dictionary to this list, like so: + ```diff CONTRIBUTORS = [ {"name": "Anderson Silva (Previous maintainer)", "username": "amsbr"}, @@ -48,8 +49,7 @@ Add your name as another dictionary to this list, like so: Your name should then show up under 'Show Contributors' in the plugin's settings pages. - #### Other points -* Please make your contributions against the `devel` branch, to make sure it has the latest codebase. Only exceptions are documentation fixes, such as this one. -* Please fill out the pull request template, to make things easier for me to process. I reply to a lot of things, and may not have the time to do the research myself! +- Please make your contributions against the `devel` branch, to make sure it has the latest codebase. Only exceptions are documentation fixes, such as this one. +- Please fill out the pull request template, to make things easier for me to process. I reply to a lot of things, and may not have the time to do the research myself! From 93d771c61a697ffc6b9d0fdb60de502baa844126 Mon Sep 17 00:00:00 2001 From: cp2004 <31997505+cp2004@users.noreply.github.com> Date: Sat, 2 Jan 2021 18:57:12 +0000 Subject: [PATCH 3/7] :loud_sound: :bug: Reduce parse errors to warning, adjust message See #19 --- octoprint_eeprom_marlin/parser.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/octoprint_eeprom_marlin/parser.py b/octoprint_eeprom_marlin/parser.py index 2993268..cae0c3c 100644 --- a/octoprint_eeprom_marlin/parser.py +++ b/octoprint_eeprom_marlin/parser.py @@ -82,8 +82,8 @@ def parse_eeprom_data(self, line): try: params = data.COMMAND_PARAMS[command] except KeyError: - self._logger.error("Unrecognised EEPROM output line, could not parse") - self._logger.error("Line: {}".format(line)) + self._logger.warning("Did not recognise EEPROM data, skipping line") + self._logger.warning("Line: {}".format(line)) return # work out what values we have @@ -92,10 +92,10 @@ def parse_eeprom_data(self, line): try: param_match = regexes_parameters["float{}".format(param)].search(line) except KeyError: - self._logger.error( - "Unrecognised EEPROM command parameter, could not parse" + self._logger.warning( + "Did not recognise EEPROM parameter, skipping param" ) - self._logger.error("Parameter: {}".format(param)) + self._logger.warning("Parameter: {}".format(param)) continue if param_match: parameters[param] = float(param_match.group("value")) From 4b17e80aad020b0540fa56063f3e8313e1b7d271 Mon Sep 17 00:00:00 2001 From: cp2004 <31997505+cp2004@users.noreply.github.com> Date: Sun, 3 Jan 2021 14:57:35 +0000 Subject: [PATCH 4/7] :sparkles: Add M603 change filament Closes #19 --- octoprint_eeprom_marlin/data.py | 9 +++++ octoprint_eeprom_marlin/parser.py | 1 + .../static/js/eeprom_marlin.js | 39 ++++++++++++++++++- .../templates/sub/material.jinja2 | 8 ++++ 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/octoprint_eeprom_marlin/data.py b/octoprint_eeprom_marlin/data.py index 9db50c0..4655057 100644 --- a/octoprint_eeprom_marlin/data.py +++ b/octoprint_eeprom_marlin/data.py @@ -10,6 +10,7 @@ except ImportError: # we don't need these, just for typed comments # TODO PY3: Type annotations! + Dict = Optional = None pass COMMAND_PARAMS = { @@ -28,6 +29,7 @@ "M205": ["S", "T", "B", "X", "Y", "Z", "E", "J"], "M420": ["S", "Z"], "M145": ["S", "B", "H", "F"], + "M603": ["L", "U"], } COMMAND_NAMES = { @@ -46,6 +48,7 @@ "M205": "advanced", "M420": "autolevel", "M145": "material", + "M603": "filament_change", } @@ -128,7 +131,11 @@ def __init__(self, plugin): self.autolevel = IndividualData("autolevel", "M420", ["S", "Z"]) self.material1 = IndividualData("material1", "M145", ["S", "B", "H", "F"]) self.material2 = IndividualData("material2", "M145", ["S", "B", "H", "F"]) + self.filament_change = IndividualData( + "filament_change", "M603", COMMAND_PARAMS["M603"] + ) + # noinspection PyProtectedMember self.plugin._logger.info("EEPROM Data initialised") def from_list(self, data): @@ -155,10 +162,12 @@ def from_dict(self, data, ui=True): data_class = self.material2 else: # unable to parse again + # noinspection PyProtectedMember self.plugin._logger.error("Unable to parse M145 command") return except KeyError: # Unable to parse M145 + # noinspection PyProtectedMember self.plugin._logger.error("Unable to parse M145 command") return else: diff --git a/octoprint_eeprom_marlin/parser.py b/octoprint_eeprom_marlin/parser.py index cae0c3c..41dd663 100644 --- a/octoprint_eeprom_marlin/parser.py +++ b/octoprint_eeprom_marlin/parser.py @@ -44,6 +44,7 @@ def regex_creator(value_type, param_letter): "floatR": regex_creator("float", "R"), "floatS": regex_creator("float", "S"), "floatT": regex_creator("float", "T"), + "floatU": regex_creator("float", "U"), "floatX": regex_creator("float", "X"), "floatY": regex_creator("float", "Y"), "floatZ": regex_creator("float", "Z"), diff --git a/octoprint_eeprom_marlin/static/js/eeprom_marlin.js b/octoprint_eeprom_marlin/static/js/eeprom_marlin.js index 8fa98f5..b63bfd3 100755 --- a/octoprint_eeprom_marlin/static/js/eeprom_marlin.js +++ b/octoprint_eeprom_marlin/static/js/eeprom_marlin.js @@ -376,6 +376,26 @@ $(function () { return steps; })(); + eeprom.filament_change = (function () { + var filament_change = {}; + + filament_change.L = ko.observable(); + filament_change.U = ko.observable(); + + filament_change.visible = ko.computed(function () { + for (let param in filament_change) { + if (param === "visible") { + continue; + } + if (filament_change[param]() !== null) { + return true; + } + } + return false; + }); + return filament_change; + })(); + return eeprom; })(); @@ -693,6 +713,18 @@ $(function () { units: "steps/mm", }, ], + filament_change: [ + { + label: "Load length", + value: self.eeprom.filament_change.L, + units: "mm", + }, + { + label: "Unload length", + value: self.eeprom.filament_change.U, + units: "mm", + }, + ], }; self.eeprom_from_json = function (data) { @@ -700,7 +732,12 @@ $(function () { for (let key in data.eeprom) { let value = data.eeprom[key]; for (let param in value.params) { - self.eeprom[key][param](value.params[param]); + try { + self.eeprom[key][param](value.params[param]); + } catch { + console.log(key); + console.log(param); + } } } self.unsaved(false); diff --git a/octoprint_eeprom_marlin/templates/sub/material.jinja2 b/octoprint_eeprom_marlin/templates/sub/material.jinja2 index 7995ebf..2052e59 100644 --- a/octoprint_eeprom_marlin/templates/sub/material.jinja2 +++ b/octoprint_eeprom_marlin/templates/sub/material.jinja2 @@ -5,6 +5,14 @@ {% include "snippets/single_field.jinja2" %} +
Select a file to upload and restore
+