Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
voxelias committed Jul 26, 2023
1 parent c60e2a5 commit 652a96b
Show file tree
Hide file tree
Showing 19 changed files with 260 additions and 531 deletions.
1 change: 1 addition & 0 deletions config.sl1.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = (env, args) => {
WITH_START_PRINT_AFTER_UPLOAD: true,
WITH_LOGS: false,
WITH_FONT: false,
WITH_V1_API: true,
...env,
};
return webpackConfig(config, args);
Expand Down
7 changes: 4 additions & 3 deletions src/printer/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { LinkState, translateState } from "../state";

const SEPARATOR = " - ";

export const getPrinterLabel = (context) => {
return buildTitle([context.printer?.location, context.printer?.name]);
};
export const getPrinterLabel = (context) => buildTitle([
context.printer?.location || context.printer?.hostname,
context.printer?.name
]);

export const buildTitle = (titleItems) => {
return [...titleItems]
Expand Down
1 change: 0 additions & 1 deletion src/printer/components/cameras.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,6 @@ const createCameraSettingsModal = (cameraId, resolve) => {
inputTriggerScheme.value = translateTriggerScheme(data.trigger_scheme);

setVisible(inputFocus.parentNode, hasFocus);
console.log(`DEBUG: has focus (${hasFocus})`, data)
if (hasFocus) {
inputFocus.value = Math.round(data.focus * 100);
}
Expand Down
70 changes: 10 additions & 60 deletions src/printer/components/dataFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,6 @@ const str_GB = translate("unit.gb");
const str_true = translate("prop.true");
const str_false = translate("prop.false");

/**
* Format the value data with format specificated.
* @param {string} format - one of ["int", "number", "layer", "temp", "fan", "resin", "cover", "date", "progress", "timeEst", "time", "expo", "boolean"]
* @param {any} value
*/
const formatData = (format, value) => {
if (process.env.PRINTER_TYPE === "sla") {
return slaFormatData(format, value);
} else {
return fdmFormatData(format, value);
}
};

/**
* It formats a number using fixed-point notation with one digit after the decimal point.
* ex: 123.456 => 123.4
Expand Down Expand Up @@ -193,75 +180,38 @@ function formatBoolean(value) {
}

/**
* Format the value data with format specificated for sla type.
* @param {string} format - one of ["int", "number", "layer", "temp", "fan", "resin", "cover", "date", "progress", "timeEst", "time", "expo", "boolean"]
* Format the value data with format specificated.
* @param {string} format - one of ["number", "temp", "fan", "pos", "date", "progress", "timeEst", "time"]
* @param {any} value
*/
const slaFormatData = (format, value) => {
const formatData = (format, value) => {
if (value === undefined || (value === null && format !== "progress")) {
return translate("prop.na");
}

switch (format) {
case "int":
return parseInt(value);
case "number":
return numberFormat(value);
case "layer":
return numberFormat(value, false) + " mm";
case "temp":
return numberFormat(value) + " °C";
case "fan":
return numberFormat(value) + ` ${str_rpm}`;
case "resin":
return numberFormat(value) + ` ${str_ml}`;
case "cover":
return value
? translate("prop.cover-closed")
: translate("prop.cover-opened");
case "date":
return dateFormat(value);
case "progress":
return numberFormat((value || 0) * 100, true, 0) + "%";
case "timeEst":
return formatEstimatedTime(value);
case "time":
return formatTime(value);
case "est-time":
return "~ " + formatTime(value);
case "expo":
return formatExposure(value);
case "totalLayer":
return totalLayers(value);
case "material":
return value || translate("prop.na");
case "size":
return formatSize(value);
case "boolean":
return formatBoolean(value);
default:
return value;
}
};

/**
* Format the value data with format specificated for fdm type.
* @param {string} format - one of ["number", "temp", "fan", "pos", "date", "progress", "timeEst", "time"]
* @param {any} value
*/
const fdmFormatData = (format, value) => {
if (value === undefined || (value === null && format !== "progress")) {
return translate("prop.na");
}

switch (format) {
case "number":
return numberFormat(value);
case "temp":
return numberFormat(value) + " °C";
case "temp_int":
return numberFormat(value, 0) + "°C";
case "fan":
return numberFormat(value) + ` ${str_rpm}`;
case "resin":
return numberFormat(value) + ` ${str_ml}`;
case "cover":
return value
? translate("prop.cover-closed")
: translate("prop.cover-opened");
case "print":
return numberFormat(value || 0, true, 0) + "%";
case "pos":
Expand Down
3 changes: 3 additions & 0 deletions src/printer/components/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ const updateFiles = (opts = {}) => {
headers: { "If-None-Match": lastETag },
})
.then((result) => {
if (result.code === 304) {
return
}
if (url !== getCurrentApiPath()) {
// user navigated to other folder
return;
Expand Down
48 changes: 19 additions & 29 deletions src/printer/components/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@
// Copyright (C) 2021 Prusa Research a.s. - www.prusa3d.com
// SPDX-License-Identifier: GPL-3.0-or-later

import joinPaths from "../../helpers/join_paths";
import updateProperties from "./updateProperties";
import { cancelJob, cancelPreview, pauseJob, resumeJob, startJob } from "./jobActions";
import { deleteFile, downloadFile } from "./fileActions";
import { getImage, getJson } from "../../auth";
import { handleError } from "./errors";
import { renderProgressImg, updateProgressImg } from "./progressImage";
import { renderProgressImg } from "./progressImage";
import { setEnabled, setHidden, setVisible, showLoading, hideLoading } from "../../helpers/element";
import { updateProgressBar } from "./progressBar";
import { translate } from "../../locale_provider";
import changeExposureTimesQuestion from "../sla/exposure";
import { resinRefill } from "../sla/refill";
import changeExposureTimesQuestion from "../views/exposure";
import { resinRefill } from "../views/refill";
import { JobPendingStates, LinkState, OperationalStates } from "../../state";
import { setButtonLoading, unsetButtonLoading } from "../../helpers/button";
import printer from "..";
import { context } from "../fdm";

let pendingCommand = null;
let pendingDownload = null;
Expand Down Expand Up @@ -102,14 +98,13 @@ function updateComponent(context, isFilePreview) {
function setupRefill(stateText) {
const preview = document.getElementById("preview-wrapper")
const refill = document.getElementById("refill-wrapper")
if (stateText == "Feed me" || stateText == "Pour in resin") {
if (stateText == "Pour in resin") {
if ([LinkState.REFILL, LinkState.POUR_IN_RESIN].includes(stateText)) {
if (stateText == LinkState.POUR_IN_RESIN) {
translate("msg.sla-pour-resin", { query: "#sla-refill-text" });
}
setHidden(preview);
setVisible(refill);
}
else {
} else {
setHidden(refill);
setVisible(preview);
}
Expand Down Expand Up @@ -173,18 +168,13 @@ function setupButtons(state, dataSource, jobId) {
setupDownloadButton(state, file, jobId);

if (!!jobId) {
if (process.env.PRINTER_TYPE === "fdm") {
setupPauseButton(state, jobId, "#job #pause");
setupResumeButton(state, jobId);
}
setupPauseButton(state, jobId, "#job #pause");
setupResumeButton(state, jobId);

if (process.env.PRINTER_TYPE === "sla") {
const jobFile = jobResult?.job?.file;
if (jobFile)
setupExposureButton(state, jobFile, changeExposureTimesQuestion);
setupPauseButton(state, jobId, "#job #refill");
setupSlaResumeButton(state, "#job #continue");
setupSlaResumeButton(state, "#job #back");
setupExposureButton(state, file, changeExposureTimesQuestion);
// setupSlaResumeButton(state, "#job #resume");
//setupSlaResumeButton(state, "#job #back");
}
}
}
Expand Down Expand Up @@ -252,30 +242,30 @@ function setupPauseButton(state, jobId, selector) {

function setupResumeButton(state, jobId) {
const btn = document.querySelector("#job #resume");
const isPaused = state === LinkState.PAUSED;
const isPaused = [LinkState.PAUSED, LinkState.POUR_IN_RESIN].includes(state);
setVisible(btn, isPaused);
setEnabled(btn, !pendingCommand && isPaused);

if (btn) {
btn.onclick = () => {
setEnabled(btn, false);
pendingCommand = {code: "resume", state: state};
resumeJob(jobId)
.catch(() => pendingCommand = null);
const command = (state !== LinkState.REFILL) ? resumeJob(jobId) : resinRefill();
command.catch(() => pendingCommand = null);
}
}
}

function setupSlaResumeButton(state, selector) {
const btn = document.querySelector(selector);
if (selector.includes("#back"))
setVisible(btn, state.flags.paused && state.text === "Feed me");
setVisible(btn, state === LinkState.REFILL);
else
setVisible(btn, state.flags.paused);
setVisible(btn, state === LinkState.PAUSED);


if (btn) {
if (state.text == "Feed me" && !selector.includes("#back")) {
if (state == LinkState.REFILL && !selector.includes("#back")) {
btn.onclick = resinRefill;
} else {
btn.onclick = resumeJob;
Expand Down Expand Up @@ -324,8 +314,8 @@ function setupDownloadButton(state, file, jobId) {
function setupExposureButton(state, jobFile, changeExposureTimesQuestion) {
const btn = document.querySelector("#job #exposure");
if (btn) {
setVisible(btn, state.text === "Pour in resin" || state.text === "Printing");
setEnabled(btn, state.flags.operational);
setVisible(btn, [LinkState.POUR_IN_RESIN, LinkState.PRINTING].includes(state));
setEnabled(btn, [...OperationalStates, LinkState.POUR_IN_RESIN].includes(state));
btn.onclick = () => changeExposureTimesQuestion(jobFile);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/printer/components/toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export const createToast = (title, message, type) => {
function show({ title, message, type, onClose }) {
const article = createToast(title, message, type);
const close = () => {
toast_context.removeChild(article);
if (toast_context.contains(article)) {
toast_context.removeChild(article);
}
onClose?.();
};

Expand Down
42 changes: 32 additions & 10 deletions src/printer/fdm/context.js → src/printer/context.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getImage, getJson } from "../../auth";
import { handleError } from "../components/errors";
import { LinkState } from "../../state";
import { getEstimatedEnd } from "../common";
import { getImage, getJson } from "../auth";
import { handleError } from "./components/errors";
import { LinkState } from "../state";
import { getEstimatedEnd } from "./common";

export class Context {
constructor() {
Expand Down Expand Up @@ -64,14 +64,14 @@ export class Context {
return getJson("/api/connection", { method: "GET" })
.then(res => {
this.link.connect.settings = {
hostname: res.data.connect.hostname,
port: res.data.connect.port,
tls: res.data.connect.tls,
hostname: res.data.connect?.hostname,
port: res.data.connect?.port,
tls: res.data.connect?.tls,
};
this.link.connect.registration = res.data.connect.registration;
this.link.connect.registration = res.data.connect?.registration;
this.link.printer.settings = {
port: res.data.current.port,
baudrate: res.data.current.baudrate,
port: res.data.current?.port,
baudrate: res.data.current?.baudrate,
};
});
}
Expand Down Expand Up @@ -105,12 +105,14 @@ export class Context {
hostname: printer.hostname,
port: printer.port,
};
this.fileExtensions = printer.project_extensions ?? process.env["FILE_EXTENSIONS"].split(",")
}

updateTelemetry(printer) {
this.state = LinkState.fromApi(printer.state.toUpperCase());
this.telemetry = {
temperature: {
// fdm
nozzle: {
current: printer.temp_nozzle,
target: printer.target_nozzle,
Expand All @@ -119,6 +121,16 @@ export class Context {
current: printer.temp_bed,
target: printer.target_bed,
},
// sla
ambient: {
current: printer.temp_ambient,
},
cpu: {
current: printer.temp_cpu,
},
uvLED: {
current: printer.temp_uv_led,
},
},
axis: {
x: printer.axis_x,
Expand All @@ -128,9 +140,15 @@ export class Context {
flow: printer.flow,
speed: printer.speed,
fan: {
// fdm
hotend: printer.fan_hotend,
print: printer.fan_print,
// sla
blower: printer.fan_blower,
rear: printer.fan_rear,
uvLED: printer.fan_uv_led,
},
coverClosed: printer.cover_closed,
};
// hide status if connect is not supported
this.link.connect.message = printer.status_connect?.message ?? "";
Expand Down Expand Up @@ -344,6 +362,10 @@ const mapFile = (data) => ({
filamentType: data.meta?.filament_type,
layerHeight: data.meta?.layer_height,
estimatedPrintTime: data.meta?.estimated_print_time,
exposureTime: data.meta?.exposure_time,
exposureTimeCalibration: data.meta?.exposure_time_calibration,
exposureTimeFirst: data.meta?.exposure_time_first,
exposureUserProfile: data.meta?.exposure_user_profile,
},
readOnly: data.read_only || data.ro
});
Loading

0 comments on commit 652a96b

Please sign in to comment.