Add gcode position tracking and virtual SD card status handling in PrinterClient
All checks were successful
farmcontrol/farmcontrol-server/pipeline/head This commit looks good
All checks were successful
farmcontrol/farmcontrol-server/pipeline/head This commit looks good
- Introduced gcodePositionObject to track the printer's G-code position and related status. - Enhanced status handling to include virtual SD card information, such as file position, size, and progress. - Updated event emission to include gcodePosition updates, improving real-time feedback for printer status. - Refactored existing status handling logic to accommodate new data structures and ensure consistency.
This commit is contained in:
parent
2522e2f9ce
commit
bf9ce2da9b
@ -41,6 +41,7 @@ export class PrinterClient {
|
|||||||
this.currentSubJob = printer.currentSubJob;
|
this.currentSubJob = printer.currentSubJob;
|
||||||
this.temperatureObject = {};
|
this.temperatureObject = {};
|
||||||
this.motionObject = {};
|
this.motionObject = {};
|
||||||
|
this.gcodePositionObject = {};
|
||||||
this.miscObject = {};
|
this.miscObject = {};
|
||||||
this.currentFilamentStock = printer.currentFilamentStock;
|
this.currentFilamentStock = printer.currentFilamentStock;
|
||||||
this.currentFilament = null;
|
this.currentFilament = null;
|
||||||
@ -59,6 +60,7 @@ export class PrinterClient {
|
|||||||
gcode_move: null,
|
gcode_move: null,
|
||||||
toolhead: null,
|
toolhead: null,
|
||||||
motion_report: null,
|
motion_report: null,
|
||||||
|
virtual_sdcard: null,
|
||||||
"heater_fan nozzle_cooling_fan": null,
|
"heater_fan nozzle_cooling_fan": null,
|
||||||
fan: null,
|
fan: null,
|
||||||
"output_pin BEEPER_pin": null,
|
"output_pin BEEPER_pin": null,
|
||||||
@ -667,6 +669,43 @@ export class PrinterClient {
|
|||||||
_.merge(this.motionObject, {
|
_.merge(this.motionObject, {
|
||||||
gcodePosition: status.gcode_move.position,
|
gcodePosition: status.gcode_move.position,
|
||||||
});
|
});
|
||||||
|
_.merge(this.gcodePositionObject, {
|
||||||
|
position: status.gcode_move.position,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status.virtual_sdcard) {
|
||||||
|
const virtualSdcard = status.virtual_sdcard;
|
||||||
|
const gcodePositionPatch = {};
|
||||||
|
if (virtualSdcard.file_position !== undefined) {
|
||||||
|
gcodePositionPatch.filePosition = virtualSdcard.file_position;
|
||||||
|
}
|
||||||
|
if (virtualSdcard.file_size !== undefined) {
|
||||||
|
gcodePositionPatch.fileSize = virtualSdcard.file_size;
|
||||||
|
}
|
||||||
|
if (virtualSdcard.progress !== undefined) {
|
||||||
|
gcodePositionPatch.progress = virtualSdcard.progress;
|
||||||
|
}
|
||||||
|
if (virtualSdcard.is_active !== undefined) {
|
||||||
|
gcodePositionPatch.isActive = virtualSdcard.is_active;
|
||||||
|
}
|
||||||
|
if (Object.keys(gcodePositionPatch).length > 0) {
|
||||||
|
_.merge(this.gcodePositionObject, gcodePositionPatch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status.print_stats?.info != null) {
|
||||||
|
const info = status.print_stats.info;
|
||||||
|
const layerPatch = {};
|
||||||
|
if (info.current_layer !== undefined) {
|
||||||
|
layerPatch.currentLayer = info.current_layer;
|
||||||
|
}
|
||||||
|
if (info.total_layer !== undefined) {
|
||||||
|
layerPatch.totalLayer = info.total_layer;
|
||||||
|
}
|
||||||
|
if (Object.keys(layerPatch).length > 0) {
|
||||||
|
_.merge(this.gcodePositionObject, layerPatch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status.gcode_move?.speed !== undefined) {
|
if (status.gcode_move?.speed !== undefined) {
|
||||||
@ -897,6 +936,12 @@ export class PrinterClient {
|
|||||||
eventType: "motion",
|
eventType: "motion",
|
||||||
eventData: this.motionObject,
|
eventData: this.motionObject,
|
||||||
});
|
});
|
||||||
|
this.socketClient.objectEvent({
|
||||||
|
objectType: "printer",
|
||||||
|
_id: this.id,
|
||||||
|
eventType: "gcodePosition",
|
||||||
|
eventData: this.gcodePositionObject,
|
||||||
|
});
|
||||||
this.socketClient.objectEvent({
|
this.socketClient.objectEvent({
|
||||||
objectType: "printer",
|
objectType: "printer",
|
||||||
_id: this.id,
|
_id: this.id,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user