From 223a401dab93e84bf5dc450f9bdc6aff5269ed16 Mon Sep 17 00:00:00 2001 From: Ben Lye Date: Thu, 26 Nov 2020 20:14:30 +0000 Subject: [PATCH 1/4] Add pre-flash gcode command and delay --- octoprint_firmwareupdater/__init__.py | 24 +++++++++++-- .../static/js/firmwareupdater.js | 26 +++++++++++--- .../templates/firmwareupdater_settings.jinja2 | 35 +++++++++++++++++-- 3 files changed, 76 insertions(+), 9 deletions(-) diff --git a/octoprint_firmwareupdater/__init__.py b/octoprint_firmwareupdater/__init__.py index c7cea2c..7cb664e 100644 --- a/octoprint_firmwareupdater/__init__.py +++ b/octoprint_firmwareupdater/__init__.py @@ -116,7 +116,7 @@ def flash_firmware(self): uploaded_hex_path = flask.request.values[input_upload_path] # create a temporary - + try: file_to_flash = tempfile.NamedTemporaryFile(mode='r+b', delete=False) file_to_flash.close() @@ -192,7 +192,7 @@ def _flash_worker(self, method, firmware, printer_port): except: e = sys.exc_info()[0] self._logger.error("Error executing pre-flash commandline '{}'".format(preflash_command)) - + self._logger.info("Pre-flash command '{}' returned: {}".format(preflash_command, r)) try: @@ -211,6 +211,20 @@ def _flash_worker(self, method, firmware, printer_port): self._send_status("flasherror", message=error_message) return + preflash_gcode = self._settings.get(["preflash_gcode"]) + if preflash_gcode is not None and self._settings.get_boolean(["enable_preflash_gcode"]): + if self._printer.is_operational(): + self._logger.info("Sending pre-flash gcode commands: {}".format(preflash_gcode)) + self._printer.commands(preflash_gcode.split(";")) + + preflash_delay = self._settings.get(["preflash_delay"]) or 3 + if float(preflash_delay) > 0 and self._settings.get(["enable_preflash_delay"]): + self._logger.info("Pre-flash delay: {}s".format(preflash_delay)) + time.sleep(float(preflash_delay)) + + else: + self._logger.info("Printer not connected, not sending pre-flash gcode commands") + reconnect = None if self._printer.is_operational(): _, current_port, current_baudrate, current_profile = self._printer.get_current_connection() @@ -245,7 +259,7 @@ def _flash_worker(self, method, firmware, printer_port): except: e = sys.exc_info()[0] self._logger.error("Error executing post-flash commandline '{}'".format(postflash_command)) - + self._logger.info("Post-flash command '{}' returned: {}".format(postflash_command, r)) postflash_gcode = self._settings.get(["postflash_gcode"]) @@ -309,14 +323,18 @@ def get_settings_defaults(self): "lpc1768_path": None, "lpc1768_preflashreset": True, "postflash_delay": "0", + "preflash_delay": "3", "postflash_gcode": None, + "preflash_gcode": None, "run_postflash_gcode": False, "preflash_commandline": None, "postflash_commandline": None, "enable_preflash_commandline": None, "enable_postflash_commandline": None, "enable_postflash_delay": None, + "enable_preflash_delay": None, "enable_postflash_gcode": None, + "enable_preflash_gcode": None, "disable_bootloadercheck": None } diff --git a/octoprint_firmwareupdater/static/js/firmwareupdater.js b/octoprint_firmwareupdater/static/js/firmwareupdater.js index 10b152a..c5ab8cc 100644 --- a/octoprint_firmwareupdater/static/js/firmwareupdater.js +++ b/octoprint_firmwareupdater/static/js/firmwareupdater.js @@ -17,7 +17,9 @@ $(function() { self.showStm32flashConfig = ko.observable(false); self.showPostflashConfig = ko.observable(false); self.configEnablePostflashDelay = ko.observable(); + self.configEnablePreflashDelay = ko.observable(); self.configPostflashDelay = ko.observable(); + self.configPreflashDelay = ko.observable(); self.configEnablePostflashGcode = ko.observable(); self.configPostflashGcode = ko.observable(); self.configDisableBootloaderCheck = ko.observable(); @@ -25,6 +27,8 @@ $(function() { self.configPreflashCommandline = ko.observable(); self.configEnablePostflashCommandline = ko.observable(); self.configPostflashCommandline = ko.observable(); + self.configEnablePreflashGcode = ko.observable(); + self.configPreflashGcode = ko.observable(); // Config settings for avrdude self.configAvrdudeMcu = ko.observable(); @@ -436,7 +440,9 @@ $(function() { self.configPreflashCommandline(self.settingsViewModel.settings.plugins.firmwareupdater.preflash_commandline()); self.configPostflashCommandline(self.settingsViewModel.settings.plugins.firmwareupdater.postflash_commandline()); self.configPostflashDelay(self.settingsViewModel.settings.plugins.firmwareupdater.postflash_delay()); + self.configPreflashDelay(self.settingsViewModel.settings.plugins.firmwareupdater.preflash_delay()); self.configPostflashGcode(self.settingsViewModel.settings.plugins.firmwareupdater.postflash_gcode()); + self.configPreflashGcode(self.settingsViewModel.settings.plugins.firmwareupdater.preflash_gcode()); if(self.settingsViewModel.settings.plugins.firmwareupdater.enable_preflash_commandline() != 'false') { self.configEnablePreflashCommandline(self.settingsViewModel.settings.plugins.firmwareupdater.enable_preflash_commandline()); @@ -449,11 +455,19 @@ $(function() { if(self.settingsViewModel.settings.plugins.firmwareupdater.enable_postflash_delay() != 'false') { self.configEnablePostflashDelay(self.settingsViewModel.settings.plugins.firmwareupdater.enable_postflash_delay()); } - + + if(self.settingsViewModel.settings.plugins.firmwareupdater.enable_preflash_delay() != 'false') { + self.configEnablePreflashDelay(self.settingsViewModel.settings.plugins.firmwareupdater.enable_preflash_delay()); + } + if(self.settingsViewModel.settings.plugins.firmwareupdater.enable_postflash_gcode() != 'false') { self.configEnablePostflashGcode(self.settingsViewModel.settings.plugins.firmwareupdater.enable_postflash_gcode()); } - + + if(self.settingsViewModel.settings.plugins.firmwareupdater.enable_preflash_gcode() != 'false') { + self.configEnablePreflashGcode(self.settingsViewModel.settings.plugins.firmwareupdater.enable_preflash_gcode()); + } + if(self.settingsViewModel.settings.plugins.firmwareupdater.disable_bootloadercheck() != 'false') { self.configDisableBootloaderCheck(self.settingsViewModel.settings.plugins.firmwareupdater.disable_bootloadercheck()); } @@ -473,13 +487,13 @@ $(function() { self.configBossacPath(self.settingsViewModel.settings.plugins.firmwareupdater.bossac_path()); self.configBossacDisableVerification(self.settingsViewModel.settings.plugins.firmwareupdater.bossac_disableverify()); self.configBossacCommandLine(self.settingsViewModel.settings.plugins.firmwareupdater.bossac_commandline()); - + // Load the dfu-programmer settings self.configDfuPath(self.settingsViewModel.settings.plugins.firmwareupdater.dfuprog_path()); self.configDfuMcu(self.settingsViewModel.settings.plugins.firmwareupdater.dfuprog_avrmcu()); self.configDfuCommandLine(self.settingsViewModel.settings.plugins.firmwareupdater.dfuprog_commandline()); self.configDfuEraseCommandLine(self.settingsViewModel.settings.plugins.firmwareupdater.dfuprog_erasecommandline()); - + // Load the lpc1768 settings self.configLpc1768Path(self.settingsViewModel.settings.plugins.firmwareupdater.lpc1768_path()); if(self.settingsViewModel.settings.plugins.firmwareupdater.lpc1768_preflashreset() != 'false') { @@ -542,9 +556,13 @@ $(function() { enable_postflash_commandline: self.configEnablePostflashCommandline(), postflash_commandline: self.configPostflashCommandline(), postflash_delay: self.configPostflashDelay(), + preflash_delay: self.configPreflashDelay(), postflash_gcode: self.configPostflashGcode(), + preflash_gcode: self.configPreflashGcode(), enable_postflash_delay: self.configEnablePostflashDelay(), + enable_preflash_delay: self.configEnablePreflashDelay(), enable_postflash_gcode: self.configEnablePostflashGcode(), + enable_preflash_gcode: self.configEnablePreflashGcode(), disable_bootloadercheck: self.configDisableBootloaderCheck() } } diff --git a/octoprint_firmwareupdater/templates/firmwareupdater_settings.jinja2 b/octoprint_firmwareupdater/templates/firmwareupdater_settings.jinja2 index 15d057e..ebb7e2a 100644 --- a/octoprint_firmwareupdater/templates/firmwareupdater_settings.jinja2 +++ b/octoprint_firmwareupdater/templates/firmwareupdater_settings.jinja2 @@ -445,7 +445,7 @@ - +
@@ -463,7 +463,7 @@
- +
+ +
+ +
+ +
+ +
+ {{ _('Gcode commands which will be run before the printer is flashed. Pre-flash Gcode commands will only run if the printer is connected. Separate multiple commands with a semi colon.') }} +
+
+ + + +
+ +
+ +
+ + seconds +
+ {{ _('Delay after sending pre-flash gcode. Allows time for code to complete') }} +
+
+ +
From e8aaa5cc461847a30d088e25233886574a9d527b Mon Sep 17 00:00:00 2001 From: Ben Lye Date: Fri, 27 Nov 2020 08:40:04 +0000 Subject: [PATCH 2/4] Re-order advanced settings --- .../templates/firmwareupdater_settings.jinja2 | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/octoprint_firmwareupdater/templates/firmwareupdater_settings.jinja2 b/octoprint_firmwareupdater/templates/firmwareupdater_settings.jinja2 index ebb7e2a..7942970 100644 --- a/octoprint_firmwareupdater/templates/firmwareupdater_settings.jinja2 +++ b/octoprint_firmwareupdater/templates/firmwareupdater_settings.jinja2 @@ -433,7 +433,7 @@
- +
- +
- +
- +
- {{ _('System command line to execute after flashing.') }} + {{ _('Gcode commands to run before blashing. Pre-flash gcode commands will only run if the printer is connected. Separate multiple commands with a semi colon.') }}
- + - +
- +
- + seconds
- {{ _('Give the board time to boot before allowing OctoPrint to reconnect.') }} + {{ _('Delay after sending pre-flash gcode. Allows time for code to complete before initiating flash.') }}
- + - +
- +
- +
- {{ _('Gcode commands which will be run before the printer is flashed. Pre-flash Gcode commands will only run if the printer is connected. Separate multiple commands with a semi colon.') }} + {{ _('System command line to execute after flashing.') }}
- + - +
- +
- + seconds
- {{ _('Delay after sending pre-flash gcode. Allows time for code to complete') }} + {{ _('Give the board time to boot before allowing OctoPrint to reconnect.') }}
- +
From bef175c8ad0aa3a350a55f325f9fe8d00a5f38a7 Mon Sep 17 00:00:00 2001 From: Ben Lye Date: Fri, 27 Nov 2020 08:40:12 +0000 Subject: [PATCH 3/4] Increment version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index e5a5c44..ad44bb5 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ plugin_name = "OctoPrint-FirmwareUpdater" # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module -plugin_version = "1.7.0" +plugin_version = "1.7.1" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module From 70c8202912fec2471c8e0080314a63d16127b200 Mon Sep 17 00:00:00 2001 From: Ben Lye Date: Fri, 27 Nov 2020 08:50:20 +0000 Subject: [PATCH 4/4] Doc updates --- README.md | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 991464e..04c01e8 100644 --- a/README.md +++ b/README.md @@ -311,16 +311,35 @@ Erase: `{bossac} -i -p {port} -U true -e -w {disableverify} -b {firmware} -R` Flash: ## Pre and Post-flash Settings -#### Pre-flash Command -Specify a system command to run on the host prior to flashing. -#### Pre-flash Command -Specify a system command to run on the host after flashing. +The flash sequence is: +1. Execute the pre-flash system command(s) on the host +1. Send the pre-flash gcode commands(s) to the printer +1. Pause for the pre-flash gcode delay +1. Disconnect the printer +1. Execute the firmware update +1. Pause for the post-flash delay +1. Execute the post-flash system command(s) on the host +1. Reconnect the printer +1. Send the post-flash gcode command(s) to the printer + +#### Pre-flash System Command +Specify a system command or script to run on the host prior to flashing. Multiple commands can be separated with a semicolon. + +#### Pre-flash Gcode +Specify gcode commands to run on the printer prior to flashing. Multiple commands can be separated with a semicolon. +**Commands are only run if the printer is connected when flashing is initiated** + +#### Pre-flash Gcode Delay +Delay after sending pre-flash gcode. Allows time for code to complete before initiating flash. #### Post-flash Delay #### This setting can be used to insert a delay of up to 180s after the firmware has been uploaded. This can be useful if the board takes some time to restart. A delay of 20-30s is usually enough. -#### Post-flash Gcode #### +#### Post-flash System Command +Specify a system command or script to run on the host after flashing. Multiple commands can be separated with a semicolon. + +#### Post-flash Gcode You can use the post-flash gcode settings to run gcode commands after a successful firmware flash. The post-flash code will run more or less immediately if the printer was connected before the flash started (so reconnects automatically when the flash finishes), or whenever the printer is manually reconnected after the firmware is flashed.