Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5e47a30a2c | ||
|
|
c675495c30 | ||
|
|
12749c1a1f | ||
|
|
57c94f891f | ||
|
|
d6911ed6f0 |
No files matched your search
@@ -50,12 +50,11 @@ export function useBuffer1() {
|
||||
// Single optimistic state for all state management
|
||||
const stateOptimistic = useStateOptimistic<StateEvent>();
|
||||
|
||||
// Update optimistic state when real state changes
|
||||
useEffect(() => {
|
||||
if (state && !stateOptimistic.isOptimistic) {
|
||||
if (state) {
|
||||
stateOptimistic.setReal(state);
|
||||
}
|
||||
}, [state, stateOptimistic]);
|
||||
}, [state]);
|
||||
|
||||
// Helper function for optimistic updates using produce
|
||||
const updateStateOptimistically = (
|
||||
@@ -63,7 +62,7 @@ export function useBuffer1() {
|
||||
serverRequest: () => void,
|
||||
) => {
|
||||
const currentState = stateOptimistic.value;
|
||||
if (currentState) {
|
||||
if (currentState && !stateOptimistic.isOptimistic) {
|
||||
stateOptimistic.setOptimistic(produce(currentState, producer));
|
||||
}
|
||||
serverRequest();
|
||||
|
||||
@@ -61,12 +61,11 @@ export function useExtruder2() {
|
||||
// Single optimistic state for all state management
|
||||
const stateOptimistic = useStateOptimistic<StateEvent>();
|
||||
|
||||
// Update optimistic state when real state changes
|
||||
useEffect(() => {
|
||||
if (state && !stateOptimistic.isOptimistic) {
|
||||
if (state) {
|
||||
stateOptimistic.setReal(state);
|
||||
}
|
||||
}, [state, stateOptimistic]);
|
||||
}, [state]);
|
||||
|
||||
// Helper function for optimistic updates using produce
|
||||
const updateStateOptimistically = (
|
||||
@@ -74,7 +73,7 @@ export function useExtruder2() {
|
||||
serverRequest: () => void,
|
||||
) => {
|
||||
const currentState = stateOptimistic.value;
|
||||
if (currentState) {
|
||||
if (currentState && !stateOptimistic.isOptimistic) {
|
||||
stateOptimistic.setOptimistic(produce(currentState, producer));
|
||||
}
|
||||
serverRequest();
|
||||
|
||||
@@ -18,12 +18,11 @@ function useLaser(machine_identification_unique: MachineIdentificationUnique) {
|
||||
// Single optimistic state for all state management
|
||||
const stateOptimistic = useStateOptimistic<StateEvent>();
|
||||
|
||||
// Update optimistic state when real state changes
|
||||
useEffect(() => {
|
||||
if (state && !stateOptimistic.isOptimistic) {
|
||||
if (state) {
|
||||
stateOptimistic.setReal(state);
|
||||
}
|
||||
}, [state, stateOptimistic]);
|
||||
}, [state]);
|
||||
|
||||
// Helper function for optimistic updates using produce
|
||||
const updateStateOptimistically = (
|
||||
@@ -31,7 +30,7 @@ function useLaser(machine_identification_unique: MachineIdentificationUnique) {
|
||||
serverRequest: () => void,
|
||||
) => {
|
||||
const currentState = stateOptimistic.value;
|
||||
if (currentState) {
|
||||
if (currentState && !stateOptimistic.isOptimistic) {
|
||||
stateOptimistic.setOptimistic(produce(currentState, producer));
|
||||
}
|
||||
serverRequest();
|
||||
|
||||
@@ -17,12 +17,11 @@ function useMock(machine_identification_unique: MachineIdentificationUnique) {
|
||||
// Single optimistic state for all state management
|
||||
const stateOptimistic = useStateOptimistic<StateEvent>();
|
||||
|
||||
// Update optimistic state when real state changes
|
||||
useEffect(() => {
|
||||
if (state && !stateOptimistic.isOptimistic) {
|
||||
if (state) {
|
||||
stateOptimistic.setReal(state);
|
||||
}
|
||||
}, [state, stateOptimistic]);
|
||||
}, [state]);
|
||||
|
||||
// Helper function for optimistic updates using produce
|
||||
const updateStateOptimistically = (
|
||||
@@ -30,7 +29,7 @@ function useMock(machine_identification_unique: MachineIdentificationUnique) {
|
||||
serverRequest: () => Promise<any>,
|
||||
) => {
|
||||
const currentState = stateOptimistic.value;
|
||||
if (currentState) {
|
||||
if (currentState && !stateOptimistic.isOptimistic) {
|
||||
stateOptimistic.setOptimistic(produce(currentState, producer));
|
||||
}
|
||||
serverRequest()
|
||||
|
||||
@@ -69,12 +69,12 @@ export function useWinder2() {
|
||||
// Single optimistic state for all state management
|
||||
const stateOptimistic = useStateOptimistic<StateEvent>();
|
||||
|
||||
// Update optimistic state when real state changes
|
||||
// Update optimistic state to real when real state changes
|
||||
useEffect(() => {
|
||||
if (state && !stateOptimistic.isOptimistic) {
|
||||
if (state) {
|
||||
stateOptimistic.setReal(state);
|
||||
}
|
||||
}, [state, stateOptimistic]);
|
||||
}, [state]);
|
||||
|
||||
// Request functions for all operations
|
||||
const { request: requestTraverseGotoLimitInner } = useMachineMutation(
|
||||
@@ -178,7 +178,7 @@ export function useWinder2() {
|
||||
serverRequest: () => void,
|
||||
) => {
|
||||
const currentState = stateOptimistic.value;
|
||||
if (currentState) {
|
||||
if (currentState && !stateOptimistic.isOptimistic) {
|
||||
stateOptimistic.setOptimistic(produce(currentState, producer));
|
||||
}
|
||||
serverRequest();
|
||||
|
||||
+19
-8
@@ -2,9 +2,11 @@ use crate::app_state::AppState;
|
||||
use crate::panic::{PanicDetails, send_panic};
|
||||
use bitvec::prelude::*;
|
||||
use control_core::realtime::{set_core_affinity, set_realtime_priority};
|
||||
use smol::Timer;
|
||||
use smol::channel::Sender;
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
use tokio::time::MissedTickBehavior;
|
||||
use tracing::{instrument, trace_span};
|
||||
|
||||
pub fn init_loop(
|
||||
@@ -35,14 +37,25 @@ pub fn init_loop(
|
||||
);
|
||||
}
|
||||
|
||||
loop {
|
||||
let res = smol::block_on(rt.run(async { loop_once(app_state.clone()).await }));
|
||||
smol::block_on(rt.run(async move {
|
||||
let tick_duration = Duration::from_millis(1);
|
||||
|
||||
if let Err(err) = res {
|
||||
tracing::error!("Loop failed\n{:?}", err);
|
||||
break;
|
||||
loop {
|
||||
let loop_start = Instant::now();
|
||||
|
||||
if let Err(err) = loop_once(app_state.clone()).await {
|
||||
tracing::error!("Loop failed: {:?}", err);
|
||||
break;
|
||||
}
|
||||
|
||||
// Sleep until next tick
|
||||
let elapsed = loop_start.elapsed();
|
||||
if elapsed < tick_duration {
|
||||
smol::Timer::after(tick_duration - elapsed).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
// Exit the entire program if the Loop fails (gets restarted by systemd if running on NixOS)
|
||||
std::process::exit(1);
|
||||
})
|
||||
@@ -127,8 +140,6 @@ pub async fn loop_once<'maindevice>(app_state: Arc<AppState>) -> Result<(), anyh
|
||||
))
|
||||
})?;
|
||||
}
|
||||
// Apparently 500 Microseconds is a safe starting point for ethercat
|
||||
smol::Timer::after(Duration::from_micros(500)).await;
|
||||
}
|
||||
|
||||
// execute machines
|
||||
|
||||
Reference in new issue
Block a user