Harden HFP call controls and add runtime peer MAC configuration #3

Merged
electron-rare merged 1 commits from codex/set-up-environment-for-bluetooth-hfp into main 2026-02-13 13:42:47 +00:00
electron-rare commented 2026-02-13 13:42:15 +00:00 (Migrated from github.com)

Motivation

  • Make the HFP-enabled firmware robust and usable on real hardware by removing fragile hard-coded assumptions and adding runtime controls.
  • Avoid unsafe call actions when the Bluetooth stack or peer is not configured, and provide better visibility of runtime state for debugging and operation.
  • Keep a single codebase that still compiles on non-Classic-BT targets (ESP32-S3) with a clear fallback behavior.

Description

  • Reworked src/main.cpp to add a runtime peer configuration command (p <mac>) with MAC parsing/validation and persistent runtime string for the peer address, replacing reliance on a single hard-coded MAC constant.
  • Added HFP stack readiness and connectivity guardrails (g_hfpReady, g_hfpConnected) and checks before performing connect, disconnect, dial, answer, end and volume operations.
  • Corrected call termination logic so incoming ringing calls are rejected while active/outgoing calls use terminate, and improved state transitions (auto-answer on off-hook during ringing and auto-end on on-hook during active call).
  • Improved status/help output and runtime observability via printStatus/printHelp, normalized pin/variable names, and maintained clear ESP32-S3 fallback stubs when Classic BT is not available.
  • Minor docs and project config updates: updated README.md to document p <mac> and serial commands, and adjusted platformio.ini multi-env ordering.

Testing

  • Installed PlatformIO via python3 -m pip install --user platformio and the install completed successfully.
  • Built the project for ESP32 Classic environment with ~/.local/bin/platformio run -e esp32dev, and the build completed successfully (SUCCESS).
  • Built the project for ESP32-S3 environment with ~/.local/bin/platformio run -e esp32-s3-devkitc-1, and the build completed successfully (SUCCESS).

Codex Task

### Motivation - Make the HFP-enabled firmware robust and usable on real hardware by removing fragile hard-coded assumptions and adding runtime controls. - Avoid unsafe call actions when the Bluetooth stack or peer is not configured, and provide better visibility of runtime state for debugging and operation. - Keep a single codebase that still compiles on non-Classic-BT targets (ESP32-S3) with a clear fallback behavior. ### Description - Reworked `src/main.cpp` to add a runtime peer configuration command (`p <mac>`) with MAC parsing/validation and persistent runtime string for the peer address, replacing reliance on a single hard-coded MAC constant. - Added HFP stack readiness and connectivity guardrails (`g_hfpReady`, `g_hfpConnected`) and checks before performing `connect`, `disconnect`, `dial`, `answer`, `end` and `volume` operations. - Corrected call termination logic so incoming ringing calls are `reject`ed while active/outgoing calls use `terminate`, and improved state transitions (auto-answer on off-hook during ringing and auto-end on on-hook during active call). - Improved status/help output and runtime observability via `printStatus`/`printHelp`, normalized pin/variable names, and maintained clear ESP32-S3 fallback stubs when Classic BT is not available. - Minor docs and project config updates: updated `README.md` to document `p <mac>` and serial commands, and adjusted `platformio.ini` multi-env ordering. ### Testing - Installed PlatformIO via `python3 -m pip install --user platformio` and the install completed successfully. - Built the project for ESP32 Classic environment with `~/.local/bin/platformio run -e esp32dev`, and the build completed successfully (`SUCCESS`). - Built the project for ESP32-S3 environment with `~/.local/bin/platformio run -e esp32-s3-devkitc-1`, and the build completed successfully (`SUCCESS`). ------ [Codex Task](https://chatgpt.com/codex/tasks/task_e_698f251781c88331968f21592fbf6b90)
Sign in to join this conversation.