Skip to content

Commit

Permalink
0.0.14
Browse files Browse the repository at this point in the history
fix cache file list issues
optimize file listing to only update when retrieving file list and not while selecting or deleting a file
don't remove intermediary file on local storage
  • Loading branch information
jneilliii committed Feb 18, 2024
1 parent cb4b345 commit 3889efa
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 27 deletions.
13 changes: 9 additions & 4 deletions octoprint_bambu_printer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@


class BambuPrintPlugin(
octoprint.plugin.SettingsPlugin, octoprint.plugin.TemplatePlugin
octoprint.plugin.SettingsPlugin, octoprint.plugin.TemplatePlugin, octoprint.plugin.AssetPlugin
):


def get_assets(self):
return {'js': ["js/bambu_printer.js"]}
def get_template_configs(self):
return [{"type": "settings", "custom_bindings": False}]
return [{"type": "settings", "custom_bindings": False}] #, {"type": "generic", "custom_bindings": True, "template": "bambu_printer.jinja2"}]

def get_settings_defaults(self):
return {"device_type": "X1C",
Expand All @@ -31,7 +34,9 @@ def get_settings_defaults(self):
"local_mqtt": True,
"region": "",
"email": "",
"auth_token": ""}
"auth_token": "",
"always_use_default_options": False
}

def support_3mf_files(self):
return {'machinecode': {'3mf': ["3mf"]}}
Expand All @@ -50,7 +55,7 @@ def process():
elapsed = time.monotonic() - elapsed
sd_upload_succeeded(filename, filename, elapsed)
# remove local file after successful upload to Bambu
self._file_manager.remove_file("local", filename)
# self._file_manager.remove_file("local", filename)
else:
raise Exception("upload failed")
except Exception as e:
Expand Down
68 changes: 58 additions & 10 deletions octoprint_bambu_printer/static/js/bambu_printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,74 @@
* Author: jneilliii
* License: AGPLv3
*/

$(function() {
function Bambu_printerViewModel(parameters) {
var self = this;

// assign the injected parameters, e.g.:
// self.loginStateViewModel = parameters[0];
// self.settingsViewModel = parameters[1];
self.settingsViewModel = parameters[0];
self.filesViewModel = parameters[1];

/*$('#files div.upload-buttons > span.fileinput-button:first, #files div.folder-button').remove();
$('#files div.upload-buttons > span.fileinput-button:first').removeClass('span6').addClass('input-block-level');
self.onBeforePrintStart = function(start_print_command) {
let confirmation_html = '' +
' <div class="row-fluid form-vertical">\n' +
' <div class="control-group">\n' +
' <label class="control-label">' + gettext("Plate Number") + '</label>\n' +
' <div class="controls">\n' +
' <input type="number" min="1" value="1" id="bambu_printer_plate_number" class="input-mini">\n' +
' </div>\n' +
' </div>\n' +
' </div>';
if(!self.settingsViewModel.settings.plugins.bambu_printer.always_use_default_options()){
confirmation_html += '\n' +
' <div class="row-fluid">\n' +
' <div class="span6">\n' +
' <label class="checkbox"><input id="bambu_printer_timelapse" type="checkbox"' + ((self.settingsViewModel.settings.plugins.bambu_printer.timelapse()) ? ' checked' : '') + '> ' + gettext("Enable timelapse") + '</label>\n' +
' <label class="checkbox"><input id="bambu_printer_bed_leveling" type="checkbox"' + ((self.settingsViewModel.settings.plugins.bambu_printer.bed_leveling()) ? ' checked' : '') + '> ' + gettext("Enable bed leveling") + '</label>\n' +
' <label class="checkbox"><input id="bambu_printer_flow_cali" type="checkbox"' + ((self.settingsViewModel.settings.plugins.bambu_printer.flow_cali()) ? ' checked' : '') + '> ' + gettext("Enable flow calibration") + '</label>\n' +
' </div>\n' +
' <div class="span6">\n' +
' <label class="checkbox"><input id="bambu_printer_vibration_cali" type="checkbox"' + ((self.settingsViewModel.settings.plugins.bambu_printer.vibration_cali()) ? ' checked' : '') + '> ' + gettext("Enable vibration calibration") + '</label>\n' +
' <label class="checkbox"><input id="bambu_printer_layer_inspect" type="checkbox"' + ((self.settingsViewModel.settings.plugins.bambu_printer.layer_inspect()) ? ' checked' : '') + '> ' + gettext("Enable first layer inspection") + '</label>\n' +
' <label class="checkbox"><input id="bambu_printer_use_ams" type="checkbox"' + ((self.settingsViewModel.settings.plugins.bambu_printer.use_ams()) ? ' checked' : '') + '> ' + gettext("Use AMS") + '</label>\n' +
' </div>\n' +
' </div>\n';
}
// TODO: Implement your plugin's view model here.
showConfirmationDialog({
title: "Bambu Print Options",
html: confirmation_html,
cancel: gettext("Cancel"),
proceed: [gettext("Print"), gettext("Always")],
onproceed: function (idx) {
if(idx === 1){
self.settingsViewModel.settings.plugins.bambu_printer.timelapse($('#bambu_printer_timelapse').is(':checked'));
self.settingsViewModel.settings.plugins.bambu_printer.bed_leveling($('#bambu_printer_bed_leveling').is(':checked'));
self.settingsViewModel.settings.plugins.bambu_printer.flow_cali($('#bambu_printer_flow_cali').is(':checked'));
self.settingsViewModel.settings.plugins.bambu_printer.vibration_cali($('#bambu_printer_vibration_cali').is(':checked'));
self.settingsViewModel.settings.plugins.bambu_printer.layer_inspect($('#bambu_printer_layer_inspect').is(':checked'));
self.settingsViewModel.settings.plugins.bambu_printer.use_ams($('#bambu_printer_use_ams').is(':checked'));
self.settingsViewModel.settings.plugins.bambu_printer.always_use_default_options(true);
self.settingsViewModel.saveData();
}
// replace this with our own print command API call?
start_print_command();
},
nofade: true
});
return false;
};*/
}

/* view model class, parameters for constructor, container to bind to
* Please see http://docs.octoprint.org/en/master/plugins/viewmodels.html#registering-custom-viewmodels for more details
* and a full list of the available options.
*/
OCTOPRINT_VIEWMODELS.push({
construct: Bambu_printerViewModel,
// ViewModels your plugin depends on, e.g. loginStateViewModel, settingsViewModel, ...
dependencies: [ /* "loginStateViewModel", "settingsViewModel" */ ],
dependencies: [ "settingsViewModel", "filesViewModel" ],
// Elements to bind to, e.g. #settings_plugin_bambu_printer, #tab_plugin_bambu_printer, ...
elements: [ /* ... */ ]
elements: [ "#bambu_printer_print_options" ]
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</div>
</div>
<div class="control-group">
<label class="control-label">{{ _('Print Options') }}</label>
<label class="control-label">{{ _('Default Print Options') }}</label>
<div class="controls">
<label class="checkbox"><input type="checkbox" data-bind="checked: settings.plugins.bambu_printer.timelapse"> {{ _('Enable timelapse') }}</label>
<label class="checkbox"><input type="checkbox" data-bind="checked: settings.plugins.bambu_printer.bed_leveling"> {{ _('Enable bed leveling') }}</label>
Expand All @@ -37,4 +37,10 @@
<label class="checkbox"><input type="checkbox" data-bind="checked: settings.plugins.bambu_printer.use_ams"> {{ _('Use AMS') }}</label>
</div>
</div>
{#<div class="control-group">
<label class="control-label">{{ _('Always Use Default') }}</label>
<div class="controls">
<label class="checkbox"><input type="checkbox" data-bind="checked: settings.plugins.bambu_printer.always_use_default_options"> </label>
</div>
</div>#}
</form>
27 changes: 16 additions & 11 deletions octoprint_bambu_printer/virtual.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def __init__(
self._sdPrintStarting = False
self._sdPrintingSemaphore = threading.Event()
self._sdPrintingPausedSemaphore = threading.Event()
self._sdFileListCache = {}
self._selectedSdFile = None
self._selectedSdFileSize = 0
self._selectedSdFilePos = 0
Expand All @@ -79,6 +80,7 @@ def __init__(
self._busy_loop = None



import logging

self._logger = logging.getLogger(
Expand Down Expand Up @@ -172,8 +174,12 @@ def new_update(self, event_type):
self._sdPrintStarting = False
if not self._sdPrinting:
filename = print_job.get("subtask_name")
if filename[-4:].lower() != ".3mf":
filename = print_job.get("gcode_file")
if not self._sdFileListCache.get(filename.lower()):
if self._sdFileListCache.get(f"{filename.lower()}.3mf"):
filename = f"{filename.lower()}.3mf"
elif self._sdFileListCache.get(f"{filename.lower()}.gcode.3mf"):
filename = f"{filename.lower()}.gcode.3mf"

self._selectSdFile(filename)
self._startSdPrint(from_printer=True)

Expand Down Expand Up @@ -670,11 +676,11 @@ def _mappedSdList(self) -> Dict[str, Dict[str, Any]]:

for entry in filelistcache:
if entry.startswith("/"):
filename = entry[1:]
filename = entry[1:].replace("cache/", "")
else:
filename = entry
filesize = ftp.ftps_session.size("cache/"+entry)
date_str = ftp.ftps_session.sendcmd(f"MDTM cache/{entry}").replace("213 ", "")
filename = entry.replace("cache/", "")
filesize = ftp.ftps_session.size(entry)

This comment has been minimized.

Copy link
@Pavulon87

Pavulon87 Feb 18, 2024

Contributor

filesize and date_str broken after removing "cache/" from path.

This comment has been minimized.

Copy link
@jneilliii

jneilliii Feb 18, 2024

Author Owner

ok, this must have to do with some difference between the ftps implementations in devices. I was getting an error on these on my X1 with the way it was before once I had a file in my cache folder. I'll reinvestigate these changes this week while I'm on vacation from work.

This comment has been minimized.

Copy link
@jneilliii

jneilliii Feb 18, 2024

Author Owner

#7

date_str = ftp.ftps_session.sendcmd(f"MDTM {entry}").replace("213 ", "")
filedate = datetime.datetime.strptime(date_str, "%Y%m%d%H%M%S").replace(tzinfo=datetime.timezone.utc).timestamp()
dosname = get_dos_filename(filename, existing_filenames=list(result.keys())).lower()
data = {
Expand All @@ -690,15 +696,14 @@ def _mappedSdList(self) -> Dict[str, Dict[str, Any]]:
return result

def _getSdFileData(self, filename: str) -> Optional[Dict[str, Any]]:
files = self._mappedSdList()
data = files.get(filename.lower())
data = self._sdFileListCache.get(filename.lower())
if isinstance(data, str):
data = files.get(data.lower())
data = self._sdFileListCache.get(data.lower())
return data

def _getSdFiles(self) -> List[Dict[str, Any]]:
files = self._mappedSdList()
return [x for x in files.values() if isinstance(x, dict)]
self._sdFileListCache = self._mappedSdList()
return [x for x in self._sdFileListCache.values() if isinstance(x, dict)]

def _selectSdFile(self, filename: str, check_already_open: bool = False) -> None:
if filename.startswith("/"):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
plugin_name = "OctoPrint-BambuPrinter"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "0.0.13"
plugin_version = "0.0.14"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down

0 comments on commit 3889efa

Please sign in to comment.