Added current_input_speed state to test the calculation of buffer_lift_speed

This commit is contained in:
snacj committed 2025-10-01 12:27:15 +02:00
1 parent 1eeb3f8190
commit b4ee86a88c
4 files changed
+54 -1

No files matched your search

@@ -5,9 +5,13 @@ import React from "react";
import { useBuffer1 } from "./useBuffer1";
import { ControlCard } from "@/control/ControlCard";
import { SelectionGroup } from "@/control/SelectionGroup";
import { EditValue } from "@/control/EditValue";
export function Buffer1ControlPage() {
const { state, setBufferMode } = useBuffer1();
const { state, setBufferMode, setCurrentInputSpeed } = useBuffer1();
const current_input_speed = state?.current_input_speed_state.current_input_speed ?? 0.0;
const default_speed = 0.0;
return (
<Page>
@@ -40,6 +44,19 @@ export function Buffer1ControlPage() {
onChange={setBufferMode}
/>
</ControlCard>
<ControlCard title="Set Current Input Speed">
<EditValue
title="Input Speed"
unit="m/min"
value={current_input_speed}
defaultValue={default_speed}
min={0.0}
max={60.0}
step={0.1}
renderValue={(value) => value.toFixed(0.0)}
onChange={setCurrentInputSpeed}
/>
</ControlCard>
</ControlGrid>
</Page>
);
@@ -41,6 +41,10 @@ export const modeStateSchema = z.object({
mode: modeSchema,
});
export const currentInputSpeedSchema = z.object({
current_input_speed: z.number(),
})
/**
* Connected machine state scheme
*/
@@ -66,6 +70,7 @@ export const connectedMachineStateSchema = z.object({
export const stateEventDataSchema = z.object({
mode_state: modeStateSchema,
connected_machine_state: connectedMachineStateSchema,
current_input_speed_state: currentInputSpeedSchema,
});
// ========== Event Schemas with Wrappers ==========
@@ -122,6 +122,19 @@ export function useBuffer1() {
);
};
const setCurrentInputSpeed = (current_input_speed: number) => {
updateStateOptimistically(
(current) => {
current.data.current_input_speed_state.current_input_speed = current_input_speed;
},
() =>
requestSetCurrentInputSpeed({
machine_identification_unique,
data: { SetCurrentInputSpeed: current_input_speed},
}),
);
};
// Mutation hooks
const { request: requestBufferMode } = useMachineMutation(
z.object({
@@ -141,6 +154,12 @@ export function useBuffer1() {
}),
);
const { request: requestSetCurrentInputSpeed } = useMachineMutation(
z.object({
SetCurrentInputSpeed: z.number()
})
);
// General Helper functions
const machines = useMachines();
// Filter machines for the correct type
@@ -182,5 +201,6 @@ export function useBuffer1() {
setBufferMode,
setConnectedMachine,
disconnectMachine,
setCurrentInputSpeed,
};
}
+11
View File
@@ -32,6 +32,8 @@ pub struct StateEvent {
pub mode_state: ModeState,
/// connected machine state
pub connected_machine_state: ConnectedMachineState,
/// CurrentInputSpeed
pub current_input_speed_state: CurrentInputSpeedState,
}
impl StateEvent {
@@ -64,6 +66,11 @@ pub struct ConnectedMachineState {
pub is_available: bool,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct CurrentInputSpeedState {
pub current_input_speed: f64,
}
#[derive(Deserialize, Serialize)]
enum Mutation {
// Mode
@@ -74,6 +81,9 @@ enum Mutation {
// Disconnect Machine
DisconnectMachine(MachineIdentificationUnique),
// Set current input speed
SetCurrentInputSpeed(f64),
}
#[derive(Debug)]
@@ -128,6 +138,7 @@ impl MachineApi for BufferV1 {
Mutation::DisconnectMachine(machine_identification_unique) => {
self.disconnect_winder(machine_identification_unique);
}
Mutation::SetCurrentInputSpeed(speed) => self.set_current_input_speed(speed),
}
Ok(())
}