From c82df8a2042c6e03ad95e11a72236728aba86a5a Mon Sep 17 00:00:00 2001 From: AndrewLemons Date: Wed, 13 Mar 2024 11:00:14 -0400 Subject: [PATCH 1/5] Add disconnect method --- src/classes/BambuMQTT.ts | 8 ++++++++ src/classes/BambuPrinter.ts | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/src/classes/BambuMQTT.ts b/src/classes/BambuMQTT.ts index 7a0cfd7..4252a54 100644 --- a/src/classes/BambuMQTT.ts +++ b/src/classes/BambuMQTT.ts @@ -45,6 +45,14 @@ export default class BambuMQTT extends EventEmitter { this.client.on("message", this.onMessage.bind(this)); } + /** + * Disconnect from the printer. + */ + async disconnect() { + this.client.removeAllListeners(); + this.client.end(); + } + /** * Send a request to the device. * @param payload - The payload to send to the device. diff --git a/src/classes/BambuPrinter.ts b/src/classes/BambuPrinter.ts index 5279e8a..06ebd76 100644 --- a/src/classes/BambuPrinter.ts +++ b/src/classes/BambuPrinter.ts @@ -33,6 +33,15 @@ export default class BambuPrinter extends EventEmitter { async connect() { await this.mqtt.connect(); this.mqtt.on("update", this.onStateUpdate.bind(this)); + this.emit("disconnect"); + } + + /** + * Disconnect from the printer. + */ + async disconnect() { + await this.mqtt.disconnect(); + this.emit("connect"); } /** From e2c930359ac1ee6485552ef640aeef86f752b278 Mon Sep 17 00:00:00 2001 From: AndrewLemons Date: Wed, 13 Mar 2024 11:00:43 -0400 Subject: [PATCH 2/5] Add stop method --- src/classes/BambuPrinter.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/classes/BambuPrinter.ts b/src/classes/BambuPrinter.ts index 06ebd76..553985e 100644 --- a/src/classes/BambuPrinter.ts +++ b/src/classes/BambuPrinter.ts @@ -82,6 +82,21 @@ export default class BambuPrinter extends EventEmitter { this.mqtt.sendRequest(data); } + /** + * Stop the current print job. + */ + stop() { + let data = { + print: { + sequence_id: "0", + command: "stop", + param: "", + }, + }; + + this.mqtt.sendRequest(data); + } + /** * Set the state of the printer's LED. * @param options - Options for setting the LED state. From 107dc4ab9620391227340a51bfebf950a011139f Mon Sep 17 00:00:00 2001 From: AndrewLemons Date: Wed, 13 Mar 2024 11:03:12 -0400 Subject: [PATCH 3/5] Improve connection status event handling --- src/classes/BambuMQTT.ts | 6 +++++- src/classes/BambuPrinter.ts | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/classes/BambuMQTT.ts b/src/classes/BambuMQTT.ts index 4252a54..a504835 100644 --- a/src/classes/BambuMQTT.ts +++ b/src/classes/BambuMQTT.ts @@ -6,6 +6,8 @@ const MQTT_USERNAME = "bblp"; /** * A class for interfacing with a Bambu Lab printers over MQTT. * @emits update - Emitted when the printer's state is updated. + * @emits connect - Emitted when the printer is connected. + * @emits disconnect - Emitted when the printer is disconnected. */ export default class BambuMQTT extends EventEmitter { host: string; @@ -73,13 +75,15 @@ export default class BambuMQTT extends EventEmitter { // Request the printer's complete state this.sendRequest({ pushing: { sequence_id: "0", command: "pushall" } }); + + this.emit("connect"); } /** * Handle the disconnect event. */ private onDisconnect() { - return; + this.emit("disconnect"); } /** diff --git a/src/classes/BambuPrinter.ts b/src/classes/BambuPrinter.ts index 553985e..0090d8d 100644 --- a/src/classes/BambuPrinter.ts +++ b/src/classes/BambuPrinter.ts @@ -7,6 +7,8 @@ import BambuState from "../interfaces/BambuState"; /** * A class for interfacing with a Bambu Lab printer. * @emits update - Emitted when the printer's state is updated. + * @emits connect - Emitted when the printer is connected. + * @emits disconnect - Emitted when the printer is disconnected. */ export default class BambuPrinter extends EventEmitter { host: string; @@ -33,7 +35,8 @@ export default class BambuPrinter extends EventEmitter { async connect() { await this.mqtt.connect(); this.mqtt.on("update", this.onStateUpdate.bind(this)); - this.emit("disconnect"); + this.mqtt.on("disconnect", () => this.emit("disconnect")); + this.mqtt.on("connect", () => this.emit("connect")); } /** @@ -41,7 +44,6 @@ export default class BambuPrinter extends EventEmitter { */ async disconnect() { await this.mqtt.disconnect(); - this.emit("connect"); } /** From dd21db6b9a7e8044fe3c8b7ae1f89b6c55e36b56 Mon Sep 17 00:00:00 2001 From: AndrewLemons Date: Wed, 13 Mar 2024 11:11:21 -0400 Subject: [PATCH 4/5] Add overload errors --- src/utilities/hms.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utilities/hms.ts b/src/utilities/hms.ts index 73fdbbf..9e901b7 100644 --- a/src/utilities/hms.ts +++ b/src/utilities/hms.ts @@ -96,6 +96,11 @@ export const errorCodes = { "0700210000020004": "AMS slot 2 filament may be broken in the toolhead.", "0700220000020004": "AMS slot 3 filament may be broken in the toolhead.", "0700230000020004": "AMS slot 4 filament may be broken in the toolhead.", + // Overload + "0700600000020001": "AMS slot 1 is overloaded. The filament may be tangled or the spool may be stuck.", + "0700610000020001": "AMS slot 2 is overloaded. The filament may be tangled or the spool may be stuck.", + "0700620000020001": "AMS slot 3 is overloaded. The filament may be tangled or the spool may be stuck.", + "0700630000020001": "AMS slot 4 is overloaded. The filament may be tangled or the spool may be stuck.", // Generic "0700010000010001": "The AMS assist motor has slipped.The extrusion wheel may be worn down,or the filament may be too thin.", "0700010000010003": "The AMS assist motor torque control is malfunctioning.The current sensor may be faulty.", @@ -115,7 +120,6 @@ export const errorCodes = { "0700450000020002": "The filament cutter's cutting distance is too large.The XY motor may lose steps.", "0700450000020003": "The filament cutter handle has not released.The handle or blade ay be stuck.", "0700510000030001": "The AMS is disabled; please load filament from spool holder.", - "0700600000020001": "The AMS1 slot1 is overloaded. The filament may be tangled or the spool may be stuck.", /* Other */ From bb86d50e7dd0969c27edc004e844ab84fb0cd4f1 Mon Sep 17 00:00:00 2001 From: AndrewLemons Date: Wed, 13 Mar 2024 11:13:20 -0400 Subject: [PATCH 5/5] v1.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a853de9..e730e69 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bambu-js", - "version": "1.2.0", + "version": "1.3.0", "description": "Tools to interact with Bambu Lab printers over MQTT and FTP.", "main": "dist/index.js", "types": "dist/index.d.ts",