Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add SET_PRINT_STATS_INFO command support #1034

Merged
merged 7 commits into from
Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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