-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto flush & Performance improvements (#525)
- Loading branch information
Showing
13 changed files
with
340 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ enum class OperationMode { | |
FLUSH = 2, | ||
DESCALE = 3, | ||
STEAM = 4, | ||
FLUSH_AUTO = 5, | ||
}; | ||
|
||
struct SystemState { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
webserver/web-interface/src/components/gauges/PressureGauge.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import { useTheme } from '@mui/material'; | ||
import useSensorStateStore from '../../state/SensorStateStore'; | ||
import GaugeChart from '../chart/GaugeChart'; | ||
|
||
export default function PressureGauge() { | ||
const theme = useTheme(); | ||
const pressure = useSensorStateStore((state) => state.sensorState.pressure); | ||
|
||
return ( | ||
<GaugeChart | ||
value={pressure} | ||
primaryColor={theme.palette.pressure.main} | ||
title="Pressure" | ||
unit="bar" | ||
maxValue={14} | ||
/> | ||
); | ||
} |
19 changes: 19 additions & 0 deletions
19
webserver/web-interface/src/components/gauges/TemperatureGauge.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import { useTheme } from '@mui/material'; | ||
import useSensorStateStore from '../../state/SensorStateStore'; | ||
import GaugeChart from '../chart/GaugeChart'; | ||
|
||
export default function TemperatureGauge({ targetTemperature }: { targetTemperature: number}) { | ||
const theme = useTheme(); | ||
const temperature = useSensorStateStore((state) => state.sensorState.waterTemperature); | ||
|
||
return ( | ||
<GaugeChart | ||
value={temperature} | ||
primaryColor={theme.palette.temperature.main} | ||
maxValue={targetTemperature} | ||
flashAfterValue={120} | ||
unit="°C" | ||
/> | ||
); | ||
} |
9 changes: 9 additions & 0 deletions
9
webserver/web-interface/src/components/gauges/WaterLevelGauge.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react'; | ||
import GaugeLiquid from '../chart/GaugeLiquid'; | ||
import useSensorStateStore from '../../state/SensorStateStore'; | ||
|
||
export default function WaterLevelGauge() { | ||
const waterLevel = useSensorStateStore((state) => state.sensorState.waterLevel); | ||
|
||
return <GaugeLiquid value={waterLevel} />; | ||
} |
151 changes: 151 additions & 0 deletions
151
webserver/web-interface/src/components/inputs/SwitchLedButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import React, { ReactNode, useCallback, useState } from 'react'; | ||
import { | ||
Box, ButtonBase, alpha, useTheme, | ||
} from '@mui/material'; | ||
import AspectRatioBox from '../layout/AspectRatioBox'; | ||
|
||
const LED_COLOR_ON = '#ef4e2b'; | ||
const GLOW_ON = alpha(LED_COLOR_ON, 0.5); | ||
const LED_COLOR_AUTO = '#00b9ff'; | ||
const GLOW_AUTO = alpha(LED_COLOR_AUTO, 0.5); | ||
const LED_COLOR_OFF = '#822714'; | ||
const SWITCH_BACKGROUND_ON = 'linear-gradient(to top, rgba(127, 127, 127, 0.1) 0%, rgba(0, 0, 0, 0.1) 100%)'; | ||
const SWITCH_BACKGROUND_OFF = 'linear-gradient(to top, rgba(255, 255, 255, 0.1) 0%, rgba(80, 80, 80, 0.1) 100%)'; | ||
const SWITCH_SHADOW = '0px 1px 2px -1px rgba(0,0,0,0.2), 0px 3px 3px 0px rgba(0,0,0,0.14), 0px 1px 5px 0px rgba(0,0,0,0.12)'; | ||
|
||
export enum SwitchLedState { | ||
ON, | ||
AUTO, | ||
OFF | ||
} | ||
|
||
export interface SwitchLedButtonProps { | ||
state: SwitchLedState; | ||
icon?: ReactNode; | ||
label?: ReactNode; | ||
supportsAuto?: boolean; | ||
longPressDuration?: number; | ||
onChange?: (state: SwitchLedState) => void; | ||
} | ||
|
||
function stateToLedColor(state:SwitchLedState) { | ||
if (state === SwitchLedState.ON) return LED_COLOR_ON; | ||
if (state === SwitchLedState.AUTO) return LED_COLOR_AUTO; | ||
return LED_COLOR_OFF; | ||
} | ||
|
||
function stateToGlowColor(state:SwitchLedState) { | ||
if (state === SwitchLedState.ON) return GLOW_ON; | ||
if (state === SwitchLedState.AUTO) return GLOW_AUTO; | ||
return ''; | ||
} | ||
|
||
export function SwitchLedButton({ | ||
state, | ||
icon = undefined, | ||
label = undefined, | ||
supportsAuto = false, | ||
longPressDuration = 1500, | ||
onChange = undefined, | ||
}: SwitchLedButtonProps) { | ||
const theme = useTheme(); | ||
const background = (state === SwitchLedState.OFF) ? SWITCH_BACKGROUND_OFF : SWITCH_BACKGROUND_ON; | ||
|
||
const [pressTimeoutId, setPressTimeoutId] = useState<NodeJS.Timeout | null>(null); | ||
const [longPressActive, setLongPressActive] = useState(false); | ||
|
||
const handleLongPress = useCallback(() => { | ||
if (!supportsAuto) return; | ||
if (state === SwitchLedState.AUTO) onChange?.(SwitchLedState.OFF); | ||
else onChange?.(SwitchLedState.AUTO); | ||
}, [state, onChange, supportsAuto]); | ||
|
||
const handleShortPress = useCallback(() => { | ||
if (state === SwitchLedState.OFF) onChange?.(SwitchLedState.ON); | ||
else onChange?.(SwitchLedState.OFF); | ||
}, [state, onChange]); | ||
|
||
const handlePressStart = useCallback((event: React.MouseEvent | React.TouchEvent) => { | ||
if (event.type === 'touchstart') { | ||
event.preventDefault(); | ||
} | ||
|
||
if (!supportsAuto) return; | ||
|
||
const id = setTimeout(() => { | ||
setLongPressActive(true); | ||
}, longPressDuration); | ||
setPressTimeoutId(id); | ||
}, [longPressDuration, supportsAuto]); | ||
|
||
const handlePressEnd = useCallback((event: React.MouseEvent | React.TouchEvent) => { | ||
if (event.type === 'touchend') { | ||
event.preventDefault(); | ||
} | ||
|
||
if (pressTimeoutId) { | ||
clearTimeout(pressTimeoutId); | ||
} | ||
if (longPressActive) { | ||
handleLongPress(); | ||
} else { | ||
handleShortPress(); | ||
} | ||
setLongPressActive(false); | ||
}, [pressTimeoutId, longPressActive, handleShortPress, handleLongPress]); | ||
|
||
return ( | ||
<Box sx={{ | ||
p: { xs: 0.5, sm: 1 }, | ||
borderRadius: theme.spacing(1), | ||
background: (theme.palette.mode === 'light') ? 'rgba(0, 0, 0, 0.4)' : 'rgba(25, 25, 25, 0.2)', | ||
width: '100%', | ||
maxWidth: '120px', | ||
border: `1px solid ${alpha(theme.palette.divider, 0.05)}`, | ||
boxShadow: SWITCH_SHADOW, | ||
}} | ||
> | ||
<AspectRatioBox ratio={1 / 1.4}> | ||
<ButtonBase | ||
sx={{ | ||
borderRadius: theme.spacing(1), | ||
boxShadow: SWITCH_SHADOW, | ||
background, | ||
border: `1px solid ${alpha(theme.palette.divider, 0.05)}`, | ||
':hover': { | ||
border: `1px solid ${alpha(theme.palette.divider, 0.2)}`, | ||
}, | ||
}} | ||
onMouseDown={handlePressStart} | ||
onMouseUp={handlePressEnd} | ||
onTouchStart={handlePressStart} | ||
onTouchEnd={handlePressEnd} | ||
> | ||
<Box sx={{ | ||
height: '100%', | ||
width: '100%', | ||
display: 'flex', | ||
flexDirection: 'column', | ||
justifyContent: 'space-around', | ||
alignItems: 'center', | ||
color: 'rgba(255, 255, 255, 0.8)', | ||
py: { xs: 1, sm: 2 }, | ||
}} | ||
> | ||
<Box sx={{ fontSize: { xs: theme.typography.body2.fontSize, sm: theme.typography.body1.fontSize } }}> | ||
{icon} | ||
</Box> | ||
<Box sx={{ overflowX: 'hidden', textOverflow: 'ellipsis', width: '100%' }}>{label}</Box> | ||
<Box sx={{ | ||
width: '15px', | ||
height: '10px', | ||
backgroundColor: stateToLedColor(state), | ||
boxShadow: state !== SwitchLedState.OFF ? `0 0 5px 3px ${stateToGlowColor(state)}` : '', | ||
}} | ||
/> | ||
</Box> | ||
</ButtonBase> | ||
</AspectRatioBox> | ||
</Box> | ||
); | ||
} |
Oops, something went wrong.