Skip to content

feat(lua): enable serial terminal scripts (port query, textEdit placeholder, Enter key) - #7578

Open
graycoderep wants to merge 3 commits into
EdgeTX:mainfrom
graycoderep:cli-terminal
Open

feat(lua): enable serial terminal scripts (port query, textEdit placeholder, Enter key)#7578
graycoderep wants to merge 3 commits into
EdgeTX:mainfrom
graycoderep:cli-terminal

Conversation

@graycoderep

@graycoderep graycoderep commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary of changes:

These three changes all came out of writing a Lua app that turns the radio into
a serial terminal for any device with a text CLI over UART (flight controllers,
ESCs, GPS modules) through a port set to LUA mode. Each removes a concrete
obstacle. They are technically independent, but the app needs all three, so they
are kept together rather than split into PRs that could land partially.

What this is worth in practice: out in the field it turns hardware the pilot is
already holding into one more tool, with no laptop involved. Connecting to a
UART correctly is the whole setup. And the moment radios gain USB host support,
the very same app does exactly this over an ordinary USB-C cable to the flight
controller, with no wiring at all - so the groundwork here keeps paying off.

1. feat(lua): new serialGetLuaPort()

A script using serialRead()/serialWrite() had no way to find out whether any
serial port is actually set to LUA mode. Without it a script can only sit there
receiving nothing, unable to tell the user why. Returns the port number and its
name, or nil when no port is in LUA mode.

2. feat(color): custom placeholder on text edit fields

An empty text field always renders as ---, both in the field itself and as the
text area placeholder while editing. That is right for settings screens but
wrong for free-form input, where an empty field should simply look empty. The
default is unchanged, so no existing screen is affected; scripts can pass
placeholder = "" (or hint text) to lvgl.textEdit.

3. fix(color): keyboard Enter key does nothing on single-line fields

For a one-line text area LVGL sends LV_EVENT_READY only to the text area,
while the OK checkmark also sends it to the keyboard object - and the keyboard
object is what EdgeTX listens on. The result is that the Enter key neither
commits the value nor closes the keyboard: it does nothing at all, on every
single-line field in the radio.

The Enter key is now detected on the keyboard and routed through a new
FormField::onEnter(), so it commits and closes like the checkmark. A field may
additionally install an enter handler to treat Enter as "submit" as opposed to
the checkmark's "keep editing"; lvgl.textEdit exposes this as an enter
callback, which is what lets the terminal app send a typed command on Enter.

There are no local changes to the vendored LVGL.

Testing:

  • Built for X10/TX16S and flashed to a TX16S MK2; the Lua app using all four
    additions runs on the radio.
  • Behaviour verified against a real flight controller (IFLIGHT BLITZ F722,
    Betaflight 2025.12.5) on a UART with Configuration/MSP: # opens the CLI,
    commands echo and answer, and the keyboard Enter change commits/sends as
    expected.
  • The placeholder default is unchanged in code ("---"), so existing screens
    keep their current appearance; the new behaviour only applies to fields that
    pass the parameter.

Summary by CodeRabbit

  • New Features

    • Added configurable placeholder text for text-entry fields.
    • Pressing Enter can now submit a field and trigger a configured action.
    • Lua text-edit widgets support placeholder text and Enter callbacks.
    • Added a Lua API to identify the serial port configured for Lua communication.
  • Bug Fixes

    • Improved serial data reading to prevent buffer overruns.
    • Text fields now correctly display their configured placeholder when empty.

Scripts using serialRead()/serialWrite() had no way to tell whether a
serial port is actually configured for LUA, so a script talking to an
external device could only sit there receiving nothing with no way to
explain why. Return the port number and its name, or nil when no port
is in LUA mode.
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

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: 33539404-7701-4b9f-a30b-17c0e6a60acf

📥 Commits

Reviewing files that changed from the base of the PR and between 4bfbe4b and 0232fd2.

📒 Files selected for processing (7)
  • radio/src/gui/colorlcd/libui/form.h
  • radio/src/gui/colorlcd/libui/keyboard_base.cpp
  • radio/src/gui/colorlcd/libui/keyboard_base.h
  • radio/src/gui/colorlcd/libui/textedit.cpp
  • radio/src/gui/colorlcd/libui/textedit.h
  • radio/src/lua/lua_lvgl_widget.cpp
  • radio/src/lua/lua_lvgl_widget.h
🚧 Files skipped from review as they are similar to previous changes (6)
  • radio/src/gui/colorlcd/libui/textedit.h
  • radio/src/gui/colorlcd/libui/form.h
  • radio/src/gui/colorlcd/libui/keyboard_base.cpp
  • radio/src/lua/lua_lvgl_widget.cpp
  • radio/src/gui/colorlcd/libui/keyboard_base.h
  • radio/src/gui/colorlcd/libui/textedit.cpp

📝 Walkthrough

Walkthrough

The PR adds Enter-key submission to color LCD text fields, configurable text-edit placeholders and Lua Enter callbacks, plus a Lua API for querying the Lua-mode serial port and revised serial read buffering.

Changes

Color LCD text-edit Enter flow

Layer / File(s) Summary
Form and keyboard Enter submission
radio/src/gui/colorlcd/libui/form.h, radio/src/gui/colorlcd/libui/keyboard_base.*
FormField exposes an Enter callback, while Keyboard detects Enter, hides without cancellation, and invokes the callback during cleanup.
TextEdit placeholder and keyboard wiring
radio/src/gui/colorlcd/libui/textedit.*
TextEdit supports configurable placeholders and forwards overlay Enter events to onEnter().
Lua text-edit properties and callback
radio/src/lua/lua_lvgl_widget.*
Lua text-edit widgets accept placeholder and enter properties, manage the callback reference, and invoke it with bounded text.

Lua serial API updates

Layer / File(s) Summary
Serial port discovery and read buffering
radio/src/lua/api_general.cpp
Adds serialGetLuaPort() to return the configured Lua-mode port and changes serial reads to use LUA_SERIAL_READ_CHUNK capacity.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant TextArea
  participant Keyboard
  participant TextEdit
  participant LuaCallback
  TextArea->>Keyboard: detect Enter button
  Keyboard->>Keyboard: hide without cancellation
  Keyboard->>TextEdit: invoke onEnter during field cleanup
  TextEdit->>LuaCallback: call enter callback with bounded text
Loading

Suggested reviewers: kudzzo

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% 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
Title check ✅ Passed The title clearly matches the main change: Lua serial-terminal support via port query, placeholder, and Enter-key handling.
Description check ✅ Passed The description includes the required summary of changes and testing details, with only the optional Fixes # section omitted.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

An empty text field always renders as "---", both in the field itself
and as the text area placeholder while editing. That is right for
settings screens but wrong for free-form input, where the field should
simply look empty.

The default is unchanged, so no existing screen is affected; scripts can
now pass placeholder="" (or any hint text) to lvgl.textEdit.
For a one-line text area LVGL sends LV_EVENT_READY only to the text
area, while the OK checkmark also sends it to the keyboard object -
and the keyboard object is what EdgeTX listens on. As a result the
Enter key neither committed the value nor closed the keyboard: it did
nothing at all.

Detect the Enter key on the keyboard itself and route it through a new
FormField::onEnter(), so it commits and closes like the checkmark. A
field may additionally install an enter handler to treat Enter as
"submit" as opposed to the checkmark's "keep editing"; lvgl.textEdit
exposes this as the enter callback, which lets a script send a typed
command on Enter.
@graycoderep graycoderep changed the title feat(lua): enable serial terminal scripts (port query, RX buffer, textEdit placeholder, Enter key) feat(lua): enable serial terminal scripts (port query, textEdit placeholder, Enter key) Jul 21, 2026
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