feat: add SET_PRINT_STATS_INFO command support (#1034)

This commit is contained in:
Stefan Dej 2022-10-08 18:37:25 +02:00 committed by GitHub
parent d5cafaaa06
commit 57bb268ea0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 25 deletions

View File

@ -189,34 +189,11 @@ export default class StatusPanelPrintstatusPrinting extends Mixins(BaseMixin) {
}
get max_layers() {
if (
'first_layer_height' in this.current_file &&
'layer_height' in this.current_file &&
'object_height' in this.current_file
) {
const max = Math.ceil(
(this.current_file.object_height - this.current_file.first_layer_height) /
this.current_file.layer_height +
1
)
return max > 0 ? max : 0
}
return 0
return this.$store.getters['printer/getPrintMaxLayers'] ?? 0
}
get current_layer() {
if (this.print_time > 0 && 'first_layer_height' in this.current_file && 'layer_height' in this.current_file) {
const gcodePositionZ = this.$store.state.printer.gcode_move?.gcode_position[2] ?? 0
let current_layer = Math.ceil(
(gcodePositionZ - this.current_file.first_layer_height) / this.current_file.layer_height + 1
)
current_layer = current_layer <= this.max_layers ? current_layer : this.max_layers
return current_layer > 0 ? current_layer : 0
}
return 0
return this.$store.getters['printer/getPrintCurrentLayer'] ?? 0
}
get estimated_time_file() {

View File

@ -96,6 +96,48 @@ export const getters: GetterTree<PrinterState, RootState> = {
return state.virtual_sdcard?.progress ?? 0
},
getPrintMaxLayers: (state) => {
if (state.print_stats?.info?.total_layer !== null) {
return state.print_stats.info.total_layer
} else if (state.current_file?.layer_count) {
return state.current_file.layer_count
} else if (
'current_file' in state &&
'first_layer_height' in state.current_file &&
'layer_height' in state.current_file &&
'object_height' in state.current_file
) {
const max = Math.ceil(
(state.current_file.object_height - state.current_file.first_layer_height) /
state.current_file.layer_height +
1
)
return max > 0 ? max : 0
}
return 0
},
getPrintCurrentLayer: (state, getters) => {
if (state.print_stats?.info?.current_layer !== null) {
return state.print_stats.info.current_layer
} else if (
state.print_stats?.print_duration > 0 &&
'first_layer_height' in state.current_file &&
'layer_height' in state.current_file
) {
const gcodePositionZ = state.gcode_move?.gcode_position[2] ?? 0
const current_layer = Math.ceil(
(gcodePositionZ - state.current_file.first_layer_height) / state.current_file.layer_height + 1
)
if (current_layer > getters.getPrintMaxLayers) return getters.getPrintMaxLayers
if (current_layer > 0) return current_layer
}
return 0
},
getMacros: (state) => {
const array: PrinterStateMacro[] = []
const config = state.configfile?.config ?? {}