Skip to content

Add configurable compass heading to rotate the radar display - #111

Open
nicolasluckie wants to merge 1 commit into
MatixYo:mainfrom
nicolasluckie:feat/compass-heading
Open

nicolasluckie wants to merge 1 commit into
MatixYo:mainfrom
nicolasluckie:feat/compass-heading

Conversation

@nicolasluckie

Copy link
Copy Markdown

Add configurable compass heading to rotate the radar display

e2447a3c-eec3-485a-b6f9-df18929c25b0
250°
c7ca220f-6d7b-4215-98a0-b3395b1be311
0 (Default)

What

Adds a "Compass heading the top of the display faces (deg, 0-359)" field to the Wi-Fi/LAN setup portal. The whole radar rotates so the map matches how the device is physically mounted:

  • N/E/S/W labels move around the bezel but stay upright
  • Crosshair spokes rotate to line up with the labels
  • Aircraft positions, nose/track vectors and off-screen rim dots rotate
  • Runway lines and airport labels rotate

0 (default) keeps north at the top, so behaviour is unchanged for existing users. 90 puts east at the top, 180 south, 270 west.

Why

The device is often placed where its top doesn't face north (desk, windowsill, wall mount). Today the map is always north-up, so planes appear on the wrong side of the display relative to the real sky. This lets the display match the room.

How

  • radar_range.{h,cpp}: new persisted headingDeg() (NVS key northDeg in the existing planeradar namespace), saveHeadingFromPortal(), rotateKmForHeading() and screenBearingDeg(). sin/cos are cached when the heading changes. Input wraps modulo 360, and invalid input keeps the previous value. The heading is reset by the existing 3 s BOOT wipe (unitsReset()).
  • radar_display.cpp / runway_overlay.cpp: the rotation is applied once, in offsetKmFromCenter(), so aircraft, rim dots, runways and airport labels all follow. Aircraft nose/track angles use screenBearingDeg().
  • radar_display.cpp: crosshairs and cardinal labels are placed by angle. Each label is positioned from its measured width/height so it stays inside the round bezel at any angle.
  • wifi_setup.cpp: new number field plus a short hint, registered next to lat/lon.
  • radar_theme.h: replaced kCardinalNorthOffsetY / kCardinalSouthOffsetY (now unused) with a single kCardinalRadialOffsetPx tuning constant.
  • README.md: documented the new field and the label behaviour.

Phone compass button (not included)

I initially wanted a "use my phone's compass" button in the portal. However, browsers only expose DeviceOrientationEvent in secure contexts (HTTPS), and the portal is served over plain HTTP by WiFiManager, so Chrome and Safari never fire the event. The portal field is therefore a plain number input with a hint to read the value from the phone's Compass app. A possible follow-up is a small HTTPS helper page that reads the sensor and redirects to http://plane-radar.local/?heading=NNN.

Testing

  • pio run -e supermini builds cleanly.
  • Flashed to an ESP32-C3 Super Mini + GC9A01 (<your hardware/enclosure if different>).
  • Set heading to <value used in photo> and confirmed N/E/S/W, spokes, aircraft and rim dots all rotate consistently and labels stay upright (photo below).
  • Verified the value persists across reboot and resets with the 3 s BOOT hold.
  • <Optional: confirm heading 0 looks the same as before.>

Notes for review

  • Cardinal label spacing is now computed from text metrics rather than the old hand-tuned N/S offsets, so it can differ from before by a pixel or two. kCardinalRadialOffsetPx in radar_theme.h nudges them if you prefer the old look.
  • The range label (e.g. 5km) intentionally stays at 3 o'clock and does not rotate.
  • No new dependencies. Flash and RAM use is essentially unchanged (flash +~2 KB).

Adds a "Compass heading the top of the display faces" field to the Wi-Fi portal that rotates the entire radar (N/E/S/W labels, crosshairs, aircraft, runways) to match how the device is physically mounted. 0° = north at top (default), 90° = east at top, etc.

The cardinal labels stay upright but move around the bezel edge. Aircraft nose/track bearings and runway positions are rotated into the screen frame. The heading is stored in preferences
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant