Skip to content

Add continuous automatic display orientation #64

Description

@PurpleSentinel

Parent: #23

Summary

Extend the four fixed mounting orientations delivered by #33 with a new Auto option. Auto orientation should use the onboard QMI8658 accelerometer's gravity vector to keep the display upright and directional gestures intuitive as the device is rotated, updating without a restart or a visit back to Settings.

User experience

  • Add Auto to the existing Settings → Rotation choices alongside 0°, 90°, 180°, and 270°.
  • Preview Auto immediately. The preview should show both Auto and the currently detected quarter-turn orientation so the user can verify it before saving.
  • Swipe up to save Auto; swipe down to cancel and restore the prior manual or automatic setting.
  • When Auto is saved, startup splashes and subsequent screens should adopt the detected upright orientation as soon as a reliable gravity reading is available.
  • Continue updating while the application is running, including Ready, configuration, Timer, rest, Launch, G Mode, menus, and error screens. An orientation change must not reset, pause, or otherwise alter an active session.
  • Change touch-direction mapping at the same time as the display, so prompts remain relative to the text currently shown.
  • Keep all existing fixed-angle choices and their behavior unchanged.

Functional behavior

Detection

  • Use filtered QMI8658 acceleration rather than touch coordinates or elapsed motion.
  • Project gravity onto the display plane and classify only the four supported quarter-turn orientations.
  • Apply dominance thresholds, hysteresis, and a short stability period before changing orientation so road vibration, acceleration, and positions close to a 45° boundary do not cause rapid flipping.
  • Redraw the current framebuffer after a confirmed change; do not allocate a second 240×240 framebuffer.
  • Do not write each detected angle to flash. Persist only that the user's selection is Auto, retaining the detected angle in RAM.
  • When the display is too close to horizontal for gravity to reveal rotation about the screen normal, retain the last reliable angle. This is a physical accelerometer limitation, not an error.

Configuration and compatibility

  • Persist Auto in the canonical user configuration while continuing to accept existing integer DISPLAY_ROTATION_DEG values.
  • Existing user.json files and all fixed-angle selections must load without change.
  • Restore Defaults should continue to select fixed 0° rotation.
  • Auto must cause the IMU to initialize even when Launch Mode is disabled, while sharing the existing QMI8658 instance with Launch Mode and G Mode.

Degraded behavior

  • If the QMI8658 is unavailable at startup, keep Timer Mode usable and retain a safe fixed orientation rather than repeatedly changing the screen.
  • The Auto preview must clearly report that automatic detection is unavailable and allow cancel/back navigation.
  • If sampling fails after startup, freeze at the last reliable angle, log/show an actionable degraded-state message at an appropriate safe point, and preserve normal timing.
  • A missing IMU must not break existing manual rotation choices.

Hardware, safety, and compatibility

  • Target the supported Waveshare RP2040-Touch-LCD-1.28 and its onboard QMI8658, GC9A01A, and CST816S.
  • Keep orientation polling bounded and responsive without increasing framebuffer memory use or materially delaying touch/session loops.
  • Coordinate IMU access with Launch and G Mode so there are no duplicate sensor objects or conflicting reads.
  • Never interrupt or restart an active track/rest session solely because orientation changes or automatic sensing degrades.
  • Verify the native-axis/sign mapping on physical hardware at all four quarter turns.

Acceptance criteria

  • Rotation Settings offers Auto plus all four existing fixed angles.
  • Auto preview reports the live detected angle and supports save/cancel safely.
  • Auto persists across restart without replacing the setting with a detected integer angle.
  • The screen redraws upright and touch directions remain intuitive after each stable quarter-turn change.
  • Detection uses hysteresis/stability filtering and does not oscillate at boundaries or under short acceleration spikes.
  • A near-horizontal device retains its last reliable orientation.
  • Active track/rest timing continues uninterrupted through orientation changes.
  • Existing fixed rotation, Launch Mode, G Mode, brightness, restore-default, and configuration behavior remain compatible.
  • Missing or failing IMU behavior is safe, actionable, and does not block Timer Mode or manual rotation.
  • Host tests cover four-way detection, filtering, hysteresis, stability, flat-device retention, persistence/migration, preview/save/cancel, degraded IMU behavior, gesture mapping, and circular layout.
  • The complete suite passes and Auto is exercised on the supported physical device at all four quarter turns.

Documentation

  • Update README and User Guide with Auto selection, live behavior, the near-horizontal limitation, degraded behavior, and the required deployment module list.

Relationship

This is a follow-up enhancement to #33 and the v4.1.0 fixed-orientation release. It remains part of roadmap epic #23.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NewFeatureCandidate product capability for future development

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions