Skip to content

Commit

Permalink
Merge pull request #6 from AndrewLemons/dev
Browse files Browse the repository at this point in the history
v1.3.0
  • Loading branch information
AndrewLemons authored Mar 13, 2024
2 parents ec9856b + bb86d50 commit e11318b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
14 changes: 13 additions & 1 deletion src/classes/BambuMQTT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -45,6 +47,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.
Expand All @@ -65,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");
}

/**
Expand Down
26 changes: 26 additions & 0 deletions src/classes/BambuPrinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,6 +35,15 @@ export default class BambuPrinter extends EventEmitter {
async connect() {
await this.mqtt.connect();
this.mqtt.on("update", this.onStateUpdate.bind(this));
this.mqtt.on("disconnect", () => this.emit("disconnect"));
this.mqtt.on("connect", () => this.emit("connect"));
}

/**
* Disconnect from the printer.
*/
async disconnect() {
await this.mqtt.disconnect();
}

/**
Expand Down Expand Up @@ -73,6 +84,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.
Expand Down
6 changes: 5 additions & 1 deletion src/utilities/hms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -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
*/
Expand Down

0 comments on commit e11318b

Please sign in to comment.