UNPKG

@hiv3d/bambu-node

Version:

A node.js library for connecting to and receiving data from Bambu Lab printers through their MQTT servers.

1,534 lines (1,487 loc) 75.3 kB
var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); // src/utils/sequenceIdManager.ts var START_SEQ_ID = 2e4; var END_SEQ_ID = 3e4; var PROJECT_FILE_SEQUENCE_ID = 5e4; var sequenceId = START_SEQ_ID; function getSequenceId() { sequenceId++; if (sequenceId >= END_SEQ_ID) { sequenceId = START_SEQ_ID; } return sequenceId; } __name(getSequenceId, "getSequenceId"); function isValidSequenceId(id) { return id >= START_SEQ_ID && id < END_SEQ_ID; } __name(isValidSequenceId, "isValidSequenceId"); // src/commands/AbstractCommand.ts var _AbstractCommand = class _AbstractCommand { /** * Constructs a basic command class with the properties required for basic compatibility with @hiv3d/bambu-node. * @param extra Extra properties to add to the request object. */ constructor(extra = {}) { __publicField(this, "extra"); this.extra = extra; } async invoke(client) { const { sequence_id, ...rest } = this.extra || {}; const numericId = sequence_id ? parseInt(sequence_id, 10) : null; const isProjectFilePrint = this.category === "print" && this.command === "project_file"; const finalSequenceId = isProjectFilePrint && numericId === PROJECT_FILE_SEQUENCE_ID ? PROJECT_FILE_SEQUENCE_ID : numericId && !isNaN(numericId) && isValidSequenceId(numericId) ? numericId : getSequenceId(); const rawMessage = { [this.category]: { sequence_id: finalSequenceId.toString(), command: this.command, ...rest } }; await client.publish(rawMessage); return finalSequenceId.toString(); } }; __name(_AbstractCommand, "AbstractCommand"); var AbstractCommand = _AbstractCommand; // src/responses/print/PrintMessage.ts function isPrintMessage(data) { return !!data?.print && !!data?.print?.command && [ "push_status", "resume", "gcode_line", "gcode_file", "project_file", "ams_filament_setting" ].includes(data.print.command); } __name(isPrintMessage, "isPrintMessage"); // src/responses/print/GCodeFileResponse.ts function isGcodeFileCommand(data) { return data.command === "gcode_file"; } __name(isGcodeFileCommand, "isGcodeFileCommand"); // src/responses/print/GCodeLineResponse.ts function isGCodeLineCommand(data) { return data.command === "gcode_line"; } __name(isGCodeLineCommand, "isGCodeLineCommand"); // src/responses/print/ProjectFileResponse.ts function isProjectFileCommand(data) { return data.command === "project_file"; } __name(isProjectFileCommand, "isProjectFileCommand"); // src/responses/print/PushStatusResponse.ts function isPushStatusCommand(data) { return data.command === "push_status" && Object.keys(data).length < 40; } __name(isPushStatusCommand, "isPushStatusCommand"); // src/utils/filamentConfigs.ts var filamentConfigs = { PLA: { nozzle_temp_min: "190", nozzle_temp_max: "230", bed_temp: "60", bed_temp_type: "normal" }, ABS: { nozzle_temp_min: "220", nozzle_temp_max: "270", bed_temp: "90", bed_temp_type: "high" } }; // src/responses/print/PushAllResponse.ts var PrintStage = /* @__PURE__ */ function(PrintStage2) { PrintStage2["PRINTING"] = "Printing"; PrintStage2["BED_LEVELING"] = "Auto bed leveling"; PrintStage2["HEATBED_PREHEATING"] = "Heatbed preheating"; PrintStage2["XY_MECH_MODE_SWEEP"] = "Sweeping XY mech mode"; PrintStage2["CHANGE_MATERIAL"] = "Changing filament"; PrintStage2["M400_PAUSE"] = "M400 pause"; PrintStage2["FILAMENT_RUNOUT_PAUSE"] = "Paused due to filament runout"; PrintStage2["HOTEND_HEATING"] = "Heating hotend"; PrintStage2["EXTRUDE_COMPENSATION_SCAN"] = "Calibrating extrusion"; PrintStage2["BED_SCAN"] = "Scanning bed surface"; PrintStage2["FIRST_LAYER_SCAN"] = "Inspecting first layer"; PrintStage2["BE_SURFACE_TYPT_IDENTIFICATION"] = "Identifying build plate type"; PrintStage2["SCANNER_EXTRINSIC_PARA_CALI"] = "Calibrating Micro Lidar"; PrintStage2["TOOLHEAD_HOMING"] = "Homing toolhead"; PrintStage2["NOZZLE_TIP_CLEANING"] = "Cleaning nozzle tip"; PrintStage2["EXTRUDER_TEMP_PROTECT_CALI"] = "Checking extruder temperature"; PrintStage2["USER_PAUSE"] = "Printing was paused by the user"; PrintStage2["TOOLHEAD_SHELL_OFF_PAUSE"] = "Pause of front cover falling"; PrintStage2["SCANNER_LASER_PARA_CALI"] = "Calibrating the micro lida"; PrintStage2["EXTRUDER_ABSOLUTE_FLOW_CALI"] = "Calibrating extrusion flow"; PrintStage2["HOTEND_TEMPERATURE_ERROR_PAUSE"] = "Paused due to nozzle temperature malfunction"; PrintStage2["HEATED_BED_TEMPERATURE_ERROR_PAUSE"] = "Paused due to heat bed temperature malfunction"; PrintStage2["FILAMENT_UNLOADING"] = "Filament unloading"; PrintStage2["SKIP_STEP_PAUSE"] = "Skip step pause"; PrintStage2["FILAMENT_LOADING"] = "Filament loading"; PrintStage2["MOTOR_NOISE_CALIBRATION"] = "Motor noise calibration"; PrintStage2["AMS_LOST_PAUSE"] = "Paused due to AMS lost"; PrintStage2["HEAT_BREAK_FAN_PAUSE"] = "Paused due to low speed of the heat break fan"; PrintStage2["CHAMBER_TEMPERATURE_CONTROL_ERROR_PAUSE"] = "Paused due to chamber temperature control error"; PrintStage2["CHAMBER_COOLING"] = "Cooling chamber"; PrintStage2["USER_INSERT_GCODE_PAUSE"] = "Paused by the Gcode inserted by user"; PrintStage2["MOTOR_NOISE_SHOWOFF"] = "Motor noise showoff"; PrintStage2["NOZZLE_FILAMENT_COVERED_DETECTED_PAUSE"] = "Nozzle filament covered detected pause"; PrintStage2["CUTTER_ERROR_PAUSE"] = "Cutter error pause"; PrintStage2["FIRST_LAYER_ERROR_PAUSE"] = "First layer error pause"; PrintStage2["NOZZLE_CLOG_PAUSE"] = "Nozzle clog pause"; return PrintStage2; }({}); var stageCurrToStage = { 0: "Printing", 1: "Auto bed leveling", 2: "Heatbed preheating", 3: "Sweeping XY mech mode", 4: "Changing filament", 5: "M400 pause", 6: "Paused due to filament runout", 7: "Heating hotend", 8: "Calibrating extrusion", 9: "Scanning bed surface", 10: "Inspecting first layer", 11: "Identifying build plate type", 12: "Calibrating Micro Lidar", 13: "Homing toolhead", 14: "Cleaning nozzle tip", 15: "Checking extruder temperature", 16: "Printing was paused by the user", 17: "Pause of front cover falling", 18: "Calibrating the micro lida", 19: "Calibrating extrusion flow", 20: "Paused due to nozzle temperature malfunction", 21: "Paused due to heat bed temperature malfunction", 22: "Filament unloading", 23: "Skip step pause", 24: "Filament loading", 25: "Motor noise calibration", 26: "Paused due to AMS lost", 27: "Paused due to low speed of the heat break fan", 28: "Paused due to chamber temperature control error", 29: "Cooling chamber", 30: "Paused by the Gcode inserted by user", 31: "Motor noise showoff", 32: "Nozzle filament covered detected pause", 33: "Cutter error pause", 34: "First layer error pause", 35: "Nozzle clog pause" }; var PrintStageDetails = { ["Printing"]: { controllable: true, critical: true, description: "Actively printing the model" }, ["Auto bed leveling"]: { controllable: false, critical: true, description: "Performing automatic bed leveling calibration" }, ["Heatbed preheating"]: { controllable: false, critical: true, description: "Preheating the build plate to required temperature" }, ["Sweeping XY mech mode"]: { controllable: false, critical: true, description: "Calibrating XY mechanical movement" }, ["Changing filament"]: { controllable: true, critical: false, description: "Changing filament material" }, ["M400 pause"]: { controllable: false, critical: false, description: "Temporary pause for machine commands" }, ["Paused due to filament runout"]: { controllable: true, critical: true, description: "Print paused due to filament running out" }, ["Heating hotend"]: { controllable: false, critical: true, description: "Heating nozzle to required temperature" }, ["Calibrating extrusion"]: { controllable: false, critical: true, description: "Calibrating extrusion compensation" }, ["Scanning bed surface"]: { controllable: false, critical: true, description: "Scanning bed surface topology" }, ["Inspecting first layer"]: { controllable: false, critical: true, description: "Inspecting first layer quality" }, ["Identifying build plate type"]: { controllable: false, critical: true, description: "Identifying build plate surface type" }, ["Calibrating Micro Lidar"]: { controllable: false, critical: true, description: "Calibrating Micro Lidar parameters" }, ["Homing toolhead"]: { controllable: false, critical: true, description: "Moving toolhead to home position" }, ["Cleaning nozzle tip"]: { controllable: false, critical: true, description: "Cleaning nozzle tip" }, ["Checking extruder temperature"]: { controllable: false, critical: true, description: "Verifying extruder temperature protection" }, ["Printing was paused by the user"]: { controllable: true, critical: false, description: "Print manually paused by user" }, ["Pause of front cover falling"]: { controllable: true, critical: true, description: "Print paused due to front cover falling" }, ["Calibrating the micro lida"]: { controllable: false, critical: true, description: "Calibrating micro lidar laser parameters" }, ["Calibrating extrusion flow"]: { controllable: false, critical: true, description: "Calibrating absolute extrusion flow" }, ["Paused due to nozzle temperature malfunction"]: { controllable: true, critical: true, description: "Print paused due to nozzle temperature error" }, ["Paused due to heat bed temperature malfunction"]: { controllable: true, critical: true, description: "Print paused due to bed temperature error" }, ["Filament unloading"]: { controllable: true, critical: false, description: "Unloading filament from extruder" }, ["Skip step pause"]: { controllable: true, critical: false, description: "Print paused for step skipping" }, ["Filament loading"]: { controllable: true, critical: false, description: "Loading filament into extruder" }, ["Motor noise calibration"]: { controllable: false, critical: false, description: "Calibrating motor noise reduction" }, ["Paused due to AMS lost"]: { controllable: true, critical: true, description: "Print paused due to AMS communication loss" }, ["Paused due to low speed of the heat break fan"]: { controllable: true, critical: true, description: "Print paused due to heat break fan issue" }, ["Paused due to chamber temperature control error"]: { controllable: true, critical: true, description: "Print paused due to chamber temperature error" }, ["Cooling chamber"]: { controllable: false, critical: true, description: "Cooling print chamber" }, ["Paused by the Gcode inserted by user"]: { controllable: true, critical: false, description: "Print paused by user-inserted GCode" }, ["Motor noise showoff"]: { controllable: false, critical: false, description: "Demonstrating motor noise reduction" }, ["Nozzle filament covered detected pause"]: { controllable: true, critical: true, description: "Print paused due to filament covering nozzle" }, ["Cutter error pause"]: { controllable: true, critical: true, description: "Print paused due to filament cutter error" }, ["First layer error pause"]: { controllable: true, critical: true, description: "Print paused due to first layer error" }, ["Nozzle clog pause"]: { controllable: true, critical: true, description: "Print paused due to nozzle clog" } }; var SpeedLevel = /* @__PURE__ */ function(SpeedLevel2) { SpeedLevel2["SILENT"] = "1"; SpeedLevel2["NORMAL"] = "2"; SpeedLevel2["SPORT"] = "3"; SpeedLevel2["LUDICROUS"] = "4"; return SpeedLevel2; }({}); var AmsRFIDStatus = /* @__PURE__ */ function(AmsRFIDStatus2) { AmsRFIDStatus2[AmsRFIDStatus2["IDLE"] = 0] = "IDLE"; AmsRFIDStatus2[AmsRFIDStatus2["READING"] = 1] = "READING"; AmsRFIDStatus2[AmsRFIDStatus2["GCODE_TRANS"] = 2] = "GCODE_TRANS"; AmsRFIDStatus2[AmsRFIDStatus2["GCODE_RUNNING"] = 3] = "GCODE_RUNNING"; AmsRFIDStatus2[AmsRFIDStatus2["ASSISTANT"] = 4] = "ASSISTANT"; AmsRFIDStatus2[AmsRFIDStatus2["SWITCH_FILAMENT"] = 5] = "SWITCH_FILAMENT"; AmsRFIDStatus2[AmsRFIDStatus2["HAS_FILAMENT"] = 6] = "HAS_FILAMENT"; return AmsRFIDStatus2; }({}); var UpgradeStatusProgressState = /* @__PURE__ */ function(UpgradeStatusProgressState2) { UpgradeStatusProgressState2["DOWNLOADING"] = "DOWNLOADING"; UpgradeStatusProgressState2["UPGRADE_REQUEST"] = "UPGRADE_REQUEST"; UpgradeStatusProgressState2["PRE_FLASH_START"] = "PRE_FLASH_START"; UpgradeStatusProgressState2["PRE_FLASH_SUCCESS"] = "PRE_FLASH_SUCCESS"; return UpgradeStatusProgressState2; }({}); var UpgradeStatusFinishState = /* @__PURE__ */ function(UpgradeStatusFinishState2) { UpgradeStatusFinishState2["UPGRADE_SUCCESS"] = "UPGRADE_SUCCESS"; UpgradeStatusFinishState2["DOWNLOAD_FAIL"] = "DOWNLOAD_FAIL"; UpgradeStatusFinishState2["FLASH_FAIL"] = "FLASH_FAIL"; UpgradeStatusFinishState2["PRE_FLASH_FAIL"] = "PRE_FLASH_FAIL"; UpgradeStatusFinishState2["UPGRADE_FAIL"] = "UPGRADE_FAIL"; return UpgradeStatusFinishState2; }({}); var UpgradeErrorCode = /* @__PURE__ */ function(UpgradeErrorCode2) { UpgradeErrorCode2[UpgradeErrorCode2["UpgradeNoError"] = 0] = "UpgradeNoError"; UpgradeErrorCode2[UpgradeErrorCode2["UpgradeDownloadFailed"] = 1] = "UpgradeDownloadFailed"; UpgradeErrorCode2[UpgradeErrorCode2["UpgradeVerifyFailed"] = 2] = "UpgradeVerifyFailed"; UpgradeErrorCode2[UpgradeErrorCode2["UpgradeFlashFailed"] = 3] = "UpgradeFlashFailed"; UpgradeErrorCode2[UpgradeErrorCode2["UpgradePrinting"] = 4] = "UpgradePrinting"; return UpgradeErrorCode2; }({}); var UpgradeDisplayState = /* @__PURE__ */ function(UpgradeDisplayState2) { UpgradeDisplayState2[UpgradeDisplayState2["UNAVAILABLE"] = 0] = "UNAVAILABLE"; UpgradeDisplayState2[UpgradeDisplayState2["IDLE"] = 1] = "IDLE"; UpgradeDisplayState2[UpgradeDisplayState2["UPGRADING"] = 2] = "UPGRADING"; UpgradeDisplayState2[UpgradeDisplayState2["UPGRADE_FINISHED"] = 3] = "UPGRADE_FINISHED"; return UpgradeDisplayState2; }({}); var FilamentType = /* @__PURE__ */ function(FilamentType2) { FilamentType2["PLA"] = "PLA"; FilamentType2["ABS"] = "ABS"; FilamentType2["TPU"] = "TPU"; FilamentType2["PC"] = "PC"; FilamentType2["ASA"] = "ASA"; FilamentType2["PA_CF"] = "PA-CF"; FilamentType2["PA6_CF"] = "PA6-CF"; FilamentType2["PET_CF"] = "PET-CF"; FilamentType2["PETG"] = "PETG"; FilamentType2["PETG_CF"] = "PETG-CF"; FilamentType2["PLA_AERO"] = "PLA-AERO"; FilamentType2["PLA_CF"] = "PLA-CF"; FilamentType2["PPA_CF"] = "PPA-CF"; FilamentType2["PPA_GF"] = "PPA-GF"; FilamentType2["PA"] = "PA"; FilamentType2["HIPS"] = "HIPS"; FilamentType2["PPS"] = "PPS"; FilamentType2["PPS_CF"] = "PPS-CF"; FilamentType2["PVA"] = "PVA"; FilamentType2["PLA_S"] = "PLA-S"; FilamentType2["PA_S"] = "PLA-S"; return FilamentType2; }({}); function getFilamentConfig(id) { return filamentConfigs[id] ?? null; } __name(getFilamentConfig, "getFilamentConfig"); function getStageFromCurr(stageCurr) { return stageCurrToStage[stageCurr]; } __name(getStageFromCurr, "getStageFromCurr"); function getStagesFromArray(stages) { return stages.map((stage) => stageCurrToStage[stage]).filter((stage) => stage !== void 0); } __name(getStagesFromArray, "getStagesFromArray"); function getEnrichedStages(currentStage, stageHistory) { const currentPrintStage = stageCurrToStage[currentStage]; const historyStages = getStagesFromArray(stageHistory); const currentIndex = historyStages.findIndex((stage) => stage === currentPrintStage); const enrichedStages = historyStages.map((stage, index) => { const stageDetails = PrintStageDetails[stage]; return { stage, description: stageDetails?.description || "Unknown stage", controllable: stageDetails?.controllable || false, critical: stageDetails?.critical || false, // A stage is completed if it's before the current stage in history // or if the current stage isn't in history and this is not the last stage completed: currentIndex >= 0 ? index < currentIndex : index < historyStages.length - 1, current: stage === currentPrintStage }; }); if (currentPrintStage && !historyStages.includes(currentPrintStage)) { const stageDetails = PrintStageDetails[currentPrintStage]; enrichedStages.push({ stage: currentPrintStage, description: stageDetails?.description || "Unknown stage", controllable: stageDetails?.controllable || false, critical: stageDetails?.critical || false, completed: false, current: true }); } return enrichedStages; } __name(getEnrichedStages, "getEnrichedStages"); function isPushAllCommand(data) { return data.command === "push_status" && Object.keys(data).length >= 40; } __name(isPushAllCommand, "isPushAllCommand"); // src/responses/print/UpdateFanResponse.ts function isUpdateFanCommand(data) { return data.command === "gcode_line" && Boolean(data?.param?.startsWith("M106")); } __name(isUpdateFanCommand, "isUpdateFanCommand"); // src/responses/print/UpdateLightResponse.ts function isUpdateLightCommand(data) { return data.command === "push_status" && data.hasOwnProperty("lights_report"); } __name(isUpdateLightCommand, "isUpdateLightCommand"); // src/responses/print/UpdateSpeedResponse.ts function isUpdateSpeedCommand(data) { return data.command === "push_status" && (data.hasOwnProperty("spd_lvl") || data.hasOwnProperty("spd_mag")); } __name(isUpdateSpeedCommand, "isUpdateSpeedCommand"); // src/responses/print/UpdateStateResponse.ts function isUpdateStateCommand(data) { return data.command === data.command; } __name(isUpdateStateCommand, "isUpdateStateCommand"); // src/responses/print/UpdateTempResponse.ts function isUpdateTempCommand(data) { return data.command === "gcode_line" && Boolean(data?.param?.startsWith("M104") || data?.param?.startsWith("M140")); } __name(isUpdateTempCommand, "isUpdateTempCommand"); // src/responses/mcPrint/McPrintMessage.ts function isMCPrintMessage(data) { return !!data?.mc_print && !!data?.mc_print?.command && [ "push_info" ].includes(data.mc_print.command); } __name(isMCPrintMessage, "isMCPrintMessage"); // src/responses/mcPrint/PushInfoResponse.ts function isPushInfoCommand(data) { return data.command === "push_info"; } __name(isPushInfoCommand, "isPushInfoCommand"); function getCleanPushInfoCommand(command) { const [, category, subcategory, content] = command.param.match(/^\[(.+?)](?:\[(.+?)])?\s*(.+)$/) ?? []; return { sequenceId: Number(command.sequence_id), category, subcategory, content, rawParam: command.param }; } __name(getCleanPushInfoCommand, "getCleanPushInfoCommand"); // src/responses/info/GetVersionResponse.ts function isGetVersionCommand(data) { return data.command === "get_version"; } __name(isGetVersionCommand, "isGetVersionCommand"); // src/responses/info/InfoMessage.ts function isInfoMessage(data) { return !!data?.info && !!data?.info?.command && [ "get_version" ].includes(data.info.command); } __name(isInfoMessage, "isInfoMessage"); // src/responses/ams.ts function isAMSFilamentSettingResponse(response, commandSeqId) { const result = response.command === "ams_filament_setting" && commandSeqId == response.sequence_id; if (result) { console.log("ams_filament_setting:isAMSFilamentSettingResponse", response); } return result; } __name(isAMSFilamentSettingResponse, "isAMSFilamentSettingResponse"); // src/commands/AMSFilamentSettingCommand.ts var _AMSFilamentSettingCommand = class _AMSFilamentSettingCommand extends AbstractCommand { // j["print"]["command"] = "ams_filament_setting"; // j["print"]["ams_id"] = ams_id; // j["print"]["nozzle_temp_min"] = nozzle_temp_min; // j["print"]["nozzle_temp_max"] = nozzle_temp_max; // j["print"]["tray_color"] = tray_color; // j["print"]["sequence_id"] = std::to_string(MachineObject::m_sequence_id++); // j["print"]["tray_id"] = tray_id; // j["print"]["tray_info_idx"] = filament_id; // j["print"]["setting_id"] = setting_id; // // format "FFFFFFFF" RGBA // j["print"]["tray_type"] = tray_type; constructor(params) { super({ ams_id: params.ams_id, nozzle_temp_max: params.nozzle_temp_max, nozzle_temp_min: params.nozzle_temp_min, setting_id: params.setting_id, tray_color: params.tray_color, tray_id: params.tray_id, tray_info_idx: params.filament_id, tray_type: params.filament_type }); __publicField(this, "category", "print"); __publicField(this, "command", "ams_filament_setting"); } ownsResponse(response, commandSeqId) { return isAMSFilamentSettingResponse(response, commandSeqId); } }; __name(_AMSFilamentSettingCommand, "AMSFilamentSettingCommand"); /** Special AMS ID used for external spool */ __publicField(_AMSFilamentSettingCommand, "EXTERNAL_SPOOL_AMS_ID", 255); /** Special tray ID used for external spool (virtual tray) */ __publicField(_AMSFilamentSettingCommand, "VIRTUAL_TRAY_ID", 254); var AMSFilamentSettingCommand = _AMSFilamentSettingCommand; // src/commands/GCodeCommand.ts var _GCodeCommand = class _GCodeCommand extends AbstractCommand { /** * Constructs a basic `print.gcode_file` or `print.gcode_line` command, which must be extended first to use. * @param gcode The array of Gcode instructions to execute. Implementation can be overridden if using with `gcode_file`. * @protected */ constructor(gcode) { super({ param: gcode.join("\n") + "\n" }); __publicField(this, "category", "print"); } }; __name(_GCodeCommand, "GCodeCommand"); var GCodeCommand = _GCodeCommand; // src/commands/GCodeFileCommand.ts var _GCodeFileCommand = class _GCodeFileCommand extends AbstractCommand { /** * Constructs a new GCode file command, which executes a GCode file on the printer's filesystem. * @param fileName The file name of the GCode to execute on the printer. (on the printer's filesystem) */ constructor({ fileName }) { super({ param: fileName }); __publicField(this, "category", "print"); __publicField(this, "command", "gcode_file"); __publicField(this, "ownsResponse", isGcodeFileCommand); } }; __name(_GCodeFileCommand, "GCodeFileCommand"); var GCodeFileCommand = _GCodeFileCommand; // src/commands/GCodeLineCommand.ts var _GCodeLineCommand = class _GCodeLineCommand extends GCodeCommand { /** * Creates a raw GCode line command, which executes an array of GCode instructions on the printer. * @param gcodes The array of GCode instructions to execute. */ constructor({ gcodes }) { super(gcodes); __publicField(this, "command", "gcode_line"); __publicField(this, "ownsResponse", isGCodeLineCommand); } }; __name(_GCodeLineCommand, "GCodeLineCommand"); var GCodeLineCommand = _GCodeLineCommand; // src/commands/GetVersionCommand.ts var _GetVersionCommand = class _GetVersionCommand extends AbstractCommand { /** * Constructs a new get version command. */ constructor() { super(); __publicField(this, "category", "info"); __publicField(this, "command", "get_version"); __publicField(this, "ownsResponse", isGetVersionCommand); } }; __name(_GetVersionCommand, "GetVersionCommand"); var GetVersionCommand = _GetVersionCommand; // src/commands/PushAllCommand.ts var _PushAllCommand = class _PushAllCommand extends AbstractCommand { /** * Constructs a new `pushing.pushall` command, which gets all properties from the printer. * @version * - X1 series: Already sends `pushing.pushall` responses automatically every ~2 secs. * - Other series: Only sends partial responses of `pushing.pushall` with only the values that have changed since the last response. */ constructor() { super(); __publicField(this, "category", "pushing"); __publicField(this, "command", "pushall"); __publicField(this, "ownsResponse", isPushAllCommand); } }; __name(_PushAllCommand, "PushAllCommand"); var PushAllCommand = _PushAllCommand; // src/commands/UpdateFanCommand.ts var Fan = /* @__PURE__ */ function(Fan2) { Fan2[Fan2["PART_COOLING_FAN"] = 1] = "PART_COOLING_FAN"; Fan2[Fan2["AUXILIARY_FAN"] = 2] = "AUXILIARY_FAN"; Fan2[Fan2["CHAMBER_FAN"] = 3] = "CHAMBER_FAN"; return Fan2; }({}); var _UpdateFanCommand = class _UpdateFanCommand extends GCodeCommand { /** * Constructs a `print.gcode_line` command, which is able to update the current speeds of every fan on the printer. * @param fan {Fan} The fan's speed to update. * @param speed {NumberRange<0, 100>} The fan's new speed in % (0-100). */ constructor({ fan, speed }) { super([ `M106 P${fan.toString()} S${255 * speed / 100}` ]); __publicField(this, "command", "gcode_line"); __publicField(this, "ownsResponse", isUpdateFanCommand); } }; __name(_UpdateFanCommand, "UpdateFanCommand"); var UpdateFanCommand = _UpdateFanCommand; // src/commands/UpdateLightCommand.ts var _UpdateLightCommand = class _UpdateLightCommand extends AbstractCommand { /** * Constructs a `system.ledctrl` command, which is able to update the lights throughout the printer. * @param light The light to update. * @param mode The new mode of the light. * @param loopOptions Loop options of the light. Only if `mode = "flashing"`. */ constructor({ light, mode, loopOptions = { led_on_time: 0, led_off_time: 0, loop_times: 0, interval_time: 0 } }) { super({ led_node: light, led_mode: mode, ...loopOptions }); __publicField(this, "category", "system"); __publicField(this, "command", "ledctrl"); __publicField(this, "ownsResponse", isUpdateLightCommand); } }; __name(_UpdateLightCommand, "UpdateLightCommand"); var UpdateLightCommand = _UpdateLightCommand; // src/commands/UpdateSpeedCommand.ts var _UpdateSpeedCommand = class _UpdateSpeedCommand extends AbstractCommand { /** * Constructs a `print.print_speed` command, which is able to update the speed of the printing whilst printing. * @param speed {SpeedLevel} The new speed level to set. */ constructor({ speed }) { super({ param: speed.toString() }); __publicField(this, "category", "print"); __publicField(this, "command", "print_speed"); __publicField(this, "ownsResponse", isUpdateSpeedCommand); } }; __name(_UpdateSpeedCommand, "UpdateSpeedCommand"); var UpdateSpeedCommand = _UpdateSpeedCommand; // src/commands/UpdateStateCommand.ts var _UpdateStateCommand = class _UpdateStateCommand extends AbstractCommand { /** * Constructs a `print.print_speed` command, which is able to change the state of the printer, aka stop, resume or pause it. * @param state {State} The new state of the printer. */ constructor({ state }) { super(); __publicField(this, "category", "print"); __publicField(this, "command"); __publicField(this, "ownsResponse", isUpdateStateCommand); this.command = state; } }; __name(_UpdateStateCommand, "UpdateStateCommand"); var UpdateStateCommand = _UpdateStateCommand; // src/commands/UpdateTempCommand.ts var TEMP_LIMITS = { NOZZLE: { MIN: 20, MAX: 300 }, BED: { MIN: 20, MAX: 120 }, CHAMBER: { MIN: 20, MAX: 60 } }; var TempUpdatePartType = /* @__PURE__ */ function(TempUpdatePartType2) { TempUpdatePartType2["BED"] = "M140"; TempUpdatePartType2["EXTRUDER"] = "M104"; return TempUpdatePartType2; }({}); function validateTemperature(part, temperature) { let limits; switch (part) { case "M104": limits = TEMP_LIMITS.NOZZLE; break; case "M140": limits = TEMP_LIMITS.BED; break; case "CHAMBER": limits = TEMP_LIMITS.CHAMBER; break; default: throw new Error(`Unknown part type: ${part}`); } if (temperature < limits.MIN || temperature > limits.MAX) { throw new Error(`Temperature ${temperature}\xB0C is outside safe range (${limits.MIN}\xB0C - ${limits.MAX}\xB0C) for ${part}`); } } __name(validateTemperature, "validateTemperature"); var _UpdateTempCommand = class _UpdateTempCommand extends GCodeCommand { /** * Constructs a command to change the target temperatures of bed or extruder. * @param part The part to change the target temperature of. * @param temperature The new target temperature in Celsius. * @throws Error if temperature is outside safe range */ constructor({ part, temperature }) { validateTemperature(part, temperature); super([ `${part} S${temperature}` ]); __publicField(this, "command", "gcode_line"); __publicField(this, "ownsResponse", isUpdateTempCommand); } }; __name(_UpdateTempCommand, "UpdateTempCommand"); var UpdateTempCommand = _UpdateTempCommand; var _UpdateChamberTempCommand = class _UpdateChamberTempCommand extends AbstractCommand { /** * Constructs a command to change the target temperature of the chamber. * @param temperature The new target temperature in Celsius. * @throws Error if temperature is outside safe range */ constructor(temperature) { validateTemperature("CHAMBER", temperature); super({ ctt_val: temperature }); __publicField(this, "category", "print"); __publicField(this, "command", "set_ctt"); __publicField(this, "ownsResponse", isUpdateTempCommand); } }; __name(_UpdateChamberTempCommand, "UpdateChamberTempCommand"); var UpdateChamberTempCommand = _UpdateChamberTempCommand; // src/commands/ProjectFileCommand.ts var _ProjectFileCommand = class _ProjectFileCommand extends AbstractCommand { /** * Creates a project file command for printing a file * @param param The path to the project file (e.g., "Metadata/plate_1.gcode") * @param options Additional options for the print job * @description https://github.com/Doridian/OpenBambuAPI/blob/5868cc07cef7c43a97900092ebcc426a74a2abe5/mqtt.md */ constructor({ param, options = {} }) { super({ param, project_id: options.project_id || "0", profile_id: options.profile_id || "0", task_id: options.task_id ?? "0", subtask_id: "0", subtask_name: options.subtask_name || "", file: options.file || "", url: options.url || "", md5: options.md5 || "", timelapse: options.timelapse ?? false, bed_type: options.bed_type || "auto", bed_leveling: options.bed_leveling ?? true, flow_cali: options.flow_cali ?? true, vibration_cali: options.vibration_cali ?? true, layer_inspect: options.layer_inspect ?? true, ams_mapping: options.ams_mapping || "", use_ams: options.use_ams ?? false, sequence_id: options.sequence_id }); __publicField(this, "command", "project_file"); __publicField(this, "category", "print"); __publicField(this, "ownsResponse", isProjectFileCommand); } }; __name(_ProjectFileCommand, "ProjectFileCommand"); var ProjectFileCommand = _ProjectFileCommand; // src/commands/ResumeCommand.ts var _ResumeCommand = class _ResumeCommand extends AbstractCommand { constructor() { super({ param: "" }); __publicField(this, "category", "print"); __publicField(this, "command", "resume"); __publicField(this, "ownsResponse", isUpdateStateCommand); } }; __name(_ResumeCommand, "ResumeCommand"); var ResumeCommand = _ResumeCommand; // src/commands/LoadFilamentCommand.ts var _LoadFilamentCommand = class _LoadFilamentCommand extends AbstractCommand { constructor({ trayId, oldTemp = 210, newTemp = 210 }) { super({ target: trayId, curr_temp: oldTemp, tar_temp: newTemp }); __publicField(this, "category", "print"); __publicField(this, "command", "ams_change_filament"); } ownsResponse(response, sequence_id) { if (!("print" in response)) { return false; } const printResponse = response; const responseId = printResponse.print?.sequence_id; const extraId = this.extra?.sequence_id; if (!responseId) { return false; } if (sequence_id && responseId === sequence_id) { return true; } if (extraId && responseId === extraId) { return true; } return false; } }; __name(_LoadFilamentCommand, "LoadFilamentCommand"); var LoadFilamentCommand = _LoadFilamentCommand; // src/commands/UnloadFilamentCommand.ts var _UnloadFilamentCommand = class _UnloadFilamentCommand extends AbstractCommand { constructor({ oldTemp = 210, newTemp = 210 } = {}) { super({ curr_temp: oldTemp, tar_temp: newTemp, target: _UnloadFilamentCommand.UNLOAD_TRAY_ID }); __publicField(this, "category", "print"); __publicField(this, "command", "ams_change_filament"); } ownsResponse(response, sequence_id) { if (!("print" in response)) { return false; } const printResponse = response; const responseId = printResponse.print?.sequence_id; const extraId = this.extra?.sequence_id; if (!responseId) { return false; } if (sequence_id && responseId === sequence_id) { return true; } if (extraId && responseId === extraId) { return true; } return false; } }; __name(_UnloadFilamentCommand, "UnloadFilamentCommand"); __publicField(_UnloadFilamentCommand, "UNLOAD_TRAY_ID", 255); var UnloadFilamentCommand = _UnloadFilamentCommand; // src/commands/AbortTaskCommand.ts var _AbortTaskCommand = class _AbortTaskCommand extends AbstractCommand { constructor() { super(); __publicField(this, "category", "print"); __publicField(this, "command", "stop"); } toJSON() { return { print: { command: "stop", sequence_id: getSequenceId().toString(), param: "" } }; } ownsResponse(response, sequence_id) { if (!("print" in response)) { return false; } const printResponse = response; const responseId = printResponse.print?.sequence_id; const extraId = this.extra?.sequence_id; if (!responseId) { return false; } if (sequence_id && responseId === sequence_id) { return true; } if (extraId && responseId === extraId) { return true; } return false; } }; __name(_AbortTaskCommand, "AbortTaskCommand"); var AbortTaskCommand = _AbortTaskCommand; // src/commands/PauseTaskCommand.ts var _PauseTaskCommand = class _PauseTaskCommand extends AbstractCommand { constructor() { super(); __publicField(this, "category", "print"); __publicField(this, "command", "pause"); } toJSON() { return { print: { command: "pause", sequence_id: getSequenceId().toString(), param: "" } }; } ownsResponse(response, sequence_id) { if (!("print" in response)) { return false; } const printResponse = response; const responseId = printResponse.print?.sequence_id; const extraId = this.extra?.sequence_id; if (!responseId) { return false; } if (sequence_id && responseId === sequence_id) { return true; } if (extraId && responseId === extraId) { return true; } return false; } }; __name(_PauseTaskCommand, "PauseTaskCommand"); var PauseTaskCommand = _PauseTaskCommand; // src/commands/CleanPrintErrorCommand.ts var _CleanPrintErrorCommand = class _CleanPrintErrorCommand extends AbstractCommand { constructor(subtaskId, printError) { super(); __publicField(this, "subtaskId"); __publicField(this, "printError"); __publicField(this, "category"); __publicField(this, "command"); this.subtaskId = subtaskId, this.printError = printError, this.category = "print", this.command = "clean_print_error"; } toJSON() { return { print: { command: "clean_print_error", sequence_id: getSequenceId().toString(), subtask_id: this.subtaskId, print_error: this.printError } }; } ownsResponse(response, sequence_id) { if (!("print" in response)) { return false; } const printResponse = response; const responseId = printResponse.print?.sequence_id; const extraId = this.extra?.sequence_id; if (!responseId) { return false; } if (sequence_id && responseId === sequence_id) { return true; } if (extraId && responseId === extraId) { return true; } return false; } }; __name(_CleanPrintErrorCommand, "CleanPrintErrorCommand"); var CleanPrintErrorCommand = _CleanPrintErrorCommand; // src/commands/SetBedTempCommand.ts var _SetBedTempCommand = class _SetBedTempCommand extends AbstractCommand { constructor(temperature) { super({ ctrl_type: "bed_temp", value: temperature }); __publicField(this, "temperature"); __publicField(this, "category"); __publicField(this, "command"); this.temperature = temperature, this.category = "print", this.command = "gcode_line"; } toJSON() { return { print: { command: "gcode_line", sequence_id: getSequenceId().toString(), gcode: `M140 S${this.temperature}` } }; } ownsResponse(response, sequence_id) { if (!("print" in response)) { return false; } const printResponse = response; const responseId = printResponse.print?.sequence_id; const extraId = this.extra?.sequence_id; if (!responseId) { return false; } if (sequence_id && responseId === sequence_id) { return true; } if (extraId && responseId === extraId) { return true; } return false; } }; __name(_SetBedTempCommand, "SetBedTempCommand"); var SetBedTempCommand = _SetBedTempCommand; // src/commands/SetNozzleTempCommand.ts var _SetNozzleTempCommand = class _SetNozzleTempCommand extends AbstractCommand { constructor(temperature) { super({ ctrl_type: "nozzle_temp", value: temperature }); __publicField(this, "temperature"); __publicField(this, "category"); __publicField(this, "command"); this.temperature = temperature, this.category = "print", this.command = "gcode_line"; } toJSON() { return { print: { command: "gcode_line", sequence_id: getSequenceId().toString(), gcode: `M104 S${this.temperature}` } }; } ownsResponse(response, sequence_id) { if (!("print" in response)) { return false; } const printResponse = response; const responseId = printResponse.print?.sequence_id; const extraId = this.extra?.sequence_id; if (!responseId) { return false; } if (sequence_id && responseId === sequence_id) { return true; } if (extraId && responseId === extraId) { return true; } return false; } }; __name(_SetNozzleTempCommand, "SetNozzleTempCommand"); var SetNozzleTempCommand = _SetNozzleTempCommand; // src/commands/SetChamberTempCommand.ts var _SetChamberTempCommand = class _SetChamberTempCommand extends AbstractCommand { constructor(temperature) { super(); __publicField(this, "temperature"); __publicField(this, "category"); __publicField(this, "command"); this.temperature = temperature, this.category = "print", this.command = "set_ctt"; } toJSON() { return { print: { command: "set_ctt", sequence_id: getSequenceId().toString(), ctt_val: this.temperature } }; } ownsResponse(response, sequence_id) { if (!("print" in response)) { return false; } const printResponse = response; const responseId = printResponse.print?.sequence_id; const extraId = this.extra?.sequence_id; if (!responseId) { return false; } if (sequence_id && responseId === sequence_id) { return true; } if (extraId && responseId === extraId) { return true; } return false; } }; __name(_SetChamberTempCommand, "SetChamberTempCommand"); var SetChamberTempCommand = _SetChamberTempCommand; // src/commands/SetFanSpeedCommand.ts var FanType = /* @__PURE__ */ function(FanType2) { FanType2[FanType2["PART_COOLING"] = 1] = "PART_COOLING"; FanType2[FanType2["AUXILIARY"] = 2] = "AUXILIARY"; FanType2[FanType2["CHAMBER"] = 3] = "CHAMBER"; return FanType2; }({}); var _SetFanSpeedCommand = class _SetFanSpeedCommand extends AbstractCommand { constructor(fanType, speed) { super({ ctrl_type: getFanTypeString(fanType), value: speed }); __publicField(this, "fanType"); __publicField(this, "speed"); __publicField(this, "category"); __publicField(this, "command"); this.fanType = fanType, this.speed = speed, this.category = "print", this.command = "gcode_line"; } toJSON() { return { print: { command: "gcode_line", sequence_id: getSequenceId().toString(), gcode: `M106 P${this.fanType} S${this.speed}` } }; } ownsResponse(response, sequence_id) { if (!("print" in response)) { return false; } const printResponse = response; const responseId = printResponse.print?.sequence_id; const extraId = this.extra?.sequence_id; if (!responseId) { return false; } if (sequence_id && responseId === sequence_id) { return true; } if (extraId && responseId === extraId) { return true; } return false; } }; __name(_SetFanSpeedCommand, "SetFanSpeedCommand"); var SetFanSpeedCommand = _SetFanSpeedCommand; function getFanTypeString(fanType) { switch (fanType) { case 1: return "part_cooling_fan"; case 2: return "auxiliary_fan"; case 3: return "chamber_fan"; default: return "unknown_fan"; } } __name(getFanTypeString, "getFanTypeString"); // src/commands/AxisControlCommand.ts var _AxisControlCommand = class _AxisControlCommand extends AbstractCommand { constructor(axis, distance, unit = 1, speed) { super({ axis_control: axis }); __publicField(this, "axis"); __publicField(this, "distance"); __publicField(this, "unit"); __publicField(this, "speed"); __publicField(this, "category"); __publicField(this, "command"); this.axis = axis, this.distance = distance, this.unit = unit, this.speed = speed, this.category = "print", this.command = "gcode_line"; if (!speed) { this.speed = axis === "X" || axis === "Y" ? _AxisControlCommand.DEFAULT_XY_SPEED : _AxisControlCommand.DEFAULT_ZE_SPEED; } } toJSON() { const value = this.distance * this.unit; const gcode = this.buildGCode(value); return { print: { command: "gcode_line", sequence_id: getSequenceId().toString(), gcode } }; } buildGCode(value) { if (this.axis === "E") { return `M83 G0 ${this.axis}${value.toFixed(1)} F${this.speed}`; } return `M211 S M211 X1 Y1 Z1 M1002 push_ref_mode G91 G1 ${this.axis}${value.toFixed(1)} F${this.speed} M1002 pop_ref_mode M211 R`; } ownsResponse(response, sequence_id) { if (!("print" in response)) { return false; } const printResponse = response; const responseId = printResponse.print?.sequence_id; const extraId = this.extra?.sequence_id; if (!responseId) { return false; } if (sequence_id && responseId === sequence_id) { return true; } if (extraId && responseId === extraId) { return true; } return false; } }; __name(_AxisControlCommand, "AxisControlCommand"); __publicField(_AxisControlCommand, "DEFAULT_XY_SPEED", 3e3); __publicField(_AxisControlCommand, "DEFAULT_ZE_SPEED", 900); var AxisControlCommand = _AxisControlCommand; // src/commands/AutoLevelCommand.ts var _AutoLevelCommand = class _AutoLevelCommand extends AbstractCommand { constructor() { super(); __publicField(this, "category", "print"); __publicField(this, "command", "gcode_line"); } toJSON() { return { print: { command: "gcode_line", sequence_id: getSequenceId().toString(), gcode: "G29" } }; } ownsResponse(response, sequence_id) { if (!("print" in response)) { return false; } const printResponse = response; const responseId = printResponse.print?.sequence_id; const extraId = this.extra?.sequence_id; if (!responseId) { return false; } if (sequence_id && responseId === sequence_id) { return true; } if (extraId && responseId === extraId) { return true; } return false; } }; __name(_AutoLevelCommand, "AutoLevelCommand"); var AutoLevelCommand = _AutoLevelCommand; // src/commands/GoHomeCommand.ts var _GoHomeCommand = class _GoHomeCommand extends AbstractCommand { constructor() { super(); __publicField(this, "category", "print"); __publicField(this, "command", "gcode_line"); } toJSON() { return { print: { command: "gcode_line", sequence_id: getSequenceId().toString(), gcode: "G28" } }; } ownsResponse(response, sequence_id) { if (!("print" in response)) { return false; } const printResponse = response; const responseId = printResponse.print?.sequence_id; const extraId = this.extra?.sequence_id; if (!responseId) { return false; } if (sequence_id && responseId === sequence_id) { return true; } if (extraId && responseId === extraId) { return true; } return false; } }; __name(_GoHomeCommand, "GoHomeCommand"); var GoHomeCommand = _GoHomeCommand; // src/commands/SetLightCommand.ts var LightEffect = /* @__PURE__ */ function(LightEffect2) { LightEffect2["ON"] = "on"; LightEffect2["OFF"] = "off"; LightEffect2["FLASHING"] = "flashing"; return LightEffect2; }({}); var LightNode = /* @__PURE__ */ function(LightNode2) { LightNode2["CHAMBER"] = "chamber_light"; LightNode2["WORK"] = "work_light"; return LightNode2; }({}); var _SetLightCommand = class _SetLightCommand extends AbstractCommand { constructor(params) { super({ led_node: params.node, led_mode: params.effect, led_on_time: params.options?.onTime || _SetLightCommand.DEFAULT_ON_TIME, led_off_time: params.options?.offTime || _SetLightCommand.DEFAULT_OFF_TIME, loop_times: params.options?.loops || _SetLightCommand.DEFAULT_LOOPS, interval_time: params.options?.interval || _SetLightCommand.DEFAULT_INTERVAL }); __publicField(this, "category", "system"); __publicField(this, "command", "ledctrl"); } ownsResponse(response, sequence_id) { if (!("system" in response)) { return false; } const systemResponse = response; const responseId = systemResponse.system?.sequence_id; const extraId = this.extra?.sequence_id; if (responseId) { if (sequence_id && responseId === sequence_id) { return true; } if (extraId && responseId === extraId) { return true; } } if ("lights_report" in response) { return true; } return false; } }; __name(_SetLightCommand, "SetLightCommand"); __publicField(_SetLightCommand, "DEFAULT_ON_TIME", 500); __publicField(_SetLightCommand, "DEFAULT_OFF_TIME", 500); __publicField(_SetLightCommand, "DEFAULT_LOOPS", 1); __publicField(_SetLightCommand, "DEFAULT_INTERVAL", 1e3); var SetLightCommand = _SetLightCommand; // src/commands/CameraControlCommand.ts var CameraOperation = /* @__PURE__ */ function(CameraOperation2) { CameraOperation2["RECORD"] = "ipcam_record_set"; CameraOperation2["TIMELAPSE"] = "ipcam_timelapse"; CameraOperation2["RESOLUTION"] = "ipcam_resolution_set"; return CameraOperation2; }({}); var _CameraControlCommand = class _CameraControlCommand extends AbstractCommand { constructor(operation, value) { super(); __publicField(this, "value"); __publicField(this, "category"); __publicField(this, "command"); this.value = value, this.category = "system"; this.command = operation; } toJSON() { const base = { system: { command: this.command, sequence_id: getSequenceId().toString() } }; if (this.command === "ipcam_resolution_set") { return { ...base, system: { ...base.system, resolution: this.value } }; } return { ...base, system: { ...base.system, control: typeof this.value === "boolean" ? this.value ? "enable" : "disable" : this.value } }; } ownsResponse(response, sequence_id) { if (!("system" in response)) { return false; } const systemResponse = response; const responseId = systemResponse.system?.sequence_id; const extraId = this.extra?.sequence_id; if (!responseId) { return false; } if (sequence_id && responseId === sequence_id) { return true; } if (extraId && responseId === extraId) { return true; } return false; } }; __name(_CameraControlCommand, "CameraControlCommand"); var CameraControlCommand = _CameraControlCommand; // src/types.ts var PrinterModelNamesShort = /* @__PURE__ */ function(PrinterModelNamesShort2) { PrinterModelNamesShort2["X1C"] = "X1C"; PrinterModelNamesShort2["X1"] = "X1"; PrinterModelNamesShort2["X1E"] = "X1E"; PrinterModelNamesShort2["P1P"] =