Implementing effects. Closes #2 #19

Merged
osiu97 merged 8 commits from effects into main 2026-07-08 21:47:35 +02:00
Showing only changes of commit b866ae9d4d - Show all commits
+17 -6
View File
@@ -34,9 +34,20 @@ export const MotionEffects = {
let delay = 0; let delay = 0;
let newHasHesitated = hasHesitated; let newHasHesitated = hasHesitated;
if (target.mode === 'hesitant' && target.fraction >= 0.45 && !hasHesitated) { if (target.mode === 'hesitant') {
delay = 800; // Noticeably pause if (target.fraction >= 0.4 && hasHesitated === false) {
newHasHesitated = true; // Slow down massively instead of stopping
if (BLE.isConnected()) {
try { await BLE.write(`SPD:${Math.floor(Math.max(50, Settings.speed * 0.2))}`); } catch(e){}
}
newHasHesitated = true; // Started hesitation
} else if (target.fraction >= 0.7 && hasHesitated === true) {
// Speed back up
if (BLE.isConnected()) {
try { await BLE.write(`SPD:${Settings.speed}`); } catch(e){}
}
newHasHesitated = 2; // Finished hesitation
}
} else if (target.mode === 'overshoot_settle') { } else if (target.mode === 'overshoot_settle') {
delay = 200; // Brief pause before returning delay = 200; // Brief pause before returning
if (BLE.isConnected()) { if (BLE.isConnected()) {
@@ -48,9 +59,7 @@ export const MotionEffects = {
// Called to determine blending behaviour during queue checks // Called to determine blending behaviour during queue checks
getQueueAction(mode, maxDist, blendThreshold) { getQueueAction(mode, maxDist, blendThreshold) {
if (mode === 'erratic') { if (mode === 'jumpy') {
if (maxDist <= 5) return { action: 'wait', delay: 100 };
} else if (mode === 'jumpy') {
if (maxDist <= 5) return { action: 'wait', delay: 100 }; if (maxDist <= 5) return { action: 'wait', delay: 100 };
} else { } else {
if (maxDist <= blendThreshold) return { action: 'blend' }; if (maxDist <= blendThreshold) return { action: 'blend' };
@@ -82,6 +91,8 @@ export const MotionEffects = {
count = Math.max(count, Math.ceil(distance / 10)); // fine resolution for sine count = Math.max(count, Math.ceil(distance / 10)); // fine resolution for sine
} else if (mode === 'erratic') { } else if (mode === 'erratic') {
count = Math.max(count, Math.ceil(distance / 20)); // fewer, larger jumps count = Math.max(count, Math.ceil(distance / 20)); // fewer, larger jumps
} else if (mode === 'hesitant') {
count = Math.max(count, Math.ceil(distance / 15)); // ensure we get middle waypoints for speed changes
} }
return Math.max(1, count); return Math.max(1, count);
}, },