From 8f20ad0c095dbf893104a7fc75457a07f89274be Mon Sep 17 00:00:00 2001 From: Ben Lye Date: Wed, 31 Mar 2021 12:01:00 +0100 Subject: [PATCH] Custom firmware filenames (#235) --- octoprint_firmwareupdater/__init__.py | 5 ++- octoprint_firmwareupdater/methods/lpc1768.py | 4 ++ .../methods/marlinbft.py | 4 ++ .../static/js/firmwareupdater.js | 41 ++++++++++++++++++- .../templates/firmwareupdater_settings.jinja2 | 26 +++++++++++- 5 files changed, 77 insertions(+), 3 deletions(-) diff --git a/octoprint_firmwareupdater/__init__.py b/octoprint_firmwareupdater/__init__.py index 963b3ba..f765ad0 100644 --- a/octoprint_firmwareupdater/__init__.py +++ b/octoprint_firmwareupdater/__init__.py @@ -558,6 +558,8 @@ def get_settings_defaults(self): "lpc1768_preflashreset": True, "lpc1768_no_m997_reset_wait": False, "lpc1768_no_m997_restart_wait": False, + "lpc1768_use_custom_filename": False, + "lpc1768_custom_filename": "firmware.bin", "lpc1768_timestamp_filenames": False, "lpc1768_last_filename": None, "marlinbft_waitafterconnect": 0, @@ -565,6 +567,8 @@ def get_settings_defaults(self): "marlinbft_progresslogging": False, "marlinbft_no_m997_reset_wait": False, "marlinbft_no_m997_restart_wait": False, + "marlinbft_use_custom_filename": False, + "marlinbft_custom_filename": "firmware.bin", "marlinbft_timestamp_filenames": False, "marlinbft_last_filename": None, "postflash_delay": 0, @@ -658,7 +662,6 @@ def on_settings_migrate(self, target, current=None): # Set the profile to the new one self._settings.set_int(['_selected_profile'], 0) - #~~ EventHandlerPlugin API def on_event(self, event, payload): # Only handle the CONNECTED event diff --git a/octoprint_firmwareupdater/methods/lpc1768.py b/octoprint_firmwareupdater/methods/lpc1768.py index 0d3bcbf..7d81173 100644 --- a/octoprint_firmwareupdater/methods/lpc1768.py +++ b/octoprint_firmwareupdater/methods/lpc1768.py @@ -32,6 +32,8 @@ def _flash_lpc1768(self, firmware=None, printer_port=None, **kwargs): no_m997_reset_wait = self.get_profile_setting_boolean("lpc1768_no_m997_reset_wait") lpc1768_path = self.get_profile_setting("lpc1768_path") timestamp_filenames = self.get_profile_setting_boolean("lpc1768_timestamp_filenames") + use_custom_filename = self.get_profile_setting_boolean("lpc1768_use_custom_filename") + custom_filename = self.get_profile_setting("lpc1768_custom_filename").strip() if self.get_profile_setting_boolean("lpc1768_preflashreset"): self._send_status("progress", subtype="boardreset") @@ -120,6 +122,8 @@ def _flash_lpc1768(self, firmware=None, printer_port=None, **kwargs): # Copy the new firmware file if timestamp_filenames: target = datetime.datetime.now().strftime("fw%H%M%S.bin") + elif use_custom_filename and custom_filename is not None: + target = custom_filename else: target = "firmware.bin" diff --git a/octoprint_firmwareupdater/methods/marlinbft.py b/octoprint_firmwareupdater/methods/marlinbft.py index a5b4321..2d3af01 100644 --- a/octoprint_firmwareupdater/methods/marlinbft.py +++ b/octoprint_firmwareupdater/methods/marlinbft.py @@ -47,6 +47,8 @@ def _flash_marlinbft(self, firmware=None, printer_port=None, **kwargs): bft_verbose = self.get_profile_setting_boolean("marlinbft_progresslogging") no_m997_reset_wait = self.get_profile_setting_boolean("marlinbft_no_m997_reset_wait") timestamp_filenames = self.get_profile_setting_boolean("marlinbft_timestamp_filenames") + use_custom_filename = self.get_profile_setting_boolean("marlinbft_use_custom_filename") + custom_filename = self.get_profile_setting("marlinbft_custom_filename").strip() # Loggging if bft_verbose: @@ -85,6 +87,8 @@ def _flash_marlinbft(self, firmware=None, printer_port=None, **kwargs): # Copy the file if timestamp_filenames: target = datetime.datetime.now().strftime("fw%H%M%S.bin") + elif use_custom_filename and custom_filename is not None: + target = custom_filename else: target = "firmware.bin" diff --git a/octoprint_firmwareupdater/static/js/firmwareupdater.js b/octoprint_firmwareupdater/static/js/firmwareupdater.js index f397ba6..584dae7 100644 --- a/octoprint_firmwareupdater/static/js/firmwareupdater.js +++ b/octoprint_firmwareupdater/static/js/firmwareupdater.js @@ -84,6 +84,8 @@ $(function() { self.configLpc1768NoResetWait = ko.observable(); self.configLpc1768NoRestartWait = ko.observable(); self.configLpc1768TimestampFilenames = ko.observable(); + self.configLpc1768UseCustomFilename = ko.observable(); + self.configLpc1768CustomFilename = ko.observable(); // Observables for lpc1768 UI messages self.lpc1768PathBroken = ko.observable(false); @@ -100,6 +102,8 @@ $(function() { self.configMarlinBftNoResetWait = ko.observable(); self.configMarlinBftNoRestartWait = ko.observable(); self.configMarlinBftTimestampFilenames = ko.observable(); + self.configMarlinBftUseCustomFilename = ko.observable(); + self.configMarlinBftCustomFilename = ko.observable(); self.marlinbftHasCapability = ko.observable(); self.marlinbftHasBinProto2Package = ko.observable(); @@ -841,6 +845,8 @@ $(function() { self.configLpc1768NoResetWait(self.getProfileSetting("lpc1768_no_m997_reset_wait")); self.configLpc1768NoRestartWait(self.getProfileSetting("lpc1768_no_m997_restart_wait")); self.configLpc1768TimestampFilenames(self.getProfileSetting("lpc1768_timestamp_filenames")); + self.configLpc1768UseCustomFilename(self.getProfileSetting("lpc1768_use_custom_filename")); + self.configLpc1768CustomFilename(self.getProfileSetting("lpc1768_custom_filename")); // Load the marlinbft settings self.configMarlinBftWaitAfterConnect(self.getProfileSetting("marlinbft_waitafterconnect")); @@ -849,6 +855,8 @@ $(function() { self.configMarlinBftNoResetWait(self.getProfileSetting("marlinbft_no_m997_reset_wait")); self.configMarlinBftNoRestartWait(self.getProfileSetting("marlinbft_no_m997_restart_wait")); self.configMarlinBftTimestampFilenames(self.getProfileSetting("marlinbft_timestamp_filenames")); + self.configMarlinBftUseCustomFilename(self.getProfileSetting("marlinbft_use_custom_filename")); + self.configMarlinBftCustomFilename(self.getProfileSetting("marlinbft_custom_filename")); // Load the stm32flash settings self.configStm32flashPath(self.getProfileSetting("stm32flash_path")); @@ -951,7 +959,8 @@ $(function() { profiles[index]["lpc1768_no_m997_reset_wait"] = self.configLpc1768NoResetWait(); profiles[index]["lpc1768_no_m997_restart_wait"] = self.configLpc1768NoRestartWait(); profiles[index]["lpc1768_timestamp_filenames"] = self.configLpc1768TimestampFilenames(); - + profiles[index]["lpc1768_use_custom_filename"] = self.configLpc1768UseCustomFilename(); + profiles[index]["lpc1768_custom_filename"] = self.configLpc1768CustomFilename(); // MarlinBFT Settings profiles[index]["marlinbft_waitafterconnect"] = self.configMarlinBftWaitAfterConnect(); @@ -960,6 +969,8 @@ $(function() { profiles[index]["marlinbft_no_m997_reset_wait"] = self.configMarlinBftNoResetWait(); profiles[index]["marlinbft_no_m997_restart_wait"] = self.configMarlinBftNoRestartWait(); profiles[index]["marlinbft_timestamp_filenames"] = self.configMarlinBftTimestampFilenames(); + profiles[index]["marlinbft_use_custom_filename"] = self.configMarlinBftUseCustomFilename(); + profiles[index]["marlinbft_custom_filename"] = self.configMarlinBftCustomFilename(); // STM32Flash Settings profiles[index]["stm32flash_path"] = self.configStm32flashPath(); @@ -1092,6 +1103,34 @@ $(function() { self.configLpc1768UnmountCommand(self.profileDefaults["lpc1768_unmount_command"]); } + self.resetLpc1768CustomFilename = function() { + self.configLpc1768CustomFilename(self.profileDefaults["lpc1768_custom_filename"]); + } + + self.toggleLpc1768Filenames = function() { + if (self.configLpc1768UseCustomFilename() == true){ + self.configLpc1768TimestampFilenames(false); + } + if (self.configLpc1768TimestampFilenames() == true){ + self.configLpc1768UseCustomFilename(false); + } + return true; + } + + self.resetMarlinBftCustomFilename = function() { + self.configLpc1768CustomFilename(self.profileDefaults["marlinbft_custom_filename"]); + } + + self.toggleMarlinBftFilenames = function() { + if (self.configMarlinBftUseCustomFilename() == true){ + self.configMarlinBftTimestampFilenames(false); + } + if (self.configMarlinBftTimestampFilenames() == true){ + self.configMarlinBftUseCustomFilename(false); + } + return true; + } + self.testAvrdudePath = function() { var filePathRegEx_Linux = new RegExp("^(\/[^\0/]+)+$"); var filePathRegEx_Windows = new RegExp("^[A-z]\:\\\\.+.exe$"); diff --git a/octoprint_firmwareupdater/templates/firmwareupdater_settings.jinja2 b/octoprint_firmwareupdater/templates/firmwareupdater_settings.jinja2 index 2526f99..2ddcf0c 100644 --- a/octoprint_firmwareupdater/templates/firmwareupdater_settings.jinja2 +++ b/octoprint_firmwareupdater/templates/firmwareupdater_settings.jinja2 @@ -399,10 +399,21 @@
- +
{{ _('Firmware file will be saved on the printer as fwHHMMSS.bin (where HHMMSS is the current time) instead of firmware.bin. Needed for Ender 3 V2.') }}
+ +
+ +
+ + +
+ {{ _('Firmware file will be saved on the printer using the specified name.') }} +
@@ -464,6 +475,19 @@ {{ _('Firmware file will be saved on the printer as fwHHMMSS.bin (where HHMMSS is the current time) instead of firmware.bin. Needed for Ender 3 V2.') }} +