Skip to content

Commit

Permalink
Custom firmware filenames (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
benlye authored Mar 31, 2021
1 parent 3e3151a commit 8f20ad0
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 3 deletions.
5 changes: 4 additions & 1 deletion octoprint_firmwareupdater/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,13 +558,17 @@ 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,
"marlinbft_timeout": 1000,
"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,
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions octoprint_firmwareupdater/methods/lpc1768.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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"

Expand Down
4 changes: 4 additions & 0 deletions octoprint_firmwareupdater/methods/marlinbft.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"

Expand Down
41 changes: 40 additions & 1 deletion octoprint_firmwareupdater/static/js/firmwareupdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();

Expand Down Expand Up @@ -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"));
Expand All @@ -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"));
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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$");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,21 @@
<label class="control-label">{{ _('Use timestamp filenames') }}</label>
<div class="controls">
<div class="input">
<input type="checkbox" data-bind="checked: configLpc1768TimestampFilenames">
<input type="checkbox" data-bind="checked: configLpc1768TimestampFilenames, disable: configLpc1768UseCustomFilename, click: toggleLpc1768Filenames">
</div>
<span class="help-block">{{ _('Firmware file will be saved on the printer as <code>fwHHMMSS.bin</code> (where HHMMSS is the current time) instead of <code>firmware.bin</code>. Needed for Ender 3 V2.') }}</span>
</div>
<label class="control-label">{{ _('Customize firmware filename') }}</label>
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: configLpc1768UseCustomFilename, disable: configLpc1768TimestampFilenames, click: toggleLpc1768Filenames">
</label>
<div class="input-append">
<input type="text" class="input-block-level" data-bind="value: configLpc1768CustomFilename, enable: configLpc1768UseCustomFilename">
<button class="btn" type="button" data-bind="click: resetLpc1768CustomFilename, enable: configLpc1768UseCustomFilename">{{ _('Reset') }}</button>
</div>
<span class="help-block">{{ _('Firmware file will be saved on the printer using the specified name.') }}</span>
</div>
</div>
</div>
<!-- Advanced lpc1768 options -->
Expand Down Expand Up @@ -464,6 +475,19 @@
</div>
<span class="help-block">{{ _('Firmware file will be saved on the printer as <code>fwHHMMSS.bin</code> (where HHMMSS is the current time) instead of <code>firmware.bin</code>. Needed for Ender 3 V2.') }}</span>
</div>
<!--
<label class="control-label">{{ _('Customize firmware filename') }}</label>
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: configMarlinBftUseCustomFilename, disable: configMarlinBftTimestampFilenames, click: toggleMarlinBftFilenames">
</label>
<div class="input-append">
<input type="text" class="input-block-level" data-bind="value: configMarlinBftCustomFilename, enable: configMarlinBftUseCustomFilename">
<button class="btn" type="button" data-bind="click: resetMarlinBftCustomFilename, enable: configMarlinBftUseCustomFilename">{{ _('Reset') }}</button>
</div>
<span class="help-block">{{ _('Firmware file will be saved on the printer using the specified name.') }}</span>
</div>
-->
</div>
</div>
<!-- Advanced marlinbft options -->
Expand Down

0 comments on commit 8f20ad0

Please sign in to comment.