Enhance printer panels to handle offline state more effectively
- Added an `offline` prop to PrinterTemperaturePanel, PrinterMiscPanel, and PrinterPositionPanel components to manage state when printers are offline. - Implemented useEffect hooks in each panel to reset relevant data when offline, ensuring accurate display of printer status. - Updated ControlPrinter component to pass the `offline` state based on the printer's online status, improving user experience during offline scenarios.
This commit is contained in:
parent
f3d6bebc38
commit
e52798d4ac
@ -182,6 +182,7 @@ const ControlPrinter = ({ slicerIntegration = false }) => {
|
|||||||
>
|
>
|
||||||
<PrinterTemperaturePanel
|
<PrinterTemperaturePanel
|
||||||
id={printerId}
|
id={printerId}
|
||||||
|
offline={!objectFormState.objectData?.online}
|
||||||
disabled={
|
disabled={
|
||||||
!objectFormState.objectData?.online || objectFormState.loading
|
!objectFormState.objectData?.online || objectFormState.loading
|
||||||
}
|
}
|
||||||
@ -243,6 +244,7 @@ const ControlPrinter = ({ slicerIntegration = false }) => {
|
|||||||
>
|
>
|
||||||
<PrinterMiscPanel
|
<PrinterMiscPanel
|
||||||
id={printerId}
|
id={printerId}
|
||||||
|
offline={!objectFormState.objectData?.online}
|
||||||
disabled={
|
disabled={
|
||||||
!objectFormState.objectData?.online || objectFormState.loading
|
!objectFormState.objectData?.online || objectFormState.loading
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,12 @@ import merge from 'lodash/merge'
|
|||||||
|
|
||||||
const { Text } = Typography
|
const { Text } = Typography
|
||||||
|
|
||||||
const PrinterMiscPanel = ({ id, showControls = true, disabled = false }) => {
|
const PrinterMiscPanel = ({
|
||||||
|
id,
|
||||||
|
showControls = true,
|
||||||
|
disabled = false,
|
||||||
|
offline = true
|
||||||
|
}) => {
|
||||||
const { subscribeToObjectEvent, connected, sendObjectAction } =
|
const { subscribeToObjectEvent, connected, sendObjectAction } =
|
||||||
useContext(ApiServerContext)
|
useContext(ApiServerContext)
|
||||||
const controlsDisabled = disabled || !connected
|
const controlsDisabled = disabled || !connected
|
||||||
@ -35,6 +40,18 @@ const PrinterMiscPanel = ({ id, showControls = true, disabled = false }) => {
|
|||||||
const [lcdBrightness, setLcdBrightness] = useState(0)
|
const [lcdBrightness, setLcdBrightness] = useState(0)
|
||||||
const [beeperValue, setBeeperValue] = useState(0)
|
const [beeperValue, setBeeperValue] = useState(0)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (offline) {
|
||||||
|
setMiscData({
|
||||||
|
fan: { speed: 0, target: 0 },
|
||||||
|
lcdBacklight: { brightness: 0 },
|
||||||
|
beeper: { value: 0 },
|
||||||
|
filamentSensor: { enabled: false, filamentDetected: false },
|
||||||
|
coolingFan: { speed: 0 }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [offline])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (id && connected == true) {
|
if (id && connected == true) {
|
||||||
const miscEventUnsubscribe = subscribeToObjectEvent(
|
const miscEventUnsubscribe = subscribeToObjectEvent(
|
||||||
@ -193,7 +210,8 @@ const PrinterMiscPanel = ({ id, showControls = true, disabled = false }) => {
|
|||||||
PrinterMiscPanel.propTypes = {
|
PrinterMiscPanel.propTypes = {
|
||||||
id: PropTypes.string.isRequired,
|
id: PropTypes.string.isRequired,
|
||||||
showControls: PropTypes.bool,
|
showControls: PropTypes.bool,
|
||||||
disabled: PropTypes.bool
|
disabled: PropTypes.bool,
|
||||||
|
offline: PropTypes.bool
|
||||||
}
|
}
|
||||||
|
|
||||||
export default PrinterMiscPanel
|
export default PrinterMiscPanel
|
||||||
|
|||||||
@ -34,7 +34,8 @@ const PrinterPositionPanel = ({
|
|||||||
id,
|
id,
|
||||||
showControls = true,
|
showControls = true,
|
||||||
showMoreInfo = true,
|
showMoreInfo = true,
|
||||||
disabled = false
|
disabled = false,
|
||||||
|
offline = true
|
||||||
}) => {
|
}) => {
|
||||||
const { subscribeToObjectEvent, connected, sendObjectAction } =
|
const { subscribeToObjectEvent, connected, sendObjectAction } =
|
||||||
useContext(ApiServerContext)
|
useContext(ApiServerContext)
|
||||||
@ -55,6 +56,26 @@ const PrinterPositionPanel = ({
|
|||||||
minCruiseRatio: 0
|
minCruiseRatio: 0
|
||||||
})
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (offline) {
|
||||||
|
setPositionData({
|
||||||
|
speedFactor: 1.0,
|
||||||
|
speed: 100,
|
||||||
|
extrudeFactor: 1.0,
|
||||||
|
absoluteCoordinates: true,
|
||||||
|
absoluteExtrude: false,
|
||||||
|
homingOrigin: [0.0, 0.0, 0.0, 0.0],
|
||||||
|
toolheadPosition: [0.0, 0.0, 0.0, 0.0],
|
||||||
|
gcodePosition: [0.0, 0.0, 0.0, 0.0],
|
||||||
|
livePosition: [0.0, 0.0, 0.0, 0.0],
|
||||||
|
maxVelocity: 1000,
|
||||||
|
maxAcceleration: 1000,
|
||||||
|
squareCornerVelocity: 100,
|
||||||
|
minCruiseRatio: 0
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [offline])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (id && connected == true) {
|
if (id && connected == true) {
|
||||||
const motionEventUnsubscribe = subscribeToObjectEvent(
|
const motionEventUnsubscribe = subscribeToObjectEvent(
|
||||||
@ -73,6 +94,7 @@ const PrinterPositionPanel = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [id, connected, subscribeToObjectEvent])
|
}, [id, connected, subscribeToObjectEvent])
|
||||||
|
|
||||||
const [speedFactor, setSpeedFactor] = useState(positionData.speedFactor)
|
const [speedFactor, setSpeedFactor] = useState(positionData.speedFactor)
|
||||||
const [extrudeFactor, setExtrudeFactor] = useState(positionData.extrudeFactor)
|
const [extrudeFactor, setExtrudeFactor] = useState(positionData.extrudeFactor)
|
||||||
const [maxVelocity, setMaxVelocity] = useState(positionData.maxVelocity)
|
const [maxVelocity, setMaxVelocity] = useState(positionData.maxVelocity)
|
||||||
@ -509,7 +531,8 @@ PrinterPositionPanel.propTypes = {
|
|||||||
id: PropTypes.string.isRequired,
|
id: PropTypes.string.isRequired,
|
||||||
showControls: PropTypes.bool,
|
showControls: PropTypes.bool,
|
||||||
showMoreInfo: PropTypes.bool,
|
showMoreInfo: PropTypes.bool,
|
||||||
disabled: PropTypes.bool
|
disabled: PropTypes.bool,
|
||||||
|
offline: PropTypes.bool
|
||||||
}
|
}
|
||||||
|
|
||||||
export default PrinterPositionPanel
|
export default PrinterPositionPanel
|
||||||
|
|||||||
@ -38,7 +38,8 @@ const PrinterTemperaturePanel = ({
|
|||||||
showExtruder = true,
|
showExtruder = true,
|
||||||
showBed = true,
|
showBed = true,
|
||||||
showMoreInfo = true,
|
showMoreInfo = true,
|
||||||
disabled = false
|
disabled = false,
|
||||||
|
offline = true
|
||||||
}) => {
|
}) => {
|
||||||
const [temperatureData, setTemperatureData] = useState({
|
const [temperatureData, setTemperatureData] = useState({
|
||||||
extruder: {
|
extruder: {
|
||||||
@ -55,6 +56,17 @@ const PrinterTemperaturePanel = ({
|
|||||||
ambiant: 0
|
ambiant: 0
|
||||||
})
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (offline) {
|
||||||
|
setTemperatureData({
|
||||||
|
extruder: { current: 0, target: 0, power: 0 },
|
||||||
|
bed: { current: 0, target: 0, power: 0 },
|
||||||
|
pinda: 0,
|
||||||
|
ambiant: 0
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [offline])
|
||||||
|
|
||||||
const { subscribeToObjectEvent, connected, sendObjectAction } =
|
const { subscribeToObjectEvent, connected, sendObjectAction } =
|
||||||
useContext(ApiServerContext)
|
useContext(ApiServerContext)
|
||||||
const controlsDisabled = disabled || !connected
|
const controlsDisabled = disabled || !connected
|
||||||
@ -309,7 +321,8 @@ PrinterTemperaturePanel.propTypes = {
|
|||||||
showBed: PropTypes.bool,
|
showBed: PropTypes.bool,
|
||||||
showMoreInfo: PropTypes.bool,
|
showMoreInfo: PropTypes.bool,
|
||||||
shouldUnsubscribe: PropTypes.bool,
|
shouldUnsubscribe: PropTypes.bool,
|
||||||
disabled: PropTypes.bool
|
disabled: PropTypes.bool,
|
||||||
|
offline: PropTypes.bool
|
||||||
}
|
}
|
||||||
|
|
||||||
export default PrinterTemperaturePanel
|
export default PrinterTemperaturePanel
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user