add ams tray selector

This commit is contained in:
Stewart Allen 2025-02-10 17:00:25 -05:00
commit f1e5ccae1a
3 changed files with 48 additions and 10 deletions

View file

@ -223,6 +223,23 @@ self.kiri.load(api => {
total_layer_num,
upload
} = print || {};
let { tray_pre, tray_now, tray_tar } = ams || {};
let trays = ams?.ams?.map((ams, unit) => {
return ams.tray.map(tray => {
return { unit, wet: ams.humidity, ...tray };
});
}).flat();
if (trays && trays.length) {
let options = trays.map(tray => h.option({
_: tray.id,
_selected: tray_now === tray.id,
value: tray.id,
}));
h.bind($('bbl_ams_tray'), [
h.option({ _: 'none', value: '255' }),
...options
]);
}
let state = (gcode_state || 'unknown').toLowerCase();
$('bbl_noz').value = nozzle_diameter || '';
$('bbl_noz_temp').value = nozzle_temper?.toFixed(1) ?? '';
@ -271,11 +288,12 @@ self.kiri.load(api => {
}), undefined, 2);
$('bbl_accel').selectedIndex = (spd_lvl ?? 2) - 1;
if (print_error) {
bbl_status.value = `print error ${print_error}`
bbl_status.value = `${state} | print error ${print_error}`
} else if (mc_remaining_time && gcode_state !== 'FAILED') {
bbl_status.value = `layer ${layer_num} of ${total_layer_num} | ${mc_percent}% complete | ${mc_remaining_time} minutes left | ${state}`
} else {
bbl_status.value = `printer ${print_type || ""} | ${state}`;
let ams_tray = tray_now !== tray_tar ? ` | ams loading spool ${tray_tar}` : '';
bbl_status.value = `printer ${print_type || ""} | ${state}${ams_tray}`;
}
if (gcode_state && conn_alert) {
api.alerts.hide(conn_alert);
@ -285,7 +303,7 @@ self.kiri.load(api => {
function render_list(to) {
let list = Object.keys(printers).map(name => {
return selected?.name === name ?
h.option({ _: name, value: name, selected: true }) :
h.option({ _: name, value: name, _selected: true }) :
h.option({ _: name, value: name });
});
list = [
@ -363,6 +381,7 @@ self.kiri.load(api => {
function file_print(path) {
if (selected?.rec?.host && path) {
let { host, code, serial } = selected.rec;
console.log({ file_print: path, host, code, serial, amsmap });
socket.send({ cmd: "file-print", path, host, code, serial, amsmap });
}
}
@ -577,7 +596,7 @@ self.kiri.load(api => {
h.canvas({
id: "bbl_video",
class: "video hide",
style: "width: 100%; height: 100%; box-sizing: border-box",
style: "width: 100%; height: auto; box-sizing: border-box; aspect-ratio: 16 / 9",
})
]),
h.div({ class: "f-col gap3" }, [
@ -585,7 +604,6 @@ self.kiri.load(api => {
h.label({ class: "set-header dev-sel" }, [
h.a('ams')
]),
// { print: { auto_recovery: true, command: 'print_option', option: 1, reason: 'success', result: 'success', sequence_id: '20005' } }
h.div({ class: "var-row" }, [
// home_flag bit 11 (0x400)
h.label('auto spool advance'),
@ -601,6 +619,21 @@ self.kiri.load(api => {
})
} })
]),
h.div({ class: "var-row" }, [
h.label('tray select'),
h.select({ id: "bbl_ams_tray", onchange() {
let new_tray = $('bbl_ams_tray').value
api.alerts.show(`select tray ${new_tray}`,2);
cmd_direct({
print: {
command: 'ams_change_filament',
curr_temp: 220, // current filament heat to
tar_temp: 220, // new filament heat to
target: parseInt(new_tray)
}
});
} })
]),
]),
h.div({ class: "t-body t-inset f-col gap3 pad4 grow" }, [
h.label({ class: "set-header dev-sel" }, [
@ -676,6 +709,7 @@ self.kiri.load(api => {
onclick() {
console.log({ printing: selected.file.path });
file_print(selected.file.path);
api.alerts.show(`printing: ${selected.file.path}`,2);
}}),
]),
h.div({ class: "t-body t-inset f-col gap3 pad4" }, [

View file

@ -10,7 +10,7 @@ module.exports = async (server) => {
const mcache = {};
const wsopen = [];
const found = {};
const debug = false;
const debug = true;
class MQTT {
#timer;
@ -205,7 +205,6 @@ module.exports = async (server) => {
function file_print(opts = {}) {
const { host, code, serial, filename, amsmap } = opts;
debug && util.log({ file_print: opts });
const cmd = {
print: {
command: "project_file",
@ -221,8 +220,9 @@ module.exports = async (server) => {
}
};
if (amsmap) {
cmd.print.ams_mapping = amsmap;
cmd.print.ams_mapping = amsmap.split(',').map(v => parseInt(v));
}
debug && util.log({ file_print: cmd });
get_mqtt(host, code, serial, message => {
debug && util.log('mqtt_recv', message);
wsend({ serial, message });
@ -311,11 +311,10 @@ module.exports = async (server) => {
res.setHeader('Cache-Control', 'no-cache, no-store, private');
const data = req.app.post;
const { host, code, filename, serial, ams, start } = query;
const amsmap = ams ? ams.split(',').map(v => parseInt(v)) : undefined;
ftp_send({ host, code, filename, data })
.then(() => {
if (serial && start ==='true') {
file_print({ host, code, serial, filename, amsmap });
file_print({ host, code, serial, filename, amsmap: ams });
}
res.end(o2s({ sent: true }));
})

View file

@ -33,9 +33,14 @@ function build(data, context) {
html.push(`<${type}`);
let func = {};
for (let [key, val] of Object.entries(attr || {})) {
if (val === undefined) {
continue;
}
let tov = typeof val;
if (key === '_') {
text = val;
} else if (key.startsWith('_')) {
if (val) html.push(` ${key.substring(1)}`);
} else if (key === 'id') {
elid = val ? (tov === 'object' ? val.join('_') : val) : undefined;
} else if (tov === 'function') {