Skip to content

RF Spectrum: derive the plot area from the panel, not from a 120px screen - #2760

Open
vnxdtzip wants to merge 2 commits into
BruceDevices:devfrom
vnxdtzip:ui/rf-spectrum-theme
Open

RF Spectrum: derive the plot area from the panel, not from a 120px screen#2760
vnxdtzip wants to merge 2 commits into
BruceDevices:devfrom
vnxdtzip:ui/rf-spectrum-theme

Conversation

@vnxdtzip

@vnxdtzip vnxdtzip commented Aug 4, 2026

Copy link
Copy Markdown

Proposed Changes

The three views in this file each assumed a fixed layout. The plot started at
y = 20 and ran to tftHeight, spanned x = 0 to tftWidth, and the dBm scale was
positioned with the literal (tftHeight - 120) + 95, which only lands
correctly on a screen with 120px of usable height. The grid was TFT_DARKGREY
and the font size a literal 1.

All three now share one plot rectangle from rf_plot_top(), rf_plot_bot(),
rf_plot_left() and rf_plot_width(), derived from the title bar, the status
line and the rounded theme border at x = 5, so the trace no longer paints over
the frame on either side. The dBm arithmetic is replaced by an rssiY() that
maps -95..-20 onto that band, and the left gutter is sized from the label
width instead of a hardcoded 20px.

The header moved to drawMainBorderWithTitle with the tuning on a status line,
drawn once and repainted only when the frequency changes, so the live graph no
longer flickers. Grid and labels use theme-derived shades.

Behaviour of the RMT capture, the M5 receiver and the CC1101 sweep is
unchanged.

Types of Changes

Bugfix (layout only correct on one screen size; graph overran the frame) plus
UI rework.

Verification

Flash and open each of the three views - RF -> Spectrum, RF -> SquareWave and
RF -> RSSI, the last in both fixed-frequency and range modes. In every one:

  • the graph must stay inside the rounded border, with clear margins on the
    left and right edges
  • the title bar and the status line must not be overdrawn
  • the dBm labels in the RSSI view must line up with the trace, and -95 must
    sit at the bottom of the plot rather than off the band

The frequency-range view should still show the band edges bottom-left and
bottom-right and the Max= readout centred.

Worth checking on a panel that is not 240x135, since the old scale arithmetic
was only correct at one height and that is what this PR fixes.

Testing

No unit test harness exists for this layer. Compiled for m5stack-cardputer on
this branch. Not yet verified on hardware by me - the three views need a CC1101
or an M5 RF module to exercise fully.

Linked Issues

None. Depends on #2754 (ui/color-helpers) for blendColors. Does not need the
SpectrumPlot component, so it can be reviewed and merged independently of the
rest of the series.

User-Facing Change

RF Spectrum, SquareWave and RSSI views now size their plot area from the display instead of assuming a 120px tall screen, no longer draw over the window border, and follow the active theme.

Further Comments

The RSSI range view still draws its own bargraph rather than going through the
shared SpectrumPlot component, which it is a natural fit for - same shape of
data as the NRF sweeper. That conversion was left out to keep this PR to
layout and theming; it would be a good follow-up.


Stacked PR. This branch is built on #2754. GitHub can only base a cross-fork PR on an upstream branch, so until it is merged the diff above also contains its commit. Review only the commit titled RF Spectrum: derive the plot area from the panel, not from a 120px screen; the diff shrinks on its own once the base lands.

Vinicius added 2 commits August 4, 2026 19:54
#### Proposed Changes ####

A module that needs a dimmed or highlighted shade of the active theme has no
way to ask for one. The only helper available, getColorVariation, steps
brightness up or down and cannot mix toward another colour, so modules fall
back to a fixed constant such as TFT_DARKGREY or TFT_WHITE. That is the root
cause of most of the screens in Bruce that stop following the user's theme as
soon as they need more than the primary colour.

This adds two helpers next to it in core/display:

  blendColors(a, b, t)      linear RGB565 mix; t = 0 keeps a, t = 255 keeps b
  buildHeatPalette(lut, n)  fills a lookup table with a theme ramp running
                            from the background up to a brightened primary,
                            for waterfalls and other intensity plots

Both are pure additions. No existing function is modified, and nothing calls
them in this PR - the modules that consume them follow separately.

#### Types of Changes ####

New Feature (internal helper API). No behaviour change and no breaking change.

#### Verification ####

Nothing on screen changes from this PR alone, so verification is limited to
confirming the build is clean and that only insertions were made:

    pio run -e m5stack-cardputer
    git show --stat   # 2 files changed, 31 insertions(+), 0 deletions(-)

#### Testing ####

Bruce has no unit test harness covering the display layer, so this was
verified by compiling for m5stack-cardputer on this branch. The helpers get
exercised on hardware through the follow-up PRs that use them.

#### Linked Issues ####

None. This is the base commit of a series that standardises the
spectrum-style screens; the module PRs listed below depend on it.

#### User-Facing Change ####
```release-note
NONE
```

#### Further Comments ####

Prerequisite for ui/spectrum-view, ui/rf-waterfall-theme and
ui/rf-spectrum-theme.
…reen

#### Proposed Changes ####

The three views in this file each assumed a fixed layout. The plot started at
y = 20 and ran to tftHeight, spanned x = 0 to tftWidth, and the dBm scale was
positioned with the literal `(tftHeight - 120) + 95`, which only lands
correctly on a screen with 120px of usable height. The grid was TFT_DARKGREY
and the font size a literal 1.

All three now share one plot rectangle from rf_plot_top(), rf_plot_bot(),
rf_plot_left() and rf_plot_width(), derived from the title bar, the status
line and the rounded theme border at x = 5, so the trace no longer paints over
the frame on either side. The dBm arithmetic is replaced by an rssiY() that
maps -95..-20 onto that band, and the left gutter is sized from the label
width instead of a hardcoded 20px.

The header moved to drawMainBorderWithTitle with the tuning on a status line,
drawn once and repainted only when the frequency changes, so the live graph no
longer flickers. Grid and labels use theme-derived shades.

Behaviour of the RMT capture, the M5 receiver and the CC1101 sweep is
unchanged.

#### Types of Changes ####

Bugfix (layout only correct on one screen size; graph overran the frame) plus
UI rework.

#### Verification ####

Flash and open each of the three views - RF -> Spectrum, RF -> SquareWave and
RF -> RSSI, the last in both fixed-frequency and range modes. In every one:

  - the graph must stay inside the rounded border, with clear margins on the
    left and right edges
  - the title bar and the status line must not be overdrawn
  - the dBm labels in the RSSI view must line up with the trace, and -95 must
    sit at the bottom of the plot rather than off the band

The frequency-range view should still show the band edges bottom-left and
bottom-right and the Max= readout centred.

Worth checking on a panel that is not 240x135, since the old scale arithmetic
was only correct at one height and that is what this PR fixes.

#### Testing ####

No unit test harness exists for this layer. Compiled for m5stack-cardputer on
this branch. Not yet verified on hardware by me - the three views need a CC1101
or an M5 RF module to exercise fully.

#### Linked Issues ####

None. Depends on ui/color-helpers for blendColors. Does not need the
SpectrumPlot component, so it can be reviewed and merged independently of the
rest of the series.

#### User-Facing Change ####
```release-note
RF Spectrum, SquareWave and RSSI views now size their plot area from the display instead of assuming a 120px tall screen, no longer draw over the window border, and follow the active theme.
```

#### Further Comments ####

The RSSI range view still draws its own bargraph rather than going through the
shared SpectrumPlot component, which it is a natural fit for - same shape of
data as the NRF sweeper. That conversion was left out to keep this PR to
layout and theming; it would be a good follow-up.
@vnxdtzip

vnxdtzip commented Aug 5, 2026

Copy link
Copy Markdown
Author
IMG_8391

@bmorcelli bmorcelli added the enhancement New feature or request label Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants