Skip to content

Commit

Permalink
feat: add SET_PRINT_STATS_INFO command support (#1034)
Browse files Browse the repository at this point in the history
  • Loading branch information
meteyou authored Oct 8, 2022
1 parent d5cafaa commit 57bb268
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 25 deletions.
27 changes: 2 additions & 25 deletions src/components/panels/Status/PrintstatusPrinting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
42 changes: 42 additions & 0 deletions src/store/printer/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? {}
Expand Down

0 comments on commit 57bb268

Please sign in to comment.