Skip to content

Commit

Permalink
feat: add monitors (like TMC2240) to Temperature Panel (#1532)
Browse files Browse the repository at this point in the history
  • Loading branch information
meteyou authored Oct 6, 2023
1 parent 7d86df0 commit 5734f1c
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 20 deletions.
20 changes: 16 additions & 4 deletions src/components/charts/TempChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -313,15 +313,23 @@ export default class TempChart extends Mixins(BaseMixin) {
const seriesNameTemperature = `${baseSeriesName}-temperature`
const seriesNameTarget = `${baseSeriesName}-target`
if (seriesNameTemperature in dataset.value) output += dataset.value[seriesNameTemperature].toFixed(1)
if (seriesNameTarget in dataset.value) output += ' / ' + dataset.value[seriesNameTarget].toFixed(1)
if (seriesNameTemperature in dataset.value) {
const value = dataset.value[seriesNameTemperature]
output += value !== null ? value.toFixed(1) : '--'
}
if (seriesNameTarget in dataset.value) {
output += ' / '
const value = dataset.value[seriesNameTemperature]
output += value !== null ? value.toFixed(1) : '--'
}
output += '°C'
datasetTypesInPercents.forEach((attrKey) => {
const seriesName = `${baseSeriesName}-${attrKey}`
if (!(seriesName in dataset.value)) return
const value = (dataset.value[seriesName] * 100).toFixed(0)
let value = dataset.value[seriesName]
value = value !== null ? (dataset.value[seriesName] * 100).toFixed(0) : '--'
output += ` [ ${value}% ]`
})
Expand Down Expand Up @@ -356,7 +364,11 @@ export default class TempChart extends Mixins(BaseMixin) {
// reset tempHistory if working sources are smaller than 80%
if (newVal.length > 0 && newSource.length < this.maxHistory * 0.8) {
this.$socket.emit('server.temperature_store', {}, { action: 'printer/tempHistory/init' })
this.$socket.emit(
'server.temperature_store',
{ include_monitors: true },
{ action: 'printer/tempHistory/init' }
)
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/components/panels/Temperature/TemperaturePanelList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
:key="objectName"
:object-name="objectName"
:is-responsive-mobile="el.is.mobile ?? false" />
<template v-if="!hideMonitors">
<temperature-panel-list-item
v-for="objectName in monitors"
:key="objectName"
:object-name="objectName"
:is-responsive-mobile="el.is.mobile ?? false" />
</template>
</tbody>
</v-simple-table>
</template>
Expand Down Expand Up @@ -70,6 +77,14 @@ export default class TemperaturePanelList extends Mixins(BaseMixin) {
return this.$store.state.printer?.heaters?.available_sensors ?? []
}
get available_monitors() {
return this.$store.state.printer?.heaters?.available_monitors ?? []
}
get monitors() {
return this.available_monitors.sort(this.sortObjectName)
}
get temperature_fans() {
return this.available_sensors
.filter((name: string) => name.startsWith('temperature_fan') && !name.startsWith('temperature_fan _'))
Expand All @@ -84,6 +99,10 @@ export default class TemperaturePanelList extends Mixins(BaseMixin) {
return this.$store.state.gui.view.tempchart.hideMcuHostSensors ?? false
}
get hideMonitors(): boolean {
return this.$store.state.gui.view.tempchart.hideMonitors ?? false
}
get temperature_sensors() {
return this.available_sensors
.filter((fullName: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import { convertName } from '@/plugins/helpers'
import {
mdiFan,
mdiFire,
mdiMemory,
mdiPrinter3dNozzle,
mdiPrinter3dNozzleAlert,
mdiRadiator,
Expand Down Expand Up @@ -131,14 +132,17 @@ export default class TemperaturePanelListItem extends Mixins(BaseMixin) {
// show heater_generic icon
if (this.objectName.startsWith('heater_generic')) return mdiFire
// show heater_generic icon
if (this.objectName.startsWith('tmc')) return mdiMemory
// show fan icon, if it is a fan
if (this.isFan) return mdiFan
return mdiThermometer
}
get color() {
return this.$store.getters['printer/tempHistory/getDatasetColor'](this.objectName) ?? ''
return this.$store.getters['printer/tempHistory/getDatasetColor'](this.objectName) ?? '#FFFFFF'
}
get iconColor() {
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 @@ -20,6 +20,13 @@
hide-details
:label="$t('Panels.TemperaturePanel.HideMcuHostSensors')" />
</v-list-item>
<v-list-item class="minHeight36">
<v-checkbox
v-model="hideMonitors"
class="mt-0"
hide-details
:label="$t('Panels.TemperaturePanel.HideMonitors')" />
</v-list-item>
<v-list-item class="minHeight36">
<v-checkbox
v-model="autoscaleTempchart"
Expand Down Expand Up @@ -64,5 +71,13 @@ export default class TemperaturePanelSettings extends Mixins(BaseMixin) {
set hideMcuHostSensors(newVal: boolean) {
this.$store.dispatch('gui/saveSetting', { name: 'view.tempchart.hideMcuHostSensors', value: newVal })
}
get hideMonitors(): boolean {
return this.$store.state.gui.view.tempchart.hideMonitors ?? false
}
set hideMonitors(newVal: boolean) {
this.$store.dispatch('gui/saveSetting', { name: 'view.tempchart.hideMonitors', value: newVal })
}
}
</script>
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@
},
"Headline": "Temperatures",
"HideMcuHostSensors": "Hide Host/MCU Sensors",
"HideMonitors": "Hide Monitors",
"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 @@ -239,6 +239,7 @@ export const getDefaultState = (): GuiState => {
boolTempchart: true,
hiddenDataset: [],
hideMcuHostSensors: false,
hideMonitors: 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 @@ -165,6 +165,7 @@ export interface GuiState {
boolTempchart: boolean
hiddenDataset: string[]
hideMcuHostSensors: boolean
hideMonitors: boolean
autoscale: boolean
datasetSettings: any
}
Expand Down
9 changes: 7 additions & 2 deletions src/store/printer/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ export const actions: ActionTree<PrinterState, RootState> = {

if (Object.keys(subscripts).length > 0)
Vue.$socket.emit('printer.objects.subscribe', { objects: subscripts }, { action: 'printer/getInitData' })
else Vue.$socket.emit('server.temperature_store', {}, { action: 'printer/tempHistory/init' })
else
Vue.$socket.emit(
'server.temperature_store',
{ include_monitors: true },
{ action: 'printer/tempHistory/init' }
)

dispatch('socket/removeInitModule', 'printer/initSubscripts', { root: true })
},
Expand All @@ -70,7 +75,7 @@ export const actions: ActionTree<PrinterState, RootState> = {

dispatch('getData', payload)

Vue.$socket.emit('server.temperature_store', {}, { action: 'printer/tempHistory/init' })
Vue.$socket.emit('server.temperature_store', { include_monitors: true }, { action: 'printer/tempHistory/init' })

setTimeout(() => {
dispatch('initExtruderCanExtrude')
Expand Down
4 changes: 4 additions & 0 deletions src/store/printer/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ export const getters: GetterTree<PrinterState, RootState> = {
return state.heaters?.available_sensors ?? []
},

getAvailableMonitors: (state) => {
return state.heaters?.available_monitors ?? []
},

getFilamentSensors: (state) => {
const sensorObjectNames = ['filament_switch_sensor', 'filament_motion_sensor']
const sensors: PrinterStateFilamentSensors[] = []
Expand Down
29 changes: 18 additions & 11 deletions src/store/printer/tempHistory/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const actions: ActionTree<PrinterTempHistoryState, RootState> = {
const now = new Date()
const allHeaters = rootGetters['printer/getAvailableHeaters'] ?? []
const allSensors = rootGetters['printer/getAvailableSensors'] ?? []
const allMonitors = rootGetters['printer/getAvailableMonitors'] ?? []
const maxHistory = rootGetters['printer/tempHistory/getTemperatureStoreSize']

if (payload !== undefined) {
Expand All @@ -44,7 +45,7 @@ export const actions: ActionTree<PrinterTempHistoryState, RootState> = {
}

// break if sensor doesn't exist anymore or start with a _
if (!allSensors.includes(key) || nameOnly.startsWith('_')) {
if (!(allSensors.includes(key) || allMonitors.includes(key)) || nameOnly.startsWith('_')) {
delete payload[key]
return
}
Expand All @@ -54,7 +55,7 @@ export const actions: ActionTree<PrinterTempHistoryState, RootState> = {
if (datasetKey + 's' in datasetValues) {
const length = maxHistory - datasetValues[datasetKey + 's'].length
datasetValues[datasetKey + 's'] = [
...Array.from({ length }, () => 0),
...Array.from({ length }, () => null),
...datasetValues[datasetKey + 's'],
]
}
Expand All @@ -64,7 +65,8 @@ export const actions: ActionTree<PrinterTempHistoryState, RootState> = {
})

// add missing heaters/sensors
allSensors.forEach((key: string) => {
const allEntries = allSensors.concat(allMonitors)
allEntries.forEach((key: string) => {
// break if sensor is already in the cache
if (key in payload) return

Expand All @@ -85,15 +87,15 @@ export const actions: ActionTree<PrinterTempHistoryState, RootState> = {
powers?: number[]
speeds?: number[]
} = {
temperatures: Array(maxHistory).fill(0),
temperatures: Array(maxHistory).fill(null),
}

if (allHeaters.includes(key)) {
addValues.targets = Array(maxHistory).fill(0)
addValues.powers = Array(maxHistory).fill(0)
addValues.targets = Array(maxHistory).fill(null)
addValues.powers = Array(maxHistory).fill(null)
} else if (['temperature_fan'].includes(sensorType)) {
addValues.targets = Array(maxHistory).fill(0)
addValues.speeds = Array(maxHistory).fill(0)
addValues.targets = Array(maxHistory).fill(null)
addValues.speeds = Array(maxHistory).fill(null)
}

importData[key] = { ...addValues }
Expand Down Expand Up @@ -239,7 +241,11 @@ export const actions: ActionTree<PrinterTempHistoryState, RootState> = {
window.console.debug('update Source', t0-state.timeLastUpdate)
}*/

if (rootState?.printer?.heaters?.available_sensors?.length) {
const allSensors = rootGetters['printer/getAvailableSensors'] ?? []
const allMonitors = rootGetters['printer/getAvailableMonitors'] ?? []
const items = allSensors.concat(allMonitors)

if (items.length) {
const now = new Date()

if (state.source.length) {
Expand All @@ -255,14 +261,15 @@ export const actions: ActionTree<PrinterTempHistoryState, RootState> = {
date: now,
}

rootState.printer.heaters.available_sensors.forEach((name: string) => {
items.forEach((name: string) => {
if (!(rootState.printer && name in rootState.printer)) return
const printerObject = { ...rootState.printer[name] }

datasetTypes.forEach((attrKey) => {
if (!(attrKey in printerObject)) return

let value = Math.round(printerObject[attrKey] * 10) / 10
let value = printerObject[attrKey]
if (value !== null) value = Math.round(printerObject[attrKey] * 10) / 10
if (datasetTypesInPercents.includes(attrKey))
value = Math.round(printerObject[attrKey] * 1000) / 1000

Expand Down
15 changes: 15 additions & 0 deletions src/store/printer/tempHistory/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,21 @@ export const getters: GetterTree<PrinterTempHistoryState, RootState> = {
})
}

// hide Monitors, if the option is set to true
const hideMonitors = rootState.gui?.view?.tempchart?.hideMonitors ?? false
if (hideMonitors) {
const monitors = rootState.printer?.heaters?.available_monitors ?? []

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

return selected
},

Expand Down
4 changes: 2 additions & 2 deletions src/store/variables.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const defaultLogoColor = '#D41216'
export const defaultPrimaryColor = '#2196f3'

export const minKlipperVersion = 'v0.11.0-97'
export const minMoonrakerVersion = 'v0.8.0-38'
export const minKlipperVersion = 'v0.11.0-257'
export const minMoonrakerVersion = 'v0.8.0-137'
export const minBrowserVersions = [{ name: 'safari', version: '16.5.2' }]

export const colorArray = ['#F44336', '#8e379d', '#03DAC5', '#3F51B5', '#ffde03', '#009688', '#E91E63']
Expand Down

0 comments on commit 5734f1c

Please sign in to comment.