feat: Implement motion sway effects and enhance face sliding based on roll angle

This commit is contained in:
Joshua King
2026-02-22 20:40:27 -05:00
parent 9decccdce5
commit 16b9471107
3 changed files with 34 additions and 2 deletions

View File

@@ -81,6 +81,23 @@ static uint8_t luxToContrast(float lux) {
return (uint8_t)value;
}
static int8_t motionSwayOffsetX(unsigned long nowMs) {
// 8-step loop for a clear side-to-side motion while the accelerometer reports movement.
static const int8_t kSway[] = {-8, -4, 0, 4, 8, 4, 0, -4};
const size_t steps = sizeof(kSway) / sizeof(kSway[0]);
size_t idx = (nowMs / 90UL) % steps;
return kSway[idx];
}
static int8_t rollToFaceSlideX(float rollDeg) {
// Map tilt to a larger screen slide so the face visibly shifts toward the tilted side.
float clamped = clampFloat(rollDeg, -35.0f, 35.0f);
int v = (int)lroundf((clamped / 35.0f) * 24.0f); // -24..+24 px
if (v < -24) v = -24;
if (v > 24) v = 24;
return (int8_t)v;
}
static void initRestartButton() {
pinMode(PIN_RESTART_BUTTON, INPUT_PULLUP);
bool raw = digitalRead(PIN_RESTART_BUTTON);
@@ -332,11 +349,13 @@ void App::loop() {
motion.loop();
if (motion.available()) {
face.setTiltEffects(0, 0); // disable old motion-based eye deformation
face.setFaceSlideX(motion.eyeOffsetX()); // roll -> slide whole face left/right
int8_t slideX = rollToFaceSlideX(motion.rollDeg()); // stronger roll -> face slide
(void)motion.consumePickupEvent(); // consume pickup events so they don't accumulate
if (motion.isMoving()) {
motionWakeUntilMs = millis() + MOTION_WAKE_MS;
slideX = motionSwayOffsetX(millis());
}
face.setFaceSlideX(slideX);
} else {
face.setTiltEffects(0, 0);
face.setFaceSlideX(0);