Skip to content

chore(locator_by_rssi): c320x240 updates#281

Merged
pfeerick merged 3 commits into
masterfrom
pfeerick/locator-c320x240-updates
May 11, 2026
Merged

chore(locator_by_rssi): c320x240 updates#281
pfeerick merged 3 commits into
masterfrom
pfeerick/locator-c320x240-updates

Conversation

@pfeerick

@pfeerick pfeerick commented May 11, 2026

Copy link
Copy Markdown
Member

Fixes #279

Summary by CodeRabbit

Release Notes

  • New Features

    • Improved signal detection for FrSky RSSI and ELRS telemetry systems with clearer signal status indicators.
    • Enhanced UI layout with consistent scaling across interface elements.
  • Bug Fixes

    • Added safety checks for signal value calculations to prevent errors.
  • Chores

    • Version updated to 1.12.

Review Change Stack

pfeerick and others added 3 commits May 11, 2026 22:55
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented May 11, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The RSSI locator widget is refactored to fix a display-sizing issue by applying LVGL scaling consistently across all UI elements. Signal detection is restructured with explicit type constants for clearer FrSky/ELRS branching, value normalization is isolated by signal type, and runtime safety guards prevent invalid percentage calculations when signal values are unavailable.

Changes

Signal Detection & UI Scaling

Layer / File(s) Summary
Signal Type Constants & Version
sdcard/c320x240/SCRIPTS/TOOLS/locator_by_rssi/app.lua
Version updated to 1.12. Signal-type enumeration constants introduced (SIGNAL_NONE, SIGNAL_RSSI, SIGNAL_1RSS, SIGNAL_2RSS) replacing implicit numeric checks. Log helper print output disabled.
Signal Detection
sdcard/c320x240/SCRIPTS/TOOLS/locator_by_rssi/app.lua
detectSignalType() reimplemented to probe telemetry fields and assign signalType constant. Auto-detects FrSky RSSI, selects ELRS antenna (1RSS vs 2RSS) via TPWR check, defaults to SIGNAL_NONE if fields absent.
Signal Value Computation
sdcard/c320x240/SCRIPTS/TOOLS/locator_by_rssi/app.lua
updateSignalValues() reworked to extract signalValue, signalMin, signalMax, and txPower per signalType. FrSky RSSI scaled to 0–100; ELRS applies −115 to −20 range with value clamping. Early returns and default values for missing telemetry.
UI Layout & Presentation
sdcard/c320x240/SCRIPTS/TOOLS/locator_by_rssi/app.lua
build_ui() rebuilt using lvSCALE for consistent coordinate and size scaling throughout. Signal-type choice labels refreshed (auto detect, RSSI, ELRS antenna 1/2) with callback syncing signalType. "No signal found" UI box rescaled with locator image and updated telemetry-waiting message (RSSI/1RSS/2RSS).
Runtime Safety Guards
sdcard/c320x240/SCRIPTS/TOOLS/locator_by_rssi/app.lua
main() adds validation: signalPercent forced to 0 if signalValue is nil or signalMax equals signalMin. Beep/haptic behavior remains gated by getRSSI() ~= 0 and nextPlayTime check.

🎯 3 (Moderate) | ⏱️ ~25 minutes

🐰 A widget too large upon the screen,
With numbers lost in a scaling dream—
Now LVGL scales each box just right,
And RSSI/ELRS signals find the light,
The locator hops back into sight!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'chore(locator_by_rssi): c320x240 updates' is vague and generic, using non-descriptive terms that don't clearly convey the specific change being made. Consider a more specific title like 'fix(locator_by_rssi): scale UI properly for c320x240 resolution' to better describe the main fix being addressed.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The pull request addresses issue #279 by refactoring UI layout to use LVGL scaling consistently, which directly fixes the oversized screen problem reported in the linked issue.
Out of Scope Changes check ✅ Passed All changes are within scope: version bump, signal handling refactoring, and UI scaling align with the issue requirements; no extraneous modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pfeerick/locator-c320x240-updates

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
sdcard/c320x240/SCRIPTS/TOOLS/locator_by_rssi/app.lua (1)

307-320: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use the detected signal state for visibility and playback.

The UI visibility and audio gating still rely on getRSSI(), which only reflects FrSky RSSI. When ELRS is active (signalType = SIGNAL_1RSS or SIGNAL_2RSS), getRSSI() returns 0 even though signalValue contains a valid signal reading. This leaves the widget stuck on the "No signal found" screen and suppresses beeps/haptics during ELRS operation.

Replace visibility checks at lines 307-309 and 319-320, and the audio gate at line 354, to key off signalType and signalValue instead.

Suggested fix
-            visible=function()
-                return getRSSI() ~= 0
-            end
+            visible=function()
+                return signalType ~= SIGNAL_NONE
+                    and signalValue ~= nil
+                    and (signalType ~= SIGNAL_RSSI or signalValue > 0)
+            end
@@
-            visible=function()
-                return getRSSI() == 0
-            end
+            visible=function()
+                return signalType == SIGNAL_NONE
+                    or signalValue == nil
+                    or (signalType == SIGNAL_RSSI and signalValue <= 0)
+            end
@@
-    if getRSSI() ~= 0 and getTime() >= nextPlayTime then
+    if signalType ~= SIGNAL_NONE
+        and signalValue ~= nil
+        and (signalType ~= SIGNAL_RSSI or signalValue > 0)
+        and getTime() >= nextPlayTime then
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sdcard/c320x240/SCRIPTS/TOOLS/locator_by_rssi/app.lua` around lines 307 -
320, The UI visibility and audio gating currently check getRSSI(), which is zero
for ELRS; update the visible functions for the "signal present" and "no signal"
boxes and the audio/haptic gating logic to use the ELRS-aware state instead:
test signalType against SIGNAL_1RSS or SIGNAL_2RSS and/or check signalValue > 0
(or non-nil) in addition to existing FrSky logic so that widgets and
beeps/haptics trigger when signalType == SIGNAL_1RSS or SIGNAL_2RSS and
signalValue indicates a valid reading; modify the anonymous visible=function()
closures for those boxes and the audio gating condition to evaluate (getRSSI()
~= 0) || ((signalType == SIGNAL_1RSS or signalType == SIGNAL_2RSS) and
signalValue > 0) (or equivalent truthy check) and ensure you reference the same
signalType/signalValue variables used elsewhere in the file.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@sdcard/c320x240/SCRIPTS/TOOLS/locator_by_rssi/app.lua`:
- Around line 162-165: The log calls concatenate the raw result of
getValue("RSSI") which may be nil and will throw an error; update the log
expressions to use tostring(v) (e.g., after v = getValue("RSSI")) so nil becomes
"nil" and cannot abort the widget — apply this change to the log calls near
fieldinfo/getValue usage (the log("RSSI: " .. v) instance and the other
concatenations in the same block around lines 187-198), leaving signalValue = v
unchanged so the value is still stored as-is.
- Around line 118-133: The early check that reads txPowerFieldTpwr =
getFieldInfo("TPWR") and returns SIGNAL_NONE when nil blocks ELRS
auto-detection; remove that prerequisite so detection continues even if TPWR is
absent. Specifically, delete or disable the branch that tests txPowerFieldTpwr
== nil and sets signalType = SIGNAL_NONE / return, then allow the subsequent
getFieldInfo("1RSS") and getFieldInfo("2RSS") checks to run and set signalType
to SIGNAL_1RSS or SIGNAL_2RSS as appropriate (leaving TPWR handling in the
value-update phase intact).

---

Outside diff comments:
In `@sdcard/c320x240/SCRIPTS/TOOLS/locator_by_rssi/app.lua`:
- Around line 307-320: The UI visibility and audio gating currently check
getRSSI(), which is zero for ELRS; update the visible functions for the "signal
present" and "no signal" boxes and the audio/haptic gating logic to use the
ELRS-aware state instead: test signalType against SIGNAL_1RSS or SIGNAL_2RSS
and/or check signalValue > 0 (or non-nil) in addition to existing FrSky logic so
that widgets and beeps/haptics trigger when signalType == SIGNAL_1RSS or
SIGNAL_2RSS and signalValue indicates a valid reading; modify the anonymous
visible=function() closures for those boxes and the audio gating condition to
evaluate (getRSSI() ~= 0) || ((signalType == SIGNAL_1RSS or signalType ==
SIGNAL_2RSS) and signalValue > 0) (or equivalent truthy check) and ensure you
reference the same signalType/signalValue variables used elsewhere in the file.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7dd2ea07-c687-4a3c-967b-2d54125245ed

📥 Commits

Reviewing files that changed from the base of the PR and between d6c707f and 3463797.

📒 Files selected for processing (2)
  • sdcard/c320x240/SCRIPTS/TOOLS/locator_by_rssi/app.lua
  • sdcard/c320x240/SCRIPTS/TOOLS/locator_by_rssi/main.lua

Comment thread sdcard/c320x240/SCRIPTS/TOOLS/locator_by_rssi/app.lua
Comment on lines 162 to 165
if fieldinfo then
local v = getValue("RSSI")
log("RSSI: " .. v)
signalType = 2 -- RSSI
signalValue = v

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

# First, locate and examine the file
find . -name "app.lua" -path "*locator_by_rssi*" | head -20

Repository: EdgeTX/edgetx-sdcard

Length of output: 288


🏁 Script executed:

# Check if the file exists and read the relevant lines
if [ -f "sdcard/c320x240/SCRIPTS/TOOLS/locator_by_rssi/app.lua" ]; then
  echo "=== File exists, reading lines 160-200 ===";
  sed -n '160,200p' "sdcard/c320x240/SCRIPTS/TOOLS/locator_by_rssi/app.lua" | cat -n;
else
  echo "File not found at expected path, searching...";
  find . -type f -name "app.lua" | grep -i rssi;
fi

Repository: EdgeTX/edgetx-sdcard

Length of output: 1214


🏁 Script executed:

# Search for the log function definition in the codebase
rg "function log|log\s*=" --type lua | head -20

Repository: EdgeTX/edgetx-sdcard

Length of output: 1575


🏁 Script executed:

# Also check if there are any imports or requires that define log
rg "log" sdcard/c320x240/SCRIPTS/TOOLS/locator_by_rssi/app.lua | head -30

Repository: EdgeTX/edgetx-sdcard

Length of output: 686


🏁 Script executed:

# Check the beginning of app.lua to see log function definition
head -50 sdcard/c320x240/SCRIPTS/TOOLS/locator_by_rssi/app.lua | cat -n

Repository: EdgeTX/edgetx-sdcard

Length of output: 3136


🏁 Script executed:

# Test Lua nil concatenation behavior to confirm the error
python3 << 'EOF'
# Simulate Lua string concatenation behavior
# In Lua, attempting to concatenate with nil throws: "attempt to concatenate a nil value"
print("Testing Lua string concatenation with nil:")
print("- Lua will throw an error if you try: 'RSSI: ' .. nil")
print("- This occurs BEFORE any function call, so log() never gets called")
print("- The correct fix is to use tostring(v) which converts nil to string 'nil'")
print("\nLua examples:")
print("  'RSSI: ' .. 5     => 'RSSI: 5'  (works)")
print("  'RSSI: ' .. nil   => ERROR: attempt to concatenate a nil value")
print("  'RSSI: ' .. tostring(nil)  => 'RSSI: nil'  (works)")
EOF

Repository: EdgeTX/edgetx-sdcard

Length of output: 478


🏁 Script executed:

# Search for log function definition in the app.lua file itself
grep -n "function log" sdcard/c320x240/SCRIPTS/TOOLS/locator_by_rssi/app.lua

Repository: EdgeTX/edgetx-sdcard

Length of output: 96


🏁 Script executed:

# Get the log function definition
sed -n '68,85p' sdcard/c320x240/SCRIPTS/TOOLS/locator_by_rssi/app.lua | cat -n

Repository: EdgeTX/edgetx-sdcard

Length of output: 753


🏁 Script executed:

# Also verify the current state of the problem lines once more with context
sed -n '155,200p' sdcard/c320x240/SCRIPTS/TOOLS/locator_by_rssi/app.lua | cat -n

Repository: EdgeTX/edgetx-sdcard

Length of output: 1355


Make the debug logging nil-safe.

getValue() can return nil while telemetry is still coming up. Lua's string concatenation operator (..) throws an error when concatenating with nil, and this error occurs during expression evaluation—before log() is even called. This means Lines 164, 189, and 194 can abort the widget on a missing sample.

The fix is to use tostring(v) which safely converts nil to the string "nil":

Suggested fix
-            log("RSSI: " .. v)
+            log("RSSI: %s", tostring(v))
@@
-        log("1RSS: " .. v)
+        log("1RSS: %s", tostring(v))
@@
-        log("2RSS: " .. v)
+        log("2RSS: %s", tostring(v))

Also applies to: 187-198

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sdcard/c320x240/SCRIPTS/TOOLS/locator_by_rssi/app.lua` around lines 162 -
165, The log calls concatenate the raw result of getValue("RSSI") which may be
nil and will throw an error; update the log expressions to use tostring(v)
(e.g., after v = getValue("RSSI")) so nil becomes "nil" and cannot abort the
widget — apply this change to the log calls near fieldinfo/getValue usage (the
log("RSSI: " .. v) instance and the other concatenations in the same block
around lines 187-198), leaving signalValue = v unchanged so the value is still
stored as-is.

@pfeerick pfeerick merged commit 90cc9de into master May 11, 2026
3 checks passed
@pfeerick pfeerick deleted the pfeerick/locator-c320x240-updates branch May 11, 2026 23:41
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.

locator Screen is massive cant see the numbers

1 participant