Skip to content

feat: Glass2 OLED support + three bug fixes#13

Open
Swissola wants to merge 2 commits into
cyberwisk:mainfrom
Swissola:feat/glass2
Open

feat: Glass2 OLED support + three bug fixes#13
Swissola wants to merge 2 commits into
cyberwisk:mainfrom
Swissola:feat/glass2

Conversation

@Swissola

Copy link
Copy Markdown

Summary

Adds optional Grove Glass2 OLED (SSD1309, 128×64) display support, plus three pre-existing bug fixes found during review.

Glass2 OLED (glass2.h)

The Glass2 connects to the Grove port (SDA=G2, SCL=G1). Runtime-detected — glass2Init() returns false if not connected, making all subsequent calls no-ops with no impact on devices without the OLED.

  • setup(): initialises Glass2
  • showStation(): station name on OLED line 1 when switching stations
  • audio_showstation(): stream-reported station name on line 1, now-playing title on line 2

M5UnitGLASS2 is sourced from M5GFX, already in the transitive dependency chain via M5Cardputer/M5Unified — no new library entry required.

Bug fixes

  • bgcolor() division by zero: dh = h - header_height is used as a divisor with no guard. If header_height were ever ≥ display height, dh would be zero or negative causing a crash. Added if (dh <= 0) return 0; guard.

  • Duplicate 'f' key handler: The loop() keyboard handler had two consecutive else if (isKeyPressed('f')) blocks. The second could never execute (dead code). Removed.

  • audio_showstation buffer size mismatch: Buffer was declared char limitedInfo[241] (suggesting 240-char intent) but only 24 bytes were ever copied/used. Corrected to char[25] to match actual behaviour and avoid misleading the reader.

Test plan

  • Build in Arduino IDE / PlatformIO — no new warnings or errors
  • Flash without Glass2 connected — boots and streams normally
  • Flash with Glass2 connected — OLED shows station name when playing, stream title updates via audio_showstation
  • Toggle FFT with f key — toggles once per press (no double-fire)

🤖 Generated with Claude Code

Swissola and others added 2 commits May 25, 2026 14:03
Glass2 (Grove SSD1309, SDA=G2, SCL=G1):
- glass2Init() in setup() — no-op if OLED not connected
- showStation(): mirrors station name to OLED line 1
- audio_showstation(): adds now-playing stream title to OLED line 2

Bug fixes:
- bgcolor(): add dh <= 0 guard to prevent division by zero if
  header_height were ever >= display height
- loop(): remove duplicate else-if for 'f' key — dead code, second
  handler could never execute
- audio_showstation(): buffer was declared as char[241] but only 24
  bytes were ever written; corrected to char[25] to match actual use

M5UnitGLASS2 is sourced from M5GFX, already in the transitive dep
chain via M5Cardputer/M5Unified — no new library dependency required.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add glass2Spectrum() — 32 bars from FFT bins 0-127, station name on
top 14px, bars filling bottom 48px. Driven by the existing updateFFT()
50ms tick (no extra I2C overhead when FFT is disabled).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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