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 option to hide MCU & Host sensors in the temperature panel #1496

Merged
merged 2 commits into from
Aug 7, 2023
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
18 changes: 18 additions & 0 deletions src/components/panels/Temperature/TemperaturePanelList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,19 @@ export default class TemperaturePanelList extends Mixins(BaseMixin) {
.sort(this.sortObjectName)
}

get hideMcuHostSensors(): boolean {
return this.$store.state.gui.view.tempchart.hideMcuHostSensors ?? false
}

get temperature_sensors() {
return this.available_sensors
.filter((fullName: string) => {
if (this.available_heaters.includes(fullName)) return false
if (this.temperature_fans.includes(fullName)) return false

// hide MCU & Host sensors, if the function is enabled
if (this.hideMcuHostSensors && this.checkMcuHostSensor(fullName)) return false

const splits = fullName.split(' ')
let name = splits[0]
if (splits.length > 1) name = splits[1]
Expand All @@ -84,6 +91,17 @@ export default class TemperaturePanelList extends Mixins(BaseMixin) {
return [...this.filteredHeaters, ...this.temperature_fans, ...this.temperature_sensors]
}

get settings() {
return this.$store.state.printer?.configfile?.settings ?? {}
}

checkMcuHostSensor(fullName: string) {
const settingsObject = this.settings[fullName.toLowerCase()] ?? {}
const sensor_type = settingsObject.sensor_type ?? ''

return ['temperature_mcu', 'temperature_host'].includes(sensor_type)
}

sortObjectName(a: string, b: string) {
const splitsA = a.split(' ')
let nameA = splitsA[0]
Expand Down
15 changes: 15 additions & 0 deletions src/components/panels/Temperature/TemperaturePanelSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
hide-details
:label="$t('Panels.TemperaturePanel.ShowChart')" />
</v-list-item>
<v-list-item class="minHeight36">
<v-checkbox
v-model="hideMcuHostSensors"
class="mt-0"
hide-details
:label="$t('Panels.TemperaturePanel.HideMcuHostSensors')" />
</v-list-item>
<v-list-item class="minHeight36">
<v-checkbox
v-model="autoscaleTempchart"
Expand Down Expand Up @@ -49,5 +56,13 @@ export default class TemperaturePanelSettings extends Mixins(BaseMixin) {
set autoscaleTempchart(newVal: boolean) {
this.$store.dispatch('gui/saveSetting', { name: 'view.tempchart.autoscale', value: newVal })
}

get hideMcuHostSensors(): boolean {
return this.$store.state.gui.view.tempchart.hideMcuHostSensors ?? false
}

set hideMcuHostSensors(newVal: boolean) {
this.$store.dispatch('gui/saveSetting', { name: 'view.tempchart.hideMcuHostSensors', value: newVal })
}
}
</script>
1 change: 1 addition & 0 deletions src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@
"Temperature": "Aktuelle Temperatur"
},
"Headline": "Temperaturen",
"HideMcuHostSensors": "Host/MCU Sensoren ausblenden",
"Max": "max",
"Min": "min",
"Name": "Name",
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@
"Temperature": "current temperature"
},
"Headline": "Temperatures",
"HideMcuHostSensors": "Hide Host/MCU Sensors",
"Max": "max",
"Min": "min",
"Name": "Name",
Expand Down
1 change: 1 addition & 0 deletions src/store/gui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ export const getDefaultState = (): GuiState => {
tempchart: {
boolTempchart: true,
hiddenDataset: [],
hideMcuHostSensors: false,
autoscale: false,
datasetSettings: {},
},
Expand Down
1 change: 1 addition & 0 deletions src/store/gui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export interface GuiState {
tempchart: {
boolTempchart: boolean
hiddenDataset: string[]
hideMcuHostSensors: boolean
autoscale: boolean
datasetSettings: any
}
Expand Down
39 changes: 38 additions & 1 deletion src/store/printer/tempHistory/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,29 @@ export const getters: GetterTree<PrinterTempHistoryState, RootState> = {
return getters['getAvg'](name, 'speed')
},

getSelectedLegends: (state, _, rootState) => {
getHostMcuSensors: (state, getters, rootState) => {
const settings = rootState.printer?.configfile?.settings ?? {}
const available_heaters = rootState.printer?.heaters?.available_heaters ?? []
const available_sensors = rootState.printer?.heaters?.available_sensors ?? []

return available_sensors.filter((fullName: string) => {
// stop when the current sensor is a heater
if (available_heaters.includes(fullName)) return false
// stop when the current sensor is a temperature_fan
if (fullName.startsWith('temperature_fan')) return false

// get printer settings object from the current sensor
const settingsObject = settings[fullName.toLowerCase()]
if (!settingsObject) return false

// get the sensor type of the current sensor
const sensor_type = settingsObject.sensor_type ?? ''

return ['temperature_mcu', 'temperature_host'].includes(sensor_type)
})
},

getSelectedLegends: (state, getters, rootState) => {
interface legends {
[key: string]: boolean
}
Expand Down Expand Up @@ -108,6 +130,21 @@ export const getters: GetterTree<PrinterTempHistoryState, RootState> = {
selected[serie.name] = !datasetTypesInPercents.includes(datasetType)
})

// hide MCU & Host sensors, if the option is set to true
const hideMcuHostSensors = rootState.gui?.view?.tempchart?.hideMcuHostSensors ?? false
if (hideMcuHostSensors) {
const mcuHostSensors = getters.getHostMcuSensors ?? []

Object.keys(selected)
.filter((seriesName) => {
const datasetName = seriesName.slice(0, seriesName.lastIndexOf('-'))
return mcuHostSensors.includes(datasetName)
})
.forEach((seriesName) => {
selected[seriesName] = false
})
}

return selected
},

Expand Down