Skip to content

fix: guard modem preset frequency when region unset#338

Draft
RCGV1 wants to merge 1 commit into
meshtastic:masterfrom
RCGV1:codex/fix-unset-region-preset
Draft

fix: guard modem preset frequency when region unset#338
RCGV1 wants to merge 1 commit into
meshtastic:masterfrom
RCGV1:codex/fix-unset-region-preset

Conversation

@RCGV1

@RCGV1 RCGV1 commented Jul 8, 2026

Copy link
Copy Markdown
Member

Summary

  • Prevent unset-region LoRa settings from rendering a bogus modem-preset frequency.
  • Keep the modem preset settings button disabled until a valid region is selected.
  • Treat unset region or slot 0 as no valid radio frequency in LoRaPresets::getRadioFreq().
  • Add a doctest regression for the unset-region/slot-zero frequency path.

Proof

The bug was observed on a T-Deck with region unset. Opening the modem preset picker displayed FrequencySlot: 0 (1.07374e+09 MHz):

T-Deck showing unset-region modem preset frequency bug

Root Cause

LoRaPresets::getNumChannels() already returns 0 for RegionCode_UNSET, but getRadioFreq() still performed unsigned slot math. With channel == 0, (channel - 1) underflowed and produced a huge MHz value.

Validation

  • git diff --check
  • Focused regression harness against LoRaPresets.cpp:
    • before fix: unset=1.07374e+09 zeroSlot=1.07374e+09 valid=902.125, exit 1
    • after fix: unset=0 zeroSlot=0 valid=902.125, exit 0

Note: local full CMake/doctest build on macOS is blocked before test execution by unrelated fetched Portduino/protobuf setup issues; the repo regression test is included for CI.

Summary by CodeRabbit

  • Bug Fixes
    • LoRa modem preset controls now only appear when a valid region is selected, preventing unavailable settings from being shown.
    • Frequency selection is now properly disabled when no valid LoRa channels are available, reducing confusion in the settings screen.
    • Invalid LoRa region or channel selections now no longer produce a frequency value.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f94f2a62-b958-471a-a2c8-7010fee9f072

📥 Commits

Reviewing files that changed from the base of the PR and between effbb92 and 3e38c7a.

📒 Files selected for processing (3)
  • source/graphics/TFT/TFTView_320x240.cpp
  • source/graphics/common/LoRaPresets.cpp
  • tests/test_LoRaPresets.cpp

📝 Walkthrough

Walkthrough

Changes guard LoRa region/channel validity: getRadioFreq returns 0.0f for unset region or zero channel; UI preset button activation, disabled states, and slider initialization now check region validity and channel count; a new unit test covers the frequency function.

Changes

LoRa Region Validity Guards

Layer / File(s) Summary
Frequency calculation guard and tests
source/graphics/common/LoRaPresets.cpp, tests/test_LoRaPresets.cpp
getRadioFreq early-returns 0.0f for UNSET region or zero channel; a new doctest test verifies zero/valid frequency cases.
UI gating on region validity
source/graphics/TFT/TFTView_320x240.cpp
Preset button activation now requires a valid region, the modem preset button is disabled when region is unset, and the channel slider is set to 0..0 when no channels exist.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

A hop, a guard, a channel of zero,
No frequency found for an unset hero.
The slider now rests when channels are none,
The button stays dim till the region is won.
Tests confirm it, snug in their burrow —
902.125, found in a US furrow! 🐇📡

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: guarding modem preset frequency handling when the LoRa region is unset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

@RCGV1

RCGV1 commented Jul 9, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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