mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 01:21:20 -04:00
overcurrent fix?
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -11,7 +11,7 @@
|
|||||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
||||||
<meta name="apple-mobile-web-app-title" content="Multi Roomba Rover" />
|
<meta name="apple-mobile-web-app-title" content="Multi Roomba Rover" />
|
||||||
<title>Multi Roomba Rover</title>
|
<title>Multi Roomba Rover</title>
|
||||||
<script type="module" crossorigin src="/assets/index-cxDsY4fK.js"></script>
|
<script type="module" crossorigin src="/assets/index-CdNFroGb.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="/assets/index-gFnxuq00.css">
|
<link rel="stylesheet" crossorigin href="/assets/index-gFnxuq00.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ export function useOvercurrentLimiter(roverId, options = {}) {
|
|||||||
[options.config],
|
[options.config],
|
||||||
);
|
);
|
||||||
const [caps, setCaps] = useState(() => createInitialCaps());
|
const [caps, setCaps] = useState(() => createInitialCaps());
|
||||||
const lastTickRef = useRef(typeof performance !== 'undefined' ? performance.now() : Date.now());
|
const lastTickRef = useRef(0);
|
||||||
const flagsRef = useRef(overcurrentFlags);
|
const flagsRef = useRef(overcurrentFlags);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -45,6 +45,7 @@ export function useOvercurrentLimiter(roverId, options = {}) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setCaps(createInitialCaps());
|
setCaps(createInitialCaps());
|
||||||
|
lastTickRef.current = 0;
|
||||||
}, [roverId]);
|
}, [roverId]);
|
||||||
|
|
||||||
const hasAnyOvercurrent = useMemo(
|
const hasAnyOvercurrent = useMemo(
|
||||||
@@ -59,11 +60,12 @@ export function useOvercurrentLimiter(roverId, options = {}) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!shouldTick) return undefined;
|
if (!shouldTick) return undefined;
|
||||||
|
lastTickRef.current = typeof performance !== 'undefined' ? performance.now() : Date.now();
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
const now = typeof performance !== 'undefined' ? performance.now() : Date.now();
|
const now = typeof performance !== 'undefined' ? performance.now() : Date.now();
|
||||||
const deltaMs = Math.max(0, now - lastTickRef.current);
|
const deltaMs = Math.max(0, now - lastTickRef.current);
|
||||||
lastTickRef.current = now;
|
lastTickRef.current = now;
|
||||||
const deltaSec = deltaMs / 1000;
|
const deltaSec = Math.min(0.25, deltaMs / 1000);
|
||||||
if (deltaSec <= 0) return;
|
if (deltaSec <= 0) return;
|
||||||
setCaps((prev) => {
|
setCaps((prev) => {
|
||||||
let changed = false;
|
let changed = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user