Skip to content

Commit c9b94ea

Browse files
committed
feat: Kalico temperature chart override when mcu disconnected
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
1 parent 608b8c8 commit c9b94ea

8 files changed

Lines changed: 100 additions & 27 deletions

File tree

‎src/components/widgets/system/McuInformationDialog.vue‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<app-dialog
33
v-model="open"
4-
:title="$t('app.system_info.label.mcu_information', { mcu: mcu.name })"
4+
:title="$t('app.system_info.label.mcu_information', { mcu: mcu.prettyName })"
55
max-width="500"
66
no-actions
77
>

‎src/components/widgets/system/McuLoadChart.vue‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default class McuLoadChart extends Vue {
4141
readonly mcu!: MCU
4242
4343
get chartData () {
44-
return this.$typedState.charts[this.mcu.name] || []
44+
return this.$typedState.charts[this.mcu.key] || []
4545
}
4646
4747
get options () {

‎src/store/chart_helpers.ts‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Commit } from 'vuex'
22
import type { RootState } from './types'
33
import type { ChartData } from './charts/types'
44
import type { KlipperPrinterMcuState, KlipperPrinterState, KlipperPrinterSystemStatsState } from './printer/types'
5+
import getMcusFromConfig from '@/util/get-klipper-mcus-from-config'
56

67
export const handleMcuStatsChange = (payload: Partial<KlipperPrinterState>, state: RootState, commit: Commit) => {
78
for (const key in payload) {
@@ -118,17 +119,31 @@ export const handleSystemStatsChange = (payload: Partial<KlipperPrinterState>, s
118119
* Every packet should contain an entry for all known sensors we want to track.
119120
*/
120121
export const handleAddChartEntry = (retention: number, state: RootState, commit: Commit, getters: any) => {
122+
const nonCriticalDisconnectedMcuNames = new Set(
123+
getters.getNonCriticalDisconnectedMcuNames as string[])
124+
121125
const configureChartEntry = () => {
122126
const chartData: ChartData = {
123127
date: new Date()
124128
}
125129

126130
const keys: string[] = getters.getChartableSensors
127131

128-
keys.forEach((key) => {
132+
for (const key of keys) {
129133
const sensor = state.printer.printer[key]
130134

131135
if (sensor != null) {
136+
if (nonCriticalDisconnectedMcuNames.size > 0) {
137+
const config = state.printer.printer.configfile?.settings[key.toLowerCase()]
138+
139+
if (
140+
config != null &&
141+
getMcusFromConfig(config)?.some(mcu => nonCriticalDisconnectedMcuNames.has(mcu))
142+
) {
143+
continue
144+
}
145+
}
146+
132147
const temp = sensor.temperature
133148
const target = sensor.target
134149
const power = sensor.power
@@ -138,7 +153,7 @@ export const handleAddChartEntry = (retention: number, state: RootState, commit:
138153
if (power != null) chartData[`${key}#power`] = power
139154
if (speed != null) chartData[`${key}#speed`] = speed
140155
}
141-
})
156+
}
142157

143158
return chartData
144159
}

‎src/store/helpers.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ export const handleTrinamicDriversChange = (payload: Partial<KlipperPrinterState
1616
state.printer.printer?.[item]?.drv_status?.otpw == null &&
1717
state.config.uiSettings.warnings.warnOnStepperDriverOverheating
1818
) {
19-
const [, nameFromSplit] = item.split(' ', 2)
20-
const name = nameFromSplit ?? item
19+
const name = item.split(' ', 2).pop() || ''
2120

2221
const klippyApp: KlippyApp = getters.getKlippyApp
2322

‎src/store/printer/getters.ts‎

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { GetterTree } from 'vuex'
33
import type { RootState } from '../types'
44
import type { PrinterState, Heater, Fan, Led, OutputPin, Sensor, RunoutSensor, KnownExtruder, MCU, Endstop, ExtruderStepper, Extruder, Stepper, ScrewsTiltAdjustScrew, ScrewsTiltAdjust, BedScrews, BedSize, GcodeCommands, TimeEstimates, KlippyApp, ExcludeObjectPart, KlipperPrinterConfig, BeaconModel, BedScrewsScrew, ExtruderKey, Probe } from './types'
55
import getKlipperType from '@/util/get-klipper-type'
6+
import getMcusFromConfig from '@/util/get-klipper-mcus-from-config'
67
import i18n from '@/plugins/i18n'
78
import type { GcodeHelp } from '../console/types'
89
import { Globals } from '@/globals'
@@ -334,9 +335,12 @@ export const getters = {
334335
for (const key of mcuKeys) {
335336
const config = state.printer.configfile.settings[key.toLowerCase()]
336337

338+
const name = key.split(' ', 2).pop() || ''
339+
337340
mcus.push({
338-
name: key,
341+
name,
339342
prettyName: Vue.$filters.prettyCase(key),
343+
key,
340344
...state.printer[key],
341345
config,
342346
})
@@ -345,6 +349,20 @@ export const getters = {
345349
return mcus
346350
},
347351

352+
getNonCriticalDisconnectedMcuNames: (state, getters): string[] => {
353+
const klippyApp: KlippyApp = getters.getKlippyApp
354+
355+
if (!klippyApp.isKalico) {
356+
return []
357+
}
358+
359+
const mcus: MCU[] = getters.getMcus
360+
361+
return mcus
362+
.filter(mcu => mcu.non_critical_disconnected)
363+
.map(mcu => mcu.name)
364+
},
365+
348366
getHasExtruder: (state) => {
349367
return state.printer.extruder != null
350368
},
@@ -745,7 +763,8 @@ export const getters = {
745763
* Return available temperature probes / sensors.
746764
*/
747765
getSensors: (state, getters): Sensor[] => {
748-
const klippyApp: KlippyApp = getters.getKlippyApp
766+
const nonCriticalDisconnectedMcuNames = new Set(
767+
getters.getNonCriticalDisconnectedMcuNames as string[])
749768

750769
const sensors = Object.keys(state.printer)
751770
.filter(key => (
@@ -771,27 +790,13 @@ export const getters = {
771790
const color = Vue.$colorset.next(getKlipperType(key), key)
772791
const config = state.printer.configfile.settings[key.toLowerCase()]
773792

774-
const mcu = (
775-
klippyApp.isKalico &&
793+
const mcus = (
794+
nonCriticalDisconnectedMcuNames.size > 0 &&
776795
config != null &&
777-
(
778-
(
779-
'i2c_mcu' in config &&
780-
config.i2c_mcu
781-
) ||
782-
(
783-
'sensor_mcu' in config &&
784-
config.sensor_mcu
785-
) ||
786-
(
787-
'sensor_pin' in config &&
788-
config.sensor_pin?.includes(':') &&
789-
config.sensor_pin.split(':')[0]
790-
)
791-
)
796+
getMcusFromConfig(config)
792797
)
793798

794-
const kalicoTemperatureOverride = mcu && mcu !== 'mcu' && state.printer[`mcu ${mcu}`]?.non_critical_disconnected
799+
const kalicoTemperatureOverride = mcus && mcus.some(mcu => nonCriticalDisconnectedMcuNames.has(mcu))
795800
? {
796801
temperature: null
797802
}

‎src/store/printer/types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,7 @@ export interface Stepper extends StepperType<KlipperPrinterExtruderSettings | Kl
14411441
export interface MCU extends KlipperPrinterMcuState {
14421442
name: string;
14431443
prettyName: string;
1444+
key: string;
14441445
config?: KlipperPrinterMcuSettings;
14451446
}
14461447

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const mcuKeys = [
2+
'i2c_mcu',
3+
'sensor_mcu',
4+
]
5+
6+
const getMcusFromMcuKeyInConfig = (config: Record<string, any>): string[] | undefined => {
7+
for (const key of mcuKeys) {
8+
if (key in config) {
9+
const value = config[key]
10+
11+
if (
12+
typeof value === 'string' &&
13+
value
14+
) {
15+
return [value]
16+
}
17+
}
18+
}
19+
}
20+
21+
const getMcusFromPinKeyInConfig = (config: Record<string, any>): string[] | undefined => {
22+
const mcus = new Set<string>()
23+
24+
const pinKeys = Object.keys(config)
25+
.filter(key => (
26+
key === 'pin' ||
27+
key.endsWith('_pin')
28+
))
29+
30+
for (const key of pinKeys) {
31+
const value = config[key]
32+
33+
if (
34+
typeof value === 'string' &&
35+
value.includes(':')
36+
) {
37+
const mcu = value.split(':')[0]
38+
39+
if (mcu) {
40+
mcus.add(mcu)
41+
}
42+
}
43+
}
44+
45+
return [...mcus]
46+
}
47+
48+
const getMcusFromConfig = (config: Record<string, any>): string[] | undefined => (
49+
getMcusFromMcuKeyInConfig(config) ||
50+
getMcusFromPinKeyInConfig(config)
51+
)
52+
53+
export default getMcusFromConfig

‎src/views/System.vue‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<template v-for="mcu in mcus">
2121
<mcu-card
22-
:key="mcu.name"
22+
:key="mcu.key"
2323
:mcu="mcu"
2424
class="mb-2 mb-md-4"
2525
/>

0 commit comments

Comments
 (0)