mirror of
https://github.com/pelgraine/Meck.git
synced 2026-05-11 20:05:52 +02:00
Compare commits
93 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d601edd0ce | |||
| a378f4f1aa | |||
| 1c4d5a0daa | |||
| df6c977ee4 | |||
| 7e9e69dd67 | |||
| 6d7fd54b83 | |||
| d2ce070a3f | |||
| 44b68c40af | |||
| a4e8c31a16 | |||
| 8d69b69e1f | |||
| 0c032429eb | |||
| c578dcadc8 | |||
| ec42ac73a8 | |||
| aacf8c777f | |||
| 570776478c | |||
| 4c654c99c6 | |||
| f436f5ba50 | |||
| 0252204d73 | |||
| 595f0073f9 | |||
| 8aa0f0388e | |||
| b070af39cc | |||
| c939aa577b | |||
| abccfe154e | |||
| 23733ca555 | |||
| 9d45ac52eb | |||
| 424e152d4b | |||
| c687133b05 | |||
| c7d0449181 | |||
| 9ddb692806 | |||
| 0cab2ddfa7 | |||
| d07ad71d5d | |||
| b4983e48f0 | |||
| b991eb0fe7 | |||
| c15b30079c | |||
| 9d7cbd4866 | |||
| b9283af7fc | |||
| 39cd30890b | |||
| 902577ed10 | |||
| ce93cfa033 | |||
| 2be399f65a | |||
| 5679cda38e | |||
| 1ea883783c | |||
| bf8cf32bc2 | |||
| 465a29bb23 | |||
| 81eca29b69 | |||
| 342cf4e745 | |||
| c52a190ace | |||
| a7bc7a4733 | |||
| 47a0d2cc95 | |||
| 5dda0b686e | |||
| 60dcd6a89e | |||
| 19efb52521 | |||
| 81ef3ea3c5 | |||
| 6f07b7a372 | |||
| b0f74b101a | |||
| 06a064538e | |||
| 166a433353 | |||
| 735fefd203 | |||
| ed5cda4f44 | |||
| b208af83f6 | |||
| bad821ac4b | |||
| 8839012153 | |||
| 0958ef079e | |||
| 0bf2826110 | |||
| c2840a43aa | |||
| e8a8be521a | |||
| a627fbe0e9 | |||
| 17f8233402 | |||
| 1c9e9079f0 | |||
| 69dc62fa78 | |||
| f118a0949f | |||
| f78824cdc4 | |||
| f81de07830 | |||
| 3ae988c0bb | |||
| 5bed26cb72 | |||
| c28d22e6cc | |||
| 8e1f2a3a87 | |||
| 6d1447a45c | |||
| 77c92b3567 | |||
| 6db7b672ca | |||
| 046cce6f43 | |||
| c2c2d8cf21 | |||
| 148f8cea4f | |||
| cd69ea546f | |||
| 7780a0d76e | |||
| 33a3352692 | |||
| 4004acf15d | |||
| 0b9402b530 | |||
| e55799f8a5 | |||
| 0549efa627 | |||
| a52cf166cb | |||
| facffe9f07 | |||
| 148fb7f001 |
@@ -1,25 +1,31 @@
|
||||
## Meshcore + Fork = Meck
|
||||
|
||||
A fork created specifically to focus on enabling BLE & WiFi companion firmware for the LilyGo T-Deck Pro & LilyGo T5 E-Paper S3 Pro. Created with the assistance of Claude AI using Meshcore v1.11 code.
|
||||
A fork created specifically to focus on enabling BLE & WiFi companion firmware for the LilyGo T-Deck Pro & LilyGo T5 E-Paper S3 Pro. Created wholly with Claude AI using Meshcore v1.11 code. 100% vibecoded.
|
||||
|
||||
[Check out the Meck discussion channel on the MeshCore Discord](https://discord.com/channels/1343693475589263471/1460136499390447670)
|
||||
|
||||
<img src="https://github.com/user-attachments/assets/b30ce6bd-79af-44d3-93c4-f5e7e21e5621" alt="IMG_1453" width="300" height="650">
|
||||
|
||||
### Contents
|
||||
- [Supported Devices](#supported-devices)
|
||||
- [SD Card Requirements](#sd-card-requirements)
|
||||
- [Flashing Firmware](#flashing-firmware)
|
||||
- [First-Time Flash (Merged Firmware)](#first-time-flash-merged-firmware)
|
||||
- [Upgrading Firmware](#upgrading-firmware)
|
||||
- [SD Card Launcher](#sd-card-launcher)
|
||||
- [Launcher](#launcher)
|
||||
- [OTA Firmware Update](#ota-firmware-update-v13)
|
||||
- [Path Hash Mode (v0.9.9+)](#path-hash-mode-v099)
|
||||
- [T-Deck Pro](#t-deck-pro)
|
||||
- [Build Variants](#t-deck-pro-build-variants)
|
||||
- [Keyboard Controls](#t-deck-pro-keyboard-controls)
|
||||
- [Navigation (Home Screen)](#navigation-home-screen)
|
||||
- [Bluetooth (BLE)](#bluetooth-ble)
|
||||
- [WiFi Companion](#wifi-companion)
|
||||
- [Clock & Timezone](#clock--timezone)
|
||||
- [Channel Message Screen](#channel-message-screen)
|
||||
- [Contacts Screen](#contacts-screen)
|
||||
- [Sending a Direct Message](#sending-a-direct-message)
|
||||
- [Roomservers](#roomservers)
|
||||
- [Repeater Admin Screen](#repeater-admin-screen)
|
||||
- [Settings Screen](#settings-screen)
|
||||
- [Compose Mode](#compose-mode)
|
||||
@@ -27,6 +33,11 @@ A fork created specifically to focus on enabling BLE & WiFi companion firmware f
|
||||
- [Emoji Picker](#emoji-picker)
|
||||
- [SMS & Phone App (4G only)](#sms--phone-app-4g-only)
|
||||
- [Web Browser & IRC](#web-browser--irc)
|
||||
- [Alarm Clock (Audio only)](#alarm-clock-audio-only)
|
||||
- [Voice Notes Over LoRa (Audio only)](#voice-notes-over-lora-audio-only)
|
||||
- [Lock Screen (T-Deck Pro)](#lock-screen-t-deck-pro)
|
||||
- [Remote Repeater (T-Deck Pro 4G)](#remote-repeater-t-deck-pro-4g)
|
||||
- [WiFi Repeater](#wifi-repeater)
|
||||
- [T5S3 E-Paper Pro](#t5s3-e-paper-pro)
|
||||
- [Build Variants](#t5s3-build-variants)
|
||||
- [Touch Navigation](#touch-navigation)
|
||||
@@ -42,6 +53,8 @@ A fork created specifically to focus on enabling BLE & WiFi companion firmware f
|
||||
- [Text & EPUB Reader](TXT___EPUB_Reader_Guide.md)
|
||||
- [Web Browser & IRC Guide](Web_App_Guide.md)
|
||||
- [SMS & Phone App Guide](SMS___Phone_App_Guide.md)
|
||||
- [Audiobook Player Guide](Audiobook_Player_Guide.md)
|
||||
- [Meck-Mycelium Web App](#meck-mycelium-web-app)
|
||||
- [About MeshCore](#about-meshcore)
|
||||
- [What is MeshCore?](#what-is-meshcore)
|
||||
- [Key Features](#key-features)
|
||||
@@ -59,14 +72,24 @@ A fork created specifically to focus on enabling BLE & WiFi companion firmware f
|
||||
|
||||
## Supported Devices
|
||||
|
||||
Meck currently targets two LilyGo devices:
|
||||
Meck currently targets two LilyGo devices and also supports the Heltec V3 and V4 as remote repeaters:
|
||||
|
||||
| Device | Display | Input | LoRa | Battery | GPS | RTC |
|
||||
|--------|---------|-------|------|---------|-----|-----|
|
||||
| **T-Deck Pro** | 240×320 e-ink (GxEPD2) | TCA8418 keyboard + optional touch | SX1262 | BQ27220 fuel gauge, 1400 mAh | Yes | No (uses GPS time) |
|
||||
| **T5S3 E-Paper Pro** (V2, H752-B) | 960×540 e-ink (FastEPD, parallel) | GT911 capacitive touch (no keyboard) | SX1262 | BQ27220 fuel gauge, 1500 mAh | No (non-GPS variant) | Yes (PCF8563 hardware RTC) |
|
||||
| **Heltec V3** (remote repeater only) | 0.96" OLED (SSD1306) | — | SX1262 | — | No | No |
|
||||
| **Heltec V4** (remote repeater only) | 0.96" OLED (SSD1306) | — | SX1262 | — | No | No |
|
||||
|
||||
Both devices use the ESP32-S3 with 16 MB flash and 8 MB PSRAM.
|
||||
The T-Deck Pro and T5S3 use the ESP32-S3 with 16 MB flash and 8 MB PSRAM. The Heltec V3 and V4 use the ESP32-S3 with 8 MB flash and 8 MB PSRAM.
|
||||
|
||||
---
|
||||
|
||||
## SD Card Requirements
|
||||
|
||||
**An SD card is essential for Meck to function properly.** Many features — including the e-book reader, notes, bookmarks, web reader cache, audiobook playback, firmware updates, contact import/export, and WiFi credential storage — rely on files stored on the SD card. Without an SD card inserted, the device will boot and handle mesh messaging, but most extended features will be unavailable or will fail silently.
|
||||
|
||||
**Recommended:** A **32 GB or larger** microSD card formatted as **FAT32**. MeshCore users have found that **SanDisk** microSD cards are the most reliable across both the T-Deck Pro and T5S3.
|
||||
|
||||
---
|
||||
|
||||
@@ -76,7 +99,7 @@ Download the latest firmware from the [Releases](https://github.com/pelgraine/Me
|
||||
|
||||
| File Type | When to Use |
|
||||
|-----------|-------------|
|
||||
| `*_merged.bin` | **First-time flash** — includes bootloader, partition table, and firmware in a single file. Flash at address `0x0`. |
|
||||
| `*-merged.bin` | **First-time flash** — includes bootloader, partition table, and firmware in a single file. Flash at address `0x0`. |
|
||||
| `*.bin` (non-merged) | **Upgrading existing firmware** — firmware image only. Also used when loading firmware from an SD card via the Launcher. |
|
||||
|
||||
### First-Time Flash (Merged Firmware)
|
||||
@@ -87,7 +110,7 @@ If the device has never had Meck firmware (or you want a clean start), use the *
|
||||
|
||||
```
|
||||
esptool.py --chip esp32s3 --port /dev/ttyACM0 --baud 921600 \
|
||||
write_flash 0x0 meck_t5s3_standalone_merged.bin
|
||||
write_flash 0x0 meck_t5s3_standalone-merged.bin
|
||||
```
|
||||
|
||||
On macOS the port is typically `/dev/cu.usbmodem*`. On Windows it will be a COM port like `COM3`.
|
||||
@@ -99,7 +122,7 @@ On macOS the port is typically `/dev/cu.usbmodem*`. On Windows it will be a COM
|
||||
3. Select the **merged** `.bin` file you downloaded
|
||||
4. Click **Flash**, select your device in the popup, and click **Connect**
|
||||
|
||||
> **Note:** The MeshCore Flasher flashes at address `0x0` by default, so the merged file is the correct choice here for first-time flashes.
|
||||
> **Note:** The MeshCore Flasher detects merged firmware by the `-merged.bin` suffix in the filename and automatically flashes at address `0x0`. If the filename doesn't end with `-merged.bin`, the flasher writes at `0x10000` instead, which will fail on a clean device.
|
||||
|
||||
### Upgrading Firmware
|
||||
|
||||
@@ -114,10 +137,27 @@ esptool.py --chip esp32s3 --port /dev/ttyACM0 --baud 921600 \
|
||||
|
||||
> **Tip:** If you're unsure whether the device already has a bootloader, it's always safe to use the merged file and flash at `0x0` — it will overwrite everything cleanly.
|
||||
|
||||
### SD Card Launcher
|
||||
### Launcher
|
||||
|
||||
If you're loading firmware from an SD card via the LilyGo Launcher firmware, use the **non-merged** `.bin` file. The Launcher provides its own bootloader and only needs the application image.
|
||||
|
||||
### OTA Firmware Update (v1.3+)
|
||||
|
||||
Once Meck is installed, you can update firmware directly from your phone — no computer or serial cable required. The device creates a temporary WiFi access point and you upload the new `.bin` via your phone's browser.
|
||||
|
||||
1. Download the new **non-merged** `.bin` to your phone (from GitHub Releases, Discord, etc.)
|
||||
2. On the device: **Settings → OTA Tools → Firmware Update → Enter** (T-Deck Pro) or **tap** (T5S3)
|
||||
3. The device starts a WiFi network called `Meck-Update-XXXX` and displays connection details
|
||||
4. On your phone: connect to the `Meck-Update` WiFi network, open a browser, go to `192.168.4.1`
|
||||
5. Tap **Choose File**, select the `.bin`, tap **Upload**
|
||||
6. The device receives the file, saves to SD, verifies, flashes, and reboots
|
||||
|
||||
The partition layout supports dual OTA slots — the old firmware remains on the inactive partition as an automatic rollback target. If the new firmware fails to boot, the ESP32 bootloader reverts to the previous working version automatically.
|
||||
|
||||
> **Note:** Use the **non-merged** `.bin` for OTA updates. The merged binary is only needed for first-time USB flashing.
|
||||
|
||||
**OTA Tools (v1.5+):** The firmware update has moved into **Settings → OTA Tools**, a submenu that also contains the new **SD File Manager**. The file manager creates the same WiFi access point and serves a browser-based interface where you can browse, upload, download, and delete files on the SD card from your phone — useful for managing audiobooks, alarm sounds, e-books, and notes without ejecting the SD card. Both OTA tools work on all variants including standalone builds.
|
||||
|
||||
---
|
||||
|
||||
## Path Hash Mode (v0.9.9+)
|
||||
@@ -148,12 +188,16 @@ For a detailed explanation of what multibyte path hash means and why it matters,
|
||||
|
||||
| Variant | Environment | BLE | WiFi | 4G Modem | Audio DAC | Web Reader | Max Contacts |
|
||||
|---------|------------|-----|------|----------|-----------|------------|-------------|
|
||||
| Audio + BLE | `meck_audio_ble` | Yes | Yes (via BLE stack) | — | PCM5102A | Yes | 500 |
|
||||
| Audio + Standalone | `meck_audio_standalone` | — | — | — | PCM5102A | No | 1,500 |
|
||||
| 4G + BLE | `meck_4g_ble` | Yes | Yes | A7682E | — | Yes | 500 |
|
||||
| 4G + Standalone | `meck_4g_standalone` | — | Yes | A7682E | — | Yes | 1,500 |
|
||||
| Audio + BLE | `meck_audio_ble` | Yes | Yes (web reader only) | — | PCM5102A | Yes | 2,000 |
|
||||
| Audio + WiFi | `meck_audio_wifi` | — | Yes (TCP:5000) | — | PCM5102A | Yes | 2,000 |
|
||||
| Audio + Standalone | `meck_audio_standalone` | — | — | — | PCM5102A | No | 2,000 |
|
||||
| 4G + BLE | `meck_4g_ble` | Yes | Yes | A7682E | — | Yes | 2,000 |
|
||||
| 4G + WiFi | `meck_4g_wifi` | — | Yes (TCP:5000) | A7682E | — | Yes | 2,000 |
|
||||
| 4G + Standalone | `meck_4g_standalone` | — | Yes | A7682E | — | Yes | 2,000 |
|
||||
| Remote Repeater (4G) | `meck_remote_repeater` | — | — | A7682E (MQTT) | — | No | — |
|
||||
| WiFi Repeater | `meck_wifi_repeater` | — | Yes (MQTT) | — | — | No | — |
|
||||
|
||||
The audio DAC and 4G modem occupy the same hardware slot and are mutually exclusive.
|
||||
The audio DAC and 4G modem occupy the same hardware slot and are mutually exclusive. The remote repeater and WiFi repeater variants operate as dedicated MeshCore repeaters — they forward mesh traffic and respond to guest logins as normal, but **admin management is handled remotely via MQTT** through the [Meck-Mycelium dashboard](https://pelgraine.github.io/Meck-Mycelium), not via the standard mesh admin password login. See [Remote Repeater](#remote-repeater-t-deck-pro-4g) and [WiFi Repeater](#wifi-repeater) below.
|
||||
|
||||
### T-Deck Pro Keyboard Controls
|
||||
|
||||
@@ -174,9 +218,13 @@ The T-Deck Pro firmware includes full keyboard support for standalone messaging
|
||||
| B | Open web browser (BLE and 4G variants only) |
|
||||
| T | Open SMS & Phone app (4G variant only) |
|
||||
| P | Open audiobook player (audio variant only) |
|
||||
| K | Open alarm clock (audio variant only) |
|
||||
| F | Open node discovery (search for nearby repeaters/nodes) |
|
||||
| H | Open last heard list (passive advert history) |
|
||||
| G | Open map screen (shows contacts with GPS positions) |
|
||||
| Mic | Open voice messages (audio variant only) |
|
||||
| Q | Back to home screen |
|
||||
| Double-click Boot | Lock / unlock screen |
|
||||
|
||||
### Bluetooth (BLE)
|
||||
|
||||
@@ -184,12 +232,27 @@ BLE is **disabled by default** at boot to support standalone-first operation. Th
|
||||
|
||||
To connect to the MeshCore companion app, navigate to the **Bluetooth** home page (use D to page through) and press **Enter** to toggle BLE on. The BLE PIN will be displayed on screen. Toggle it off again the same way when you're done.
|
||||
|
||||
### WiFi Companion
|
||||
|
||||
The WiFi companion variants (`meck_audio_wifi`, `meck_4g_wifi`) connect to the MeshCore web app, meshcore.js, or Python CLI over your local network via TCP on port 5000. WiFi credentials are stored on the SD card at `/web/wifi.cfg`.
|
||||
|
||||
**Connecting:**
|
||||
|
||||
1. Navigate to the **WiFi** home page (use D to page through)
|
||||
2. Press **Enter** to toggle WiFi on
|
||||
3. The device scans for networks — select yours and enter the password
|
||||
4. Once connected, the IP address is displayed on the WiFi home page
|
||||
|
||||
Connect the MeshCore web app or meshcore.js to `<device IP>:5000`.
|
||||
|
||||
WiFi is also used by the web reader and IRC client on WiFi variants. The web reader shares the same connection — no extra setup needed.
|
||||
|
||||
### Clock & Timezone
|
||||
|
||||
The T-Deck Pro does not include a dedicated RTC chip, so after each reboot the device clock starts unset. The clock will appear in the nav bar (between node name and battery) once the time has been synced by one of two methods:
|
||||
The T-Deck Pro does not include a dedicated RTC chip, so after each reboot the device clock starts unset. The clock will appear in the nav bar (between node name and battery) once the time has been synced by one of these methods:
|
||||
|
||||
1. **GPS fix** (standalone) — Once the GPS acquires a satellite fix, the time is automatically synced from the NMEA data. No phone or BLE connection required. Typical time to first fix is 30–90 seconds outdoors with clear sky.
|
||||
2. **BLE companion app** — If BLE is enabled and connected to the MeshCore companion app, the app will push the current time to the device.
|
||||
2. **BLE/WiFi companion app** — If connected to the MeshCore companion app (via BLE or WiFi), the app will push the current time to the device.
|
||||
|
||||
**Setting your timezone:**
|
||||
|
||||
@@ -211,7 +274,7 @@ The GPS page also shows the current time, satellite count, position, altitude, a
|
||||
| Key | Action |
|
||||
|-----|--------|
|
||||
| W / S | Scroll messages up/down |
|
||||
| A / D | Switch between channels |
|
||||
| A / D | Switch between channels (press D past the last channel to reach the DM inbox, A to return) |
|
||||
| Enter | Compose new message |
|
||||
| R | Reply to a message — enter reply select mode, scroll to a message with W/S, then press Enter to compose a reply with an @mention |
|
||||
| V | View relay path of the last received message (scrollable, up to 20 hops) |
|
||||
@@ -219,23 +282,96 @@ The GPS page also shows the current time, satellite count, position, altitude, a
|
||||
|
||||
### Contacts Screen
|
||||
|
||||
Press **C** from the home screen to open the contacts list. All known mesh contacts are shown sorted by most recently seen, with their type (Chat, Repeater, Room, Sensor), hop count, and time since last advert.
|
||||
Press **C** from the home screen to open the contacts list. All known mesh contacts are shown sorted by most recently heard, with their type prefix, estimated hop count, and time since last advert.
|
||||
|
||||
**Contact type prefixes**
|
||||
|
||||
| Prefix | Type |
|
||||
|--------|------|
|
||||
| C | Chat node |
|
||||
| R | Repeater |
|
||||
| RS | Room server |
|
||||
| ? | Unknown / sensor |
|
||||
|
||||
**Hop count display**
|
||||
|
||||
| Display | Meaning |
|
||||
|---------|---------|
|
||||
| `D` | Direct path known (path exchange completed) |
|
||||
| `D*` | Direct path, manually locked |
|
||||
| `N` | N-hop path known (e.g. `2` = 2 hops) |
|
||||
| `N*` | N-hop path, manually locked |
|
||||
| `~D` | Heard direct via flood advert (no path exchange yet) |
|
||||
| `~N` | Estimated N hops via flood advert |
|
||||
| `?` | No path information available |
|
||||
|
||||
Flood-based hop estimates (`~D`, `~N`) are shown for the 12 most recently heard contacts and reset to `?` on reboot until each contact re-advertises. Confirmed path values (`D`, `N`) persist until overwritten by a new path exchange.
|
||||
|
||||
**Normal mode controls**
|
||||
|
||||
| Key | Action |
|
||||
|-----|--------|
|
||||
| W / S | Scroll up / down through contacts |
|
||||
| A / D | Cycle filter: All → Chat → Repeater → Room → Sensor → Favourites |
|
||||
| Enter | Open DM compose (Chat contact) or repeater admin (Repeater contact) |
|
||||
| X | Export contacts to SD card (wait 5–10 seconds for confirmation popup) |
|
||||
| R | Import contacts from SD card (wait 5–10 seconds for confirmation popup) |
|
||||
| A / D | Cycle filter: All → Chat → Rptr → Room → Sens → Fav |
|
||||
| Enter | Enter select mode (highlights current contact, enables batch operations) |
|
||||
| P | Open path editor for the highlighted contact |
|
||||
| Q | Back to home screen |
|
||||
|
||||
**Contact limits:** Standalone variants support up to 1,500 contacts (stored in PSRAM). BLE variants (both Audio-BLE and 4G-BLE) are limited to 500 contacts due to BLE protocol constraints.
|
||||
> **Note:** The **Fav** filter shows only contacts you have marked as favourites. If it appears empty, no contacts have been favourited yet — use select mode (Enter) and then **F** to mark contacts.
|
||||
|
||||
**Select mode** — press Enter from the contacts list to enter select mode. The highlighted contact is pre-selected. Use W/S to scroll and Enter to toggle selection on any row.
|
||||
|
||||
| Key | Action |
|
||||
|-----|--------|
|
||||
| W / S | Scroll up / down |
|
||||
| Enter | Toggle selection on current contact |
|
||||
| A | Select all contacts in current filter |
|
||||
| D | Deselect all |
|
||||
| F | Toggle favourite on all selected contacts |
|
||||
| X | Export selected contacts to SD card |
|
||||
| Backspace | Delete selected contacts |
|
||||
| Q | Exit select mode |
|
||||
|
||||
**Adding contacts**
|
||||
|
||||
Contacts can be added three ways:
|
||||
|
||||
1. **Automatic** — if Settings → Contacts → Add Mode is set to *Auto All*, any node whose advert is heard is added automatically. *Custom* mode adds only nodes matching the enabled type toggles (Companion, Repeater, Room Server, Sensor) — each toggle controls whether receiving an advert of that type triggers an auto-add. *Manual Only* disables all auto-add.
|
||||
|
||||
2. **From the Last Heard screen** — press **H** from the home screen to open the last-heard advert list. Scroll to the node you want and press **Enter** (or tap the row) to add it to contacts. Press **Enter** again on an existing contact to remove it (favourites require a second press within 3 seconds to confirm). Entries show `[+]` if already in contacts, `[★]` if a favourite.
|
||||
|
||||
> **Note:** The Last Heard list holds up to 1,000 entries in PSRAM, and advert data is stored persistently on the SD card — so contacts can be added long after the original advertisement was received, even across reboots. This makes Last Heard especially useful when auto-add is set to *Manual Only*, as it provides a passive catalogue of every node heard on the network.
|
||||
|
||||
3. **From the Discovery screen** — press **F** from the home screen to run an active discovery scan. Nodes that respond appear in a list; press **Enter** on any entry to add it to contacts.
|
||||
|
||||
**Deleting contacts**
|
||||
|
||||
Enter select mode (Enter), select the contacts to remove (Enter to toggle, A to select all), then press **Backspace** to delete. You will be returned to the contacts list once the deletion is complete.
|
||||
|
||||
**Exporting and importing contacts**
|
||||
|
||||
In select mode, press **X** to export. If contacts are selected, only those contacts are exported; if none are selected, all contacts are exported. Contacts are saved as a JSON file to `/meshcore/` on the SD card with a timestamp in the filename. The JSON format is compatible with MeshCore companion apps — you can copy the file from the SD card and import it into the Android, iOS, or web companion app.
|
||||
|
||||
Press **R** on the contacts list (outside select mode) to import contacts from a JSON file on the SD card. The most recent export file in `/meshcore/` is used automatically.
|
||||
|
||||
**Contact limits:** All variants support up to 2,000 contacts (stored in PSRAM).
|
||||
|
||||
### Sending a Direct Message
|
||||
|
||||
Select a **Chat** contact in the contacts list and press **Enter** to start composing a direct message. The compose screen will show `DM: ContactName` in the header. Type your message and press **Enter** to send. The DM is sent encrypted directly to that contact (or flooded if no direct path is known). After sending or cancelling, you're returned to the contacts list.
|
||||
|
||||
Contacts with unread direct messages show a `*` marker next to their name in the contacts list.
|
||||
|
||||
**Reading received DMs:** On the Channel Messages screen, press **D** past the last group channel to reach the **DM inbox**. This shows all received direct messages with sender name and timestamp. Entering the DM inbox marks all DM messages as read and clears the unread indicator. Press **A** to return to group channels.
|
||||
|
||||
### Roomservers
|
||||
|
||||
Room servers are MeshCore nodes that host persistent chat rooms. Messages sent to a room server are stored and relayed to anyone who logs in. In Meck, room server messages arrive as contact messages and appear in the DM inbox alongside regular direct messages.
|
||||
|
||||
To interact with a room server, navigate to the Contacts screen, filter to **Room** contacts, select the room, and press **Enter** to open the Repeater Admin screen. Log in with the room's admin password to access room administration. On successful login, all unread messages from that room are automatically marked as read.
|
||||
|
||||
Room server messages are also synced to the companion app when connected via BLE or WiFi — the companion app will pull and display them alongside other messages.
|
||||
|
||||
### Repeater Admin Screen
|
||||
|
||||
Select a **Repeater** contact in the contacts list and press **Enter** to open the repeater admin screen. You'll be prompted for the repeater's admin password. Characters briefly appear as you type them before being masked, making it easier to enter symbols and numbers on the T-Deck Pro keyboard.
|
||||
@@ -266,8 +402,8 @@ Press **S** from the home screen to open settings. On first boot (when the devic
|
||||
| Key | Action |
|
||||
|-----|--------|
|
||||
| W / S | Navigate up / down through settings |
|
||||
| Enter | Edit selected setting |
|
||||
| Q | Back to home screen |
|
||||
| Enter | Edit selected setting, or enter a sub-screen |
|
||||
| Q | Back one level (sub-screen → top level → home screen) |
|
||||
|
||||
**Available settings:**
|
||||
|
||||
@@ -275,17 +411,38 @@ Press **S** from the home screen to open settings. On first boot (when the devic
|
||||
|---------|-------------|
|
||||
| Device Name | Text entry — type a name, Enter to confirm |
|
||||
| Radio Preset | A / D to cycle presets (MeshCore Default, Long Range, Fast/Short, EU Default), Enter to apply |
|
||||
| Frequency | W / S to adjust, Enter to confirm |
|
||||
| Frequency | Text entry — type exact value (e.g. 916.575), Enter to confirm |
|
||||
| Bandwidth | W / S to cycle standard values (31.25 / 62.5 / 125 / 250 / 500 kHz), Enter to confirm |
|
||||
| Spreading Factor | W / S to adjust (5–12), Enter to confirm |
|
||||
| Coding Rate | W / S to adjust (5–8), Enter to confirm |
|
||||
| TX Power | W / S to adjust (1–20 dBm), Enter to confirm |
|
||||
| UTC Offset | W / S to adjust (-12 to +14), Enter to confirm |
|
||||
| Path Hash Mode | A / D to cycle (0 = 1-byte, 1 = 2-byte, 2 = 3-byte), Enter to confirm |
|
||||
| Channels | View existing channels, add hashtag channels, or delete non-primary channels (X) |
|
||||
| Msg Rcvd LED Pulse | Toggle keyboard backlight flash on new message (Enter to toggle) |
|
||||
| GPS Baud Rate | A / D to cycle (Default 38400 / 4800 / 9600 / 19200 / 38400 / 57600 / 115200), Enter to confirm. **Requires reboot to take effect.** |
|
||||
| Path Hash Mode | W / S to cycle (1-byte / 2-byte / 3-byte), Enter to confirm |
|
||||
| Dark Mode | Toggle inverted display — white text on black background (Enter to toggle) |
|
||||
| Larger Font | Toggle larger text size on channel messages, contacts, DM inbox, and repeater admin screens (Enter to toggle) |
|
||||
| Auto Lock | A / D to cycle timeout (None / 2 / 5 / 10 / 15 / 30 min), Enter to confirm |
|
||||
| Contacts >> | Opens the Contacts sub-screen (see below) |
|
||||
| Channels >> | Opens the Channels sub-screen (see below) |
|
||||
| OTA Tools >> | Opens the OTA sub-screen — Firmware Update and SD File Manager (see [OTA Firmware Update](#ota-firmware-update-v13)) |
|
||||
| Device Info | Public key and firmware version (read-only) |
|
||||
|
||||
The bottom of the settings screen also displays your node ID and firmware version. On the 4G variant, IMEI, carrier name, and APN details are shown here as well.
|
||||
**Contacts sub-screen** — press Enter on the `Contacts >>` row to open. Contains the contact auto-add mode picker and, when set to Custom, per-type toggles:
|
||||
|
||||
| Toggle | Meaning when ON |
|
||||
|--------|----------------|
|
||||
| Companion | Auto-add a chat node when its advert is heard |
|
||||
| Repeater | Auto-add repeaters heard via advert |
|
||||
| Room Server | Auto-add room servers heard via advert |
|
||||
| Sensor | Auto-add sensor nodes heard via advert |
|
||||
| Overwrite Oldest | When the contact list is full, overwrite the oldest non-favourite entry instead of discarding the new contact |
|
||||
|
||||
Press Q to return to the top-level settings list.
|
||||
|
||||
**Channels sub-screen** — press Enter on the `Channels >>` row to open. Lists all current channels, with an option to add hashtag channels or delete non-primary channels (X). Press Q to return to the top-level settings list.
|
||||
|
||||
The top-level settings screen also displays your node ID and firmware version. On the 4G variant, IMEI, carrier name, and APN details are shown here as well.
|
||||
|
||||
When adding a hashtag channel, type the channel name and press Enter. The channel secret is automatically derived from the name via SHA-256, matching the standard MeshCore hashtag convention.
|
||||
|
||||
@@ -329,7 +486,7 @@ Press the **Sym** key then the letter key to enter numbers and symbols:
|
||||
|
||||
### Emoji Picker
|
||||
|
||||
While in compose mode, press the **$** key to open the emoji picker. A scrollable grid of 47 emoji is displayed in a 5-column layout.
|
||||
While in compose mode, press the **$** key to open the emoji picker. A scrollable grid of emoji is displayed in a 5-column layout.
|
||||
|
||||
| Key | Action |
|
||||
|-----|--------|
|
||||
@@ -346,7 +503,7 @@ For full documentation including key mappings, dialpad usage, contacts managemen
|
||||
|
||||
### Web Browser & IRC
|
||||
|
||||
Press **B** from the home screen to open the web reader. This is available on the BLE and 4G variants (not the standalone audio variant, which excludes WiFi to preserve lowest-battery-usage design).
|
||||
Press **B** from the home screen to open the web reader. This is available on the BLE, WiFi, and 4G variants (not the standalone audio variant, which excludes WiFi to preserve lowest-battery-usage design).
|
||||
|
||||
The web reader home screen provides access to the **IRC client**, the **URL bar**, and your **bookmarks** and **history**. Select IRC Chat and press Enter to configure and connect to an IRC server. Select the URL bar to enter a web address, or scroll down to open a bookmark or history entry.
|
||||
|
||||
@@ -354,6 +511,136 @@ The browser is a text-centric reader best suited to text-heavy websites. It also
|
||||
|
||||
For full documentation including key mappings, WiFi setup, bookmarks, IRC configuration, and SD card structure, see the [Web App Guide](Web_App_Guide.md).
|
||||
|
||||
### Alarm Clock (Audio only)
|
||||
|
||||
Press **K** from the home screen to open the alarm clock. This is available on the audio variant of the T-Deck Pro (PCM5102A DAC). Set up to five daily alarms that play custom MP3 files through the headphone jack.
|
||||
|
||||
**Setup:**
|
||||
|
||||
1. Place MP3 files (44100 Hz sample rate) in `/alarms/` on the SD card
|
||||
2. Press **K** to open the alarm clock
|
||||
3. Select an alarm slot (1–5) with **W / S** and press **Enter** to edit
|
||||
4. Set the hour and minute, then choose an MP3 file from the list
|
||||
5. Press **Enter** to save the alarm
|
||||
|
||||
| Key | Action |
|
||||
|-----|--------|
|
||||
| W / S | Navigate alarm slots / adjust time |
|
||||
| A / D | Switch between hour and minute fields |
|
||||
| Enter | Edit slot / save alarm / select MP3 |
|
||||
| X | Delete selected alarm |
|
||||
| Q | Back to home screen |
|
||||
|
||||
**When an alarm fires:**
|
||||
|
||||
The selected MP3 plays through the headphone jack, even if you're on another screen or playing an audiobook.
|
||||
|
||||
| Key | Action |
|
||||
|-----|--------|
|
||||
| Z | Snooze for 5 minutes |
|
||||
| Any other key | Dismiss alarm |
|
||||
|
||||
Alarm configuration is stored in `/alarms/.alarmcfg` on the SD card. Alarms persist across reboots — if the RTC has valid time (via GPS or companion app sync), alarms fire at the correct time after a restart.
|
||||
|
||||
> **Note:** MP3 files should be encoded at **44100 Hz** sample rate. Lower sample rates may cause distortion due to ESP32-S3 I2S hardware limitations (same requirement as the audiobook player).
|
||||
|
||||
**SD Card Folder Structure:**
|
||||
|
||||
```
|
||||
SD Card
|
||||
├── alarms/
|
||||
│ ├── .alarmcfg (auto-created, stores alarm slot config)
|
||||
│ ├── morning-chime.mp3
|
||||
│ ├── rooster.mp3
|
||||
│ └── gentle-bells.mp3
|
||||
├── audiobooks/ (existing — audiobook player)
|
||||
│ └── ...
|
||||
├── books/ (existing — text reader)
|
||||
│ └── ...
|
||||
└── ...
|
||||
```
|
||||
|
||||
### Voice Notes Over LoRa (Audio only)
|
||||
|
||||
Press the **Microphone key** (the zero key on the keyboard) to open the Voice Messages screen. This is available on the audio variant of the T-Deck Pro (PCM5102A DAC).
|
||||
|
||||
Record and send voice messages of up to 12 seconds over LoRa. Audio is encoded on-device using Codec2 at 1200 bps, compressing each second of speech into a single 150-byte LoRa packet. Voice notes use very little airtime relative to what they deliver — a 5-second message is just 5 packets.
|
||||
|
||||
Voice notes can be sent to another T-Deck Pro Audio device (plays automatically through the headphone jack) or to any MeshCore companion device connected to the [Meck-Mycelium web app](https://pelgraine.github.io/Meck-Mycelium) (plays through your phone's speaker as a tappable bubble in the DM view).
|
||||
|
||||
**Sending a voice note:**
|
||||
|
||||
1. Press the **Microphone key** to open the Voice Messages screen
|
||||
2. Press and **hold** the Microphone key to record — release to stop (max 12 seconds)
|
||||
3. Press **S** to open the contact picker — contacts with a direct path appear at the top
|
||||
4. Scroll to your contact and press **Enter** to send
|
||||
|
||||
Packets are sent with staggered 3-second delays to avoid congesting the channel. On a 62.5 kHz / SF7 radio preset (e.g. Australia Narrow), a 5-second voice note arrives in roughly 20 seconds and a 12-second recording in about 42 seconds.
|
||||
|
||||
**Receiving voice notes:**
|
||||
|
||||
* **On a T-Deck Pro Audio device:** the voice message screen opens automatically and the message plays through the headphone jack. **Headphones are recommended** — the built-in speaker is very quiet.
|
||||
* **Via Meck-Mycelium:** voice messages appear as "🎙️ Voice message" bubbles in the DM view. Tap to play. Codec2 decoding happens entirely in the browser via WebAssembly.
|
||||
|
||||
> **Note:** Voice recording and sending requires the **Audio variant** hardware (PCM5102A DAC). Receiving and playback works on all Audio variants. Non-audio Meck devices can receive and relay voice packets but cannot play them locally — use the Meck-Mycelium web app for playback on those devices.
|
||||
|
||||
| Key | Action |
|
||||
|-----|--------|
|
||||
| Mic (hold) | Record voice note |
|
||||
| Mic (release) | Stop recording |
|
||||
| S | Open contact picker to send |
|
||||
| Enter | Send to selected contact |
|
||||
| Q | Back to home screen |
|
||||
|
||||
### Lock Screen (T-Deck Pro)
|
||||
|
||||
Double-click the Boot button to lock the screen. The lock screen shows the current time, battery percentage, and unread message count. The CPU drops to 40 MHz while locked to reduce power consumption.
|
||||
|
||||
Double-click the Boot button again to unlock and return to whatever screen you were on.
|
||||
|
||||
An auto-lock timer can be configured in **Settings → Auto Lock** (None / 2 / 5 / 10 / 15 / 30 minutes of idle time).
|
||||
|
||||
---
|
||||
|
||||
## Remote Repeater (T-Deck Pro 4G)
|
||||
|
||||
> **TODO — This section needs full documentation.** The feature is implemented and shipping. Draft outline below.
|
||||
|
||||
The remote repeater variant (`meck_remote_repeater`) turns a T-Deck Pro 4G board into a dedicated MeshCore repeater with cellular MQTT remote management. The repeater functions as a normal MeshCore repeater on the mesh — it forwards packets and responds to guest logins — but **admin management (clock sync, send advert, reboot, get status, configuration) is performed remotely via MQTT** through the [Meck-Mycelium dashboard](https://pelgraine.github.io/Meck-Mycelium), not via the standard mesh admin password login. The device connects to an MQTT broker (HiveMQ Cloud recommended — free tier available) over cellular data, publishing telemetry (uptime, battery, signal strength, temperature, neighbour count) and subscribing to admin commands.
|
||||
|
||||
**Sections to write:**
|
||||
|
||||
- **Requirements** — T-Deck Pro 4G (A7682E), active SIM with data plan, SD card, MQTT broker account
|
||||
- **Setting up HiveMQ Cloud** — step-by-step free account creation, cluster setup, credentials
|
||||
- **SD card configuration** — `/remote/mqtt.cfg` (broker, port, username, password, device ID) and optional `/remote/apn.cfg`
|
||||
- **Deploying** — flash `meck_remote_repeater`, insert SIM and SD, boot sequence, display status indicators
|
||||
- **Dashboard usage** — connecting Meck-Mycelium to your MQTT broker, available commands (clock sync, send advert, reboot, get status), telemetry display
|
||||
- **Troubleshooting** — common issues (SIM not registering, MQTT auth failures, APN auto-detection)
|
||||
|
||||
---
|
||||
|
||||
## WiFi Repeater
|
||||
|
||||
> **TODO — This section needs full documentation.** The feature is implemented. Draft outline below.
|
||||
|
||||
The WiFi repeater variants turn a device into a dedicated MeshCore repeater with WiFi MQTT remote management — similar to the cellular remote repeater but using WiFi instead of 4G. The repeater forwards mesh traffic and responds to guest logins as normal, but **admin management is performed remotely via MQTT** through the Meck-Mycelium dashboard, not via the standard mesh admin password login. Available for the following platforms:
|
||||
|
||||
| Variant | Environment | Platform |
|
||||
|---------|------------|----------|
|
||||
| T-Deck Pro WiFi Repeater | `meck_wifi_repeater` | LilyGo T-Deck Pro |
|
||||
| T5S3 WiFi Repeater | `meck_wifi_repeater_t5s3` | LilyGo T5S3 E-Paper Pro |
|
||||
| Heltec V3 WiFi Repeater | `meck_wifi_repeater_heltec_v3` | Heltec V3 |
|
||||
| Heltec V4 WiFi Repeater | `meck_wifi_repeater_heltec_v4` | Heltec V4 |
|
||||
| Heltec V4 WiFi Repeater (headless) | `meck_wifi_repeater_heltec_v4_headless` | Heltec V4 (no display) |
|
||||
|
||||
**Sections to write:**
|
||||
|
||||
- **Requirements** — device, WiFi network, MQTT broker account, SD card (T-Deck Pro / T5S3) or SPIFFS config (Heltec V4)
|
||||
- **SD card configuration** — `/remote/wifi.cfg` (supports multiple SSIDs) and `/remote/mqtt.cfg`
|
||||
- **Heltec V4 specifics** — no SD card slot, config stored in SPIFFS, headless vs display variant
|
||||
- **OTA updates** — NTP time sync, HTTP firmware download over WiFi
|
||||
- **Dashboard** — same Meck-Mycelium dashboard as the cellular remote repeater
|
||||
|
||||
---
|
||||
|
||||
## T5S3 E-Paper Pro
|
||||
@@ -364,11 +651,12 @@ The LilyGo T5S3 E-Paper Pro (V2, H752-B) is a 4.7-inch e-ink device with capacit
|
||||
|
||||
| Variant | Environment | BLE | WiFi | Web Reader | Max Contacts |
|
||||
|---------|------------|-----|------|------------|-------------|
|
||||
| Standalone | `meck_t5s3_standalone` | — | — | No | 1,500 |
|
||||
| BLE Companion | `meck_t5s3_ble` | Yes | — | No | 500 |
|
||||
| WiFi Companion | `meck_t5s3_wifi` | — | Yes (TCP:5000) | Yes | 1,500 |
|
||||
| Standalone | `meck_t5s3_standalone` | — | — | No | 2,000 |
|
||||
| BLE Companion | `meck_t5s3_ble` | Yes | — | No | 2,000 |
|
||||
| WiFi Companion | `meck_t5s3_wifi` | — | Yes (TCP:5000) | Yes | 2,000 |
|
||||
| WiFi Repeater | `meck_wifi_repeater_t5s3` | — | Yes (MQTT) | No | — |
|
||||
|
||||
The WiFi variant connects to the MeshCore web app or meshcore.js over your local network. The web reader shares the same WiFi connection — no extra setup needed.
|
||||
The WiFi variant connects to the MeshCore web app or meshcore.js over your local network. The web reader shares the same WiFi connection — no extra setup needed. The WiFi Repeater variant is a dedicated remote repeater — see [WiFi Repeater](#wifi-repeater) for details on MQTT-based admin management.
|
||||
|
||||
### Touch Navigation
|
||||
|
||||
@@ -423,6 +711,8 @@ Long press the Boot button to lock the device. The lock screen shows:
|
||||
|
||||
Touch input is completely disabled while locked. Long press the Boot button again to unlock and return to whatever screen you were on.
|
||||
|
||||
An auto-lock timer can be configured in **Settings → Auto Lock** (None / 2 / 5 / 10 / 15 / 30 minutes of idle time). The CPU drops to 40 MHz while locked to reduce power consumption.
|
||||
|
||||
### Virtual Keyboard
|
||||
|
||||
Since the T5S3 has no physical keyboard, a full-screen QWERTY virtual keyboard appears automatically when text input is needed (composing messages, entering WiFi passwords, editing settings, etc.).
|
||||
@@ -430,19 +720,28 @@ Since the T5S3 has no physical keyboard, a full-screen QWERTY virtual keyboard a
|
||||
The virtual keyboard supports:
|
||||
- QWERTY letter layout with a symbol/number layer (tap the **123** key to switch)
|
||||
- Shift toggle for uppercase
|
||||
- Backspace and Enter keys
|
||||
- Backspace (UTF-8 aware — correctly deletes multi-byte emoji) and Enter keys
|
||||
- **Emoji picker** — tap the **$** key to open a scrollable grid of emoji sprites. Tap an emoji to insert it inline in your message. Tap **Back** to return to the keyboard.
|
||||
- Inline emoji rendering — emoji appear as pixel sprites in the text field as you type
|
||||
- Phantom keystroke prevention (a brief cooldown after the keyboard opens prevents accidental taps)
|
||||
|
||||
Tap keys to type. Tap **Enter** to submit, or press the **Boot button** to cancel and close the keyboard.
|
||||
|
||||
### External Keyboard (CardKB)
|
||||
|
||||
The T5S3 supports the M5Stack CardKB (or compatible I2C keyboard) connected via the QWIIC port. When detected at boot, the CardKB can be used for all text input — composing messages, entering URLs, editing notes, and navigating menus — without the on-screen virtual keyboard.
|
||||
|
||||
The CardKB is auto-detected on the I2C bus at address `0x5F`. No configuration is needed — just plug it in.
|
||||
|
||||
### Display Settings
|
||||
|
||||
The T5S3 Settings screen includes two additional options not available on the T-Deck Pro:
|
||||
The T5S3 Settings screen includes one additional display option not available on the T-Deck Pro:
|
||||
|
||||
| Setting | Description |
|
||||
|---------|-------------|
|
||||
| **Dark Mode** | Inverts the display — white text on black background. Tap to toggle on/off. |
|
||||
| **Portrait Mode** | Rotates the display 90° from landscape (960×540) to portrait (540×960). Touch coordinates are automatically remapped. Text reader layout recalculates on orientation change. |
|
||||
| **Dark Mode** | Inverts the display — white text on black background. Tap to toggle on/off. Available on both T-Deck Pro and T5S3. |
|
||||
| **Larger Font** | Increases text size on channel messages, contacts, DM inbox, and repeater admin screens. Tap to toggle on/off. Available on both T-Deck Pro and T5S3. |
|
||||
| **Portrait Mode** | Rotates the display 90° from landscape (960×540) to portrait (540×960). Touch coordinates are automatically remapped. Text reader layout recalculates on orientation change. T5S3 only. |
|
||||
|
||||
These settings are persisted and survive reboots.
|
||||
|
||||
@@ -481,20 +780,52 @@ The UTC offset is configured in the Settings screen (same as T-Deck Pro) and is
|
||||
| Gesture | Action |
|
||||
|---------|--------|
|
||||
| Swipe up / down | Scroll messages |
|
||||
| Swipe left / right | Switch between channels |
|
||||
| Swipe left / right | Switch between channels (swipe left past the last channel to reach the DM inbox) |
|
||||
| Tap footer area | View relay path of last received message |
|
||||
| Tap path overlay | Dismiss overlay |
|
||||
| Long press (touch) | Open virtual keyboard to compose message to current channel |
|
||||
|
||||
#### Contacts
|
||||
|
||||
The contacts list shows all known nodes sorted by most recently heard, with type prefix, estimated hop count, and time since last advert. See the [T-Deck Pro Contacts Screen](#contacts-screen) section for an explanation of the type prefix and hop count display — the same conventions apply on the T5S3.
|
||||
|
||||
**Normal mode**
|
||||
|
||||
| Gesture | Action |
|
||||
|---------|--------|
|
||||
| Swipe up / down | Scroll through contacts |
|
||||
| Swipe left / right | Cycle contact filter (All → Chat → Repeater → Room → Sensor → Favourites) |
|
||||
| Tap | Select contact |
|
||||
| Long press on Chat contact | Open virtual keyboard to compose DM |
|
||||
| Long press on Repeater contact | Open repeater admin login |
|
||||
| Swipe left / right | Cycle contact filter (All → Chat → Rptr → Room → Sens → Fav) |
|
||||
| Tap | Enter select mode (tapped contact is pre-selected) |
|
||||
| Long press on Chat contact | View unread DMs (if any), then compose DM |
|
||||
| Long press on Repeater/RS contact | Open repeater admin login |
|
||||
|
||||
> **Note:** The **Fav** filter shows only contacts you have marked as favourites. If it appears empty, no contacts have been favourited yet — use select mode (tap a contact) and then long-press to mark favourites.
|
||||
|
||||
**Select mode** — tap any contact row to enter select mode. The tapped contact is pre-selected (shown with `*`). Swipe or tap to navigate and toggle selections. You can also use a **two-finger tap** anywhere on the contacts screen to toggle select mode on and off.
|
||||
|
||||
| Gesture | Action |
|
||||
|---------|--------|
|
||||
| Tap | Toggle selection on tapped row |
|
||||
| Swipe left | Select all contacts in current filter |
|
||||
| Swipe right | Deselect all |
|
||||
| Two-finger tap | Toggle select mode on/off |
|
||||
| Long press | Exit select mode (confirm favourites / deletions first) |
|
||||
|
||||
Batch operations (favourite toggle, delete) are triggered from the overlay that appears after exiting select mode with contacts selected.
|
||||
|
||||
**Adding contacts**
|
||||
|
||||
1. **Automatic** — if Settings → Contacts → Add Mode is set to *Auto All*, nodes are added as their adverts are heard. *Custom* mode adds only nodes matching the enabled type toggles (Companion, Repeater, Room Server, Sensor). *Manual Only* disables auto-add.
|
||||
|
||||
2. **From the Last Heard screen** — tap the **Discover** tile (or access via the home page on non-WiFi builds) and navigate to Last Heard. Tap any entry to add it to contacts, or tap an existing contact to remove it (favourites require a second tap within 3 seconds to confirm). Entries show `[+]` if already in contacts, `[★]` if a favourite.
|
||||
|
||||
> **Note:** The Last Heard list holds up to 1,000 entries in PSRAM, and advert data is stored persistently on the SD card — so contacts can be added long after the original advertisement was received, even across reboots. This makes Last Heard especially useful when auto-add is set to *Manual Only*, as it provides a passive catalogue of every node heard on the network.
|
||||
|
||||
3. **From the Discovery screen** — tap the Discover tile and run an active scan. Tap any result to add it to contacts.
|
||||
|
||||
**Deleting contacts**
|
||||
|
||||
Tap a contact to enter select mode, select the contacts to remove, exit select mode, and choose delete from the confirmation overlay.
|
||||
|
||||
#### Text Reader (File List)
|
||||
|
||||
@@ -508,6 +839,7 @@ The UTC offset is configured in the Settings screen (same as T-Deck Pro) and is
|
||||
| Gesture | Action |
|
||||
|---------|--------|
|
||||
| Tap anywhere | Next page |
|
||||
| Tap footer bar | Go to page number (via virtual keyboard) |
|
||||
| Swipe left | Next page |
|
||||
| Swipe right | Previous page |
|
||||
| Swipe up / down | Next / previous page |
|
||||
@@ -548,8 +880,16 @@ The UTC offset is configured in the Settings screen (same as T-Deck Pro) and is
|
||||
| Gesture | Action |
|
||||
|---------|--------|
|
||||
| Swipe up / down | Scroll node list |
|
||||
| Tap | Add selected node to contacts |
|
||||
| Long press | Rescan for nodes |
|
||||
|
||||
#### Last Heard
|
||||
|
||||
| Gesture | Action |
|
||||
|---------|--------|
|
||||
| Swipe up / down | Scroll advert list |
|
||||
| Tap | Add to or delete from contacts |
|
||||
|
||||
#### Repeater Admin
|
||||
|
||||
| Gesture | Action |
|
||||
@@ -565,6 +905,22 @@ The UTC offset is configured in the Settings screen (same as T-Deck Pro) and is
|
||||
|
||||
---
|
||||
|
||||
## Meck-Mycelium Web App
|
||||
|
||||
The [Meck-Mycelium web app](https://pelgraine.github.io/Meck-Mycelium) is a browser-based companion that connects to your MeshCore device via BLE (using WebBLE in Chrome) or to your MQTT broker for remote repeater management.
|
||||
|
||||
**Features:**
|
||||
|
||||
- **Voice message playback** — voice notes sent from a Meck Audio device appear as tappable playback bubbles in the DM view. Codec2 decoding happens entirely in the browser via WebAssembly — no app install or audio hardware needed on the receiving end.
|
||||
- **Remote repeater dashboard** — connect to your MQTT broker to administer remote repeater devices (cellular or WiFi). View live telemetry, send admin commands (clock sync, send advert, reboot, get status), and manage repeaters that are out of LoRa range. This replaces the standard mesh admin password login for remote repeater variants.
|
||||
- **Standard companion features** — messaging, contacts, channel messages via BLE.
|
||||
|
||||
Open **https://pelgraine.github.io/Meck-Mycelium** in Chrome on your phone or computer.
|
||||
|
||||
> **Note:** WebBLE requires Chrome (or a Chromium-based browser). Safari and Firefox do not support WebBLE.
|
||||
|
||||
---
|
||||
|
||||
## About MeshCore
|
||||
|
||||
MeshCore is a lightweight, portable C++ library that enables multi-hop packet routing for embedded projects using LoRa and other packet radios. It is designed for developers who want to create resilient, decentralized communication networks that work without the internet.
|
||||
@@ -610,11 +966,12 @@ For developers:
|
||||
|
||||
**Companion Firmware**
|
||||
|
||||
The companion firmware can be connected to via BLE (T-Deck Pro and T5S3 BLE variants) or WiFi (T5S3 WiFi variant, TCP port 5000).
|
||||
The companion firmware can be connected to via BLE (T-Deck Pro and T5S3 BLE variants) or WiFi (T-Deck Pro WiFi variants and T5S3 WiFi variant, TCP port 5000).
|
||||
|
||||
> **Note:** On both the T-Deck Pro and T5S3, BLE is disabled by default at boot. On the T-Deck Pro, navigate to the Bluetooth home page and press Enter to enable BLE. On the T5S3, navigate to the Bluetooth home page and long-press the screen to toggle BLE on.
|
||||
> **Note:** On both the T-Deck Pro and T5S3, BLE and WiFi are disabled by default at boot. On the T-Deck Pro, navigate to the Bluetooth or WiFi home page and press Enter to enable. On the T5S3, navigate to the Bluetooth home page and long-press the screen to toggle BLE on.
|
||||
|
||||
- Web: https://app.meshcore.nz
|
||||
- Meck-Mycelium: https://pelgraine.github.io/Meck-Mycelium (voice playback, remote repeater dashboard)
|
||||
- Android: https://play.google.com/store/apps/details?id=com.liamcottle.meshcore.android
|
||||
- iOS: https://apps.apple.com/us/app/meshcore/id6742354151?platform=iphone
|
||||
- NodeJS: https://github.com/liamcottle/meshcore.js
|
||||
@@ -622,7 +979,7 @@ The companion firmware can be connected to via BLE (T-Deck Pro and T5S3 BLE vari
|
||||
|
||||
## 🛠 Hardware Compatibility
|
||||
|
||||
MeshCore is designed for devices listed in the [MeshCore Flasher](https://flasher.meshcore.co.uk). Meck specifically targets the LilyGo T-Deck Pro and LilyGo T5S3 E-Paper Pro.
|
||||
MeshCore is designed for devices listed in the [MeshCore Flasher](https://flasher.meshcore.co.uk). Meck specifically targets the LilyGo T-Deck Pro, LilyGo T5S3 E-Paper Pro, Heltec V3 (remote repeater only), and Heltec V4 (remote repeater only).
|
||||
|
||||
## Contributing
|
||||
|
||||
@@ -649,17 +1006,34 @@ There are a number of fairly major features in the pipeline, with no particular
|
||||
- [X] Settings screen with radio presets, channel management, and first-boot onboarding
|
||||
- [X] Expand SMS app to enable phone calls
|
||||
- [X] Basic web reader app with IRC client
|
||||
- [X] Lock screen with auto-lock timer and low-power standby
|
||||
- [X] Last heard passive advert list
|
||||
- [X] Touch-to-select on contacts, discovery, settings, text reader, notes screens
|
||||
- [X] Map screen with GPS tile rendering
|
||||
- [X] WiFi companion environment
|
||||
- [X] OTA firmware update via phone
|
||||
- [X] DM inbox with per-contact unread indicators
|
||||
- [X] Roomserver message handling and mark-read on login
|
||||
- [X] Alarm clock with custom MP3 sounds (audio variant)
|
||||
- [X] Customised user option for larger-font mode
|
||||
- [X] Voice notes over LoRa (Codec2, audio variant)
|
||||
- [X] Contact select mode with batch favourite, export, import, and delete
|
||||
- [X] Path editor for manual contact route management
|
||||
- [X] Remote repeater with cellular MQTT admin management (4G variant)
|
||||
- [X] WiFi remote repeater with MQTT admin management
|
||||
- [X] SD File Manager via OTA Tools
|
||||
- [X] 2,000 contact support (PSRAM, all variants)
|
||||
- [ ] Fix M4B rendering to enable chaptered audiobook playback
|
||||
- [ ] Better JPEG and PNG decoding
|
||||
- [ ] Improve EPUB rendering and EPUB format handling
|
||||
- [ ] Map support with GPS
|
||||
- [ ] WiFi companion environment
|
||||
- [ ] Figure out a way to silence the ringtone
|
||||
- [ ] Figure out a way to customise the ringtone
|
||||
|
||||
**T5S3 E-Paper Pro:**
|
||||
- [X] Core port: display, touch input, LoRa, battery, RTC
|
||||
- [X] Touch-navigable home screen with tappable tile grid
|
||||
- [X] Full virtual keyboard for text entry
|
||||
- [X] Lock screen with clock, battery, and unread count
|
||||
- [X] Lock screen with clock, battery, unread count, and auto-lock timer
|
||||
- [X] Backlight control (double/triple-click Boot button)
|
||||
- [X] Dark mode and portrait mode display settings
|
||||
- [X] Channel messages with swipe navigation and touch compose
|
||||
@@ -668,9 +1042,28 @@ There are a number of fairly major features in the pipeline, with no particular
|
||||
- [X] Web reader with virtual keyboard URL/search entry (WiFi variant)
|
||||
- [X] Settings screen with touch editing
|
||||
- [X] Serial clock sync for hardware RTC
|
||||
- [ ] Emoji sprites on home tiles
|
||||
- [ ] Portrait mode toggle via quadruple-click Boot button
|
||||
- [ ] Hibernate should auto-off backlight
|
||||
- [X] CardKB external keyboard support (via QWIIC)
|
||||
- [X] Last heard passive advert list
|
||||
- [X] Tap-to-select on contacts, discovery, settings, text reader, notes screens
|
||||
- [X] OTA firmware update via phone (WiFi variant)
|
||||
- [X] DM inbox with per-contact unread indicators
|
||||
- [X] Roomserver message handling and mark-read on login
|
||||
- [X] Customised user option for larger-font mode
|
||||
- [X] Contact select mode with batch favourite and delete
|
||||
- [X] WiFi remote repeater with MQTT admin management
|
||||
- [X] 2,000 contact support (PSRAM, all variants)
|
||||
- [ ] Improve EPUB rendering and EPUB format handling
|
||||
|
||||
**Heltec V4:**
|
||||
- [X] WiFi remote repeater with MQTT admin management
|
||||
- [X] Headless WiFi repeater variant (no display)
|
||||
|
||||
**Heltec V3:**
|
||||
- [X] WiFi remote repeater with MQTT admin management
|
||||
|
||||
**In development (WIP):**
|
||||
- [ ] T-Deck Pro MAX — ESP32-S3 with XL9555 I/O expander, combined 4G (A7682E) + audio (ES8311), working e-ink front-light, 1500 mAh battery. LoRa mesh, keyboard, display, GPS, touch, SD card all working. Modem and ES8311 audio integration pending hardware validation.
|
||||
- [ ] T-Echo Card — nRF52840 (BLE-native) with SX1262, SSD1315 OLED (72×40), L76K GPS, speaker, PDM mic, IMU, solar charging, NFC. Preliminary variant files created; awaiting hardware.
|
||||
|
||||
## 📞 Get Support
|
||||
|
||||
@@ -698,5 +1091,7 @@ However, this firmware links against libraries with different license terms. Bec
|
||||
| [CRC32](https://github.com/bakercp/CRC32) | MIT | Christopher Baker |
|
||||
| [base64](https://github.com/Densaugeo/base64_arduino) | MIT | densaugeo |
|
||||
| [Arduino Crypto](https://github.com/rweather/arduinolibs) | MIT | Rhys Weatherley |
|
||||
| [PubSubClient](https://github.com/knolleary/pubsubclient) | MIT | Nick O'Leary |
|
||||
| [Codec2](https://github.com/sh123/esp32_codec2_arduino) | LGPL-2.1 | sh123 (ESP32 port) |
|
||||
|
||||
Full license texts for each dependency are available in their respective repositories linked above.
|
||||
@@ -57,6 +57,7 @@ All commands follow a simple pattern: `get` to read, `set` to write.
|
||||
| `get radio` | All radio params in one line |
|
||||
| `get utc` | UTC offset (hours) |
|
||||
| `get notify` | Keyboard flash notification (on/off) |
|
||||
| `get largefont` | Larger font mode (on/off) |
|
||||
| `get gps` | GPS status and interval |
|
||||
| `get pin` | BLE pairing PIN |
|
||||
| `get path.hash.mode` | Path hash size (0=1-byte, 1=2-byte, 2=3-byte) |
|
||||
@@ -64,6 +65,8 @@ All commands follow a simple pattern: `get` to read, `set` to write.
|
||||
| `get af` | Airtime factor |
|
||||
| `get multi.acks` | Redundant ACKs (0 or 1) |
|
||||
| `get int.thresh` | Interference threshold (0=disabled) |
|
||||
| `get tx.fail.reset` | TX fail reset threshold (0=disabled, default 3) |
|
||||
| `get rx.fail.reboot` | RX stuck reboot threshold (0=disabled, default 3) |
|
||||
| `get gps.baud` | GPS baud rate (0=compile-time default) |
|
||||
| `get channels` | List all channels with index numbers |
|
||||
| `get presets` | List all radio presets with parameters |
|
||||
@@ -164,6 +167,15 @@ set notify on
|
||||
set notify off
|
||||
```
|
||||
|
||||
#### Larger Font Mode
|
||||
|
||||
Toggle larger text on channel messages, contacts, DM inbox, and repeater admin screens:
|
||||
|
||||
```
|
||||
set largefont on
|
||||
set largefont off
|
||||
```
|
||||
|
||||
#### BLE PIN
|
||||
|
||||
```
|
||||
@@ -231,6 +243,28 @@ set int.thresh 0
|
||||
|
||||
Values: 0 (disabled, default) or 14+ (14 is the typical setting). Values between 1–13 are not functional and will be rejected.
|
||||
|
||||
#### TX Fail Reset Threshold (tx.fail.reset)
|
||||
|
||||
Automatically resets the radio hardware after this many consecutive failed transmission attempts. This recovers from "zombie radio" states where the SX1262 stops responding to send commands.
|
||||
|
||||
```
|
||||
set tx.fail.reset 3
|
||||
set tx.fail.reset 0
|
||||
```
|
||||
|
||||
Values: 0 (disabled) or 1–10 (default: 3). After the threshold is reached, the radio is reset and the failed packet is re-queued.
|
||||
|
||||
#### RX Stuck Reboot Threshold (rx.fail.reboot)
|
||||
|
||||
Automatically reboots the device after this many consecutive RX-stuck recovery failures. An RX-stuck event occurs when the radio is not in receive mode for 8 seconds despite automatic recovery attempts.
|
||||
|
||||
```
|
||||
set rx.fail.reboot 3
|
||||
set rx.fail.reboot 0
|
||||
```
|
||||
|
||||
Values: 0 (disabled) or 1–10 (default: 3). A full device reboot is a last resort — this should only trigger in rare cases of persistent radio hardware malfunction.
|
||||
|
||||
#### GPS Baud Rate (gps.baud)
|
||||
|
||||
Override the GPS serial baud rate. The default (0) uses the compile-time value of 38400. **Requires a reboot to take effect** — the GPS serial port is only configured at startup.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
## Overview
|
||||
|
||||
This adds a text reader accessible via the **R** key from the home screen.
|
||||
This adds a text reader accessible via the **E** key from the home screen.
|
||||
|
||||
**Features:**
|
||||
- Browse `.txt` and `.epub` files from `/books/` folder on SD card
|
||||
@@ -13,17 +13,27 @@ This adds a text reader accessible via the **R** key from the home screen.
|
||||
- Index files cached to SD for instant re-opens
|
||||
- Bookmark indicator (`*`) on files with saved positions
|
||||
|
||||
**Key Mapping:**
|
||||
**Key Mapping (T-Deck Pro):**
|
||||
| Context | Key | Action |
|
||||
|---------|-----|--------|
|
||||
| Home screen | E | Open text reader |
|
||||
| File list | W/S | Navigate up/down |
|
||||
| File list | Enter | Open selected file |
|
||||
| File list | Tap / Enter | Open selected file |
|
||||
| File list | Q | Back to home screen |
|
||||
| Reading | W/A | Previous page |
|
||||
| Reading | S/D/Space/Enter | Next page |
|
||||
| Reading | S/D/Space | Next page |
|
||||
| Reading | Enter | Go to page number (type digits, Enter to confirm, Q to cancel) |
|
||||
| Reading | Q | Close book → file list |
|
||||
| Reading | C | Enter compose mode |
|
||||
|
||||
**Touch Gestures (T5S3):**
|
||||
| Context | Gesture | Action |
|
||||
|---------|---------|--------|
|
||||
| File list | Swipe up/down | Scroll file list |
|
||||
| File list | Tap | Open selected book |
|
||||
| Reading | Tap | Next page |
|
||||
| Reading | Swipe left/right | Next / previous page |
|
||||
| Reading | Tap footer | Go to page number (via virtual keyboard) |
|
||||
| Reading | Long press | Close book → file list |
|
||||
|
||||
---
|
||||
|
||||
@@ -113,4 +123,4 @@ The conversion is handled by three components:
|
||||
- Page content is pre-read from SD into a memory buffer during `handleInput()`, then rendered from buffer during `render()` — this avoids SPI bus conflicts during display refresh
|
||||
- Layout metrics (chars per line, lines per page) are calculated dynamically from the display driver's font metrics on first entry
|
||||
- EPUB conversion runs synchronously in `openBook()` — the e-ink splash screen keeps the user informed while the ESP32 processes the archive
|
||||
- ZIP extraction uses the ESP32-S3's hardware-optimised ROM `tinfl` inflate, avoiding external compression library dependencies and the linker conflicts they cause
|
||||
- ZIP extraction uses the ESP32-S3's hardware-optimised ROM `tinfl` inflate, avoiding external compression library dependencies and the linker conflicts they cause
|
||||
@@ -39,7 +39,7 @@
|
||||
"frameworks": ["arduino"],
|
||||
"name": "Heltec nrf (Adafruit BSP)",
|
||||
"upload": {
|
||||
"maximum_ram_size": 248832,
|
||||
"maximum_ram_size": 235520,
|
||||
"maximum_size": 815104,
|
||||
"speed": 115200,
|
||||
"protocol": "nrfutil",
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"build": {
|
||||
"arduino": {
|
||||
"ldscript": "nrf52840_s140_v6.ld"
|
||||
},
|
||||
"core": "nRF5",
|
||||
"cpu": "cortex-m4",
|
||||
"extra_flags": [
|
||||
"-DARDUINO_NRF52840_TECHO_CARD",
|
||||
"-DNRF52840_XXAA",
|
||||
"-DNRF52_SERIES"
|
||||
],
|
||||
"f_cpu": "64000000L",
|
||||
"hwids": [["0x239A", "0x8029"]],
|
||||
"mcu": "nrf52840",
|
||||
"variant": "lilygo_techo_card",
|
||||
"bsp": {
|
||||
"name": "adafruit"
|
||||
},
|
||||
"softdevice": {
|
||||
"sd_name": "s140",
|
||||
"sd_version": "6.1.1",
|
||||
"sd_fwid": "0x00B6"
|
||||
},
|
||||
"usb_product": "T-Echo Card"
|
||||
},
|
||||
"connectivity": ["bluetooth", "lora"],
|
||||
"debug": {
|
||||
"jlink_device": "nRF52840_xxAA",
|
||||
"openocd_target": "nrf52840"
|
||||
},
|
||||
"frameworks": ["arduino"],
|
||||
"name": "LilyGo T-Echo Card (nRF52840, SX1262, 4MB Flash)",
|
||||
"upload": {
|
||||
"flash_size": "796KB",
|
||||
"maximum_ram_size": 248832,
|
||||
"maximum_size": 815104,
|
||||
"native_usb": true,
|
||||
"protocol": "nrfutil",
|
||||
"protocols": ["nrfutil", "jlink", "cmsis-dap"],
|
||||
"require_upload_port": true,
|
||||
"speed": 115200,
|
||||
"use_1200bps_touch": true,
|
||||
"wait_for_upload_port": true
|
||||
},
|
||||
"url": "https://github.com/Xinyuan-LilyGO/T-Echo-Card",
|
||||
"vendor": "LILYGO"
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"build": {
|
||||
"arduino": {
|
||||
"ldscript": "esp32s3_out.ld",
|
||||
"memory_type": "qio_qspi",
|
||||
"partitions": "default_16MB.csv"
|
||||
},
|
||||
"core": "esp32",
|
||||
"extra_flags": [
|
||||
"-DBOARD_HAS_PSRAM",
|
||||
"-DARDUINO_USB_CDC_ON_BOOT=1",
|
||||
"-DARDUINO_USB_MODE=1",
|
||||
"-DARDUINO_RUNNING_CORE=1",
|
||||
"-DARDUINO_EVENT_RUNNING_CORE=1"
|
||||
],
|
||||
"f_cpu": "240000000L",
|
||||
"f_flash": "80000000L",
|
||||
"flash_mode": "qio",
|
||||
"hwids": [["0x303A", "0x1001"]],
|
||||
"mcu": "esp32s3",
|
||||
"variant": "esp32s3"
|
||||
},
|
||||
"connectivity": ["wifi", "bluetooth", "lora"],
|
||||
"debug": {
|
||||
"default_tool": "esp-builtin",
|
||||
"onboard_tools": ["esp-builtin"],
|
||||
"openocd_target": "esp32s3.cfg"
|
||||
},
|
||||
"frameworks": ["arduino", "espidf"],
|
||||
"name": "LilyGo T-Deck Pro MAX (16MB Flash 8MB QSPI PSRAM)",
|
||||
"upload": {
|
||||
"flash_size": "16MB",
|
||||
"maximum_ram_size": 327680,
|
||||
"maximum_size": 16777216,
|
||||
"require_upload_port": true,
|
||||
"speed": 921600
|
||||
},
|
||||
"url": "https://www.lilygo.cc/products/t-deck-pro",
|
||||
"vendor": "LilyGo"
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
6818ce5f77dd45bb90facf753ba81d81.s1.eu.hivemq.cloud
|
||||
8883
|
||||
meckremote
|
||||
yourpassword
|
||||
heltec-wifi-1
|
||||
@@ -0,0 +1,2 @@
|
||||
SSID
|
||||
Password
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "DataStore.h"
|
||||
|
||||
#if defined(EXTRAFS) || defined(QSPIFLASH)
|
||||
#define MAX_BLOBRECS 100
|
||||
#define MAX_BLOBRECS 1000
|
||||
#else
|
||||
#define MAX_BLOBRECS 20
|
||||
#endif
|
||||
@@ -252,6 +252,50 @@ void DataStore::loadPrefsInt(const char *filename, NodePrefs& _prefs, double& no
|
||||
if (_prefs.path_hash_mode > 2) _prefs.path_hash_mode = 0;
|
||||
if (_prefs.autoadd_max_hops > 64) _prefs.autoadd_max_hops = 0;
|
||||
|
||||
// v1.1+ Meck fields — may not exist in older prefs files
|
||||
if (file.read((uint8_t *)&_prefs.gps_baudrate, sizeof(_prefs.gps_baudrate)) != sizeof(_prefs.gps_baudrate)) {
|
||||
_prefs.gps_baudrate = 0; // default: use compile-time GPS_BAUDRATE
|
||||
}
|
||||
if (file.read((uint8_t *)&_prefs.interference_threshold, sizeof(_prefs.interference_threshold)) != sizeof(_prefs.interference_threshold)) {
|
||||
_prefs.interference_threshold = 0; // default: disabled
|
||||
}
|
||||
if (file.read((uint8_t *)&_prefs.dark_mode, sizeof(_prefs.dark_mode)) != sizeof(_prefs.dark_mode)) {
|
||||
_prefs.dark_mode = 0; // default: light mode
|
||||
}
|
||||
if (file.read((uint8_t *)&_prefs.portrait_mode, sizeof(_prefs.portrait_mode)) != sizeof(_prefs.portrait_mode)) {
|
||||
_prefs.portrait_mode = 0; // default: landscape
|
||||
}
|
||||
if (file.read((uint8_t *)&_prefs.auto_lock_minutes, sizeof(_prefs.auto_lock_minutes)) != sizeof(_prefs.auto_lock_minutes)) {
|
||||
_prefs.auto_lock_minutes = 0; // default: disabled
|
||||
}
|
||||
if (file.read((uint8_t *)&_prefs.hint_shown, sizeof(_prefs.hint_shown)) != sizeof(_prefs.hint_shown)) {
|
||||
_prefs.hint_shown = 0; // default: show boot hint
|
||||
}
|
||||
if (file.read((uint8_t *)&_prefs.large_font, sizeof(_prefs.large_font)) != sizeof(_prefs.large_font)) {
|
||||
_prefs.large_font = 0; // default: tiny font
|
||||
}
|
||||
if (file.read((uint8_t *)&_prefs.tx_fail_reset_threshold, sizeof(_prefs.tx_fail_reset_threshold)) != sizeof(_prefs.tx_fail_reset_threshold)) {
|
||||
_prefs.tx_fail_reset_threshold = 3; // default: 3
|
||||
}
|
||||
if (file.read((uint8_t *)&_prefs.rx_fail_reboot_threshold, sizeof(_prefs.rx_fail_reboot_threshold)) != sizeof(_prefs.rx_fail_reboot_threshold)) {
|
||||
_prefs.rx_fail_reboot_threshold = 3; // default: 3
|
||||
}
|
||||
|
||||
// Clamp to valid ranges
|
||||
if (_prefs.dark_mode > 1) _prefs.dark_mode = 0;
|
||||
if (_prefs.portrait_mode > 1) _prefs.portrait_mode = 0;
|
||||
if (_prefs.hint_shown > 1) _prefs.hint_shown = 0;
|
||||
if (_prefs.large_font > 1) _prefs.large_font = 0;
|
||||
if (_prefs.tx_fail_reset_threshold > 10) _prefs.tx_fail_reset_threshold = 3;
|
||||
if (_prefs.rx_fail_reboot_threshold > 10) _prefs.rx_fail_reboot_threshold = 3;
|
||||
// auto_lock_minutes: only accept known options (0, 2, 5, 10, 15, 30)
|
||||
{
|
||||
uint8_t alm = _prefs.auto_lock_minutes;
|
||||
if (alm != 0 && alm != 2 && alm != 5 && alm != 10 && alm != 15 && alm != 30) {
|
||||
_prefs.auto_lock_minutes = 0;
|
||||
}
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
@@ -291,6 +335,15 @@ void DataStore::savePrefs(const NodePrefs& _prefs, double node_lat, double node_
|
||||
file.write((uint8_t *)&_prefs.ringtone_enabled, sizeof(_prefs.ringtone_enabled)); // 90
|
||||
file.write((uint8_t *)&_prefs.path_hash_mode, sizeof(_prefs.path_hash_mode)); // 91
|
||||
file.write((uint8_t *)&_prefs.autoadd_max_hops, sizeof(_prefs.autoadd_max_hops)); // 92
|
||||
file.write((uint8_t *)&_prefs.gps_baudrate, sizeof(_prefs.gps_baudrate)); // 93
|
||||
file.write((uint8_t *)&_prefs.interference_threshold, sizeof(_prefs.interference_threshold)); // 97
|
||||
file.write((uint8_t *)&_prefs.dark_mode, sizeof(_prefs.dark_mode)); // 98
|
||||
file.write((uint8_t *)&_prefs.portrait_mode, sizeof(_prefs.portrait_mode)); // 99
|
||||
file.write((uint8_t *)&_prefs.auto_lock_minutes, sizeof(_prefs.auto_lock_minutes)); // 100
|
||||
file.write((uint8_t *)&_prefs.hint_shown, sizeof(_prefs.hint_shown)); // 101
|
||||
file.write((uint8_t *)&_prefs.large_font, sizeof(_prefs.large_font)); // 102
|
||||
file.write((uint8_t *)&_prefs.tx_fail_reset_threshold, sizeof(_prefs.tx_fail_reset_threshold)); // 103
|
||||
file.write((uint8_t *)&_prefs.rx_fail_reboot_threshold, sizeof(_prefs.rx_fail_reboot_threshold)); // 104
|
||||
|
||||
file.close();
|
||||
}
|
||||
@@ -443,6 +496,112 @@ void DataStore::saveContacts(DataStoreHost* host) {
|
||||
}
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Chunked contact save — non-blocking across multiple loop iterations
|
||||
// =========================================================================
|
||||
|
||||
bool DataStore::beginSaveContacts(DataStoreHost* host) {
|
||||
if (_saveInProgress) return false; // Already saving
|
||||
|
||||
FILESYSTEM* fs = _getContactsChannelsFS();
|
||||
// Defensive cleanup in case a previous save didn't reach finishSaveContacts()
|
||||
if (_saveFile) {
|
||||
_saveFile->close();
|
||||
delete _saveFile;
|
||||
_saveFile = nullptr;
|
||||
}
|
||||
_saveFile = new File(openWrite(fs, "/contacts3.tmp"));
|
||||
if (!_saveFile || !*_saveFile) {
|
||||
Serial.println("DataStore: chunked save FAILED — cannot open tmp file");
|
||||
if (_saveFile) { delete _saveFile; _saveFile = nullptr; }
|
||||
return false;
|
||||
}
|
||||
|
||||
_saveHost = host;
|
||||
_saveIdx = 0;
|
||||
_saveRecordsWritten = 0;
|
||||
_saveWriteOk = true;
|
||||
_saveInProgress = true;
|
||||
Serial.println("DataStore: chunked save started");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DataStore::saveContactsChunk(int batchSize) {
|
||||
if (!_saveInProgress || !_saveWriteOk) return false;
|
||||
|
||||
ContactInfo c;
|
||||
uint8_t unused = 0;
|
||||
int written = 0;
|
||||
|
||||
while (written < batchSize && _saveHost->getContactForSave(_saveIdx, c)) {
|
||||
bool success = (_saveFile->write(c.id.pub_key, 32) == 32);
|
||||
success = success && (_saveFile->write((uint8_t *)&c.name, 32) == 32);
|
||||
success = success && (_saveFile->write(&c.type, 1) == 1);
|
||||
success = success && (_saveFile->write(&c.flags, 1) == 1);
|
||||
success = success && (_saveFile->write(&unused, 1) == 1);
|
||||
success = success && (_saveFile->write((uint8_t *)&c.sync_since, 4) == 4);
|
||||
success = success && (_saveFile->write((uint8_t *)&c.out_path_len, 1) == 1);
|
||||
success = success && (_saveFile->write((uint8_t *)&c.last_advert_timestamp, 4) == 4);
|
||||
success = success && (_saveFile->write(c.out_path, 64) == 64);
|
||||
success = success && (_saveFile->write((uint8_t *)&c.lastmod, 4) == 4);
|
||||
success = success && (_saveFile->write((uint8_t *)&c.gps_lat, 4) == 4);
|
||||
success = success && (_saveFile->write((uint8_t *)&c.gps_lon, 4) == 4);
|
||||
|
||||
if (!success) {
|
||||
_saveWriteOk = false;
|
||||
Serial.printf("DataStore: chunked save write error at record %d\n", _saveIdx);
|
||||
return false; // Error — finishSaveContacts will clean up
|
||||
}
|
||||
|
||||
_saveRecordsWritten++;
|
||||
_saveIdx++;
|
||||
written++;
|
||||
}
|
||||
|
||||
// Check if there are more contacts to write
|
||||
ContactInfo peek;
|
||||
if (_saveHost->getContactForSave(_saveIdx, peek)) {
|
||||
return true; // More to write
|
||||
}
|
||||
return false; // Done
|
||||
}
|
||||
|
||||
void DataStore::finishSaveContacts() {
|
||||
if (!_saveInProgress) return;
|
||||
|
||||
if (_saveFile) {
|
||||
_saveFile->close();
|
||||
delete _saveFile;
|
||||
_saveFile = nullptr;
|
||||
}
|
||||
_saveInProgress = false;
|
||||
|
||||
FILESYSTEM* fs = _getContactsChannelsFS();
|
||||
const char* finalPath = "/contacts3";
|
||||
const char* tmpPath = "/contacts3.tmp";
|
||||
|
||||
// Verify
|
||||
size_t expectedBytes = _saveRecordsWritten * 152;
|
||||
File verify = openRead(fs, tmpPath);
|
||||
size_t bytesWritten = verify ? verify.size() : 0;
|
||||
if (verify) verify.close();
|
||||
|
||||
if (!_saveWriteOk || bytesWritten != expectedBytes) {
|
||||
Serial.printf("DataStore: chunked save ABORTED — wrote %d bytes, expected %d (%d records)\n",
|
||||
(int)bytesWritten, (int)expectedBytes, _saveRecordsWritten);
|
||||
fs->remove(tmpPath);
|
||||
return;
|
||||
}
|
||||
|
||||
fs->remove(finalPath);
|
||||
if (fs->rename(tmpPath, finalPath)) {
|
||||
Serial.printf("DataStore: saved %d contacts (%d bytes, chunked)\n",
|
||||
_saveRecordsWritten, (int)bytesWritten);
|
||||
} else {
|
||||
Serial.println("DataStore: rename failed, tmp file preserved");
|
||||
}
|
||||
}
|
||||
|
||||
void DataStore::loadChannels(DataStoreHost* host) {
|
||||
FILESYSTEM* fs = _getContactsChannelsFS();
|
||||
|
||||
@@ -543,16 +702,27 @@ struct BlobRec {
|
||||
};
|
||||
|
||||
void DataStore::checkAdvBlobFile() {
|
||||
if (!_getContactsChannelsFS()->exists("/adv_blobs")) {
|
||||
File file = openWrite(_getContactsChannelsFS(), "/adv_blobs");
|
||||
if (file) {
|
||||
BlobRec zeroes;
|
||||
memset(&zeroes, 0, sizeof(zeroes));
|
||||
for (int i = 0; i < MAX_BLOBRECS; i++) { // pre-allocate to fixed size
|
||||
file.write((uint8_t *) &zeroes, sizeof(zeroes));
|
||||
}
|
||||
file.close();
|
||||
FILESYSTEM* fs = _getContactsChannelsFS();
|
||||
size_t expectedSize = (size_t)MAX_BLOBRECS * sizeof(BlobRec);
|
||||
|
||||
if (fs->exists("/adv_blobs")) {
|
||||
File existing = openRead(fs, "/adv_blobs");
|
||||
size_t actualSize = existing ? (size_t)existing.size() : 0;
|
||||
if (existing) existing.close();
|
||||
if (actualSize == expectedSize) return; // already correct size
|
||||
Serial.printf("[DataStore] adv_blobs wrong size (%u vs %u) — recreating\n",
|
||||
(unsigned)actualSize, (unsigned)expectedSize);
|
||||
fs->remove("/adv_blobs"); // delete undersized (or oversized) file
|
||||
}
|
||||
|
||||
File file = openWrite(fs, "/adv_blobs");
|
||||
if (file) {
|
||||
BlobRec zeroes;
|
||||
memset(&zeroes, 0, sizeof(zeroes));
|
||||
for (int i = 0; i < MAX_BLOBRECS; i++) {
|
||||
file.write((uint8_t *) &zeroes, sizeof(zeroes));
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -725,10 +895,14 @@ uint8_t DataStore::getBlobByKey(const uint8_t key[], int key_len, uint8_t dest_b
|
||||
|
||||
if (key_len > 8) key_len = 8; // just use first 8 bytes (prefix)
|
||||
mesh::Utils::toHex(fname, key, key_len);
|
||||
// Prefer SD card (_fsExtra) — unlimited file count vs SPIFFS ~100-200 file limit.
|
||||
// Fall back to SPIFFS (_fs) for devices without SD.
|
||||
FILESYSTEM* blobFs = (_fsExtra != nullptr) ? _fsExtra : _fs;
|
||||
|
||||
sprintf(path, "/bl/%s", fname);
|
||||
|
||||
if (_fs->exists(path)) {
|
||||
File f = openRead(_fs, path);
|
||||
if (blobFs->exists(path)) {
|
||||
File f = openRead(blobFs, path);
|
||||
if (f) {
|
||||
int len = f.read(dest_buf, 255); // currently MAX 255 byte blob len supported!!
|
||||
f.close();
|
||||
@@ -744,15 +918,20 @@ bool DataStore::putBlobByKey(const uint8_t key[], int key_len, const uint8_t src
|
||||
|
||||
if (key_len > 8) key_len = 8; // just use first 8 bytes (prefix)
|
||||
mesh::Utils::toHex(fname, key, key_len);
|
||||
// Prefer SD card (_fsExtra) — unlimited file count vs SPIFFS ~100-200 file limit.
|
||||
FILESYSTEM* blobFs = (_fsExtra != nullptr) ? _fsExtra : _fs;
|
||||
|
||||
blobFs->mkdir("/bl"); // ensure directory exists on chosen filesystem
|
||||
|
||||
sprintf(path, "/bl/%s", fname);
|
||||
|
||||
File f = openWrite(_fs, path);
|
||||
File f = openWrite(blobFs, path);
|
||||
if (f) {
|
||||
int n = f.write(src_buf, len);
|
||||
f.close();
|
||||
if (n == len) return true; // success!
|
||||
|
||||
_fs->remove(path); // blob was only partially written!
|
||||
blobFs->remove(path); // blob was only partially written!
|
||||
}
|
||||
return false; // error
|
||||
}
|
||||
|
||||
@@ -24,6 +24,17 @@ class DataStore {
|
||||
void checkAdvBlobFile();
|
||||
#endif
|
||||
|
||||
// Chunked save state
|
||||
// Stored as a pointer (allocated in beginSaveContacts, freed in
|
||||
// finishSaveContacts) because Adafruit_LittleFS::File has no default
|
||||
// constructor — we can't keep one as a default-initialized value member.
|
||||
File* _saveFile = nullptr;
|
||||
DataStoreHost* _saveHost = nullptr;
|
||||
uint32_t _saveIdx = 0;
|
||||
uint32_t _saveRecordsWritten = 0;
|
||||
bool _saveInProgress = false;
|
||||
bool _saveWriteOk = true;
|
||||
|
||||
public:
|
||||
DataStore(FILESYSTEM& fs, mesh::RTCClock& clock);
|
||||
DataStore(FILESYSTEM& fs, FILESYSTEM& fsExtra, mesh::RTCClock& clock);
|
||||
@@ -37,6 +48,14 @@ public:
|
||||
void savePrefs(const NodePrefs& prefs, double node_lat, double node_lon);
|
||||
void loadContacts(DataStoreHost* host);
|
||||
void saveContacts(DataStoreHost* host);
|
||||
// Chunked save — splits contact write across multiple loop iterations
|
||||
// to prevent blocking the main loop for 500ms+ on large contact lists.
|
||||
// Call beginSaveContacts(), then saveContactsChunk() each loop until it
|
||||
// returns false (done), then finishSaveContacts() to verify and commit.
|
||||
bool beginSaveContacts(DataStoreHost* host);
|
||||
bool saveContactsChunk(int batchSize = 20); // returns true if more to write
|
||||
void finishSaveContacts();
|
||||
bool isSaveInProgress() const { return _saveInProgress; }
|
||||
void loadChannels(DataStoreHost* host);
|
||||
void saveChannels(DataStoreHost* host);
|
||||
void migrateToSecondaryFS();
|
||||
@@ -51,4 +70,4 @@ public:
|
||||
|
||||
private:
|
||||
FILESYSTEM* _getContactsChannelsFS() const { if (_fsExtra) return _fsExtra; return _fs;};
|
||||
};
|
||||
};
|
||||
@@ -12,6 +12,13 @@
|
||||
#include "ModemManager.h" // Serial CLI modem commands
|
||||
#endif
|
||||
|
||||
// Fallback for variants that don't define GPS_BAUDRATE (HAS_GPS=0 boards like
|
||||
// Heltec Meshpocket). Used in CLI "get/set gps.baud" handlers as the default
|
||||
// when node prefs haven't been configured. Zero means "not applicable".
|
||||
#ifndef GPS_BAUDRATE
|
||||
#define GPS_BAUDRATE 0
|
||||
#endif
|
||||
|
||||
#define CMD_APP_START 1
|
||||
#define CMD_SEND_TXT_MSG 2
|
||||
#define CMD_SEND_CHANNEL_TXT_MSG 3
|
||||
@@ -166,7 +173,7 @@ void MyMesh::writeDisabledFrame() {
|
||||
_serial->writeFrame(buf, 1);
|
||||
}
|
||||
|
||||
void MyMesh::writeContactRespFrame(uint8_t code, const ContactInfo &contact) {
|
||||
size_t MyMesh::writeContactRespFrame(uint8_t code, const ContactInfo &contact) {
|
||||
int i = 0;
|
||||
out_frame[i++] = code;
|
||||
memcpy(&out_frame[i], contact.id.pub_key, PUB_KEY_SIZE);
|
||||
@@ -186,7 +193,7 @@ void MyMesh::writeContactRespFrame(uint8_t code, const ContactInfo &contact) {
|
||||
i += 4;
|
||||
memcpy(&out_frame[i], &contact.lastmod, 4);
|
||||
i += 4;
|
||||
_serial->writeFrame(out_frame, i);
|
||||
return _serial->writeFrame(out_frame, i);
|
||||
}
|
||||
|
||||
void MyMesh::updateContactFromFrame(ContactInfo &contact, uint32_t& last_mod, const uint8_t *frame, int len) {
|
||||
@@ -264,6 +271,16 @@ int MyMesh::getInterferenceThreshold() const {
|
||||
return _prefs.interference_threshold;
|
||||
}
|
||||
|
||||
uint8_t MyMesh::getTxFailResetThreshold() const {
|
||||
return _prefs.tx_fail_reset_threshold;
|
||||
}
|
||||
uint8_t MyMesh::getRxFailRebootThreshold() const {
|
||||
return _prefs.rx_fail_reboot_threshold;
|
||||
}
|
||||
void MyMesh::onRxUnrecoverable() {
|
||||
board.reboot();
|
||||
}
|
||||
|
||||
int MyMesh::calcRxDelay(float score, uint32_t air_time) const {
|
||||
if (_prefs.rx_delay_base <= 0.0f) return 0;
|
||||
return (int)((pow(_prefs.rx_delay_base, 0.85f - score) - 1.0) * air_time);
|
||||
@@ -305,6 +322,7 @@ bool MyMesh::isAutoAddEnabled() const {
|
||||
}
|
||||
|
||||
bool MyMesh::shouldAutoAddContactType(uint8_t contact_type) const {
|
||||
if (_forceNextImport) return true; // explicit user add from Last Heard / Discovery
|
||||
if ((_prefs.manual_add_contacts & 1) == 0) {
|
||||
return true;
|
||||
}
|
||||
@@ -350,6 +368,7 @@ void MyMesh::onContactsFull() {
|
||||
}
|
||||
|
||||
void MyMesh::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path_len, const uint8_t* path) {
|
||||
_forceNextImport = false; // clear force-add flag (set by forceImportContact)
|
||||
if (_serial->isConnected()) {
|
||||
if (is_new) {
|
||||
writeContactRespFrame(PUSH_CODE_NEW_ADVERT, contact);
|
||||
@@ -380,6 +399,7 @@ void MyMesh::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path
|
||||
|
||||
memcpy(p->pubkey_prefix, contact.id.pub_key, sizeof(p->pubkey_prefix));
|
||||
strcpy(p->name, contact.name);
|
||||
p->type = contact.type;
|
||||
p->recv_timestamp = getRTCClock()->getCurrentTime();
|
||||
p->path_len = mesh::Packet::copyPath(p->path, path, path_len);
|
||||
}
|
||||
@@ -427,6 +447,10 @@ int MyMesh::getRecentlyHeard(AdvertPath dest[], int max_num) {
|
||||
return max_num;
|
||||
}
|
||||
|
||||
void MyMesh::scheduleLazyContactSave() {
|
||||
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY);
|
||||
}
|
||||
|
||||
void MyMesh::onContactPathUpdated(const ContactInfo &contact) {
|
||||
out_frame[0] = PUSH_CODE_PATH_UPDATED;
|
||||
memcpy(&out_frame[1], contact.id.pub_key, PUB_KEY_SIZE);
|
||||
@@ -493,7 +517,24 @@ void MyMesh::queueMessage(const ContactInfo &from, uint8_t txt_type, mesh::Packe
|
||||
bool should_display = txt_type == TXT_TYPE_PLAIN || txt_type == TXT_TYPE_SIGNED_PLAIN;
|
||||
if (should_display && _ui) {
|
||||
const uint8_t* msg_path = (pkt->isRouteFlood() && pkt->path_len > 0) ? pkt->path : nullptr;
|
||||
_ui->newMsg(path_len, from.name, text, offline_queue_len, msg_path, pkt->_snr);
|
||||
|
||||
// For signed messages (room server posts): the extra bytes contain the
|
||||
// original poster's pub_key prefix. Look up their name and format as
|
||||
// "PosterName: message" so the UI shows who actually wrote it.
|
||||
if (txt_type == TXT_TYPE_SIGNED_PLAIN && extra && extra_len >= 4) {
|
||||
ContactInfo* poster = lookupContactByPubKey(extra, extra_len);
|
||||
if (poster) {
|
||||
char formatted[MAX_PACKET_PAYLOAD];
|
||||
snprintf(formatted, sizeof(formatted), "%s: %s", poster->name, text);
|
||||
_ui->newMsg(path_len, from.name, formatted, offline_queue_len, msg_path, pkt->_snr);
|
||||
} else {
|
||||
// Poster not in contacts — show raw text (no name prefix)
|
||||
_ui->newMsg(path_len, from.name, text, offline_queue_len, msg_path, pkt->_snr);
|
||||
}
|
||||
} else {
|
||||
_ui->newMsg(path_len, from.name, text, offline_queue_len, msg_path, pkt->_snr);
|
||||
}
|
||||
|
||||
if (!_prefs.buzzer_quiet) _ui->notify(UIEventType::contactMessage); //buzz if enabled
|
||||
}
|
||||
#endif
|
||||
@@ -538,12 +579,12 @@ void MyMesh::sendFloodScoped(const ContactInfo& recipient, mesh::Packet* pkt, ui
|
||||
recipient.name, delay_millis, _prefs.path_hash_mode, _prefs.path_hash_mode + 1);
|
||||
// TODO: dynamic send_scope, depending on recipient and current 'home' Region
|
||||
if (send_scope.isNull()) {
|
||||
sendFlood(pkt, delay_millis, _prefs.path_hash_mode + 1);
|
||||
sendFlood(pkt, delay_millis, getPathHashSize());
|
||||
} else {
|
||||
uint16_t codes[2];
|
||||
codes[0] = send_scope.calcTransportCode(pkt);
|
||||
codes[1] = 0; // REVISIT: set to 'home' Region, for sender/return region?
|
||||
sendFlood(pkt, codes, delay_millis, _prefs.path_hash_mode + 1);
|
||||
sendFlood(pkt, codes, delay_millis, getPathHashSize());
|
||||
}
|
||||
}
|
||||
void MyMesh::sendFloodScoped(const mesh::GroupChannel& channel, mesh::Packet* pkt, uint32_t delay_millis) {
|
||||
@@ -560,18 +601,25 @@ void MyMesh::sendFloodScoped(const mesh::GroupChannel& channel, mesh::Packet* pk
|
||||
|
||||
// TODO: have per-channel send_scope
|
||||
if (send_scope.isNull()) {
|
||||
sendFlood(pkt, delay_millis, _prefs.path_hash_mode + 1);
|
||||
sendFlood(pkt, delay_millis, getPathHashSize());
|
||||
} else {
|
||||
uint16_t codes[2];
|
||||
codes[0] = send_scope.calcTransportCode(pkt);
|
||||
codes[1] = 0; // REVISIT: set to 'home' Region, for sender/return region?
|
||||
sendFlood(pkt, codes, delay_millis, _prefs.path_hash_mode + 1);
|
||||
sendFlood(pkt, codes, delay_millis, getPathHashSize());
|
||||
}
|
||||
}
|
||||
|
||||
void MyMesh::onMessageRecv(const ContactInfo &from, mesh::Packet *pkt, uint32_t sender_timestamp,
|
||||
const char *text) {
|
||||
markConnectionActive(from); // in case this is from a server, and we have a connection
|
||||
|
||||
// Detect VE3 voice envelope and notify voice handler
|
||||
if (_voiceEnvHandler && text && strncmp(text, "VE3:", 4) == 0) {
|
||||
MESH_DEBUG_PRINTLN("Voice: VE3 envelope from %s: %s", from.name, text);
|
||||
_voiceEnvHandler(from.name, text);
|
||||
}
|
||||
|
||||
queueMessage(from, TXT_TYPE_PLAIN, pkt, sender_timestamp, NULL, 0, text);
|
||||
}
|
||||
|
||||
@@ -714,6 +762,31 @@ bool MyMesh::uiSendDirectMessage(uint32_t contact_idx, const char* text) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MyMesh::uiSendRawToContact(uint32_t contact_idx, const uint8_t* data, uint8_t len) {
|
||||
ContactInfo contact;
|
||||
if (!getContactByIdx(contact_idx, contact)) return false;
|
||||
|
||||
ContactInfo* recipient = lookupContactByPubKey(contact.id.pub_key, PUB_KEY_SIZE);
|
||||
if (!recipient) return false;
|
||||
|
||||
// Raw custom packets are direct-route only — cannot flood
|
||||
if (recipient->out_path_len == OUT_PATH_UNKNOWN) {
|
||||
MESH_DEBUG_PRINTLN("UI: Raw send to %s failed — no direct path", recipient->name);
|
||||
return false;
|
||||
}
|
||||
|
||||
mesh::Packet* pkt = createRawData(data, len);
|
||||
if (!pkt) {
|
||||
MESH_DEBUG_PRINTLN("UI: Raw send to %s failed — packet pool empty", recipient->name);
|
||||
return false;
|
||||
}
|
||||
|
||||
sendDirect(pkt, recipient->out_path, recipient->out_path_len);
|
||||
MESH_DEBUG_PRINTLN("UI: Raw sent %d bytes to %s (direct, path_len=0x%02X)",
|
||||
len, recipient->name, recipient->out_path_len);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MyMesh::uiLoginToRepeater(uint32_t contact_idx, const char* password, uint32_t& est_timeout_ms) {
|
||||
ContactInfo contact;
|
||||
if (!getContactByIdx(contact_idx, contact)) {
|
||||
@@ -732,6 +805,13 @@ bool MyMesh::uiLoginToRepeater(uint32_t contact_idx, const char* password, uint3
|
||||
uint8_t save_path_len = recipient->out_path_len;
|
||||
recipient->out_path_len = OUT_PATH_UNKNOWN;
|
||||
|
||||
// For room servers: reset sync_since to zero so the server pushes ALL posts.
|
||||
// The device has no persistent DM storage, so every session needs full history.
|
||||
// sync_since naturally updates as messages arrive (BaseChatMesh::onPeerDataRecv).
|
||||
if (recipient->type == ADV_TYPE_ROOM) {
|
||||
recipient->sync_since = 0;
|
||||
}
|
||||
|
||||
Serial.printf("[uiLogin] Sending login to '%s' (idx=%d, path was 0x%02X, now 0x%02X, hash_mode=%d)\n",
|
||||
recipient->name, contact_idx, save_path_len, recipient->out_path_len, _prefs.path_hash_mode);
|
||||
|
||||
@@ -802,6 +882,43 @@ bool MyMesh::uiSendTelemetryRequest(uint32_t contact_idx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MyMesh::setCustomPath(int contactIdx, const uint8_t* path, uint8_t pathLen, bool lock) {
|
||||
ContactInfo contact;
|
||||
if (!getContactByIdx(contactIdx, contact)) return false;
|
||||
|
||||
ContactInfo* c = lookupContactByPubKey(contact.id.pub_key, PUB_KEY_SIZE);
|
||||
if (!c) return false;
|
||||
|
||||
c->out_path_len = pathLen;
|
||||
int byteLen = mesh::Packet::getPathByteLenFor(pathLen);
|
||||
if (byteLen > MAX_PATH_SIZE) byteLen = MAX_PATH_SIZE;
|
||||
memcpy(c->out_path, path, byteLen);
|
||||
c->lastmod = getRTCClock()->getCurrentTime();
|
||||
|
||||
if (lock) {
|
||||
c->flags |= CONTACT_FLAG_CUSTOM_PATH;
|
||||
}
|
||||
|
||||
MESH_DEBUG_PRINTLN("setCustomPath: contact %s, pathLen=0x%02X (%d hops, %dB/hop), lock=%d",
|
||||
c->name, pathLen, pathLen & 0x3F, ((pathLen >> 6) & 3) + 1, lock);
|
||||
return true;
|
||||
}
|
||||
|
||||
void MyMesh::clearCustomPath(int contactIdx) {
|
||||
ContactInfo contact;
|
||||
if (!getContactByIdx(contactIdx, contact)) return;
|
||||
|
||||
ContactInfo* c = lookupContactByPubKey(contact.id.pub_key, PUB_KEY_SIZE);
|
||||
if (!c) return;
|
||||
|
||||
c->out_path_len = OUT_PATH_UNKNOWN;
|
||||
memset(c->out_path, 0, MAX_PATH_SIZE);
|
||||
c->flags &= ~CONTACT_FLAG_CUSTOM_PATH;
|
||||
c->lastmod = getRTCClock()->getCurrentTime();
|
||||
|
||||
MESH_DEBUG_PRINTLN("clearCustomPath: contact %s — reverted to auto-discovery", c->name);
|
||||
}
|
||||
|
||||
uint8_t MyMesh::onContactRequest(const ContactInfo &contact, uint32_t sender_timestamp, const uint8_t *data,
|
||||
uint8_t len, uint8_t *reply) {
|
||||
if (data[0] == REQ_TYPE_GET_TELEMETRY_DATA) {
|
||||
@@ -972,6 +1089,13 @@ bool MyMesh::onContactPathRecv(ContactInfo& contact, uint8_t* in_path, uint8_t i
|
||||
}
|
||||
}
|
||||
// let base class handle received path and data
|
||||
// BUT: if this contact has a custom (manually set) path lock, don't let
|
||||
// auto-discovery overwrite it. Skip the base class call entirely — ACKs
|
||||
// embedded in path responses will still be delivered via separate ACK packets.
|
||||
if (contact.flags & CONTACT_FLAG_CUSTOM_PATH) {
|
||||
MESH_DEBUG_PRINTLN("onContactPathRecv: skipping path update for custom-path contact %s", contact.name);
|
||||
return false;
|
||||
}
|
||||
return BaseChatMesh::onContactPathRecv(contact, in_path, in_path_len, out_path, out_path_len, extra_type, extra, extra_len);
|
||||
}
|
||||
|
||||
@@ -1056,6 +1180,32 @@ void MyMesh::onRawDataRecv(mesh::Packet *packet) {
|
||||
MESH_DEBUG_PRINTLN("onRawDataRecv(), payload_len too long: %d", packet->payload_len);
|
||||
return;
|
||||
}
|
||||
|
||||
// Log ALL incoming raw packets for diagnosis
|
||||
Serial.printf("onRawDataRecv: len=%d, magic=0x%02X, route=%s\n",
|
||||
packet->payload_len,
|
||||
packet->payload_len > 0 ? packet->payload[0] : 0,
|
||||
packet->isRouteDirect() ? "direct" : "flood");
|
||||
|
||||
// Voice-over-LoRa (dz0ny VE3 protocol): intercept voice packets and fetch requests
|
||||
// before forwarding to BLE companion. In standalone mode (no BLE), this is the
|
||||
// only way to handle them. In BLE mode, we still intercept so on-device voice works.
|
||||
if (packet->payload_len > 1 && _voiceHandler) {
|
||||
uint8_t magic = packet->payload[0];
|
||||
if (magic == 0x56 || magic == 0x72) { // Voice data (V) or fetch request (r)
|
||||
Serial.printf("onRawDataRecv: voice %s, payload_len=%d, first6=[%02X %02X %02X %02X %02X %02X]\n",
|
||||
magic == 0x56 ? "PKT" : "FETCH", packet->payload_len,
|
||||
packet->payload[0],
|
||||
packet->payload_len > 1 ? packet->payload[1] : 0,
|
||||
packet->payload_len > 2 ? packet->payload[2] : 0,
|
||||
packet->payload_len > 3 ? packet->payload[3] : 0,
|
||||
packet->payload_len > 4 ? packet->payload[4] : 0,
|
||||
packet->payload_len > 5 ? packet->payload[5] : 0);
|
||||
_voiceHandler(magic, packet->payload, packet->payload_len);
|
||||
// Don't return — still forward to BLE companion if connected
|
||||
}
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
out_frame[i++] = PUSH_CODE_RAW_DATA;
|
||||
out_frame[i++] = (int8_t)(_radio->getLastSNR() * 4);
|
||||
@@ -1124,7 +1274,7 @@ MyMesh::MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMe
|
||||
next_ack_idx = 0;
|
||||
sign_data = NULL;
|
||||
dirty_contacts_expiry = 0;
|
||||
memset(advert_paths, 0, sizeof(advert_paths));
|
||||
advert_paths = nullptr; // PSRAM-allocated in begin()
|
||||
memset(send_scope.key, 0, sizeof(send_scope.key));
|
||||
memset(_sent_track, 0, sizeof(_sent_track));
|
||||
_sent_track_idx = 0;
|
||||
@@ -1151,16 +1301,34 @@ MyMesh::MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMe
|
||||
}
|
||||
|
||||
void MyMesh::begin(bool has_display) {
|
||||
#if defined(ESP32)
|
||||
// ESP32 variants have PSRAM — allocate the large advert path table there
|
||||
advert_paths = (AdvertPath*)ps_calloc(ADVERT_PATH_TABLE_SIZE, sizeof(AdvertPath));
|
||||
#else
|
||||
// nRF52 / other non-PSRAM platforms — fall back to regular heap. Table size
|
||||
// is smaller on these platforms (see ADVERT_PATH_TABLE_SIZE in MyMesh.h) to
|
||||
// avoid blowing the limited SRAM budget.
|
||||
advert_paths = (AdvertPath*)calloc(ADVERT_PATH_TABLE_SIZE, sizeof(AdvertPath));
|
||||
#endif
|
||||
BaseChatMesh::begin();
|
||||
|
||||
if (!_store->loadMainIdentity(self_id)) {
|
||||
Serial.println("[ID] loadMainIdentity FAILED — generating new identity");
|
||||
self_id = radio_new_identity(); // create new random identity
|
||||
int count = 0;
|
||||
while (count < 10 && (self_id.pub_key[0] == 0x00 || self_id.pub_key[0] == 0xFF)) { // reserved id hashes
|
||||
self_id = radio_new_identity();
|
||||
count++;
|
||||
}
|
||||
_store->saveMainIdentity(self_id);
|
||||
bool ok = _store->saveMainIdentity(self_id);
|
||||
Serial.printf("[ID] saveMainIdentity returned %d\n", ok ? 1 : 0);
|
||||
} else {
|
||||
Serial.println("[ID] loadMainIdentity OK — using persisted identity");
|
||||
}
|
||||
{
|
||||
char hex[10];
|
||||
mesh::Utils::toHex(hex, self_id.pub_key, 4);
|
||||
Serial.printf("[ID] pub_key[0..3] = %s\n", hex);
|
||||
}
|
||||
|
||||
// if name is provided as a build flag, use that as default node name instead
|
||||
@@ -1193,12 +1361,25 @@ void MyMesh::begin(bool has_display) {
|
||||
_prefs.gps_baudrate != 9600 && _prefs.gps_baudrate != 19200 &&
|
||||
_prefs.gps_baudrate != 38400 && _prefs.gps_baudrate != 57600 &&
|
||||
_prefs.gps_baudrate != 115200) {
|
||||
Serial.printf("PREFS: invalid gps_baudrate=%lu — reset to 0 (default)\n",
|
||||
(unsigned long)_prefs.gps_baudrate);
|
||||
_prefs.gps_baudrate = 0; // reset to default if invalid
|
||||
}
|
||||
// interference_threshold: 0 = disabled, minimum functional value is 14
|
||||
// interference_threshold: 0 = disabled, minimum functional value is 14, max sane ~30
|
||||
if (_prefs.interference_threshold > 0 && _prefs.interference_threshold < 14) {
|
||||
_prefs.interference_threshold = 0;
|
||||
}
|
||||
if (_prefs.interference_threshold > 50) {
|
||||
Serial.printf("PREFS: invalid interference_threshold=%d — reset to 0 (disabled)\n",
|
||||
_prefs.interference_threshold);
|
||||
_prefs.interference_threshold = 0; // garbage from prefs upgrade — disable
|
||||
}
|
||||
// Clamp remaining v1.0 fields that may contain garbage after upgrade from older firmware
|
||||
if (_prefs.path_hash_mode > 2) _prefs.path_hash_mode = 0;
|
||||
if (_prefs.autoadd_max_hops > 64) _prefs.autoadd_max_hops = 0;
|
||||
if (_prefs.dark_mode > 1) _prefs.dark_mode = 0;
|
||||
if (_prefs.portrait_mode > 1) _prefs.portrait_mode = 0;
|
||||
if (_prefs.hint_shown > 1) _prefs.hint_shown = 0;
|
||||
|
||||
#ifdef BLE_PIN_CODE // 123456 by default
|
||||
if (_prefs.ble_pin == 0) {
|
||||
@@ -1246,6 +1427,7 @@ void MyMesh::startInterface(BaseSerialInterface &serial) {
|
||||
}
|
||||
|
||||
void MyMesh::handleCmdFrame(size_t len) {
|
||||
Serial.printf("[CMD] rx opcode=0x%02X len=%d\n", cmd_frame[0], (int)len);
|
||||
if (cmd_frame[0] == CMD_DEVICE_QEURY && len >= 2) { // sent when app establishes connection
|
||||
app_target_ver = cmd_frame[1]; // which version of protocol does app understand
|
||||
|
||||
@@ -1448,7 +1630,7 @@ void MyMesh::handleCmdFrame(size_t len) {
|
||||
if (pkt) {
|
||||
if (len >= 2 && cmd_frame[1] == 1) { // optional param (1 = flood, 0 = zero hop)
|
||||
unsigned long delay_millis = 0;
|
||||
sendFlood(pkt, delay_millis, _prefs.path_hash_mode + 1);
|
||||
sendFlood(pkt, delay_millis, getPathHashSize());
|
||||
} else {
|
||||
sendZeroHop(pkt);
|
||||
}
|
||||
@@ -1548,12 +1730,19 @@ void MyMesh::handleCmdFrame(size_t len) {
|
||||
}
|
||||
}
|
||||
} else if (cmd_frame[0] == CMD_IMPORT_CONTACT && len > 2 + 32 + 64) {
|
||||
Serial.printf("[IMP] CMD_IMPORT_CONTACT received, len=%d\n", len);
|
||||
if (importContact(&cmd_frame[1], len - 1)) {
|
||||
Serial.println("[IMP] importContact OK, scheduling dirty flush");
|
||||
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY);
|
||||
writeOKFrame();
|
||||
} else {
|
||||
Serial.println("[IMP] importContact REJECTED by BaseChatMesh");
|
||||
writeErrFrame(ERR_CODE_ILLEGAL_ARG);
|
||||
}
|
||||
} else if (cmd_frame[0] == CMD_IMPORT_CONTACT) {
|
||||
Serial.printf("[IMP] CMD_IMPORT_CONTACT dropped — len=%d too short (need >%d)\n",
|
||||
len, 2 + 32 + 64);
|
||||
writeErrFrame(ERR_CODE_ILLEGAL_ARG);
|
||||
} else if (cmd_frame[0] == CMD_SYNC_NEXT_MESSAGE) {
|
||||
int out_len;
|
||||
if ((out_len = getFromOfflineQueue(out_frame)) > 0) {
|
||||
@@ -1571,6 +1760,13 @@ void MyMesh::handleCmdFrame(size_t len) {
|
||||
uint8_t ch_idx = is_v3_ch ? out_frame[4] : out_frame[1];
|
||||
_ui->markChannelReadFromBLE(ch_idx);
|
||||
}
|
||||
|
||||
// Mark DM slot read when companion app syncs a contact (DM/room) message
|
||||
bool is_v3_dm = (out_frame[0] == RESP_CODE_CONTACT_MSG_RECV_V3);
|
||||
bool is_old_dm = (out_frame[0] == RESP_CODE_CONTACT_MSG_RECV);
|
||||
if (is_v3_dm || is_old_dm) {
|
||||
_ui->markChannelReadFromBLE(0xFF);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
@@ -1683,23 +1879,29 @@ void MyMesh::handleCmdFrame(size_t len) {
|
||||
writeDisabledFrame();
|
||||
#endif
|
||||
} else if (cmd_frame[0] == CMD_IMPORT_PRIVATE_KEY && len >= 65) {
|
||||
Serial.printf("[PK] CMD_IMPORT_PRIVATE_KEY received, len=%d\n", (int)len);
|
||||
#if ENABLE_PRIVATE_KEY_IMPORT
|
||||
if (!mesh::LocalIdentity::validatePrivateKey(&cmd_frame[1])) {
|
||||
Serial.println("[PK] validatePrivateKey FAILED — key bytes rejected");
|
||||
writeErrFrame(ERR_CODE_ILLEGAL_ARG); // invalid key
|
||||
} else {
|
||||
Serial.println("[PK] validatePrivateKey OK — attempting save");
|
||||
mesh::LocalIdentity identity;
|
||||
identity.readFrom(&cmd_frame[1], 64);
|
||||
if (_store->saveMainIdentity(identity)) {
|
||||
Serial.println("[PK] saveMainIdentity OK");
|
||||
self_id = identity;
|
||||
writeOKFrame();
|
||||
// re-load contacts, to invalidate ecdh shared_secrets
|
||||
resetContacts();
|
||||
_store->loadContacts(this);
|
||||
} else {
|
||||
Serial.println("[PK] saveMainIdentity FAILED");
|
||||
writeErrFrame(ERR_CODE_FILE_IO_ERROR);
|
||||
}
|
||||
}
|
||||
#else
|
||||
Serial.println("[PK] ENABLE_PRIVATE_KEY_IMPORT not defined — responding DISABLED");
|
||||
writeDisabledFrame();
|
||||
#endif
|
||||
} else if (cmd_frame[0] == CMD_SEND_RAW_DATA && len >= 6) {
|
||||
@@ -1894,17 +2096,21 @@ void MyMesh::handleCmdFrame(size_t len) {
|
||||
writeErrFrame(ERR_CODE_NOT_FOUND);
|
||||
}
|
||||
} else if (cmd_frame[0] == CMD_SET_CHANNEL && len >= 2 + 32 + 32) {
|
||||
Serial.printf("[CH] CMD_SET_CHANNEL 256-bit secret not supported (len=%d)\n", len);
|
||||
writeErrFrame(ERR_CODE_UNSUPPORTED_CMD); // not supported (yet)
|
||||
} else if (cmd_frame[0] == CMD_SET_CHANNEL && len >= 2 + 32 + 16) {
|
||||
uint8_t channel_idx = cmd_frame[1];
|
||||
Serial.printf("[CH] CMD_SET_CHANNEL idx=%d len=%d\n", channel_idx, len);
|
||||
ChannelDetails channel;
|
||||
StrHelper::strncpy(channel.name, (char *)&cmd_frame[2], 32);
|
||||
memset(channel.channel.secret, 0, sizeof(channel.channel.secret));
|
||||
memcpy(channel.channel.secret, &cmd_frame[2 + 32], 16); // NOTE: only 128-bit supported
|
||||
if (setChannel(channel_idx, channel)) {
|
||||
Serial.println("[CH] setChannel OK, calling saveChannels");
|
||||
saveChannels();
|
||||
writeOKFrame();
|
||||
} else {
|
||||
Serial.printf("[CH] setChannel REJECTED (bad idx=%d)\n", channel_idx);
|
||||
writeErrFrame(ERR_CODE_NOT_FOUND); // bad channel_idx
|
||||
}
|
||||
} else if (cmd_frame[0] == CMD_SIGN_START) {
|
||||
@@ -2134,6 +2340,8 @@ void MyMesh::handleCmdFrame(size_t len) {
|
||||
_serial->writeFrame(out_frame, i);
|
||||
} else {
|
||||
writeErrFrame(ERR_CODE_UNSUPPORTED_CMD);
|
||||
Serial.printf("[CMD] UNKNOWN opcode=0x%02X len=%d — responded UNSUPPORTED\n",
|
||||
cmd_frame[0], (int)len);
|
||||
MESH_DEBUG_PRINTLN("ERROR: unknown command: %02X", cmd_frame[0]);
|
||||
}
|
||||
}
|
||||
@@ -2206,6 +2414,10 @@ void MyMesh::checkCLIRescueCmd() {
|
||||
Serial.printf(" > %d\n", _prefs.multi_acks);
|
||||
} else if (strcmp(key, "int.thresh") == 0) {
|
||||
Serial.printf(" > %d\n", _prefs.interference_threshold);
|
||||
} else if (strcmp(key, "tx.fail.threshold") == 0) {
|
||||
Serial.printf(" > %d\n", _prefs.tx_fail_reset_threshold);
|
||||
} else if (strcmp(key, "rx.fail.threshold") == 0) {
|
||||
Serial.printf(" > %d\n", _prefs.rx_fail_reboot_threshold);
|
||||
} else if (strcmp(key, "gps.baud") == 0) {
|
||||
uint32_t effective = _prefs.gps_baudrate ? _prefs.gps_baudrate : GPS_BAUDRATE;
|
||||
Serial.printf(" > %lu (effective: %lu)\n",
|
||||
@@ -2266,6 +2478,8 @@ void MyMesh::checkCLIRescueCmd() {
|
||||
Serial.printf(" af: %.1f\n", _prefs.airtime_factor);
|
||||
Serial.printf(" multi.acks: %d\n", _prefs.multi_acks);
|
||||
Serial.printf(" int.thresh: %d\n", _prefs.interference_threshold);
|
||||
Serial.printf(" tx.fail: %d\n", _prefs.tx_fail_reset_threshold);
|
||||
Serial.printf(" rx.fail: %d\n", _prefs.rx_fail_reboot_threshold);
|
||||
{
|
||||
uint32_t eff_baud = _prefs.gps_baudrate ? _prefs.gps_baudrate : GPS_BAUDRATE;
|
||||
Serial.printf(" gps.baud: %lu\n", (unsigned long)eff_baud);
|
||||
@@ -2661,6 +2875,30 @@ void MyMesh::checkCLIRescueCmd() {
|
||||
Serial.println(" Error: use 0 (disabled) or 14+ (typical: 14)");
|
||||
}
|
||||
|
||||
} else if (memcmp(config, "tx.fail.threshold ", 18) == 0) {
|
||||
int val = atoi(&config[18]);
|
||||
if (val < 0) val = 0;
|
||||
if (val > 10) val = 10;
|
||||
_prefs.tx_fail_reset_threshold = (uint8_t)val;
|
||||
savePrefs();
|
||||
if (val == 0) {
|
||||
Serial.println(" > tx fail reset disabled");
|
||||
} else {
|
||||
Serial.printf(" > tx fail reset after %d failures\n", val);
|
||||
}
|
||||
|
||||
} else if (memcmp(config, "rx.fail.threshold ", 18) == 0) {
|
||||
int val = atoi(&config[18]);
|
||||
if (val < 0) val = 0;
|
||||
if (val > 10) val = 10;
|
||||
_prefs.rx_fail_reboot_threshold = (uint8_t)val;
|
||||
savePrefs();
|
||||
if (val == 0) {
|
||||
Serial.println(" > rx fail reboot disabled");
|
||||
} else {
|
||||
Serial.printf(" > reboot after %d rx recovery failures\n", val);
|
||||
}
|
||||
|
||||
} else if (memcmp(config, "gps.baud ", 9) == 0) {
|
||||
uint32_t val = (uint32_t)atol(&config[9]);
|
||||
if (val == 0 || val == 4800 || val == 9600 || val == 19200 ||
|
||||
@@ -2758,6 +2996,8 @@ void MyMesh::checkCLIRescueCmd() {
|
||||
Serial.println(" af <0-9> Airtime factor");
|
||||
Serial.println(" multi.acks <0|1> Redundant ACKs (default: 1)");
|
||||
Serial.println(" int.thresh <0|14+> Interference threshold dB (0=off, 14=typical)");
|
||||
Serial.println(" tx.fail.threshold <0-10> TX fail radio reset (0=off, default 3)");
|
||||
Serial.println(" rx.fail.threshold <0-10> RX stuck reboot (0=off, default 3)");
|
||||
Serial.println(" gps.baud <rate> GPS baud (0=default, reboot to apply)");
|
||||
Serial.println("");
|
||||
Serial.println(" Clock:");
|
||||
@@ -2949,20 +3189,29 @@ void MyMesh::checkSerialInterface() {
|
||||
} else if (_iter_started // check if our ContactsIterator is 'running'
|
||||
&& !_serial->isWriteBusy() // don't spam the Serial Interface too quickly!
|
||||
) {
|
||||
// Batch-fill: queue multiple contacts per loop iteration so the BLE
|
||||
// send queue stays saturated during sync. writeFrame() returns 0
|
||||
// when the queue is full, which naturally throttles us.
|
||||
ContactInfo contact;
|
||||
if (_iter.hasNext(this, contact)) {
|
||||
if (contact.lastmod > _iter_filter_since) { // apply the 'since' filter
|
||||
writeContactRespFrame(RESP_CODE_CONTACT, contact);
|
||||
if (contact.lastmod > _most_recent_lastmod) {
|
||||
_most_recent_lastmod = contact.lastmod; // save for the RESP_CODE_END_OF_CONTACTS frame
|
||||
bool done = false;
|
||||
int queued = 0;
|
||||
while (!done && queued < 8) { // up to 8 per iteration to avoid starving loop()
|
||||
if (_iter.hasNext(this, contact)) {
|
||||
if (contact.lastmod > _iter_filter_since) { // apply the 'since' filter
|
||||
if (writeContactRespFrame(RESP_CODE_CONTACT, contact) == 0) break; // queue full
|
||||
queued++;
|
||||
if (contact.lastmod > _most_recent_lastmod) {
|
||||
_most_recent_lastmod = contact.lastmod;
|
||||
}
|
||||
}
|
||||
} else { // EOF
|
||||
out_frame[0] = RESP_CODE_END_OF_CONTACTS;
|
||||
memcpy(&out_frame[1], &_most_recent_lastmod,
|
||||
4); // include the most recent lastmod, so app can update their 'since'
|
||||
_serial->writeFrame(out_frame, 5);
|
||||
_iter_started = false;
|
||||
done = true;
|
||||
}
|
||||
} else { // EOF
|
||||
out_frame[0] = RESP_CODE_END_OF_CONTACTS;
|
||||
memcpy(&out_frame[1], &_most_recent_lastmod,
|
||||
4); // include the most recent lastmod, so app can update their 'since'
|
||||
_serial->writeFrame(out_frame, 5);
|
||||
_iter_started = false;
|
||||
}
|
||||
//} else if (!_serial->isWriteBusy()) {
|
||||
// checkConnections(); // TODO - deprecate the 'Connections' stuff
|
||||
@@ -2982,10 +3231,36 @@ void MyMesh::loop() {
|
||||
|
||||
// is there are pending dirty contacts write needed?
|
||||
if (dirty_contacts_expiry && millisHasNowPassed(dirty_contacts_expiry)) {
|
||||
saveContacts();
|
||||
dirty_contacts_expiry = 0;
|
||||
if (_deferSaves) {
|
||||
// Voice session receiving — push save forward to avoid SPI contention
|
||||
dirty_contacts_expiry = futureMillis(2000);
|
||||
} else {
|
||||
#ifdef HELTEC_MESH_POCKET
|
||||
// Meshpocket: use upstream-style synchronous save. Max 500 contacts =
|
||||
// ~74KB, finishes in well under a second on InternalFS. Avoids the
|
||||
// chunked trio's File* lifetime pitfalls entirely.
|
||||
Serial.println("[DS] saveContacts (synchronous) triggered by dirty flag");
|
||||
_store->saveContacts(this);
|
||||
dirty_contacts_expiry = 0;
|
||||
#else
|
||||
if (!_store->isSaveInProgress()) {
|
||||
_store->beginSaveContacts(this);
|
||||
dirty_contacts_expiry = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef HELTEC_MESH_POCKET
|
||||
// Drive chunked contact save — write a batch each loop iteration.
|
||||
// Only used for non-Meshpocket builds (ESP32 PSRAM heavyweight).
|
||||
if (_store->isSaveInProgress() && !_deferSaves) {
|
||||
if (!_store->saveContactsChunk(20)) { // 20 contacts per chunk (~3KB, ~30ms)
|
||||
_store->finishSaveContacts(); // Done or error — verify and commit
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Discovery scan timeout
|
||||
if (_discoveryActive && millisHasNowPassed(_discoveryTimeout)) {
|
||||
_discoveryActive = false;
|
||||
@@ -3044,6 +3319,13 @@ void MyMesh::stopDiscovery() {
|
||||
_discoveryActive = false;
|
||||
}
|
||||
|
||||
bool MyMesh::forceImportContact(const uint8_t* blob, uint8_t len) {
|
||||
_forceNextImport = true;
|
||||
bool ok = importContact(blob, len);
|
||||
if (!ok) _forceNextImport = false; // clear if importContact failed (no loopback queued)
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool MyMesh::addDiscoveredToContacts(int idx) {
|
||||
if (idx < 0 || idx >= _discoveredCount) return false;
|
||||
if (_discovered[idx].already_in_contacts) return true; // already there
|
||||
@@ -3052,7 +3334,7 @@ bool MyMesh::addDiscoveredToContacts(int idx) {
|
||||
uint8_t buf[256];
|
||||
int plen = getBlobByKey(_discovered[idx].contact.id.pub_key, PUB_KEY_SIZE, buf);
|
||||
if (plen > 0) {
|
||||
bool ok = importContact(buf, (uint8_t)plen);
|
||||
bool ok = forceImportContact(buf, (uint8_t)plen);
|
||||
if (ok) {
|
||||
_discovered[idx].already_in_contacts = true;
|
||||
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY);
|
||||
@@ -3062,4 +3344,20 @@ bool MyMesh::addDiscoveredToContacts(int idx) {
|
||||
}
|
||||
MESH_DEBUG_PRINTLN("Discovery: no cached advert blob for contact '%s'", _discovered[idx].contact.name);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#ifdef HELTEC_MESH_POCKET
|
||||
// =============================================================================
|
||||
// Power saving — adapted from MeshCore PR #2286 (IoTThinks)
|
||||
// Returns true if the radio has outbound packets queued (any priority, any
|
||||
// scheduling window). main.cpp loop() uses this to decide whether it's safe
|
||||
// to drop into board.sleep(0) until the next interrupt.
|
||||
//
|
||||
// Upstream uses _mgr->getOutboundTotal() which doesn't exist in this tree —
|
||||
// the equivalent call in Meck is getOutboundCount(0xFFFFFFFF) which passes
|
||||
// max uint32 as `now` so scheduled_for < now is always true. Already used
|
||||
// elsewhere in this file (see line ~2221 in the queue-stats block).
|
||||
// =============================================================================
|
||||
bool MyMesh::hasPendingWork() const {
|
||||
return _mgr->getOutboundCount(0xFFFFFFFF) > 0;
|
||||
}
|
||||
#endif
|
||||
@@ -5,14 +5,14 @@
|
||||
#include "AbstractUITask.h"
|
||||
|
||||
/*------------ Frame Protocol --------------*/
|
||||
#define FIRMWARE_VER_CODE 10
|
||||
#define FIRMWARE_VER_CODE 11
|
||||
|
||||
#ifndef FIRMWARE_BUILD_DATE
|
||||
#define FIRMWARE_BUILD_DATE "13 March 2026"
|
||||
#define FIRMWARE_BUILD_DATE "16 April 2026"
|
||||
#endif
|
||||
|
||||
#ifndef FIRMWARE_VERSION
|
||||
#define FIRMWARE_VERSION "Meck v1.0"
|
||||
#define FIRMWARE_VERSION "Meck v1.7"
|
||||
#endif
|
||||
|
||||
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
||||
@@ -70,6 +70,11 @@
|
||||
#include <helpers/BaseChatMesh.h>
|
||||
#include <helpers/TransportKeyStore.h>
|
||||
|
||||
// Custom path lock flag — bit 7 of ContactInfo.flags
|
||||
// When set, onContactPathRecv skips auto-updating this contact's out_path.
|
||||
// Bits 0-6 remain available (bit 0 = favourite, bits 1-3 = telemetry perms).
|
||||
#define CONTACT_FLAG_CUSTOM_PATH 0x80
|
||||
|
||||
/* -------------------------------------------------------------------------------------- */
|
||||
|
||||
#define REQ_TYPE_GET_STATUS 0x01 // same as _GET_STATS
|
||||
@@ -77,8 +82,9 @@
|
||||
#define REQ_TYPE_GET_TELEMETRY_DATA 0x03
|
||||
|
||||
struct AdvertPath {
|
||||
uint8_t pubkey_prefix[7];
|
||||
uint8_t pubkey_prefix[8];
|
||||
uint8_t path_len;
|
||||
uint8_t type; // ADV_TYPE_* (Chat/Repeater/Room/Sensor)
|
||||
char name[32];
|
||||
uint32_t recv_timestamp;
|
||||
uint8_t path[MAX_PATH_SIZE];
|
||||
@@ -119,6 +125,15 @@ public:
|
||||
int getDiscoveredCount() const { return _discoveredCount; }
|
||||
const DiscoveredNode& getDiscovered(int idx) const { return _discovered[idx]; }
|
||||
bool addDiscoveredToContacts(int idx); // promote a discovered node into contacts
|
||||
|
||||
// Last Heard — public wrappers for contact add/remove from UI
|
||||
void scheduleLazyContactSave();
|
||||
int getContactBlob(const uint8_t key[], int key_len, uint8_t dest_buf[]) {
|
||||
return getBlobByKey(key, key_len, dest_buf);
|
||||
}
|
||||
// Force-add a contact from a raw advert blob, bypassing auto-add settings.
|
||||
// Used by Last Heard and Discovery when the user explicitly selects a node to add.
|
||||
bool forceImportContact(const uint8_t* blob, uint8_t len);
|
||||
|
||||
// Queue a sent channel message for BLE app sync
|
||||
void queueSentChannelMessage(uint8_t channel_idx, uint32_t timestamp, const char* sender, const char* text);
|
||||
@@ -126,16 +141,51 @@ public:
|
||||
// Send a direct message from the UI (no BLE dependency)
|
||||
bool uiSendDirectMessage(uint32_t contact_idx, const char* text);
|
||||
|
||||
// Send raw binary data to a contact (PAYLOAD_TYPE_RAW_CUSTOM, direct route only)
|
||||
// Used for dz0ny VE3 voice protocol: voice packets (0x56) and fetch requests (0x72)
|
||||
bool uiSendRawToContact(uint32_t contact_idx, const uint8_t* data, uint8_t len);
|
||||
|
||||
// Voice-over-LoRa: callback for incoming raw voice packets (dz0ny VE3 protocol)
|
||||
// magic 0x56 = voice data packet, 0x72 = fetch request
|
||||
typedef void (*VoiceRawHandler)(uint8_t magic, const uint8_t* payload, uint8_t len);
|
||||
void setVoiceHandler(VoiceRawHandler h) { _voiceHandler = h; }
|
||||
|
||||
// Voice-over-LoRa: callback for incoming VE3 envelope in a DM
|
||||
// Called with sender name and the VE3 text (e.g. "VE3:a:1:3:2")
|
||||
typedef void (*VoiceEnvelopeHandler)(const char* senderName, const char* ve3Text);
|
||||
void setVoiceEnvelopeHandler(VoiceEnvelopeHandler h) { _voiceEnvHandler = h; }
|
||||
|
||||
// Defer contact saves while voice packets are being received
|
||||
// (SD writes block SPI bus shared with LoRa radio)
|
||||
void setDeferSaves(bool defer) { _deferSaves = defer; }
|
||||
bool isDeferSaves() const { return _deferSaves; }
|
||||
|
||||
// Repeater admin - UI-initiated operations
|
||||
bool uiLoginToRepeater(uint32_t contact_idx, const char* password, uint32_t& est_timeout_ms);
|
||||
bool uiSendCliCommand(uint32_t contact_idx, const char* command);
|
||||
bool uiSendTelemetryRequest(uint32_t contact_idx);
|
||||
int getAdminContactIdx() const { return _admin_contact_idx; }
|
||||
|
||||
// Custom path editor — set or clear a manually configured path for a contact
|
||||
// When locked, automatic path discovery will not overwrite this contact's path.
|
||||
bool setCustomPath(int contactIdx, const uint8_t* path, uint8_t pathLen, bool lock);
|
||||
void clearCustomPath(int contactIdx);
|
||||
|
||||
#ifdef HELTEC_MESH_POCKET
|
||||
// Power saving: check if there is pending work (outbound packets queued, etc.)
|
||||
// Used by main.cpp loop to decide whether board.sleep() is safe.
|
||||
// Adapted from MeshCore PR #2286 (IoTThinks) — substitutes getOutboundCount(0xFFFFFFFF)
|
||||
// for upstream's getOutboundTotal() which doesn't exist in this tree.
|
||||
bool hasPendingWork() const;
|
||||
#endif
|
||||
|
||||
|
||||
protected:
|
||||
float getAirtimeBudgetFactor() const override;
|
||||
int getInterferenceThreshold() const override;
|
||||
uint8_t getTxFailResetThreshold() const override;
|
||||
uint8_t getRxFailRebootThreshold() const override;
|
||||
void onRxUnrecoverable() override;
|
||||
int calcRxDelay(float score, uint32_t air_time) const override;
|
||||
uint32_t getRetransmitDelay(const mesh::Packet *packet) override;
|
||||
uint32_t getDirectRetransmitDelay(const mesh::Packet *packet) override;
|
||||
@@ -143,6 +193,7 @@ protected:
|
||||
uint8_t getAutoAddMaxHops() const override;
|
||||
bool filterRecvFloodPacket(mesh::Packet* packet) override;
|
||||
|
||||
uint8_t getPathHashSize() const override { return _prefs.path_hash_mode + 1; }
|
||||
void sendFloodScoped(const ContactInfo& recipient, mesh::Packet* pkt, uint32_t delay_millis=0) override;
|
||||
void sendFloodScoped(const mesh::GroupChannel& channel, mesh::Packet* pkt, uint32_t delay_millis=0) override;
|
||||
|
||||
@@ -203,7 +254,7 @@ private:
|
||||
void writeOKFrame();
|
||||
void writeErrFrame(uint8_t err_code);
|
||||
void writeDisabledFrame();
|
||||
void writeContactRespFrame(uint8_t code, const ContactInfo &contact);
|
||||
size_t writeContactRespFrame(uint8_t code, const ContactInfo &contact);
|
||||
void updateContactFromFrame(ContactInfo &contact, uint32_t& last_mod, const uint8_t *frame, int len);
|
||||
void addToOfflineQueue(const uint8_t frame[], int len);
|
||||
int getFromOfflineQueue(uint8_t frame[]);
|
||||
@@ -219,6 +270,10 @@ private:
|
||||
|
||||
DataStore* _store;
|
||||
NodePrefs _prefs;
|
||||
VoiceRawHandler _voiceHandler = nullptr;
|
||||
VoiceEnvelopeHandler _voiceEnvHandler = nullptr;
|
||||
mutable bool _forceNextImport = false;
|
||||
bool _deferSaves = false;
|
||||
uint32_t pending_login;
|
||||
uint32_t pending_status;
|
||||
uint32_t pending_telemetry, pending_discovery; // pending _TELEMETRY_REQ
|
||||
@@ -262,8 +317,17 @@ private:
|
||||
AckTableEntry expected_ack_table[EXPECTED_ACK_TABLE_SIZE]; // circular table
|
||||
int next_ack_idx;
|
||||
|
||||
#define ADVERT_PATH_TABLE_SIZE 16
|
||||
AdvertPath advert_paths[ADVERT_PATH_TABLE_SIZE]; // circular table
|
||||
// Advert path table: stores paths we've heard back to us for sorting/recency.
|
||||
// ESP32 variants (T-Deck Pro, T5S3, Heltec V4) have PSRAM, so can afford the
|
||||
// large 1000-entry table (~50KB). nRF52 companion builds (Heltec Meshpocket,
|
||||
// T-Echo Card) have no PSRAM and only 256KB total SRAM shared with BLE, so
|
||||
// use a much smaller table sized for realistic handheld usage.
|
||||
#if defined(ESP32)
|
||||
#define ADVERT_PATH_TABLE_SIZE 1000
|
||||
#else
|
||||
#define ADVERT_PATH_TABLE_SIZE 50
|
||||
#endif
|
||||
AdvertPath* advert_paths; // PSRAM-allocated (ESP32) or heap-allocated (nRF52) in begin()
|
||||
|
||||
// Sent message repeat tracking
|
||||
#define SENT_TRACK_SIZE 4
|
||||
|
||||
@@ -37,4 +37,43 @@ struct NodePrefs { // persisted to file
|
||||
uint8_t interference_threshold; // Interference threshold in dB (0=disabled, 14+=enabled)
|
||||
uint8_t dark_mode; // 0=off (white bg), 1=on (black bg)
|
||||
uint8_t portrait_mode; // 0=landscape, 1=portrait — T5S3 only
|
||||
uint8_t auto_lock_minutes; // 0=disabled, 2/5/10/15/30=auto-lock after idle
|
||||
uint8_t hint_shown; // 0=show nav hint on boot, 1=already shown (dismiss permanently)
|
||||
uint8_t large_font; // 0=tiny (built-in 6x8), 1=larger (FreeSans9pt) — T-Deck Pro only
|
||||
uint8_t tx_fail_reset_threshold; // 0=disabled, 1-10, default 3
|
||||
uint8_t rx_fail_reboot_threshold; // 0=disabled, 1-10, default 3
|
||||
|
||||
// --- Font helpers (inline, no overhead) ---
|
||||
// Returns the DisplayDriver text-size index for "small/body" text.
|
||||
// T-Deck Pro: 0 = built-in 6×8, 1 = FreeSans9pt.
|
||||
// T5S3: both 0 and 1 are 12pt fonts (regular vs bold) with identical line
|
||||
// height, so large_font has no layout effect there.
|
||||
inline uint8_t smallTextSize() const {
|
||||
return large_font ? 1 : 0;
|
||||
}
|
||||
|
||||
// Returns the virtual-coordinate line height matching smallTextSize().
|
||||
// T-Deck Pro size 0 → 9 (6×8 + 1px gap), size 1 → 11 (9pt ascent+descent).
|
||||
// T5S3 size 0/1 → same 12pt height → always 9 in virtual coords.
|
||||
inline int smallLineH() const {
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
return 9;
|
||||
#else
|
||||
return large_font ? 11 : 9;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Returns the Y offset for selection highlight fillRect (T-Deck Pro only).
|
||||
// Size 0 (built-in font): cursor positions at top-left, +5 offset in
|
||||
// setCursor places text below → fillRect at y+5 aligns with text.
|
||||
// Size 1 (FreeSans9pt): cursor positions at baseline, ascenders render
|
||||
// upward → fillRect must start above baseline to cover ascenders.
|
||||
// T5S3: always 0 (both sizes use baseline fonts with highlight at y).
|
||||
inline int smallHighlightOff() const {
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
return 0;
|
||||
#else
|
||||
return large_font ? -2 : 5;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
+2230
-236
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -43,6 +43,8 @@
|
||||
// JPEG decoder for cover art — JPEGDEC by bitbank2
|
||||
#include <JPEGDEC.h>
|
||||
|
||||
#include "../NodePrefs.h"
|
||||
|
||||
// Forward declarations
|
||||
class UITask;
|
||||
|
||||
@@ -151,6 +153,7 @@ public:
|
||||
|
||||
private:
|
||||
UITask* _task;
|
||||
NodePrefs* _prefs;
|
||||
Audio* _audio;
|
||||
Mode _mode;
|
||||
bool _sdReady;
|
||||
@@ -1193,10 +1196,10 @@ private:
|
||||
}
|
||||
|
||||
// Switch to tiny font for file list (6x8 built-in)
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs ? _prefs->smallTextSize() : 0);
|
||||
|
||||
// Calculate visible items — tiny font uses ~8 virtual units per line
|
||||
int itemHeight = 8;
|
||||
// Calculate visible items
|
||||
int itemHeight = (_prefs ? _prefs->smallLineH() : 9) - 1;
|
||||
int listTop = 13;
|
||||
int listBottom = display.height() - 14; // Reserve footer space
|
||||
int visibleItems = (listBottom - listTop) / itemHeight;
|
||||
@@ -1208,7 +1211,7 @@ private:
|
||||
_scrollOffset = _selectedFile - visibleItems + 1;
|
||||
}
|
||||
|
||||
// Approx chars that fit in tiny font (~36 on 128 virtual width)
|
||||
// Approx chars for suffix/type tag sizing (still needed for type tag assembly)
|
||||
const int charsPerLine = 36;
|
||||
|
||||
// Draw file list
|
||||
@@ -1218,9 +1221,7 @@ private:
|
||||
|
||||
if (fileIdx == _selectedFile) {
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
// setCursor adds +5 to y internally, but fillRect does not.
|
||||
// Offset fillRect by +5 to align highlight bar with text.
|
||||
display.fillRect(0, y + 5, display.width(), itemHeight - 1);
|
||||
display.fillRect(0, y + (_prefs ? _prefs->smallHighlightOff() : 5), display.width(), itemHeight - 1);
|
||||
display.setColor(DisplayDriver::DARK);
|
||||
} else {
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
@@ -1231,29 +1232,15 @@ private:
|
||||
char fullLine[96];
|
||||
|
||||
if (fe.isDir) {
|
||||
// Directory entry: show as "/ FolderName" or just ".."
|
||||
if (fe.name == "..") {
|
||||
snprintf(fullLine, sizeof(fullLine), ".. (up)");
|
||||
} else {
|
||||
snprintf(fullLine, sizeof(fullLine), "/%s", fe.name.c_str());
|
||||
// Truncate if needed
|
||||
if ((int)strlen(fullLine) > charsPerLine - 1) {
|
||||
fullLine[charsPerLine - 4] = '.';
|
||||
fullLine[charsPerLine - 3] = '.';
|
||||
fullLine[charsPerLine - 2] = '.';
|
||||
fullLine[charsPerLine - 1] = '\0';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Audio file: "Title - Author [TYPE]"
|
||||
char lineBuf[80];
|
||||
|
||||
// Reserve space for type tag and bookmark indicator
|
||||
int suffixLen = fe.fileType.length() + 3; // " [M4B]" or " [MP3]"
|
||||
int bmkLen = fe.hasBookmark ? 2 : 0; // " >"
|
||||
int availChars = charsPerLine - suffixLen - bmkLen;
|
||||
if (availChars < 10) availChars = 10;
|
||||
|
||||
if (fe.displayAuthor.length() > 0) {
|
||||
snprintf(lineBuf, sizeof(lineBuf), "%s - %s",
|
||||
fe.displayTitle.c_str(), fe.displayAuthor.c_str());
|
||||
@@ -1261,24 +1248,13 @@ private:
|
||||
snprintf(lineBuf, sizeof(lineBuf), "%s", fe.displayTitle.c_str());
|
||||
}
|
||||
|
||||
// Truncate with ellipsis if needed
|
||||
if ((int)strlen(lineBuf) > availChars) {
|
||||
if (availChars > 3) {
|
||||
lineBuf[availChars - 3] = '.';
|
||||
lineBuf[availChars - 2] = '.';
|
||||
lineBuf[availChars - 1] = '.';
|
||||
lineBuf[availChars] = '\0';
|
||||
} else {
|
||||
lineBuf[availChars] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
// Append file type tag
|
||||
snprintf(fullLine, sizeof(fullLine), "%s [%s]", lineBuf, fe.fileType.c_str());
|
||||
}
|
||||
|
||||
display.setCursor(2, y);
|
||||
display.print(fullLine);
|
||||
// Pixel-aware ellipsis — reserve space for bookmark indicator
|
||||
int reserveRight = (!fe.isDir && fe.hasBookmark) ? 10 : 2;
|
||||
display.drawTextEllipsized(2, y, display.width() - reserveRight, fullLine);
|
||||
|
||||
// Bookmark indicator (right-aligned, files only)
|
||||
if (!fe.isDir && fe.hasBookmark) {
|
||||
@@ -1464,8 +1440,8 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
AudiobookPlayerScreen(UITask* task, Audio* audio)
|
||||
: _task(task), _audio(audio), _mode(FILE_LIST),
|
||||
AudiobookPlayerScreen(UITask* task, Audio* audio, NodePrefs* prefs = nullptr)
|
||||
: _task(task), _prefs(prefs), _audio(audio), _mode(FILE_LIST),
|
||||
_sdReady(false), _i2sInitialized(false), _dacPowered(false),
|
||||
_displayRef(nullptr),
|
||||
_selectedFile(0), _scrollOffset(0),
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
#pragma once
|
||||
// =============================================================================
|
||||
// CardKBKeyboard — M5Stack CardKB (or compatible) I2C keyboard driver
|
||||
//
|
||||
// Polls 0x5F on the shared I2C bus via QWIIC connector.
|
||||
// Maps CardKB special key codes to Meck key constants.
|
||||
//
|
||||
// Usage:
|
||||
// CardKBKeyboard cardkb;
|
||||
// if (cardkb.begin()) { /* detected */ }
|
||||
// char key = cardkb.readKey(); // returns 0 if no key
|
||||
// =============================================================================
|
||||
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro) && defined(MECK_CARDKB)
|
||||
#ifndef CARDKB_KEYBOARD_H
|
||||
#define CARDKB_KEYBOARD_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
#include "variant.h" // For I2C_SDA, I2C_SCL (bus recovery)
|
||||
|
||||
// I2C address (defined in variant.h, fallback here)
|
||||
#ifndef CARDKB_I2C_ADDR
|
||||
#define CARDKB_I2C_ADDR 0x5F
|
||||
#endif
|
||||
|
||||
// CardKB special key codes (from M5Stack documentation)
|
||||
#define CARDKB_KEY_UP 0xB5
|
||||
#define CARDKB_KEY_DOWN 0xB6
|
||||
#define CARDKB_KEY_LEFT 0xB4
|
||||
#define CARDKB_KEY_RIGHT 0xB7
|
||||
#define CARDKB_KEY_TAB 0x09
|
||||
#define CARDKB_KEY_ESC 0x1B
|
||||
#define CARDKB_KEY_BS 0x08
|
||||
#define CARDKB_KEY_ENTER 0x0D
|
||||
#define CARDKB_KEY_DEL 0x7F
|
||||
#define CARDKB_KEY_FN 0x00 // Fn modifier (swallowed by CardKB internally)
|
||||
|
||||
class CardKBKeyboard {
|
||||
public:
|
||||
CardKBKeyboard() : _detected(false) {}
|
||||
|
||||
// Probe for CardKB on the I2C bus. Call after Wire.begin().
|
||||
bool begin() {
|
||||
Wire.beginTransmission(CARDKB_I2C_ADDR);
|
||||
_detected = (Wire.endTransmission() == 0);
|
||||
if (_detected) {
|
||||
Serial.println("[CardKB] Detected at 0x5F");
|
||||
}
|
||||
return _detected;
|
||||
}
|
||||
|
||||
// Re-probe (e.g. for hot-plug detection every few seconds)
|
||||
bool probe() {
|
||||
Wire.beginTransmission(CARDKB_I2C_ADDR);
|
||||
_detected = (Wire.endTransmission() == 0);
|
||||
return _detected;
|
||||
}
|
||||
|
||||
bool isDetected() const { return _detected; }
|
||||
|
||||
// Poll for a keypress. Returns 0 if no key available.
|
||||
// Returns raw ASCII for printable chars, or Meck KEY_* constants for nav keys.
|
||||
// Throttled to avoid flooding I2C bus — polls at most every 50ms.
|
||||
// On read failure, backs off 500ms and re-inits Wire to recover bus state.
|
||||
char readKey() {
|
||||
if (!_detected) return 0;
|
||||
|
||||
unsigned long now = millis();
|
||||
if (now - _lastPoll < _pollInterval) return 0;
|
||||
_lastPoll = now;
|
||||
|
||||
Wire.requestFrom((uint8_t)CARDKB_I2C_ADDR, (uint8_t)1);
|
||||
if (!Wire.available()) {
|
||||
_errorCount++;
|
||||
if (_errorCount >= 3) {
|
||||
// I2C bus may be stuck — re-init to recover
|
||||
Wire.begin(I2C_SDA, I2C_SCL);
|
||||
Wire.setClock(100000);
|
||||
_pollInterval = 500; // Back off for 500ms
|
||||
_errorCount = 0;
|
||||
Serial.println("[CardKB] I2C error recovery — bus re-init");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
_errorCount = 0;
|
||||
_pollInterval = 50; // Normal polling rate
|
||||
|
||||
uint8_t raw = Wire.read();
|
||||
if (raw == 0) return 0;
|
||||
|
||||
// Map CardKB special keys to Meck constants
|
||||
switch (raw) {
|
||||
case CARDKB_KEY_UP: return 0xF2; // KEY_PREV
|
||||
case CARDKB_KEY_DOWN: return 0xF1; // KEY_NEXT
|
||||
case CARDKB_KEY_LEFT: return 0xF3; // KEY_LEFT
|
||||
case CARDKB_KEY_RIGHT: return 0xF4; // KEY_RIGHT
|
||||
case CARDKB_KEY_ENTER: return '\r';
|
||||
case CARDKB_KEY_BS: return '\b';
|
||||
case CARDKB_KEY_DEL: return '\b'; // Treat delete same as backspace
|
||||
case CARDKB_KEY_ESC: return 0x1B; // ESC — handled by caller
|
||||
case CARDKB_KEY_TAB: return 0x09; // Tab — available for future use
|
||||
default:
|
||||
// Printable ASCII — pass through unchanged
|
||||
if (raw >= 0x20 && raw <= 0x7E) {
|
||||
return (char)raw;
|
||||
}
|
||||
// Unknown code — ignore
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
bool _detected;
|
||||
unsigned long _lastPoll = 0;
|
||||
unsigned long _pollInterval = 50; // ms between polls (increases on error)
|
||||
uint8_t _errorCount = 0;
|
||||
};
|
||||
|
||||
#endif // CARDKB_KEYBOARD_H
|
||||
#endif // LilyGo_T5S3_EPaper_Pro && MECK_CARDKB
|
||||
@@ -59,11 +59,19 @@ public:
|
||||
uint8_t path_len;
|
||||
uint8_t channel_idx; // Which channel this message belongs to
|
||||
int8_t snr; // Receive SNR × 4 (0 if locally sent or unknown)
|
||||
uint32_t dm_peer_hash; // DM peer name hash (for conversation filtering)
|
||||
uint8_t path[MSG_PATH_MAX]; // Repeater hop hashes
|
||||
char text[CHANNEL_MSG_TEXT_LEN];
|
||||
bool valid;
|
||||
};
|
||||
|
||||
// Simple hash for DM peer matching
|
||||
static uint32_t peerHash(const char* s) {
|
||||
uint32_t h = 5381;
|
||||
while (*s) { h = ((h << 5) + h) ^ (uint8_t)*s++; }
|
||||
return h;
|
||||
}
|
||||
|
||||
private:
|
||||
UITask* _task;
|
||||
mesh::RTCClock* _rtc;
|
||||
@@ -84,6 +92,31 @@ private:
|
||||
int _replySelectPos; // Index into chronological channelMsgs[] (0=oldest)
|
||||
int _replyChannelMsgCount; // Cached count from last render (for input bounds)
|
||||
|
||||
// DM tab (channel_idx == 0xFF) two-level view:
|
||||
// Inbox mode: list of contacts you have DMs from
|
||||
// Conversation mode: messages filtered to one contact
|
||||
bool _dmInboxMode; // true = showing inbox list, false = conversation
|
||||
int _dmInboxScroll; // Scroll position in inbox list
|
||||
char _dmFilterName[32]; // Selected contact name for conversation view
|
||||
int _dmContactIdx; // Contact index for conversation (-1 if unknown)
|
||||
uint8_t _dmContactPerms; // Last login permissions for this contact (0=none/guest)
|
||||
const uint8_t* _dmUnreadPtr; // Pointer to per-contact DM unread array (from UITask)
|
||||
|
||||
// Helper: does a message belong to the current view?
|
||||
bool msgMatchesView(const ChannelMessage& msg) const {
|
||||
if (!msg.valid) return false;
|
||||
if (_viewChannelIdx != 0xFF) {
|
||||
return msg.channel_idx == _viewChannelIdx;
|
||||
}
|
||||
// DM tab in conversation mode: filter by peer hash
|
||||
if (!_dmInboxMode && _dmFilterName[0] != '\0') {
|
||||
if (msg.channel_idx != 0xFF) return false;
|
||||
return msg.dm_peer_hash == peerHash(_dmFilterName);
|
||||
}
|
||||
// Inbox mode or no filter — match all DMs
|
||||
return msg.channel_idx == 0xFF;
|
||||
}
|
||||
|
||||
// Per-channel unread message counts (standalone mode)
|
||||
// Index 0..MAX_GROUP_CHANNELS-1 for channel messages
|
||||
// Index MAX_GROUP_CHANNELS for DMs (channel_idx == 0xFF)
|
||||
@@ -93,10 +126,13 @@ public:
|
||||
ChannelScreen(UITask* task, mesh::RTCClock* rtc)
|
||||
: _task(task), _rtc(rtc), _msgCount(0), _newestIdx(-1), _scrollPos(0),
|
||||
_msgsPerPage(6), _viewChannelIdx(0), _sdReady(false), _showPathOverlay(false), _pathScrollPos(0), _pathHopsVisible(20),
|
||||
_replySelectMode(false), _replySelectPos(-1), _replyChannelMsgCount(0) {
|
||||
_replySelectMode(false), _replySelectPos(-1), _replyChannelMsgCount(0),
|
||||
_dmInboxMode(true), _dmInboxScroll(0), _dmContactIdx(-1), _dmContactPerms(0), _dmUnreadPtr(nullptr) {
|
||||
_dmFilterName[0] = '\0';
|
||||
// Initialize all messages as invalid
|
||||
for (int i = 0; i < CHANNEL_MSG_HISTORY_SIZE; i++) {
|
||||
_messages[i].valid = false;
|
||||
_messages[i].dm_peer_hash = 0;
|
||||
memset(_messages[i].path, 0, MSG_PATH_MAX);
|
||||
}
|
||||
// Initialize unread counts
|
||||
@@ -106,8 +142,9 @@ public:
|
||||
void setSDReady(bool ready) { _sdReady = ready; }
|
||||
|
||||
// Add a new message to the history
|
||||
// peer_name: for DMs, the contact this message belongs to (sender for received, recipient for sent)
|
||||
void addMessage(uint8_t channel_idx, uint8_t path_len, const char* sender, const char* text,
|
||||
const uint8_t* path_bytes = nullptr, int8_t snr = 0) {
|
||||
const uint8_t* path_bytes = nullptr, int8_t snr = 0, const char* peer_name = nullptr) {
|
||||
// Move to next slot in circular buffer
|
||||
_newestIdx = (_newestIdx + 1) % CHANNEL_MSG_HISTORY_SIZE;
|
||||
|
||||
@@ -118,6 +155,13 @@ public:
|
||||
msg->snr = snr;
|
||||
msg->valid = true;
|
||||
|
||||
// Set DM peer hash for conversation filtering
|
||||
if (channel_idx == 0xFF) {
|
||||
msg->dm_peer_hash = peerHash(peer_name ? peer_name : sender);
|
||||
} else {
|
||||
msg->dm_peer_hash = 0;
|
||||
}
|
||||
|
||||
// Store path hop hashes
|
||||
memset(msg->path, 0, MSG_PATH_MAX);
|
||||
if (path_bytes && path_len > 0 && path_len != 0xFF) {
|
||||
@@ -158,7 +202,7 @@ public:
|
||||
int getMessageCountForChannel() const {
|
||||
int count = 0;
|
||||
for (int i = 0; i < CHANNEL_MSG_HISTORY_SIZE; i++) {
|
||||
if (_messages[i].valid && _messages[i].channel_idx == _viewChannelIdx) {
|
||||
if (msgMatchesView(_messages[i])) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
@@ -173,11 +217,47 @@ public:
|
||||
_scrollPos = 0;
|
||||
_showPathOverlay = false;
|
||||
_pathScrollPos = 0;
|
||||
// Reset DM inbox state when entering DM tab
|
||||
if (idx == 0xFF) {
|
||||
_dmInboxMode = true;
|
||||
_dmInboxScroll = 0;
|
||||
_dmFilterName[0] = '\0';
|
||||
_dmContactIdx = -1;
|
||||
_dmContactPerms = 0;
|
||||
}
|
||||
markChannelRead(idx);
|
||||
}
|
||||
bool isDMTab() const { return _viewChannelIdx == 0xFF; }
|
||||
bool isDMInboxMode() const { return _viewChannelIdx == 0xFF && _dmInboxMode; }
|
||||
bool isDMConversation() const { return _viewChannelIdx == 0xFF && !_dmInboxMode; }
|
||||
const char* getDMFilterName() const { return _dmFilterName; }
|
||||
|
||||
// Open a specific contact's DM conversation directly (skipping inbox)
|
||||
void openConversation(const char* contactName, int contactIdx = -1, uint8_t perms = 0) {
|
||||
strncpy(_dmFilterName, contactName, sizeof(_dmFilterName) - 1);
|
||||
_dmFilterName[sizeof(_dmFilterName) - 1] = '\0';
|
||||
_dmInboxMode = false;
|
||||
_dmContactIdx = contactIdx;
|
||||
_dmContactPerms = perms;
|
||||
_scrollPos = 0;
|
||||
}
|
||||
|
||||
int getDMContactIdx() const { return _dmContactIdx; }
|
||||
uint8_t getDMContactPerms() const { return _dmContactPerms; }
|
||||
void setDMContactPerms(uint8_t p) { _dmContactPerms = p; }
|
||||
bool isShowingPathOverlay() const { return _showPathOverlay; }
|
||||
void dismissPathOverlay() { _showPathOverlay = false; _pathScrollPos = 0; }
|
||||
|
||||
// Set pointer to per-contact DM unread array (called by UITask after allocation)
|
||||
void setDMUnreadPtr(const uint8_t* ptr) { _dmUnreadPtr = ptr; }
|
||||
|
||||
// Subtract a specific amount from the DM unread slot (used by per-contact clearing)
|
||||
void subtractDMUnread(int count) {
|
||||
int slot = MAX_GROUP_CHANNELS; // DM slot
|
||||
_unread[slot] -= count;
|
||||
if (_unread[slot] < 0) _unread[slot] = 0;
|
||||
}
|
||||
|
||||
// --- Reply select mode (R key → pick a message → Enter to @mention reply) ---
|
||||
bool isReplySelectMode() const { return _replySelectMode; }
|
||||
void exitReplySelect() { _replySelectMode = false; _replySelectPos = -1; }
|
||||
@@ -206,7 +286,7 @@ public:
|
||||
int idx = _newestIdx - i;
|
||||
while (idx < 0) idx += CHANNEL_MSG_HISTORY_SIZE;
|
||||
idx = idx % CHANNEL_MSG_HISTORY_SIZE;
|
||||
if (_messages[idx].valid && _messages[idx].channel_idx == _viewChannelIdx) {
|
||||
if (_messages[idx].valid && msgMatchesView(_messages[idx])) {
|
||||
rsMsgs[count++] = idx;
|
||||
}
|
||||
}
|
||||
@@ -230,7 +310,7 @@ public:
|
||||
int idx = _newestIdx - i;
|
||||
while (idx < 0) idx += CHANNEL_MSG_HISTORY_SIZE;
|
||||
idx = idx % CHANNEL_MSG_HISTORY_SIZE;
|
||||
if (_messages[idx].valid && _messages[idx].channel_idx == _viewChannelIdx) {
|
||||
if (_messages[idx].valid && msgMatchesView(_messages[idx])) {
|
||||
rsMsgs[count++] = idx;
|
||||
}
|
||||
}
|
||||
@@ -277,7 +357,7 @@ public:
|
||||
int idx = _newestIdx - i;
|
||||
while (idx < 0) idx += CHANNEL_MSG_HISTORY_SIZE;
|
||||
idx = idx % CHANNEL_MSG_HISTORY_SIZE;
|
||||
if (_messages[idx].valid && _messages[idx].channel_idx == _viewChannelIdx
|
||||
if (msgMatchesView(_messages[idx])
|
||||
&& _messages[idx].path_len != 0) {
|
||||
return &_messages[idx];
|
||||
}
|
||||
@@ -449,7 +529,15 @@ public:
|
||||
|
||||
// Get channel name
|
||||
ChannelDetails channel;
|
||||
if (the_mesh.getChannel(_viewChannelIdx, channel)) {
|
||||
if (_viewChannelIdx == 0xFF) {
|
||||
if (_dmInboxMode) {
|
||||
display.print("Direct Messages");
|
||||
} else {
|
||||
char hdr[40];
|
||||
snprintf(hdr, sizeof(hdr), "DM: %s", _dmFilterName);
|
||||
display.print(hdr);
|
||||
}
|
||||
} else if (the_mesh.getChannel(_viewChannelIdx, channel)) {
|
||||
display.print(channel.name);
|
||||
} else {
|
||||
sprintf(tmp, "Channel %d", _viewChannelIdx);
|
||||
@@ -464,11 +552,201 @@ public:
|
||||
|
||||
// Divider line
|
||||
display.drawRect(0, 11, display.width(), 1);
|
||||
|
||||
// === DM Inbox mode: show list of contacts with DMs ===
|
||||
if (_viewChannelIdx == 0xFF && _dmInboxMode) {
|
||||
#define DM_INBOX_MAX 20
|
||||
struct DMInboxEntry {
|
||||
uint32_t hash;
|
||||
char name[32];
|
||||
int msgCount;
|
||||
int unreadCount;
|
||||
uint32_t newestTs;
|
||||
};
|
||||
DMInboxEntry inbox[DM_INBOX_MAX];
|
||||
int inboxCount = 0;
|
||||
|
||||
// Scan all DMs and group by peer hash
|
||||
for (int i = 0; i < _msgCount && i < CHANNEL_MSG_HISTORY_SIZE; i++) {
|
||||
int idx = _newestIdx - i;
|
||||
while (idx < 0) idx += CHANNEL_MSG_HISTORY_SIZE;
|
||||
idx = idx % CHANNEL_MSG_HISTORY_SIZE;
|
||||
if (!_messages[idx].valid || _messages[idx].channel_idx != 0xFF) continue;
|
||||
if (_messages[idx].dm_peer_hash == 0) continue;
|
||||
|
||||
uint32_t h = _messages[idx].dm_peer_hash;
|
||||
|
||||
// Find existing entry by hash
|
||||
int found = -1;
|
||||
for (int j = 0; j < inboxCount; j++) {
|
||||
if (inbox[j].hash == h) { found = j; break; }
|
||||
}
|
||||
if (found < 0 && inboxCount < DM_INBOX_MAX) {
|
||||
found = inboxCount++;
|
||||
inbox[found].hash = h;
|
||||
inbox[found].name[0] = '\0';
|
||||
inbox[found].msgCount = 0;
|
||||
inbox[found].unreadCount = 0;
|
||||
inbox[found].newestTs = 0;
|
||||
|
||||
// Look up name from contacts by matching peer hash
|
||||
uint32_t numC = the_mesh.getNumContacts();
|
||||
ContactInfo ci;
|
||||
for (uint32_t c = 0; c < numC; c++) {
|
||||
if (the_mesh.getContactByIdx(c, ci) && peerHash(ci.name) == h) {
|
||||
strncpy(inbox[found].name, ci.name, 31);
|
||||
inbox[found].name[31] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Fallback: extract from text if contact not found
|
||||
if (inbox[found].name[0] == '\0') {
|
||||
extractSenderName(_messages[idx].text, inbox[found].name, sizeof(inbox[found].name));
|
||||
}
|
||||
}
|
||||
if (found >= 0) {
|
||||
inbox[found].msgCount++;
|
||||
if (_messages[idx].timestamp > inbox[found].newestTs)
|
||||
inbox[found].newestTs = _messages[idx].timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
// Look up unread counts from per-contact array
|
||||
if (_dmUnreadPtr) {
|
||||
for (int e = 0; e < inboxCount; e++) {
|
||||
uint32_t numC = the_mesh.getNumContacts();
|
||||
ContactInfo ci;
|
||||
for (uint32_t c = 0; c < numC; c++) {
|
||||
if (the_mesh.getContactByIdx(c, ci) && peerHash(ci.name) == inbox[e].hash) {
|
||||
inbox[e].unreadCount = _dmUnreadPtr[c];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sort by newest timestamp descending (insertion sort)
|
||||
for (int i = 1; i < inboxCount; i++) {
|
||||
DMInboxEntry tmp2 = inbox[i];
|
||||
int j = i - 1;
|
||||
while (j >= 0 && inbox[j].newestTs < tmp2.newestTs) {
|
||||
inbox[j + 1] = inbox[j];
|
||||
j--;
|
||||
}
|
||||
inbox[j + 1] = tmp2;
|
||||
}
|
||||
|
||||
// Render inbox list
|
||||
display.setTextSize(the_mesh.getNodePrefs()->smallTextSize());
|
||||
int lineH = the_mesh.getNodePrefs()->smallLineH();
|
||||
int headerH = 14;
|
||||
int footerH = 14;
|
||||
int maxY = display.height() - footerH;
|
||||
int y = headerH;
|
||||
int maxVisible = (maxY - headerH) / lineH;
|
||||
if (maxVisible < 3) maxVisible = 3;
|
||||
|
||||
// Clamp scroll
|
||||
if (_dmInboxScroll >= inboxCount) _dmInboxScroll = inboxCount > 0 ? inboxCount - 1 : 0;
|
||||
|
||||
if (inboxCount == 0) {
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.setCursor(0, y);
|
||||
display.print("No direct messages");
|
||||
display.setCursor(0, y + lineH);
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.print("DMs from contacts appear here");
|
||||
#else
|
||||
display.print("A/D: Switch channel");
|
||||
#endif
|
||||
} else {
|
||||
int startIdx = max(0, min(_dmInboxScroll - maxVisible / 2,
|
||||
inboxCount - maxVisible));
|
||||
int endIdx = min(inboxCount, startIdx + maxVisible);
|
||||
|
||||
for (int i = startIdx; i < endIdx && y + lineH <= maxY; i++) {
|
||||
bool selected = (i == _dmInboxScroll);
|
||||
|
||||
if (selected) {
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.fillRect(0, y, display.width(), lineH);
|
||||
#else
|
||||
display.fillRect(0, y + the_mesh.getNodePrefs()->smallHighlightOff(), display.width(), lineH);
|
||||
#endif
|
||||
display.setColor(DisplayDriver::DARK);
|
||||
} else {
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
}
|
||||
|
||||
display.setCursor(0, y);
|
||||
|
||||
// Prefix: > for selected, unread indicator
|
||||
char prefix[6];
|
||||
if (inbox[i].unreadCount > 0) {
|
||||
snprintf(prefix, sizeof(prefix), "%s*%d", selected ? ">" : " ", inbox[i].unreadCount);
|
||||
} else {
|
||||
snprintf(prefix, sizeof(prefix), "%s ", selected ? ">" : " ");
|
||||
}
|
||||
display.print(prefix);
|
||||
|
||||
// Name (truncated)
|
||||
char filteredName[32];
|
||||
display.translateUTF8ToBlocks(filteredName, inbox[i].name, sizeof(filteredName));
|
||||
|
||||
// Right side: message count + age
|
||||
char ageStr[8];
|
||||
uint32_t age = _rtc->getCurrentTime() - inbox[i].newestTs;
|
||||
if (age < 60) snprintf(ageStr, sizeof(ageStr), "%ds", age);
|
||||
else if (age < 3600) snprintf(ageStr, sizeof(ageStr), "%dm", age / 60);
|
||||
else if (age < 86400) snprintf(ageStr, sizeof(ageStr), "%dh", age / 3600);
|
||||
else snprintf(ageStr, sizeof(ageStr), "%dd", age / 86400);
|
||||
|
||||
char rightStr[16];
|
||||
snprintf(rightStr, sizeof(rightStr), "(%d) %s", inbox[i].msgCount, ageStr);
|
||||
int rightW = display.getTextWidth(rightStr) + 2;
|
||||
|
||||
int nameX = display.getTextWidth(prefix) + 2;
|
||||
int nameMaxW = display.width() - nameX - rightW - 2;
|
||||
display.drawTextEllipsized(nameX, y, nameMaxW, filteredName);
|
||||
|
||||
display.setCursor(display.width() - rightW, y);
|
||||
display.print(rightStr);
|
||||
|
||||
y += lineH;
|
||||
}
|
||||
}
|
||||
|
||||
// Footer
|
||||
display.setTextSize(1);
|
||||
int footerY = display.height() - 12;
|
||||
display.drawRect(0, footerY - 2, display.width(), 1);
|
||||
display.setColor(DisplayDriver::YELLOW);
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.setCursor(0, footerY);
|
||||
display.print("Swipe:Nav");
|
||||
const char* rtInbox = "Hold:Open";
|
||||
display.setCursor(display.width() - display.getTextWidth(rtInbox) - 2, footerY);
|
||||
display.print(rtInbox);
|
||||
#else
|
||||
display.setCursor(0, footerY);
|
||||
display.print("Q:Bck A/D:Ch");
|
||||
const char* rtInbox = "Ent:Open";
|
||||
display.setCursor(display.width() - display.getTextWidth(rtInbox) - 2, footerY);
|
||||
display.print(rtInbox);
|
||||
#endif
|
||||
|
||||
#ifdef USE_EINK
|
||||
return 5000;
|
||||
#else
|
||||
return 1000;
|
||||
#endif
|
||||
}
|
||||
|
||||
// --- Path detail overlay ---
|
||||
if (_showPathOverlay) {
|
||||
display.setTextSize(0);
|
||||
int lineH = 9;
|
||||
display.setTextSize(the_mesh.getNodePrefs()->smallTextSize());
|
||||
int lineH = the_mesh.getNodePrefs()->smallLineH();
|
||||
int y = 14;
|
||||
|
||||
ChannelMessage* msg = getNewestReceivedMsg();
|
||||
@@ -664,24 +942,160 @@ public:
|
||||
}
|
||||
|
||||
if (channelMsgCount == 0) {
|
||||
display.setTextSize(0); // Tiny font for body text
|
||||
display.setTextSize(the_mesh.getNodePrefs()->smallTextSize()); // Tiny font for body text
|
||||
display.setCursor(0, 20);
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.print("No messages yet");
|
||||
display.setCursor(0, 30);
|
||||
if (_viewChannelIdx == 0xFF) {
|
||||
char noMsg[48];
|
||||
snprintf(noMsg, sizeof(noMsg), "No messages from %s", _dmFilterName);
|
||||
display.print(noMsg);
|
||||
display.setCursor(0, 30);
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.print("Swipe: Switch channel");
|
||||
display.setCursor(0, 40);
|
||||
display.print("Long press: Compose");
|
||||
display.print("Hold: Compose reply");
|
||||
#else
|
||||
display.print("A/D: Switch channel");
|
||||
display.setCursor(0, 40);
|
||||
display.print("C: Compose message");
|
||||
display.print("Q: Back to inbox");
|
||||
display.setCursor(0, 40);
|
||||
display.print("Ent: Compose reply");
|
||||
#endif
|
||||
} else {
|
||||
display.print("No messages yet");
|
||||
display.setCursor(0, 30);
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.print("Swipe: Switch channel");
|
||||
display.setCursor(0, 40);
|
||||
display.print("Long press: Compose");
|
||||
#else
|
||||
display.print("A/D: Switch channel");
|
||||
display.setCursor(0, 40);
|
||||
display.print("C: Compose message");
|
||||
#endif
|
||||
}
|
||||
display.setTextSize(1); // Restore for footer
|
||||
} else if (_viewChannelIdx == 0xFF && _dmInboxMode) {
|
||||
// =================================================================
|
||||
// DM Inbox: list of contacts/rooms you have DM history with
|
||||
// =================================================================
|
||||
display.setTextSize(the_mesh.getNodePrefs()->smallTextSize());
|
||||
int lineHeight = the_mesh.getNodePrefs()->smallLineH();
|
||||
int headerHeight = 14;
|
||||
int footerHeight = 14;
|
||||
int maxY = display.height() - footerHeight;
|
||||
int y = headerHeight;
|
||||
|
||||
// Scan all DM messages and collect unique senders
|
||||
#define DM_INBOX_MAX 16
|
||||
struct InboxEntry {
|
||||
char name[24];
|
||||
int count;
|
||||
uint32_t newest_ts;
|
||||
};
|
||||
static InboxEntry inbox[DM_INBOX_MAX];
|
||||
int inboxCount = 0;
|
||||
|
||||
for (int i = 0; i < _msgCount; i++) {
|
||||
int idx = _newestIdx - i;
|
||||
while (idx < 0) idx += CHANNEL_MSG_HISTORY_SIZE;
|
||||
idx = idx % CHANNEL_MSG_HISTORY_SIZE;
|
||||
if (!_messages[idx].valid || _messages[idx].channel_idx != 0xFF) continue;
|
||||
|
||||
char sender[24];
|
||||
if (!extractSenderName(_messages[idx].text, sender, sizeof(sender))) continue;
|
||||
|
||||
// Find or add sender in inbox
|
||||
bool found = false;
|
||||
for (int j = 0; j < inboxCount; j++) {
|
||||
if (strcmp(inbox[j].name, sender) == 0) {
|
||||
inbox[j].count++;
|
||||
if (_messages[idx].timestamp > inbox[j].newest_ts)
|
||||
inbox[j].newest_ts = _messages[idx].timestamp;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found && inboxCount < DM_INBOX_MAX) {
|
||||
strncpy(inbox[inboxCount].name, sender, 23);
|
||||
inbox[inboxCount].name[23] = '\0';
|
||||
inbox[inboxCount].count = 1;
|
||||
inbox[inboxCount].newest_ts = _messages[idx].timestamp;
|
||||
inboxCount++;
|
||||
}
|
||||
}
|
||||
|
||||
// Sort by newest timestamp descending (most recent first)
|
||||
for (int i = 1; i < inboxCount; i++) {
|
||||
InboxEntry tmp2 = inbox[i];
|
||||
int j = i - 1;
|
||||
while (j >= 0 && inbox[j].newest_ts < tmp2.newest_ts) {
|
||||
inbox[j + 1] = inbox[j];
|
||||
j--;
|
||||
}
|
||||
inbox[j + 1] = tmp2;
|
||||
}
|
||||
|
||||
if (inboxCount == 0) {
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.setCursor(0, y);
|
||||
display.print("No conversations");
|
||||
} else {
|
||||
// Clamp scroll
|
||||
if (_dmInboxScroll >= inboxCount) _dmInboxScroll = inboxCount - 1;
|
||||
if (_dmInboxScroll < 0) _dmInboxScroll = 0;
|
||||
|
||||
int maxVisible = (maxY - headerHeight) / lineHeight;
|
||||
if (maxVisible < 3) maxVisible = 3;
|
||||
int startIdx = max(0, min(_dmInboxScroll - maxVisible / 2,
|
||||
inboxCount - maxVisible));
|
||||
int endIdx = min(inboxCount, startIdx + maxVisible);
|
||||
|
||||
uint32_t now = _rtc->getCurrentTime();
|
||||
for (int i = startIdx; i < endIdx && y + lineHeight <= maxY; i++) {
|
||||
bool selected = (i == _dmInboxScroll);
|
||||
|
||||
if (selected) {
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.fillRect(0, y, display.width(), lineHeight);
|
||||
#else
|
||||
display.fillRect(0, y + the_mesh.getNodePrefs()->smallHighlightOff(), display.width(), lineHeight);
|
||||
#endif
|
||||
display.setColor(DisplayDriver::DARK);
|
||||
} else {
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
}
|
||||
|
||||
display.setCursor(0, y);
|
||||
display.print(selected ? ">" : " ");
|
||||
|
||||
// Name (ellipsized)
|
||||
char filteredName[24];
|
||||
display.translateUTF8ToBlocks(filteredName, inbox[i].name, sizeof(filteredName));
|
||||
|
||||
// Right side: message count + age
|
||||
char ageStr[8];
|
||||
uint32_t age = now - inbox[i].newest_ts;
|
||||
if (age < 60) snprintf(ageStr, sizeof(ageStr), "%ds", age);
|
||||
else if (age < 3600) snprintf(ageStr, sizeof(ageStr), "%dm", age / 60);
|
||||
else if (age < 86400) snprintf(ageStr, sizeof(ageStr), "%dh", age / 3600);
|
||||
else snprintf(ageStr, sizeof(ageStr), "%dd", age / 86400);
|
||||
|
||||
char rightStr[16];
|
||||
snprintf(rightStr, sizeof(rightStr), "[%d] %s", inbox[i].count, ageStr);
|
||||
int rightW = display.getTextWidth(rightStr) + 2;
|
||||
|
||||
int nameX = display.getTextWidth(">") + 2;
|
||||
int nameMaxW = display.width() - nameX - rightW - 2;
|
||||
display.drawTextEllipsized(nameX, y, nameMaxW, filteredName);
|
||||
|
||||
display.setCursor(display.width() - rightW, y);
|
||||
display.print(rightStr);
|
||||
|
||||
y += lineHeight;
|
||||
}
|
||||
}
|
||||
display.setTextSize(1);
|
||||
} else {
|
||||
display.setTextSize(0); // Tiny font for message body
|
||||
int lineHeight = 9; // 8px font + 1px spacing
|
||||
display.setTextSize(the_mesh.getNodePrefs()->smallTextSize()); // Tiny font for message body
|
||||
int lineHeight = the_mesh.getNodePrefs()->smallLineH(); // 8px font + 1px spacing
|
||||
int headerHeight = 14;
|
||||
int footerHeight = 14;
|
||||
int scrollBarW = 4; // Width of scroll indicator on right edge
|
||||
@@ -701,7 +1115,7 @@ public:
|
||||
while (idx < 0) idx += CHANNEL_MSG_HISTORY_SIZE;
|
||||
idx = idx % CHANNEL_MSG_HISTORY_SIZE;
|
||||
|
||||
if (_messages[idx].valid && _messages[idx].channel_idx == _viewChannelIdx) {
|
||||
if (msgMatchesView(_messages[idx])) {
|
||||
channelMsgs[numChannelMsgs++] = idx;
|
||||
}
|
||||
}
|
||||
@@ -749,7 +1163,7 @@ public:
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.fillRect(0, y, contentW, maxFillH);
|
||||
#else
|
||||
display.fillRect(0, y + 5, contentW, maxFillH);
|
||||
display.fillRect(0, y + the_mesh.getNodePrefs()->smallHighlightOff(), contentW, maxFillH);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -910,7 +1324,7 @@ public:
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.fillRect(0, y, contentW, maxFillH - usedH);
|
||||
#else
|
||||
display.fillRect(0, y + 5, contentW, maxFillH - usedH);
|
||||
display.fillRect(0, y + the_mesh.getNodePrefs()->smallHighlightOff(), contentW, maxFillH - usedH);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -968,13 +1382,20 @@ public:
|
||||
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.setCursor(0, footerY);
|
||||
display.print("Swipe:Ch/Scroll");
|
||||
const char* midCh = "Tap:Path";
|
||||
display.setCursor((display.width() - display.getTextWidth(midCh)) / 2, footerY);
|
||||
display.print(midCh);
|
||||
const char* rtCh = "Hold:Compose";
|
||||
display.setCursor(display.width() - display.getTextWidth(rtCh) - 2, footerY);
|
||||
display.print(rtCh);
|
||||
if (_viewChannelIdx == 0xFF) {
|
||||
display.print("Swipe:Scroll");
|
||||
const char* rtCh = "Hold:Reply";
|
||||
display.setCursor(display.width() - display.getTextWidth(rtCh) - 2, footerY);
|
||||
display.print(rtCh);
|
||||
} else {
|
||||
display.print("Swipe:Ch/Scroll");
|
||||
const char* midCh = "Tap:Path";
|
||||
display.setCursor((display.width() - display.getTextWidth(midCh)) / 2, footerY);
|
||||
display.print(midCh);
|
||||
const char* rtCh = "Hold:Compose";
|
||||
display.setCursor(display.width() - display.getTextWidth(rtCh) - 2, footerY);
|
||||
display.print(rtCh);
|
||||
}
|
||||
#else
|
||||
// Left side: abbreviated controls
|
||||
if (_replySelectMode) {
|
||||
@@ -982,6 +1403,15 @@ public:
|
||||
const char* rightText = "Ent:Reply";
|
||||
display.setCursor(display.width() - display.getTextWidth(rightText) - 2, footerY);
|
||||
display.print(rightText);
|
||||
} else if (_viewChannelIdx == 0xFF) {
|
||||
if (_dmContactPerms > 0) {
|
||||
display.print("Q:Exit L:Admin");
|
||||
} else {
|
||||
display.print("Q:Exit");
|
||||
}
|
||||
const char* rightText = "Ent:Reply";
|
||||
display.setCursor(display.width() - display.getTextWidth(rightText) - 2, footerY);
|
||||
display.print(rightText);
|
||||
} else {
|
||||
display.print("Q:Bck A/D:Ch R:Rply");
|
||||
const char* rightText = "Ent:New";
|
||||
@@ -1080,10 +1510,92 @@ public:
|
||||
return true; // Consume all other keys in reply select
|
||||
}
|
||||
|
||||
// --- DM Inbox mode (two-level DM view) ---
|
||||
if (_viewChannelIdx == 0xFF && _dmInboxMode) {
|
||||
// W - scroll up in inbox
|
||||
if (c == 'w' || c == 'W' || c == 0xF2) {
|
||||
if (_dmInboxScroll > 0) { _dmInboxScroll--; return true; }
|
||||
return false;
|
||||
}
|
||||
// S - scroll down in inbox
|
||||
if (c == 's' || c == 'S' || c == 0xF1) {
|
||||
_dmInboxScroll++; // Clamped during render
|
||||
return true;
|
||||
}
|
||||
// Enter - open conversation for selected entry
|
||||
if (c == '\r' || c == 13) {
|
||||
// Rebuild inbox by hash to find the selected entry
|
||||
uint32_t seenHash[DM_INBOX_MAX];
|
||||
int cur = 0;
|
||||
for (int i = 0; i < _msgCount; i++) {
|
||||
int idx = _newestIdx - i;
|
||||
while (idx < 0) idx += CHANNEL_MSG_HISTORY_SIZE;
|
||||
idx = idx % CHANNEL_MSG_HISTORY_SIZE;
|
||||
if (!_messages[idx].valid || _messages[idx].channel_idx != 0xFF) continue;
|
||||
if (_messages[idx].dm_peer_hash == 0) continue;
|
||||
|
||||
uint32_t h = _messages[idx].dm_peer_hash;
|
||||
bool dup = false;
|
||||
for (int k = 0; k < cur; k++) {
|
||||
if (seenHash[k] == h) { dup = true; break; }
|
||||
}
|
||||
if (dup) continue;
|
||||
if (cur < DM_INBOX_MAX) seenHash[cur] = h;
|
||||
|
||||
if (cur == _dmInboxScroll) {
|
||||
// Found the selected entry — look up name from contacts
|
||||
_dmFilterName[0] = '\0';
|
||||
_dmContactIdx = -1;
|
||||
_dmContactPerms = 0;
|
||||
uint32_t numC = the_mesh.getNumContacts();
|
||||
ContactInfo ci;
|
||||
for (uint32_t c2 = 0; c2 < numC; c2++) {
|
||||
if (the_mesh.getContactByIdx(c2, ci) && peerHash(ci.name) == h) {
|
||||
strncpy(_dmFilterName, ci.name, sizeof(_dmFilterName) - 1);
|
||||
_dmFilterName[sizeof(_dmFilterName) - 1] = '\0';
|
||||
_dmContactIdx = (int)c2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Fallback to text extraction if contact not found
|
||||
if (_dmFilterName[0] == '\0') {
|
||||
extractSenderName(_messages[idx].text, _dmFilterName, sizeof(_dmFilterName));
|
||||
}
|
||||
_dmInboxMode = false;
|
||||
_scrollPos = 0;
|
||||
return true;
|
||||
}
|
||||
cur++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// Q - let main.cpp handle (back to home)
|
||||
if (c == 'q' || c == 'Q' || c == '\b') {
|
||||
return false;
|
||||
}
|
||||
// A/D pass through to channel switching below
|
||||
if (c == 'a' || c == 'A' || c == 'd' || c == 'D') {
|
||||
// Fall through to channel switching
|
||||
} else {
|
||||
return true; // Consume other keys
|
||||
}
|
||||
}
|
||||
|
||||
// --- DM Conversation mode: Q goes back to inbox ---
|
||||
if (_viewChannelIdx == 0xFF && !_dmInboxMode) {
|
||||
if (c == 'q' || c == 'Q' || c == '\b') {
|
||||
_dmInboxMode = true;
|
||||
_dmFilterName[0] = '\0';
|
||||
_scrollPos = 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
int channelMsgCount = getMessageCountForChannel();
|
||||
|
||||
// R - enter reply select mode
|
||||
// R - enter reply select mode (group channels only — DM tab uses Enter to reply)
|
||||
if (c == 'r' || c == 'R') {
|
||||
if (_viewChannelIdx == 0xFF) return false; // Not applicable on DM tab
|
||||
if (channelMsgCount > 0) {
|
||||
_replySelectMode = true;
|
||||
// Start with newest message selected
|
||||
@@ -1120,14 +1632,12 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
// A - previous channel
|
||||
// A - previous channel (includes DM tab at 0xFF)
|
||||
if (c == 'a' || c == 'A') {
|
||||
_replySelectMode = false;
|
||||
_replySelectPos = -1;
|
||||
if (_viewChannelIdx > 0) {
|
||||
_viewChannelIdx--;
|
||||
} else {
|
||||
// Wrap to last valid channel
|
||||
if (_viewChannelIdx == 0xFF) {
|
||||
// DM tab → go to last valid group channel
|
||||
for (uint8_t i = MAX_GROUP_CHANNELS - 1; i > 0; i--) {
|
||||
ChannelDetails ch;
|
||||
if (the_mesh.getChannel(i, ch) && ch.name[0] != '\0') {
|
||||
@@ -1135,22 +1645,64 @@ public:
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (_viewChannelIdx > 0) {
|
||||
// Skip backwards over any empty/gap slots
|
||||
uint8_t prev = _viewChannelIdx - 1;
|
||||
bool found = false;
|
||||
while (true) {
|
||||
ChannelDetails ch;
|
||||
if (the_mesh.getChannel(prev, ch) && ch.name[0] != '\0') {
|
||||
_viewChannelIdx = prev;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
if (prev == 0) break;
|
||||
prev--;
|
||||
}
|
||||
if (!found) {
|
||||
// No valid channel below → wrap to DM tab
|
||||
_viewChannelIdx = 0xFF;
|
||||
_dmInboxMode = true;
|
||||
_dmInboxScroll = 0;
|
||||
_dmFilterName[0] = '\0';
|
||||
}
|
||||
} else {
|
||||
// Channel 0 → wrap to DM tab
|
||||
_viewChannelIdx = 0xFF;
|
||||
_dmInboxMode = true;
|
||||
_dmInboxScroll = 0;
|
||||
_dmFilterName[0] = '\0';
|
||||
}
|
||||
_scrollPos = 0;
|
||||
markChannelRead(_viewChannelIdx);
|
||||
return true;
|
||||
}
|
||||
|
||||
// D - next channel
|
||||
// D - next channel (includes DM tab at 0xFF)
|
||||
if (c == 'd' || c == 'D') {
|
||||
_replySelectMode = false;
|
||||
_replySelectPos = -1;
|
||||
ChannelDetails ch;
|
||||
uint8_t nextIdx = _viewChannelIdx + 1;
|
||||
if (the_mesh.getChannel(nextIdx, ch) && ch.name[0] != '\0') {
|
||||
_viewChannelIdx = nextIdx;
|
||||
} else {
|
||||
if (_viewChannelIdx == 0xFF) {
|
||||
// DM tab → wrap to channel 0
|
||||
_viewChannelIdx = 0;
|
||||
} else {
|
||||
// Skip forward over any empty/gap slots
|
||||
bool found = false;
|
||||
for (uint8_t next = _viewChannelIdx + 1; next < MAX_GROUP_CHANNELS; next++) {
|
||||
ChannelDetails ch;
|
||||
if (the_mesh.getChannel(next, ch) && ch.name[0] != '\0') {
|
||||
_viewChannelIdx = next;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
// Past last channel → go to DM tab
|
||||
_viewChannelIdx = 0xFF;
|
||||
_dmInboxMode = true;
|
||||
_dmInboxScroll = 0;
|
||||
_dmFilterName[0] = '\0';
|
||||
}
|
||||
}
|
||||
_scrollPos = 0;
|
||||
markChannelRead(_viewChannelIdx);
|
||||
|
||||
@@ -4,7 +4,11 @@
|
||||
#include <helpers/ui/DisplayDriver.h>
|
||||
#include <MeshCore.h>
|
||||
|
||||
// Forward declarations
|
||||
// Timestamps before this (Jan 1 2026 UTC) are treated as invalid/unsynced
|
||||
#define EPOCH_2026 1735689600UL
|
||||
|
||||
// Forward declarations — MyMesh.h (which defines AdvertPath) is always
|
||||
// included by the translation unit before this header.
|
||||
class UITask;
|
||||
class MyMesh;
|
||||
extern MyMesh the_mesh;
|
||||
@@ -33,13 +37,22 @@ private:
|
||||
// We rebuild this on filter change or when entering the screen
|
||||
// Arrays allocated in PSRAM when available (supports 1000+ contacts)
|
||||
uint16_t* _filteredIdx; // indices into contact table
|
||||
uint32_t* _filteredTs; // cached last_advert_timestamp for sorting
|
||||
uint32_t* _filteredTs; // cached lastmod for sorting
|
||||
int _filteredCount; // how many contacts match current filter
|
||||
AdvertPath _hopBuf[40]; // recently heard advert paths for hop-count display
|
||||
int _hopBufCount;
|
||||
bool _cacheValid;
|
||||
|
||||
// How many rows fit on screen (computed during render)
|
||||
int _rowsPerPage;
|
||||
|
||||
// Pointer to per-contact DM unread array (owned by UITask, set via setter)
|
||||
const uint8_t* _dmUnread = nullptr;
|
||||
|
||||
// --- Select mode state ---
|
||||
bool _selectMode;
|
||||
uint8_t* _selectedBits; // Bitfield: 1 bit per MAX_CONTACTS raw index
|
||||
|
||||
// --- helpers ---
|
||||
|
||||
static const char* filterLabel(FilterMode f) {
|
||||
@@ -54,12 +67,12 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
static char typeChar(uint8_t adv_type) {
|
||||
static const char* typeStr(uint8_t adv_type) {
|
||||
switch (adv_type) {
|
||||
case ADV_TYPE_CHAT: return 'C';
|
||||
case ADV_TYPE_REPEATER: return 'R';
|
||||
case ADV_TYPE_ROOM: return 'S'; // Server
|
||||
default: return '?';
|
||||
case ADV_TYPE_CHAT: return "C";
|
||||
case ADV_TYPE_REPEATER: return "R";
|
||||
case ADV_TYPE_ROOM: return "RS";
|
||||
default: return "?";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,12 +98,13 @@ private:
|
||||
if (the_mesh.getContactByIdx(i, contact)) {
|
||||
if (matchesFilter(contact.type, contact.flags)) {
|
||||
_filteredIdx[_filteredCount] = (uint16_t)i;
|
||||
_filteredTs[_filteredCount] = contact.last_advert_timestamp;
|
||||
// Use lastmod (our receive time) for sort/age; pre-2026 or zero → 0 sinks to bottom
|
||||
_filteredTs[_filteredCount] = (contact.lastmod >= EPOCH_2026) ? contact.lastmod : 0;
|
||||
_filteredCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Sort by last_advert_timestamp descending (most recently seen first)
|
||||
// Sort by lastmod descending (most recently heard first; pre-2026/unsynced sink to bottom)
|
||||
// Insertion sort — fine for up to ~1000 entries on ESP32
|
||||
for (int i = 1; i < _filteredCount; i++) {
|
||||
uint16_t tmpIdx = _filteredIdx[i];
|
||||
@@ -105,46 +119,64 @@ private:
|
||||
_filteredTs[j + 1] = tmpTs;
|
||||
}
|
||||
_cacheValid = true;
|
||||
// Refresh hop-count cache from the 12 most recently heard adverts
|
||||
_hopBufCount = the_mesh.getRecentlyHeard(_hopBuf, 40);
|
||||
// Clamp scroll position
|
||||
if (_scrollPos >= _filteredCount) {
|
||||
_scrollPos = (_filteredCount > 0) ? _filteredCount - 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Format seconds-ago as compact string: "3s" "5m" "2h" "4d" "??"
|
||||
// Format seconds-ago as compact string: "3s" "5m" "2h" "4d" "--"
|
||||
static void formatAge(char* buf, size_t bufLen, uint32_t now, uint32_t timestamp) {
|
||||
if (timestamp == 0) {
|
||||
if (timestamp == 0 || timestamp < EPOCH_2026 || now < timestamp) {
|
||||
strncpy(buf, "--", bufLen);
|
||||
return;
|
||||
}
|
||||
int secs = (int)(now - timestamp);
|
||||
if (secs < 0) secs = 0;
|
||||
uint32_t secs = now - timestamp;
|
||||
if (secs < 60) {
|
||||
snprintf(buf, bufLen, "%ds", secs);
|
||||
snprintf(buf, bufLen, "%ds", (int)secs);
|
||||
} else if (secs < 3600) {
|
||||
snprintf(buf, bufLen, "%dm", secs / 60);
|
||||
snprintf(buf, bufLen, "%dm", (int)(secs / 60));
|
||||
} else if (secs < 86400) {
|
||||
snprintf(buf, bufLen, "%dh", secs / 3600);
|
||||
snprintf(buf, bufLen, "%dh", (int)(secs / 3600));
|
||||
} else {
|
||||
snprintf(buf, bufLen, "%dd", secs / 86400);
|
||||
snprintf(buf, bufLen, "%dd", (int)(secs / 86400));
|
||||
}
|
||||
}
|
||||
|
||||
// --- Bitfield helpers ---
|
||||
bool isSelectedRaw(int rawIdx) const {
|
||||
if (rawIdx < 0 || rawIdx >= MAX_CONTACTS) return false;
|
||||
return (_selectedBits[rawIdx / 8] & (1 << (rawIdx % 8))) != 0;
|
||||
}
|
||||
void setSelectedRaw(int rawIdx, bool sel) {
|
||||
if (rawIdx < 0 || rawIdx >= MAX_CONTACTS) return;
|
||||
if (sel) _selectedBits[rawIdx / 8] |= (1 << (rawIdx % 8));
|
||||
else _selectedBits[rawIdx / 8] &= ~(1 << (rawIdx % 8));
|
||||
}
|
||||
|
||||
public:
|
||||
ContactsScreen(UITask* task, mesh::RTCClock* rtc)
|
||||
: _task(task), _rtc(rtc), _scrollPos(0), _filter(FILTER_ALL),
|
||||
_filteredCount(0), _cacheValid(false), _rowsPerPage(5) {
|
||||
_filteredCount(0), _cacheValid(false), _rowsPerPage(5),
|
||||
_selectMode(false), _hopBufCount(0) {
|
||||
#if defined(ESP32) && defined(BOARD_HAS_PSRAM)
|
||||
_filteredIdx = (uint16_t*)ps_calloc(MAX_CONTACTS, sizeof(uint16_t));
|
||||
_filteredTs = (uint32_t*)ps_calloc(MAX_CONTACTS, sizeof(uint32_t));
|
||||
_selectedBits = (uint8_t*)ps_calloc((MAX_CONTACTS + 7) / 8, 1);
|
||||
#else
|
||||
_filteredIdx = new uint16_t[MAX_CONTACTS]();
|
||||
_filteredTs = new uint32_t[MAX_CONTACTS]();
|
||||
_selectedBits = new uint8_t[(MAX_CONTACTS + 7) / 8]();
|
||||
#endif
|
||||
}
|
||||
|
||||
void invalidateCache() { _cacheValid = false; }
|
||||
|
||||
// Set pointer to per-contact DM unread array (called by UITask after allocation)
|
||||
void setDMUnreadPtr(const uint8_t* ptr) { _dmUnread = ptr; }
|
||||
|
||||
void resetScroll() {
|
||||
_scrollPos = 0;
|
||||
_cacheValid = false;
|
||||
@@ -152,6 +184,83 @@ public:
|
||||
|
||||
FilterMode getFilter() const { return _filter; }
|
||||
|
||||
// --- Select mode API ---
|
||||
bool isInSelectMode() const { return _selectMode; }
|
||||
|
||||
void enterSelectMode() {
|
||||
_selectMode = true;
|
||||
memset(_selectedBits, 0, (MAX_CONTACTS + 7) / 8);
|
||||
// Pre-select the currently highlighted contact
|
||||
if (_filteredCount > 0 && _scrollPos < _filteredCount) {
|
||||
setSelectedRaw(_filteredIdx[_scrollPos], true);
|
||||
}
|
||||
}
|
||||
|
||||
void exitSelectMode() {
|
||||
_selectMode = false;
|
||||
memset(_selectedBits, 0, (MAX_CONTACTS + 7) / 8);
|
||||
}
|
||||
|
||||
void toggleSelected() {
|
||||
if (_filteredCount == 0 || _scrollPos >= _filteredCount) return;
|
||||
int rawIdx = _filteredIdx[_scrollPos];
|
||||
setSelectedRaw(rawIdx, !isSelectedRaw(rawIdx));
|
||||
}
|
||||
|
||||
void selectAll() {
|
||||
for (int i = 0; i < _filteredCount; i++) {
|
||||
setSelectedRaw(_filteredIdx[i], true);
|
||||
}
|
||||
}
|
||||
|
||||
void deselectAll() {
|
||||
memset(_selectedBits, 0, (MAX_CONTACTS + 7) / 8);
|
||||
}
|
||||
|
||||
int getSelectedCount() const {
|
||||
int count = 0;
|
||||
for (int i = 0; i < _filteredCount; i++) {
|
||||
if (isSelectedRaw(_filteredIdx[i])) count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// Fill outBuf with raw contact table indices of selected contacts
|
||||
int getSelectedRawIndices(uint16_t* outBuf, int maxOut) const {
|
||||
int count = 0;
|
||||
for (int i = 0; i < _filteredCount && count < maxOut; i++) {
|
||||
if (isSelectedRaw(_filteredIdx[i])) {
|
||||
outBuf[count++] = _filteredIdx[i];
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// Tap-to-select: given virtual Y, select contact row.
|
||||
// Returns: 0=miss, 1=moved, 2=tapped current row.
|
||||
int selectRowAtVY(int vy) {
|
||||
if (_filteredCount == 0) return 0;
|
||||
const int headerH = 14, footerH = 14, lineH = the_mesh.getNodePrefs()->smallLineH();
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
const int bodyTop = headerH;
|
||||
#else
|
||||
const int bodyTop = headerH + the_mesh.getNodePrefs()->smallHighlightOff();
|
||||
#endif
|
||||
if (vy < bodyTop || vy >= 128 - footerH) return 0;
|
||||
|
||||
int maxVisible = (128 - headerH - footerH) / lineH;
|
||||
if (maxVisible < 3) maxVisible = 3;
|
||||
int startIdx = max(0, min(_scrollPos - maxVisible / 2,
|
||||
_filteredCount - maxVisible));
|
||||
|
||||
int tappedRow = startIdx + (vy - bodyTop) / lineH;
|
||||
if (tappedRow < 0 || tappedRow >= _filteredCount) return 0;
|
||||
|
||||
if (tappedRow == _scrollPos) return 2;
|
||||
_scrollPos = tappedRow;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Get the raw contact table index for the currently highlighted item
|
||||
// Returns -1 if no valid selection
|
||||
int getSelectedContactIdx() const {
|
||||
@@ -188,7 +297,12 @@ public:
|
||||
display.setTextSize(1);
|
||||
display.setColor(DisplayDriver::GREEN);
|
||||
display.setCursor(0, 0);
|
||||
snprintf(tmp, sizeof(tmp), "Contacts [%s]", filterLabel(_filter));
|
||||
if (_selectMode) {
|
||||
int selCount = getSelectedCount();
|
||||
snprintf(tmp, sizeof(tmp), "%d Selected [%s]", selCount, filterLabel(_filter));
|
||||
} else {
|
||||
snprintf(tmp, sizeof(tmp), "Contacts [%s]", filterLabel(_filter));
|
||||
}
|
||||
display.print(tmp);
|
||||
|
||||
// Count on right: All → total/max, filtered → matched/total
|
||||
@@ -204,8 +318,8 @@ public:
|
||||
display.drawRect(0, 11, display.width(), 1);
|
||||
|
||||
// === Body - contact rows ===
|
||||
display.setTextSize(0); // tiny font for compact rows
|
||||
int lineHeight = 9; // 8px font + 1px gap
|
||||
display.setTextSize(the_mesh.getNodePrefs()->smallTextSize()); // tiny font for compact rows
|
||||
int lineHeight = the_mesh.getNodePrefs()->smallLineH(); // 8px font + 1px gap
|
||||
int headerHeight = 14;
|
||||
int footerHeight = 14;
|
||||
int maxY = display.height() - footerHeight;
|
||||
@@ -237,6 +351,7 @@ public:
|
||||
if (!the_mesh.getContactByIdx(_filteredIdx[i], contact)) continue;
|
||||
|
||||
bool selected = (i == _scrollPos);
|
||||
bool sel = _selectMode && isSelectedRaw(_filteredIdx[i]);
|
||||
|
||||
// Highlight: fill LIGHT rect first, then draw DARK text on top
|
||||
if (selected) {
|
||||
@@ -244,7 +359,7 @@ public:
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.fillRect(0, y, display.width(), lineHeight);
|
||||
#else
|
||||
display.fillRect(0, y + 5, display.width(), lineHeight);
|
||||
display.fillRect(0, y + the_mesh.getNodePrefs()->smallHighlightOff(), display.width(), lineHeight);
|
||||
#endif
|
||||
display.setColor(DisplayDriver::DARK);
|
||||
} else {
|
||||
@@ -254,12 +369,16 @@ public:
|
||||
// Set cursor AFTER fillRect so text draws on top of highlight
|
||||
display.setCursor(0, y);
|
||||
|
||||
// Prefix: "> " for selected, type char + space for others
|
||||
char prefix[4];
|
||||
if (selected) {
|
||||
snprintf(prefix, sizeof(prefix), ">%c", typeChar(contact.type));
|
||||
// Prefix: select mode uses * for selected, normal uses > for cursor
|
||||
char prefix[5];
|
||||
if (_selectMode) {
|
||||
snprintf(prefix, sizeof(prefix), "%c%s",
|
||||
sel ? '*' : (selected ? '>' : ' '),
|
||||
typeStr(contact.type));
|
||||
} else if (selected) {
|
||||
snprintf(prefix, sizeof(prefix), ">%s", typeStr(contact.type));
|
||||
} else {
|
||||
snprintf(prefix, sizeof(prefix), " %c", typeChar(contact.type));
|
||||
snprintf(prefix, sizeof(prefix), " %s", typeStr(contact.type));
|
||||
}
|
||||
display.print(prefix);
|
||||
|
||||
@@ -269,18 +388,47 @@ public:
|
||||
|
||||
// Reserve space for hops + age on right side
|
||||
char hopStr[6];
|
||||
if (contact.out_path_len == 0xFF || contact.out_path_len == 0) {
|
||||
strcpy(hopStr, "D"); // direct
|
||||
if (contact.out_path_len == 0xFF) {
|
||||
// No confirmed direct path — look up flood hop estimate from recent advert cache
|
||||
hopStr[0] = '?'; hopStr[1] = '\0'; // default
|
||||
for (int h = 0; h < _hopBufCount; h++) {
|
||||
if (memcmp(contact.id.pub_key, _hopBuf[h].pubkey_prefix, 7) == 0) {
|
||||
uint8_t bph = (_hopBuf[h].path_len >> 6) + 1;
|
||||
uint8_t hops = _hopBuf[h].path_len & 0x3F;
|
||||
uint8_t max_hops = 64 / bph; // sanity cap based on path encoding
|
||||
if (hops <= max_hops) {
|
||||
if (hops == 0)
|
||||
strcpy(hopStr, "~D");
|
||||
else
|
||||
snprintf(hopStr, sizeof(hopStr), "~%d", (int)hops);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (contact.out_path_len == 0) {
|
||||
bool customDirect = (contact.flags & CONTACT_FLAG_CUSTOM_PATH) != 0;
|
||||
strcpy(hopStr, customDirect ? "D*" : "D");
|
||||
} else {
|
||||
snprintf(hopStr, sizeof(hopStr), "%d", contact.out_path_len);
|
||||
int hops = contact.out_path_len & 0x3F; // lower 6 bits = hop count
|
||||
bool customPath = (contact.flags & CONTACT_FLAG_CUSTOM_PATH) != 0;
|
||||
if (customPath) {
|
||||
snprintf(hopStr, sizeof(hopStr), "%d*", hops); // asterisk = custom/locked path
|
||||
} else {
|
||||
snprintf(hopStr, sizeof(hopStr), "%d", hops);
|
||||
}
|
||||
}
|
||||
|
||||
char ageStr[6];
|
||||
formatAge(ageStr, sizeof(ageStr), now, contact.last_advert_timestamp);
|
||||
formatAge(ageStr, sizeof(ageStr), now, contact.lastmod);
|
||||
|
||||
// Build right-side string: "hops age"
|
||||
char rightStr[14];
|
||||
snprintf(rightStr, sizeof(rightStr), "%sh %s", hopStr, ageStr);
|
||||
// Build right-side string: "*N hops age" if unread, else "hops age"
|
||||
int dmCount = (_dmUnread && _filteredIdx[i] < MAX_CONTACTS) ? _dmUnread[_filteredIdx[i]] : 0;
|
||||
char rightStr[20];
|
||||
if (dmCount > 0) {
|
||||
snprintf(rightStr, sizeof(rightStr), "*%d %sh %s", dmCount, hopStr, ageStr);
|
||||
} else {
|
||||
snprintf(rightStr, sizeof(rightStr), "%sh %s", hopStr, ageStr);
|
||||
}
|
||||
int rightWidth = display.getTextWidth(rightStr) + 2;
|
||||
|
||||
// Name region: after prefix + small gap, before right info
|
||||
@@ -307,24 +455,30 @@ public:
|
||||
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.setCursor(0, footerY);
|
||||
display.print("Swipe:Filter");
|
||||
const char* right = "Hold:DM/Admin";
|
||||
display.setCursor(display.width() - display.getTextWidth(right) - 2, footerY);
|
||||
display.print(right);
|
||||
if (_selectMode) {
|
||||
display.print("Swipe:All/Clr");
|
||||
const char* right = "Tap:Tog Hold:Exit";
|
||||
display.setCursor(display.width() - display.getTextWidth(right) - 2, footerY);
|
||||
display.print(right);
|
||||
} else {
|
||||
display.print("Swipe:Filter");
|
||||
const char* right = "Hold:DM/Admin";
|
||||
display.setCursor(display.width() - display.getTextWidth(right) - 2, footerY);
|
||||
display.print(right);
|
||||
}
|
||||
#else
|
||||
// Left: Q:Bk
|
||||
display.setCursor(0, footerY);
|
||||
display.print("Q:Bk");
|
||||
|
||||
// Center: A/D:Filter
|
||||
const char* mid = "A/D:Filtr";
|
||||
display.setCursor((display.width() - display.getTextWidth(mid)) / 2, footerY);
|
||||
display.print(mid);
|
||||
|
||||
// Right: F:Dscvr
|
||||
const char* right = "F:Dscvr";
|
||||
display.setCursor(display.width() - display.getTextWidth(right) - 2, footerY);
|
||||
display.print(right);
|
||||
if (_selectMode) {
|
||||
display.print("A:All D:Clr");
|
||||
const char* right = "X:Exp F:Fav Q:Done";
|
||||
display.setCursor(display.width() - display.getTextWidth(right) - 2, footerY);
|
||||
display.print(right);
|
||||
} else {
|
||||
display.print("Q:Bk A/D:Filter");
|
||||
const char* right = "P:Path Ent:Sel";
|
||||
display.setCursor(display.width() - display.getTextWidth(right) - 2, footerY);
|
||||
display.print(right);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 5000; // e-ink: next render after 5s
|
||||
@@ -347,6 +501,29 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
// --- Select mode key handling ---
|
||||
if (_selectMode) {
|
||||
// Enter/tap: toggle selection on current contact
|
||||
if (c == 13 || c == KEY_ENTER) {
|
||||
toggleSelected();
|
||||
return true;
|
||||
}
|
||||
// A: select all in current filter
|
||||
if (c == 'a' || c == 'A') {
|
||||
selectAll();
|
||||
return true;
|
||||
}
|
||||
// D: deselect all
|
||||
if (c == 'd' || c == 'D') {
|
||||
deselectAll();
|
||||
return true;
|
||||
}
|
||||
// Q, X, F, Backspace — handled by main.cpp (needs mesh/SD access)
|
||||
return false;
|
||||
}
|
||||
|
||||
// --- Normal mode key handling ---
|
||||
|
||||
// A - previous filter
|
||||
if (c == 'a' || c == 'A') {
|
||||
_filter = (FilterMode)(((int)_filter + FILTER_COUNT - 1) % FILTER_COUNT);
|
||||
|
||||
@@ -44,6 +44,32 @@ public:
|
||||
|
||||
int getSelectedIdx() const { return _scrollPos; }
|
||||
|
||||
// Tap-to-select: given virtual Y, select discovered node row.
|
||||
// Returns: 0=miss, 1=moved, 2=tapped current row.
|
||||
int selectRowAtVY(int vy) {
|
||||
int count = the_mesh.getDiscoveredCount();
|
||||
if (count == 0) return 0;
|
||||
const int headerH = 14, footerH = 14, lineH = the_mesh.getNodePrefs()->smallLineH();
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
const int bodyTop = headerH;
|
||||
#else
|
||||
const int bodyTop = headerH + the_mesh.getNodePrefs()->smallHighlightOff();
|
||||
#endif
|
||||
if (vy < bodyTop || vy >= 128 - footerH) return 0;
|
||||
|
||||
int maxVisible = (128 - headerH - footerH) / lineH;
|
||||
if (maxVisible < 3) maxVisible = 3;
|
||||
int startIdx = max(0, min(_scrollPos - maxVisible / 2,
|
||||
count - maxVisible));
|
||||
|
||||
int tappedRow = startIdx + (vy - bodyTop) / lineH;
|
||||
if (tappedRow < 0 || tappedRow >= count) return 0;
|
||||
|
||||
if (tappedRow == _scrollPos) return 2;
|
||||
_scrollPos = tappedRow;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int render(DisplayDriver& display) override {
|
||||
int count = the_mesh.getDiscoveredCount();
|
||||
bool active = the_mesh.isDiscoveryActive();
|
||||
@@ -65,8 +91,8 @@ public:
|
||||
display.drawRect(0, 11, display.width(), 1);
|
||||
|
||||
// === Body — discovered node rows ===
|
||||
display.setTextSize(0); // tiny font for compact rows
|
||||
int lineHeight = 9;
|
||||
display.setTextSize(the_mesh.getNodePrefs()->smallTextSize()); // tiny font for compact rows
|
||||
int lineHeight = the_mesh.getNodePrefs()->smallLineH();
|
||||
int headerHeight = 14;
|
||||
int footerHeight = 14;
|
||||
int maxY = display.height() - footerHeight;
|
||||
@@ -103,7 +129,7 @@ public:
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.fillRect(0, y, display.width(), lineHeight);
|
||||
#else
|
||||
display.fillRect(0, y + 5, display.width(), lineHeight);
|
||||
display.fillRect(0, y + the_mesh.getNodePrefs()->smallHighlightOff(), display.width(), lineHeight);
|
||||
#endif
|
||||
display.setColor(DisplayDriver::DARK);
|
||||
} else {
|
||||
@@ -177,13 +203,9 @@ public:
|
||||
display.setCursor(display.width() - display.getTextWidth(right) - 2, footerY);
|
||||
display.print(right);
|
||||
#else
|
||||
display.print("Q:Back");
|
||||
display.print("Q:Bk F:Rescan");
|
||||
|
||||
const char* mid = "Ent:Add";
|
||||
display.setCursor((display.width() - display.getTextWidth(mid)) / 2, footerY);
|
||||
display.print(mid);
|
||||
|
||||
const char* right = "F:Rescan";
|
||||
const char* right = "Tap/Ent:Add";
|
||||
display.setCursor(display.width() - display.getTextWidth(right) - 2, footerY);
|
||||
display.print(right);
|
||||
#endif
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// Emoji sprites for e-ink display - dual size
|
||||
// Large (12x12) for compose/picker, Small (10x10) for channel view
|
||||
// MSB-first, 2 bytes per row
|
||||
// 65 total emoji: joy/thumbsup/frown first, then 43 original, then 19 new
|
||||
// 76 total emoji: joy/thumbsup/frown first, then 43 original, then 19 new, then 11 newest
|
||||
|
||||
#include <stdint.h>
|
||||
#ifdef ESP32
|
||||
@@ -15,11 +15,11 @@
|
||||
#define EMOJI_SM_W 10
|
||||
#define EMOJI_SM_H 10
|
||||
|
||||
#define EMOJI_COUNT 65
|
||||
#define EMOJI_COUNT 76
|
||||
|
||||
// Escape codes in 0x80+ range - safe from keyboard ASCII (32-126)
|
||||
#define EMOJI_ESCAPE_START 0x80
|
||||
#define EMOJI_ESCAPE_END 0xC0 // 0x80 + 64
|
||||
#define EMOJI_ESCAPE_END 0xCB // 0x80 + 75
|
||||
#define EMOJI_PAD_BYTE 0x7F // DEL, not typeable (key < 127 guard)
|
||||
|
||||
// ======== LARGE 12x12 SPRITES ========
|
||||
@@ -36,6 +36,14 @@ static const uint8_t emoji_lg_thumbsup[] PROGMEM = {
|
||||
static const uint8_t emoji_lg_frown[] PROGMEM = {
|
||||
0x1F,0x80, 0x20,0x40, 0x59,0xA0, 0x59,0xA0, 0x80,0x10, 0x9F,0x90, 0xA0,0x50, 0x40,0x20, 0x20,0x40, 0x1F,0x80, 0x00,0x00, 0x00,0x00,
|
||||
};
|
||||
// [65] loudly_crying 😭
|
||||
static const uint8_t emoji_lg_loudly_crying[] PROGMEM = {
|
||||
0x1F,0x80, 0x20,0x40, 0x5B,0x40, 0x5B,0x20, 0x80,0x10, 0x9F,0x10, 0xA0,0x90, 0x60,0xC0, 0xA0,0xA0, 0x1F,0x00, 0x40,0x40, 0x00,0x00,
|
||||
};
|
||||
// [66] heart ♥️
|
||||
static const uint8_t emoji_lg_heart[] PROGMEM = {
|
||||
0x00,0x00, 0x73,0x80, 0xFF,0xC0, 0xFF,0xC0, 0xFF,0xC0, 0x7F,0x80, 0x3F,0x00, 0x1E,0x00, 0x0C,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
|
||||
};
|
||||
// [3] wireless
|
||||
static const uint8_t emoji_lg_wireless[] PROGMEM = {
|
||||
0x00,0x00, 0x3F,0xC0, 0x60,0x60, 0xC0,0x30, 0x0F,0x00, 0x19,0x80, 0x30,0xC0, 0x00,0x00, 0x06,0x00, 0x0F,0x00, 0x06,0x00, 0x00,0x00,
|
||||
@@ -284,23 +292,68 @@ static const uint8_t emoji_lg_tipping[] PROGMEM = {
|
||||
static const uint8_t emoji_lg_hedgehog[] PROGMEM = {
|
||||
0x00,0x00, 0x0A,0x80, 0x15,0x40, 0x2A,0xA0, 0x55,0x60, 0x7E,0xF0, 0xDB,0x90, 0xFF,0xD0, 0x7F,0xE0, 0x3F,0xC0, 0x24,0x80, 0x00,0x00,
|
||||
};
|
||||
// [67] diamond_suit ♦️
|
||||
static const uint8_t emoji_lg_diamond_suit[] PROGMEM = {
|
||||
0x00,0x00, 0x04,0x00, 0x0E,0x00, 0x1F,0x00, 0x3F,0x80, 0x7F,0xC0, 0x3F,0x80, 0x1F,0x00, 0x0E,0x00, 0x04,0x00, 0x00,0x00, 0x00,0x00,
|
||||
};
|
||||
// [68] spade_suit ♠️
|
||||
static const uint8_t emoji_lg_spade_suit[] PROGMEM = {
|
||||
0x04,0x00, 0x0E,0x00, 0x1F,0x00, 0x3F,0x80, 0x7F,0xC0, 0xFF,0xE0, 0xFF,0xE0, 0x7F,0xC0, 0x15,0x00, 0x04,0x00, 0x0E,0x00, 0x00,0x00,
|
||||
};
|
||||
// [69] pizza 🍕
|
||||
static const uint8_t emoji_lg_pizza[] PROGMEM = {
|
||||
0x02,0x00, 0x06,0x00, 0x0F,0x00, 0x0B,0x00, 0x1F,0x80, 0x1D,0x80, 0x3F,0xC0, 0x2F,0x40, 0x7F,0xE0, 0x7F,0xE0, 0xFF,0xF0, 0x00,0x00,
|
||||
};
|
||||
// [70] four_leaf_clover 🍀
|
||||
static const uint8_t emoji_lg_four_leaf_clover[] PROGMEM = {
|
||||
0x0C,0x00, 0x1E,0x00, 0x1E,0x00, 0x6D,0x80, 0xF3,0xC0, 0xF3,0xC0, 0x6D,0x80, 0x1E,0x00, 0x1E,0x00, 0x0C,0x00, 0x06,0x00, 0x00,0x00,
|
||||
};
|
||||
// [71] cloud ☁️
|
||||
static const uint8_t emoji_lg_cloud[] PROGMEM = {
|
||||
0x00,0x00, 0x1C,0x00, 0x3E,0x00, 0x7F,0x80, 0xFF,0xC0, 0xFF,0xE0, 0xFF,0xE0, 0x7F,0xC0, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
|
||||
};
|
||||
// [72] rocket 🚀
|
||||
static const uint8_t emoji_lg_rocket[] PROGMEM = {
|
||||
0x04,0x00, 0x0E,0x00, 0x1F,0x00, 0x1B,0x00, 0x1B,0x00, 0x3F,0x80, 0x7F,0xC0, 0x5F,0x40, 0x9F,0x20, 0x0E,0x00, 0x15,0x00, 0x00,0x00,
|
||||
};
|
||||
// [73] passport_control 🛂
|
||||
static const uint8_t emoji_lg_passport_control[] PROGMEM = {
|
||||
0x3F,0xC0, 0x40,0x20, 0x46,0x20, 0x4F,0x20, 0x46,0x20, 0x40,0x20, 0x44,0x20, 0x4E,0x20, 0x5F,0x20, 0x40,0x20, 0x3F,0xC0, 0x00,0x00,
|
||||
};
|
||||
// [74] eight_spoked_asterisk ✳️
|
||||
static const uint8_t emoji_lg_eight_spoked_asterisk[] PROGMEM = {
|
||||
0x7F,0xE0, 0x84,0x10, 0xA4,0x90, 0x95,0x10, 0x8E,0x10, 0xFF,0xD0, 0x8E,0x10, 0x95,0x10, 0xA4,0x90, 0x84,0x10, 0x7F,0xE0, 0x00,0x00,
|
||||
};
|
||||
// [75] signal_strength 📶
|
||||
static const uint8_t emoji_lg_signal_strength[] PROGMEM = {
|
||||
0x00,0x20, 0x00,0x20, 0x00,0xA0, 0x00,0xA0, 0x02,0xA0, 0x02,0xA0, 0x0A,0xA0, 0x0A,0xA0, 0x2A,0xA0, 0x2A,0xA0, 0xAA,0xA0, 0xAA,0xA0,
|
||||
};
|
||||
|
||||
|
||||
static const uint8_t* const EMOJI_SPRITES_LG[] PROGMEM = {
|
||||
emoji_lg_joy, emoji_lg_thumbsup, emoji_lg_frown,
|
||||
// Faces/emotion first
|
||||
emoji_lg_joy, emoji_lg_frown, emoji_lg_loudly_crying,
|
||||
emoji_lg_grimace, emoji_lg_zany_face, emoji_lg_cowboy,
|
||||
// Thumbsup + heart
|
||||
emoji_lg_thumbsup, emoji_lg_heart,
|
||||
// Everything else in original relative order
|
||||
emoji_lg_wireless, emoji_lg_infinity, emoji_lg_trex, emoji_lg_skull, emoji_lg_cross,
|
||||
emoji_lg_lightning, emoji_lg_tophat, emoji_lg_motorcycle, emoji_lg_seedling, emoji_lg_flag_au,
|
||||
emoji_lg_umbrella, emoji_lg_nazar, emoji_lg_globe, emoji_lg_radioactive, emoji_lg_cow,
|
||||
emoji_lg_alien, emoji_lg_invader, emoji_lg_dagger, emoji_lg_grimace,
|
||||
emoji_lg_alien, emoji_lg_invader, emoji_lg_dagger,
|
||||
emoji_lg_mountain, emoji_lg_end_arrow, emoji_lg_hollow_circle, emoji_lg_dragon, emoji_lg_globe_meridians,
|
||||
emoji_lg_eggplant, emoji_lg_shield, emoji_lg_goggles, emoji_lg_lizard, emoji_lg_zany_face,
|
||||
emoji_lg_eggplant, emoji_lg_shield, emoji_lg_goggles, emoji_lg_lizard,
|
||||
emoji_lg_kangaroo, emoji_lg_feather, emoji_lg_bright, emoji_lg_part_alt, emoji_lg_motorboat,
|
||||
emoji_lg_domino, emoji_lg_satellite, emoji_lg_customs, emoji_lg_cowboy, emoji_lg_wheel,
|
||||
emoji_lg_domino, emoji_lg_satellite, emoji_lg_customs, emoji_lg_wheel,
|
||||
emoji_lg_koala, emoji_lg_control_knobs, emoji_lg_peach, emoji_lg_racing_car,
|
||||
emoji_lg_mouse, emoji_lg_mushroom, emoji_lg_biohazard, emoji_lg_panda,
|
||||
emoji_lg_anger, emoji_lg_dragon_face, emoji_lg_pager, emoji_lg_bee,
|
||||
emoji_lg_bulb, emoji_lg_cat, emoji_lg_fleur, emoji_lg_moon,
|
||||
emoji_lg_coffee, emoji_lg_tooth, emoji_lg_pretzel, emoji_lg_abacus,
|
||||
emoji_lg_moai, emoji_lg_tipping, emoji_lg_hedgehog,
|
||||
emoji_lg_diamond_suit, emoji_lg_spade_suit, emoji_lg_pizza, emoji_lg_four_leaf_clover,
|
||||
emoji_lg_cloud, emoji_lg_rocket, emoji_lg_passport_control,
|
||||
emoji_lg_eight_spoked_asterisk, emoji_lg_signal_strength,
|
||||
};
|
||||
|
||||
// ======== SMALL 10x10 SPRITES ========
|
||||
@@ -519,94 +572,160 @@ static const uint8_t emoji_sm_tipping[] PROGMEM = {
|
||||
static const uint8_t emoji_sm_hedgehog[] PROGMEM = {
|
||||
0x15,0x00, 0x2A,0x80, 0x55,0x40, 0xFF,0xC0, 0xDB,0x40, 0xFF,0x80, 0x7F,0x80, 0x3F,0x00, 0x24,0x00, 0x00,0x00,
|
||||
};
|
||||
// [65] loudly_crying 😭
|
||||
static const uint8_t emoji_sm_loudly_crying[] PROGMEM = {
|
||||
0x3E,0x00, 0x41,0x00, 0xB6,0x80, 0x80,0x40, 0xBE,0x40, 0x81,0x40, 0x63,0x00, 0x9C,0x80, 0x00,0x00, 0x00,0x00,
|
||||
};
|
||||
// [66] heart ♥️
|
||||
static const uint8_t emoji_sm_heart[] PROGMEM = {
|
||||
0x00,0x00, 0x6C,0x00, 0xFE,0x00, 0xFE,0x00, 0x7C,0x00, 0x38,0x00, 0x10,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
|
||||
};
|
||||
// [67] diamond_suit ♦️
|
||||
static const uint8_t emoji_sm_diamond_suit[] PROGMEM = {
|
||||
0x00,0x00, 0x08,0x00, 0x1C,0x00, 0x3E,0x00, 0x7F,0x00, 0x3E,0x00, 0x1C,0x00, 0x08,0x00, 0x00,0x00, 0x00,0x00,
|
||||
};
|
||||
// [68] spade_suit ♠️
|
||||
static const uint8_t emoji_sm_spade_suit[] PROGMEM = {
|
||||
0x08,0x00, 0x1C,0x00, 0x3E,0x00, 0x7F,0x00, 0xFF,0x80, 0xFF,0x80, 0x2A,0x00, 0x08,0x00, 0x1C,0x00, 0x00,0x00,
|
||||
};
|
||||
// [69] pizza 🍕
|
||||
static const uint8_t emoji_sm_pizza[] PROGMEM = {
|
||||
0x08,0x00, 0x1C,0x00, 0x14,0x00, 0x3E,0x00, 0x36,0x00, 0x6D,0x00, 0x7F,0x00, 0xFF,0x80, 0xFF,0x80, 0x00,0x00,
|
||||
};
|
||||
// [70] four_leaf_clover 🍀
|
||||
static const uint8_t emoji_sm_four_leaf_clover[] PROGMEM = {
|
||||
0x18,0x00, 0x3C,0x00, 0xDB,0x00, 0xE7,0x00, 0xE7,0x00, 0xDB,0x00, 0x3C,0x00, 0x18,0x00, 0x0C,0x00, 0x00,0x00,
|
||||
};
|
||||
// [71] cloud ☁️
|
||||
static const uint8_t emoji_sm_cloud[] PROGMEM = {
|
||||
0x00,0x00, 0x38,0x00, 0x7E,0x00, 0xFF,0x00, 0xFF,0x80, 0xFF,0x80, 0x7F,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
|
||||
};
|
||||
// [72] rocket 🚀
|
||||
static const uint8_t emoji_sm_rocket[] PROGMEM = {
|
||||
0x08,0x00, 0x1C,0x00, 0x36,0x00, 0x36,0x00, 0x7F,0x00, 0xBE,0x80, 0x3E,0x00, 0x1C,0x00, 0x2A,0x00, 0x00,0x00,
|
||||
};
|
||||
// [73] passport_control 🛂
|
||||
static const uint8_t emoji_sm_passport_control[] PROGMEM = {
|
||||
0x7F,0x80, 0x80,0x40, 0x8C,0x40, 0x9E,0x40, 0x8C,0x40, 0x80,0x40, 0x9C,0x40, 0xBE,0x40, 0x80,0x40, 0x7F,0x80,
|
||||
};
|
||||
// [74] eight_spoked_asterisk ✳️
|
||||
static const uint8_t emoji_sm_eight_spoked_asterisk[] PROGMEM = {
|
||||
0x7F,0x80, 0x84,0x40, 0xA5,0x40, 0x9E,0x40, 0xFF,0xC0, 0x9E,0x40, 0xA5,0x40, 0x84,0x40, 0x7F,0x80, 0x00,0x00,
|
||||
};
|
||||
// [75] signal_strength 📶
|
||||
static const uint8_t emoji_sm_signal_strength[] PROGMEM = {
|
||||
0x00,0x80, 0x00,0x80, 0x02,0x80, 0x02,0x80, 0x0A,0x80, 0x0A,0x80, 0x2A,0x80, 0x2A,0x80, 0xAA,0x80, 0xAA,0x80,
|
||||
};
|
||||
|
||||
static const uint8_t* const EMOJI_SPRITES_SM[] PROGMEM = {
|
||||
emoji_sm_joy, emoji_sm_thumbsup, emoji_sm_frown,
|
||||
// Faces/emotion first
|
||||
emoji_sm_joy, emoji_sm_frown, emoji_sm_loudly_crying,
|
||||
emoji_sm_grimace, emoji_sm_zany_face, emoji_sm_cowboy,
|
||||
// Thumbsup + heart
|
||||
emoji_sm_thumbsup, emoji_sm_heart,
|
||||
// Everything else in original relative order
|
||||
emoji_sm_wireless, emoji_sm_infinity, emoji_sm_trex, emoji_sm_skull, emoji_sm_cross,
|
||||
emoji_sm_lightning, emoji_sm_tophat, emoji_sm_motorcycle, emoji_sm_seedling, emoji_sm_flag_au,
|
||||
emoji_sm_umbrella, emoji_sm_nazar, emoji_sm_globe, emoji_sm_radioactive, emoji_sm_cow,
|
||||
emoji_sm_alien, emoji_sm_invader, emoji_sm_dagger, emoji_sm_grimace,
|
||||
emoji_sm_alien, emoji_sm_invader, emoji_sm_dagger,
|
||||
emoji_sm_mountain, emoji_sm_end_arrow, emoji_sm_hollow_circle, emoji_sm_dragon, emoji_sm_globe_meridians,
|
||||
emoji_sm_eggplant, emoji_sm_shield, emoji_sm_goggles, emoji_sm_lizard, emoji_sm_zany_face,
|
||||
emoji_sm_eggplant, emoji_sm_shield, emoji_sm_goggles, emoji_sm_lizard,
|
||||
emoji_sm_kangaroo, emoji_sm_feather, emoji_sm_bright, emoji_sm_part_alt, emoji_sm_motorboat,
|
||||
emoji_sm_domino, emoji_sm_satellite, emoji_sm_customs, emoji_sm_cowboy, emoji_sm_wheel,
|
||||
emoji_sm_domino, emoji_sm_satellite, emoji_sm_customs, emoji_sm_wheel,
|
||||
emoji_sm_koala, emoji_sm_control_knobs, emoji_sm_peach, emoji_sm_racing_car,
|
||||
emoji_sm_mouse, emoji_sm_mushroom, emoji_sm_biohazard, emoji_sm_panda,
|
||||
emoji_sm_anger, emoji_sm_dragon_face, emoji_sm_pager, emoji_sm_bee,
|
||||
emoji_sm_bulb, emoji_sm_cat, emoji_sm_fleur, emoji_sm_moon,
|
||||
emoji_sm_coffee, emoji_sm_tooth, emoji_sm_pretzel, emoji_sm_abacus,
|
||||
emoji_sm_moai, emoji_sm_tipping, emoji_sm_hedgehog,
|
||||
emoji_sm_diamond_suit, emoji_sm_spade_suit, emoji_sm_pizza, emoji_sm_four_leaf_clover,
|
||||
emoji_sm_cloud, emoji_sm_rocket, emoji_sm_passport_control,
|
||||
emoji_sm_eight_spoked_asterisk, emoji_sm_signal_strength,
|
||||
};
|
||||
|
||||
// ---- Codepoint lookup for UTF-8 conversion ----
|
||||
struct EmojiCodepoint { uint32_t cp; uint32_t cp2; uint8_t escape; };
|
||||
|
||||
static const EmojiCodepoint EMOJI_CODEPOINTS[EMOJI_COUNT] = {
|
||||
// Faces/emotion first
|
||||
{ 0x1F602, 0x0000, 0x80 }, // joy
|
||||
{ 0x1F44D, 0x0000, 0x81 }, // thumbsup
|
||||
{ 0x2639, 0x0000, 0x82 }, // frown
|
||||
{ 0x1F6DC, 0x0000, 0x83 }, // wireless
|
||||
{ 0x267E, 0x0000, 0x84 }, // infinity
|
||||
{ 0x1F996, 0x0000, 0x85 }, // trex
|
||||
{ 0x2620, 0x0000, 0x86 }, // skull
|
||||
{ 0x271D, 0x0000, 0x87 }, // cross
|
||||
{ 0x26A1, 0x0000, 0x88 }, // lightning
|
||||
{ 0x1F3A9, 0x0000, 0x89 }, // tophat
|
||||
{ 0x1F3CD, 0x0000, 0x8A }, // motorcycle
|
||||
{ 0x1F331, 0x0000, 0x8B }, // seedling
|
||||
{ 0x1F1E6, 0x1F1FA, 0x8C }, // flag_au
|
||||
{ 0x2602, 0x0000, 0x8D }, // umbrella
|
||||
{ 0x1F9FF, 0x0000, 0x8E }, // nazar
|
||||
{ 0x1F30F, 0x0000, 0x8F }, // globe
|
||||
{ 0x2622, 0x0000, 0x90 }, // radioactive
|
||||
{ 0x1F404, 0x0000, 0x91 }, // cow
|
||||
{ 0x1F47D, 0x0000, 0x92 }, // alien
|
||||
{ 0x1F47E, 0x0000, 0x93 }, // invader
|
||||
{ 0x1F5E1, 0x0000, 0x94 }, // dagger
|
||||
{ 0x1F62C, 0x0000, 0x95 }, // grimace
|
||||
{ 0x26F0, 0x0000, 0x96 }, // mountain
|
||||
{ 0x1F51A, 0x0000, 0x97 }, // end_arrow
|
||||
{ 0x2B55, 0x0000, 0x98 }, // hollow_circle
|
||||
{ 0x1F409, 0x0000, 0x99 }, // dragon
|
||||
{ 0x1F310, 0x0000, 0x9A }, // globe_meridians
|
||||
{ 0x1F346, 0x0000, 0x9B }, // eggplant
|
||||
{ 0x1F6E1, 0x0000, 0x9C }, // shield
|
||||
{ 0x1F97D, 0x0000, 0x9D }, // goggles
|
||||
{ 0x1F98E, 0x0000, 0x9E }, // lizard
|
||||
{ 0x1F92A, 0x0000, 0x9F }, // zany_face
|
||||
{ 0x1F998, 0x0000, 0xA0 }, // kangaroo
|
||||
{ 0x1FAB6, 0x0000, 0xA1 }, // feather
|
||||
{ 0x1F506, 0x0000, 0xA2 }, // bright
|
||||
{ 0x303D, 0x0000, 0xA3 }, // part_alt
|
||||
{ 0x1F6E5, 0x0000, 0xA4 }, // motorboat
|
||||
{ 0x1F030, 0x0000, 0xA5 }, // domino
|
||||
{ 0x1F4E1, 0x0000, 0xA6 }, // satellite
|
||||
{ 0x1F6C3, 0x0000, 0xA7 }, // customs
|
||||
{ 0x1F920, 0x0000, 0xA8 }, // cowboy
|
||||
{ 0x1F6DE, 0x0000, 0xA9 }, // wheel
|
||||
{ 0x1F428, 0x0000, 0xAA }, // koala
|
||||
{ 0x1F39B, 0x0000, 0xAB }, // control_knobs
|
||||
{ 0x1F351, 0x0000, 0xAC }, // peach
|
||||
{ 0x1F3CE, 0x0000, 0xAD }, // racing_car
|
||||
{ 0x1F42D, 0x0000, 0xAE }, // mouse
|
||||
{ 0x1F344, 0x0000, 0xAF }, // mushroom
|
||||
{ 0x2623, 0x0000, 0xB0 }, // biohazard
|
||||
{ 0x1F43C, 0x0000, 0xB1 }, // panda
|
||||
{ 0x1F4A2, 0x0000, 0xB2 }, // anger
|
||||
{ 0x1F432, 0x0000, 0xB3 }, // dragon_face
|
||||
{ 0x1F4DF, 0x0000, 0xB4 }, // pager
|
||||
{ 0x1F41D, 0x0000, 0xB5 }, // bee
|
||||
{ 0x1F4A1, 0x0000, 0xB6 }, // bulb
|
||||
{ 0x1F431, 0x0000, 0xB7 }, // cat
|
||||
{ 0x269C, 0x0000, 0xB8 }, // fleur
|
||||
{ 0x1F314, 0x0000, 0xB9 }, // moon
|
||||
{ 0x2615, 0x0000, 0xBA }, // coffee
|
||||
{ 0x1F9B7, 0x0000, 0xBB }, // tooth
|
||||
{ 0x1F968, 0x0000, 0xBC }, // pretzel
|
||||
{ 0x1F9EE, 0x0000, 0xBD }, // abacus
|
||||
{ 0x1F5FF, 0x0000, 0xBE }, // moai
|
||||
{ 0x1F481, 0x0000, 0xBF }, // tipping
|
||||
{ 0x1F994, 0x0000, 0xC0 }, // hedgehog
|
||||
{ 0x2639, 0x0000, 0x81 }, // frown
|
||||
{ 0x1F62D, 0x0000, 0x82 }, // loudly_crying
|
||||
{ 0x1F62C, 0x0000, 0x83 }, // grimace
|
||||
{ 0x1F92A, 0x0000, 0x84 }, // zany_face
|
||||
{ 0x1F920, 0x0000, 0x85 }, // cowboy
|
||||
// Thumbsup + heart
|
||||
{ 0x1F44D, 0x0000, 0x86 }, // thumbsup
|
||||
{ 0x2665, 0x0000, 0x87 }, // heart
|
||||
// Everything else in original relative order
|
||||
{ 0x1F6DC, 0x0000, 0x88 }, // wireless
|
||||
{ 0x267E, 0x0000, 0x89 }, // infinity
|
||||
{ 0x1F996, 0x0000, 0x8A }, // trex
|
||||
{ 0x2620, 0x0000, 0x8B }, // skull
|
||||
{ 0x271D, 0x0000, 0x8C }, // cross
|
||||
{ 0x26A1, 0x0000, 0x8D }, // lightning
|
||||
{ 0x1F3A9, 0x0000, 0x8E }, // tophat
|
||||
{ 0x1F3CD, 0x0000, 0x8F }, // motorcycle
|
||||
{ 0x1F331, 0x0000, 0x90 }, // seedling
|
||||
{ 0x1F1E6, 0x1F1FA, 0x91 }, // flag_au
|
||||
{ 0x2602, 0x0000, 0x92 }, // umbrella
|
||||
{ 0x1F9FF, 0x0000, 0x93 }, // nazar
|
||||
{ 0x1F30F, 0x0000, 0x94 }, // globe
|
||||
{ 0x2622, 0x0000, 0x95 }, // radioactive
|
||||
{ 0x1F404, 0x0000, 0x96 }, // cow
|
||||
{ 0x1F47D, 0x0000, 0x97 }, // alien
|
||||
{ 0x1F47E, 0x0000, 0x98 }, // invader
|
||||
{ 0x1F5E1, 0x0000, 0x99 }, // dagger
|
||||
{ 0x26F0, 0x0000, 0x9A }, // mountain
|
||||
{ 0x1F51A, 0x0000, 0x9B }, // end_arrow
|
||||
{ 0x2B55, 0x0000, 0x9C }, // hollow_circle
|
||||
{ 0x1F409, 0x0000, 0x9D }, // dragon
|
||||
{ 0x1F310, 0x0000, 0x9E }, // globe_meridians
|
||||
{ 0x1F346, 0x0000, 0x9F }, // eggplant
|
||||
{ 0x1F6E1, 0x0000, 0xA0 }, // shield
|
||||
{ 0x1F97D, 0x0000, 0xA1 }, // goggles
|
||||
{ 0x1F98E, 0x0000, 0xA2 }, // lizard
|
||||
{ 0x1F998, 0x0000, 0xA3 }, // kangaroo
|
||||
{ 0x1FAB6, 0x0000, 0xA4 }, // feather
|
||||
{ 0x1F506, 0x0000, 0xA5 }, // bright
|
||||
{ 0x303D, 0x0000, 0xA6 }, // part_alt
|
||||
{ 0x1F6E5, 0x0000, 0xA7 }, // motorboat
|
||||
{ 0x1F030, 0x0000, 0xA8 }, // domino
|
||||
{ 0x1F4E1, 0x0000, 0xA9 }, // satellite
|
||||
{ 0x1F6C3, 0x0000, 0xAA }, // customs
|
||||
{ 0x1F6DE, 0x0000, 0xAB }, // wheel
|
||||
{ 0x1F428, 0x0000, 0xAC }, // koala
|
||||
{ 0x1F39B, 0x0000, 0xAD }, // control_knobs
|
||||
{ 0x1F351, 0x0000, 0xAE }, // peach
|
||||
{ 0x1F3CE, 0x0000, 0xAF }, // racing_car
|
||||
{ 0x1F42D, 0x0000, 0xB0 }, // mouse
|
||||
{ 0x1F344, 0x0000, 0xB1 }, // mushroom
|
||||
{ 0x2623, 0x0000, 0xB2 }, // biohazard
|
||||
{ 0x1F43C, 0x0000, 0xB3 }, // panda
|
||||
{ 0x1F4A2, 0x0000, 0xB4 }, // anger
|
||||
{ 0x1F432, 0x0000, 0xB5 }, // dragon_face
|
||||
{ 0x1F4DF, 0x0000, 0xB6 }, // pager
|
||||
{ 0x1F41D, 0x0000, 0xB7 }, // bee
|
||||
{ 0x1F4A1, 0x0000, 0xB8 }, // bulb
|
||||
{ 0x1F431, 0x0000, 0xB9 }, // cat
|
||||
{ 0x269C, 0x0000, 0xBA }, // fleur
|
||||
{ 0x1F314, 0x0000, 0xBB }, // moon
|
||||
{ 0x2615, 0x0000, 0xBC }, // coffee
|
||||
{ 0x1F9B7, 0x0000, 0xBD }, // tooth
|
||||
{ 0x1F968, 0x0000, 0xBE }, // pretzel
|
||||
{ 0x1F9EE, 0x0000, 0xBF }, // abacus
|
||||
{ 0x1F5FF, 0x0000, 0xC0 }, // moai
|
||||
{ 0x1F481, 0x0000, 0xC1 }, // tipping
|
||||
{ 0x1F994, 0x0000, 0xC2 }, // hedgehog
|
||||
{ 0x2666, 0x0000, 0xC3 }, // diamond_suit
|
||||
{ 0x2660, 0x0000, 0xC4 }, // spade_suit
|
||||
{ 0x1F355, 0x0000, 0xC5 }, // pizza
|
||||
{ 0x1F340, 0x0000, 0xC6 }, // four_leaf_clover
|
||||
{ 0x2601, 0x0000, 0xC7 }, // cloud
|
||||
{ 0x1F680, 0x0000, 0xC8 }, // rocket
|
||||
{ 0x1F6C2, 0x0000, 0xC9 }, // passport_control
|
||||
{ 0x2733, 0x0000, 0xCA }, // eight_spoked_asterisk
|
||||
{ 0x1F4F6, 0x0000, 0xCB }, // signal_strength
|
||||
};
|
||||
|
||||
// ---- Helper functions ----
|
||||
@@ -616,7 +735,7 @@ static const EmojiCodepoint EMOJI_CODEPOINTS[EMOJI_COUNT] = {
|
||||
struct EmojiAlias { uint32_t cp; uint8_t escape; };
|
||||
#define EMOJI_ALIAS_COUNT 1
|
||||
static const EmojiAlias EMOJI_ALIASES[EMOJI_ALIAS_COUNT] = {
|
||||
{ 0x1F08E, 0xA5 }, // domino tile (MWD node signifier) -> domino sprite
|
||||
{ 0x1F08E, 0xA8 }, // domino tile (MWD node signifier) -> domino sprite
|
||||
};
|
||||
|
||||
static uint32_t emojiDecodeUtf8(const uint8_t* s, int remaining, int* bytes_consumed) {
|
||||
|
||||
@@ -0,0 +1,249 @@
|
||||
#pragma once
|
||||
|
||||
#include <helpers/ui/UIScreen.h>
|
||||
#include <helpers/ui/DisplayDriver.h>
|
||||
#include <helpers/AdvertDataHelpers.h>
|
||||
#include <MeshCore.h>
|
||||
|
||||
extern MyMesh the_mesh;
|
||||
|
||||
// ==========================================================================
|
||||
// Last Heard Screen — passive advert list
|
||||
// Shows all recently heard nodes from the advert path table, sorted by
|
||||
// recency. Unlike Discovery (active zero-hop scan), this is purely passive
|
||||
// — it shows nodes whose adverts have been received over time.
|
||||
// ==========================================================================
|
||||
// Display cap — we never need to show all 200 storage entries at once
|
||||
#define LAST_HEARD_DISPLAY_SIZE 100
|
||||
|
||||
class LastHeardScreen : public UIScreen {
|
||||
mesh::RTCClock* _rtc;
|
||||
int _scrollPos;
|
||||
|
||||
// Local sorted copy of advert paths (PSRAM-allocated, refreshed each render)
|
||||
AdvertPath* _entries;
|
||||
int _count;
|
||||
|
||||
static char typeChar(uint8_t adv_type) {
|
||||
switch (adv_type) {
|
||||
case ADV_TYPE_CHAT: return 'C';
|
||||
case ADV_TYPE_REPEATER: return 'R';
|
||||
case ADV_TYPE_ROOM: return 'S';
|
||||
case ADV_TYPE_SENSOR: return 'N';
|
||||
default: return '?';
|
||||
}
|
||||
}
|
||||
|
||||
// Format age as human-readable string (e.g. "2m", "1h", "3d")
|
||||
static void formatAge(uint32_t now, uint32_t timestamp, char* buf, int bufLen) {
|
||||
if (timestamp == 0 || now < timestamp) {
|
||||
snprintf(buf, bufLen, "---");
|
||||
return;
|
||||
}
|
||||
uint32_t age = now - timestamp;
|
||||
if (age < 60) snprintf(buf, bufLen, "%ds", age);
|
||||
else if (age < 3600) snprintf(buf, bufLen, "%dm", age / 60);
|
||||
else if (age < 86400) snprintf(buf, bufLen, "%dh", age / 3600);
|
||||
else snprintf(buf, bufLen, "%dd", age / 86400);
|
||||
}
|
||||
|
||||
public:
|
||||
LastHeardScreen(mesh::RTCClock* rtc)
|
||||
: _rtc(rtc), _scrollPos(0), _count(0) {
|
||||
#if defined(ESP32)
|
||||
// ESP32 variants have PSRAM — allocate the entries buffer there
|
||||
_entries = (AdvertPath*)ps_calloc(LAST_HEARD_DISPLAY_SIZE, sizeof(AdvertPath));
|
||||
#else
|
||||
// nRF52 has no PSRAM — fall back to regular heap. At 100 entries × ~84
|
||||
// bytes each this is ~8.4KB, manageable within Meshpocket's SRAM budget.
|
||||
_entries = (AdvertPath*)calloc(LAST_HEARD_DISPLAY_SIZE, sizeof(AdvertPath));
|
||||
#endif
|
||||
}
|
||||
|
||||
void resetScroll() { _scrollPos = 0; }
|
||||
|
||||
int getSelectedIdx() const { return _scrollPos; }
|
||||
|
||||
// Check if selected node is already in contacts
|
||||
bool isSelectedInContacts() const {
|
||||
if (_scrollPos < 0 || _scrollPos >= _count) return false;
|
||||
return the_mesh.lookupContactByPubKey(_entries[_scrollPos].pubkey_prefix, 8) != nullptr;
|
||||
}
|
||||
|
||||
// Get selected entry (for add/delete operations)
|
||||
const AdvertPath* getSelectedEntry() const {
|
||||
if (_scrollPos < 0 || _scrollPos >= _count) return nullptr;
|
||||
return &_entries[_scrollPos];
|
||||
}
|
||||
|
||||
// Tap-to-select: given virtual Y, select row.
|
||||
// Returns: 0=miss, 1=moved, 2=tapped current row.
|
||||
int selectRowAtVY(int vy) {
|
||||
if (_count == 0) return 0;
|
||||
const int headerH = 14, footerH = 14, lineH = the_mesh.getNodePrefs()->smallLineH();
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
const int bodyTop = headerH;
|
||||
#else
|
||||
const int bodyTop = headerH + the_mesh.getNodePrefs()->smallHighlightOff();
|
||||
#endif
|
||||
if (vy < bodyTop || vy >= 128 - footerH) return 0;
|
||||
|
||||
int maxVisible = (128 - headerH - footerH) / lineH;
|
||||
if (maxVisible < 3) maxVisible = 3;
|
||||
int startIdx = max(0, min(_scrollPos - maxVisible / 2,
|
||||
_count - maxVisible));
|
||||
|
||||
int tappedRow = startIdx + (vy - bodyTop) / lineH;
|
||||
if (tappedRow < 0 || tappedRow >= _count) return 0;
|
||||
|
||||
if (tappedRow == _scrollPos) return 2;
|
||||
_scrollPos = tappedRow;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int render(DisplayDriver& display) override {
|
||||
// Refresh sorted list from mesh
|
||||
_count = the_mesh.getRecentlyHeard(_entries, LAST_HEARD_DISPLAY_SIZE);
|
||||
|
||||
// Filter out empty entries (recv_timestamp == 0)
|
||||
int validCount = 0;
|
||||
for (int i = 0; i < _count; i++) {
|
||||
if (_entries[i].recv_timestamp > 0) validCount++;
|
||||
else break; // sorted by recency, so first zero means rest are empty
|
||||
}
|
||||
_count = validCount;
|
||||
|
||||
if (_scrollPos >= _count) _scrollPos = max(0, _count - 1);
|
||||
|
||||
uint32_t now = _rtc->getCurrentTime();
|
||||
|
||||
// === Header ===
|
||||
display.setTextSize(1);
|
||||
display.setColor(DisplayDriver::GREEN);
|
||||
display.setCursor(0, 0);
|
||||
|
||||
char hdr[32];
|
||||
snprintf(hdr, sizeof(hdr), "Last Heard: %d nodes", _count);
|
||||
display.print(hdr);
|
||||
|
||||
display.drawRect(0, 11, display.width(), 1);
|
||||
|
||||
// === Body — node rows ===
|
||||
display.setTextSize(the_mesh.getNodePrefs()->smallTextSize());
|
||||
int lineHeight = the_mesh.getNodePrefs()->smallLineH();
|
||||
int headerHeight = 14;
|
||||
int footerHeight = 14;
|
||||
int maxY = display.height() - footerHeight;
|
||||
int y = headerHeight;
|
||||
|
||||
if (_count == 0) {
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.setCursor(4, 28);
|
||||
display.print("No adverts received yet");
|
||||
display.setCursor(4, 38);
|
||||
display.print("Nodes appear as adverts arrive");
|
||||
} else {
|
||||
int maxVisible = (maxY - headerHeight) / lineHeight;
|
||||
if (maxVisible < 3) maxVisible = 3;
|
||||
int startIdx = max(0, min(_scrollPos - maxVisible / 2,
|
||||
_count - maxVisible));
|
||||
int endIdx = min(_count, startIdx + maxVisible);
|
||||
|
||||
for (int i = startIdx; i < endIdx && y + lineHeight <= maxY; i++) {
|
||||
const AdvertPath& entry = _entries[i];
|
||||
bool selected = (i == _scrollPos);
|
||||
|
||||
// Highlight selected row
|
||||
if (selected) {
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.fillRect(0, y, display.width(), lineHeight);
|
||||
#else
|
||||
display.fillRect(0, y + the_mesh.getNodePrefs()->smallHighlightOff(), display.width(), lineHeight);
|
||||
#endif
|
||||
display.setColor(DisplayDriver::DARK);
|
||||
} else {
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
}
|
||||
|
||||
display.setCursor(0, y);
|
||||
|
||||
// Prefix: cursor + type char
|
||||
char prefix[4];
|
||||
snprintf(prefix, sizeof(prefix), "%c%c",
|
||||
selected ? '>' : ' ', typeChar(entry.type));
|
||||
display.print(prefix);
|
||||
|
||||
// Right side: age + hops + [★] for favourites, [+] for other contacts
|
||||
char rightStr[20];
|
||||
char ageBuf[8];
|
||||
formatAge(now, entry.recv_timestamp, ageBuf, sizeof(ageBuf));
|
||||
|
||||
ContactInfo* ci = the_mesh.lookupContactByPubKey(entry.pubkey_prefix, 8);
|
||||
bool inContacts = (ci != nullptr);
|
||||
bool isFav = inContacts && (ci->flags & 0x01);
|
||||
if (isFav) {
|
||||
snprintf(rightStr, sizeof(rightStr), "%s %dh [*]", ageBuf, entry.path_len & 63);
|
||||
} else if (inContacts) {
|
||||
snprintf(rightStr, sizeof(rightStr), "%s %dh [+]", ageBuf, entry.path_len & 63);
|
||||
} else {
|
||||
snprintf(rightStr, sizeof(rightStr), "%s %dh", ageBuf, entry.path_len & 63);
|
||||
}
|
||||
int rightWidth = display.getTextWidth(rightStr) + 2;
|
||||
|
||||
// Name (truncated with ellipsis)
|
||||
char filteredName[32];
|
||||
display.translateUTF8ToBlocks(filteredName, entry.name, sizeof(filteredName));
|
||||
int nameX = display.getTextWidth(prefix) + 2;
|
||||
int nameMaxW = display.width() - nameX - rightWidth - 2;
|
||||
display.drawTextEllipsized(nameX, y, nameMaxW, filteredName);
|
||||
|
||||
// Right-aligned info
|
||||
display.setCursor(display.width() - rightWidth, y);
|
||||
display.print(rightStr);
|
||||
|
||||
y += lineHeight;
|
||||
}
|
||||
}
|
||||
|
||||
display.setTextSize(1);
|
||||
|
||||
// === Footer ===
|
||||
int footerY = display.height() - 12;
|
||||
display.drawRect(0, footerY - 2, display.width(), 1);
|
||||
display.setColor(DisplayDriver::YELLOW);
|
||||
|
||||
display.setCursor(0, footerY);
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.print("Swipe:Scroll");
|
||||
const char* right = "Tap:Add/Del";
|
||||
display.setCursor(display.width() - display.getTextWidth(right) - 2, footerY);
|
||||
display.print(right);
|
||||
#else
|
||||
display.print("Q:Bk");
|
||||
const char* right = "Tap/Ent:Add/Del";
|
||||
display.setCursor(display.width() - display.getTextWidth(right) - 2, footerY);
|
||||
display.print(right);
|
||||
#endif
|
||||
|
||||
return 5000; // refresh every 5s to update ages
|
||||
}
|
||||
|
||||
bool handleInput(char c) override {
|
||||
// Scroll up
|
||||
if (c == 'w' || c == 'W' || c == 0xF2) {
|
||||
if (_scrollPos > 0) { _scrollPos--; return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
// Scroll down
|
||||
if (c == 's' || c == 'S' || c == 0xF1) {
|
||||
if (_scrollPos < _count - 1) { _scrollPos++; return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
// Enter — handled by main.cpp (needs access to private MyMesh methods)
|
||||
// Q — handled by main.cpp (navigation)
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@@ -137,22 +137,18 @@ public:
|
||||
_zoomMin(MAP_MIN_ZOOM),
|
||||
_zoomMax(MAP_MAX_ZOOM),
|
||||
_pngBuf(nullptr),
|
||||
_lineBuf(nullptr),
|
||||
_tileFound(false)
|
||||
{
|
||||
// Allocate marker array in PSRAM at construction (~20KB)
|
||||
// so addMarker() works before enter() is called
|
||||
_markers = (MapMarker*)ps_calloc(MAP_MAX_MARKERS, sizeof(MapMarker));
|
||||
if (_markers) {
|
||||
Serial.printf("MapScreen: markers allocated (%d × %d = %d bytes PSRAM)\n",
|
||||
MAP_MAX_MARKERS, (int)sizeof(MapMarker),
|
||||
MAP_MAX_MARKERS * (int)sizeof(MapMarker));
|
||||
} else {
|
||||
Serial.println("MapScreen: marker PSRAM alloc FAILED");
|
||||
}
|
||||
// Marker array and PNG buffers are deferred to enter() to avoid
|
||||
// consuming 20KB+ PSRAM at boot when the map may never be opened.
|
||||
_markers = nullptr;
|
||||
_numMarkers = 0;
|
||||
}
|
||||
|
||||
~MapScreen() {
|
||||
if (_pngBuf) { free(_pngBuf); _pngBuf = nullptr; }
|
||||
if (_lineBuf) { free(_lineBuf); _lineBuf = nullptr; }
|
||||
if (_markers) { free(_markers); _markers = nullptr; }
|
||||
}
|
||||
|
||||
@@ -184,7 +180,12 @@ public:
|
||||
// Add a location marker (call once per contact before entering map)
|
||||
void clearMarkers() { _numMarkers = 0; }
|
||||
void addMarker(double lat, double lon, const char* name = "", uint8_t type = 0) {
|
||||
if (!_markers || _numMarkers >= MAP_MAX_MARKERS) return;
|
||||
// Lazy-allocate markers on first use (deferred from constructor)
|
||||
if (!_markers) {
|
||||
_markers = (MapMarker*)ps_calloc(MAP_MAX_MARKERS, sizeof(MapMarker));
|
||||
if (!_markers) return; // Alloc failed — skip silently
|
||||
}
|
||||
if (_numMarkers >= MAP_MAX_MARKERS) return;
|
||||
if (lat == 0.0 && lon == 0.0) return; // Skip no-location contacts
|
||||
_markers[_numMarkers].lat = lat;
|
||||
_markers[_numMarkers].lon = lon;
|
||||
@@ -203,6 +204,18 @@ public:
|
||||
_einkDisplay = static_cast<GxEPDDisplay*>(&display);
|
||||
_needsRedraw = true;
|
||||
|
||||
// Allocate marker array in PSRAM on first use (~20KB)
|
||||
if (!_markers) {
|
||||
_markers = (MapMarker*)ps_calloc(MAP_MAX_MARKERS, sizeof(MapMarker));
|
||||
if (_markers) {
|
||||
Serial.printf("MapScreen: markers allocated (%d × %d = %d bytes PSRAM)\n",
|
||||
MAP_MAX_MARKERS, (int)sizeof(MapMarker),
|
||||
MAP_MAX_MARKERS * (int)sizeof(MapMarker));
|
||||
} else {
|
||||
Serial.println("MapScreen: marker PSRAM alloc FAILED");
|
||||
}
|
||||
}
|
||||
|
||||
// Allocate PNG read buffer in PSRAM on first use
|
||||
if (!_pngBuf) {
|
||||
_pngBuf = (uint8_t*)ps_malloc(MAP_PNG_BUF_SIZE);
|
||||
@@ -217,6 +230,20 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
// Allocate scanline decode buffer in PSRAM (512 bytes — avoids stack
|
||||
// allocation inside the PNGdec callback which is called 256× per tile)
|
||||
if (!_lineBuf) {
|
||||
_lineBuf = (uint16_t*)ps_malloc(MAP_TILE_SIZE * sizeof(uint16_t));
|
||||
if (!_lineBuf) {
|
||||
_lineBuf = (uint16_t*)malloc(MAP_TILE_SIZE * sizeof(uint16_t));
|
||||
}
|
||||
if (_lineBuf) {
|
||||
Serial.println("MapScreen: lineBuf allocated");
|
||||
} else {
|
||||
Serial.println("MapScreen: lineBuf alloc FAILED");
|
||||
}
|
||||
}
|
||||
|
||||
// Detect available zoom levels from SD card directories
|
||||
detectZoomRange();
|
||||
}
|
||||
@@ -356,6 +383,7 @@ private:
|
||||
|
||||
// PNG decode buffer (PSRAM)
|
||||
uint8_t* _pngBuf;
|
||||
uint16_t* _lineBuf; // Scanline RGB565 buffer for PNG decode (PSRAM)
|
||||
bool _tileFound; // Did last tile load succeed?
|
||||
|
||||
// PNGdec instance
|
||||
@@ -381,6 +409,7 @@ private:
|
||||
int offsetY; // Screen Y offset for this tile
|
||||
int viewportY; // Top of viewport (MAP_VIEWPORT_Y)
|
||||
int viewportH; // Height of viewport (MAP_VIEWPORT_H)
|
||||
uint16_t* lineBuf; // Scanline decode buffer (PSRAM-allocated, avoids 512B stack usage per callback)
|
||||
};
|
||||
DrawContext _drawCtx;
|
||||
|
||||
@@ -487,7 +516,7 @@ private:
|
||||
// Load a PNG tile from SD and decode it directly to the display
|
||||
// screenX, screenY = top-left corner on display where this tile goes
|
||||
bool loadAndRenderTile(int tileX, int tileY, int screenX, int screenY) {
|
||||
if (!_pngBuf || !_einkDisplay) return false;
|
||||
if (!_pngBuf || !_lineBuf || !_einkDisplay) return false;
|
||||
|
||||
char path[64];
|
||||
buildTilePath(path, sizeof(path), _zoom, tileX, tileY);
|
||||
@@ -521,6 +550,7 @@ private:
|
||||
_drawCtx.offsetY = screenY;
|
||||
_drawCtx.viewportY = MAP_VIEWPORT_Y;
|
||||
_drawCtx.viewportH = MAP_VIEWPORT_H;
|
||||
_drawCtx.lineBuf = _lineBuf;
|
||||
|
||||
// Open PNG from memory buffer
|
||||
int rc = _png.openRAM(_pngBuf, fileSize, pngDrawCallback);
|
||||
@@ -547,7 +577,7 @@ private:
|
||||
// Uses getLineAsRGB565 with correct (little) endianness for ESP32.
|
||||
static int pngDrawCallback(PNGDRAW* pDraw) {
|
||||
DrawContext* ctx = (DrawContext*)pDraw->pUser;
|
||||
if (!ctx || !ctx->display || !ctx->png) return 0;
|
||||
if (!ctx || !ctx->display || !ctx->png || !ctx->lineBuf) return 0;
|
||||
|
||||
int screenY = ctx->offsetY + pDraw->y;
|
||||
|
||||
@@ -564,9 +594,8 @@ private:
|
||||
}
|
||||
|
||||
uint16_t lineWidth = pDraw->iWidth;
|
||||
uint16_t lineBuf[MAP_TILE_SIZE];
|
||||
if (lineWidth > MAP_TILE_SIZE) lineWidth = MAP_TILE_SIZE;
|
||||
ctx->png->getLineAsRGB565(pDraw, lineBuf, PNG_RGB565_LITTLE_ENDIAN, 0xFFFFFFFF);
|
||||
ctx->png->getLineAsRGB565(pDraw, ctx->lineBuf, PNG_RGB565_LITTLE_ENDIAN, 0xFFFFFFFF);
|
||||
|
||||
for (int x = 0; x < lineWidth; x++) {
|
||||
int screenX = ctx->offsetX + x;
|
||||
@@ -574,7 +603,7 @@ private:
|
||||
|
||||
// RGB565 little-endian on ESP32: standard bit layout
|
||||
// R[15:11] G[10:5] B[4:0]
|
||||
uint16_t pixel = lineBuf[x];
|
||||
uint16_t pixel = ctx->lineBuf[x];
|
||||
|
||||
// For B&W tiles this is 0x0000 (black) or 0xFFFF (white)
|
||||
// Simple threshold on full 16-bit value handles both cleanly
|
||||
@@ -639,6 +668,7 @@ private:
|
||||
} else {
|
||||
missing++;
|
||||
}
|
||||
yield(); // Feed WDT between tiles — each tile can take 1-2s at 80MHz
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,18 @@
|
||||
|
||||
#include <helpers/ui/UIScreen.h>
|
||||
#include <helpers/ui/DisplayDriver.h>
|
||||
#include <SD.h>
|
||||
#include <vector>
|
||||
#include "Utf8CP437.h"
|
||||
#ifdef ESP32
|
||||
#include <SD.h>
|
||||
#include <vector>
|
||||
#include "Utf8CP437.h"
|
||||
#endif
|
||||
#include "../NodePrefs.h"
|
||||
|
||||
// Forward declarations
|
||||
class UITask;
|
||||
|
||||
#ifdef ESP32
|
||||
|
||||
// ============================================================================
|
||||
// Configuration
|
||||
// ============================================================================
|
||||
@@ -52,9 +57,11 @@ public:
|
||||
|
||||
private:
|
||||
UITask* _task;
|
||||
NodePrefs* _prefs;
|
||||
Mode _mode;
|
||||
bool _sdReady;
|
||||
bool _initialized;
|
||||
uint8_t _lastFontPref;
|
||||
DisplayDriver* _display;
|
||||
|
||||
// Display layout (calculated once from display metrics)
|
||||
@@ -102,6 +109,10 @@ private:
|
||||
uint32_t _rtcTime; // Unix timestamp (0 = unavailable)
|
||||
int8_t _utcOffset; // UTC offset in hours
|
||||
|
||||
// Callback to get fresh RTC time (set by UITask at init)
|
||||
typedef uint32_t (*TimeGetterFn)();
|
||||
TimeGetterFn _getTimeFn = nullptr;
|
||||
|
||||
// ---- Helpers ----
|
||||
|
||||
String getFullPath(const String& filename) {
|
||||
@@ -514,8 +525,8 @@ private:
|
||||
display.drawRect(0, 11, display.width(), 1);
|
||||
|
||||
// File list with "+ New Note" at index 0
|
||||
display.setTextSize(0);
|
||||
int listLineH = 9; // Match contacts/discovery for consistent selection highlight
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
int listLineH = _prefs->smallLineH();
|
||||
int startY = 14;
|
||||
int totalItems = 1 + (int)_fileList.size();
|
||||
int maxVisible = (display.height() - startY - _footerHeight) / listLineH;
|
||||
@@ -535,27 +546,21 @@ private:
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.fillRect(0, y, display.width(), listLineH);
|
||||
#else
|
||||
display.fillRect(0, y + 5, display.width(), listLineH);
|
||||
display.fillRect(0, y + _prefs->smallHighlightOff(), display.width(), listLineH);
|
||||
#endif
|
||||
display.setColor(DisplayDriver::DARK);
|
||||
} else {
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
}
|
||||
|
||||
display.setCursor(0, y);
|
||||
|
||||
if (i == 0) {
|
||||
display.setColor(selected ? DisplayDriver::DARK : DisplayDriver::GREEN);
|
||||
display.print(selected ? "> + New Note" : " + New Note");
|
||||
display.drawTextEllipsized(0, y, display.width() - 4,
|
||||
selected ? "> + New Note" : " + New Note");
|
||||
} else {
|
||||
String line = selected ? "> " : " ";
|
||||
String name = _fileList[i - 1];
|
||||
int maxLen = _charsPerLine - 4;
|
||||
if ((int)name.length() > maxLen) {
|
||||
name = name.substring(0, maxLen - 3) + "...";
|
||||
}
|
||||
line += name;
|
||||
display.print(line.c_str());
|
||||
line += _fileList[i - 1];
|
||||
display.drawTextEllipsized(0, y, display.width() - 4, line.c_str());
|
||||
}
|
||||
y += listLineH;
|
||||
}
|
||||
@@ -570,8 +575,8 @@ private:
|
||||
display.print("Swipe:Nav");
|
||||
const char* right = "Tap:Open";
|
||||
#else
|
||||
display.print("Q:Back W/S:Nav");
|
||||
const char* right = "Ent:Open";
|
||||
display.print("Q:Bk");
|
||||
const char* right = "Tap/Ent:Open";
|
||||
#endif
|
||||
display.setCursor(display.width() - display.getTextWidth(right) - 2, footerY);
|
||||
display.print(right);
|
||||
@@ -592,8 +597,8 @@ private:
|
||||
display.print("Tap:Edit");
|
||||
const char* right = "Hold:Delete";
|
||||
#else
|
||||
display.print("Q:Bck Ent:Edit");
|
||||
const char* right = "Sh+Del:Del";
|
||||
display.print("Q:Bk Ent:Edit");
|
||||
const char* right = "X:Delete";
|
||||
#endif
|
||||
display.setCursor(display.width() - display.getTextWidth(right) - 2, footerY);
|
||||
display.print(right);
|
||||
@@ -601,7 +606,7 @@ private:
|
||||
}
|
||||
|
||||
// Render current page using tiny font
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
|
||||
int pageStart = _pageOffsets[_currentPage];
|
||||
@@ -684,9 +689,9 @@ private:
|
||||
|
||||
const char* right = "Tap:Edit";
|
||||
#else
|
||||
display.print("Q:Bck Ent:Edit");
|
||||
display.print("Q:Bk Ent:Edit");
|
||||
|
||||
const char* right = "Sh+Del:Del";
|
||||
const char* right = "X:Delete";
|
||||
#endif
|
||||
display.setCursor(display.width() - display.getTextWidth(right) - 2, footerY);
|
||||
display.print(right);
|
||||
@@ -718,7 +723,7 @@ private:
|
||||
int textAreaTop = 14;
|
||||
int textAreaBottom = display.height() - 16;
|
||||
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
|
||||
// Find cursor line
|
||||
int cursorLine = lineForPos(_cursorPos);
|
||||
@@ -767,7 +772,7 @@ private:
|
||||
|
||||
// If buffer is empty, show cursor at top
|
||||
if (_bufLen == 0) {
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
display.setColor(DisplayDriver::GREEN);
|
||||
display.setCursor(0, textAreaTop);
|
||||
display.print("|");
|
||||
@@ -825,7 +830,7 @@ private:
|
||||
display.setCursor(0, 20);
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.print("From: ");
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
String origDisplay = _renameOriginal;
|
||||
if (origDisplay.length() > 30) origDisplay = origDisplay.substring(0, 27) + "...";
|
||||
display.print(origDisplay.c_str());
|
||||
@@ -836,7 +841,7 @@ private:
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.print("To: ");
|
||||
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
display.setColor(DisplayDriver::GREEN);
|
||||
char displayName[NOTES_RENAME_MAX + 2];
|
||||
snprintf(displayName, sizeof(displayName), "%s|", _renameBuf);
|
||||
@@ -876,7 +881,7 @@ private:
|
||||
display.setCursor(0, 25);
|
||||
display.print("File:");
|
||||
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
display.setCursor(0, 38);
|
||||
String nameDisplay = _deleteTarget;
|
||||
if (nameDisplay.length() > 35) nameDisplay = nameDisplay.substring(0, 32) + "...";
|
||||
@@ -1077,6 +1082,10 @@ private:
|
||||
// ---- Note Creation ----
|
||||
|
||||
void createNewNote() {
|
||||
// Refresh timestamp at creation time for accurate filenames
|
||||
if (_getTimeFn) {
|
||||
_rtcTime = _getTimeFn();
|
||||
}
|
||||
_currentFile = generateFilename();
|
||||
_buf[0] = '\0';
|
||||
_bufLen = 0;
|
||||
@@ -1088,9 +1097,9 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
NotesScreen(UITask* task)
|
||||
: _task(task), _mode(FILE_LIST),
|
||||
_sdReady(false), _initialized(false), _display(nullptr),
|
||||
NotesScreen(UITask* task, NodePrefs* prefs = nullptr)
|
||||
: _task(task), _prefs(prefs), _mode(FILE_LIST),
|
||||
_sdReady(false), _initialized(false), _lastFontPref(0), _display(nullptr),
|
||||
_charsPerLine(38), _linesPerPage(22), _lineHeight(5), _footerHeight(14),
|
||||
_editCharsPerLine(20), _editLineHeight(12), _editMaxLines(8),
|
||||
_selectedFile(0), _buf(nullptr), _bufLen(0), _cursorPos(0),
|
||||
@@ -1125,15 +1134,31 @@ public:
|
||||
// ---- Layout Init ----
|
||||
|
||||
void initLayout(DisplayDriver& display) {
|
||||
// Re-init if font preference changed since last layout
|
||||
uint8_t curFont = _prefs ? _prefs->large_font : 0;
|
||||
if (_initialized && curFont != _lastFontPref) {
|
||||
_initialized = false;
|
||||
Serial.println("Notes: font changed, recalculating layout");
|
||||
}
|
||||
if (_initialized) return;
|
||||
_lastFontPref = curFont;
|
||||
_display = &display;
|
||||
|
||||
// Tiny font metrics (for read mode)
|
||||
display.setTextSize(0);
|
||||
// Font metrics (for read mode)
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
uint16_t tenCharsW = display.getTextWidth("MMMMMMMMMM");
|
||||
if (tenCharsW > 0) {
|
||||
_charsPerLine = (display.width() * 10) / tenCharsW;
|
||||
}
|
||||
// Proportional font: use average-width measurement instead of M-width
|
||||
if (_prefs && _prefs->large_font) {
|
||||
const char* sample = "the quick brown fox jumps over lazy dog";
|
||||
uint16_t sampleW = display.getTextWidth(sample);
|
||||
int sampleLen = strlen(sample);
|
||||
if (sampleW > 0 && sampleLen > 0) {
|
||||
_charsPerLine = (display.width() * sampleLen * 70) / ((int)sampleW * 100);
|
||||
}
|
||||
}
|
||||
if (_charsPerLine < 15) _charsPerLine = 15;
|
||||
if (_charsPerLine > 60) _charsPerLine = 60;
|
||||
|
||||
@@ -1143,6 +1168,10 @@ public:
|
||||
} else {
|
||||
_lineHeight = 5;
|
||||
}
|
||||
// Large font: formula above assumes built-in 6x8 ratio — too small for 9pt
|
||||
if (_prefs && _prefs->large_font) {
|
||||
_lineHeight = _prefs->smallLineH();
|
||||
}
|
||||
|
||||
_footerHeight = 14;
|
||||
int textAreaHeight = display.height() - _footerHeight;
|
||||
@@ -1176,6 +1205,8 @@ public:
|
||||
_utcOffset = utcOffset;
|
||||
}
|
||||
|
||||
void setTimeGetter(TimeGetterFn fn) { _getTimeFn = fn; }
|
||||
|
||||
void enter(DisplayDriver& display) {
|
||||
initLayout(display);
|
||||
scanFiles();
|
||||
@@ -1341,4 +1372,42 @@ public:
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
#else // !ESP32
|
||||
|
||||
// Non-ESP32 stub: Meshpocket / T-Echo Card have no SD card hardware, so the
|
||||
// full notes editor (which depends on SD.h) can't work here. This stub keeps
|
||||
// UITask.cpp compilable by providing the same public interface as no-ops.
|
||||
// Navigating to notes from the home screen on a Meshpocket will just render
|
||||
// a placeholder message and do nothing.
|
||||
class NotesScreen : public UIScreen {
|
||||
public:
|
||||
typedef uint32_t (*TimeGetterFn)();
|
||||
|
||||
NotesScreen(UITask* task, NodePrefs* prefs = nullptr) {
|
||||
(void)task; (void)prefs;
|
||||
}
|
||||
|
||||
int render(DisplayDriver& display) override {
|
||||
display.setTextSize(1);
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.setCursor(0, 20);
|
||||
display.print("Notes: SD card required");
|
||||
display.setCursor(0, 30);
|
||||
display.print("(not available)");
|
||||
return 5000;
|
||||
}
|
||||
|
||||
bool handleInput(char c) override { (void)c; return false; }
|
||||
bool isEditing() const { return false; }
|
||||
void triggerSaveAndExit() {}
|
||||
void exitNotes() {}
|
||||
void enter(DisplayDriver& display) { (void)display; }
|
||||
void setTimestamp(uint32_t rtcTime, int8_t utcOffset) {
|
||||
(void)rtcTime; (void)utcOffset;
|
||||
}
|
||||
void setTimeGetter(TimeGetterFn fn) { (void)fn; }
|
||||
};
|
||||
|
||||
#endif // ESP32
|
||||
@@ -0,0 +1,805 @@
|
||||
#pragma once
|
||||
|
||||
#include <helpers/ui/UIScreen.h>
|
||||
#include <helpers/ui/DisplayDriver.h>
|
||||
#include <MeshCore.h>
|
||||
#include <Packet.h>
|
||||
|
||||
// Forward declarations
|
||||
class UITask;
|
||||
class MyMesh;
|
||||
extern MyMesh the_mesh;
|
||||
|
||||
class PathEditorScreen : public UIScreen {
|
||||
public:
|
||||
enum EditorState {
|
||||
STATE_MAIN,
|
||||
STATE_PICK_HOP
|
||||
};
|
||||
|
||||
// Main-state menu items (dynamic, built each render)
|
||||
enum MenuItem {
|
||||
MENU_MODE = 0, // "Mode: 1B/hop" or "Mode: 2B/hop"
|
||||
// After mode: hop lines (MENU_HOP_BASE + i)
|
||||
// Then: action items
|
||||
MENU_HOP_BASE = 1,
|
||||
// Dynamic items after hops:
|
||||
MENU_ADD_HOP = 100,
|
||||
MENU_SET_DIRECT,
|
||||
MENU_REMOVE_LAST,
|
||||
MENU_CLEAR_PATH,
|
||||
MENU_SAVE_EXIT
|
||||
};
|
||||
|
||||
private:
|
||||
UITask* _task;
|
||||
mesh::RTCClock* _rtc;
|
||||
|
||||
int _contactIdx; // Index into contact table
|
||||
char _contactName[32]; // Contact name for header
|
||||
|
||||
EditorState _state;
|
||||
int _menuSel; // Selected menu item index (0-based in visible list)
|
||||
int _menuCount; // Total visible menu items
|
||||
|
||||
// Path being edited (working copy)
|
||||
uint8_t _pathBuf[MAX_PATH_SIZE];
|
||||
uint8_t _pathLen; // Encoded: bits[7:6]=mode, bits[5:0]=hops
|
||||
int _hopCount; // Decoded hop count
|
||||
int _bytesPerHop; // 1 or 2
|
||||
|
||||
// Repeater picker state
|
||||
static const int MAX_REPEATERS = 200;
|
||||
uint16_t* _repIdx; // Indices into contact table (PSRAM)
|
||||
int _repCount; // Number of repeaters found
|
||||
int _repSel; // Selected repeater in picker
|
||||
int _repScroll; // Scroll offset in picker
|
||||
|
||||
bool _dirty; // Path has been modified
|
||||
bool _wantExit; // Set by Save & Exit — caller should navigate back
|
||||
bool _directLocked; // True = path is explicitly set to direct (0 hops, locked)
|
||||
|
||||
// --- helpers ---
|
||||
|
||||
void decodePath() {
|
||||
_hopCount = _pathLen & 0x3F;
|
||||
uint8_t mode = (_pathLen >> 6) & 0x03;
|
||||
_bytesPerHop = mode + 1;
|
||||
}
|
||||
|
||||
uint8_t encodePath() const {
|
||||
uint8_t mode = (_bytesPerHop - 1) & 0x03;
|
||||
return (mode << 6) | (_hopCount & 0x3F);
|
||||
}
|
||||
|
||||
void buildRepeaterList() {
|
||||
_repCount = 0;
|
||||
uint32_t numContacts = the_mesh.getNumContacts();
|
||||
ContactInfo c;
|
||||
for (uint32_t i = 0; i < numContacts && _repCount < MAX_REPEATERS; i++) {
|
||||
if (the_mesh.getContactByIdx(i, c)) {
|
||||
if (c.type == ADV_TYPE_REPEATER) {
|
||||
_repIdx[_repCount++] = (uint16_t)i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Look up a contact name by matching pub_key prefix bytes
|
||||
bool findNameForHop(int hopIndex, char* name, size_t nameLen) const {
|
||||
if (hopIndex < 0 || hopIndex >= _hopCount) return false;
|
||||
int offset = hopIndex * _bytesPerHop;
|
||||
uint32_t numContacts = the_mesh.getNumContacts();
|
||||
ContactInfo c;
|
||||
for (uint32_t i = 0; i < numContacts; i++) {
|
||||
if (the_mesh.getContactByIdx(i, c)) {
|
||||
bool match = true;
|
||||
for (int b = 0; b < _bytesPerHop; b++) {
|
||||
if (c.id.pub_key[b] != _pathBuf[offset + b]) {
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (match) {
|
||||
strncpy(name, c.name, nameLen);
|
||||
name[nameLen - 1] = '\0';
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Build the visible menu items list and return count
|
||||
// Menu layout:
|
||||
// 0: Mode selector
|
||||
// 1..hopCount: each hop
|
||||
// hopCount+1: Add hop
|
||||
// hopCount+2: Remove last (only if hops > 0)
|
||||
// hopCount+2 or +3: Clear path (only if custom path flag set or hops > 0)
|
||||
// last: Save & Exit
|
||||
int buildMenuCount() const {
|
||||
int count = 1; // Mode selector
|
||||
count += _hopCount; // One per hop
|
||||
if (_hopCount < 8) count++; // Add hop (max 8 hops)
|
||||
count++; // Set Direct (always visible)
|
||||
if (_hopCount > 0) count++; // Remove last
|
||||
if (_hopCount > 0 || _directLocked || isCustomPathSet()) count++; // Clear path
|
||||
count++; // Save & Exit
|
||||
return count;
|
||||
}
|
||||
|
||||
// Map a menu index to a MenuItem enum
|
||||
MenuItem menuItemAt(int idx) const {
|
||||
if (idx == 0) return MENU_MODE;
|
||||
int pos = 1;
|
||||
// Hop lines
|
||||
for (int h = 0; h < _hopCount; h++) {
|
||||
if (idx == pos) return (MenuItem)(MENU_HOP_BASE + h);
|
||||
pos++;
|
||||
}
|
||||
// Add hop
|
||||
if (_hopCount < 8) {
|
||||
if (idx == pos) return MENU_ADD_HOP;
|
||||
pos++;
|
||||
}
|
||||
// Set Direct
|
||||
if (idx == pos) return MENU_SET_DIRECT;
|
||||
pos++;
|
||||
// Remove last
|
||||
if (_hopCount > 0) {
|
||||
if (idx == pos) return MENU_REMOVE_LAST;
|
||||
pos++;
|
||||
}
|
||||
// Clear path
|
||||
if (_hopCount > 0 || _directLocked || isCustomPathSet()) {
|
||||
if (idx == pos) return MENU_CLEAR_PATH;
|
||||
pos++;
|
||||
}
|
||||
// Save & Exit
|
||||
return MENU_SAVE_EXIT;
|
||||
}
|
||||
|
||||
bool isCustomPathSet() const {
|
||||
ContactInfo c;
|
||||
if (!the_mesh.getContactByIdx(_contactIdx, c)) return false;
|
||||
return (c.flags & CONTACT_FLAG_CUSTOM_PATH) != 0;
|
||||
}
|
||||
|
||||
public:
|
||||
PathEditorScreen(UITask* task, mesh::RTCClock* rtc)
|
||||
: _task(task), _rtc(rtc), _contactIdx(-1), _state(STATE_MAIN),
|
||||
_menuSel(0), _menuCount(1), _pathLen(0), _hopCount(0),
|
||||
_bytesPerHop(1), _repCount(0), _repSel(0), _repScroll(0),
|
||||
_dirty(false), _wantExit(false), _directLocked(false) {
|
||||
memset(_contactName, 0, sizeof(_contactName));
|
||||
memset(_pathBuf, 0, sizeof(_pathBuf));
|
||||
#if defined(ESP32) && defined(BOARD_HAS_PSRAM)
|
||||
_repIdx = (uint16_t*)ps_calloc(MAX_REPEATERS, sizeof(uint16_t));
|
||||
#else
|
||||
_repIdx = new uint16_t[MAX_REPEATERS]();
|
||||
#endif
|
||||
}
|
||||
|
||||
void openForContact(int contactIdx) {
|
||||
_contactIdx = contactIdx;
|
||||
_state = STATE_MAIN;
|
||||
_menuSel = 0;
|
||||
_repSel = 0;
|
||||
_repScroll = 0;
|
||||
_dirty = false;
|
||||
_wantExit = false;
|
||||
_directLocked = false;
|
||||
|
||||
// Load contact info
|
||||
ContactInfo c;
|
||||
if (the_mesh.getContactByIdx(contactIdx, c)) {
|
||||
strncpy(_contactName, c.name, sizeof(_contactName) - 1);
|
||||
_contactName[sizeof(_contactName) - 1] = '\0';
|
||||
|
||||
// Copy current path
|
||||
if (c.out_path_len != OUT_PATH_UNKNOWN) {
|
||||
_pathLen = c.out_path_len;
|
||||
decodePath();
|
||||
int byteLen = _hopCount * _bytesPerHop;
|
||||
if (byteLen > MAX_PATH_SIZE) byteLen = MAX_PATH_SIZE;
|
||||
memcpy(_pathBuf, c.out_path, byteLen);
|
||||
// Detect existing direct-locked path
|
||||
if (_hopCount == 0 && (c.flags & CONTACT_FLAG_CUSTOM_PATH)) {
|
||||
_directLocked = true;
|
||||
}
|
||||
} else {
|
||||
_pathLen = 0;
|
||||
_hopCount = 0;
|
||||
_bytesPerHop = 1;
|
||||
memset(_pathBuf, 0, sizeof(_pathBuf));
|
||||
}
|
||||
} else {
|
||||
strcpy(_contactName, "Unknown");
|
||||
_pathLen = 0;
|
||||
_hopCount = 0;
|
||||
_bytesPerHop = 1;
|
||||
}
|
||||
|
||||
_menuCount = buildMenuCount();
|
||||
}
|
||||
|
||||
int render(DisplayDriver& display) override {
|
||||
if (_state == STATE_PICK_HOP) {
|
||||
return renderPicker(display);
|
||||
}
|
||||
return renderMain(display);
|
||||
}
|
||||
|
||||
int renderMain(DisplayDriver& display) {
|
||||
char tmp[64];
|
||||
|
||||
// === Header ===
|
||||
display.setTextSize(1);
|
||||
display.setColor(DisplayDriver::GREEN);
|
||||
display.setCursor(0, 0);
|
||||
snprintf(tmp, sizeof(tmp), "Path: %s", _contactName);
|
||||
// Truncate if too long
|
||||
if (display.getTextWidth(tmp) > display.width() - 4) {
|
||||
snprintf(tmp, sizeof(tmp), "Path: %.12s..", _contactName);
|
||||
}
|
||||
display.print(tmp);
|
||||
|
||||
// Show lock icon or dirty indicator on right
|
||||
if (_dirty) {
|
||||
const char* mod = "[*]";
|
||||
display.setCursor(display.width() - display.getTextWidth(mod) - 2, 0);
|
||||
display.print(mod);
|
||||
} else if (isCustomPathSet()) {
|
||||
const char* lock = "[L]";
|
||||
display.setCursor(display.width() - display.getTextWidth(lock) - 2, 0);
|
||||
display.print(lock);
|
||||
}
|
||||
|
||||
display.drawRect(0, 11, display.width(), 1);
|
||||
|
||||
// === Body ===
|
||||
display.setTextSize(0);
|
||||
int lineH = 9;
|
||||
int headerH = 14;
|
||||
int footerH = 14;
|
||||
int maxY = display.height() - footerH;
|
||||
int y = headerH;
|
||||
|
||||
_menuCount = buildMenuCount();
|
||||
|
||||
// Center visible window around selected item
|
||||
int maxVisible = (maxY - headerH) / lineH;
|
||||
if (maxVisible < 3) maxVisible = 3;
|
||||
int startIdx = max(0, min(_menuSel - maxVisible / 2, _menuCount - maxVisible));
|
||||
if (startIdx < 0) startIdx = 0;
|
||||
int endIdx = min(_menuCount, startIdx + maxVisible);
|
||||
|
||||
for (int i = startIdx; i < endIdx && y + lineH <= maxY; i++) {
|
||||
bool selected = (i == _menuSel);
|
||||
MenuItem item = menuItemAt(i);
|
||||
|
||||
if (selected) {
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.fillRect(0, y, display.width(), lineH);
|
||||
#else
|
||||
display.fillRect(0, y + 5, display.width(), lineH);
|
||||
#endif
|
||||
display.setColor(DisplayDriver::DARK);
|
||||
} else {
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
}
|
||||
|
||||
display.setCursor(2, y);
|
||||
char prefix = selected ? '>' : ' ';
|
||||
|
||||
switch (item) {
|
||||
case MENU_MODE:
|
||||
if (_directLocked) {
|
||||
snprintf(tmp, sizeof(tmp), "%c Mode: DIRECT", prefix);
|
||||
} else {
|
||||
snprintf(tmp, sizeof(tmp), "%c Mode: %dB/hop", prefix, _bytesPerHop);
|
||||
}
|
||||
display.print(tmp);
|
||||
// Show hint on right
|
||||
if (!_directLocked) {
|
||||
const char* hint = "(A/D)";
|
||||
display.setCursor(display.width() - display.getTextWidth(hint) - 4, y);
|
||||
display.print(hint);
|
||||
}
|
||||
break;
|
||||
|
||||
case MENU_ADD_HOP:
|
||||
snprintf(tmp, sizeof(tmp), "%c + Add hop...", prefix);
|
||||
display.print(tmp);
|
||||
break;
|
||||
|
||||
case MENU_SET_DIRECT:
|
||||
if (_directLocked) {
|
||||
snprintf(tmp, sizeof(tmp), "%c * Direct (set)", prefix);
|
||||
} else {
|
||||
snprintf(tmp, sizeof(tmp), "%c * Set Direct", prefix);
|
||||
}
|
||||
display.print(tmp);
|
||||
break;
|
||||
|
||||
case MENU_REMOVE_LAST:
|
||||
snprintf(tmp, sizeof(tmp), "%c - Remove last hop", prefix);
|
||||
display.print(tmp);
|
||||
break;
|
||||
|
||||
case MENU_CLEAR_PATH:
|
||||
snprintf(tmp, sizeof(tmp), "%c Clear custom path", prefix);
|
||||
display.print(tmp);
|
||||
break;
|
||||
|
||||
case MENU_SAVE_EXIT:
|
||||
snprintf(tmp, sizeof(tmp), "%c Save & Exit", prefix);
|
||||
display.print(tmp);
|
||||
break;
|
||||
|
||||
default:
|
||||
// Hop line: MENU_HOP_BASE + hopIndex
|
||||
if (item >= MENU_HOP_BASE && item < MENU_HOP_BASE + 64) {
|
||||
int hopIdx = item - MENU_HOP_BASE;
|
||||
char hopName[24];
|
||||
int offset = hopIdx * _bytesPerHop;
|
||||
|
||||
if (findNameForHop(hopIdx, hopName, sizeof(hopName))) {
|
||||
if (_bytesPerHop == 1) {
|
||||
snprintf(tmp, sizeof(tmp), "%c %d: %s (%02X)", prefix, hopIdx + 1,
|
||||
hopName, _pathBuf[offset]);
|
||||
} else {
|
||||
snprintf(tmp, sizeof(tmp), "%c %d: %s (%02X%02X)", prefix, hopIdx + 1,
|
||||
hopName, _pathBuf[offset], _pathBuf[offset + 1]);
|
||||
}
|
||||
} else {
|
||||
if (_bytesPerHop == 1) {
|
||||
snprintf(tmp, sizeof(tmp), "%c %d: ??? (%02X)", prefix, hopIdx + 1,
|
||||
_pathBuf[offset]);
|
||||
} else {
|
||||
snprintf(tmp, sizeof(tmp), "%c %d: ??? (%02X%02X)", prefix, hopIdx + 1,
|
||||
_pathBuf[offset], _pathBuf[offset + 1]);
|
||||
}
|
||||
}
|
||||
display.drawTextEllipsized(2, y, display.width() - 4, tmp);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
y += lineH;
|
||||
}
|
||||
|
||||
// === Footer ===
|
||||
display.setTextSize(1);
|
||||
int footerY = display.height() - 12;
|
||||
display.drawRect(0, footerY - 2, display.width(), 1);
|
||||
display.setColor(DisplayDriver::YELLOW);
|
||||
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.setCursor(0, footerY);
|
||||
display.print("Swipe:Nav");
|
||||
const char* right = "Hold:Select";
|
||||
display.setCursor(display.width() - display.getTextWidth(right) - 2, footerY);
|
||||
display.print(right);
|
||||
#else
|
||||
display.setCursor(0, footerY);
|
||||
display.print("Q:Bk W/S:Nav");
|
||||
const char* right = "Enter:Sel";
|
||||
display.setCursor(display.width() - display.getTextWidth(right) - 2, footerY);
|
||||
display.print(right);
|
||||
#endif
|
||||
|
||||
return 5000;
|
||||
}
|
||||
|
||||
int renderPicker(DisplayDriver& display) {
|
||||
char tmp[64];
|
||||
|
||||
// === Header ===
|
||||
display.setTextSize(1);
|
||||
display.setColor(DisplayDriver::GREEN);
|
||||
display.setCursor(0, 0);
|
||||
snprintf(tmp, sizeof(tmp), "Select Repeater (%d)", _repCount);
|
||||
display.print(tmp);
|
||||
|
||||
display.drawRect(0, 11, display.width(), 1);
|
||||
|
||||
// === Body ===
|
||||
display.setTextSize(0);
|
||||
int lineH = 9;
|
||||
int headerH = 14;
|
||||
int footerH = 14;
|
||||
int maxY = display.height() - footerH;
|
||||
int y = headerH;
|
||||
|
||||
if (_repCount == 0) {
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.setCursor(0, y);
|
||||
display.print("No repeaters in contacts");
|
||||
display.setCursor(0, y + lineH);
|
||||
display.print("Add repeaters first");
|
||||
} else {
|
||||
int maxVisible = (maxY - headerH) / lineH;
|
||||
if (maxVisible < 3) maxVisible = 3;
|
||||
int startIdx = max(0, min(_repSel - maxVisible / 2, _repCount - maxVisible));
|
||||
if (startIdx < 0) startIdx = 0;
|
||||
int endIdx = min(_repCount, startIdx + maxVisible);
|
||||
|
||||
for (int i = startIdx; i < endIdx && y + lineH <= maxY; i++) {
|
||||
ContactInfo c;
|
||||
if (!the_mesh.getContactByIdx(_repIdx[i], c)) continue;
|
||||
|
||||
bool selected = (i == _repSel);
|
||||
|
||||
if (selected) {
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.fillRect(0, y, display.width(), lineH);
|
||||
#else
|
||||
display.fillRect(0, y + 5, display.width(), lineH);
|
||||
#endif
|
||||
display.setColor(DisplayDriver::DARK);
|
||||
} else {
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
}
|
||||
|
||||
display.setCursor(2, y);
|
||||
char prefix = selected ? '>' : ' ';
|
||||
|
||||
if (_bytesPerHop == 1) {
|
||||
snprintf(tmp, sizeof(tmp), "%c %s (%02X)", prefix, c.name, c.id.pub_key[0]);
|
||||
} else {
|
||||
snprintf(tmp, sizeof(tmp), "%c %s (%02X%02X)", prefix, c.name,
|
||||
c.id.pub_key[0], c.id.pub_key[1]);
|
||||
}
|
||||
display.drawTextEllipsized(2, y, display.width() - 4, tmp);
|
||||
|
||||
y += lineH;
|
||||
}
|
||||
}
|
||||
|
||||
// === Footer ===
|
||||
display.setTextSize(1);
|
||||
int footerY = display.height() - 12;
|
||||
display.drawRect(0, footerY - 2, display.width(), 1);
|
||||
display.setColor(DisplayDriver::YELLOW);
|
||||
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.setCursor(0, footerY);
|
||||
display.print("Swipe:Scroll");
|
||||
const char* right = "Hold:Add Back:Cancel";
|
||||
display.setCursor(display.width() - display.getTextWidth(right) - 2, footerY);
|
||||
display.print(right);
|
||||
#else
|
||||
display.setCursor(0, footerY);
|
||||
display.print("Q:Cancel W/S:Scroll");
|
||||
const char* right = "Enter:Add";
|
||||
display.setCursor(display.width() - display.getTextWidth(right) - 2, footerY);
|
||||
display.print(right);
|
||||
#endif
|
||||
|
||||
return 5000;
|
||||
}
|
||||
|
||||
bool handleInput(char c) override {
|
||||
if (_state == STATE_PICK_HOP) {
|
||||
return handlePickerInput(c);
|
||||
}
|
||||
return handleMainInput(c);
|
||||
}
|
||||
|
||||
bool handleMainInput(char c) {
|
||||
// W - scroll up
|
||||
if (c == 'w' || c == 'W' || c == 0xF2) {
|
||||
if (_menuSel > 0) {
|
||||
_menuSel--;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// S - scroll down
|
||||
if (c == 's' || c == 'S' || c == 0xF1) {
|
||||
if (_menuSel < _menuCount - 1) {
|
||||
_menuSel++;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// A/D — toggle mode (only when Mode item is selected and not direct-locked)
|
||||
if (c == 'a' || c == 'A' || c == 'd' || c == 'D') {
|
||||
MenuItem item = menuItemAt(_menuSel);
|
||||
if (item == MENU_MODE && !_directLocked) {
|
||||
// Toggle between 1-byte and 2-byte
|
||||
if (_bytesPerHop == 1) {
|
||||
switchMode(2);
|
||||
} else {
|
||||
switchMode(1);
|
||||
}
|
||||
_dirty = true;
|
||||
_menuCount = buildMenuCount();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Enter - select
|
||||
if (c == 13 || c == KEY_ENTER || c == '\r') {
|
||||
MenuItem item = menuItemAt(_menuSel);
|
||||
|
||||
switch (item) {
|
||||
case MENU_MODE:
|
||||
// Toggle mode on Enter too (no-op if direct locked)
|
||||
if (!_directLocked) {
|
||||
if (_bytesPerHop == 1) {
|
||||
switchMode(2);
|
||||
} else {
|
||||
switchMode(1);
|
||||
}
|
||||
_dirty = true;
|
||||
_menuCount = buildMenuCount();
|
||||
}
|
||||
return true;
|
||||
|
||||
case MENU_ADD_HOP:
|
||||
// Enter picker mode — adding a hop clears direct lock
|
||||
_directLocked = false;
|
||||
buildRepeaterList();
|
||||
_repSel = 0;
|
||||
_repScroll = 0;
|
||||
_state = STATE_PICK_HOP;
|
||||
return true;
|
||||
|
||||
case MENU_SET_DIRECT:
|
||||
// Set path to direct (0 hops, locked)
|
||||
_hopCount = 0;
|
||||
_pathLen = 0;
|
||||
memset(_pathBuf, 0, sizeof(_pathBuf));
|
||||
_directLocked = true;
|
||||
_dirty = true;
|
||||
_menuCount = buildMenuCount();
|
||||
return true;
|
||||
|
||||
case MENU_REMOVE_LAST:
|
||||
if (_hopCount > 0) {
|
||||
_hopCount--;
|
||||
_pathLen = encodePath();
|
||||
_dirty = true;
|
||||
_menuCount = buildMenuCount();
|
||||
// Clamp selection
|
||||
if (_menuSel >= _menuCount) _menuSel = _menuCount - 1;
|
||||
}
|
||||
return true;
|
||||
|
||||
case MENU_CLEAR_PATH:
|
||||
_hopCount = 0;
|
||||
_pathLen = 0;
|
||||
_directLocked = false;
|
||||
memset(_pathBuf, 0, sizeof(_pathBuf));
|
||||
_dirty = true;
|
||||
_menuCount = buildMenuCount();
|
||||
_menuSel = 0;
|
||||
return true;
|
||||
|
||||
case MENU_SAVE_EXIT:
|
||||
savePath();
|
||||
_wantExit = true; // Signal to main.cpp to navigate back to contacts
|
||||
return true;
|
||||
|
||||
default:
|
||||
// Hop line — no action (could add remove-specific-hop later)
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Q - back (discard changes or prompt?)
|
||||
// For simplicity, just go back without saving
|
||||
if (c == 'q' || c == 'Q') {
|
||||
// Return to contacts screen without saving
|
||||
// The UITask will handle this via the key falling through
|
||||
return false; // Let UITask handle Q as back
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool handlePickerInput(char c) {
|
||||
// W - scroll up
|
||||
if (c == 'w' || c == 'W' || c == 0xF2) {
|
||||
if (_repSel > 0) {
|
||||
_repSel--;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// S - scroll down
|
||||
if (c == 's' || c == 'S' || c == 0xF1) {
|
||||
if (_repSel < _repCount - 1) {
|
||||
_repSel++;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Enter - add selected repeater as hop
|
||||
if (c == 13 || c == KEY_ENTER || c == '\r') {
|
||||
if (_repCount > 0 && _repSel >= 0 && _repSel < _repCount) {
|
||||
addHopFromContact(_repIdx[_repSel]);
|
||||
}
|
||||
_state = STATE_MAIN;
|
||||
_menuCount = buildMenuCount();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Q - cancel picker, return to main
|
||||
if (c == 'q' || c == 'Q') {
|
||||
_state = STATE_MAIN;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Tap-to-select for T5S3 touch
|
||||
int selectRowAtVY(int vy) {
|
||||
if (_state == STATE_PICK_HOP) {
|
||||
return selectPickerRowAtVY(vy);
|
||||
}
|
||||
return selectMainRowAtVY(vy);
|
||||
}
|
||||
|
||||
int selectMainRowAtVY(int vy) {
|
||||
if (_menuCount == 0) return 0;
|
||||
const int headerH = 14, footerH = 14, lineH = 9;
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
const int bodyTop = headerH;
|
||||
#else
|
||||
const int bodyTop = headerH + 5;
|
||||
#endif
|
||||
if (vy < bodyTop || vy >= 128 - footerH) return 0;
|
||||
|
||||
int maxVisible = (128 - headerH - footerH) / lineH;
|
||||
if (maxVisible < 3) maxVisible = 3;
|
||||
int startIdx = max(0, min(_menuSel - maxVisible / 2, _menuCount - maxVisible));
|
||||
if (startIdx < 0) startIdx = 0;
|
||||
|
||||
int tappedRow = startIdx + (vy - bodyTop) / lineH;
|
||||
if (tappedRow < 0 || tappedRow >= _menuCount) return 0;
|
||||
if (tappedRow == _menuSel) return 2;
|
||||
_menuSel = tappedRow;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int selectPickerRowAtVY(int vy) {
|
||||
if (_repCount == 0) return 0;
|
||||
const int headerH = 14, footerH = 14, lineH = 9;
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
const int bodyTop = headerH;
|
||||
#else
|
||||
const int bodyTop = headerH + 5;
|
||||
#endif
|
||||
if (vy < bodyTop || vy >= 128 - footerH) return 0;
|
||||
|
||||
int maxVisible = (128 - headerH - footerH) / lineH;
|
||||
if (maxVisible < 3) maxVisible = 3;
|
||||
int startIdx = max(0, min(_repSel - maxVisible / 2, _repCount - maxVisible));
|
||||
if (startIdx < 0) startIdx = 0;
|
||||
|
||||
int tappedRow = startIdx + (vy - bodyTop) / lineH;
|
||||
if (tappedRow < 0 || tappedRow >= _repCount) return 0;
|
||||
if (tappedRow == _repSel) return 2;
|
||||
_repSel = tappedRow;
|
||||
return 1;
|
||||
}
|
||||
|
||||
EditorState getState() const { return _state; }
|
||||
bool isDirty() const { return _dirty; }
|
||||
bool wantsExit() const { return _wantExit; }
|
||||
|
||||
private:
|
||||
void switchMode(int newBytesPerHop) {
|
||||
if (newBytesPerHop == _bytesPerHop) return;
|
||||
|
||||
if (_hopCount > 0) {
|
||||
// Rebuild path buffer for new mode
|
||||
// We need the full pub_keys to re-extract the right prefix bytes
|
||||
uint8_t newBuf[MAX_PATH_SIZE];
|
||||
memset(newBuf, 0, sizeof(newBuf));
|
||||
int newHopCount = 0;
|
||||
|
||||
for (int h = 0; h < _hopCount && newHopCount < 8; h++) {
|
||||
int oldOffset = h * _bytesPerHop;
|
||||
// Try to find the contact that matches this hop
|
||||
uint32_t numContacts = the_mesh.getNumContacts();
|
||||
ContactInfo c;
|
||||
bool found = false;
|
||||
for (uint32_t i = 0; i < numContacts; i++) {
|
||||
if (the_mesh.getContactByIdx(i, c)) {
|
||||
bool match = true;
|
||||
for (int b = 0; b < _bytesPerHop; b++) {
|
||||
if (c.id.pub_key[b] != _pathBuf[oldOffset + b]) {
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (match) {
|
||||
// Found the contact — copy new prefix size
|
||||
int newOffset = newHopCount * newBytesPerHop;
|
||||
for (int b = 0; b < newBytesPerHop; b++) {
|
||||
newBuf[newOffset + b] = c.id.pub_key[b];
|
||||
}
|
||||
newHopCount++;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
// Contact not found — copy what we can
|
||||
int newOffset = newHopCount * newBytesPerHop;
|
||||
int oldOff = h * _bytesPerHop;
|
||||
for (int b = 0; b < newBytesPerHop; b++) {
|
||||
if (b < _bytesPerHop) {
|
||||
newBuf[newOffset + b] = _pathBuf[oldOff + b];
|
||||
} else {
|
||||
newBuf[newOffset + b] = 0x00; // pad with zero
|
||||
}
|
||||
}
|
||||
newHopCount++;
|
||||
}
|
||||
}
|
||||
|
||||
_hopCount = newHopCount;
|
||||
memcpy(_pathBuf, newBuf, sizeof(newBuf));
|
||||
}
|
||||
|
||||
_bytesPerHop = newBytesPerHop;
|
||||
_pathLen = encodePath();
|
||||
}
|
||||
|
||||
void addHopFromContact(uint16_t contactTableIdx) {
|
||||
if (_hopCount >= 8) return;
|
||||
ContactInfo c;
|
||||
if (!the_mesh.getContactByIdx(contactTableIdx, c)) return;
|
||||
|
||||
int offset = _hopCount * _bytesPerHop;
|
||||
if (offset + _bytesPerHop > MAX_PATH_SIZE) return;
|
||||
|
||||
for (int b = 0; b < _bytesPerHop; b++) {
|
||||
_pathBuf[offset + b] = c.id.pub_key[b];
|
||||
}
|
||||
_hopCount++;
|
||||
_pathLen = encodePath();
|
||||
_dirty = true;
|
||||
}
|
||||
|
||||
void savePath() {
|
||||
if (_contactIdx < 0) return;
|
||||
|
||||
if (_directLocked) {
|
||||
// Set as direct (0 hops) with lock — prevents flood routing
|
||||
the_mesh.setCustomPath(_contactIdx, _pathBuf, 0, true);
|
||||
Serial.printf("PathEditor: set DIRECT path for contact %d (%s)\n",
|
||||
_contactIdx, _contactName);
|
||||
} else if (_hopCount > 0) {
|
||||
// Set custom path with lock
|
||||
the_mesh.setCustomPath(_contactIdx, _pathBuf, encodePath(), true);
|
||||
Serial.printf("PathEditor: saved %d-hop %dB/hop path for contact %d (%s)\n",
|
||||
_hopCount, _bytesPerHop, _contactIdx, _contactName);
|
||||
} else {
|
||||
// Clear custom path — revert to auto-discovery
|
||||
the_mesh.clearCustomPath(_contactIdx);
|
||||
Serial.printf("PathEditor: cleared custom path for contact %d (%s)\n",
|
||||
_contactIdx, _contactName);
|
||||
}
|
||||
|
||||
// Trigger contact save to SD
|
||||
the_mesh.saveContacts();
|
||||
_dirty = false;
|
||||
}
|
||||
};
|
||||
@@ -475,6 +475,7 @@ public:
|
||||
|
||||
int getContactIdx() const { return _contactIdx; }
|
||||
AdminState getState() const { return _state; }
|
||||
uint8_t getPermissions() const { return _permissions; }
|
||||
|
||||
void onLoginResult(bool success, uint8_t permissions, uint32_t server_time) {
|
||||
_waitingForLogin = false;
|
||||
@@ -561,7 +562,9 @@ public:
|
||||
display.setTextSize(1);
|
||||
display.setColor(DisplayDriver::GREEN);
|
||||
display.setCursor(0, 0);
|
||||
snprintf(tmp, sizeof(tmp), "Admin: %.16s", _repeaterName);
|
||||
const char* hdrPrefix = (_state == STATE_PASSWORD_ENTRY || _state == STATE_LOGGING_IN)
|
||||
? "Login" : "Admin";
|
||||
snprintf(tmp, sizeof(tmp), "%s: %.16s", hdrPrefix, _repeaterName);
|
||||
display.print(tmp);
|
||||
|
||||
if (_state >= STATE_CATEGORY_MENU && _state <= STATE_RESPONSE_VIEW) {
|
||||
@@ -774,8 +777,8 @@ private:
|
||||
// =====================================================================
|
||||
|
||||
void renderCategoryMenu(DisplayDriver& display, int y, int bodyHeight) {
|
||||
display.setTextSize(0);
|
||||
int lineHeight = 9;
|
||||
display.setTextSize(the_mesh.getNodePrefs()->smallTextSize());
|
||||
int lineHeight = the_mesh.getNodePrefs()->smallLineH();
|
||||
|
||||
// Clock drift info line
|
||||
if (_serverTime > 0) {
|
||||
@@ -859,8 +862,8 @@ private:
|
||||
// =====================================================================
|
||||
|
||||
void renderCommandMenu(DisplayDriver& display, int y, int bodyHeight) {
|
||||
display.setTextSize(0);
|
||||
int lineHeight = 9;
|
||||
display.setTextSize(the_mesh.getNodePrefs()->smallTextSize());
|
||||
int lineHeight = the_mesh.getNodePrefs()->smallLineH();
|
||||
const AdminCategoryDef& cat = CATEGORIES[_catSel];
|
||||
|
||||
// Category title
|
||||
@@ -1022,7 +1025,7 @@ private:
|
||||
if (_pendingCmd) display.print(_pendingCmd->label);
|
||||
|
||||
y += 14;
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(the_mesh.getNodePrefs()->smallTextSize());
|
||||
display.setCursor(0, y);
|
||||
|
||||
// Show the param value if one was collected
|
||||
@@ -1030,7 +1033,7 @@ private:
|
||||
char preview[80];
|
||||
snprintf(preview, sizeof(preview), "Value: %s", _paramBuf);
|
||||
display.print(preview);
|
||||
y += 10;
|
||||
y += the_mesh.getNodePrefs()->smallLineH() + 1;
|
||||
display.setCursor(0, y);
|
||||
}
|
||||
|
||||
@@ -1068,8 +1071,8 @@ private:
|
||||
// =====================================================================
|
||||
|
||||
void renderResponse(DisplayDriver& display, int y, int bodyHeight) {
|
||||
display.setTextSize(0);
|
||||
int lineHeight = 9;
|
||||
display.setTextSize(the_mesh.getNodePrefs()->smallTextSize());
|
||||
int lineHeight = the_mesh.getNodePrefs()->smallLineH();
|
||||
|
||||
display.setColor((_state == STATE_ERROR) ? DisplayDriver::YELLOW : DisplayDriver::LIGHT);
|
||||
|
||||
@@ -1163,7 +1166,7 @@ private:
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.fillRect(0, y, display.width(), lineHeight);
|
||||
#else
|
||||
display.fillRect(0, y + 5, display.width(), lineHeight);
|
||||
display.fillRect(0, y + the_mesh.getNodePrefs()->smallHighlightOff(), display.width(), lineHeight);
|
||||
#endif
|
||||
display.setColor(DisplayDriver::DARK);
|
||||
} else if (warn) {
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "ModemManager.h"
|
||||
#include "SMSStore.h"
|
||||
#include "SMSContacts.h"
|
||||
#include "../NodePrefs.h"
|
||||
|
||||
// Limits
|
||||
#define SMS_INBOX_PAGE_SIZE 4
|
||||
@@ -51,6 +52,7 @@ public:
|
||||
|
||||
private:
|
||||
UITask* _task;
|
||||
NodePrefs* _prefs;
|
||||
SubView _view;
|
||||
|
||||
// App menu state
|
||||
@@ -117,8 +119,8 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
SMSScreen(UITask* task)
|
||||
: _task(task), _view(APP_MENU)
|
||||
SMSScreen(UITask* task, NodePrefs* prefs = nullptr)
|
||||
: _task(task), _prefs(prefs), _view(APP_MENU)
|
||||
, _menuCursor(0)
|
||||
, _convCount(0), _inboxCursor(0), _inboxScrollTop(0)
|
||||
, _msgCount(0), _msgScrollPos(0)
|
||||
@@ -276,7 +278,7 @@ public:
|
||||
|
||||
// Show modem state text if not ready
|
||||
if (ms != ModemState::READY && ms != ModemState::SENDING_SMS) {
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
display.setColor(DisplayDriver::YELLOW);
|
||||
const char* label = ModemManager::stateToString(ms);
|
||||
uint16_t labelW = display.getTextWidth(label);
|
||||
@@ -356,7 +358,7 @@ public:
|
||||
|
||||
// Modem status indicator
|
||||
ModemState ms = modemManager.getState();
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
display.setCursor(4, y + lineHeight + 8);
|
||||
if (ms == ModemState::OFF || ms == ModemState::POWERING_ON ||
|
||||
ms == ModemState::INITIALIZING) {
|
||||
@@ -483,7 +485,7 @@ public:
|
||||
bool isAction = (row == 4); // Bottom row has action buttons
|
||||
|
||||
if (isAction) {
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
if (col == 2 && _phoneInputPos > 0) {
|
||||
display.setColor(DisplayDriver::GREEN); // CALL
|
||||
} else if (col == 1) {
|
||||
@@ -544,7 +546,7 @@ public:
|
||||
display.drawRect(0, 11, display.width(), 1);
|
||||
|
||||
if (_convCount == 0) {
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.setCursor(0, 20);
|
||||
display.print("No conversations");
|
||||
@@ -560,8 +562,8 @@ public:
|
||||
}
|
||||
display.setTextSize(1);
|
||||
} else {
|
||||
display.setTextSize(0);
|
||||
int lineHeight = 10;
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
int lineHeight = _prefs->smallLineH() + 1;
|
||||
int y = 14;
|
||||
|
||||
int visibleCount = (display.height() - 14 - 14) / (lineHeight * 2 + 2);
|
||||
@@ -643,14 +645,14 @@ public:
|
||||
display.drawRect(0, 11, display.width(), 1);
|
||||
|
||||
if (_msgCount == 0) {
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.setCursor(0, 25);
|
||||
display.print("No messages");
|
||||
display.setTextSize(1);
|
||||
} else {
|
||||
display.setTextSize(0);
|
||||
int lineHeight = 10;
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
int lineHeight = _prefs->smallLineH() + 1;
|
||||
int headerHeight = 14;
|
||||
int footerHeight = 14;
|
||||
|
||||
@@ -764,12 +766,13 @@ public:
|
||||
// Message body
|
||||
display.setCursor(0, 14);
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
|
||||
uint16_t testWidth = display.getTextWidth("MMMMMMMMMM");
|
||||
int charsPerLine = (testWidth > 0) ? (display.width() * 10) / testWidth : 20;
|
||||
if (charsPerLine < 12) charsPerLine = 12;
|
||||
|
||||
int composeLH = _prefs->smallLineH() + 1;
|
||||
int y = 14;
|
||||
int x = 0;
|
||||
char cs[2] = {0, 0};
|
||||
@@ -780,7 +783,7 @@ public:
|
||||
x++;
|
||||
if (x >= charsPerLine) {
|
||||
x = 0;
|
||||
y += 10;
|
||||
y += composeLH;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -827,7 +830,7 @@ public:
|
||||
int cnt = smsContacts.count();
|
||||
|
||||
if (cnt == 0) {
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.setCursor(0, 25);
|
||||
display.print("No contacts saved");
|
||||
@@ -837,8 +840,8 @@ public:
|
||||
display.print("and press A to add");
|
||||
display.setTextSize(1);
|
||||
} else {
|
||||
display.setTextSize(0);
|
||||
int lineHeight = 10;
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
int lineHeight = _prefs->smallLineH() + 1;
|
||||
int y = 14;
|
||||
|
||||
int visibleCount = (display.height() - 14 - 14) / (lineHeight * 2 + 2);
|
||||
@@ -900,7 +903,7 @@ public:
|
||||
display.drawRect(0, 11, display.width(), 1);
|
||||
|
||||
// Phone number (read-only)
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.setCursor(0, 16);
|
||||
display.print("Phone: ");
|
||||
@@ -956,7 +959,7 @@ public:
|
||||
display.print(dispName);
|
||||
|
||||
// Phone number below name (smaller, dimmer)
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.setCursor(4, 36);
|
||||
display.print(_callPhone);
|
||||
@@ -1011,7 +1014,7 @@ public:
|
||||
display.print(dispName);
|
||||
|
||||
// Phone number below name (smaller, dimmer)
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.setCursor(4, 36);
|
||||
display.print(_callPhone);
|
||||
@@ -1070,7 +1073,7 @@ public:
|
||||
display.print(dispName);
|
||||
|
||||
// Phone number below name (smaller, dimmer)
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.setCursor(4, 36);
|
||||
display.print(_callPhone);
|
||||
@@ -1090,7 +1093,7 @@ public:
|
||||
display.print(timeBuf);
|
||||
|
||||
// Volume (left-aligned)
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
char volLabel[12];
|
||||
snprintf(volLabel, sizeof(volLabel), "Vol: %d/5", _callVolume);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,20 +2,25 @@
|
||||
|
||||
#include <helpers/ui/UIScreen.h>
|
||||
#include <helpers/ui/DisplayDriver.h>
|
||||
#include <SD.h>
|
||||
#include <vector>
|
||||
#include "Utf8CP437.h"
|
||||
#include "EpubProcessor.h"
|
||||
#ifdef ESP32
|
||||
#include <SD.h>
|
||||
#include <vector>
|
||||
#include "Utf8CP437.h"
|
||||
#include "EpubProcessor.h"
|
||||
#endif
|
||||
#include "../NodePrefs.h"
|
||||
|
||||
// Forward declarations
|
||||
class UITask;
|
||||
|
||||
#ifdef ESP32
|
||||
|
||||
// ============================================================================
|
||||
// Configuration
|
||||
// ============================================================================
|
||||
#define BOOKS_FOLDER "/books"
|
||||
#define INDEX_FOLDER "/.indexes"
|
||||
#define INDEX_VERSION 9 // v9: indexer buffer matches page buffer (fixes chunk boundary gaps)
|
||||
#define INDEX_VERSION 12 // v12: indexer breaks page BEFORE overflowing line (matches renderer pre-check)
|
||||
#define PREINDEX_PAGES 100
|
||||
#define READER_MAX_FILES 50
|
||||
#define READER_BUF_SIZE 4096
|
||||
@@ -115,10 +120,16 @@ inline WrapResult findLineBreakPixel(const char* buffer, int bufLen, int lineSta
|
||||
result.nextStart = lineStart;
|
||||
if (lineStart >= bufLen || !display) return result;
|
||||
|
||||
int displayW = display->width() - 3; // 3-unit right margin (rounding safety for proportional fonts)
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
int rightMargin = 5; // Wider margin for T5S3 (portrait mode especially tight)
|
||||
#else
|
||||
int rightMargin = 3;
|
||||
#endif
|
||||
int displayW = display->width() - rightMargin;
|
||||
char measBuf[300]; // temp buffer for pixel measurement
|
||||
int measLen = 0;
|
||||
int lastBreakPoint = -1;
|
||||
int lastBreakMeasLen = 0; // measLen at lastBreakPoint (for mid-word fallback)
|
||||
bool inWord = false;
|
||||
int charCount = 0;
|
||||
|
||||
@@ -145,6 +156,7 @@ inline WrapResult findLineBreakPixel(const char* buffer, int bufLen, int lineSta
|
||||
// UTF-8 handling: decode multi-byte sequences to CP437 for accurate
|
||||
// width measurement. The renderer (renderPage) does this same conversion,
|
||||
// so the measurement must match or it underestimates line width.
|
||||
int charStartIdx = i; // buffer index where this character started
|
||||
if ((uint8_t)c >= 0xC0) {
|
||||
// UTF-8 lead byte — decode full sequence to CP437
|
||||
int decPos = i;
|
||||
@@ -156,65 +168,54 @@ inline WrapResult findLineBreakPixel(const char* buffer, int bufLen, int lineSta
|
||||
}
|
||||
i = decPos - 1; // -1 because the for loop will i++
|
||||
inWord = true;
|
||||
continue;
|
||||
}
|
||||
if ((uint8_t)c >= 0x80 && (uint8_t)c < 0xC0) {
|
||||
} else if ((uint8_t)c >= 0x80 && (uint8_t)c < 0xC0) {
|
||||
// Orphan continuation byte — treat as CP437 pass-through (same as renderer)
|
||||
if (measLen < 298) measBuf[measLen++] = c;
|
||||
charCount++;
|
||||
inWord = true;
|
||||
continue;
|
||||
} else {
|
||||
// Plain ASCII
|
||||
charCount++;
|
||||
if (measLen < 298) measBuf[measLen++] = c;
|
||||
|
||||
if (c == ' ' || c == '\t') {
|
||||
if (inWord) {
|
||||
lastBreakPoint = i;
|
||||
lastBreakMeasLen = measLen;
|
||||
inWord = false;
|
||||
}
|
||||
} else if (c == '-') {
|
||||
if (inWord) {
|
||||
lastBreakPoint = i + 1;
|
||||
lastBreakMeasLen = measLen;
|
||||
}
|
||||
inWord = true;
|
||||
} else {
|
||||
inWord = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Plain ASCII
|
||||
charCount++;
|
||||
if (measLen < 298) measBuf[measLen++] = c;
|
||||
|
||||
if (c == ' ' || c == '\t') {
|
||||
if (inWord) {
|
||||
// Measure pixel width at this word boundary
|
||||
measBuf[measLen] = '\0';
|
||||
int pw = display->getTextWidth(measBuf);
|
||||
if (pw >= displayW) {
|
||||
// Current word pushes past edge — break at previous word boundary
|
||||
if (lastBreakPoint > lineStart) {
|
||||
result.lineEnd = lastBreakPoint;
|
||||
result.nextStart = lastBreakPoint;
|
||||
while (result.nextStart < bufLen &&
|
||||
(buffer[result.nextStart] == ' ' || buffer[result.nextStart] == '\t'))
|
||||
result.nextStart++;
|
||||
} else {
|
||||
result.lineEnd = i;
|
||||
result.nextStart = i;
|
||||
}
|
||||
return result;
|
||||
// Per-character pixel width check — catches long words that exceed
|
||||
// displayW without ever hitting a space/hyphen break point.
|
||||
// Only measure every 3 chars to avoid excessive getTextWidth() calls.
|
||||
if ((charCount & 3) == 0 || c == ' ' || c == '-') {
|
||||
measBuf[measLen] = '\0';
|
||||
int pw = display->getTextWidth(measBuf);
|
||||
if (pw >= displayW) {
|
||||
if (lastBreakPoint > lineStart) {
|
||||
// Break at last word boundary
|
||||
result.lineEnd = lastBreakPoint;
|
||||
result.nextStart = lastBreakPoint;
|
||||
while (result.nextStart < bufLen &&
|
||||
(buffer[result.nextStart] == ' ' || buffer[result.nextStart] == '\t'))
|
||||
result.nextStart++;
|
||||
} else {
|
||||
// No word boundary found — break mid-word before this character
|
||||
result.lineEnd = charStartIdx;
|
||||
result.nextStart = charStartIdx;
|
||||
}
|
||||
lastBreakPoint = i;
|
||||
inWord = false;
|
||||
return result;
|
||||
}
|
||||
} else if (c == '-') {
|
||||
if (inWord) {
|
||||
// Measure at hyphen break point
|
||||
measBuf[measLen] = '\0';
|
||||
int pw = display->getTextWidth(measBuf);
|
||||
if (pw >= displayW) {
|
||||
if (lastBreakPoint > lineStart) {
|
||||
result.lineEnd = lastBreakPoint;
|
||||
result.nextStart = lastBreakPoint;
|
||||
while (result.nextStart < bufLen &&
|
||||
(buffer[result.nextStart] == ' ' || buffer[result.nextStart] == '\t'))
|
||||
result.nextStart++;
|
||||
} else {
|
||||
result.lineEnd = i;
|
||||
result.nextStart = i;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
lastBreakPoint = i + 1;
|
||||
}
|
||||
inWord = true;
|
||||
} else {
|
||||
inWord = true;
|
||||
}
|
||||
|
||||
// Safety: hard char limit (handles spaceless lines, URLs, etc.)
|
||||
@@ -242,17 +243,25 @@ inline WrapResult findLineBreakPixel(const char* buffer, int bufLen, int lineSta
|
||||
|
||||
// ============================================================================
|
||||
// Page Indexer (word-wrap aware, matches display rendering)
|
||||
// When textAreaHeight and lineHeight are provided (both > 0), uses height-based
|
||||
// pagination that accounts for blank lines getting 40% height (matching renderer).
|
||||
// Otherwise falls back to simple line counting.
|
||||
// ============================================================================
|
||||
inline int indexPagesWordWrap(File& file, long startPos,
|
||||
std::vector<long>& pagePositions,
|
||||
int linesPerPage, int charsPerLine,
|
||||
int maxPages) {
|
||||
int maxPages,
|
||||
int textAreaHeight = 0, int lineHeight = 0) {
|
||||
const int BUF_SIZE = READER_BUF_SIZE; // Match page buffer to avoid chunk boundary wrap mismatches
|
||||
char buffer[BUF_SIZE];
|
||||
|
||||
bool heightAware = (textAreaHeight > 0 && lineHeight > 0);
|
||||
int blankLineH = heightAware ? max(2, lineHeight * 2 / 5) : 0;
|
||||
|
||||
file.seek(startPos);
|
||||
int pagesAdded = 0;
|
||||
int lineCount = 0;
|
||||
int accHeight = 0;
|
||||
int leftover = 0;
|
||||
long chunkFileStart = startPos;
|
||||
|
||||
@@ -263,17 +272,42 @@ inline int indexPagesWordWrap(File& file, long startPos,
|
||||
|
||||
int pos = 0;
|
||||
while (pos < bufLen) {
|
||||
int lineStart = pos;
|
||||
WrapResult wrap = findLineBreak(buffer, bufLen, pos, charsPerLine);
|
||||
if (wrap.nextStart <= pos && wrap.lineEnd >= bufLen) break;
|
||||
|
||||
lineCount++;
|
||||
// Blank line = newline at line start (no printable content before it)
|
||||
bool isBlankLine = (wrap.lineEnd == lineStart);
|
||||
|
||||
bool pageBreak = false;
|
||||
if (heightAware) {
|
||||
int thisH = isBlankLine ? blankLineH : lineHeight;
|
||||
// Check BEFORE adding: does this line fit on the current page?
|
||||
// The renderer checks y <= maxY before rendering each line,
|
||||
// so we must break the page BEFORE a line that won't fit.
|
||||
if (accHeight > 0 && accHeight + thisH > textAreaHeight) {
|
||||
// This line doesn't fit — start new page at this line's position
|
||||
long pageFilePos = chunkFileStart + lineStart;
|
||||
pagePositions.push_back(pageFilePos);
|
||||
pagesAdded++;
|
||||
accHeight = 0;
|
||||
if (maxPages > 0 && pagesAdded >= maxPages) break;
|
||||
}
|
||||
accHeight += thisH;
|
||||
} else {
|
||||
lineCount++;
|
||||
if (lineCount >= linesPerPage) {
|
||||
pageBreak = true;
|
||||
lineCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
pos = wrap.nextStart;
|
||||
|
||||
if (lineCount >= linesPerPage) {
|
||||
if (pageBreak) {
|
||||
long pageFilePos = chunkFileStart + pos;
|
||||
pagePositions.push_back(pageFilePos);
|
||||
pagesAdded++;
|
||||
lineCount = 0;
|
||||
if (maxPages > 0 && pagesAdded >= maxPages) break;
|
||||
}
|
||||
if (pos >= bufLen) break;
|
||||
@@ -298,12 +332,13 @@ inline int indexPagesWordWrap(File& file, long startPos,
|
||||
inline int indexPagesWordWrapPixel(File& file, long startPos,
|
||||
std::vector<long>& pagePositions,
|
||||
int linesPerPage, int maxChars,
|
||||
DisplayDriver* display, int maxPages) {
|
||||
DisplayDriver* display, int maxPages,
|
||||
NodePrefs* prefs = nullptr) {
|
||||
const int BUF_SIZE = READER_BUF_SIZE; // Match page buffer to avoid chunk boundary wrap mismatches
|
||||
char buffer[BUF_SIZE];
|
||||
|
||||
// Ensure body font is active for pixel measurement
|
||||
display->setTextSize(0);
|
||||
display->setTextSize(prefs ? prefs->smallTextSize() : 0);
|
||||
|
||||
file.seek(startPos);
|
||||
int pagesAdded = 0;
|
||||
@@ -367,9 +402,11 @@ public:
|
||||
|
||||
private:
|
||||
UITask* _task;
|
||||
NodePrefs* _prefs;
|
||||
Mode _mode;
|
||||
bool _sdReady;
|
||||
bool _initialized; // Layout metrics calculated
|
||||
uint8_t _lastFontPref; // Font preference at last layout init (detect changes)
|
||||
bool _bootIndexed; // Boot-time pre-indexing done
|
||||
DisplayDriver* _display; // Stored reference for splash screens
|
||||
|
||||
@@ -377,6 +414,7 @@ private:
|
||||
int _charsPerLine;
|
||||
int _linesPerPage;
|
||||
int _lineHeight; // virtual coord units per text line
|
||||
int _textAreaHeight; // usable height for text (excluding header/footer)
|
||||
int _headerHeight;
|
||||
int _footerHeight;
|
||||
|
||||
@@ -400,6 +438,11 @@ private:
|
||||
int _pageBufLen;
|
||||
bool _contentDirty; // Need to re-read from SD
|
||||
|
||||
// Go-to-page input mode (Enter in reading view)
|
||||
bool _gotoMode = false;
|
||||
char _gotoBuf[6]; // Up to 5 digits + null
|
||||
int _gotoBufLen = 0;
|
||||
|
||||
// ---- Splash Screen Drawing ----
|
||||
// Draw directly to display outside the normal render cycle.
|
||||
// Matches the style of the standalone text reader firmware splash.
|
||||
@@ -899,22 +942,14 @@ private:
|
||||
if (_pagePositions.empty()) {
|
||||
// Cache had no pages (e.g. dummy entry) — full index from scratch
|
||||
_pagePositions.push_back(0);
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
indexPagesWordWrapPixel(_file, 0, _pagePositions,
|
||||
_linesPerPage, _charsPerLine, _display, 0);
|
||||
#else
|
||||
indexPagesWordWrap(_file, 0, _pagePositions,
|
||||
_linesPerPage, _charsPerLine, 0);
|
||||
#endif
|
||||
_linesPerPage, _charsPerLine, 0,
|
||||
_textAreaHeight, _lineHeight);
|
||||
} else {
|
||||
long lastPos = cache->pagePositions.back();
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
indexPagesWordWrapPixel(_file, lastPos, _pagePositions,
|
||||
_linesPerPage, _charsPerLine, _display, 0);
|
||||
#else
|
||||
indexPagesWordWrap(_file, lastPos, _pagePositions,
|
||||
_linesPerPage, _charsPerLine, 0);
|
||||
#endif
|
||||
_linesPerPage, _charsPerLine, 0,
|
||||
_textAreaHeight, _lineHeight);
|
||||
}
|
||||
} else {
|
||||
// No cache — full index from scratch
|
||||
@@ -932,13 +967,9 @@ private:
|
||||
drawSplash("Indexing...", "Please wait", shortName);
|
||||
|
||||
_pagePositions.push_back(0);
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
indexPagesWordWrapPixel(_file, 0, _pagePositions,
|
||||
_linesPerPage, _charsPerLine, _display, 0);
|
||||
#else
|
||||
indexPagesWordWrap(_file, 0, _pagePositions,
|
||||
_linesPerPage, _charsPerLine, 0);
|
||||
#endif
|
||||
_linesPerPage, _charsPerLine, 0,
|
||||
_textAreaHeight, _lineHeight);
|
||||
}
|
||||
|
||||
// Save complete index
|
||||
@@ -1061,8 +1092,8 @@ private:
|
||||
display.setCursor(0, 42);
|
||||
display.print("/books/ on SD card");
|
||||
} else {
|
||||
display.setTextSize(0); // Tiny font for file list
|
||||
int listLineH = 8; // Approximate tiny font line height in virtual coords
|
||||
display.setTextSize(_prefs->smallTextSize()); // Tiny font for file list
|
||||
int listLineH = _prefs->smallLineH();
|
||||
int startY = 14;
|
||||
int maxVisible = (display.height() - startY - _footerHeight) / listLineH;
|
||||
if (maxVisible < 3) maxVisible = 3;
|
||||
@@ -1083,7 +1114,7 @@ private:
|
||||
#else
|
||||
// setCursor adds +5 to y internally, but fillRect does not.
|
||||
// Offset fillRect by +5 to align highlight bar with text.
|
||||
display.fillRect(0, y + 5, display.width(), listLineH);
|
||||
display.fillRect(0, y + _prefs->smallHighlightOff(), display.width(), listLineH);
|
||||
#endif
|
||||
display.setColor(DisplayDriver::DARK);
|
||||
} else {
|
||||
@@ -1091,8 +1122,6 @@ private:
|
||||
}
|
||||
|
||||
// Set cursor AFTER fillRect so text draws on top of highlight
|
||||
display.setCursor(0, y);
|
||||
|
||||
int type = itemTypeAt(i);
|
||||
String line = selected ? "> " : " ";
|
||||
|
||||
@@ -1102,10 +1131,6 @@ private:
|
||||
} else if (type == 1) {
|
||||
// Subdirectory
|
||||
line += "/" + dirNameAt(i);
|
||||
// Truncate if needed
|
||||
if ((int)line.length() > _charsPerLine) {
|
||||
line = line.substring(0, _charsPerLine - 3) + "...";
|
||||
}
|
||||
} else {
|
||||
// File
|
||||
int fi = fileIndexAt(i);
|
||||
@@ -1118,16 +1143,11 @@ private:
|
||||
suffix = " *";
|
||||
}
|
||||
}
|
||||
|
||||
// Truncate if needed
|
||||
int maxLen = _charsPerLine - 4 - suffix.length();
|
||||
if ((int)name.length() > maxLen) {
|
||||
name = name.substring(0, maxLen - 3) + "...";
|
||||
}
|
||||
line += name + suffix;
|
||||
}
|
||||
|
||||
display.print(line.c_str());
|
||||
// Pixel-aware ellipsis — small margin prevents GxEPD edge wrapping
|
||||
display.drawTextEllipsized(0, y, display.width() - 4, line.c_str());
|
||||
y += listLineH;
|
||||
}
|
||||
display.setTextSize(1); // Restore
|
||||
@@ -1140,13 +1160,13 @@ private:
|
||||
display.setColor(DisplayDriver::YELLOW);
|
||||
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
display.drawTextCentered(display.width() / 2, footerY, "Swipe: Scroll Tap: Open Boot: home");
|
||||
#else
|
||||
display.setCursor(0, footerY);
|
||||
display.print("Q:Back W/S:Nav");
|
||||
display.print("Q:Bk");
|
||||
|
||||
const char* right = "Ent:Open";
|
||||
const char* right = "Tap/Ent:Open";
|
||||
display.setCursor(display.width() - display.getTextWidth(right) - 2, footerY);
|
||||
display.print(right);
|
||||
#endif
|
||||
@@ -1154,7 +1174,7 @@ private:
|
||||
|
||||
void renderPage(DisplayDriver& display) {
|
||||
// Use tiny font for maximum text density
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
|
||||
int y = 0;
|
||||
@@ -1165,13 +1185,9 @@ private:
|
||||
// Render all lines in the page buffer using word wrap.
|
||||
// The buffer contains exactly the bytes for this page (from indexed positions),
|
||||
// so we render everything in it.
|
||||
while (pos < _pageBufLen && lineCount < _linesPerPage && y <= maxY) {
|
||||
while (pos < _pageBufLen && y <= maxY) {
|
||||
int oldPos = pos;
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
WrapResult wrap = findLineBreakPixel(_pageBuf, _pageBufLen, pos, &display, _charsPerLine);
|
||||
#else
|
||||
WrapResult wrap = findLineBreak(_pageBuf, _pageBufLen, pos, _charsPerLine);
|
||||
#endif
|
||||
|
||||
// Safety: stop if findLineBreak made no progress (stuck at end of buffer)
|
||||
if (wrap.nextStart <= oldPos && wrap.lineEnd >= _pageBufLen) break;
|
||||
@@ -1242,31 +1258,37 @@ private:
|
||||
|
||||
char status[30];
|
||||
int pct = _totalPages > 1 ? (_currentPage * 100) / (_totalPages - 1) : 100;
|
||||
sprintf(status, "%d/%d %d%%", _currentPage + 1, _totalPages, pct);
|
||||
|
||||
if (_gotoMode) {
|
||||
// Go-to-page input mode — show typed digits in footer
|
||||
snprintf(status, sizeof(status), "Go to: %.*s_", _gotoBufLen, _gotoBuf);
|
||||
} else {
|
||||
sprintf(status, "%d/%d %d%%", _currentPage + 1, _totalPages, pct);
|
||||
}
|
||||
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
display.setCursor(0, footerY);
|
||||
display.print(status);
|
||||
const char* right = "Swipe: Page Tap: Next Hold: Close";
|
||||
const char* right = "Swipe:Page Tap:GoTo Hold:Close";
|
||||
display.setCursor(display.width() - display.getTextWidth(right) - 2, footerY);
|
||||
display.print(right);
|
||||
#else
|
||||
display.setCursor(0, footerY);
|
||||
display.print(status);
|
||||
|
||||
const char* right = "W/S:Nav Q:Back";
|
||||
const char* right = _gotoMode ? "Ent:Go Q:Cancel" : "Entr:Pg# Q:Bk";
|
||||
display.setCursor(display.width() - display.getTextWidth(right) - 2, footerY);
|
||||
display.print(right);
|
||||
#endif
|
||||
}
|
||||
|
||||
public:
|
||||
TextReaderScreen(UITask* task)
|
||||
: _task(task), _mode(FILE_LIST), _sdReady(false), _initialized(false),
|
||||
TextReaderScreen(UITask* task, NodePrefs* prefs = nullptr)
|
||||
: _task(task), _prefs(prefs), _mode(FILE_LIST), _sdReady(false), _initialized(false), _lastFontPref(0),
|
||||
_bootIndexed(false), _display(nullptr),
|
||||
_charsPerLine(38), _linesPerPage(22), _lineHeight(5),
|
||||
_headerHeight(14), _footerHeight(14),
|
||||
_textAreaHeight(100), _headerHeight(14), _footerHeight(14),
|
||||
_selectedFile(0), _currentPath(BOOKS_FOLDER),
|
||||
_fileOpen(false), _currentPage(0), _totalPages(0),
|
||||
_pageBufLen(0), _contentDirty(true) {
|
||||
@@ -1288,25 +1310,53 @@ public:
|
||||
|
||||
// Call once after display is available to calculate layout metrics
|
||||
void initLayout(DisplayDriver& display) {
|
||||
// Re-init if font preference changed since last layout
|
||||
uint8_t curFont = _prefs ? _prefs->large_font : 0;
|
||||
if (_initialized && curFont != _lastFontPref) {
|
||||
_initialized = false;
|
||||
Serial.println("TextReader: font changed, recalculating layout");
|
||||
}
|
||||
if (_initialized) return;
|
||||
_lastFontPref = curFont;
|
||||
|
||||
// Store display reference for splash screens during openBook
|
||||
_display = &display;
|
||||
|
||||
// Measure tiny font metrics using the display driver
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
|
||||
// Measure character width: use 10 M's to get accurate average
|
||||
// Measure character width: use 10 M's for monospace (T-Deck Pro tiny font).
|
||||
// Proportional fonts (T5S3 and T-Deck Pro large_font) override below with
|
||||
// average-width measurement since M is the widest glyph (~40% wider than average).
|
||||
uint16_t tenCharsW = display.getTextWidth("MMMMMMMMMM");
|
||||
if (tenCharsW > 0) {
|
||||
_charsPerLine = (display.width() * 10) / tenCharsW;
|
||||
}
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
// T5S3 uses pixel-based line breaking (findLineBreakPixel) which measures
|
||||
// actual text width via getTextWidth(). _charsPerLine serves only as a
|
||||
// safety upper bound for lines without word breaks (URLs, etc.).
|
||||
_charsPerLine = 120;
|
||||
// T5S3 uses proportional font (FreeSans12pt) — measure average character
|
||||
// width from a representative English sample. M-based measurement is far
|
||||
// too conservative (M is the widest glyph), leaving half the line empty.
|
||||
{
|
||||
const char* sample = "the quick brown fox jumps over lazy dog";
|
||||
uint16_t sampleW = display.getTextWidth(sample);
|
||||
int sampleLen = strlen(sample);
|
||||
if (sampleW > 0 && sampleLen > 0) {
|
||||
// 95% factor as small safety margin for slightly-wider-than-average text
|
||||
_charsPerLine = (display.width() * sampleLen * 95) / ((int)sampleW * 100);
|
||||
}
|
||||
}
|
||||
if (_charsPerLine < 15) _charsPerLine = 15;
|
||||
if (_charsPerLine > 80) _charsPerLine = 80;
|
||||
#else
|
||||
// T-Deck Pro: large_font uses FreeSans9pt (proportional) — same fix
|
||||
if (_prefs && _prefs->large_font) {
|
||||
const char* sample = "the quick brown fox jumps over lazy dog";
|
||||
uint16_t sampleW = display.getTextWidth(sample);
|
||||
int sampleLen = strlen(sample);
|
||||
if (sampleW > 0 && sampleLen > 0) {
|
||||
_charsPerLine = (display.width() * sampleLen * 70) / ((int)sampleW * 100);
|
||||
}
|
||||
}
|
||||
if (_charsPerLine < 15) _charsPerLine = 15;
|
||||
if (_charsPerLine > 60) _charsPerLine = 60;
|
||||
#endif
|
||||
@@ -1326,33 +1376,138 @@ public:
|
||||
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
// T5S3 uses FreeSans12pt/FreeSerif12pt for size 0 (yAdvance=29px).
|
||||
// Line height in virtual coords depends on orientation:
|
||||
// Landscape: 29px / scale_y(4.22) ≈ 7 + 1 spacing = 8
|
||||
// Portrait: 29px / scale_y(7.50) ≈ 4 + 1 spacing = 5
|
||||
{
|
||||
extern DISPLAY_CLASS display;
|
||||
_lineHeight = display.isPortraitMode() ? 5 : 8;
|
||||
}
|
||||
#else
|
||||
// T-Deck Pro large_font uses FreeSans9pt (yAdvance=22px at scale 1.5625×).
|
||||
// The 6x8 formula above gives ~5-7 which is way too small — lines overlap.
|
||||
// Use smallLineH() which is already tuned for this font.
|
||||
if (_prefs && _prefs->large_font) {
|
||||
_lineHeight = _prefs->smallLineH();
|
||||
}
|
||||
#endif
|
||||
|
||||
_headerHeight = 0; // No header in reading mode (maximize text area)
|
||||
_footerHeight = 14;
|
||||
int textAreaHeight = display.height() - _headerHeight - _footerHeight;
|
||||
_linesPerPage = textAreaHeight / _lineHeight;
|
||||
_textAreaHeight = display.height() - _headerHeight - _footerHeight;
|
||||
_linesPerPage = _textAreaHeight / _lineHeight;
|
||||
if (_linesPerPage < 5) _linesPerPage = 5;
|
||||
if (_linesPerPage > 40) _linesPerPage = 40;
|
||||
|
||||
display.setTextSize(1); // Restore
|
||||
_initialized = true;
|
||||
|
||||
Serial.printf("TextReader layout: %d chars/line, %d lines/page, lineH=%d (display %dx%d)\n",
|
||||
_charsPerLine, _linesPerPage, _lineHeight, display.width(), display.height());
|
||||
Serial.printf("TextReader layout: %d chars/line, %d lines/page, lineH=%d, textH=%d (display %dx%d)\n",
|
||||
_charsPerLine, _linesPerPage, _lineHeight, _textAreaHeight, display.width(), display.height());
|
||||
}
|
||||
|
||||
// ---- Boot-time Indexing ----
|
||||
// Called from setup() after SD card init. Scans files, pre-indexes first
|
||||
// 100 pages of each, and shows progress on the e-ink display.
|
||||
|
||||
// Pre-index files inside one level of subdirectories so navigating
|
||||
// into them later is instant (idx files already on SD).
|
||||
void bootIndexSubfolders() {
|
||||
// Work from the root-level _dirList that scanFiles() already populated.
|
||||
// Copy it -- scanFiles() will overwrite _dirList when we scan each subfolder.
|
||||
std::vector<String> subDirs = _dirList;
|
||||
if (subDirs.empty()) return;
|
||||
|
||||
Serial.printf("TextReader: Pre-indexing %d subfolders\n", (int)subDirs.size());
|
||||
|
||||
int totalSubFiles = 0;
|
||||
int cachedSubFiles = 0;
|
||||
int indexedSubFiles = 0;
|
||||
|
||||
for (int d = 0; d < (int)subDirs.size(); d++) {
|
||||
String subPath = String(BOOKS_FOLDER) + "/" + subDirs[d];
|
||||
_currentPath = subPath;
|
||||
scanFiles(); // populates _fileList for this subfolder
|
||||
|
||||
// Also pick up previously converted EPUB cache files for this subfolder
|
||||
String epubCachePath = subPath + "/.epub_cache";
|
||||
if (SD.exists(epubCachePath.c_str())) {
|
||||
File cacheDir = SD.open(epubCachePath.c_str());
|
||||
if (cacheDir && cacheDir.isDirectory()) {
|
||||
File cf = cacheDir.openNextFile();
|
||||
while (cf && _fileList.size() < READER_MAX_FILES) {
|
||||
if (!cf.isDirectory()) {
|
||||
String cname = String(cf.name());
|
||||
int cslash = cname.lastIndexOf('/');
|
||||
if (cslash >= 0) cname = cname.substring(cslash + 1);
|
||||
if (cname.endsWith(".txt") || cname.endsWith(".TXT")) {
|
||||
bool dup = false;
|
||||
for (int k = 0; k < (int)_fileList.size(); k++) {
|
||||
if (_fileList[k] == cname) { dup = true; break; }
|
||||
}
|
||||
if (!dup) _fileList.push_back(cname);
|
||||
}
|
||||
}
|
||||
cf = cacheDir.openNextFile();
|
||||
}
|
||||
cacheDir.close();
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < (int)_fileList.size(); i++) {
|
||||
totalSubFiles++;
|
||||
|
||||
// Try loading existing .idx cache -- if hit, skip
|
||||
FileCache tempCache;
|
||||
if (loadIndex(_fileList[i], tempCache)) {
|
||||
cachedSubFiles++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip .epub files (converted on first open)
|
||||
if (_fileList[i].endsWith(".epub") || _fileList[i].endsWith(".EPUB")) continue;
|
||||
|
||||
// Index this .txt file
|
||||
String fullPath = _currentPath + "/" + _fileList[i];
|
||||
File file = SD.open(fullPath.c_str(), FILE_READ);
|
||||
if (!file) {
|
||||
// Try epub cache fallback
|
||||
String cacheFallback = epubCachePath + "/" + _fileList[i];
|
||||
file = SD.open(cacheFallback.c_str(), FILE_READ);
|
||||
}
|
||||
if (!file) continue;
|
||||
|
||||
indexedSubFiles++;
|
||||
String displayName = subDirs[d] + "/" + _fileList[i];
|
||||
drawBootSplash(indexedSubFiles, 0, displayName);
|
||||
|
||||
FileCache cache;
|
||||
cache.filename = _fileList[i];
|
||||
cache.fileSize = file.size();
|
||||
cache.fullyIndexed = false;
|
||||
cache.lastReadPage = 0;
|
||||
cache.pagePositions.clear();
|
||||
cache.pagePositions.push_back(0);
|
||||
|
||||
indexPagesWordWrap(file, 0, cache.pagePositions,
|
||||
_linesPerPage, _charsPerLine,
|
||||
PREINDEX_PAGES - 1,
|
||||
_textAreaHeight, _lineHeight);
|
||||
cache.fullyIndexed = !file.available();
|
||||
file.close();
|
||||
|
||||
saveIndex(cache.filename, cache.pagePositions, cache.fileSize,
|
||||
cache.fullyIndexed, 0);
|
||||
|
||||
Serial.printf("TextReader: %s/%s - indexed %d pages%s\n",
|
||||
subDirs[d].c_str(), _fileList[i].c_str(),
|
||||
(int)cache.pagePositions.size(),
|
||||
cache.fullyIndexed ? " (complete)" : "");
|
||||
yield(); // Feed WDT between files
|
||||
}
|
||||
}
|
||||
|
||||
Serial.printf("TextReader: Subfolder pre-index: %d files (%d cached, %d newly indexed)\n",
|
||||
totalSubFiles, cachedSubFiles, indexedSubFiles);
|
||||
}
|
||||
|
||||
void bootIndex(DisplayDriver& display) {
|
||||
if (!_sdReady) return;
|
||||
|
||||
@@ -1394,20 +1549,24 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
if (_fileList.size() == 0) {
|
||||
Serial.println("TextReader: No files to index");
|
||||
if (_fileList.size() == 0 && _dirList.size() == 0) {
|
||||
Serial.println("TextReader: No files or folders to index");
|
||||
_bootIndexed = true;
|
||||
return;
|
||||
}
|
||||
|
||||
int cachedCount = 0;
|
||||
int needsIndexCount = 0;
|
||||
|
||||
// --- Pass 1 & 2: Index root-level files ---
|
||||
if (_fileList.size() > 0) {
|
||||
|
||||
// --- Pass 1: Fast cache load (no per-file splash screens) ---
|
||||
// Try to load existing .idx files from SD for every file.
|
||||
// This is just SD reads — no indexing, no e-ink refreshes.
|
||||
_fileCache.clear();
|
||||
_fileCache.resize(_fileList.size()); // Pre-allocate slots to maintain alignment with _fileList
|
||||
|
||||
int cachedCount = 0;
|
||||
int needsIndexCount = 0;
|
||||
|
||||
for (int i = 0; i < (int)_fileList.size(); i++) {
|
||||
if (loadIndex(_fileList[i], _fileCache[i])) {
|
||||
@@ -1457,15 +1616,10 @@ public:
|
||||
cache.pagePositions.clear();
|
||||
cache.pagePositions.push_back(0);
|
||||
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
int added = indexPagesWordWrapPixel(file, 0, cache.pagePositions,
|
||||
_linesPerPage, _charsPerLine,
|
||||
_display, PREINDEX_PAGES - 1);
|
||||
#else
|
||||
int added = indexPagesWordWrap(file, 0, cache.pagePositions,
|
||||
_linesPerPage, _charsPerLine,
|
||||
PREINDEX_PAGES - 1);
|
||||
#endif
|
||||
PREINDEX_PAGES - 1,
|
||||
_textAreaHeight, _lineHeight);
|
||||
cache.fullyIndexed = !file.available();
|
||||
file.close();
|
||||
|
||||
@@ -1478,6 +1632,26 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
} // end if (_fileList.size() > 0)
|
||||
|
||||
// --- Pass 3: Pre-index files inside subfolders (one level deep) ---
|
||||
// Save root state -- bootIndexSubfolders() will overwrite _fileList/_dirList
|
||||
// via scanFiles() as it iterates each subdirectory.
|
||||
if (_dirList.size() > 0) {
|
||||
std::vector<String> savedFileList = _fileList;
|
||||
std::vector<String> savedDirList = _dirList;
|
||||
std::vector<FileCache> savedFileCache = _fileCache;
|
||||
|
||||
bootIndexSubfolders();
|
||||
|
||||
// Restore root state
|
||||
_currentPath = String(BOOKS_FOLDER);
|
||||
_fileList = savedFileList;
|
||||
_dirList = savedDirList;
|
||||
_fileCache = savedFileCache;
|
||||
}
|
||||
|
||||
|
||||
// Deselect SD to free SPI bus
|
||||
digitalWrite(SDCARD_CS, HIGH);
|
||||
|
||||
@@ -1508,13 +1682,9 @@ public:
|
||||
// Layout was invalidated (orientation change) — reindex the open book
|
||||
Serial.println("TextReader: Reindexing after layout change");
|
||||
_pagePositions.push_back(0);
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
indexPagesWordWrapPixel(_file, 0, _pagePositions,
|
||||
_linesPerPage, _charsPerLine, _display, 0);
|
||||
#else
|
||||
indexPagesWordWrap(_file, 0, _pagePositions,
|
||||
_linesPerPage, _charsPerLine, 0);
|
||||
#endif
|
||||
_linesPerPage, _charsPerLine, 0,
|
||||
_textAreaHeight, _lineHeight);
|
||||
_totalPages = _pagePositions.size();
|
||||
if (_currentPage >= _totalPages) _currentPage = 0;
|
||||
_mode = READING;
|
||||
@@ -1529,6 +1699,49 @@ public:
|
||||
bool isReading() const { return _mode == READING; }
|
||||
bool isInFileList() const { return _mode == FILE_LIST; }
|
||||
|
||||
// Jump to a specific page number (1-based for user-facing, converted to 0-based)
|
||||
void gotoPage(int pageNum) {
|
||||
if (!_fileOpen || _totalPages == 0) return;
|
||||
int target = pageNum - 1; // Convert 1-based input to 0-based
|
||||
if (target < 0) target = 0;
|
||||
if (target >= _totalPages) target = _totalPages - 1;
|
||||
_currentPage = target;
|
||||
loadPageContent();
|
||||
Serial.printf("TextReader: Go to page %d/%d\n", _currentPage + 1, _totalPages);
|
||||
}
|
||||
|
||||
int getTotalPages() const { return _totalPages; }
|
||||
int getCurrentPage() const { return _currentPage; }
|
||||
|
||||
// Tap-to-select: given virtual Y, select file list row.
|
||||
// Returns: 0=miss, 1=moved, 2=tapped current row.
|
||||
int selectRowAtVY(int vy) {
|
||||
if (_mode != FILE_LIST) return 0;
|
||||
const int startY = 14, footerH = 14;
|
||||
const int listLineH = _prefs ? _prefs->smallLineH() : 9;
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
const int bodyTop = startY;
|
||||
#else
|
||||
const int bodyTop = startY + (_prefs ? _prefs->smallHighlightOff() : 5);
|
||||
#endif
|
||||
if (vy < bodyTop || vy >= 128 - footerH) return 0;
|
||||
|
||||
int totalItems = totalListItems();
|
||||
if (totalItems == 0) return 0;
|
||||
int maxVisible = (128 - startY - footerH) / listLineH;
|
||||
if (maxVisible < 3) maxVisible = 3;
|
||||
if (maxVisible > 15) maxVisible = 15;
|
||||
int startIdx = max(0, min(_selectedFile - maxVisible / 2,
|
||||
totalItems - maxVisible));
|
||||
|
||||
int tappedRow = startIdx + (vy - bodyTop) / listLineH;
|
||||
if (tappedRow < 0 || tappedRow >= totalItems) return 0;
|
||||
|
||||
if (tappedRow == _selectedFile) return 2;
|
||||
_selectedFile = tappedRow;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int render(DisplayDriver& display) override {
|
||||
if (!_sdReady) {
|
||||
display.setCursor(0, 20);
|
||||
@@ -1553,6 +1766,7 @@ public:
|
||||
if (_mode == FILE_LIST) {
|
||||
return handleFileListInput(c);
|
||||
} else if (_mode == READING) {
|
||||
if (_gotoMode) return handleGotoInput(c);
|
||||
return handleReadingInput(c);
|
||||
}
|
||||
return false;
|
||||
@@ -1639,15 +1853,10 @@ public:
|
||||
cache.lastReadPage = 0;
|
||||
cache.pagePositions.clear();
|
||||
cache.pagePositions.push_back(0);
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
indexPagesWordWrapPixel(file, 0, cache.pagePositions,
|
||||
_linesPerPage, _charsPerLine,
|
||||
_display, PREINDEX_PAGES - 1);
|
||||
#else
|
||||
indexPagesWordWrap(file, 0, cache.pagePositions,
|
||||
_linesPerPage, _charsPerLine,
|
||||
PREINDEX_PAGES - 1);
|
||||
#endif
|
||||
PREINDEX_PAGES - 1,
|
||||
_textAreaHeight, _lineHeight);
|
||||
cache.fullyIndexed = !file.available();
|
||||
file.close();
|
||||
saveIndex(cache.filename, cache.pagePositions, cache.fileSize,
|
||||
@@ -1673,9 +1882,9 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
// S/D/Space/Enter - next page
|
||||
// S/D/Space - next page
|
||||
if (c == 's' || c == 'S' || c == 'd' || c == 'D' ||
|
||||
c == ' ' || c == '\r' || c == 13 || c == 0xF1) {
|
||||
c == ' ' || c == 0xF1) {
|
||||
if (_currentPage < _totalPages - 1) {
|
||||
_currentPage++;
|
||||
loadPageContent();
|
||||
@@ -1684,6 +1893,14 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
// Enter - go-to-page input mode
|
||||
if (c == '\r' || c == 13) {
|
||||
_gotoMode = true;
|
||||
_gotoBufLen = 0;
|
||||
_gotoBuf[0] = '\0';
|
||||
return true;
|
||||
}
|
||||
|
||||
// Q - close book, back to file list
|
||||
if (c == 'q' || c == 'Q') {
|
||||
closeBook();
|
||||
@@ -1694,9 +1911,83 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
bool handleGotoInput(char c) {
|
||||
// Enter — commit page number
|
||||
if (c == '\r' || c == 13) {
|
||||
if (_gotoBufLen > 0) {
|
||||
int pageNum = atoi(_gotoBuf);
|
||||
gotoPage(pageNum);
|
||||
}
|
||||
_gotoMode = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Q or Escape — cancel
|
||||
if (c == 'q' || c == 'Q' || c == 0x1B) {
|
||||
_gotoMode = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Backspace — delete last digit
|
||||
if (c == '\b' || c == 0x7F) {
|
||||
if (_gotoBufLen > 0) {
|
||||
_gotoBufLen--;
|
||||
_gotoBuf[_gotoBufLen] = '\0';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Digit — append (max 5 digits)
|
||||
if (c >= '0' && c <= '9' && _gotoBufLen < 5) {
|
||||
_gotoBuf[_gotoBufLen++] = c;
|
||||
_gotoBuf[_gotoBufLen] = '\0';
|
||||
return true;
|
||||
}
|
||||
|
||||
return true; // Consume all other keys while in goto mode
|
||||
}
|
||||
|
||||
// External close (called when leaving reader screen entirely)
|
||||
void exitReader() {
|
||||
if (_fileOpen) closeBook();
|
||||
_mode = FILE_LIST;
|
||||
}
|
||||
};
|
||||
};
|
||||
#else // !ESP32
|
||||
|
||||
// Non-ESP32 stub: Meshpocket / T-Echo Card have no SD card hardware, so the
|
||||
// full EPUB/text reader can't work here. This stub keeps UITask.cpp and
|
||||
// main.cpp compilable by providing the same public interface as no-ops.
|
||||
// Navigating to the reader on a non-SD board just shows a placeholder.
|
||||
class TextReaderScreen : public UIScreen {
|
||||
public:
|
||||
TextReaderScreen(UITask* task, NodePrefs* prefs = nullptr) {
|
||||
(void)task; (void)prefs;
|
||||
}
|
||||
|
||||
int render(DisplayDriver& display) override {
|
||||
display.setTextSize(1);
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.setCursor(0, 20);
|
||||
display.print("Reader: SD card required");
|
||||
display.setCursor(0, 30);
|
||||
display.print("(not available)");
|
||||
return 5000;
|
||||
}
|
||||
|
||||
bool handleInput(char c) override { (void)c; return false; }
|
||||
|
||||
// No-op public API matching the ESP32 class for call-site compatibility
|
||||
void invalidateLayout() {}
|
||||
void bootIndex(DisplayDriver& display) { (void)display; }
|
||||
void setSDReady(bool ready) { (void)ready; }
|
||||
void enter(DisplayDriver& display) { (void)display; }
|
||||
bool isReading() const { return false; }
|
||||
bool isInFileList() const { return false; }
|
||||
void gotoPage(int pageNum) { (void)pageNum; }
|
||||
int getTotalPages() const { return 0; }
|
||||
int selectRowAtVY(int vy) { (void)vy; return -1; }
|
||||
void exitReader() {}
|
||||
};
|
||||
|
||||
#endif // ESP32
|
||||
File diff suppressed because it is too large
Load Diff
@@ -30,6 +30,10 @@
|
||||
#include "WebReaderScreen.h"
|
||||
#endif
|
||||
|
||||
#ifdef MECK_AUDIO_VARIANT
|
||||
#include "AlarmScreen.h"
|
||||
#endif
|
||||
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
#include "VirtualKeyboard.h"
|
||||
#endif
|
||||
@@ -56,6 +60,9 @@ class UITask : public AbstractUITask {
|
||||
NodePrefs* _node_prefs;
|
||||
char _alert[80];
|
||||
unsigned long _alert_expiry;
|
||||
bool _hintActive = false; // Boot navigation hint overlay
|
||||
unsigned long _hintExpiry = 0; // Auto-dismiss time for hint
|
||||
bool _pendingBootHint = false; // Deferred hint — show after splash screen
|
||||
int _msgcount;
|
||||
unsigned long ui_started_at, next_batt_chck;
|
||||
uint8_t _low_batt_count = 0; // Consecutive low-voltage readings for debounce
|
||||
@@ -72,18 +79,26 @@ class UITask : public AbstractUITask {
|
||||
|
||||
UIScreen* splash;
|
||||
UIScreen* home;
|
||||
#ifndef HELTEC_MESH_POCKET
|
||||
UIScreen* msg_preview;
|
||||
#endif
|
||||
UIScreen* channel_screen; // Channel message history screen
|
||||
UIScreen* contacts_screen; // Contacts list screen
|
||||
UIScreen* text_reader; // *** NEW: Text reader screen ***
|
||||
UIScreen* notes_screen; // Notes editor screen
|
||||
UIScreen* settings_screen; // Settings/onboarding screen
|
||||
UIScreen* audiobook_screen; // Audiobook player screen (null if not available)
|
||||
#ifdef MECK_AUDIO_VARIANT
|
||||
UIScreen* alarm_screen; // Alarm clock screen (audio variant only)
|
||||
UIScreen* voice_screen; // Voice message screen (audio variant only)
|
||||
#endif
|
||||
#ifdef HAS_4G_MODEM
|
||||
UIScreen* sms_screen; // SMS messaging screen (4G variant only)
|
||||
#endif
|
||||
UIScreen* repeater_admin; // Repeater admin screen
|
||||
UIScreen* path_editor; // Custom path editor screen (lazy-init)
|
||||
UIScreen* discovery_screen; // Node discovery scan screen
|
||||
UIScreen* last_heard_screen; // Last heard passive advert list
|
||||
#ifdef MECK_WEB_READER
|
||||
UIScreen* web_reader; // Web reader screen (lazy-init, WiFi required)
|
||||
#endif
|
||||
@@ -95,12 +110,50 @@ class UITask : public AbstractUITask {
|
||||
UIScreen* lock_screen; // Lock screen (big clock + battery + unread)
|
||||
UIScreen* _screenBeforeLock = nullptr;
|
||||
bool _locked = false;
|
||||
unsigned long _lastInputMillis = 0; // Auto-lock idle tracking
|
||||
unsigned long _lastLockRefresh = 0; // Periodic lock screen clock update
|
||||
|
||||
VirtualKeyboard _vkb;
|
||||
bool _vkbActive = false;
|
||||
UIScreen* _screenBeforeVKB = nullptr;
|
||||
unsigned long _vkbOpenedAt = 0;
|
||||
|
||||
// Powersaving: light sleep when locked + idle (standalone only — no BLE/WiFi)
|
||||
// Wakes on LoRa packet (DIO1), boot button (GPIO0), or 30-min timer
|
||||
#if !defined(BLE_PIN_CODE) && !defined(MECK_WIFI_COMPANION)
|
||||
unsigned long _psLastActive = 0; // millis() at last wake or lock entry
|
||||
unsigned long _psNextSleepSecs = 60; // Seconds before first sleep (60s), then 5s cycles
|
||||
#endif
|
||||
#ifdef MECK_CARDKB
|
||||
bool _cardkbDetected = false;
|
||||
#endif
|
||||
#elif defined(LilyGo_TDeck_Pro)
|
||||
UIScreen* lock_screen; // Lock screen (big clock + battery + unread)
|
||||
UIScreen* _screenBeforeLock = nullptr;
|
||||
bool _locked = false;
|
||||
unsigned long _lastInputMillis = 0; // Auto-lock idle tracking
|
||||
unsigned long _lastLockRefresh = 0; // Periodic lock screen clock update
|
||||
#endif
|
||||
|
||||
// --- Message dedup ring buffer (suppress retry spam at UI level) ---
|
||||
#define MSG_DEDUP_SIZE 8
|
||||
#define MSG_DEDUP_WINDOW_MS 60000 // 60 seconds
|
||||
struct MsgDedup {
|
||||
uint32_t name_hash;
|
||||
uint32_t text_hash;
|
||||
unsigned long millis;
|
||||
};
|
||||
MsgDedup _dedup[MSG_DEDUP_SIZE];
|
||||
int _dedupIdx = 0;
|
||||
|
||||
// --- Per-contact DM unread tracking ---
|
||||
uint8_t* _dmUnread = nullptr; // PSRAM-allocated, MAX_CONTACTS entries
|
||||
|
||||
static uint32_t simpleHash(const char* s) {
|
||||
uint32_t h = 5381;
|
||||
while (*s) { h = ((h << 5) + h) ^ (uint8_t)*s++; }
|
||||
return h;
|
||||
}
|
||||
|
||||
void userLedHandler();
|
||||
|
||||
@@ -129,14 +182,23 @@ public:
|
||||
|
||||
void gotoHomeScreen();
|
||||
void gotoChannelScreen(); // Navigate to channel message screen
|
||||
void gotoDMTab(); // Navigate directly to DM tab on channel screen
|
||||
void gotoDMConversation(const char* contactName, int contactIdx = -1, uint8_t perms = 0);
|
||||
void gotoContactsScreen(); // Navigate to contacts list
|
||||
void gotoTextReader(); // *** NEW: Navigate to text reader ***
|
||||
void gotoNotesScreen(); // Navigate to notes editor
|
||||
void gotoSettingsScreen(); // Navigate to settings
|
||||
void gotoOnboarding(); // Navigate to settings in onboarding mode
|
||||
void gotoAudiobookPlayer(); // Navigate to audiobook player
|
||||
#ifdef MECK_AUDIO_VARIANT
|
||||
void gotoAlarmScreen(); // Navigate to alarm clock
|
||||
void gotoVoiceScreen(); // Navigate to voice message recorder
|
||||
#endif
|
||||
void gotoRepeaterAdmin(int contactIdx); // Navigate to repeater admin
|
||||
void gotoRepeaterAdminDirect(int contactIdx); // Auto-login admin (L key from conversation)
|
||||
void gotoPathEditor(int contactIdx); // Navigate to custom path editor
|
||||
void gotoDiscoveryScreen(); // Navigate to node discovery scan
|
||||
void gotoLastHeardScreen(); // Navigate to last heard passive list
|
||||
#if HAS_GPS
|
||||
void gotoMapScreen(); // Navigate to map tile screen
|
||||
#endif
|
||||
@@ -150,6 +212,9 @@ public:
|
||||
#endif
|
||||
void showAlert(const char* text, int duration_millis) override;
|
||||
void forceRefresh() override { _next_refresh = 100; }
|
||||
void showBootHint(bool immediate = false); // Show navigation hint overlay on first boot
|
||||
void dismissBootHint(); // Dismiss hint and save preference
|
||||
bool isHintActive() const { return _hintActive; }
|
||||
// Wake display and extend auto-off timer. Call this when handling keys
|
||||
// outside of injectKey() to prevent display auto-off during direct input.
|
||||
void keepAlive() {
|
||||
@@ -158,6 +223,14 @@ public:
|
||||
}
|
||||
int getMsgCount() const { return _msgcount; }
|
||||
int getUnreadMsgCount() const; // Per-channel unread tracking (standalone)
|
||||
|
||||
// Per-contact DM unread tracking
|
||||
bool hasDMUnread(int contactIdx) const;
|
||||
int getDMUnreadCount(int contactIdx) const;
|
||||
void clearDMUnread(int contactIdx);
|
||||
|
||||
// Flag: suppress room→conversation redirect on next login (L key admin access)
|
||||
bool _skipRoomRedirect = false;
|
||||
bool hasDisplay() const { return _display != NULL; }
|
||||
bool isButtonPressed() const;
|
||||
bool isOnChannelScreen() const { return curr == channel_screen; }
|
||||
@@ -171,19 +244,32 @@ public:
|
||||
bool isOnNotesScreen() const { return curr == notes_screen; }
|
||||
bool isOnSettingsScreen() const { return curr == settings_screen; }
|
||||
bool isOnAudiobookPlayer() const { return curr == audiobook_screen; }
|
||||
#ifdef MECK_AUDIO_VARIANT
|
||||
bool isOnAlarmScreen() const { return curr == alarm_screen; }
|
||||
bool isOnVoiceScreen() const { return curr == voice_screen; }
|
||||
#endif
|
||||
bool isOnRepeaterAdmin() const { return curr == repeater_admin; }
|
||||
bool isOnPathEditor() const { return curr == path_editor; }
|
||||
bool isOnDiscoveryScreen() const { return curr == discovery_screen; }
|
||||
bool isOnLastHeardScreen() const { return curr == last_heard_screen; }
|
||||
bool isOnMapScreen() const { return curr == map_screen; }
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro) || defined(LilyGo_TDeck_Pro)
|
||||
bool isLocked() const { return _locked; }
|
||||
void lockScreen();
|
||||
void unlockScreen();
|
||||
#endif
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
bool isVKBActive() const { return _vkbActive; }
|
||||
unsigned long vkbOpenedAt() const { return _vkbOpenedAt; }
|
||||
VirtualKeyboard& getVKB() { return _vkb; }
|
||||
void showVirtualKeyboard(VKBPurpose purpose, const char* label, const char* initial, int maxLen, int contextIdx = 0);
|
||||
void onVKBSubmit();
|
||||
void onVKBCancel();
|
||||
#ifdef MECK_CARDKB
|
||||
void setCardKBDetected(bool v) { _cardkbDetected = v; }
|
||||
bool hasCardKB() const { return _cardkbDetected; }
|
||||
void feedCardKBChar(char c);
|
||||
#endif
|
||||
#endif
|
||||
#ifdef MECK_WEB_READER
|
||||
bool isOnWebReader() const { return curr == web_reader; }
|
||||
@@ -202,12 +288,15 @@ public:
|
||||
|
||||
// Check if home screen is in an editing mode (e.g. UTC offset editor)
|
||||
bool isEditingHomeScreen() const;
|
||||
// Check if home screen is showing the Recent Adverts page
|
||||
bool isHomeOnRecentPage() const;
|
||||
|
||||
// Inject a key press from external source (e.g., keyboard)
|
||||
void injectKey(char c);
|
||||
|
||||
// Add a sent message to the channel screen history
|
||||
void addSentChannelMessage(uint8_t channel_idx, const char* sender, const char* text) override;
|
||||
void addSentDM(const char* recipientName, const char* sender, const char* text);
|
||||
|
||||
// Mark channel as read when BLE companion app syncs messages
|
||||
void markChannelReadFromBLE(uint8_t channel_idx) override;
|
||||
@@ -219,16 +308,27 @@ public:
|
||||
|
||||
// Get current screen for checking state
|
||||
UIScreen* getCurrentScreen() const { return curr; }
|
||||
#ifndef HELTEC_MESH_POCKET
|
||||
UIScreen* getMsgPreviewScreen() const { return msg_preview; }
|
||||
#endif
|
||||
UIScreen* getTextReaderScreen() const { return text_reader; } // *** NEW ***
|
||||
UIScreen* getNotesScreen() const { return notes_screen; }
|
||||
UIScreen* getContactsScreen() const { return contacts_screen; }
|
||||
UIScreen* getChannelScreen() const { return channel_screen; }
|
||||
UIScreen* getSettingsScreen() const { return settings_screen; }
|
||||
NodePrefs* getNodePrefs() const { return _node_prefs; }
|
||||
UIScreen* getAudiobookScreen() const { return audiobook_screen; }
|
||||
void setAudiobookScreen(UIScreen* s) { audiobook_screen = s; }
|
||||
#ifdef MECK_AUDIO_VARIANT
|
||||
UIScreen* getAlarmScreen() const { return alarm_screen; }
|
||||
void setAlarmScreen(UIScreen* s) { alarm_screen = s; }
|
||||
UIScreen* getVoiceScreen() const { return voice_screen; }
|
||||
void setVoiceScreen(UIScreen* s) { voice_screen = s; }
|
||||
#endif
|
||||
UIScreen* getRepeaterAdminScreen() const { return repeater_admin; }
|
||||
UIScreen* getPathEditorScreen() const { return path_editor; }
|
||||
UIScreen* getDiscoveryScreen() const { return discovery_screen; }
|
||||
UIScreen* getLastHeardScreen() const { return last_heard_screen; }
|
||||
UIScreen* getMapScreen() const { return map_screen; }
|
||||
#ifdef MECK_WEB_READER
|
||||
UIScreen* getWebReaderScreen() const { return web_reader; }
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -39,6 +39,7 @@
|
||||
#include "ModemManager.h"
|
||||
#endif
|
||||
#include "Utf8CP437.h"
|
||||
#include "../NodePrefs.h"
|
||||
|
||||
// Forward declarations
|
||||
class UITask;
|
||||
@@ -1030,8 +1031,10 @@ public:
|
||||
|
||||
private:
|
||||
UITask* _task;
|
||||
NodePrefs* _prefs;
|
||||
Mode _mode;
|
||||
bool _initialized;
|
||||
uint8_t _lastFontPref;
|
||||
DisplayDriver* _display;
|
||||
|
||||
// Display layout (calculated once)
|
||||
@@ -1424,7 +1427,7 @@ private:
|
||||
_display->print("WiFi Setup");
|
||||
_display->drawRect(0, 11, _display->width(), 1);
|
||||
_display->setColor(DisplayDriver::LIGHT);
|
||||
_display->setTextSize(0);
|
||||
_display->setTextSize(_prefs->smallTextSize());
|
||||
_display->setCursor(0, 18);
|
||||
_display->print("Scanning for networks...");
|
||||
_display->endFrame();
|
||||
@@ -1524,7 +1527,7 @@ private:
|
||||
_display->print("Web Reader");
|
||||
_display->drawRect(0, 11, _display->width(), 1);
|
||||
|
||||
_display->setTextSize(0);
|
||||
_display->setTextSize(_prefs->smallTextSize());
|
||||
_display->setCursor(0, 18);
|
||||
_display->print("Connected!");
|
||||
_display->setCursor(0, 30);
|
||||
@@ -2306,7 +2309,7 @@ private:
|
||||
_display->print("Web Reader");
|
||||
_display->drawRect(0, 11, _display->width(), 1);
|
||||
_display->setColor(DisplayDriver::YELLOW);
|
||||
_display->setTextSize(0);
|
||||
_display->setTextSize(_prefs->smallTextSize());
|
||||
_display->setCursor(0, 18);
|
||||
_display->print("Fetch failed:");
|
||||
_display->setColor(DisplayDriver::LIGHT);
|
||||
@@ -2442,7 +2445,7 @@ private:
|
||||
_display->setTextSize(2);
|
||||
_display->setCursor(10, 20);
|
||||
_display->print("Logging in...");
|
||||
_display->setTextSize(0);
|
||||
_display->setTextSize(_prefs->smallTextSize());
|
||||
_display->setColor(DisplayDriver::LIGHT);
|
||||
_display->setCursor(10, 45);
|
||||
_display->print("Refreshing session...");
|
||||
@@ -2656,14 +2659,14 @@ private:
|
||||
display.drawRect(0, 11, display.width(), 1);
|
||||
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
|
||||
if (_wifiState == WIFI_SCANNING) {
|
||||
display.setCursor(0, 18);
|
||||
display.print("Scanning for networks...");
|
||||
} else if (_wifiState == WIFI_SCAN_DONE) {
|
||||
int y = 14;
|
||||
int listLineH = 8;
|
||||
int listLineH = _prefs ? _prefs->smallLineH() : 9;
|
||||
for (int i = 0; i < _ssidCount && y < display.height() - 24; i++) {
|
||||
bool selected = (i == _selectedSSID);
|
||||
if (selected) {
|
||||
@@ -2671,7 +2674,7 @@ private:
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.fillRect(0, y, display.width(), listLineH);
|
||||
#else
|
||||
display.fillRect(0, y + 5, display.width(), listLineH);
|
||||
display.fillRect(0, y + _prefs->smallHighlightOff(), display.width(), listLineH);
|
||||
#endif
|
||||
display.setColor(DisplayDriver::DARK);
|
||||
} else {
|
||||
@@ -2695,7 +2698,7 @@ private:
|
||||
y += 12;
|
||||
display.setCursor(0, y);
|
||||
display.print("Password:");
|
||||
y += 10;
|
||||
y += _prefs->smallLineH() + 1;
|
||||
display.setCursor(0, y);
|
||||
// Show masked password with brief reveal of last char
|
||||
char passBuf[WEB_WIFI_PASS_LEN + 2];
|
||||
@@ -2771,7 +2774,7 @@ private:
|
||||
|
||||
if (isNetworkAvailable()) {
|
||||
display.print("Web Reader");
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
display.setColor(DisplayDriver::GREEN);
|
||||
if (isWiFiConnected()) {
|
||||
IPAddress ip = WiFi.localIP();
|
||||
@@ -2797,7 +2800,7 @@ private:
|
||||
const int footerY = display.height() - 12;
|
||||
const int viewportH = display.height() - headerY - footerH;
|
||||
const int scrollbarW = 4;
|
||||
const int listLineH = 8;
|
||||
const int listLineH = _prefs ? _prefs->smallLineH() : 9;
|
||||
const int sepH = 8; // Separator between IRC and web sections
|
||||
const int sectionH = listLineH; // Section header height
|
||||
int maxChars = _charsPerLine - 2; // Account for "> " prefix
|
||||
@@ -2875,7 +2878,7 @@ private:
|
||||
if (totalContentH <= viewportH) _homeScrollY = 0;
|
||||
|
||||
// ---- Render pass (with scroll offset) ----
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
int y = headerY - _homeScrollY; // Start Y in screen coords
|
||||
itemIdx = 0;
|
||||
bool needsScroll = (totalContentH > viewportH);
|
||||
@@ -2895,7 +2898,7 @@ private:
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.fillRect(0, y, display.width() - (needsScroll ? scrollbarW + 1 : 0), listLineH);
|
||||
#else
|
||||
display.fillRect(0, y + 5, display.width() - (needsScroll ? scrollbarW + 1 : 0), listLineH);
|
||||
display.fillRect(0, y + _prefs->smallHighlightOff(), display.width() - (needsScroll ? scrollbarW + 1 : 0), listLineH);
|
||||
#endif
|
||||
display.setColor(DisplayDriver::DARK);
|
||||
} else {
|
||||
@@ -2934,7 +2937,7 @@ private:
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.fillRect(0, y, display.width() - (needsScroll ? scrollbarW + 1 : 0), listLineH);
|
||||
#else
|
||||
display.fillRect(0, y + 5, display.width() - (needsScroll ? scrollbarW + 1 : 0), listLineH);
|
||||
display.fillRect(0, y + _prefs->smallHighlightOff(), display.width() - (needsScroll ? scrollbarW + 1 : 0), listLineH);
|
||||
#endif
|
||||
display.setColor(DisplayDriver::DARK);
|
||||
} else {
|
||||
@@ -2971,7 +2974,7 @@ private:
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.fillRect(0, y, display.width() - (needsScroll ? scrollbarW + 1 : 0), listLineH);
|
||||
#else
|
||||
display.fillRect(0, y + 5, display.width() - (needsScroll ? scrollbarW + 1 : 0), listLineH);
|
||||
display.fillRect(0, y + _prefs->smallHighlightOff(), display.width() - (needsScroll ? scrollbarW + 1 : 0), listLineH);
|
||||
#endif
|
||||
display.setColor(DisplayDriver::DARK);
|
||||
} else {
|
||||
@@ -3024,7 +3027,7 @@ private:
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.fillRect(0, y, contentW, itemH);
|
||||
#else
|
||||
display.fillRect(0, y + 5, contentW, itemH);
|
||||
display.fillRect(0, y + _prefs->smallHighlightOff(), contentW, itemH);
|
||||
#endif
|
||||
display.setColor(DisplayDriver::DARK);
|
||||
} else {
|
||||
@@ -3076,7 +3079,7 @@ private:
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
display.fillRect(0, y, contentW, itemH);
|
||||
#else
|
||||
display.fillRect(0, y + 5, contentW, itemH);
|
||||
display.fillRect(0, y + _prefs->smallHighlightOff(), contentW, itemH);
|
||||
#endif
|
||||
display.setColor(DisplayDriver::DARK);
|
||||
} else {
|
||||
@@ -3198,7 +3201,7 @@ private:
|
||||
display.setCursor(10, 20);
|
||||
display.print("Loading...");
|
||||
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
|
||||
// Word-wrap the URL across multiple lines
|
||||
@@ -3243,7 +3246,7 @@ private:
|
||||
display.print("Download Complete");
|
||||
display.drawRect(0, 11, display.width(), 1);
|
||||
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.setCursor(0, 16);
|
||||
display.print("Saved to /books/:");
|
||||
@@ -3277,7 +3280,7 @@ private:
|
||||
display.print("Download Failed");
|
||||
display.drawRect(0, 11, display.width(), 1);
|
||||
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.setCursor(0, 18);
|
||||
display.print(_fetchError.c_str());
|
||||
@@ -3314,7 +3317,7 @@ private:
|
||||
return;
|
||||
}
|
||||
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
|
||||
// Determine page bounds
|
||||
@@ -3476,9 +3479,16 @@ private:
|
||||
// ---- Layout Initialization ----
|
||||
|
||||
void initLayout(DisplayDriver& display) {
|
||||
// Re-init if font preference changed since last layout
|
||||
uint8_t curFont = _prefs ? _prefs->large_font : 0;
|
||||
if (_initialized && curFont != _lastFontPref) {
|
||||
_initialized = false;
|
||||
Serial.println("WebReader: font changed, recalculating layout");
|
||||
}
|
||||
if (_initialized) return;
|
||||
_lastFontPref = curFont;
|
||||
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
uint16_t mWidth = display.getTextWidth("M");
|
||||
if (mWidth > 0) {
|
||||
_charsPerLine = display.width() / mWidth;
|
||||
@@ -3487,6 +3497,19 @@ private:
|
||||
_charsPerLine = 40;
|
||||
_lineHeight = 5;
|
||||
}
|
||||
// Proportional font: use average-width measurement instead of M-width
|
||||
if (_prefs && _prefs->large_font && mWidth > 0) {
|
||||
const char* sample = "the quick brown fox jumps over lazy dog";
|
||||
uint16_t sampleW = display.getTextWidth(sample);
|
||||
int sampleLen = strlen(sample);
|
||||
if (sampleW > 0 && sampleLen > 0) {
|
||||
_charsPerLine = (display.width() * sampleLen * 70) / ((int)sampleW * 100);
|
||||
}
|
||||
}
|
||||
// Large font: formula above assumes built-in 6x8 ratio — too small for 9pt
|
||||
if (_prefs && _prefs->large_font) {
|
||||
_lineHeight = _prefs->smallLineH();
|
||||
}
|
||||
|
||||
_footerHeight = 14;
|
||||
int textAreaHeight = display.height() - _footerHeight;
|
||||
@@ -3931,7 +3954,7 @@ private:
|
||||
if (_activeForm < 0 || _activeForm >= _formCount) return;
|
||||
WebForm& form = _forms[_activeForm];
|
||||
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
|
||||
// Header
|
||||
display.setColor(DisplayDriver::GREEN);
|
||||
@@ -3954,7 +3977,7 @@ private:
|
||||
display.drawRect(0, 9, display.width(), 1);
|
||||
|
||||
int y = 12;
|
||||
int lineH = 10; // Taller lines for form fields
|
||||
int lineH = _prefs->smallLineH() + 1; // Taller lines for form fields
|
||||
int visCount = getVisibleFieldCount(form);
|
||||
|
||||
// Render each visible field
|
||||
@@ -4662,9 +4685,9 @@ private:
|
||||
display.print("IRC Setup");
|
||||
display.drawRect(0, 11, display.width(), 1);
|
||||
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
int y = 16;
|
||||
int lineH = 10;
|
||||
int lineH = _prefs->smallLineH() + 1;
|
||||
|
||||
const char* labels[] = {"Server:", "Port:", "Nick:", "Channel:", "[ Connect ]"};
|
||||
const char* chanDisp = (_ircChannel[0] != '\0') ? _ircChannel : "(none)";
|
||||
@@ -4822,7 +4845,7 @@ private:
|
||||
display.print(header);
|
||||
|
||||
// Connection indicator on right
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
if (!_ircConnected) {
|
||||
display.setColor(DisplayDriver::YELLOW);
|
||||
display.setCursor(display.width() - 42, -3);
|
||||
@@ -4848,7 +4871,7 @@ private:
|
||||
|
||||
if (_ircComposing) {
|
||||
// Compose text just above separator (tiny font to match messages)
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.setCursor(0, footerY - 12);
|
||||
char compDisp[IRC_COMPOSE_MAX + 4];
|
||||
@@ -4878,10 +4901,10 @@ private:
|
||||
}
|
||||
|
||||
// Message area
|
||||
display.setTextSize(0);
|
||||
display.setTextSize(_prefs->smallTextSize());
|
||||
int msgAreaTop = 14;
|
||||
int msgAreaBottom = _ircComposing ? footerY - 16 : footerY - 4;
|
||||
int lineH = 8;
|
||||
int lineH = _prefs->smallLineH() - 1;
|
||||
int scrollBarW = 4;
|
||||
int lineW = _charsPerLine - 1; // Reserve space for scroll bar
|
||||
_ircLinesPerPage = (msgAreaBottom - msgAreaTop) / lineH;
|
||||
@@ -5065,8 +5088,8 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
WebReaderScreen(UITask* task)
|
||||
: _task(task), _mode(HOME), _initialized(false), _display(nullptr),
|
||||
WebReaderScreen(UITask* task, NodePrefs* prefs = nullptr)
|
||||
: _task(task), _prefs(prefs), _mode(HOME), _initialized(false), _lastFontPref(0), _display(nullptr),
|
||||
_charsPerLine(40), _linesPerPage(15), _lineHeight(5), _footerHeight(14),
|
||||
_wifiState(WIFI_IDLE), _ssidCount(0), _selectedSSID(0), _wifiPassLen(0),
|
||||
_urlLen(0), _urlCursor(0),
|
||||
@@ -5150,7 +5173,7 @@ public:
|
||||
_display->print("Web Reader");
|
||||
_display->drawRect(0, 11, _display->width(), 1);
|
||||
_display->setColor(DisplayDriver::LIGHT);
|
||||
_display->setTextSize(0);
|
||||
_display->setTextSize(_prefs->smallTextSize());
|
||||
_display->setCursor(0, 18);
|
||||
_display->print("Connecting to WiFi...");
|
||||
_display->endFrame();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
// Emoji Picker with scrolling grid and scroll bar
|
||||
// 5 columns, 4 visible rows, scrollable through all 65 emoji
|
||||
// 5 columns, 4 visible rows, scrollable through all 76 emoji
|
||||
// WASD navigation, Enter to select, $/Q/Backspace to cancel
|
||||
|
||||
#include <helpers/ui/DisplayDriver.h>
|
||||
@@ -12,71 +12,85 @@
|
||||
#define EMOJI_PICKER_TOTAL_ROWS ((EMOJI_COUNT + EMOJI_PICKER_COLS - 1) / EMOJI_PICKER_COLS)
|
||||
|
||||
static const char* EMOJI_LABELS[EMOJI_COUNT] = {
|
||||
// Faces/emotion
|
||||
"Lol", // 0 joy
|
||||
"Like", // 1 thumbsup
|
||||
"Sad", // 2 frown
|
||||
"WiFi", // 3 wireless
|
||||
"Inf", // 4 infinity
|
||||
"Rex", // 5 trex
|
||||
"Skul", // 6 skull
|
||||
"Cros", // 7 cross
|
||||
"Bolt", // 8 lightning
|
||||
"Hat", // 9 tophat
|
||||
"Moto", // 10 motorcycle
|
||||
"Leaf", // 11 seedling
|
||||
"AU", // 12 flag_au
|
||||
"Umbr", // 13 umbrella
|
||||
"Eye", // 14 nazar
|
||||
"Glob", // 15 globe
|
||||
"Rad", // 16 radioactive
|
||||
"Cow", // 17 cow
|
||||
"ET", // 18 alien
|
||||
"Inv", // 19 invader
|
||||
"Dagr", // 20 dagger
|
||||
"Grim", // 21 grimace
|
||||
"Mtn", // 22 mountain
|
||||
"End", // 23 end_arrow
|
||||
"Ring", // 24 hollow_circle
|
||||
"Drag", // 25 dragon
|
||||
"Web", // 26 globe_meridians
|
||||
"Eggp", // 27 eggplant
|
||||
"Shld", // 28 shield
|
||||
"Gogl", // 29 goggles
|
||||
"Lzrd", // 30 lizard
|
||||
"Zany", // 31 zany_face
|
||||
"Roo", // 32 kangaroo
|
||||
"Fthr", // 33 feather
|
||||
"Sun", // 34 bright
|
||||
"Wave", // 35 part_alt
|
||||
"Boat", // 36 motorboat
|
||||
"Domi", // 37 domino
|
||||
"Dish", // 38 satellite
|
||||
"Pass", // 39 customs
|
||||
"Cowb", // 40 cowboy
|
||||
"Whl", // 41 wheel
|
||||
"Koal", // 42 koala
|
||||
"Knob", // 43 control_knobs
|
||||
"Pch", // 44 peach
|
||||
"Race", // 45 racing_car
|
||||
"Mous", // 46 mouse
|
||||
"Shrm", // 47 mushroom
|
||||
"Bio", // 48 biohazard
|
||||
"Pnda", // 49 panda
|
||||
"Bang", // 50 anger
|
||||
"DrgF", // 51 dragon_face
|
||||
"Pagr", // 52 pager
|
||||
"Bee", // 53 bee
|
||||
"Bulb", // 54 bulb
|
||||
"Cat", // 55 cat
|
||||
"Flur", // 56 fleur
|
||||
"Moon", // 57 moon
|
||||
"Cafe", // 58 coffee
|
||||
"Toth", // 59 tooth
|
||||
"Prtz", // 60 pretzel
|
||||
"Abac", // 61 abacus
|
||||
"Moai", // 62 moai
|
||||
"Hiii", // 63 tipping
|
||||
"Hedg", // 64 hedgehog
|
||||
"Sad", // 1 frown
|
||||
"Cry", // 2 loudly_crying
|
||||
"Grim", // 3 grimace
|
||||
"Zany", // 4 zany_face
|
||||
"Cowb", // 5 cowboy
|
||||
// Thumbsup + heart
|
||||
"Like", // 6 thumbsup
|
||||
"Love", // 7 heart
|
||||
// Everything else
|
||||
"WiFi", // 8 wireless
|
||||
"Inf", // 9 infinity
|
||||
"Rex", // 10 trex
|
||||
"Skul", // 11 skull
|
||||
"Cros", // 12 cross
|
||||
"Bolt", // 13 lightning
|
||||
"Hat", // 14 tophat
|
||||
"Moto", // 15 motorcycle
|
||||
"Leaf", // 16 seedling
|
||||
"AU", // 17 flag_au
|
||||
"Umbr", // 18 umbrella
|
||||
"Eye", // 19 nazar
|
||||
"Glob", // 20 globe
|
||||
"Rad", // 21 radioactive
|
||||
"Cow", // 22 cow
|
||||
"ET", // 23 alien
|
||||
"Inv", // 24 invader
|
||||
"Dagr", // 25 dagger
|
||||
"Mtn", // 26 mountain
|
||||
"End", // 27 end_arrow
|
||||
"Ring", // 28 hollow_circle
|
||||
"Drag", // 29 dragon
|
||||
"Web", // 30 globe_meridians
|
||||
"Eggp", // 31 eggplant
|
||||
"Shld", // 32 shield
|
||||
"Gogl", // 33 goggles
|
||||
"Lzrd", // 34 lizard
|
||||
"Roo", // 35 kangaroo
|
||||
"Fthr", // 36 feather
|
||||
"Sun", // 37 bright
|
||||
"Wave", // 38 part_alt
|
||||
"Boat", // 39 motorboat
|
||||
"Domi", // 40 domino
|
||||
"Dish", // 41 satellite
|
||||
"Pass", // 42 customs
|
||||
"Whl", // 43 wheel
|
||||
"Koal", // 44 koala
|
||||
"Knob", // 45 control_knobs
|
||||
"Pch", // 46 peach
|
||||
"Race", // 47 racing_car
|
||||
"Mous", // 48 mouse
|
||||
"Shrm", // 49 mushroom
|
||||
"Bio", // 50 biohazard
|
||||
"Pnda", // 51 panda
|
||||
"Bang", // 52 anger
|
||||
"DrgF", // 53 dragon_face
|
||||
"Pagr", // 54 pager
|
||||
"Bee", // 55 bee
|
||||
"Bulb", // 56 bulb
|
||||
"Cat", // 57 cat
|
||||
"Flur", // 58 fleur
|
||||
"Moon", // 59 moon
|
||||
"Cafe", // 60 coffee
|
||||
"Toth", // 61 tooth
|
||||
"Prtz", // 62 pretzel
|
||||
"Abac", // 63 abacus
|
||||
"Moai", // 64 moai
|
||||
"Hiii", // 65 tipping
|
||||
"Hedg", // 66 hedgehog
|
||||
"Diam", // 67 diamond_suit
|
||||
"Spde", // 68 spade_suit
|
||||
"Piza", // 69 pizza
|
||||
"Luck", // 70 four_leaf_clover
|
||||
"Cld", // 71 cloud
|
||||
"Rckt", // 72 rocket
|
||||
"HFC", // 73 passport_control
|
||||
"Star", // 74 eight_spoked_asterisk
|
||||
"Sig", // 75 signal_strength
|
||||
};
|
||||
|
||||
struct EmojiPicker {
|
||||
@@ -105,13 +119,23 @@ struct EmojiPicker {
|
||||
|
||||
switch (key) {
|
||||
case 'w': case 'W': case 0xF2:
|
||||
if (row > 0) cursor -= EMOJI_PICKER_COLS;
|
||||
if (row > 0) {
|
||||
cursor -= EMOJI_PICKER_COLS;
|
||||
} else {
|
||||
// Wrap to last row, same column
|
||||
int target = (EMOJI_PICKER_TOTAL_ROWS - 1) * EMOJI_PICKER_COLS + col;
|
||||
cursor = (target >= EMOJI_COUNT) ? EMOJI_COUNT - 1 : target;
|
||||
}
|
||||
break;
|
||||
case 's': case 'S': case 0xF1:
|
||||
if (cursor + EMOJI_PICKER_COLS < EMOJI_COUNT)
|
||||
if (cursor + EMOJI_PICKER_COLS < EMOJI_COUNT) {
|
||||
cursor += EMOJI_PICKER_COLS;
|
||||
else if (row < EMOJI_PICKER_TOTAL_ROWS - 1)
|
||||
} else if (row < EMOJI_PICKER_TOTAL_ROWS - 1) {
|
||||
cursor = EMOJI_COUNT - 1;
|
||||
} else {
|
||||
// Wrap to first row, same column
|
||||
cursor = col;
|
||||
}
|
||||
break;
|
||||
case 'a': case 'A':
|
||||
if (cursor > 0) cursor--;
|
||||
|
||||
@@ -46,4 +46,18 @@ static const uint8_t icon_notepad[] PROGMEM = {
|
||||
static const uint8_t icon_search[] PROGMEM = {
|
||||
0x3C,0x00, 0x42,0x00, 0x81,0x00, 0x81,0x00, 0x81,0x00, 0x42,0x00,
|
||||
0x3C,0x00, 0x03,0x00, 0x01,0x80, 0x00,0xC0, 0x00,0x40, 0x00,0x00,
|
||||
};
|
||||
|
||||
// ⏰ Alarm Clock (AlarmScreen) — 12x12 home tile icon
|
||||
static const uint8_t icon_alarm[] PROGMEM = {
|
||||
0x40,0x40, 0x9E,0x20, 0x20,0x80, 0x44,0x40, 0x44,0x40, 0x46,0x40,
|
||||
0x40,0x40, 0x20,0x80, 0x1F,0x00, 0x00,0x00, 0x20,0x40, 0x40,0x20,
|
||||
};
|
||||
|
||||
// 🔔 Bell — 7x8 status bar indicator (alarm enabled)
|
||||
// MSB-first, 1 byte per row
|
||||
#define BELL_ICON_W 7
|
||||
#define BELL_ICON_H 8
|
||||
static const uint8_t icon_bell_small[] PROGMEM = {
|
||||
0x10, 0x38, 0x7C, 0x7C, 0x7C, 0xFE, 0x00, 0x10,
|
||||
};
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <helpers/ui/DisplayDriver.h>
|
||||
#include "EmojiSprites.h"
|
||||
|
||||
enum VKBStatus { VKB_EDITING, VKB_SUBMITTED, VKB_CANCELLED };
|
||||
|
||||
@@ -29,6 +30,7 @@ enum VKBPurpose {
|
||||
VKB_ADMIN_CLI, // Repeater admin CLI command
|
||||
VKB_NOTES, // Insert text into notes
|
||||
VKB_SETTINGS_NAME, // Edit node name
|
||||
VKB_SETTINGS_TEXT, // Generic settings text edit (channel name, freq, APN)
|
||||
VKB_WIFI_PASSWORD, // WiFi password entry (settings screen)
|
||||
#ifdef MECK_WEB_READER
|
||||
VKB_WEB_URL, // Web reader URL entry
|
||||
@@ -36,6 +38,7 @@ enum VKBPurpose {
|
||||
VKB_WEB_WIFI_PASS, // Web reader WiFi password
|
||||
VKB_WEB_LINK, // Web reader link number entry
|
||||
#endif
|
||||
VKB_TEXT_PAGE, // Text reader: go to page number
|
||||
};
|
||||
|
||||
class VirtualKeyboard {
|
||||
@@ -43,7 +46,8 @@ public:
|
||||
static const int MAX_TEXT = 140;
|
||||
|
||||
VirtualKeyboard() : _status(VKB_CANCELLED), _purpose(VKB_CHANNEL_MSG),
|
||||
_contextIdx(0), _textLen(0), _shifted(false), _symbols(false) {
|
||||
_contextIdx(0), _textLen(0), _shifted(false), _symbols(false),
|
||||
_emojiMode(false), _emojiScroll(0) {
|
||||
_text[0] = '\0';
|
||||
_label[0] = '\0';
|
||||
}
|
||||
@@ -54,6 +58,8 @@ public:
|
||||
_status = VKB_EDITING;
|
||||
_shifted = false;
|
||||
_symbols = false;
|
||||
_emojiMode = false;
|
||||
_emojiScroll = 0;
|
||||
_maxLen = (maxLen > 0 && maxLen < MAX_TEXT) ? maxLen : MAX_TEXT;
|
||||
|
||||
strncpy(_label, label, sizeof(_label) - 1);
|
||||
@@ -88,13 +94,8 @@ public:
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.drawRect(0, 10, 128, 18); // Border
|
||||
|
||||
display.setCursor(2, 12);
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
|
||||
// Show text with cursor
|
||||
char dispBuf[MAX_TEXT + 2];
|
||||
snprintf(dispBuf, sizeof(dispBuf), "%s_", _text);
|
||||
display.print(dispBuf);
|
||||
// Render text with inline emoji sprites
|
||||
renderTextField(display);
|
||||
|
||||
// Character count
|
||||
{
|
||||
@@ -109,6 +110,11 @@ public:
|
||||
// Separator
|
||||
display.drawRect(0, 30, 128, 1);
|
||||
|
||||
if (_emojiMode) {
|
||||
renderEmojiGrid(display);
|
||||
return;
|
||||
}
|
||||
|
||||
// --- Draw keyboard rows ---
|
||||
const char* const* layout = getLayout();
|
||||
|
||||
@@ -181,6 +187,8 @@ public:
|
||||
bool handleTap(int vx, int vy) {
|
||||
if (_status != VKB_EDITING) return false;
|
||||
|
||||
if (_emojiMode) return handleEmojiTap(vx, vy);
|
||||
|
||||
// Check keyboard rows 0-2
|
||||
const char* const* layout = getLayout();
|
||||
|
||||
@@ -215,6 +223,32 @@ public:
|
||||
// Swipe up on keyboard = cancel
|
||||
void cancel() { _status = VKB_CANCELLED; }
|
||||
|
||||
// --- Feed a raw ASCII character from an external physical keyboard ---
|
||||
// Maps standard ASCII control chars to internal VKB actions.
|
||||
// Returns true if the character was consumed.
|
||||
#ifdef MECK_CARDKB
|
||||
bool feedChar(char c) {
|
||||
if (_status != VKB_EDITING) return false;
|
||||
switch (c) {
|
||||
case '\r': processKey('>'); return true; // Enter → submit
|
||||
case '\b': processKey('<'); return true; // Backspace
|
||||
case 0x7F: processKey('<'); return true; // Delete → backspace
|
||||
case 0x1B: _status = VKB_CANCELLED; return true; // ESC → cancel
|
||||
case ' ': processKey('~'); return true; // Space
|
||||
default:
|
||||
// Printable ASCII → insert directly
|
||||
if (c >= 0x20 && c <= 0x7E) {
|
||||
if (_textLen < _maxLen) {
|
||||
_text[_textLen++] = c;
|
||||
_text[_textLen] = '\0';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false; // Non-printable / nav keys — not consumed
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
VKBStatus _status;
|
||||
VKBPurpose _purpose;
|
||||
@@ -225,6 +259,169 @@ private:
|
||||
char _label[40];
|
||||
bool _shifted;
|
||||
bool _symbols;
|
||||
bool _emojiMode;
|
||||
int _emojiScroll;
|
||||
|
||||
// Emoji grid constants (virtual coords)
|
||||
static const int EMJ_COLS = 8;
|
||||
static const int EMJ_CELL = 15; // 12px sprite + 3px gap
|
||||
static const int EMJ_GRID_X = 4;
|
||||
static const int EMJ_GRID_Y = 34;
|
||||
static const int EMJ_VIS_ROWS = 5;
|
||||
|
||||
int emojiTotalRows() const { return (EMOJI_COUNT + EMJ_COLS - 1) / EMJ_COLS; }
|
||||
int emojiMaxScroll() const { int m = emojiTotalRows() - EMJ_VIS_ROWS; return m < 0 ? 0 : m; }
|
||||
|
||||
void renderEmojiGrid(DisplayDriver& display) {
|
||||
display.setTextSize(0);
|
||||
|
||||
for (int vr = 0; vr < EMJ_VIS_ROWS; vr++) {
|
||||
int absRow = _emojiScroll + vr;
|
||||
if (absRow >= emojiTotalRows()) break;
|
||||
|
||||
for (int col = 0; col < EMJ_COLS; col++) {
|
||||
int idx = absRow * EMJ_COLS + col;
|
||||
if (idx >= EMOJI_COUNT) break;
|
||||
|
||||
int cx = EMJ_GRID_X + col * EMJ_CELL;
|
||||
int cy = EMJ_GRID_Y + vr * EMJ_CELL;
|
||||
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
const uint8_t* sprite = (const uint8_t*)pgm_read_ptr(&EMOJI_SPRITES_LG[idx]);
|
||||
if (sprite) {
|
||||
display.drawXbm(cx + 1, cy + 1, sprite, EMOJI_LG_W, EMOJI_LG_H);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Footer: [Back] [▲] page/total [▼]
|
||||
int fy = EMJ_GRID_Y + EMJ_VIS_ROWS * EMJ_CELL + 2;
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.drawRect(0, fy - 1, 128, 1);
|
||||
|
||||
// Back button (inverted)
|
||||
display.fillRect(4, fy + 1, 30, 12);
|
||||
display.setColor(DisplayDriver::DARK);
|
||||
int bw = display.getTextWidth("Back");
|
||||
display.setCursor(4 + (30 - bw) / 2, fy + 2);
|
||||
display.print("Back");
|
||||
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
|
||||
// Scroll arrows (only if scrollable)
|
||||
if (emojiTotalRows() > EMJ_VIS_ROWS) {
|
||||
// Up arrow
|
||||
if (_emojiScroll > 0) {
|
||||
display.fillRect(50, fy + 1, 12, 12);
|
||||
display.setColor(DisplayDriver::DARK);
|
||||
display.setCursor(53, fy + 2);
|
||||
display.print("^");
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
}
|
||||
|
||||
// Page info
|
||||
char pg[8];
|
||||
snprintf(pg, sizeof(pg), "%d/%d", _emojiScroll + 1, emojiMaxScroll() + 1);
|
||||
int pw = display.getTextWidth(pg);
|
||||
display.setCursor(75 - pw / 2, fy + 2);
|
||||
display.print(pg);
|
||||
|
||||
// Down arrow
|
||||
if (_emojiScroll < emojiMaxScroll()) {
|
||||
display.fillRect(90, fy + 1, 12, 12);
|
||||
display.setColor(DisplayDriver::DARK);
|
||||
display.setCursor(93, fy + 2);
|
||||
display.print("v");
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool handleEmojiTap(int vx, int vy) {
|
||||
int fy = EMJ_GRID_Y + EMJ_VIS_ROWS * EMJ_CELL + 2;
|
||||
|
||||
// Footer area
|
||||
if (vy >= fy) {
|
||||
if (vx >= 4 && vx < 34) {
|
||||
// Back button
|
||||
_emojiMode = false;
|
||||
return true;
|
||||
}
|
||||
if (vx >= 50 && vx < 62 && _emojiScroll > 0) {
|
||||
_emojiScroll--;
|
||||
return true;
|
||||
}
|
||||
if (vx >= 90 && vx < 102 && _emojiScroll < emojiMaxScroll()) {
|
||||
_emojiScroll++;
|
||||
return true;
|
||||
}
|
||||
return true; // Consume tap in footer
|
||||
}
|
||||
|
||||
// Grid area
|
||||
if (vy >= EMJ_GRID_Y && vy < EMJ_GRID_Y + EMJ_VIS_ROWS * EMJ_CELL) {
|
||||
int col = (vx - EMJ_GRID_X) / EMJ_CELL;
|
||||
int vr = (vy - EMJ_GRID_Y) / EMJ_CELL;
|
||||
if (col < 0 || col >= EMJ_COLS || vr < 0 || vr >= EMJ_VIS_ROWS) return true;
|
||||
|
||||
int idx = (_emojiScroll + vr) * EMJ_COLS + col;
|
||||
if (idx >= 0 && idx < EMOJI_COUNT) {
|
||||
insertEmoji(idx);
|
||||
_emojiMode = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return true; // Consume any tap while in emoji mode
|
||||
}
|
||||
|
||||
void insertEmoji(int idx) {
|
||||
// Insert as UTF-8 directly (not escape bytes) so sent messages are valid
|
||||
uint8_t utf8[8];
|
||||
int len = emojiEncodeUtf8(EMOJI_CODEPOINTS[idx].cp, utf8);
|
||||
if (EMOJI_CODEPOINTS[idx].cp2 != 0)
|
||||
len += emojiEncodeUtf8(EMOJI_CODEPOINTS[idx].cp2, utf8 + len);
|
||||
if (_textLen + len > _maxLen) return;
|
||||
memcpy(_text + _textLen, utf8, len);
|
||||
_textLen += len;
|
||||
_text[_textLen] = '\0';
|
||||
}
|
||||
|
||||
// Render text field with inline emoji sprites (10×10)
|
||||
void renderTextField(DisplayDriver& display) {
|
||||
// Convert UTF-8 emoji to escape bytes for sprite lookup
|
||||
char sanitized[MAX_TEXT + 1];
|
||||
emojiSanitize(_text, sanitized, sizeof(sanitized));
|
||||
|
||||
int x = 2;
|
||||
int maxX = 124;
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.setTextSize(0);
|
||||
|
||||
for (int i = 0; sanitized[i] && x < maxX; i++) {
|
||||
uint8_t b = (uint8_t)sanitized[i];
|
||||
if (b == EMOJI_PAD_BYTE) continue;
|
||||
|
||||
if (isEmojiEscape(b)) {
|
||||
const uint8_t* sprite = getEmojiSpriteSm(b);
|
||||
if (sprite && x + EMOJI_SM_W < maxX) {
|
||||
display.drawXbm(x, 14, sprite, EMOJI_SM_W, EMOJI_SM_H);
|
||||
x += EMOJI_SM_W + 1;
|
||||
}
|
||||
} else {
|
||||
char ch[2] = { (char)b, '\0' };
|
||||
display.setCursor(x, 12);
|
||||
display.print(ch);
|
||||
x += display.getTextWidth(ch);
|
||||
}
|
||||
}
|
||||
|
||||
// Blinking cursor
|
||||
if (x < maxX) {
|
||||
display.setCursor(x, 12);
|
||||
display.print("_");
|
||||
}
|
||||
}
|
||||
|
||||
// Layout constants (virtual coords)
|
||||
static const int KEY_W = 11;
|
||||
@@ -233,7 +430,7 @@ private:
|
||||
static const int KEY_START_Y = 34;
|
||||
|
||||
// Key layouts — rows 0-2 as char arrays
|
||||
// Special: ^ = shift, < = backspace, # = symbols, > = enter, ~ = space
|
||||
// Special: ^ = shift, < = backspace, \x01 = sym toggle, \x02 = emoji, > = enter, ~ = space
|
||||
const char* const* getLayout() const {
|
||||
static const char* const lower[3] = { "qwertyuiop", "asdfghjkl", "^zxcvbnm<" };
|
||||
static const char* const upper[3] = { "QWERTYUIOP", "ASDFGHJKL", "^ZXCVBNM<" };
|
||||
@@ -241,26 +438,22 @@ private:
|
||||
return _symbols ? syms : (_shifted ? upper : lower);
|
||||
}
|
||||
|
||||
// Row 4: variable-width keys [#/ABC] [,] [SPACE] [.] [Enter]
|
||||
// Row 4: variable-width keys [#/ABC] [,] [$] [SPACE] [.] [Enter]
|
||||
// Defined by physical zones, not the char-array approach
|
||||
struct R4Key { int x; int w; char ch; const char* label; };
|
||||
|
||||
void drawRow4(DisplayDriver& display, int y) {
|
||||
// # or ABC toggle: x=4, w=20
|
||||
// comma: x=26, w=11
|
||||
// space: x=39, w=50
|
||||
// period: x=91, w=11
|
||||
// enter: x=104, w=20
|
||||
const R4Key keys[] = {
|
||||
{ 4, 20, '\x01', _symbols ? "ABC" : "123" },
|
||||
{ 26, 11, ',', "," },
|
||||
{ 39, 50, '~', "space" },
|
||||
{ 39, 11, '\x02', "$" },
|
||||
{ 52, 37, '~', "space" },
|
||||
{ 91, 11, '.', "." },
|
||||
{ 104, 20, '>', "Send" }
|
||||
};
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
bool special = (keys[i].ch == '\x01' || keys[i].ch == '>');
|
||||
for (int i = 0; i < 6; i++) {
|
||||
bool special = (keys[i].ch == '\x01' || keys[i].ch == '>' || keys[i].ch == '\x02');
|
||||
if (special) {
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.fillRect(keys[i].x, y + 1, keys[i].w, KEY_H - 1);
|
||||
@@ -284,11 +477,12 @@ private:
|
||||
const R4Key keys[] = {
|
||||
{ 4, 20, '\x01', nullptr },
|
||||
{ 26, 11, ',', nullptr },
|
||||
{ 39, 50, '~', nullptr },
|
||||
{ 39, 11, '\x02', nullptr },
|
||||
{ 52, 37, '~', nullptr },
|
||||
{ 91, 11, '.', nullptr },
|
||||
{ 104, 20, '>', nullptr }
|
||||
};
|
||||
for (int i = 0; i < 5; i++) {
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if (vx >= keys[i].x && vx < keys[i].x + keys[i].w) {
|
||||
processKey(keys[i].ch);
|
||||
return true;
|
||||
@@ -306,10 +500,17 @@ private:
|
||||
// Symbol/letter toggle
|
||||
_symbols = !_symbols;
|
||||
_shifted = false;
|
||||
} else if (ch == '\x02') {
|
||||
// Emoji picker toggle
|
||||
_emojiMode = !_emojiMode;
|
||||
_emojiScroll = 0;
|
||||
} else if (ch == '<') {
|
||||
// Backspace
|
||||
// Backspace — UTF-8 aware (walk back past continuation bytes 10xxxxxx)
|
||||
if (_textLen > 0) {
|
||||
_textLen--;
|
||||
while (_textLen > 0 && ((uint8_t)_text[_textLen] & 0xC0) == 0x80) {
|
||||
_textLen--;
|
||||
}
|
||||
_text[_textLen] = '\0';
|
||||
}
|
||||
} else if (ch == '>') {
|
||||
|
||||
@@ -0,0 +1,372 @@
|
||||
#pragma once
|
||||
|
||||
// =============================================================================
|
||||
// ApnDatabase.h - Embedded APN Lookup Table
|
||||
//
|
||||
// Maps MCC/MNC (Mobile Country Code / Mobile Network Code) to default APN
|
||||
// settings for common carriers worldwide. Compiled directly into flash (~3KB)
|
||||
// so users never need to manually install a lookup file.
|
||||
//
|
||||
// The modem queries IMSI via AT+CIMI to extract MCC (3 digits) + MNC (2-3
|
||||
// digits), then looks up the APN here. If not found, falls back to the
|
||||
// modem's existing PDP context (AT+CGDCONT?) or user-configured APN.
|
||||
//
|
||||
// To add a carrier: append to APN_DATABASE[] with the MCC+MNC as a single
|
||||
// integer. MNC can be 2 or 3 digits:
|
||||
// MCC=310, MNC=260 → mccmnc = 310260
|
||||
// MCC=505, MNC=01 → mccmnc = 50501
|
||||
//
|
||||
// Guard: HAS_4G_MODEM
|
||||
// =============================================================================
|
||||
|
||||
#ifdef HAS_4G_MODEM
|
||||
|
||||
#ifndef APN_DATABASE_H
|
||||
#define APN_DATABASE_H
|
||||
|
||||
struct ApnEntry {
|
||||
uint32_t mccmnc; // MCC+MNC as integer (e.g. 310260 for T-Mobile US)
|
||||
const char* apn; // APN string
|
||||
const char* carrier; // Human-readable carrier name (for debug/display)
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// APN Database — sorted by MCC for binary search potential (not required)
|
||||
//
|
||||
// Sources: carrier documentation, GSMA databases, community wikis.
|
||||
// This covers ~120 major carriers across key regions. Users with less
|
||||
// common carriers can set APN manually in Settings.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
static const ApnEntry APN_DATABASE[] = {
|
||||
// =========================================================================
|
||||
// Australia (MCC 505)
|
||||
// =========================================================================
|
||||
{ 50501, "telstra.internet", "Telstra" },
|
||||
{ 50502, "yesinternet", "Optus" },
|
||||
{ 50503, "vfinternet.au", "Vodafone AU" },
|
||||
{ 50506, "3netaccess", "Three AU" },
|
||||
{ 50507, "telstra.internet", "Vodafone AU (MVNO)" }, // Many MVNOs on Telstra
|
||||
{ 50510, "telstra.internet", "Norfolk Tel" },
|
||||
{ 50512, "3netaccess", "Amaysim" }, // Optus MVNO
|
||||
{ 50514, "yesinternet", "Aussie Broadband" }, // Optus MVNO
|
||||
{ 50590, "yesinternet", "Optus MVNO" },
|
||||
|
||||
// =========================================================================
|
||||
// New Zealand (MCC 530)
|
||||
// =========================================================================
|
||||
{ 53001, "internet", "Vodafone NZ" },
|
||||
{ 53005, "internet", "Spark NZ" },
|
||||
{ 53024, "internet", "2degrees" },
|
||||
|
||||
// =========================================================================
|
||||
// United States (MCC 310, 311, 312, 313, 316)
|
||||
// =========================================================================
|
||||
{ 310012, "fast.t-mobile.com", "Verizon (old)" },
|
||||
{ 310026, "fast.t-mobile.com", "T-Mobile US" },
|
||||
{ 310030, "fast.t-mobile.com", "T-Mobile US" },
|
||||
{ 310032, "fast.t-mobile.com", "T-Mobile US" },
|
||||
{ 310060, "fast.t-mobile.com", "T-Mobile US" },
|
||||
{ 310160, "fast.t-mobile.com", "T-Mobile US" },
|
||||
{ 310200, "fast.t-mobile.com", "T-Mobile US" },
|
||||
{ 310210, "fast.t-mobile.com", "T-Mobile US" },
|
||||
{ 310220, "fast.t-mobile.com", "T-Mobile US" },
|
||||
{ 310230, "fast.t-mobile.com", "T-Mobile US" },
|
||||
{ 310240, "fast.t-mobile.com", "T-Mobile US" },
|
||||
{ 310250, "fast.t-mobile.com", "T-Mobile US" },
|
||||
{ 310260, "fast.t-mobile.com", "T-Mobile US" },
|
||||
{ 310270, "fast.t-mobile.com", "T-Mobile US" },
|
||||
{ 310310, "fast.t-mobile.com", "T-Mobile US" },
|
||||
{ 310490, "fast.t-mobile.com", "T-Mobile US" },
|
||||
{ 310530, "fast.t-mobile.com", "T-Mobile US" },
|
||||
{ 310580, "fast.t-mobile.com", "T-Mobile US" },
|
||||
{ 310660, "fast.t-mobile.com", "T-Mobile US" },
|
||||
{ 310800, "fast.t-mobile.com", "T-Mobile US" },
|
||||
{ 311480, "vzwinternet", "Verizon" },
|
||||
{ 311481, "vzwinternet", "Verizon" },
|
||||
{ 311482, "vzwinternet", "Verizon" },
|
||||
{ 311483, "vzwinternet", "Verizon" },
|
||||
{ 311484, "vzwinternet", "Verizon" },
|
||||
{ 311489, "vzwinternet", "Verizon" },
|
||||
{ 310410, "fast.t-mobile.com", "AT&T (migrated)" },
|
||||
{ 310120, "att.mvno", "AT&T (Sprint)" },
|
||||
{ 312530, "iot.1nce.net", "1NCE IoT" },
|
||||
{ 310120, "tfdata", "Tracfone" },
|
||||
|
||||
// =========================================================================
|
||||
// Canada (MCC 302)
|
||||
// =========================================================================
|
||||
{ 30220, "internet.com", "Rogers" },
|
||||
{ 30221, "internet.com", "Rogers" },
|
||||
{ 30237, "internet.com", "Rogers" },
|
||||
{ 30272, "internet.com", "Rogers" },
|
||||
{ 30234, "sp.telus.com", "Telus" },
|
||||
{ 30286, "sp.telus.com", "Telus" },
|
||||
{ 30236, "sp.telus.com", "Telus" },
|
||||
{ 30261, "sp.bell.ca", "Bell" },
|
||||
{ 30263, "sp.bell.ca", "Bell" },
|
||||
{ 30267, "sp.bell.ca", "Bell" },
|
||||
{ 30268, "fido-core-appl1.apn", "Fido" },
|
||||
{ 30278, "internet.com", "SaskTel" },
|
||||
{ 30266, "sp.mb.com", "MTS" },
|
||||
|
||||
// =========================================================================
|
||||
// United Kingdom (MCC 234, 235)
|
||||
// =========================================================================
|
||||
{ 23410, "o2-internet", "O2 UK" },
|
||||
{ 23415, "three.co.uk", "Vodafone UK" },
|
||||
{ 23420, "three.co.uk", "Three UK" },
|
||||
{ 23430, "everywhere", "EE" },
|
||||
{ 23431, "everywhere", "EE" },
|
||||
{ 23432, "everywhere", "EE" },
|
||||
{ 23433, "everywhere", "EE" },
|
||||
{ 23450, "data.lycamobile.co.uk","Lycamobile UK" },
|
||||
{ 23486, "three.co.uk", "Three UK" },
|
||||
|
||||
// =========================================================================
|
||||
// Germany (MCC 262)
|
||||
// =========================================================================
|
||||
{ 26201, "internet.t-mobile", "Telekom DE" },
|
||||
{ 26202, "web.vodafone.de", "Vodafone DE" },
|
||||
{ 26203, "internet", "O2 DE" },
|
||||
{ 26207, "internet", "O2 DE" },
|
||||
|
||||
// =========================================================================
|
||||
// France (MCC 208)
|
||||
// =========================================================================
|
||||
{ 20801, "orange", "Orange FR" },
|
||||
{ 20810, "sl2sfr", "SFR" },
|
||||
{ 20815, "free", "Free Mobile" },
|
||||
{ 20820, "ofnew.fr", "Bouygues" },
|
||||
|
||||
// =========================================================================
|
||||
// Italy (MCC 222)
|
||||
// =========================================================================
|
||||
{ 22201, "mobile.vodafone.it", "TIM" },
|
||||
{ 22210, "mobile.vodafone.it", "Vodafone IT" },
|
||||
{ 22250, "internet.it", "Iliad IT" },
|
||||
{ 22288, "internet.wind", "WindTre" },
|
||||
{ 22299, "internet.wind", "WindTre" },
|
||||
|
||||
// =========================================================================
|
||||
// Spain (MCC 214)
|
||||
// =========================================================================
|
||||
{ 21401, "internet", "Vodafone ES" },
|
||||
{ 21403, "internet", "Orange ES" },
|
||||
{ 21404, "internet", "Yoigo" },
|
||||
{ 21407, "internet", "Movistar" },
|
||||
|
||||
// =========================================================================
|
||||
// Netherlands (MCC 204)
|
||||
// =========================================================================
|
||||
{ 20404, "internet", "Vodafone NL" },
|
||||
{ 20408, "internet", "KPN" },
|
||||
{ 20412, "internet", "Telfort" },
|
||||
{ 20416, "internet", "T-Mobile NL" },
|
||||
{ 20420, "internet", "T-Mobile NL" },
|
||||
|
||||
// =========================================================================
|
||||
// Sweden (MCC 240)
|
||||
// =========================================================================
|
||||
{ 24001, "internet.telia.se", "Telia SE" },
|
||||
{ 24002, "tre.se", "Three SE" },
|
||||
{ 24007, "internet.telenor.se", "Telenor SE" },
|
||||
|
||||
// =========================================================================
|
||||
// Norway (MCC 242)
|
||||
// =========================================================================
|
||||
{ 24201, "internet.telenor.no", "Telenor NO" },
|
||||
{ 24202, "internet.netcom.no", "Telia NO" },
|
||||
|
||||
// =========================================================================
|
||||
// Denmark (MCC 238)
|
||||
// =========================================================================
|
||||
{ 23801, "internet", "TDC" },
|
||||
{ 23802, "internet", "Telenor DK" },
|
||||
{ 23806, "internet", "Three DK" },
|
||||
{ 23820, "internet", "Telia DK" },
|
||||
|
||||
// =========================================================================
|
||||
// Switzerland (MCC 228)
|
||||
// =========================================================================
|
||||
{ 22801, "gprs.swisscom.ch", "Swisscom" },
|
||||
{ 22802, "internet", "Sunrise" },
|
||||
{ 22803, "internet", "Salt" },
|
||||
|
||||
// =========================================================================
|
||||
// Austria (MCC 232)
|
||||
// =========================================================================
|
||||
{ 23201, "a1.net", "A1" },
|
||||
{ 23203, "web.one.at", "Three AT" },
|
||||
{ 23205, "web", "T-Mobile AT" },
|
||||
|
||||
// =========================================================================
|
||||
// Japan (MCC 440, 441)
|
||||
// =========================================================================
|
||||
{ 44010, "spmode.ne.jp", "NTT Docomo" },
|
||||
{ 44020, "plus.4g", "SoftBank" },
|
||||
{ 44051, "au.au-net.ne.jp", "KDDI au" },
|
||||
|
||||
// =========================================================================
|
||||
// South Korea (MCC 450)
|
||||
// =========================================================================
|
||||
{ 45005, "lte.sktelecom.com", "SK Telecom" },
|
||||
{ 45006, "lte.ktfwing.com", "KT" },
|
||||
{ 45008, "lte.lguplus.co.kr", "LG U+" },
|
||||
|
||||
// =========================================================================
|
||||
// India (MCC 404, 405)
|
||||
// =========================================================================
|
||||
{ 40445, "airtelgprs.com", "Airtel" },
|
||||
{ 40410, "airtelgprs.com", "Airtel" },
|
||||
{ 40411, "www", "Vodafone IN (Vi)" },
|
||||
{ 40413, "www", "Vodafone IN (Vi)" },
|
||||
{ 40486, "www", "Vodafone IN (Vi)" },
|
||||
{ 40553, "jionet", "Jio" },
|
||||
{ 40554, "jionet", "Jio" },
|
||||
{ 40512, "bsnlnet", "BSNL" },
|
||||
|
||||
// =========================================================================
|
||||
// Singapore (MCC 525)
|
||||
// =========================================================================
|
||||
{ 52501, "internet", "Singtel" },
|
||||
{ 52503, "internet", "M1" },
|
||||
{ 52505, "internet", "StarHub" },
|
||||
|
||||
// =========================================================================
|
||||
// Hong Kong (MCC 454)
|
||||
// =========================================================================
|
||||
{ 45400, "internet", "CSL" },
|
||||
{ 45406, "internet", "SmarTone" },
|
||||
{ 45412, "internet", "CMHK" },
|
||||
|
||||
// =========================================================================
|
||||
// Brazil (MCC 724)
|
||||
// =========================================================================
|
||||
{ 72405, "claro.com.br", "Claro BR" },
|
||||
{ 72406, "wap.oi.com.br", "Vivo" },
|
||||
{ 72410, "wap.oi.com.br", "Vivo" },
|
||||
{ 72411, "wap.oi.com.br", "Vivo" },
|
||||
{ 72415, "internet.tim.br", "TIM BR" },
|
||||
{ 72431, "gprs.oi.com.br", "Oi" },
|
||||
|
||||
// =========================================================================
|
||||
// Mexico (MCC 334)
|
||||
// =========================================================================
|
||||
{ 33402, "internet.itelcel.com","Telcel" },
|
||||
{ 33403, "internet.movistar.mx","Movistar MX" },
|
||||
{ 33404, "internet.att.net.mx", "AT&T MX" },
|
||||
|
||||
// =========================================================================
|
||||
// South Africa (MCC 655)
|
||||
// =========================================================================
|
||||
{ 65501, "internet", "Vodacom" },
|
||||
{ 65502, "internet", "Telkom ZA" },
|
||||
{ 65507, "internet", "Cell C" },
|
||||
{ 65510, "internet", "MTN ZA" },
|
||||
|
||||
// =========================================================================
|
||||
// Philippines (MCC 515)
|
||||
// =========================================================================
|
||||
{ 51502, "internet.globe.com.ph","Globe" },
|
||||
{ 51503, "internet", "Smart" },
|
||||
{ 51505, "internet", "Sun Cellular" },
|
||||
|
||||
// =========================================================================
|
||||
// Thailand (MCC 520)
|
||||
// =========================================================================
|
||||
{ 52001, "internet", "AIS" },
|
||||
{ 52004, "internet", "TrueMove" },
|
||||
{ 52005, "internet", "dtac" },
|
||||
|
||||
// =========================================================================
|
||||
// Indonesia (MCC 510)
|
||||
// =========================================================================
|
||||
{ 51001, "internet", "Telkomsel" },
|
||||
{ 51010, "internet", "Telkomsel" },
|
||||
{ 51011, "3gprs", "XL Axiata" },
|
||||
{ 51028, "3gprs", "XL Axiata (Axis)" },
|
||||
|
||||
// =========================================================================
|
||||
// Malaysia (MCC 502)
|
||||
// =========================================================================
|
||||
{ 50212, "celcom3g", "Celcom" },
|
||||
{ 50213, "celcom3g", "Celcom" },
|
||||
{ 50216, "internet", "Digi" },
|
||||
{ 50219, "celcom3g", "Celcom" },
|
||||
|
||||
// =========================================================================
|
||||
// Czech Republic (MCC 230)
|
||||
// =========================================================================
|
||||
{ 23001, "internet.t-mobile.cz","T-Mobile CZ" },
|
||||
{ 23002, "internet", "O2 CZ" },
|
||||
{ 23003, "internet.vodafone.cz","Vodafone CZ" },
|
||||
|
||||
// =========================================================================
|
||||
// Poland (MCC 260)
|
||||
// =========================================================================
|
||||
{ 26001, "internet", "Plus PL" },
|
||||
{ 26002, "internet", "T-Mobile PL" },
|
||||
{ 26003, "internet", "Orange PL" },
|
||||
{ 26006, "internet", "Play" },
|
||||
|
||||
// =========================================================================
|
||||
// Portugal (MCC 268)
|
||||
// =========================================================================
|
||||
{ 26801, "internet", "Vodafone PT" },
|
||||
{ 26803, "internet", "NOS" },
|
||||
{ 26806, "internet", "MEO" },
|
||||
|
||||
// =========================================================================
|
||||
// Ireland (MCC 272)
|
||||
// =========================================================================
|
||||
{ 27201, "internet", "Vodafone IE" },
|
||||
{ 27202, "open.internet", "Three IE" },
|
||||
{ 27205, "three.ie", "Three IE" },
|
||||
|
||||
// =========================================================================
|
||||
// IoT / Global SIMs
|
||||
// =========================================================================
|
||||
{ 901028, "iot.1nce.net", "1NCE (IoT)" },
|
||||
{ 90143, "hologram", "Hologram" },
|
||||
};
|
||||
|
||||
#define APN_DATABASE_SIZE (sizeof(APN_DATABASE) / sizeof(APN_DATABASE[0]))
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Lookup function — returns nullptr if not found
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
inline const ApnEntry* apnLookup(uint32_t mccmnc) {
|
||||
for (int i = 0; i < (int)APN_DATABASE_SIZE; i++) {
|
||||
if (APN_DATABASE[i].mccmnc == mccmnc) {
|
||||
return &APN_DATABASE[i];
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Parse IMSI string into MCC+MNC. Tries 3-digit MNC first (6-digit mccmnc),
|
||||
// falls back to 2-digit MNC (5-digit mccmnc) if not found.
|
||||
inline const ApnEntry* apnLookupFromIMSI(const char* imsi) {
|
||||
if (!imsi || strlen(imsi) < 5) return nullptr;
|
||||
|
||||
// Extract MCC (always 3 digits)
|
||||
uint32_t mcc = (imsi[0] - '0') * 100 + (imsi[1] - '0') * 10 + (imsi[2] - '0');
|
||||
|
||||
// Try 3-digit MNC first (more specific)
|
||||
if (strlen(imsi) >= 6) {
|
||||
uint32_t mnc3 = (imsi[3] - '0') * 100 + (imsi[4] - '0') * 10 + (imsi[5] - '0');
|
||||
uint32_t mccmnc6 = mcc * 1000 + mnc3;
|
||||
const ApnEntry* entry = apnLookup(mccmnc6);
|
||||
if (entry) return entry;
|
||||
}
|
||||
|
||||
// Fall back to 2-digit MNC
|
||||
uint32_t mnc2 = (imsi[3] - '0') * 10 + (imsi[4] - '0');
|
||||
uint32_t mccmnc5 = mcc * 100 + mnc2;
|
||||
return apnLookup(mccmnc5);
|
||||
}
|
||||
|
||||
#endif // APN_DATABASE_H
|
||||
#endif // HAS_4G_MODEM
|
||||
@@ -0,0 +1,227 @@
|
||||
#pragma once
|
||||
|
||||
// =============================================================================
|
||||
// CellularMQTT — A7682E Modem + MQTT via native AT commands
|
||||
// =============================================================================
|
||||
|
||||
#ifdef HAS_4G_MODEM
|
||||
|
||||
#ifndef CELLULAR_MQTT_H
|
||||
#define CELLULAR_MQTT_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <freertos/queue.h>
|
||||
#include <freertos/semphr.h>
|
||||
#include "variant.h"
|
||||
#include "ApnDatabase.h"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Configuration
|
||||
// ---------------------------------------------------------------------------
|
||||
#define MQTT_TOPIC_MAX 80
|
||||
#define MQTT_PAYLOAD_MAX 512
|
||||
#define MQTT_CLIENT_ID_MAX 32
|
||||
|
||||
#define CMD_QUEUE_SIZE 4
|
||||
#define RSP_QUEUE_SIZE 4
|
||||
|
||||
#define TELEMETRY_INTERVAL 60000
|
||||
|
||||
#define CELL_TASK_PRIORITY 1
|
||||
#define CELL_TASK_STACK_SIZE 8192
|
||||
#define CELL_TASK_CORE 0
|
||||
|
||||
#define MQTT_RECONNECT_MIN 5000
|
||||
#define MQTT_RECONNECT_MAX 300000
|
||||
|
||||
#define MQTT_PUB_FAIL_MAX 5
|
||||
|
||||
#define OTA_CHUNK_SIZE 1024
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// State machine
|
||||
// ---------------------------------------------------------------------------
|
||||
enum class CellState : uint8_t {
|
||||
OFF,
|
||||
POWERING_ON,
|
||||
INITIALIZING,
|
||||
REGISTERING,
|
||||
DATA_ACTIVATING,
|
||||
MQTT_STARTING,
|
||||
MQTT_CONNECTING,
|
||||
CONNECTED,
|
||||
RECONNECTING,
|
||||
OTA_IN_PROGRESS,
|
||||
ERROR
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Queue message types
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
struct MQTTCommand {
|
||||
char cmd[MQTT_PAYLOAD_MAX];
|
||||
};
|
||||
|
||||
struct MQTTResponse {
|
||||
char topic[MQTT_TOPIC_MAX];
|
||||
char payload[MQTT_PAYLOAD_MAX];
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// MQTT config (loaded from SD: /remote/mqtt.cfg)
|
||||
// ---------------------------------------------------------------------------
|
||||
struct MQTTConfig {
|
||||
char broker[80];
|
||||
uint16_t port;
|
||||
char username[40];
|
||||
char password[40];
|
||||
char deviceId[MQTT_CLIENT_ID_MAX];
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Telemetry snapshot
|
||||
// ---------------------------------------------------------------------------
|
||||
struct TelemetryData {
|
||||
uint32_t uptime_secs;
|
||||
uint16_t battery_mv;
|
||||
uint8_t battery_pct;
|
||||
int16_t temperature;
|
||||
int csq;
|
||||
uint8_t neighbor_count;
|
||||
float freq;
|
||||
float bw;
|
||||
uint8_t sf;
|
||||
uint8_t cr;
|
||||
uint8_t tx_power;
|
||||
char node_name[32];
|
||||
char apn[40];
|
||||
char oper[24];
|
||||
bool mqtt_connected;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// CellularMQTT class
|
||||
// ---------------------------------------------------------------------------
|
||||
class CellularMQTT {
|
||||
public:
|
||||
void begin();
|
||||
void stop();
|
||||
|
||||
// --- Queue API (called from main loop) ---
|
||||
bool recvCommand(MQTTCommand& out);
|
||||
bool sendResponse(const char* topic, const char* payload);
|
||||
|
||||
// --- Telemetry ---
|
||||
void updateTelemetry(const TelemetryData& data);
|
||||
|
||||
// --- OTA ---
|
||||
void requestOTA(const char* url);
|
||||
bool isOTAInProgress() const { return _state == CellState::OTA_IN_PROGRESS; }
|
||||
|
||||
// --- State queries ---
|
||||
CellState getState() const { return _state; }
|
||||
bool isConnected() const { return _state == CellState::CONNECTED; }
|
||||
int getCSQ() const { return _csq; }
|
||||
int getSignalBars() const;
|
||||
const char* getOperator() const { return _operator; }
|
||||
const char* getIPAddress() const { return _ipAddr; }
|
||||
const char* getBroker() const { return _config.broker; }
|
||||
const char* getAPN() const { return _apn; }
|
||||
const char* getRspTopic() const { return _topicRsp; }
|
||||
const char* stateString() const;
|
||||
uint32_t getLastCmdTime() const { return _lastCmdTime; }
|
||||
|
||||
static bool loadConfig(MQTTConfig& cfg);
|
||||
|
||||
private:
|
||||
volatile CellState _state = CellState::OFF;
|
||||
volatile int _csq = 99;
|
||||
volatile uint32_t _lastCmdTime = 0;
|
||||
|
||||
char _operator[24] = {0};
|
||||
char _ipAddr[20] = {0};
|
||||
char _imei[20] = {0};
|
||||
char _imsi[20] = {0};
|
||||
char _apn[64] = {0};
|
||||
|
||||
MQTTConfig _config = {};
|
||||
TelemetryData _telemetry = {};
|
||||
SemaphoreHandle_t _telemetryMutex = nullptr;
|
||||
|
||||
char _topicCmd[MQTT_TOPIC_MAX] = {0};
|
||||
char _topicRsp[MQTT_TOPIC_MAX] = {0};
|
||||
char _topicTelem[MQTT_TOPIC_MAX] = {0};
|
||||
char _topicOta[MQTT_TOPIC_MAX] = {0};
|
||||
|
||||
TaskHandle_t _taskHandle = nullptr;
|
||||
QueueHandle_t _cmdQueue = nullptr;
|
||||
QueueHandle_t _rspQueue = nullptr;
|
||||
SemaphoreHandle_t _uartMutex = nullptr;
|
||||
|
||||
uint8_t _pubFailCount = 0;
|
||||
|
||||
static const int AT_BUF_SIZE = 512;
|
||||
char _atBuf[AT_BUF_SIZE];
|
||||
|
||||
static const int URC_BUF_SIZE = 600;
|
||||
char _urcBuf[URC_BUF_SIZE];
|
||||
int _urcPos = 0;
|
||||
|
||||
enum MqttRxState { RX_IDLE, RX_WAIT_TOPIC, RX_WAIT_PAYLOAD };
|
||||
MqttRxState _rxState = RX_IDLE;
|
||||
int _rxTopicLen = 0;
|
||||
int _rxPayloadLen = 0;
|
||||
char _rxTopic[MQTT_TOPIC_MAX];
|
||||
char _rxPayload[MQTT_PAYLOAD_MAX];
|
||||
|
||||
uint32_t _reconnectDelay = MQTT_RECONNECT_MIN;
|
||||
|
||||
// OTA state
|
||||
volatile bool _otaPending = false;
|
||||
char _otaUrl[256] = {0};
|
||||
|
||||
// --- Modem UART helpers ---
|
||||
bool modemPowerOn();
|
||||
bool sendAT(const char* cmd, const char* expect, uint32_t timeout_ms = 2000);
|
||||
bool waitResponse(const char* expect, uint32_t timeout_ms, char* buf = nullptr, size_t bufLen = 0);
|
||||
bool waitPrompt(uint32_t timeout_ms = 5000);
|
||||
void drainURCs();
|
||||
void processURCLine(const char* line);
|
||||
|
||||
// --- Data connection ---
|
||||
void resolveAPN();
|
||||
bool activateData();
|
||||
|
||||
// --- MQTT operations ---
|
||||
bool mqttStart();
|
||||
bool mqttConnect();
|
||||
bool mqttSubscribe(const char* topic);
|
||||
bool mqttPublish(const char* topic, const char* payload);
|
||||
void mqttDisconnect();
|
||||
|
||||
// --- URC handlers ---
|
||||
void handleMqttRxStart(const char* line);
|
||||
void handleMqttRxTopic(const char* data, int len);
|
||||
void handleMqttRxPayload(const char* data, int len);
|
||||
void handleMqttRxEnd();
|
||||
void handleMqttConnLost(const char* line);
|
||||
|
||||
// --- OTA operations (modem task only) ---
|
||||
void performOTA();
|
||||
int httpGet(const char* url);
|
||||
bool httpReadChunk(int offset, int len, uint8_t* dest, int* bytesRead);
|
||||
void httpTerm();
|
||||
int readRawBytes(uint8_t* dest, int count, uint32_t timeout_ms);
|
||||
|
||||
// --- Task ---
|
||||
static void taskEntry(void* param);
|
||||
void taskLoop();
|
||||
};
|
||||
|
||||
extern CellularMQTT cellularMQTT;
|
||||
|
||||
#endif // CELLULAR_MQTT_H
|
||||
#endif // HAS_4G_MODEM
|
||||
+1076
-1927
File diff suppressed because it is too large
Load Diff
@@ -68,11 +68,11 @@ struct NeighbourInfo {
|
||||
};
|
||||
|
||||
#ifndef FIRMWARE_BUILD_DATE
|
||||
#define FIRMWARE_BUILD_DATE "30 Nov 2025"
|
||||
#define FIRMWARE_BUILD_DATE "3 April 2026"
|
||||
#endif
|
||||
|
||||
#ifndef FIRMWARE_VERSION
|
||||
#define FIRMWARE_VERSION "v1.11.0"
|
||||
#define FIRMWARE_VERSION "v0.2"
|
||||
#endif
|
||||
|
||||
#define FIRMWARE_ROLE "repeater"
|
||||
|
||||
@@ -2,7 +2,21 @@
|
||||
#include <Arduino.h>
|
||||
#include <helpers/CommonCLI.h>
|
||||
|
||||
#define AUTO_OFF_MILLIS 20000 // 20 seconds
|
||||
#ifdef HAS_4G_MODEM
|
||||
#include "CellularMQTT.h"
|
||||
#endif
|
||||
|
||||
#ifdef MECK_WIFI_REMOTE
|
||||
#include "WiFiMQTT.h"
|
||||
#endif
|
||||
|
||||
#if defined(HAS_4G_MODEM) || defined(MECK_WIFI_REMOTE)
|
||||
#define AUTO_OFF_DISABLED true
|
||||
#else
|
||||
#define AUTO_OFF_DISABLED false
|
||||
#endif
|
||||
|
||||
#define AUTO_OFF_MILLIS 20000 // 20 seconds (ignored when AUTO_OFF_DISABLED)
|
||||
#define BOOT_SCREEN_MILLIS 4000 // 4 seconds
|
||||
|
||||
// 'meshcore', 128x13px
|
||||
@@ -28,55 +42,144 @@ void UITask::begin(NodePrefs* node_prefs, const char* build_date, const char* fi
|
||||
_node_prefs = node_prefs;
|
||||
_display->turnOn();
|
||||
|
||||
// strip off dash and commit hash by changing dash to null terminator
|
||||
// e.g: v1.2.3-abcdef -> v1.2.3
|
||||
char *version = strdup(firmware_version);
|
||||
char *dash = strchr(version, '-');
|
||||
if(dash){
|
||||
*dash = 0;
|
||||
}
|
||||
if (dash) *dash = 0;
|
||||
|
||||
// v1.2.3 (1 Jan 2025)
|
||||
sprintf(_version_info, "%s (%s)", version, build_date);
|
||||
snprintf(_version_info, sizeof(_version_info), "%s (%s)", version, build_date);
|
||||
free(version);
|
||||
}
|
||||
|
||||
void UITask::renderCurrScreen() {
|
||||
char tmp[80];
|
||||
if (millis() < BOOT_SCREEN_MILLIS) { // boot screen
|
||||
// meshcore logo
|
||||
if (millis() < BOOT_SCREEN_MILLIS) {
|
||||
// Boot screen — logo + version
|
||||
_display->setColor(DisplayDriver::BLUE);
|
||||
int logoWidth = 128;
|
||||
_display->drawXbm((_display->width() - logoWidth) / 2, 3, meshcore_logo, logoWidth, 13);
|
||||
|
||||
// version info
|
||||
_display->setColor(DisplayDriver::LIGHT);
|
||||
_display->setTextSize(1);
|
||||
uint16_t versionWidth = _display->getTextWidth(_version_info);
|
||||
_display->setCursor((_display->width() - versionWidth) / 2, 22);
|
||||
_display->print(_version_info);
|
||||
|
||||
// node type
|
||||
#if defined(HAS_4G_MODEM)
|
||||
const char* node_type = "< Remote Repeater >";
|
||||
#elif defined(MECK_WIFI_REMOTE)
|
||||
const char* node_type = "< WiFi Repeater >";
|
||||
#else
|
||||
const char* node_type = "< Repeater >";
|
||||
#endif
|
||||
uint16_t typeWidth = _display->getTextWidth(node_type);
|
||||
_display->setCursor((_display->width() - typeWidth) / 2, 35);
|
||||
_display->print(node_type);
|
||||
} else { // home screen
|
||||
// node name
|
||||
} else {
|
||||
// Home screen — node info + connection status
|
||||
_display->setCursor(0, 0);
|
||||
_display->setTextSize(1);
|
||||
_display->setColor(DisplayDriver::GREEN);
|
||||
_display->print(_node_prefs->node_name);
|
||||
|
||||
// freq / sf
|
||||
_display->setCursor(0, 20);
|
||||
_display->setColor(DisplayDriver::YELLOW);
|
||||
sprintf(tmp, "FREQ: %06.3f SF%d", _node_prefs->freq, _node_prefs->sf);
|
||||
_display->print(tmp);
|
||||
|
||||
// bw / cr
|
||||
_display->setCursor(0, 30);
|
||||
sprintf(tmp, "BW: %03.2f CR: %d", _node_prefs->bw, _node_prefs->cr);
|
||||
_display->print(tmp);
|
||||
|
||||
// --- Cellular status (4G variant) ---
|
||||
#ifdef HAS_4G_MODEM
|
||||
int y = 44;
|
||||
|
||||
_display->setCursor(0, y);
|
||||
_display->setColor(DisplayDriver::LIGHT);
|
||||
sprintf(tmp, "4G: %s", cellularMQTT.stateString());
|
||||
_display->print(tmp);
|
||||
y += 10;
|
||||
|
||||
_display->setCursor(0, y);
|
||||
sprintf(tmp, "CSQ: %d (%d bars)", cellularMQTT.getCSQ(), cellularMQTT.getSignalBars());
|
||||
_display->print(tmp);
|
||||
y += 10;
|
||||
|
||||
const char* oper = cellularMQTT.getOperator();
|
||||
if (oper[0]) {
|
||||
_display->setCursor(0, y);
|
||||
sprintf(tmp, "Op: %.16s", oper);
|
||||
_display->print(tmp);
|
||||
y += 10;
|
||||
}
|
||||
|
||||
_display->setCursor(0, y);
|
||||
_display->setColor(cellularMQTT.isConnected() ? DisplayDriver::GREEN : DisplayDriver::YELLOW);
|
||||
sprintf(tmp, "MQTT: %s", cellularMQTT.isConnected() ? "Connected" : "---");
|
||||
_display->print(tmp);
|
||||
y += 10;
|
||||
|
||||
const char* ip4g = cellularMQTT.getIPAddress();
|
||||
if (ip4g[0]) {
|
||||
_display->setColor(DisplayDriver::LIGHT);
|
||||
_display->setCursor(0, y);
|
||||
sprintf(tmp, "IP: %s", ip4g);
|
||||
_display->print(tmp);
|
||||
y += 10;
|
||||
}
|
||||
|
||||
uint32_t upSec = millis() / 1000;
|
||||
uint32_t upH = upSec / 3600;
|
||||
uint32_t upM = (upSec % 3600) / 60;
|
||||
_display->setColor(DisplayDriver::LIGHT);
|
||||
_display->setCursor(0, y);
|
||||
sprintf(tmp, "Up: %luh %lum Heap:%dk", upH, upM, ESP.getFreeHeap() / 1024);
|
||||
_display->print(tmp);
|
||||
#endif
|
||||
|
||||
// --- WiFi status (WiFi variant) ---
|
||||
#ifdef MECK_WIFI_REMOTE
|
||||
int y = 44;
|
||||
|
||||
_display->setCursor(0, y);
|
||||
_display->setColor(DisplayDriver::LIGHT);
|
||||
sprintf(tmp, "WiFi: %s", wifiMQTT.stateString());
|
||||
_display->print(tmp);
|
||||
y += 10;
|
||||
|
||||
_display->setCursor(0, y);
|
||||
sprintf(tmp, "RSSI: %d (%d bars)", wifiMQTT.getRSSI(), wifiMQTT.getSignalBars());
|
||||
_display->print(tmp);
|
||||
y += 10;
|
||||
|
||||
_display->setCursor(0, y);
|
||||
sprintf(tmp, "SSID: %.16s", wifiMQTT.getSSID());
|
||||
_display->print(tmp);
|
||||
y += 10;
|
||||
|
||||
_display->setCursor(0, y);
|
||||
_display->setColor(wifiMQTT.isConnected() ? DisplayDriver::GREEN : DisplayDriver::YELLOW);
|
||||
sprintf(tmp, "MQTT: %s", wifiMQTT.isConnected() ? "Connected" : "---");
|
||||
_display->print(tmp);
|
||||
y += 10;
|
||||
|
||||
const char* ipWifi = wifiMQTT.getIPAddress();
|
||||
if (ipWifi[0]) {
|
||||
_display->setColor(DisplayDriver::LIGHT);
|
||||
_display->setCursor(0, y);
|
||||
sprintf(tmp, "IP: %s", ipWifi);
|
||||
_display->print(tmp);
|
||||
y += 10;
|
||||
}
|
||||
|
||||
uint32_t upSec = millis() / 1000;
|
||||
uint32_t upH = upSec / 3600;
|
||||
uint32_t upM = (upSec % 3600) / 60;
|
||||
_display->setColor(DisplayDriver::LIGHT);
|
||||
_display->setCursor(0, y);
|
||||
sprintf(tmp, "Up: %luh %lum Heap:%dk", upH, upM, ESP.getFreeHeap() / 1024);
|
||||
_display->print(tmp);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,17 +188,15 @@ void UITask::loop() {
|
||||
if (millis() >= _next_read) {
|
||||
int btnState = digitalRead(PIN_USER_BTN);
|
||||
if (btnState != _prevBtnState) {
|
||||
if (btnState == LOW) { // pressed?
|
||||
if (_display->isOn()) {
|
||||
// TODO: any action ?
|
||||
} else {
|
||||
if (btnState == LOW) {
|
||||
if (!_display->isOn()) {
|
||||
_display->turnOn();
|
||||
}
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS; // extend auto-off timer
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||
}
|
||||
_prevBtnState = btnState;
|
||||
}
|
||||
_next_read = millis() + 200; // 5 reads per second
|
||||
_next_read = millis() + 200;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -105,10 +206,10 @@ void UITask::loop() {
|
||||
renderCurrScreen();
|
||||
_display->endFrame();
|
||||
|
||||
_next_refresh = millis() + 1000; // refresh every second
|
||||
_next_refresh = millis() + 10000;
|
||||
}
|
||||
if (millis() > _auto_off) {
|
||||
if (!AUTO_OFF_DISABLED && millis() > _auto_off) {
|
||||
_display->turnOff();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ class UITask {
|
||||
unsigned long _next_read, _next_refresh, _auto_off;
|
||||
int _prevBtnState;
|
||||
NodePrefs* _node_prefs;
|
||||
char _version_info[32];
|
||||
char _version_info[48];
|
||||
|
||||
void renderCurrScreen();
|
||||
public:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,20 @@
|
||||
#include <Arduino.h> // needed for PlatformIO
|
||||
#include <Mesh.h>
|
||||
|
||||
#include <time.h>
|
||||
#include "MyMesh.h"
|
||||
|
||||
#ifdef HAS_4G_MODEM
|
||||
#include <SD.h>
|
||||
#include "CellularMQTT.h"
|
||||
#endif
|
||||
|
||||
#ifdef MECK_WIFI_REMOTE
|
||||
#if defined(HAS_SDCARD) || defined(SDCARD_CS)
|
||||
#include <SD.h>
|
||||
#endif
|
||||
#include "WiFiMQTT.h"
|
||||
#endif
|
||||
|
||||
#ifdef DISPLAY_CLASS
|
||||
#include "UITask.h"
|
||||
static UITask ui_task(display);
|
||||
@@ -23,6 +35,10 @@ static char command[160];
|
||||
unsigned long lastActive = 0; // mark last active time
|
||||
unsigned long nextSleepinSecs = 120; // next sleep in seconds. The first sleep (if enabled) is after 2 minutes from boot
|
||||
|
||||
#if (defined(HAS_4G_MODEM) || defined(MECK_WIFI_REMOTE)) && (defined(HAS_SDCARD) || defined(SDCARD_CS))
|
||||
static bool sdCardReady = false;
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
@@ -83,6 +99,72 @@ void setup() {
|
||||
|
||||
the_mesh.begin(fs);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// SD card init — needed for MQTT config on devices with SD slots.
|
||||
// T-Deck Pro: SD shares display SPI bus (HSPI via displaySpi)
|
||||
// T5S3: SD shares LoRa SPI bus (SCK=14, MOSI=13, MISO=21)
|
||||
// Heltec V4 and others without SD: config lives in SPIFFS (already init'd)
|
||||
// ---------------------------------------------------------------------------
|
||||
#if (defined(HAS_4G_MODEM) || defined(MECK_WIFI_REMOTE)) && (defined(HAS_SDCARD) || defined(SDCARD_CS))
|
||||
{
|
||||
// Deselect all SPI devices before SD init to prevent bus contention
|
||||
#ifdef SDCARD_CS
|
||||
pinMode(SDCARD_CS, OUTPUT);
|
||||
digitalWrite(SDCARD_CS, HIGH);
|
||||
#endif
|
||||
#ifdef PIN_DISPLAY_CS
|
||||
pinMode(PIN_DISPLAY_CS, OUTPUT);
|
||||
digitalWrite(PIN_DISPLAY_CS, HIGH);
|
||||
#endif
|
||||
#ifdef P_LORA_NSS
|
||||
pinMode(P_LORA_NSS, OUTPUT);
|
||||
digitalWrite(P_LORA_NSS, HIGH);
|
||||
#endif
|
||||
delay(100);
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro)
|
||||
// T5S3: SD shares LoRa SPI bus — create local HSPI reference
|
||||
static SPIClass sdSpi(HSPI);
|
||||
sdSpi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI, SDCARD_CS);
|
||||
if (SD.begin(SDCARD_CS, sdSpi, 4000000)) { sdCardReady = true; break; }
|
||||
#elif defined(SDCARD_CS)
|
||||
extern SPIClass displaySpi;
|
||||
if (SD.begin(SDCARD_CS, displaySpi)) { sdCardReady = true; break; }
|
||||
#else
|
||||
if (SD.begin(SPI_CS)) { sdCardReady = true; break; }
|
||||
#endif
|
||||
delay(200);
|
||||
}
|
||||
Serial.printf("SD card: %s\n", sdCardReady ? "ready" : "FAILED");
|
||||
}
|
||||
#endif
|
||||
|
||||
// Start MQTT backhaul
|
||||
#ifdef HAS_4G_MODEM
|
||||
if (sdCardReady) {
|
||||
cellularMQTT.begin();
|
||||
Serial.println("Cellular MQTT starting...");
|
||||
} else {
|
||||
Serial.println("Cellular MQTT skipped — no SD card for config");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MECK_WIFI_REMOTE
|
||||
#if defined(HAS_SDCARD) || defined(SDCARD_CS)
|
||||
if (sdCardReady) {
|
||||
wifiMQTT.begin();
|
||||
Serial.println("WiFi MQTT starting...");
|
||||
} else {
|
||||
Serial.println("WiFi MQTT skipped — no SD card for config");
|
||||
}
|
||||
#else
|
||||
// No SD card slot — config lives in SPIFFS (already initialized above)
|
||||
wifiMQTT.begin();
|
||||
Serial.println("WiFi MQTT starting (SPIFFS config)...");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef DISPLAY_CLASS
|
||||
ui_task.begin(the_mesh.getNodePrefs(), FIRMWARE_BUILD_DATE, FIRMWARE_VERSION);
|
||||
#endif
|
||||
@@ -118,6 +200,112 @@ void loop() {
|
||||
command[0] = 0; // reset command buffer
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// MQTT → CLI bridge: process incoming commands from MQTT (cellular)
|
||||
// ---------------------------------------------------------------------------
|
||||
#ifdef HAS_4G_MODEM
|
||||
{
|
||||
MQTTCommand mqttCmd;
|
||||
while (cellularMQTT.recvCommand(mqttCmd)) {
|
||||
Serial.printf("[MQTT] CLI: %s\n", mqttCmd.cmd);
|
||||
char reply[512];
|
||||
reply[0] = '\0';
|
||||
the_mesh.handleCommand((uint32_t)time(nullptr), mqttCmd.cmd, reply);
|
||||
|
||||
if (reply[0] == '\0') strcpy(reply, "OK");
|
||||
|
||||
cellularMQTT.sendResponse(cellularMQTT.getRspTopic(), reply);
|
||||
Serial.printf("[MQTT] Reply: %.80s\n", reply);
|
||||
}
|
||||
}
|
||||
|
||||
// Periodic telemetry snapshot for cellular MQTT
|
||||
{
|
||||
static unsigned long lastTelemUpdate = 0;
|
||||
if (millis() - lastTelemUpdate > 10000) {
|
||||
NodePrefs* p = the_mesh.getNodePrefs();
|
||||
TelemetryData td;
|
||||
memset(&td, 0, sizeof(td));
|
||||
td.uptime_secs = millis() / 1000;
|
||||
td.battery_mv = board.getBattMilliVolts();
|
||||
#ifdef HAS_BQ27220
|
||||
td.battery_pct = board.getBatteryPercent();
|
||||
td.temperature = board.getBattTemperature();
|
||||
#else
|
||||
td.battery_pct = 0;
|
||||
td.temperature = 0;
|
||||
#endif
|
||||
td.csq = cellularMQTT.getCSQ();
|
||||
td.freq = p->freq;
|
||||
td.bw = p->bw;
|
||||
td.sf = p->sf;
|
||||
td.cr = p->cr;
|
||||
td.tx_power = p->tx_power_dbm;
|
||||
strncpy(td.node_name, p->node_name, sizeof(td.node_name) - 1);
|
||||
strncpy(td.apn, cellularMQTT.getAPN(), sizeof(td.apn) - 1);
|
||||
strncpy(td.oper, cellularMQTT.getOperator(), sizeof(td.oper) - 1);
|
||||
td.mqtt_connected = cellularMQTT.isConnected();
|
||||
td.neighbor_count = 0; // TODO: expose from MyMesh
|
||||
|
||||
cellularMQTT.updateTelemetry(td);
|
||||
lastTelemUpdate = millis();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// MQTT → CLI bridge: process incoming commands from MQTT (WiFi)
|
||||
// ---------------------------------------------------------------------------
|
||||
#ifdef MECK_WIFI_REMOTE
|
||||
wifiMQTT.loop();
|
||||
|
||||
{
|
||||
MQTTCommand mqttCmd;
|
||||
while (wifiMQTT.recvCommand(mqttCmd)) {
|
||||
Serial.printf("[MQTT] CLI: %s\n", mqttCmd.cmd);
|
||||
char reply[512];
|
||||
reply[0] = '\0';
|
||||
the_mesh.handleCommand((uint32_t)time(nullptr), mqttCmd.cmd, reply);
|
||||
|
||||
if (reply[0] == '\0') strcpy(reply, "OK");
|
||||
|
||||
wifiMQTT.sendResponse(wifiMQTT.getRspTopic(), reply);
|
||||
Serial.printf("[MQTT] Reply: %.80s\n", reply);
|
||||
}
|
||||
}
|
||||
|
||||
// Periodic telemetry snapshot for WiFi MQTT
|
||||
{
|
||||
static unsigned long lastTelemUpdate = 0;
|
||||
if (millis() - lastTelemUpdate > 10000) {
|
||||
NodePrefs* p = the_mesh.getNodePrefs();
|
||||
TelemetryData td;
|
||||
memset(&td, 0, sizeof(td));
|
||||
td.uptime_secs = millis() / 1000;
|
||||
td.battery_mv = board.getBattMilliVolts();
|
||||
#ifdef HAS_BQ27220
|
||||
td.battery_pct = board.getBatteryPercent();
|
||||
td.temperature = board.getBattTemperature();
|
||||
#else
|
||||
td.battery_pct = 0;
|
||||
td.temperature = 0;
|
||||
#endif
|
||||
td.rssi = wifiMQTT.getRSSI();
|
||||
td.freq = p->freq;
|
||||
td.bw = p->bw;
|
||||
td.sf = p->sf;
|
||||
td.cr = p->cr;
|
||||
td.tx_power = p->tx_power_dbm;
|
||||
strncpy(td.node_name, p->node_name, sizeof(td.node_name) - 1);
|
||||
td.mqtt_connected = wifiMQTT.isConnected();
|
||||
td.neighbor_count = 0;
|
||||
|
||||
wifiMQTT.updateTelemetry(td);
|
||||
lastTelemUpdate = millis();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
the_mesh.loop();
|
||||
sensors.loop();
|
||||
#ifdef DISPLAY_CLASS
|
||||
@@ -125,14 +313,16 @@ void loop() {
|
||||
#endif
|
||||
rtc_clock.tick();
|
||||
|
||||
if (the_mesh.getNodePrefs()->powersaving_enabled && // To check if power saving is enabled
|
||||
the_mesh.millisHasNowPassed(lastActive + nextSleepinSecs * 1000)) { // To check if it is time to sleep
|
||||
if (!the_mesh.hasPendingWork()) { // No pending work. Safe to sleep
|
||||
board.sleep(1800); // To sleep. Wake up after 30 minutes or when receiving a LoRa packet
|
||||
#if !defined(HAS_4G_MODEM) && !defined(MECK_WIFI_REMOTE)
|
||||
if (the_mesh.getNodePrefs()->powersaving_enabled &&
|
||||
the_mesh.millisHasNowPassed(lastActive + nextSleepinSecs * 1000)) {
|
||||
if (!the_mesh.hasPendingWork()) {
|
||||
board.sleep(1800);
|
||||
lastActive = millis();
|
||||
nextSleepinSecs = 5; // Default: To work for 5s and sleep again
|
||||
nextSleepinSecs = 5;
|
||||
} else {
|
||||
nextSleepinSecs += 5; // When there is pending work, to work another 5s
|
||||
nextSleepinSecs += 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,509 @@
|
||||
#ifdef MECK_WIFI_REMOTE
|
||||
|
||||
#include "WiFiMQTT.h"
|
||||
#include <esp_mac.h>
|
||||
#include <Update.h>
|
||||
#include <HTTPClient.h>
|
||||
#include "target.h"
|
||||
|
||||
WiFiMQTT wifiMQTT;
|
||||
|
||||
#define WIFI_CONFIG_FILE "/remote/wifi.cfg"
|
||||
#define MQTT_CONFIG_FILE "/remote/mqtt.cfg"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Public API
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void WiFiMQTT::begin() {
|
||||
Serial.println("[WiFi] begin()");
|
||||
|
||||
_state = WiFiMQTTState::OFF;
|
||||
_cmdHead = _cmdTail = 0;
|
||||
_rspHead = _rspTail = 0;
|
||||
_activeNetwork = 0;
|
||||
|
||||
if (!loadConfig(_config)) {
|
||||
Serial.println("[WiFi] ERROR: Missing config files — cannot start");
|
||||
_state = WiFiMQTTState::ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.printf("[WiFi] Config: %d network(s), broker=%s:%d id=%s\n",
|
||||
_config.networkCount, _config.broker, _config.port, _config.deviceId);
|
||||
for (int i = 0; i < _config.networkCount; i++) {
|
||||
Serial.printf("[WiFi] %d: %s\n", i + 1, _config.networks[i].ssid);
|
||||
}
|
||||
|
||||
snprintf(_topicCmd, sizeof(_topicCmd), "meck/%s/cmd", _config.deviceId);
|
||||
snprintf(_topicRsp, sizeof(_topicRsp), "meck/%s/rsp", _config.deviceId);
|
||||
snprintf(_topicTelem, sizeof(_topicTelem), "meck/%s/telemetry", _config.deviceId);
|
||||
snprintf(_topicOta, sizeof(_topicOta), "meck/%s/ota", _config.deviceId);
|
||||
|
||||
// Configure TLS — skip server cert verification (same as cellular)
|
||||
_wifiClient.setInsecure();
|
||||
|
||||
_mqttClient.setClient(_wifiClient);
|
||||
_mqttClient.setServer(_config.broker, _config.port);
|
||||
_mqttClient.setCallback(mqttCallback);
|
||||
_mqttClient.setBufferSize(MQTT_PAYLOAD_MAX + MQTT_TOPIC_MAX);
|
||||
|
||||
_state = WiFiMQTTState::WIFI_CONNECTING;
|
||||
}
|
||||
|
||||
void WiFiMQTT::loop() {
|
||||
if (_state == WiFiMQTTState::OFF || _state == WiFiMQTTState::ERROR) return;
|
||||
|
||||
// Check for pending OTA
|
||||
if (_otaPending && _state == WiFiMQTTState::CONNECTED) {
|
||||
performOTA();
|
||||
return;
|
||||
}
|
||||
|
||||
// WiFi connection management
|
||||
if (WiFi.status() != WL_CONNECTED) {
|
||||
if (_state == WiFiMQTTState::CONNECTED || _state == WiFiMQTTState::MQTT_CONNECTING) {
|
||||
Serial.println("[WiFi] Connection lost");
|
||||
_state = WiFiMQTTState::WIFI_CONNECTING;
|
||||
}
|
||||
if (millis() - _lastWifiAttempt > WIFI_RECONNECT_MS) {
|
||||
connectWiFi();
|
||||
_lastWifiAttempt = millis();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// WiFi is up — check MQTT
|
||||
if (!_mqttClient.connected()) {
|
||||
if (_state == WiFiMQTTState::CONNECTED) {
|
||||
Serial.println("[WiFi] MQTT disconnected");
|
||||
}
|
||||
_state = WiFiMQTTState::MQTT_CONNECTING;
|
||||
if (millis() - _lastMqttAttempt > MQTT_RECONNECT_MS) {
|
||||
connectMQTT();
|
||||
_lastMqttAttempt = millis();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Connected — run MQTT loop
|
||||
_mqttClient.loop();
|
||||
|
||||
// Publish queued responses
|
||||
publishQueuedResponses();
|
||||
|
||||
// Periodic RSSI
|
||||
if (millis() - _lastRSSI > 30000) {
|
||||
_rssi = WiFi.RSSI();
|
||||
_lastRSSI = millis();
|
||||
}
|
||||
|
||||
// Periodic telemetry
|
||||
if (millis() - _lastTelem > TELEMETRY_INTERVAL) {
|
||||
publishTelemetry();
|
||||
_lastTelem = millis();
|
||||
}
|
||||
}
|
||||
|
||||
bool WiFiMQTT::recvCommand(MQTTCommand& out) {
|
||||
if (_cmdHead == _cmdTail) return false;
|
||||
memcpy(&out, &_cmdBuf[_cmdTail], sizeof(MQTTCommand));
|
||||
_cmdTail = (_cmdTail + 1) % CMD_QUEUE_SIZE;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WiFiMQTT::sendResponse(const char* topic, const char* payload) {
|
||||
int next = (_rspHead + 1) % RSP_QUEUE_SIZE;
|
||||
if (next == _rspTail) return false; // Full
|
||||
memset(&_rspBuf[_rspHead], 0, sizeof(MQTTResponse));
|
||||
strncpy(_rspBuf[_rspHead].topic, topic, MQTT_TOPIC_MAX - 1);
|
||||
strncpy(_rspBuf[_rspHead].payload, payload, MQTT_PAYLOAD_MAX - 1);
|
||||
_rspHead = next;
|
||||
return true;
|
||||
}
|
||||
|
||||
void WiFiMQTT::updateTelemetry(const TelemetryData& data) {
|
||||
memcpy(&_telemetry, &data, sizeof(data));
|
||||
}
|
||||
|
||||
void WiFiMQTT::requestOTA(const char* url) {
|
||||
if (_state == WiFiMQTTState::OTA_IN_PROGRESS) return;
|
||||
strncpy(_otaUrl, url, sizeof(_otaUrl) - 1);
|
||||
_otaUrl[sizeof(_otaUrl) - 1] = '\0';
|
||||
_otaPending = true;
|
||||
Serial.printf("[OTA] Requested: %s\n", url);
|
||||
}
|
||||
|
||||
int WiFiMQTT::getSignalBars() const {
|
||||
if (_rssi == 0) return 0;
|
||||
if (_rssi > -50) return 5;
|
||||
if (_rssi > -60) return 4;
|
||||
if (_rssi > -70) return 3;
|
||||
if (_rssi > -80) return 2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char* WiFiMQTT::stateString() const {
|
||||
switch (_state) {
|
||||
case WiFiMQTTState::OFF: return "OFF";
|
||||
case WiFiMQTTState::WIFI_CONNECTING: return "WiFi...";
|
||||
case WiFiMQTTState::WIFI_CONNECTED: return "WiFi OK";
|
||||
case WiFiMQTTState::MQTT_CONNECTING: return "MQTT...";
|
||||
case WiFiMQTTState::CONNECTED: return "CONNECTED";
|
||||
case WiFiMQTTState::OTA_IN_PROGRESS: return "OTA";
|
||||
case WiFiMQTTState::ERROR: return "ERROR";
|
||||
default: return "???";
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Config files
|
||||
//
|
||||
// /remote/wifi.cfg — SSID/password pairs, two lines each:
|
||||
// HomeNetwork
|
||||
// HomePassword
|
||||
// BackupNetwork
|
||||
// BackupPassword
|
||||
//
|
||||
// /remote/mqtt.cfg — same format as cellular variant
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
bool WiFiMQTT::loadConfig(WiFiMQTTConfig& cfg) {
|
||||
memset(&cfg, 0, sizeof(cfg));
|
||||
|
||||
// Determine filesystem: SD if available, otherwise SPIFFS
|
||||
// Heltec V4 and other headless boards have no SD slot — config lives in SPIFFS.
|
||||
// Upload config files via: pio run -t uploadfs (with data/ folder)
|
||||
#if defined(HAS_SDCARD) || defined(SDCARD_CS)
|
||||
fs::FS& configFS = SD;
|
||||
Serial.println("[WiFi] Config source: SD card");
|
||||
#else
|
||||
fs::FS& configFS = SPIFFS;
|
||||
Serial.println("[WiFi] Config source: SPIFFS");
|
||||
#endif
|
||||
|
||||
// WiFi config: read SSID/password pairs
|
||||
File wf = configFS.open(WIFI_CONFIG_FILE, FILE_READ);
|
||||
if (!wf) {
|
||||
Serial.printf("[WiFi] No %s\n", WIFI_CONFIG_FILE);
|
||||
return false;
|
||||
}
|
||||
|
||||
cfg.networkCount = 0;
|
||||
while (wf.available() && cfg.networkCount < MAX_WIFI_NETWORKS) {
|
||||
String ssid = wf.readStringUntil('\n'); ssid.trim();
|
||||
if (ssid.length() == 0) break;
|
||||
String pass = wf.readStringUntil('\n'); pass.trim();
|
||||
strncpy(cfg.networks[cfg.networkCount].ssid, ssid.c_str(), sizeof(cfg.networks[0].ssid) - 1);
|
||||
strncpy(cfg.networks[cfg.networkCount].password, pass.c_str(), sizeof(cfg.networks[0].password) - 1);
|
||||
cfg.networkCount++;
|
||||
}
|
||||
wf.close();
|
||||
|
||||
if (cfg.networkCount == 0) {
|
||||
Serial.println("[WiFi] No networks in wifi.cfg");
|
||||
return false;
|
||||
}
|
||||
|
||||
// MQTT config: /remote/mqtt.cfg (same format as cellular)
|
||||
File mf = configFS.open(MQTT_CONFIG_FILE, FILE_READ);
|
||||
if (!mf) {
|
||||
Serial.printf("[WiFi] No %s\n", MQTT_CONFIG_FILE);
|
||||
return false;
|
||||
}
|
||||
String line;
|
||||
line = mf.readStringUntil('\n'); line.trim();
|
||||
strncpy(cfg.broker, line.c_str(), sizeof(cfg.broker) - 1);
|
||||
line = mf.readStringUntil('\n'); line.trim();
|
||||
cfg.port = line.length() > 0 ? line.toInt() : 8883;
|
||||
line = mf.readStringUntil('\n'); line.trim();
|
||||
strncpy(cfg.username, line.c_str(), sizeof(cfg.username) - 1);
|
||||
line = mf.readStringUntil('\n'); line.trim();
|
||||
strncpy(cfg.password, line.c_str(), sizeof(cfg.password) - 1);
|
||||
if (mf.available()) {
|
||||
line = mf.readStringUntil('\n'); line.trim();
|
||||
if (line.length() > 0) {
|
||||
strncpy(cfg.deviceId, line.c_str(), sizeof(cfg.deviceId) - 1);
|
||||
}
|
||||
}
|
||||
mf.close();
|
||||
|
||||
// Auto-generate device ID if not provided
|
||||
if (cfg.deviceId[0] == '\0') {
|
||||
uint8_t mac[6];
|
||||
esp_efuse_mac_get_default(mac);
|
||||
snprintf(cfg.deviceId, sizeof(cfg.deviceId), "meck-%02x%02x%02x%02x",
|
||||
mac[2], mac[3], mac[4], mac[5]);
|
||||
}
|
||||
|
||||
return cfg.broker[0] != '\0';
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// WiFi connection — tries each configured network in order
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
bool WiFiMQTT::connectWiFi() {
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
||||
for (int n = 0; n < _config.networkCount; n++) {
|
||||
Serial.printf("[WiFi] Trying %s (%d/%d)...\n",
|
||||
_config.networks[n].ssid, n + 1, _config.networkCount);
|
||||
WiFi.begin(_config.networks[n].ssid, _config.networks[n].password);
|
||||
|
||||
unsigned long start = millis();
|
||||
while (WiFi.status() != WL_CONNECTED && millis() - start < 10000) {
|
||||
delay(100);
|
||||
}
|
||||
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
IPAddress ip = WiFi.localIP();
|
||||
snprintf(_ipAddr, sizeof(_ipAddr), "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
|
||||
_rssi = WiFi.RSSI();
|
||||
_activeNetwork = n;
|
||||
Serial.printf("[WiFi] Connected to %s — IP: %s RSSI: %d\n",
|
||||
_config.networks[n].ssid, _ipAddr, _rssi);
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
IPAddress ip = WiFi.localIP();
|
||||
snprintf(_ipAddr, sizeof(_ipAddr), "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
|
||||
_rssi = WiFi.RSSI();
|
||||
_activeNetwork = n;
|
||||
Serial.printf("[WiFi] Connected to %s — IP: %s RSSI: %d\n",
|
||||
_config.networks[n].ssid, _ipAddr, _rssi);
|
||||
|
||||
// Sync clock via NTP
|
||||
configTime(0, 0, "pool.ntp.org", "time.google.com");
|
||||
Serial.print("[WiFi] NTP sync...");
|
||||
int tries = 0;
|
||||
while (time(nullptr) < 1700000000 && tries < 20) {
|
||||
delay(500);
|
||||
tries++;
|
||||
}
|
||||
time_t now = time(nullptr);
|
||||
if (now > 1700000000) {
|
||||
extern AutoDiscoverRTCClock rtc_clock;
|
||||
rtc_clock.setCurrentTime((uint32_t)now);
|
||||
Serial.printf(" OK (%lu)\n", (unsigned long)now);
|
||||
} else {
|
||||
Serial.println(" timeout");
|
||||
}
|
||||
|
||||
_state = WiFiMQTTState::WIFI_CONNECTED;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
WiFi.disconnect();
|
||||
delay(500);
|
||||
}
|
||||
|
||||
Serial.println("[WiFi] All networks failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// MQTT connection
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
bool WiFiMQTT::connectMQTT() {
|
||||
Serial.printf("[WiFi] MQTT connecting to %s:%d...\n", _config.broker, _config.port);
|
||||
|
||||
char clientId[48];
|
||||
snprintf(clientId, sizeof(clientId), "%s-%lu", _config.deviceId, millis() & 0xFFFF);
|
||||
|
||||
if (_mqttClient.connect(clientId, _config.username, _config.password)) {
|
||||
Serial.println("[WiFi] MQTT connected!");
|
||||
|
||||
_mqttClient.subscribe(_topicCmd, 1);
|
||||
_mqttClient.subscribe(_topicOta, 1);
|
||||
|
||||
_state = WiFiMQTTState::CONNECTED;
|
||||
|
||||
// Publish boot event
|
||||
_mqttClient.publish(_topicTelem, "{\"event\":\"boot\",\"state\":\"connected\"}", true);
|
||||
return true;
|
||||
}
|
||||
|
||||
Serial.printf("[WiFi] MQTT connect failed, rc=%d\n", _mqttClient.state());
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// MQTT message callback
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void WiFiMQTT::mqttCallback(char* topic, byte* payload, unsigned int length) {
|
||||
wifiMQTT.onMessage(topic, payload, length);
|
||||
}
|
||||
|
||||
void WiFiMQTT::onMessage(char* topic, byte* payload, unsigned int length) {
|
||||
char buf[MQTT_PAYLOAD_MAX];
|
||||
int len = (length < MQTT_PAYLOAD_MAX - 1) ? length : MQTT_PAYLOAD_MAX - 1;
|
||||
memcpy(buf, payload, len);
|
||||
buf[len] = '\0';
|
||||
|
||||
Serial.printf("[WiFi] RX [%s]: %.80s\n", topic, buf);
|
||||
|
||||
if (strstr(topic, "/cmd")) {
|
||||
int next = (_cmdHead + 1) % CMD_QUEUE_SIZE;
|
||||
if (next != _cmdTail) {
|
||||
memset(&_cmdBuf[_cmdHead], 0, sizeof(MQTTCommand));
|
||||
strncpy(_cmdBuf[_cmdHead].cmd, buf, MQTT_PAYLOAD_MAX - 1);
|
||||
_cmdHead = next;
|
||||
Serial.printf("[WiFi] Queued CLI: %s\n", buf);
|
||||
} else {
|
||||
Serial.println("[WiFi] Command queue full");
|
||||
}
|
||||
} else if (strstr(topic, "/ota")) {
|
||||
requestOTA(buf);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Publish helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void WiFiMQTT::publishQueuedResponses() {
|
||||
while (_rspHead != _rspTail) {
|
||||
_mqttClient.publish(_rspBuf[_rspTail].topic, _rspBuf[_rspTail].payload);
|
||||
_rspTail = (_rspTail + 1) % RSP_QUEUE_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
void WiFiMQTT::publishTelemetry() {
|
||||
_rssi = WiFi.RSSI();
|
||||
|
||||
char json[400];
|
||||
snprintf(json, sizeof(json),
|
||||
"{\"uptime\":%lu,\"batt_mv\":%d,\"batt_pct\":%d,\"temp\":%.1f,"
|
||||
"\"rssi\":%d,\"bars\":%d,\"neighbors\":%d,"
|
||||
"\"freq\":%.3f,\"bw\":%.1f,\"sf\":%d,\"cr\":%d,\"tx\":%d,"
|
||||
"\"name\":\"%s\",\"ip\":\"%s\",\"ssid\":\"%s\","
|
||||
"\"heap\":%d}",
|
||||
_telemetry.uptime_secs, _telemetry.battery_mv, _telemetry.battery_pct,
|
||||
_telemetry.temperature / 10.0f,
|
||||
_rssi, getSignalBars(), _telemetry.neighbor_count,
|
||||
_telemetry.freq, _telemetry.bw, _telemetry.sf, _telemetry.cr, _telemetry.tx_power,
|
||||
_telemetry.node_name, _ipAddr, _config.networks[_activeNetwork].ssid,
|
||||
ESP.getFreeHeap());
|
||||
|
||||
_mqttClient.publish(_topicTelem, json);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// OTA — HTTP download over WiFi + ESP32 flash
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void WiFiMQTT::performOTA() {
|
||||
_otaPending = false;
|
||||
_state = WiFiMQTTState::OTA_IN_PROGRESS;
|
||||
|
||||
Serial.printf("[OTA] URL: %s\n", _otaUrl);
|
||||
|
||||
_mqttClient.publish(_topicRsp, "OTA: Starting download...");
|
||||
_mqttClient.loop();
|
||||
|
||||
HTTPClient http;
|
||||
http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
|
||||
http.setTimeout(180000);
|
||||
|
||||
if (!http.begin(_wifiClient, _otaUrl)) {
|
||||
Serial.println("[OTA] HTTP begin failed");
|
||||
_mqttClient.publish(_topicRsp, "OTA: HTTP begin failed");
|
||||
_state = WiFiMQTTState::CONNECTED;
|
||||
return;
|
||||
}
|
||||
|
||||
int httpCode = http.GET();
|
||||
if (httpCode != HTTP_CODE_OK) {
|
||||
Serial.printf("[OTA] HTTP error: %d\n", httpCode);
|
||||
char msg[60];
|
||||
snprintf(msg, sizeof(msg), "OTA: HTTP error %d", httpCode);
|
||||
_mqttClient.publish(_topicRsp, msg);
|
||||
http.end();
|
||||
_state = WiFiMQTTState::CONNECTED;
|
||||
return;
|
||||
}
|
||||
|
||||
int fileSize = http.getSize();
|
||||
if (fileSize <= 0) {
|
||||
Serial.println("[OTA] Unknown content length");
|
||||
_mqttClient.publish(_topicRsp, "OTA: Unknown file size");
|
||||
http.end();
|
||||
_state = WiFiMQTTState::CONNECTED;
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.printf("[OTA] File size: %d bytes\n", fileSize);
|
||||
|
||||
if (!Update.begin(fileSize)) {
|
||||
Serial.printf("[OTA] Update.begin failed: %s\n", Update.errorString());
|
||||
_mqttClient.publish(_topicRsp, "OTA: Flash init failed");
|
||||
http.end();
|
||||
_state = WiFiMQTTState::CONNECTED;
|
||||
return;
|
||||
}
|
||||
|
||||
WiFiClient* stream = http.getStreamPtr();
|
||||
uint8_t buf[1024];
|
||||
int offset = 0;
|
||||
int lastPct = -1;
|
||||
|
||||
while (offset < fileSize) {
|
||||
int avail = stream->available();
|
||||
if (avail <= 0) {
|
||||
if (!stream->connected()) break;
|
||||
delay(10);
|
||||
continue;
|
||||
}
|
||||
|
||||
int toRead = (avail < (int)sizeof(buf)) ? avail : sizeof(buf);
|
||||
int got = stream->readBytes(buf, toRead);
|
||||
if (got <= 0) break;
|
||||
|
||||
size_t written = Update.write(buf, got);
|
||||
if (written != (size_t)got) {
|
||||
Serial.printf("[OTA] Write failed: %d of %d\n", written, got);
|
||||
break;
|
||||
}
|
||||
|
||||
offset += got;
|
||||
|
||||
int pct = (offset * 100) / fileSize;
|
||||
if (pct / 10 != lastPct / 10) {
|
||||
Serial.printf("[OTA] Progress: %d%% (%d/%d)\n", pct, offset, fileSize);
|
||||
char msg[60];
|
||||
snprintf(msg, sizeof(msg), "OTA: Flashing %d%%", pct);
|
||||
_mqttClient.publish(_topicRsp, msg);
|
||||
_mqttClient.loop();
|
||||
lastPct = pct;
|
||||
}
|
||||
|
||||
delay(1);
|
||||
}
|
||||
|
||||
http.end();
|
||||
|
||||
if (offset < fileSize) {
|
||||
Serial.printf("[OTA] Incomplete: %d of %d\n", offset, fileSize);
|
||||
Update.abort();
|
||||
_mqttClient.publish(_topicRsp, "OTA: Download incomplete");
|
||||
_state = WiFiMQTTState::CONNECTED;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Update.end(true)) {
|
||||
Serial.printf("[OTA] Update.end failed: %s\n", Update.errorString());
|
||||
_mqttClient.publish(_topicRsp, "OTA: Verification failed");
|
||||
_state = WiFiMQTTState::CONNECTED;
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.println("[OTA] SUCCESS — rebooting in 3 seconds");
|
||||
_mqttClient.publish(_topicRsp, "OTA: Success! Rebooting...");
|
||||
_mqttClient.loop();
|
||||
delay(3000);
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
#endif // MECK_WIFI_REMOTE
|
||||
@@ -0,0 +1,191 @@
|
||||
#pragma once
|
||||
|
||||
// =============================================================================
|
||||
// WiFiMQTT — WiFi + MQTT for audio variant remote repeater
|
||||
//
|
||||
// Same interface as CellularMQTT but uses ESP32 native WiFi + PubSubClient.
|
||||
// No modem, no AT commands, no FreeRTOS task — runs in the main loop.
|
||||
//
|
||||
// Supports multiple WiFi networks in wifi.cfg (SSID/password pairs).
|
||||
// Tries each in order on connect/reconnect.
|
||||
//
|
||||
// Guard: MECK_WIFI_REMOTE (set in platformio env build_flags)
|
||||
// =============================================================================
|
||||
|
||||
#ifdef MECK_WIFI_REMOTE
|
||||
|
||||
#ifndef WIFI_MQTT_H
|
||||
#define WIFI_MQTT_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <WiFi.h>
|
||||
#include <WiFiClientSecure.h>
|
||||
#include <PubSubClient.h>
|
||||
#if defined(HAS_SDCARD) || defined(SDCARD_CS)
|
||||
#include <SD.h>
|
||||
#endif
|
||||
#include <SPIFFS.h>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Configuration
|
||||
// ---------------------------------------------------------------------------
|
||||
#define MQTT_TOPIC_MAX 80
|
||||
#define MQTT_PAYLOAD_MAX 512
|
||||
#define MQTT_CLIENT_ID_MAX 32
|
||||
|
||||
#define CMD_QUEUE_SIZE 8
|
||||
#define RSP_QUEUE_SIZE 8
|
||||
|
||||
#define MAX_WIFI_NETWORKS 4
|
||||
|
||||
#define TELEMETRY_INTERVAL 60000 // 60 seconds
|
||||
#define WIFI_RECONNECT_MS 10000 // 10 seconds between WiFi reconnect attempts
|
||||
#define MQTT_RECONNECT_MS 5000 // 5 seconds between MQTT reconnect attempts
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// State machine
|
||||
// ---------------------------------------------------------------------------
|
||||
enum class WiFiMQTTState : uint8_t {
|
||||
OFF,
|
||||
WIFI_CONNECTING,
|
||||
WIFI_CONNECTED,
|
||||
MQTT_CONNECTING,
|
||||
CONNECTED,
|
||||
OTA_IN_PROGRESS,
|
||||
ERROR
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Queue message types (same as CellularMQTT for compatibility)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
struct MQTTCommand {
|
||||
char cmd[MQTT_PAYLOAD_MAX];
|
||||
};
|
||||
|
||||
struct MQTTResponse {
|
||||
char topic[MQTT_TOPIC_MAX];
|
||||
char payload[MQTT_PAYLOAD_MAX];
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Config (loaded from SD)
|
||||
// ---------------------------------------------------------------------------
|
||||
struct WiFiNetwork {
|
||||
char ssid[40];
|
||||
char password[64];
|
||||
};
|
||||
|
||||
struct WiFiMQTTConfig {
|
||||
WiFiNetwork networks[MAX_WIFI_NETWORKS];
|
||||
int networkCount;
|
||||
char broker[80];
|
||||
uint16_t port; // 8883 for MQTT TLS
|
||||
char username[40];
|
||||
char password[40];
|
||||
char deviceId[MQTT_CLIENT_ID_MAX];
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Telemetry snapshot
|
||||
// ---------------------------------------------------------------------------
|
||||
struct TelemetryData {
|
||||
uint32_t uptime_secs;
|
||||
uint16_t battery_mv;
|
||||
uint8_t battery_pct;
|
||||
int16_t temperature;
|
||||
int rssi;
|
||||
uint8_t neighbor_count;
|
||||
float freq;
|
||||
float bw;
|
||||
uint8_t sf;
|
||||
uint8_t cr;
|
||||
uint8_t tx_power;
|
||||
char node_name[32];
|
||||
bool mqtt_connected;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// WiFiMQTT class
|
||||
// ---------------------------------------------------------------------------
|
||||
class WiFiMQTT {
|
||||
public:
|
||||
void begin();
|
||||
void loop(); // Call from main loop — handles WiFi, MQTT, publish/subscribe
|
||||
|
||||
// --- Queue API (called from main loop) ---
|
||||
bool recvCommand(MQTTCommand& out);
|
||||
bool sendResponse(const char* topic, const char* payload);
|
||||
|
||||
// --- Telemetry ---
|
||||
void updateTelemetry(const TelemetryData& data);
|
||||
|
||||
// --- OTA ---
|
||||
void requestOTA(const char* url);
|
||||
bool isOTAInProgress() const { return _state == WiFiMQTTState::OTA_IN_PROGRESS; }
|
||||
|
||||
// --- State queries ---
|
||||
WiFiMQTTState getState() const { return _state; }
|
||||
bool isConnected() const { return _state == WiFiMQTTState::CONNECTED; }
|
||||
int getRSSI() const { return _rssi; }
|
||||
int getSignalBars() const;
|
||||
const char* getSSID() const { return _config.networks[_activeNetwork].ssid; }
|
||||
const char* getIPAddress() const { return _ipAddr; }
|
||||
const char* getBroker() const { return _config.broker; }
|
||||
const char* getRspTopic() const { return _topicRsp; }
|
||||
const char* stateString() const;
|
||||
|
||||
static bool loadConfig(WiFiMQTTConfig& cfg);
|
||||
|
||||
private:
|
||||
WiFiMQTTState _state = WiFiMQTTState::OFF;
|
||||
int _rssi = 0;
|
||||
int _activeNetwork = 0;
|
||||
|
||||
char _ipAddr[20] = {0};
|
||||
WiFiMQTTConfig _config = {};
|
||||
TelemetryData _telemetry = {};
|
||||
|
||||
// Topic strings
|
||||
char _topicCmd[MQTT_TOPIC_MAX] = {0};
|
||||
char _topicRsp[MQTT_TOPIC_MAX] = {0};
|
||||
char _topicTelem[MQTT_TOPIC_MAX] = {0};
|
||||
char _topicOta[MQTT_TOPIC_MAX] = {0};
|
||||
|
||||
// Command/response ring buffers (no FreeRTOS queues needed — single-threaded)
|
||||
MQTTCommand _cmdBuf[CMD_QUEUE_SIZE];
|
||||
int _cmdHead = 0, _cmdTail = 0;
|
||||
|
||||
MQTTResponse _rspBuf[RSP_QUEUE_SIZE];
|
||||
int _rspHead = 0, _rspTail = 0;
|
||||
|
||||
// MQTT client stack
|
||||
WiFiClientSecure _wifiClient;
|
||||
PubSubClient _mqttClient;
|
||||
|
||||
// Timers
|
||||
unsigned long _lastWifiAttempt = 0;
|
||||
unsigned long _lastMqttAttempt = 0;
|
||||
unsigned long _lastTelem = 0;
|
||||
unsigned long _lastRSSI = 0;
|
||||
|
||||
// OTA state
|
||||
bool _otaPending = false;
|
||||
char _otaUrl[256] = {0};
|
||||
|
||||
// --- Internal ---
|
||||
bool connectWiFi();
|
||||
bool connectMQTT();
|
||||
void publishTelemetry();
|
||||
void publishQueuedResponses();
|
||||
void performOTA();
|
||||
|
||||
// PubSubClient callback (static → instance)
|
||||
static void mqttCallback(char* topic, byte* payload, unsigned int length);
|
||||
void onMessage(char* topic, byte* payload, unsigned int length);
|
||||
};
|
||||
|
||||
extern WiFiMQTT wifiMQTT;
|
||||
|
||||
#endif // WIFI_MQTT_H
|
||||
#endif // MECK_WIFI_REMOTE
|
||||
+97
-3
@@ -1,7 +1,10 @@
|
||||
"""
|
||||
PlatformIO post-build script: merge bootloader + partitions + firmware
|
||||
PlatformIO post-build script: merge bootloader + partitions + firmware + SPIFFS
|
||||
into a single flashable binary.
|
||||
|
||||
Includes a pre-formatted empty SPIFFS image so first-boot doesn't need to
|
||||
format the partition (which takes 1-2 minutes on 16MB flash).
|
||||
|
||||
Output: .pio/build/<env>/firmware_merged.bin
|
||||
Flash: esptool.py --chip esp32s3 write_flash 0x0 firmware_merged.bin
|
||||
|
||||
@@ -12,6 +15,87 @@ Add to each environment (or the base section):
|
||||
|
||||
Import("env")
|
||||
|
||||
def find_spiffs_partition(partitions_bin):
|
||||
"""Parse compiled partitions.bin to find SPIFFS partition offset and size.
|
||||
|
||||
ESP32 partition entry format (32 bytes each):
|
||||
0xAA50 magic, type, subtype, offset(u32le), size(u32le), label(16), flags(u32le)
|
||||
SPIFFS: type=0x01(data), subtype=0x82(spiffs)
|
||||
"""
|
||||
import struct
|
||||
|
||||
with open(partitions_bin, "rb") as f:
|
||||
data = f.read()
|
||||
|
||||
for i in range(0, len(data) - 32, 32):
|
||||
magic = struct.unpack_from("<H", data, i)[0]
|
||||
if magic != 0xAA50:
|
||||
continue
|
||||
ptype = data[i + 2]
|
||||
subtype = data[i + 3]
|
||||
offset = struct.unpack_from("<I", data, i + 4)[0]
|
||||
size = struct.unpack_from("<I", data, i + 8)[0]
|
||||
label = data[i + 12:i + 28].split(b'\x00')[0].decode("ascii", errors="ignore")
|
||||
if ptype == 0x01 and subtype == 0x82: # data/spiffs
|
||||
return offset, size, label
|
||||
return None, None, None
|
||||
|
||||
|
||||
def build_spiffs_image(env, size):
|
||||
"""Generate an empty formatted SPIFFS image using mkspiffs."""
|
||||
import subprocess, os, tempfile, glob
|
||||
|
||||
build_dir = env.subst("$BUILD_DIR")
|
||||
spiffs_bin = os.path.join(build_dir, "spiffs_empty.bin")
|
||||
|
||||
# If already generated for this build, reuse it
|
||||
if os.path.isfile(spiffs_bin) and os.path.getsize(spiffs_bin) == size:
|
||||
return spiffs_bin
|
||||
|
||||
# Find mkspiffs in PlatformIO packages
|
||||
pio_home = os.path.expanduser("~/.platformio")
|
||||
mkspiffs_paths = glob.glob(os.path.join(pio_home, "packages", "tool-mkspiffs*", "mkspiffs*"))
|
||||
if not mkspiffs_paths:
|
||||
# Also check platform-specific tool paths
|
||||
mkspiffs_paths = glob.glob(os.path.join(pio_home, "packages", "tool-mklittlefs*", "mkspiffs*"))
|
||||
|
||||
mkspiffs = None
|
||||
for p in mkspiffs_paths:
|
||||
if os.path.isfile(p) and os.access(p, os.X_OK):
|
||||
mkspiffs = p
|
||||
break
|
||||
|
||||
if not mkspiffs:
|
||||
print("[merge] WARNING: mkspiffs not found, skipping SPIFFS image")
|
||||
return None
|
||||
|
||||
# Create empty data directory for mkspiffs
|
||||
data_dir = os.path.join(build_dir, "_empty_spiffs_data")
|
||||
os.makedirs(data_dir, exist_ok=True)
|
||||
|
||||
# SPIFFS block/page sizes — ESP32 Arduino defaults
|
||||
block_size = 4096
|
||||
page_size = 256
|
||||
|
||||
cmd = [
|
||||
mkspiffs,
|
||||
"-c", data_dir,
|
||||
"-b", str(block_size),
|
||||
"-p", str(page_size),
|
||||
"-s", str(size),
|
||||
spiffs_bin,
|
||||
]
|
||||
|
||||
print(f"[merge] Generating empty SPIFFS image ({size // 1024} KB)...")
|
||||
result = subprocess.run(cmd, capture_output=True, text=True)
|
||||
if result.returncode == 0 and os.path.isfile(spiffs_bin):
|
||||
print(f"[merge] SPIFFS image OK: {spiffs_bin}")
|
||||
return spiffs_bin
|
||||
else:
|
||||
print(f"[merge] mkspiffs failed: {result.stderr}")
|
||||
return None
|
||||
|
||||
|
||||
def merge_bin(source, target, env):
|
||||
import subprocess, os
|
||||
|
||||
@@ -21,7 +105,7 @@ def merge_bin(source, target, env):
|
||||
bootloader = os.path.join(build_dir, "bootloader.bin")
|
||||
partitions = os.path.join(build_dir, "partitions.bin")
|
||||
firmware = os.path.join(build_dir, "firmware.bin")
|
||||
output = os.path.join(build_dir, "firmware_merged.bin")
|
||||
output = os.path.join(build_dir, "firmware-merged.bin")
|
||||
|
||||
# Verify all inputs exist
|
||||
for f in [bootloader, partitions, firmware]:
|
||||
@@ -52,8 +136,18 @@ def merge_bin(source, target, env):
|
||||
"0x10000", firmware,
|
||||
]
|
||||
|
||||
# Try to include a pre-formatted SPIFFS image (eliminates 1-2 min first-boot format)
|
||||
spiffs_offset, spiffs_size, spiffs_label = find_spiffs_partition(partitions)
|
||||
if spiffs_offset and spiffs_size:
|
||||
spiffs_bin = build_spiffs_image(env, spiffs_size)
|
||||
if spiffs_bin:
|
||||
cmd.extend([f"0x{spiffs_offset:x}", spiffs_bin])
|
||||
print(f"[merge] Including SPIFFS image at 0x{spiffs_offset:x} ({spiffs_size // 1024} KB)")
|
||||
else:
|
||||
print("[merge] No SPIFFS partition found in partition table, skipping SPIFFS image")
|
||||
|
||||
print(f"\n[merge] Creating merged firmware for {env_name}...")
|
||||
print(f"[merge] {' '.join(cmd[-6:])}")
|
||||
print(f"[merge] {' '.join(cmd[-8:])}")
|
||||
|
||||
result = subprocess.run(cmd, capture_output=True, text=True)
|
||||
if result.returncode == 0:
|
||||
|
||||
Binary file not shown.
+39
-4
@@ -36,7 +36,7 @@ uint32_t Dispatcher::getCADFailRetryDelay() const {
|
||||
return 200;
|
||||
}
|
||||
uint32_t Dispatcher::getCADFailMaxDuration() const {
|
||||
return 4000; // 4 seconds
|
||||
return 6000; // 6 seconds
|
||||
}
|
||||
|
||||
void Dispatcher::loop() {
|
||||
@@ -52,10 +52,28 @@ void Dispatcher::loop() {
|
||||
prev_isrecv_mode = is_recv;
|
||||
if (!is_recv) {
|
||||
radio_nonrx_start = _ms->getMillis();
|
||||
} else {
|
||||
rx_stuck_count = 0; // radio recovered — reset counter
|
||||
}
|
||||
}
|
||||
if (!is_recv && _ms->getMillis() - radio_nonrx_start > 8000) { // radio has not been in Rx mode for 8 seconds!
|
||||
_err_flags |= ERR_EVENT_STARTRX_TIMEOUT;
|
||||
|
||||
rx_stuck_count++;
|
||||
MESH_DEBUG_PRINTLN("%s Dispatcher::loop(): RX stuck (attempt %d), calling onRxStuck()", getLogDateTime(), rx_stuck_count);
|
||||
onRxStuck();
|
||||
|
||||
uint8_t reboot_threshold = getRxFailRebootThreshold();
|
||||
if (reboot_threshold > 0 && rx_stuck_count >= reboot_threshold) {
|
||||
MESH_DEBUG_PRINTLN("%s Dispatcher::loop(): RX unrecoverable after %d attempts", getLogDateTime(), rx_stuck_count);
|
||||
onRxUnrecoverable();
|
||||
}
|
||||
|
||||
// Reset state to give recovery the full 8s window before re-triggering
|
||||
radio_nonrx_start = _ms->getMillis();
|
||||
prev_isrecv_mode = true;
|
||||
cad_busy_start = 0;
|
||||
next_agc_reset_time = futureMillis(getAGCResetInterval());
|
||||
}
|
||||
|
||||
if (outbound) { // waiting for outbound send to be completed
|
||||
@@ -273,14 +291,31 @@ void Dispatcher::checkSend() {
|
||||
outbound_start = _ms->getMillis();
|
||||
bool success = _radio->startSendRaw(raw, len);
|
||||
if (!success) {
|
||||
MESH_DEBUG_PRINTLN("%s Dispatcher::loop(): ERROR: send start failed!", getLogDateTime());
|
||||
MESH_DEBUG_PRINTLN("%s Dispatcher::checkSend(): ERROR: send start failed!", getLogDateTime());
|
||||
|
||||
logTxFail(outbound, outbound->getRawLength());
|
||||
|
||||
releasePacket(outbound); // return to pool
|
||||
|
||||
// re-queue packet for retry instead of dropping it
|
||||
int retry_delay = getCADFailRetryDelay();
|
||||
unsigned long retry_time = futureMillis(retry_delay);
|
||||
_mgr->queueOutbound(outbound, 0, retry_time);
|
||||
outbound = NULL;
|
||||
next_tx_time = retry_time;
|
||||
|
||||
// count consecutive failures and reset radio if stuck
|
||||
uint8_t threshold = getTxFailResetThreshold();
|
||||
if (threshold > 0) {
|
||||
tx_fail_count++;
|
||||
if (tx_fail_count >= threshold) {
|
||||
MESH_DEBUG_PRINTLN("%s Dispatcher::checkSend(): TX stuck (%d failures), resetting radio", getLogDateTime(), tx_fail_count);
|
||||
onTxStuck();
|
||||
tx_fail_count = 0;
|
||||
next_tx_time = futureMillis(2000);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
tx_fail_count = 0; // clear counter on successful TX start
|
||||
outbound_expiry = futureMillis(max_airtime);
|
||||
|
||||
#if MESH_PACKET_LOGGING
|
||||
|
||||
+10
-1
@@ -122,6 +122,8 @@ class Dispatcher {
|
||||
bool prev_isrecv_mode;
|
||||
uint32_t n_sent_flood, n_sent_direct;
|
||||
uint32_t n_recv_flood, n_recv_direct;
|
||||
uint8_t tx_fail_count;
|
||||
uint8_t rx_stuck_count;
|
||||
|
||||
void processRecvPacket(Packet* pkt);
|
||||
|
||||
@@ -142,6 +144,8 @@ protected:
|
||||
_err_flags = 0;
|
||||
radio_nonrx_start = 0;
|
||||
prev_isrecv_mode = true;
|
||||
tx_fail_count = 0;
|
||||
rx_stuck_count = 0;
|
||||
}
|
||||
|
||||
virtual DispatcherAction onRecvPacket(Packet* pkt) = 0;
|
||||
@@ -159,6 +163,11 @@ protected:
|
||||
virtual uint32_t getCADFailMaxDuration() const;
|
||||
virtual int getInterferenceThreshold() const { return 0; } // disabled by default
|
||||
virtual int getAGCResetInterval() const { return 0; } // disabled by default
|
||||
virtual uint8_t getTxFailResetThreshold() const { return 3; } // reset radio after N consecutive TX failures; 0=disabled
|
||||
virtual void onTxStuck() { _radio->resetAGC(); } // override to use doFullRadioReset() when available
|
||||
virtual uint8_t getRxFailRebootThreshold() const { return 3; } // reboot after N failed RX recovery attempts; 0=disabled
|
||||
virtual void onRxStuck() { _radio->resetAGC(); } // called each time RX stuck for 8s; override for deeper reset
|
||||
virtual void onRxUnrecoverable() { } // called when reboot threshold exceeded; override to call _board->reboot()
|
||||
|
||||
public:
|
||||
void begin();
|
||||
@@ -188,4 +197,4 @@ private:
|
||||
void checkSend();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
@@ -10,10 +10,10 @@
|
||||
#endif
|
||||
|
||||
void BaseChatMesh::sendFloodScoped(const ContactInfo& recipient, mesh::Packet* pkt, uint32_t delay_millis) {
|
||||
sendFlood(pkt, delay_millis);
|
||||
sendFlood(pkt, delay_millis, getPathHashSize());
|
||||
}
|
||||
void BaseChatMesh::sendFloodScoped(const mesh::GroupChannel& channel, mesh::Packet* pkt, uint32_t delay_millis) {
|
||||
sendFlood(pkt, delay_millis);
|
||||
sendFlood(pkt, delay_millis, getPathHashSize());
|
||||
}
|
||||
|
||||
mesh::Packet* BaseChatMesh::createSelfAdvert(const char* name) {
|
||||
|
||||
@@ -130,6 +130,7 @@ protected:
|
||||
virtual void onContactResponse(const ContactInfo& contact, const uint8_t* data, uint8_t len) = 0;
|
||||
virtual void handleReturnPathRetry(const ContactInfo& contact, const uint8_t* path, uint8_t path_len);
|
||||
|
||||
virtual uint8_t getPathHashSize() const = 0;
|
||||
virtual void sendFloodScoped(const ContactInfo& recipient, mesh::Packet* pkt, uint32_t delay_millis=0);
|
||||
virtual void sendFloodScoped(const mesh::GroupChannel& channel, mesh::Packet* pkt, uint32_t delay_millis=0);
|
||||
|
||||
|
||||
@@ -81,7 +81,8 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
|
||||
file.read((uint8_t *)&_prefs->discovery_mod_timestamp, sizeof(_prefs->discovery_mod_timestamp)); // 162
|
||||
file.read((uint8_t *)&_prefs->adc_multiplier, sizeof(_prefs->adc_multiplier)); // 166
|
||||
file.read((uint8_t *)_prefs->owner_info, sizeof(_prefs->owner_info)); // 170
|
||||
// 290
|
||||
file.read((uint8_t *)&_prefs->path_hash_mode, sizeof(_prefs->path_hash_mode)); // 290
|
||||
// 291
|
||||
|
||||
// sanitise bad pref values
|
||||
_prefs->rx_delay_base = constrain(_prefs->rx_delay_base, 0, 20.0f);
|
||||
@@ -107,6 +108,7 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
|
||||
|
||||
_prefs->gps_enabled = constrain(_prefs->gps_enabled, 0, 1);
|
||||
_prefs->advert_loc_policy = constrain(_prefs->advert_loc_policy, 0, 2);
|
||||
_prefs->path_hash_mode = constrain(_prefs->path_hash_mode, 0, 2);
|
||||
|
||||
file.close();
|
||||
}
|
||||
@@ -165,7 +167,8 @@ void CommonCLI::savePrefs(FILESYSTEM* fs) {
|
||||
file.write((uint8_t *)&_prefs->discovery_mod_timestamp, sizeof(_prefs->discovery_mod_timestamp)); // 162
|
||||
file.write((uint8_t *)&_prefs->adc_multiplier, sizeof(_prefs->adc_multiplier)); // 166
|
||||
file.write((uint8_t *)_prefs->owner_info, sizeof(_prefs->owner_info)); // 170
|
||||
// 290
|
||||
file.write((uint8_t *)&_prefs->path_hash_mode, sizeof(_prefs->path_hash_mode)); // 290
|
||||
// 291
|
||||
|
||||
file.close();
|
||||
}
|
||||
@@ -285,7 +288,7 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
|
||||
sprintf(reply, "> %d", ((uint32_t) _prefs->advert_interval) * 2);
|
||||
} else if (memcmp(config, "guest.password", 14) == 0) {
|
||||
sprintf(reply, "> %s", _prefs->guest_password);
|
||||
} else if (sender_timestamp == 0 && memcmp(config, "prv.key", 7) == 0) { // from serial command line only
|
||||
} else if (memcmp(config, "prv.key", 7) == 0) { // from serial command line only
|
||||
uint8_t prv_key[PRV_KEY_SIZE];
|
||||
int len = _callbacks->getSelfId().writeTo(prv_key, PRV_KEY_SIZE);
|
||||
mesh::Utils::toHex(tmp, prv_key, len);
|
||||
@@ -545,7 +548,7 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
|
||||
savePrefs();
|
||||
_callbacks->setTxPower(_prefs->tx_power_dbm);
|
||||
strcpy(reply, "OK");
|
||||
} else if (sender_timestamp == 0 && memcmp(config, "freq ", 5) == 0) {
|
||||
} else if (memcmp(config, "freq ", 5) == 0) {
|
||||
_prefs->freq = atof(&config[5]);
|
||||
savePrefs();
|
||||
strcpy(reply, "OK - reboot to apply");
|
||||
@@ -767,13 +770,13 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
|
||||
} else if (sender_timestamp == 0 && memcmp(command, "log", 3) == 0) {
|
||||
_callbacks->dumpLogFile();
|
||||
strcpy(reply, " EOF");
|
||||
} else if (sender_timestamp == 0 && memcmp(command, "stats-packets", 13) == 0 && (command[13] == 0 || command[13] == ' ')) {
|
||||
} else if (memcmp(command, "stats-packets", 13) == 0 && (command[13] == 0 || command[13] == ' ')) {
|
||||
_callbacks->formatPacketStatsReply(reply);
|
||||
} else if (sender_timestamp == 0 && memcmp(command, "stats-radio", 11) == 0 && (command[11] == 0 || command[11] == ' ')) {
|
||||
} else if (memcmp(command, "stats-radio", 11) == 0 && (command[11] == 0 || command[11] == ' ')) {
|
||||
_callbacks->formatRadioStatsReply(reply);
|
||||
} else if (sender_timestamp == 0 && memcmp(command, "stats-core", 10) == 0 && (command[10] == 0 || command[10] == ' ')) {
|
||||
} else if (memcmp(command, "stats-core", 10) == 0 && (command[10] == 0 || command[10] == ' ')) {
|
||||
_callbacks->formatStatsReply(reply);
|
||||
} else {
|
||||
strcpy(reply, "Unknown command");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,8 @@ struct NodePrefs { // persisted to file
|
||||
uint32_t discovery_mod_timestamp;
|
||||
float adc_multiplier;
|
||||
char owner_info[120];
|
||||
// Multi-byte path hash support (added for Meck remote repeater)
|
||||
uint8_t path_hash_mode; // 0=1-byte (legacy), 1=2-byte, 2=3-byte path hashes
|
||||
};
|
||||
|
||||
class CommonCLICallbacks {
|
||||
@@ -110,4 +112,4 @@ public:
|
||||
void savePrefs(FILESYSTEM* _fs);
|
||||
void handleCommand(uint32_t sender_timestamp, const char* command, char* reply);
|
||||
uint8_t buildAdvertData(uint8_t node_type, uint8_t* app_data);
|
||||
};
|
||||
};
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <Wire.h>
|
||||
#include "esp_wifi.h"
|
||||
#include "driver/rtc_io.h"
|
||||
#include "driver/gpio.h"
|
||||
|
||||
class ESP32Board : public mesh::MainBoard {
|
||||
protected:
|
||||
@@ -60,13 +61,20 @@ public:
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32S3) && defined(P_LORA_DIO_1) // Supported ESP32 variants
|
||||
if (rtc_gpio_is_valid_gpio((gpio_num_t)P_LORA_DIO_1)) { // Only enter sleep mode if P_LORA_DIO_1 is RTC pin
|
||||
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
|
||||
esp_sleep_enable_ext1_wakeup((1L << P_LORA_DIO_1), ESP_EXT1_WAKEUP_ANY_HIGH); // To wake up when receiving a LoRa packet
|
||||
esp_sleep_enable_ext1_wakeup((1ULL << P_LORA_DIO_1), ESP_EXT1_WAKEUP_ANY_HIGH); // Wake on LoRa packet
|
||||
|
||||
// T5S3: Also wake on boot button press (GPIO0, active LOW).
|
||||
// gpio_wakeup uses level trigger — works for light sleep only.
|
||||
#if defined(LilyGo_T5S3_EPaper_Pro) && defined(PIN_USER_BTN)
|
||||
gpio_wakeup_enable((gpio_num_t)PIN_USER_BTN, GPIO_INTR_LOW_LEVEL);
|
||||
esp_sleep_enable_gpio_wakeup();
|
||||
#endif
|
||||
|
||||
if (secs > 0) {
|
||||
esp_sleep_enable_timer_wakeup(secs * 1000000); // To wake up every hour to do periodically jobs
|
||||
esp_sleep_enable_timer_wakeup(secs * 1000000ULL); // Timer wake (microseconds)
|
||||
}
|
||||
|
||||
esp_light_sleep_start(); // CPU enters light sleep
|
||||
esp_light_sleep_start(); // CPU halts here, resumes on wake
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -154,4 +162,4 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,4 +1,6 @@
|
||||
#include "SerialBLEInterface.h"
|
||||
#include "esp_bt.h"
|
||||
#include "esp_gap_ble_api.h"
|
||||
|
||||
// See the following for generating UUIDs:
|
||||
// https://www.uuidgenerator.net/
|
||||
@@ -27,6 +29,11 @@ void SerialBLEInterface::begin(const char* prefix, char* name, uint32_t pin_code
|
||||
BLEDevice::setSecurityCallbacks(this);
|
||||
BLEDevice::setMTU(MAX_FRAME_SIZE);
|
||||
|
||||
// Boost BLE TX power for improved range (+9 dBm, up from default +3 dBm)
|
||||
esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_DEFAULT, ESP_PWR_LVL_P9);
|
||||
esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_ADV, ESP_PWR_LVL_P9);
|
||||
esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_SCAN, ESP_PWR_LVL_P9);
|
||||
|
||||
BLESecurity sec;
|
||||
sec.setStaticPIN(pin_code);
|
||||
sec.setAuthenticationMode(ESP_LE_AUTH_REQ_SC_MITM_BOND);
|
||||
@@ -77,6 +84,18 @@ void SerialBLEInterface::onAuthenticationComplete(esp_ble_auth_cmpl_t cmpl) {
|
||||
if (cmpl.success) {
|
||||
BLE_DEBUG_PRINTLN(" - SecurityCallback - Authentication Success");
|
||||
deviceConnected = true;
|
||||
|
||||
// Request fast connection interval (15ms) for faster contact sync.
|
||||
// Phone may negotiate higher, but most modern phones accept 15ms.
|
||||
// Units are 1.25ms, so 12 = 15ms, 16 = 20ms.
|
||||
esp_ble_conn_update_params_t conn_params;
|
||||
memcpy(conn_params.bda, _remote_bda, 6);
|
||||
conn_params.min_int = 12; // 15ms (12 × 1.25ms)
|
||||
conn_params.max_int = 16; // 20ms (16 × 1.25ms)
|
||||
conn_params.latency = 0; // no skipped intervals
|
||||
conn_params.timeout = 400; // 4 seconds supervision timeout
|
||||
esp_ble_gap_update_conn_params(&conn_params);
|
||||
BLE_DEBUG_PRINTLN(" - Requested fast connection interval (15-20ms)");
|
||||
} else {
|
||||
BLE_DEBUG_PRINTLN(" - SecurityCallback - Authentication Failure*");
|
||||
|
||||
@@ -94,6 +113,7 @@ void SerialBLEInterface::onConnect(BLEServer* pServer) {
|
||||
void SerialBLEInterface::onConnect(BLEServer* pServer, esp_ble_gatts_cb_param_t *param) {
|
||||
BLE_DEBUG_PRINTLN("onConnect(), conn_id=%d, mtu=%d", param->connect.conn_id, pServer->getPeerMTU(param->connect.conn_id));
|
||||
last_conn_id = param->connect.conn_id;
|
||||
memcpy(_remote_bda, param->connect.remote_bda, 6);
|
||||
}
|
||||
|
||||
void SerialBLEInterface::onMtuChanged(BLEServer* pServer, esp_ble_gatts_cb_param_t* param) {
|
||||
@@ -185,7 +205,7 @@ size_t SerialBLEInterface::writeFrame(const uint8_t src[], size_t len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define BLE_WRITE_MIN_INTERVAL 60
|
||||
#define BLE_WRITE_MIN_INTERVAL 15
|
||||
|
||||
bool SerialBLEInterface::isWriteBusy() const {
|
||||
return millis() < _last_write + BLE_WRITE_MIN_INTERVAL; // still too soon to start another write?
|
||||
|
||||
@@ -14,6 +14,7 @@ class SerialBLEInterface : public BaseSerialInterface, BLESecurityCallbacks, BLE
|
||||
bool oldDeviceConnected;
|
||||
bool _isEnabled;
|
||||
uint16_t last_conn_id;
|
||||
uint8_t _remote_bda[6]; // peer BDA, stored in onConnect for conn param updates
|
||||
uint32_t _pin_code;
|
||||
unsigned long _last_write;
|
||||
unsigned long adv_restart_time;
|
||||
@@ -23,7 +24,7 @@ class SerialBLEInterface : public BaseSerialInterface, BLESecurityCallbacks, BLE
|
||||
uint8_t buf[MAX_FRAME_SIZE];
|
||||
};
|
||||
|
||||
#define FRAME_QUEUE_SIZE 4
|
||||
#define FRAME_QUEUE_SIZE 16
|
||||
int recv_queue_len;
|
||||
Frame recv_queue[FRAME_QUEUE_SIZE];
|
||||
int send_queue_len;
|
||||
@@ -58,6 +59,7 @@ public:
|
||||
_isEnabled = false;
|
||||
_last_write = 0;
|
||||
last_conn_id = 0;
|
||||
memset(_remote_bda, 0, 6);
|
||||
send_queue_len = recv_queue_len = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ size_t SerialWifiInterface::writeFrame(const uint8_t src[], size_t len) {
|
||||
}
|
||||
|
||||
bool SerialWifiInterface::isWriteBusy() const {
|
||||
return false;
|
||||
return send_queue_len >= (FRAME_QUEUE_SIZE * 3 / 4); // backpressure at 75% full
|
||||
}
|
||||
|
||||
bool SerialWifiInterface::hasReceivedFrameHeader() {
|
||||
@@ -82,8 +82,8 @@ size_t SerialWifiInterface::checkRecvFrame(uint8_t dest[]) {
|
||||
}
|
||||
|
||||
if (deviceConnected) {
|
||||
if (send_queue_len > 0) { // first, check send queue
|
||||
|
||||
// drain all pending send frames — WiFi TCP can handle the throughput
|
||||
while (send_queue_len > 0) {
|
||||
_last_write = millis();
|
||||
int len = send_queue[0].len;
|
||||
|
||||
@@ -97,70 +97,68 @@ size_t SerialWifiInterface::checkRecvFrame(uint8_t dest[]) {
|
||||
for (int i = 0; i < send_queue_len; i++) { // delete top item from queue
|
||||
send_queue[i] = send_queue[i + 1];
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
// check if we are waiting for a frame header
|
||||
if(!hasReceivedFrameHeader()){
|
||||
// check if we are waiting for a frame header
|
||||
if(!hasReceivedFrameHeader()){
|
||||
|
||||
// make sure we have received enough bytes for a frame header
|
||||
// 3 bytes frame header = (1 byte frame type) + (2 bytes frame length as unsigned 16-bit little endian)
|
||||
int frame_header_length = 3;
|
||||
if(client.available() >= frame_header_length){
|
||||
// make sure we have received enough bytes for a frame header
|
||||
// 3 bytes frame header = (1 byte frame type) + (2 bytes frame length as unsigned 16-bit little endian)
|
||||
int frame_header_length = 3;
|
||||
if(client.available() >= frame_header_length){
|
||||
|
||||
// read frame header
|
||||
client.readBytes(&received_frame_header.type, 1);
|
||||
client.readBytes((uint8_t*)&received_frame_header.length, 2);
|
||||
|
||||
}
|
||||
// read frame header
|
||||
client.readBytes(&received_frame_header.type, 1);
|
||||
client.readBytes((uint8_t*)&received_frame_header.length, 2);
|
||||
|
||||
}
|
||||
|
||||
// check if we have received a frame header
|
||||
if(hasReceivedFrameHeader()){
|
||||
}
|
||||
|
||||
// make sure we have received enough bytes for the required frame length
|
||||
int available = client.available();
|
||||
int frame_type = received_frame_header.type;
|
||||
int frame_length = received_frame_header.length;
|
||||
if(frame_length > available){
|
||||
WIFI_DEBUG_PRINTLN("Waiting for %d more bytes", frame_length - available);
|
||||
return 0;
|
||||
// check if we have received a frame header
|
||||
if(hasReceivedFrameHeader()){
|
||||
|
||||
// make sure we have received enough bytes for the required frame length
|
||||
int available = client.available();
|
||||
int frame_type = received_frame_header.type;
|
||||
int frame_length = received_frame_header.length;
|
||||
if(frame_length > available){
|
||||
WIFI_DEBUG_PRINTLN("Waiting for %d more bytes", frame_length - available);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// skip frames that are larger than MAX_FRAME_SIZE
|
||||
if(frame_length > MAX_FRAME_SIZE){
|
||||
WIFI_DEBUG_PRINTLN("Skipping frame: length=%d is larger than MAX_FRAME_SIZE=%d", frame_length, MAX_FRAME_SIZE);
|
||||
while(frame_length > 0){
|
||||
uint8_t skip[1];
|
||||
int skipped = client.read(skip, 1);
|
||||
frame_length -= skipped;
|
||||
}
|
||||
|
||||
// skip frames that are larger than MAX_FRAME_SIZE
|
||||
if(frame_length > MAX_FRAME_SIZE){
|
||||
WIFI_DEBUG_PRINTLN("Skipping frame: length=%d is larger than MAX_FRAME_SIZE=%d", frame_length, MAX_FRAME_SIZE);
|
||||
while(frame_length > 0){
|
||||
uint8_t skip[1];
|
||||
int skipped = client.read(skip, 1);
|
||||
frame_length -= skipped;
|
||||
}
|
||||
resetReceivedFrameHeader();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// skip frames that are not expected type
|
||||
// '<' is 0x3c which indicates a frame sent from app to radio
|
||||
if(frame_type != '<'){
|
||||
WIFI_DEBUG_PRINTLN("Skipping frame: type=0x%x is unexpected", frame_type);
|
||||
while(frame_length > 0){
|
||||
uint8_t skip[1];
|
||||
int skipped = client.read(skip, 1);
|
||||
frame_length -= skipped;
|
||||
}
|
||||
resetReceivedFrameHeader();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// read frame data to provided buffer
|
||||
client.readBytes(dest, frame_length);
|
||||
|
||||
// ready for next frame
|
||||
resetReceivedFrameHeader();
|
||||
return frame_length;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// skip frames that are not expected type
|
||||
// '<' is 0x3c which indicates a frame sent from app to radio
|
||||
if(frame_type != '<'){
|
||||
WIFI_DEBUG_PRINTLN("Skipping frame: type=0x%x is unexpected", frame_type);
|
||||
while(frame_length > 0){
|
||||
uint8_t skip[1];
|
||||
int skipped = client.read(skip, 1);
|
||||
frame_length -= skipped;
|
||||
}
|
||||
resetReceivedFrameHeader();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// read frame data to provided buffer
|
||||
client.readBytes(dest, frame_length);
|
||||
|
||||
// ready for next frame
|
||||
resetReceivedFrameHeader();
|
||||
return frame_length;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class SerialWifiInterface : public BaseSerialInterface {
|
||||
|
||||
FrameHeader received_frame_header;
|
||||
|
||||
#define FRAME_QUEUE_SIZE 4
|
||||
#define FRAME_QUEUE_SIZE 64
|
||||
int recv_queue_len;
|
||||
Frame recv_queue[FRAME_QUEUE_SIZE];
|
||||
int send_queue_len;
|
||||
@@ -68,4 +68,4 @@ public:
|
||||
#else
|
||||
#define WIFI_DEBUG_PRINT(...) {}
|
||||
#define WIFI_DEBUG_PRINTLN(...) {}
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,350 +0,0 @@
|
||||
#if defined(TBEAM_SUPREME_SX1262) || defined(TBEAM_SX1262) || defined(TBEAM_SX1276)
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "TBeamBoard.h"
|
||||
//#include <RadioLib.h>
|
||||
|
||||
uint32_t deviceOnline = 0x00;
|
||||
|
||||
bool pmuInterrupt;
|
||||
static void setPmuFlag()
|
||||
{
|
||||
pmuInterrupt = true;
|
||||
}
|
||||
|
||||
void TBeamBoard::begin() {
|
||||
|
||||
ESP32Board::begin();
|
||||
|
||||
power_init();
|
||||
|
||||
//Configure user button
|
||||
pinMode(PIN_USER_BTN, INPUT);
|
||||
|
||||
#ifndef TBEAM_SUPREME_SX1262
|
||||
digitalWrite(P_LORA_TX_LED, HIGH); //inverted pin for SX1276 - HIGH for off
|
||||
#endif
|
||||
|
||||
//radiotype_detect();
|
||||
|
||||
esp_reset_reason_t reason = esp_reset_reason();
|
||||
if (reason == ESP_RST_DEEPSLEEP) {
|
||||
long wakeup_source = esp_sleep_get_ext1_wakeup_status();
|
||||
if (wakeup_source & (1 << P_LORA_DIO_1)) { // received a LoRa packet (while in deep sleep)
|
||||
startup_reason = BD_STARTUP_RX_PACKET;
|
||||
}
|
||||
|
||||
rtc_gpio_hold_dis((gpio_num_t)P_LORA_NSS);
|
||||
rtc_gpio_deinit((gpio_num_t)P_LORA_DIO_1);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MESH_DEBUG
|
||||
void TBeamBoard::scanDevices(TwoWire *w)
|
||||
{
|
||||
uint8_t err, addr;
|
||||
int nDevices = 0;
|
||||
uint32_t start = 0;
|
||||
|
||||
Serial.println("Scanning I2C for Devices");
|
||||
for (addr = 1; addr < 127; addr++) {
|
||||
start = millis();
|
||||
w->beginTransmission(addr); delay(2);
|
||||
err = w->endTransmission();
|
||||
if (err == 0) {
|
||||
nDevices++;
|
||||
switch (addr) {
|
||||
case 0x77:
|
||||
case 0x76:
|
||||
Serial.println("\tFound BME280 Sensor");
|
||||
deviceOnline |= BME280_ONLINE;
|
||||
break;
|
||||
case 0x34:
|
||||
Serial.println("\tFound AXP192/AXP2101 PMU");
|
||||
deviceOnline |= POWERMANAGE_ONLINE;
|
||||
break;
|
||||
case 0x3C:
|
||||
Serial.println("\tFound SSD1306/SH1106 display");
|
||||
deviceOnline |= DISPLAY_ONLINE;
|
||||
break;
|
||||
case 0x51:
|
||||
Serial.println("\tFound PCF8563 RTC");
|
||||
deviceOnline |= PCF8563_ONLINE;
|
||||
break;
|
||||
case 0x1C:
|
||||
Serial.println("\tFound QMC6310 MAG Sensor");
|
||||
deviceOnline |= QMC6310_ONLINE;
|
||||
break;
|
||||
default:
|
||||
Serial.print("\tI2C device found at address 0x");
|
||||
if (addr < 16) {
|
||||
Serial.print("0");
|
||||
}
|
||||
Serial.print(addr, HEX);
|
||||
Serial.println(" !");
|
||||
break;
|
||||
}
|
||||
|
||||
} else if (err == 4) {
|
||||
Serial.print("Unknow error at address 0x");
|
||||
if (addr < 16) {
|
||||
Serial.print("0");
|
||||
}
|
||||
Serial.println(addr, HEX);
|
||||
}
|
||||
}
|
||||
if (nDevices == 0)
|
||||
Serial.println("No I2C devices found\n");
|
||||
|
||||
Serial.println("Scan for devices is complete.");
|
||||
Serial.println("\n");
|
||||
|
||||
Serial.printf("GPS RX pin: %d", PIN_GPS_RX);
|
||||
Serial.printf(" GPS TX pin: %d", PIN_GPS_TX);
|
||||
Serial.println();
|
||||
}
|
||||
void TBeamBoard::printPMU()
|
||||
{
|
||||
Serial.print("isCharging:"); Serial.println(PMU->isCharging() ? "YES" : "NO");
|
||||
Serial.print("isDischarge:"); Serial.println(PMU->isDischarge() ? "YES" : "NO");
|
||||
Serial.print("isVbusIn:"); Serial.println(PMU->isVbusIn() ? "YES" : "NO");
|
||||
Serial.print("getBattVoltage:"); Serial.print(PMU->getBattVoltage()); Serial.println("mV");
|
||||
Serial.print("getVbusVoltage:"); Serial.print(PMU->getVbusVoltage()); Serial.println("mV");
|
||||
Serial.print("getSystemVoltage:"); Serial.print(PMU->getSystemVoltage()); Serial.println("mV");
|
||||
|
||||
// The battery percentage may be inaccurate at first use, the PMU will automatically
|
||||
// learn the battery curve and will automatically calibrate the battery percentage
|
||||
// after a charge and discharge cycle
|
||||
if (PMU->isBatteryConnect()) {
|
||||
Serial.print("getBatteryPercent:"); Serial.print(PMU->getBatteryPercent()); Serial.println("%");
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
}
|
||||
#endif
|
||||
|
||||
bool TBeamBoard::power_init()
|
||||
{
|
||||
if (!PMU) {
|
||||
#ifdef TBEAM_SUPREME_SX1262
|
||||
PMU = new XPowersAXP2101(PMU_WIRE_PORT, PIN_BOARD_SDA1, PIN_BOARD_SCL1, I2C_PMU_ADD);
|
||||
#else
|
||||
PMU = new XPowersAXP2101(PMU_WIRE_PORT, PIN_BOARD_SDA, PIN_BOARD_SCL, I2C_PMU_ADD);
|
||||
#endif
|
||||
if (!PMU->init()) {
|
||||
MESH_DEBUG_PRINTLN("Warning: Failed to find AXP2101 power management");
|
||||
delete PMU;
|
||||
PMU = NULL;
|
||||
} else {
|
||||
MESH_DEBUG_PRINTLN("AXP2101 PMU init succeeded, using AXP2101 PMU");
|
||||
}
|
||||
}
|
||||
if (!PMU) {
|
||||
PMU = new XPowersAXP192(PMU_WIRE_PORT, PIN_BOARD_SDA, PIN_BOARD_SCL, I2C_PMU_ADD);
|
||||
if (!PMU->init()) {
|
||||
MESH_DEBUG_PRINTLN("Warning: Failed to find AXP192 power management");
|
||||
delete PMU;
|
||||
PMU = NULL;
|
||||
} else {
|
||||
MESH_DEBUG_PRINTLN("AXP192 PMU init succeeded, using AXP192 PMU");
|
||||
}
|
||||
}
|
||||
|
||||
if (!PMU) {
|
||||
return false;
|
||||
}
|
||||
|
||||
deviceOnline |= POWERMANAGE_ONLINE;
|
||||
|
||||
PMU->setChargingLedMode(XPOWERS_CHG_LED_CTRL_CHG);
|
||||
|
||||
// Set up PMU interrupts
|
||||
pinMode(PIN_PMU_IRQ, INPUT_PULLUP);
|
||||
attachInterrupt(PIN_PMU_IRQ, setPmuFlag, FALLING);
|
||||
|
||||
if (PMU->getChipModel() == XPOWERS_AXP192) {
|
||||
|
||||
PMU->setPowerChannelVoltage(XPOWERS_LDO2, 3300); //Set up LoRa power rail
|
||||
PMU->enablePowerOutput(XPOWERS_LDO2); //Enable the LoRa power rail
|
||||
|
||||
PMU->setPowerChannelVoltage(XPOWERS_DCDC1, 3300); //Set up OLED power rail
|
||||
PMU->enablePowerOutput(XPOWERS_DCDC1); //Enable the OLED power rail
|
||||
|
||||
PMU->setPowerChannelVoltage(XPOWERS_LDO3, 3300); //Set up GPS power rail
|
||||
PMU->enablePowerOutput(XPOWERS_LDO3); //Enable the GPS power rail
|
||||
|
||||
PMU->setProtectedChannel(XPOWERS_DCDC1); //Protect the OLED power rail
|
||||
PMU->setProtectedChannel(XPOWERS_DCDC3); //Protect the ESP32 power rail
|
||||
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC2); //Disable unsused power rail DC2
|
||||
|
||||
PMU->disableIRQ(XPOWERS_AXP192_ALL_IRQ); //Disable PMU IRQ
|
||||
|
||||
PMU->setChargerConstantCurr(XPOWERS_AXP192_CHG_CUR_450MA); //Set battery charging current
|
||||
PMU->setChargeTargetVoltage(XPOWERS_AXP192_CHG_VOL_4V2); //Set battery charge-stop voltage
|
||||
}
|
||||
else if(PMU->getChipModel() == XPOWERS_AXP2101){
|
||||
#ifdef TBEAM_SUPREME_SX1262
|
||||
//Set up the GPS power rail
|
||||
PMU->setPowerChannelVoltage(XPOWERS_ALDO4, 3300);
|
||||
PMU->enablePowerOutput(XPOWERS_ALDO4);
|
||||
|
||||
//Set up the LoRa power rail
|
||||
PMU->setPowerChannelVoltage(XPOWERS_ALDO3, 3300);
|
||||
PMU->enablePowerOutput(XPOWERS_ALDO3);
|
||||
|
||||
//Set up power rail for the M.2 interface
|
||||
PMU->setPowerChannelVoltage(XPOWERS_DCDC3, 3300);
|
||||
PMU->enablePowerOutput(XPOWERS_DCDC3);
|
||||
|
||||
if (ESP_SLEEP_WAKEUP_UNDEFINED == esp_sleep_get_wakeup_cause()) {
|
||||
MESH_DEBUG_PRINTLN("Power off and restart ALDO BLDO..");
|
||||
PMU->disablePowerOutput(XPOWERS_ALDO1);
|
||||
PMU->disablePowerOutput(XPOWERS_ALDO2);
|
||||
PMU->disablePowerOutput(XPOWERS_BLDO1);
|
||||
delay(250);
|
||||
}
|
||||
|
||||
//Set up power rail for QMC6310U
|
||||
PMU->setPowerChannelVoltage(XPOWERS_ALDO2, 3300);
|
||||
PMU->enablePowerOutput(XPOWERS_ALDO2);
|
||||
|
||||
//Set up power rail for BME280 and OLED
|
||||
PMU->setPowerChannelVoltage(XPOWERS_ALDO1, 3300);
|
||||
PMU->enablePowerOutput(XPOWERS_ALDO1);
|
||||
|
||||
//Set up pwer rail for SD Card
|
||||
PMU->setPowerChannelVoltage(XPOWERS_BLDO1, 3300);
|
||||
PMU->enablePowerOutput(XPOWERS_BLDO1);
|
||||
|
||||
//Set up power rail BLDO2 to headers
|
||||
PMU->setPowerChannelVoltage(XPOWERS_BLDO2, 3300);
|
||||
PMU->enablePowerOutput(XPOWERS_BLDO2);
|
||||
|
||||
//Set up power rail DCDC4 to headers
|
||||
PMU->setPowerChannelVoltage(XPOWERS_DCDC4, XPOWERS_AXP2101_DCDC4_VOL2_MAX);
|
||||
PMU->enablePowerOutput(XPOWERS_DCDC4);
|
||||
|
||||
//Set up power rail DCDC5 to headers
|
||||
PMU->setPowerChannelVoltage(XPOWERS_DCDC5, 3300);
|
||||
PMU->enablePowerOutput(XPOWERS_DCDC5);
|
||||
|
||||
//Disable unused power rails
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC2);
|
||||
PMU->disablePowerOutput(XPOWERS_DLDO1);
|
||||
PMU->disablePowerOutput(XPOWERS_DLDO2);
|
||||
PMU->disablePowerOutput(XPOWERS_VBACKUP);
|
||||
#else
|
||||
//Turn off unused power rails
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC2);
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC3);
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC4);
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC5);
|
||||
PMU->disablePowerOutput(XPOWERS_ALDO1);
|
||||
PMU->disablePowerOutput(XPOWERS_ALDO4);
|
||||
PMU->disablePowerOutput(XPOWERS_BLDO1);
|
||||
PMU->disablePowerOutput(XPOWERS_BLDO2);
|
||||
PMU->disablePowerOutput(XPOWERS_DLDO1);
|
||||
PMU->disablePowerOutput(XPOWERS_DLDO2);
|
||||
//PMU->disablePowerOutput(XPOWERS_CPULDO);
|
||||
|
||||
PMU->setPowerChannelVoltage(XPOWERS_VBACKUP, 3300); //Set up GPS RTC power
|
||||
PMU->enablePowerOutput(XPOWERS_VBACKUP); //Turn on GPS RTC power
|
||||
|
||||
PMU->setPowerChannelVoltage(XPOWERS_ALDO2, 3300); //Set up LoRa power rail
|
||||
PMU->enablePowerOutput(XPOWERS_ALDO2); //Enable LoRa power rail
|
||||
|
||||
PMU->setPowerChannelVoltage(XPOWERS_ALDO3, 3300); //Set up GPS power rail
|
||||
PMU->enablePowerOutput(XPOWERS_ALDO3); //Enable GPS power rail
|
||||
|
||||
#endif
|
||||
|
||||
PMU->disableIRQ(XPOWERS_AXP2101_ALL_IRQ); //Disable all PMU interrupts
|
||||
|
||||
PMU->setChargerConstantCurr(XPOWERS_AXP2101_CHG_CUR_500MA); //Set battery charging current to 500mA
|
||||
PMU->setChargeTargetVoltage(XPOWERS_AXP2101_CHG_VOL_4V2); //Set battery charging cutoff voltage to 4.2V
|
||||
|
||||
}
|
||||
|
||||
PMU->clearIrqStatus(); //Clear interrupt flags
|
||||
|
||||
PMU->disableTSPinMeasure(); //Disable TS detection, since it is not used
|
||||
|
||||
//Enable voltage measurements
|
||||
PMU->enableSystemVoltageMeasure();
|
||||
PMU->enableVbusVoltageMeasure();
|
||||
PMU->enableBattVoltageMeasure();
|
||||
|
||||
#ifdef MESH_DEBUG
|
||||
scanDevices(&Wire);
|
||||
printPMU();
|
||||
#endif
|
||||
|
||||
// Set the power key off press time
|
||||
PMU->setPowerKeyPressOffTime(XPOWERS_POWEROFF_4S);
|
||||
return true;
|
||||
}
|
||||
|
||||
#pragma region "Debug code"
|
||||
// void TBeamBoard::radiotype_detect(){
|
||||
|
||||
// static SPIClass spi;
|
||||
// char chipTypeInfo;
|
||||
|
||||
// #if defined(P_LORA_SCLK)
|
||||
// spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI);
|
||||
// #endif
|
||||
|
||||
// for(int i = 0; i<radioVersions; i++){
|
||||
// switch(i){
|
||||
// case 0:
|
||||
// CustomSX1262 radio = new Module(P_LORA_NSS, P_LORA_DIO_0, P_LORA_RESET, P_LORA_DIO_1, spi);
|
||||
// int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8);
|
||||
// if (status != RADIOLIB_ERR_NONE) {
|
||||
// Serial.print("ERROR: SX1262 not found: ");
|
||||
// Serial.println(status);
|
||||
// //delete radio;
|
||||
// radio = NULL;
|
||||
// break;
|
||||
// }
|
||||
// else{
|
||||
// MESH_DEBUG_PRINTLN("SX1262 detected");
|
||||
// P_LORA_BUSY = 32;
|
||||
// RADIO_CLASS = CustomSX1262;
|
||||
// WRAPPER_CLASS = CustomSX1262Wrapper;
|
||||
// SX126X_RX_BOOSTED_GAIN = true;
|
||||
// SX126X_CURRENT_LIMIT = 140;
|
||||
// //delete radio;
|
||||
// radio = NULL;
|
||||
// break;
|
||||
// }
|
||||
// case 1:
|
||||
// SX1276 radio = new Module(P_LORA_NSS, P_LORA_DIO_0, P_LORA_RESET, P_LORA_DIO_1, spi);
|
||||
// int status1 = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8);
|
||||
// if (status1 != RADIOLIB_ERR_NONE) {
|
||||
// Serial.print("ERROR: SX1272 not found: ");
|
||||
// Serial.println(status1);
|
||||
// //delete radio;
|
||||
// radio = NULL;
|
||||
// }
|
||||
// else{
|
||||
// MESH_DEBUG_PRINTLN("SX1272 detected");
|
||||
// P_LORA_BUSY = RADIOLIB_NC;
|
||||
// P_LORA_DIO_2 = 32;
|
||||
// RADIO_CLASS = CustomSX1272;
|
||||
// WRAPPER_CLASS = CustomSX1272Wrapper;
|
||||
// SX127X_CURRENT_LIMIT = 120;
|
||||
// //delete radio;
|
||||
// radio = NULL;
|
||||
// return;
|
||||
// }
|
||||
// default:
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// }
|
||||
#pragma endregion
|
||||
|
||||
#endif
|
||||
@@ -1,166 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#if defined(TBEAM_SUPREME_SX1262) || defined(TBEAM_SX1262) || defined(TBEAM_SX1276)
|
||||
|
||||
// Define pin mappings BEFORE including ESP32Board.h so sleep() can use P_LORA_DIO_1
|
||||
#ifdef TBEAM_SUPREME_SX1262
|
||||
// LoRa radio module pins for TBeam S3 Supreme SX1262
|
||||
#define P_LORA_DIO_0 -1 //NC
|
||||
#define P_LORA_DIO_1 1 //SX1262 IRQ pin
|
||||
#define P_LORA_NSS 10 //SX1262 SS pin
|
||||
#define P_LORA_RESET 5 //SX1262 Rest pin
|
||||
#define P_LORA_BUSY 4 //SX1262 Busy pin
|
||||
#define P_LORA_SCLK 12 //SX1262 SCLK pin
|
||||
#define P_LORA_MISO 13 //SX1262 MISO pin
|
||||
#define P_LORA_MOSI 11 //SX1262 MOSI pin
|
||||
|
||||
#define PIN_BOARD_SDA1 42 //SDA for PMU and PFC8563 (RTC)
|
||||
#define PIN_BOARD_SCL1 41 //SCL for PMU and PFC8563 (RTC)
|
||||
|
||||
#define PIN_PMU_IRQ 40 //IRQ pin for PMU
|
||||
|
||||
// #define PIN_GPS_RX 9
|
||||
// #define PIN_GPS_TX 8
|
||||
// #define PIN_GPS_EN 7
|
||||
|
||||
#define P_BOARD_SPI_MOSI 35 //SPI for SD Card and QMI8653 (IMU)
|
||||
#define P_BOARD_SPI_MISO 37 //SPI for SD Card and QMI8653 (IMU)
|
||||
#define P_BOARD_SPI_SCK 36 //SPI for SD Card and QMI8653 (IMU)
|
||||
#define P_BPARD_SPI_CS 47 //Pin for SD Card CS
|
||||
#define P_BOARD_IMU_CS 34 //Pin for QMI8653 (IMU) CS
|
||||
|
||||
#define P_BOARD_IMU_INT 33 //IMU Int pin
|
||||
#define P_BOARD_RTC_INT 14 //RTC Int pin
|
||||
|
||||
//I2C Wire addresses
|
||||
#define I2C_BME280_ADD 0x76 //BME280 sensor I2C address on Wire
|
||||
#define I2C_OLED_ADD 0x3C //SH1106 OLED I2C address on Wire
|
||||
#define I2C_QMC6310U_ADD 0x1C //QMC6310U mag sensor I2C address on Wire
|
||||
|
||||
//I2C Wire1 addresses
|
||||
#define I2C_RTC_ADD 0x51 //RTC I2C address on Wire1
|
||||
#define I2C_PMU_ADD 0x34 //AXP2101 I2C address on Wire1
|
||||
|
||||
#define PMU_WIRE_PORT Wire1
|
||||
#define RTC_WIRE_PORT Wire1
|
||||
#endif
|
||||
|
||||
#ifdef TBEAM_SX1262
|
||||
#define P_LORA_BUSY 32
|
||||
#endif
|
||||
|
||||
#ifdef TBEAM_SX1276
|
||||
#define P_LORA_DIO_2 32
|
||||
#define P_LORA_BUSY RADIOLIB_NC
|
||||
#endif
|
||||
|
||||
#if defined(TBEAM_SX1262) || defined(TBEAM_SX1276)
|
||||
// LoRa radio module pins for TBeam
|
||||
// uint32_t P_LORA_BUSY = 0; //shared, so define at run
|
||||
// uint32_t P_LORA_DIO_2 = 0; //SX1276 only, so define at run
|
||||
|
||||
#define P_LORA_DIO_0 26
|
||||
#define P_LORA_DIO_1 33
|
||||
#define P_LORA_NSS 18
|
||||
#define P_LORA_RESET 23
|
||||
#define P_LORA_SCLK 5
|
||||
#define P_LORA_MISO 19
|
||||
#define P_LORA_MOSI 27
|
||||
|
||||
// #define PIN_GPS_RX 34
|
||||
// #define PIN_GPS_TX 12
|
||||
|
||||
#define PIN_PMU_IRQ 35
|
||||
#define PMU_WIRE_PORT Wire
|
||||
#define RTC_WIRE_PORT Wire
|
||||
#define I2C_PMU_ADD 0x34
|
||||
#endif
|
||||
|
||||
// enum RadioType {
|
||||
// SX1262,
|
||||
// SX1276
|
||||
// };
|
||||
|
||||
// Include headers AFTER pin definitions so ESP32Board::sleep() can use P_LORA_DIO_1
|
||||
#include <Wire.h>
|
||||
#include <Arduino.h>
|
||||
#include "XPowersLib.h"
|
||||
#include "helpers/ESP32Board.h"
|
||||
#include <driver/rtc_io.h>
|
||||
|
||||
class TBeamBoard : public ESP32Board {
|
||||
XPowersLibInterface *PMU = NULL;
|
||||
//PhysicalLayer * pl;
|
||||
//RadioType * radio = NULL;
|
||||
// int radioVersions = 2;
|
||||
|
||||
enum {
|
||||
POWERMANAGE_ONLINE = _BV(0),
|
||||
DISPLAY_ONLINE = _BV(1),
|
||||
RADIO_ONLINE = _BV(2),
|
||||
GPS_ONLINE = _BV(3),
|
||||
PSRAM_ONLINE = _BV(4),
|
||||
SDCARD_ONLINE = _BV(5),
|
||||
AXDL345_ONLINE = _BV(6),
|
||||
BME280_ONLINE = _BV(7),
|
||||
BMP280_ONLINE = _BV(8),
|
||||
BME680_ONLINE = _BV(9),
|
||||
QMC6310_ONLINE = _BV(10),
|
||||
QMI8658_ONLINE = _BV(11),
|
||||
PCF8563_ONLINE = _BV(12),
|
||||
OSC32768_ONLINE = _BV(13),
|
||||
};
|
||||
|
||||
bool power_init();
|
||||
//void radiotype_detect();
|
||||
|
||||
public:
|
||||
|
||||
#ifdef MESH_DEBUG
|
||||
void printPMU();
|
||||
void scanDevices(TwoWire *w);
|
||||
#endif
|
||||
void begin();
|
||||
|
||||
#ifndef TBEAM_SUPREME_SX1262
|
||||
void onBeforeTransmit() override{
|
||||
digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED on - invert pin for SX1276
|
||||
}
|
||||
void onAfterTransmit() override{
|
||||
digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED off - invert pin for SX1276
|
||||
}
|
||||
#endif
|
||||
|
||||
void enterDeepSleep(uint32_t secs, int pin_wake_btn) {
|
||||
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
|
||||
|
||||
// Make sure the DIO1 and NSS GPIOs are hold on required levels during deep sleep
|
||||
rtc_gpio_set_direction((gpio_num_t)P_LORA_DIO_1, RTC_GPIO_MODE_INPUT_ONLY);
|
||||
rtc_gpio_pulldown_en((gpio_num_t)P_LORA_DIO_1);
|
||||
|
||||
rtc_gpio_hold_en((gpio_num_t)P_LORA_NSS);
|
||||
|
||||
if (pin_wake_btn < 0) {
|
||||
esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet
|
||||
} else {
|
||||
esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1) | (1L << pin_wake_btn), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet OR wake btn
|
||||
}
|
||||
|
||||
if (secs > 0) {
|
||||
esp_sleep_enable_timer_wakeup(secs * 1000000);
|
||||
}
|
||||
|
||||
// Finally set ESP32 into sleep
|
||||
esp_deep_sleep_start(); // CPU halts here and never returns!
|
||||
}
|
||||
|
||||
uint16_t getBattMilliVolts(){
|
||||
return PMU->getBattVoltage();
|
||||
}
|
||||
|
||||
const char* getManufacturerName() const{
|
||||
return "LilyGo T-Beam";
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -246,6 +246,7 @@ void SerialBLEInterface::enable() {
|
||||
clearBuffers();
|
||||
_last_health_check = millis();
|
||||
|
||||
Bluefruit.Advertising.restartOnDisconnect(true);
|
||||
Bluefruit.Advertising.start(0);
|
||||
}
|
||||
|
||||
@@ -259,8 +260,9 @@ void SerialBLEInterface::disable() {
|
||||
_isEnabled = false;
|
||||
BLE_DEBUG_PRINTLN("SerialBLEInterface: disable");
|
||||
|
||||
disconnect();
|
||||
Bluefruit.Advertising.restartOnDisconnect(false);
|
||||
Bluefruit.Advertising.stop();
|
||||
disconnect();
|
||||
_last_health_check = 0;
|
||||
}
|
||||
|
||||
@@ -394,4 +396,4 @@ bool SerialBLEInterface::isConnected() const {
|
||||
|
||||
bool SerialBLEInterface::isWriteBusy() const {
|
||||
return send_queue_len >= (FRAME_QUEUE_SIZE * 2 / 3);
|
||||
}
|
||||
}
|
||||
@@ -77,4 +77,4 @@ public:
|
||||
#else
|
||||
#define BLE_DEBUG_PRINT(...) {}
|
||||
#define BLE_DEBUG_PRINTLN(...) {}
|
||||
#endif
|
||||
#endif
|
||||
@@ -25,6 +25,14 @@ bool GxEPDDisplay::begin() {
|
||||
// Tell GxEPD2 to use our SPI instance
|
||||
// Using slower speed (4MHz) for reliable e-ink communication
|
||||
display.epd2.selectSPI(displaySpi, SPISettings(4000000, MSBFIRST, SPI_MODE0));
|
||||
#elif defined(NRF52_PLATFORM)
|
||||
// nRF52 (Meshpocket et al): LoRa sits on the default SPI bus (PIN_SPI_MISO/
|
||||
// MOSI/SCK), e-ink sits on SPI1 (MISO/MOSI/SCK globals set by the variant's
|
||||
// variant.cpp). GxEPD2's default _pSPIx=&SPI would send display traffic to
|
||||
// the LoRa bus — hand the e-ink its own bus explicitly. This matches
|
||||
// upstream MeshCore's approach (which uses SPI1 universally).
|
||||
display.epd2.selectSPI(SPI1, SPISettings(4000000, MSBFIRST, SPI_MODE0));
|
||||
SPI1.begin();
|
||||
#endif
|
||||
|
||||
// Initialize with:
|
||||
@@ -52,7 +60,7 @@ bool GxEPDDisplay::begin() {
|
||||
|
||||
void GxEPDDisplay::turnOn() {
|
||||
if (!_init) begin();
|
||||
#if defined(DISP_BACKLIGHT) && !defined(BACKLIGHT_BTN)
|
||||
#if defined(DISP_BACKLIGHT) && !defined(BACKLIGHT_BTN) && !defined(LilyGo_TDeck_Pro)
|
||||
digitalWrite(DISP_BACKLIGHT, HIGH);
|
||||
#elif defined(EXP_PIN_BACKLIGHT) && !defined(BACKLIGHT_BTN)
|
||||
expander.digitalWrite(EXP_PIN_BACKLIGHT, HIGH);
|
||||
@@ -61,12 +69,17 @@ void GxEPDDisplay::turnOn() {
|
||||
}
|
||||
|
||||
void GxEPDDisplay::turnOff() {
|
||||
#if defined(DISP_BACKLIGHT) && !defined(BACKLIGHT_BTN)
|
||||
#if defined(DISP_BACKLIGHT) && !defined(BACKLIGHT_BTN) && !defined(LilyGo_TDeck_Pro)
|
||||
// Only toggle backlight on boards that actually have one.
|
||||
// T-Deck Pro defines DISP_BACKLIGHT (GPIO 45) but has no physical backlight —
|
||||
// setting _isOn=false would stop the render loop, making the device appear frozen.
|
||||
digitalWrite(DISP_BACKLIGHT, LOW);
|
||||
_isOn = false;
|
||||
#elif defined(EXP_PIN_BACKLIGHT) && !defined(BACKLIGHT_BTN)
|
||||
expander.digitalWrite(EXP_PIN_BACKLIGHT, LOW);
|
||||
#endif
|
||||
_isOn = false;
|
||||
#endif
|
||||
// T-Deck Pro: _isOn stays true — e-ink has no backlight, render loop must keep running
|
||||
}
|
||||
|
||||
void GxEPDDisplay::clear() {
|
||||
@@ -100,15 +113,23 @@ void GxEPDDisplay::setTextSize(int sz) {
|
||||
break;
|
||||
case 1: // Small - use 9pt (was 9pt)
|
||||
display.setFont(&FreeSans9pt7b);
|
||||
display.setTextSize(1);
|
||||
break;
|
||||
case 2: // Medium Bold - use 9pt bold instead of 12pt
|
||||
display.setFont(&FreeSans9pt7b);
|
||||
display.setTextSize(1);
|
||||
break;
|
||||
case 3: // Large - use 12pt instead of 18pt
|
||||
display.setFont(&FreeSansBold12pt7b);
|
||||
display.setTextSize(1);
|
||||
break;
|
||||
case 5: // Extra Large - lock screen clock face
|
||||
display.setFont(&FreeSansBold12pt7b);
|
||||
display.setTextSize(2); // GxEPD2 native 2× scaling on 12pt bold
|
||||
break;
|
||||
default:
|
||||
display.setFont(&FreeSans9pt7b);
|
||||
display.setTextSize(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <helpers/RefCountedDigitalPin.h>
|
||||
#include <helpers/ESP32Board.h>
|
||||
|
||||
// built-ins
|
||||
#ifndef PIN_VBAT_READ // set in platformio.ini for boards like Heltec Wireless Paper (20)
|
||||
#define PIN_VBAT_READ 1
|
||||
#endif
|
||||
#ifndef PIN_ADC_CTRL // set in platformio.ini for Heltec Wireless Tracker (2)
|
||||
#define PIN_ADC_CTRL 37
|
||||
#endif
|
||||
#define PIN_ADC_CTRL_ACTIVE LOW
|
||||
#define PIN_ADC_CTRL_INACTIVE HIGH
|
||||
|
||||
#include <driver/rtc_io.h>
|
||||
|
||||
class HeltecV3Board : public ESP32Board {
|
||||
private:
|
||||
bool adc_active_state;
|
||||
|
||||
public:
|
||||
RefCountedDigitalPin periph_power;
|
||||
|
||||
HeltecV3Board() : periph_power(PIN_VEXT_EN) { }
|
||||
|
||||
void begin() {
|
||||
ESP32Board::begin();
|
||||
|
||||
// Auto-detect correct ADC_CTRL pin polarity (different for boards >3.2)
|
||||
pinMode(PIN_ADC_CTRL, INPUT);
|
||||
adc_active_state = !digitalRead(PIN_ADC_CTRL);
|
||||
|
||||
pinMode(PIN_ADC_CTRL, OUTPUT);
|
||||
digitalWrite(PIN_ADC_CTRL, !adc_active_state); // Initially inactive
|
||||
|
||||
periph_power.begin();
|
||||
|
||||
esp_reset_reason_t reason = esp_reset_reason();
|
||||
if (reason == ESP_RST_DEEPSLEEP) {
|
||||
long wakeup_source = esp_sleep_get_ext1_wakeup_status();
|
||||
if (wakeup_source & (1 << P_LORA_DIO_1)) { // received a LoRa packet (while in deep sleep)
|
||||
startup_reason = BD_STARTUP_RX_PACKET;
|
||||
}
|
||||
|
||||
rtc_gpio_hold_dis((gpio_num_t)P_LORA_NSS);
|
||||
rtc_gpio_deinit((gpio_num_t)P_LORA_DIO_1);
|
||||
}
|
||||
}
|
||||
|
||||
void enterDeepSleep(uint32_t secs, int pin_wake_btn = -1) {
|
||||
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
|
||||
|
||||
// Make sure the DIO1 and NSS GPIOs are hold on required levels during deep sleep
|
||||
rtc_gpio_set_direction((gpio_num_t)P_LORA_DIO_1, RTC_GPIO_MODE_INPUT_ONLY);
|
||||
rtc_gpio_pulldown_en((gpio_num_t)P_LORA_DIO_1);
|
||||
|
||||
rtc_gpio_hold_en((gpio_num_t)P_LORA_NSS);
|
||||
|
||||
if (pin_wake_btn < 0) {
|
||||
esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet
|
||||
} else {
|
||||
esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1) | (1L << pin_wake_btn), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet OR wake btn
|
||||
}
|
||||
|
||||
if (secs > 0) {
|
||||
esp_sleep_enable_timer_wakeup(secs * 1000000);
|
||||
}
|
||||
|
||||
// Finally set ESP32 into sleep
|
||||
esp_deep_sleep_start(); // CPU halts here and never returns!
|
||||
}
|
||||
|
||||
void powerOff() override {
|
||||
enterDeepSleep(0);
|
||||
}
|
||||
|
||||
uint16_t getBattMilliVolts() override {
|
||||
analogReadResolution(10);
|
||||
digitalWrite(PIN_ADC_CTRL, adc_active_state);
|
||||
|
||||
uint32_t raw = 0;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
raw += analogRead(PIN_VBAT_READ);
|
||||
}
|
||||
raw = raw / 8;
|
||||
|
||||
digitalWrite(PIN_ADC_CTRL, !adc_active_state);
|
||||
|
||||
return (5.42 * (3.3 / 1024.0) * raw) * 1000;
|
||||
}
|
||||
|
||||
const char* getManufacturerName() const override {
|
||||
return "Heltec V3";
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,61 @@
|
||||
[Heltec_lora32_v3]
|
||||
extends = esp32_base
|
||||
board = esp32-s3-devkitc-1
|
||||
build_flags =
|
||||
${esp32_base.build_flags}
|
||||
${sensor_base.build_flags}
|
||||
-I variants/heltec_v3
|
||||
-D HELTEC_LORA_V3
|
||||
-D ESP32_CPU_FREQ=80
|
||||
-D P_LORA_DIO_1=14
|
||||
-D P_LORA_NSS=8
|
||||
-D P_LORA_RESET=RADIOLIB_NC
|
||||
-D P_LORA_BUSY=13
|
||||
-D P_LORA_SCLK=9
|
||||
-D P_LORA_MISO=11
|
||||
-D P_LORA_MOSI=10
|
||||
-D USE_SX1262
|
||||
-D RADIO_CLASS=CustomSX1262
|
||||
-D WRAPPER_CLASS=CustomSX1262Wrapper
|
||||
-D LORA_TX_POWER=22
|
||||
; -D P_LORA_TX_LED=35
|
||||
-D PIN_BOARD_SDA=17
|
||||
-D PIN_BOARD_SCL=18
|
||||
-D PIN_USER_BTN=0
|
||||
-D PIN_VEXT_EN=36
|
||||
-D SX126X_DIO2_AS_RF_SWITCH=true
|
||||
-D SX126X_DIO3_TCXO_VOLTAGE=1.8
|
||||
-D SX126X_CURRENT_LIMIT=140
|
||||
-D SX126X_RX_BOOSTED_GAIN=1
|
||||
-D PIN_GPS_RX=47
|
||||
-D PIN_GPS_TX=48
|
||||
-D PIN_GPS_EN=26
|
||||
build_src_filter = ${esp32_base.build_src_filter}
|
||||
+<../variants/heltec_v3>
|
||||
+<helpers/sensors>
|
||||
lib_deps =
|
||||
${esp32_base.lib_deps}
|
||||
${sensor_base.lib_deps}
|
||||
|
||||
[env:meck_wifi_repeater_heltec_v3]
|
||||
extends = Heltec_lora32_v3
|
||||
build_flags =
|
||||
${Heltec_lora32_v3.build_flags}
|
||||
-D DISPLAY_CLASS=SSD1306Display
|
||||
-D ADVERT_NAME='"WiFi Repeater"'
|
||||
-D ADVERT_LAT=0.0
|
||||
-D ADVERT_LON=0.0
|
||||
-D ADMIN_PASSWORD='"password"'
|
||||
-D MAX_NEIGHBOURS=50
|
||||
-D MECK_WIFI_REMOTE=1
|
||||
; -D MESH_PACKET_LOGGING=1
|
||||
; -D MESH_DEBUG=1
|
||||
build_src_filter = ${Heltec_lora32_v3.build_src_filter}
|
||||
+<helpers/ui/SSD1306Display.cpp>
|
||||
+<helpers/ui/MomentaryButton.cpp>
|
||||
+<../examples/simple_repeater>
|
||||
lib_deps =
|
||||
${Heltec_lora32_v3.lib_deps}
|
||||
${esp32_ota.lib_deps}
|
||||
knolleary/PubSubClient @ ^2.8
|
||||
bakercp/CRC32 @ ^2.0.0
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <Arduino.h>
|
||||
#include "target.h"
|
||||
|
||||
TDeckBoard board;
|
||||
HeltecV3Board board;
|
||||
|
||||
#if defined(P_LORA_SCLK)
|
||||
static SPIClass spi;
|
||||
@@ -14,8 +14,14 @@ WRAPPER_CLASS radio_driver(radio, board);
|
||||
|
||||
ESP32RTCClock fallback_clock;
|
||||
AutoDiscoverRTCClock rtc_clock(fallback_clock);
|
||||
MicroNMEALocationProvider gps(Serial1, &rtc_clock);
|
||||
EnvironmentSensorManager sensors(gps);
|
||||
|
||||
#if ENV_INCLUDE_GPS
|
||||
#include <helpers/sensors/MicroNMEALocationProvider.h>
|
||||
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
|
||||
EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
|
||||
#else
|
||||
EnvironmentSensorManager sensors;
|
||||
#endif
|
||||
|
||||
#ifdef DISPLAY_CLASS
|
||||
DISPLAY_CLASS display;
|
||||
@@ -25,8 +31,7 @@ EnvironmentSensorManager sensors(gps);
|
||||
bool radio_init() {
|
||||
fallback_clock.begin();
|
||||
rtc_clock.begin(Wire);
|
||||
Wire.begin(18, 8);
|
||||
|
||||
|
||||
#if defined(P_LORA_SCLK)
|
||||
return radio.std_init(&spi);
|
||||
#else
|
||||
@@ -45,11 +50,12 @@ void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
|
||||
radio.setCodingRate(cr);
|
||||
}
|
||||
|
||||
void radio_set_tx_power(uint8_t dbm) {
|
||||
void radio_set_tx_power(int8_t dbm) {
|
||||
radio.setOutputPower(dbm);
|
||||
}
|
||||
|
||||
mesh::LocalIdentity radio_new_identity() {
|
||||
RadioNoiseListener rng(radio);
|
||||
return mesh::LocalIdentity(&rng); // create new random identity
|
||||
}
|
||||
return mesh::LocalIdentity(&rng); // create new random identity
|
||||
}
|
||||
|
||||
@@ -3,18 +3,17 @@
|
||||
#define RADIOLIB_STATIC_ONLY 1
|
||||
#include <RadioLib.h>
|
||||
#include <helpers/radiolib/RadioLibWrappers.h>
|
||||
#include <HeltecV3Board.h>
|
||||
#include <helpers/radiolib/CustomSX1262Wrapper.h>
|
||||
#include <TDeckBoard.h>
|
||||
#include <helpers/AutoDiscoverRTCClock.h>
|
||||
#include <helpers/SensorManager.h>
|
||||
#include <helpers/sensors/EnvironmentSensorManager.h>
|
||||
#ifdef DISPLAY_CLASS
|
||||
#include <helpers/ui/ST7789LCDDisplay.h>
|
||||
#include <helpers/ui/SSD1306Display.h>
|
||||
#include <helpers/ui/MomentaryButton.h>
|
||||
#endif
|
||||
#include "helpers/sensors/EnvironmentSensorManager.h"
|
||||
#include "helpers/sensors/MicroNMEALocationProvider.h"
|
||||
|
||||
extern TDeckBoard board;
|
||||
extern HeltecV3Board board;
|
||||
extern WRAPPER_CLASS radio_driver;
|
||||
extern AutoDiscoverRTCClock rtc_clock;
|
||||
extern EnvironmentSensorManager sensors;
|
||||
@@ -27,5 +26,5 @@ extern EnvironmentSensorManager sensors;
|
||||
bool radio_init();
|
||||
uint32_t radio_get_rng_seed();
|
||||
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr);
|
||||
void radio_set_tx_power(uint8_t dbm);
|
||||
mesh::LocalIdentity radio_new_identity();
|
||||
void radio_set_tx_power(int8_t dbm);
|
||||
mesh::LocalIdentity radio_new_identity();
|
||||
@@ -0,0 +1,103 @@
|
||||
#include "HeltecV4Board.h"
|
||||
|
||||
void HeltecV4Board::begin() {
|
||||
ESP32Board::begin();
|
||||
|
||||
|
||||
pinMode(PIN_ADC_CTRL, OUTPUT);
|
||||
digitalWrite(PIN_ADC_CTRL, LOW); // Initially inactive
|
||||
|
||||
// Set up digital GPIO registers before releasing RTC hold. The hold latches
|
||||
// the pad state including function select, so register writes accumulate
|
||||
// without affecting the pad. On hold release, all changes apply atomically
|
||||
// (IO MUX switches to digital GPIO with output already HIGH — no glitch).
|
||||
pinMode(P_LORA_PA_POWER, OUTPUT);
|
||||
digitalWrite(P_LORA_PA_POWER,HIGH);
|
||||
rtc_gpio_hold_dis((gpio_num_t)P_LORA_PA_POWER);
|
||||
|
||||
pinMode(P_LORA_PA_EN, OUTPUT);
|
||||
digitalWrite(P_LORA_PA_EN,HIGH);
|
||||
rtc_gpio_hold_dis((gpio_num_t)P_LORA_PA_EN);
|
||||
pinMode(P_LORA_PA_TX_EN, OUTPUT);
|
||||
digitalWrite(P_LORA_PA_TX_EN,LOW);
|
||||
|
||||
esp_reset_reason_t reason = esp_reset_reason();
|
||||
if (reason != ESP_RST_DEEPSLEEP) {
|
||||
delay(1); // GC1109 startup time after cold power-on
|
||||
}
|
||||
|
||||
periph_power.begin();
|
||||
if (reason == ESP_RST_DEEPSLEEP) {
|
||||
long wakeup_source = esp_sleep_get_ext1_wakeup_status();
|
||||
if (wakeup_source & (1 << P_LORA_DIO_1)) { // received a LoRa packet (while in deep sleep)
|
||||
startup_reason = BD_STARTUP_RX_PACKET;
|
||||
}
|
||||
|
||||
rtc_gpio_hold_dis((gpio_num_t)P_LORA_NSS);
|
||||
rtc_gpio_deinit((gpio_num_t)P_LORA_DIO_1);
|
||||
}
|
||||
}
|
||||
|
||||
void HeltecV4Board::onBeforeTransmit(void) {
|
||||
digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED on
|
||||
digitalWrite(P_LORA_PA_TX_EN,HIGH);
|
||||
}
|
||||
|
||||
void HeltecV4Board::onAfterTransmit(void) {
|
||||
digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED off
|
||||
digitalWrite(P_LORA_PA_TX_EN,LOW);
|
||||
}
|
||||
|
||||
void HeltecV4Board::enterDeepSleep(uint32_t secs, int pin_wake_btn) {
|
||||
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
|
||||
|
||||
// Make sure the DIO1 and NSS GPIOs are hold on required levels during deep sleep
|
||||
rtc_gpio_set_direction((gpio_num_t)P_LORA_DIO_1, RTC_GPIO_MODE_INPUT_ONLY);
|
||||
rtc_gpio_pulldown_en((gpio_num_t)P_LORA_DIO_1);
|
||||
|
||||
rtc_gpio_hold_en((gpio_num_t)P_LORA_NSS);
|
||||
|
||||
// Hold GC1109 FEM pins during sleep to keep LNA active for RX wake
|
||||
rtc_gpio_hold_en((gpio_num_t)P_LORA_PA_POWER);
|
||||
rtc_gpio_hold_en((gpio_num_t)P_LORA_PA_EN);
|
||||
|
||||
if (pin_wake_btn < 0) {
|
||||
esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet
|
||||
} else {
|
||||
esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1) | (1L << pin_wake_btn), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet OR wake btn
|
||||
}
|
||||
|
||||
if (secs > 0) {
|
||||
esp_sleep_enable_timer_wakeup(secs * 1000000);
|
||||
}
|
||||
|
||||
// Finally set ESP32 into sleep
|
||||
esp_deep_sleep_start(); // CPU halts here and never returns!
|
||||
}
|
||||
|
||||
void HeltecV4Board::powerOff() {
|
||||
enterDeepSleep(0);
|
||||
}
|
||||
|
||||
uint16_t HeltecV4Board::getBattMilliVolts() {
|
||||
analogReadResolution(10);
|
||||
digitalWrite(PIN_ADC_CTRL, HIGH);
|
||||
delay(10);
|
||||
uint32_t raw = 0;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
raw += analogRead(PIN_VBAT_READ);
|
||||
}
|
||||
raw = raw / 8;
|
||||
|
||||
digitalWrite(PIN_ADC_CTRL, LOW);
|
||||
|
||||
return (5.42 * (3.3 / 1024.0) * raw) * 1000;
|
||||
}
|
||||
|
||||
const char* HeltecV4Board::getManufacturerName() const {
|
||||
#ifdef HELTEC_LORA_V4_TFT
|
||||
return "Heltec V4 TFT";
|
||||
#else
|
||||
return "Heltec V4 OLED";
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <helpers/RefCountedDigitalPin.h>
|
||||
#include <helpers/ESP32Board.h>
|
||||
#include <driver/rtc_io.h>
|
||||
|
||||
class HeltecV4Board : public ESP32Board {
|
||||
|
||||
public:
|
||||
RefCountedDigitalPin periph_power;
|
||||
|
||||
HeltecV4Board() : periph_power(PIN_VEXT_EN,PIN_VEXT_EN_ACTIVE) { }
|
||||
|
||||
void begin();
|
||||
void onBeforeTransmit(void) override;
|
||||
void onAfterTransmit(void) override;
|
||||
void enterDeepSleep(uint32_t secs, int pin_wake_btn = -1);
|
||||
void powerOff() override;
|
||||
uint16_t getBattMilliVolts() override;
|
||||
const char* getManufacturerName() const override ;
|
||||
|
||||
};
|
||||
@@ -0,0 +1,61 @@
|
||||
# Heltec V4 WiFi Remote Repeater — Setup Guide
|
||||
|
||||
## Variant Files
|
||||
|
||||
Copy the following into `variants/heltec_v4/`:
|
||||
- `HeltecV4Board.h`, `HeltecV4Board.cpp`
|
||||
- `target.h`, `target.cpp`
|
||||
- `pins_arduino.h`
|
||||
|
||||
Copy `heltec_v4.json` into `boards/`
|
||||
|
||||
## Config Files (SPIFFS)
|
||||
|
||||
The Heltec V4 has no SD card slot — config lives in SPIFFS.
|
||||
|
||||
Create a `data/remote/` folder in your project root:
|
||||
|
||||
```
|
||||
data/
|
||||
remote/
|
||||
wifi.cfg
|
||||
mqtt.cfg
|
||||
```
|
||||
|
||||
### data/remote/wifi.cfg
|
||||
```
|
||||
YourSSID
|
||||
YourPassword
|
||||
BackupSSID
|
||||
BackupPassword
|
||||
```
|
||||
|
||||
### data/remote/mqtt.cfg
|
||||
```
|
||||
6818ce5f77dd45bb90facf753ba81d81.s1.eu.hivemq.cloud
|
||||
8883
|
||||
meckremote
|
||||
yourpassword
|
||||
heltec-wifi-1
|
||||
```
|
||||
|
||||
### Upload config to SPIFFS
|
||||
```bash
|
||||
pio run -e meck_wifi_repeater_heltec_v4 -t uploadfs
|
||||
```
|
||||
|
||||
This uploads the `data/` folder contents to SPIFFS on the device.
|
||||
|
||||
### Flash firmware
|
||||
```bash
|
||||
pio run -e meck_wifi_repeater_heltec_v4 -t upload
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- The OLED display shows basic repeater status (same as stock repeater)
|
||||
- WiFi MQTT and Mycelium dashboard work identically to T-Deck Pro builds
|
||||
- OTA firmware updates work over WiFi via the Mycelium dashboard
|
||||
- Config changes require re-uploading SPIFFS (`-t uploadfs`)
|
||||
- The same `main.cpp`, `WiFiMQTT.h/cpp`, and `MyMesh.cpp` are shared
|
||||
with T-Deck Pro and T5S3 builds — no Heltec-specific source changes
|
||||
@@ -0,0 +1,67 @@
|
||||
#ifndef Pins_Arduino_h
|
||||
#define Pins_Arduino_h
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
static const uint8_t LED_BUILTIN = 35;
|
||||
#define BUILTIN_LED LED_BUILTIN // backward compatibility
|
||||
#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN
|
||||
|
||||
static const uint8_t TX = 43;
|
||||
static const uint8_t RX = 44;
|
||||
|
||||
static const uint8_t SDA = 3;
|
||||
static const uint8_t SCL = 4;
|
||||
|
||||
static const uint8_t SS = 8;
|
||||
static const uint8_t MOSI = 10;
|
||||
static const uint8_t MISO = 11;
|
||||
static const uint8_t SCK = 9;
|
||||
|
||||
static const uint8_t A0 = 1;
|
||||
static const uint8_t A1 = 2;
|
||||
static const uint8_t A2 = 3;
|
||||
static const uint8_t A3 = 4;
|
||||
static const uint8_t A4 = 5;
|
||||
static const uint8_t A5 = 6;
|
||||
static const uint8_t A6 = 7;
|
||||
static const uint8_t A7 = 8;
|
||||
static const uint8_t A8 = 9;
|
||||
static const uint8_t A9 = 10;
|
||||
static const uint8_t A10 = 11;
|
||||
static const uint8_t A11 = 12;
|
||||
static const uint8_t A12 = 13;
|
||||
static const uint8_t A13 = 14;
|
||||
static const uint8_t A14 = 15;
|
||||
static const uint8_t A15 = 16;
|
||||
static const uint8_t A16 = 17;
|
||||
static const uint8_t A17 = 18;
|
||||
static const uint8_t A18 = 19;
|
||||
static const uint8_t A19 = 20;
|
||||
|
||||
static const uint8_t T1 = 1;
|
||||
static const uint8_t T2 = 2;
|
||||
static const uint8_t T3 = 3;
|
||||
static const uint8_t T4 = 4;
|
||||
static const uint8_t T5 = 5;
|
||||
static const uint8_t T6 = 6;
|
||||
static const uint8_t T7 = 7;
|
||||
static const uint8_t T8 = 8;
|
||||
static const uint8_t T9 = 9;
|
||||
static const uint8_t T10 = 10;
|
||||
static const uint8_t T11 = 11;
|
||||
static const uint8_t T12 = 12;
|
||||
static const uint8_t T13 = 13;
|
||||
static const uint8_t T14 = 14;
|
||||
|
||||
static const uint8_t Vext = 36;
|
||||
static const uint8_t LED = 35;
|
||||
static const uint8_t RST_OLED = 21;
|
||||
static const uint8_t SCL_OLED = 18;
|
||||
static const uint8_t SDA_OLED = 17;
|
||||
|
||||
static const uint8_t RST_LoRa = 12;
|
||||
static const uint8_t BUSY_LoRa = 13;
|
||||
static const uint8_t DIO0 = 14;
|
||||
|
||||
#endif /* Pins_Arduino_h */
|
||||
@@ -0,0 +1,208 @@
|
||||
[Heltec_lora32_v4]
|
||||
extends = esp32_base
|
||||
board = heltec_v4
|
||||
build_flags =
|
||||
${esp32_base.build_flags}
|
||||
${sensor_base.build_flags}
|
||||
-I variants/heltec_v4
|
||||
-D HELTEC_LORA_V4
|
||||
-D USE_SX1262
|
||||
-D ESP32_CPU_FREQ=80
|
||||
-D RADIO_CLASS=CustomSX1262
|
||||
-D WRAPPER_CLASS=CustomSX1262Wrapper
|
||||
-D P_LORA_TX_LED=35
|
||||
-D P_LORA_DIO_1=14
|
||||
-D P_LORA_NSS=8
|
||||
-D P_LORA_RESET=12
|
||||
-D P_LORA_BUSY=13
|
||||
-D P_LORA_SCLK=9
|
||||
-D P_LORA_MISO=11
|
||||
-D P_LORA_MOSI=10
|
||||
-D P_LORA_PA_POWER=7 ; VFEM_Ctrl - Power on GC1109
|
||||
-D P_LORA_PA_EN=2 ; PA CSD - Enable GC1109
|
||||
-D P_LORA_PA_TX_EN=46 ; PA CPS - GC1109 TX PA full(High) / bypass(Low)
|
||||
-D PIN_USER_BTN=0
|
||||
-D PIN_VEXT_EN=36
|
||||
-D PIN_VEXT_EN_ACTIVE=HIGH
|
||||
-D LORA_TX_POWER=10 ;If it is configured as 10 here, the final output will be 22 dbm.
|
||||
-D MAX_LORA_TX_POWER=22 ; Max SX1262 output
|
||||
-D SX126X_REGISTER_PATCH=1 ; Patch register 0x8B5 for improved RX
|
||||
-D SX126X_DIO2_AS_RF_SWITCH=true ; GC1109 CTX is controlled by SX1262 DIO2
|
||||
-D SX126X_DIO3_TCXO_VOLTAGE=1.8
|
||||
-D SX126X_CURRENT_LIMIT=140
|
||||
-D SX126X_RX_BOOSTED_GAIN=1 ; In some cases, commenting this out will improve RX
|
||||
-D PIN_GPS_RX=38
|
||||
-D PIN_GPS_TX=39
|
||||
-D PIN_GPS_RESET=42
|
||||
-D PIN_GPS_RESET_ACTIVE=LOW
|
||||
-D PIN_GPS_EN=34
|
||||
-D PIN_GPS_EN_ACTIVE=LOW
|
||||
-D ENV_INCLUDE_GPS=1
|
||||
-D PIN_ADC_CTRL=37
|
||||
-D PIN_VBAT_READ=1
|
||||
build_src_filter = ${esp32_base.build_src_filter}
|
||||
+<../variants/heltec_v4>
|
||||
+<helpers/sensors>
|
||||
lib_deps =
|
||||
${esp32_base.lib_deps}
|
||||
${sensor_base.lib_deps}
|
||||
|
||||
[heltec_v4_oled]
|
||||
extends = Heltec_lora32_v4
|
||||
build_flags =
|
||||
${Heltec_lora32_v4.build_flags}
|
||||
-D HELTEC_LORA_V4_OLED
|
||||
-D PIN_BOARD_SDA=17
|
||||
-D PIN_BOARD_SCL=18
|
||||
-D PIN_OLED_RESET=21
|
||||
build_src_filter= ${Heltec_lora32_v4.build_src_filter}
|
||||
lib_deps = ${Heltec_lora32_v4.lib_deps}
|
||||
|
||||
[heltec_v4_tft]
|
||||
extends = Heltec_lora32_v4
|
||||
build_flags =
|
||||
${Heltec_lora32_v4.build_flags}
|
||||
-D HELTEC_LORA_V4_TFT
|
||||
-D PIN_BOARD_SDA=4
|
||||
-D PIN_BOARD_SCL=3
|
||||
-D DISPLAY_SCALE_X=2.5
|
||||
-D DISPLAY_SCALE_Y=3.75
|
||||
-D PIN_TFT_RST=18
|
||||
-D PIN_TFT_VDD_CTL=-1
|
||||
-D PIN_TFT_LEDA_CTL=21
|
||||
-D PIN_TFT_LEDA_CTL_ACTIVE=HIGH
|
||||
-D PIN_TFT_CS=15
|
||||
-D PIN_TFT_DC=16
|
||||
-D PIN_TFT_SCL=17
|
||||
-D PIN_TFT_SDA=33
|
||||
build_src_filter= ${Heltec_lora32_v4.build_src_filter}
|
||||
lib_deps =
|
||||
${Heltec_lora32_v4.lib_deps}
|
||||
adafruit/Adafruit ST7735 and ST7789 Library @ ^1.11.0
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Heltec V4 WiFi Remote Repeater — WiFi MQTT backhaul, remote management
|
||||
; No SD card — config files stored in SPIFFS.
|
||||
; Upload config: create data/remote/ folder with wifi.cfg and mqtt.cfg,
|
||||
; then run: pio run -e meck_wifi_repeater_heltec_v4 -t uploadfs
|
||||
; OLED display shows status (optional — works headless too)
|
||||
; Flash: pio run -e meck_wifi_repeater_heltec_v4 -t upload
|
||||
; ---------------------------------------------------------------------------
|
||||
[env:meck_wifi_repeater_heltec_v4]
|
||||
extends = heltec_v4_oled
|
||||
upload_port = /dev/cu.usbmodem101
|
||||
build_src_filter = ${heltec_v4_oled.build_src_filter}
|
||||
+<helpers/esp32/*.cpp>
|
||||
-<helpers/esp32/SerialBLEInterface.cpp>
|
||||
+<helpers/ui/SSD1306Display.cpp>
|
||||
+<helpers/ui/MomentaryButton.cpp>
|
||||
+<../examples/simple_repeater/*.cpp>
|
||||
build_flags =
|
||||
${heltec_v4_oled.build_flags}
|
||||
-D FIRMWARE_VERSION='"Meck HV4 WiFi Rptr v0.1"'
|
||||
-D FIRMWARE_BUILD_DATE='"5 Apr 2026"'
|
||||
-D DISPLAY_CLASS=SSD1306Display
|
||||
-D ADVERT_NAME='"Heltec Repeater"'
|
||||
-D ADMIN_PASSWORD='"password"'
|
||||
-D MECK_WIFI_REMOTE
|
||||
-D MECK_REMOTE_REPEATER=1
|
||||
-D DISABLE_WIFI_OTA=1
|
||||
-D MAX_NEIGHBOURS=50
|
||||
-D RADIOLIB_EXCLUDE_CC1101=1
|
||||
-D RADIOLIB_EXCLUDE_NRF24=1
|
||||
-D RADIOLIB_EXCLUDE_RF69=1
|
||||
-D RADIOLIB_EXCLUDE_SX1231=1
|
||||
-D RADIOLIB_EXCLUDE_SX1233=1
|
||||
-D RADIOLIB_EXCLUDE_SI443X=1
|
||||
-D RADIOLIB_EXCLUDE_RFM2X=1
|
||||
-D RADIOLIB_EXCLUDE_SX127X=1
|
||||
-D RADIOLIB_EXCLUDE_SX1272=1
|
||||
-D RADIOLIB_EXCLUDE_SX1278=1
|
||||
-D RADIOLIB_EXCLUDE_STM32WLX=1
|
||||
-D RADIOLIB_EXCLUDE_LR11X0=1
|
||||
-D RADIOLIB_EXCLUDE_LLCC68=1
|
||||
-D RADIOLIB_EXCLUDE_SX128X=1
|
||||
-D RADIOLIB_EXCLUDE_AFSK=1
|
||||
-D RADIOLIB_EXCLUDE_AX25=1
|
||||
-D RADIOLIB_EXCLUDE_HELLSCHREIBER=1
|
||||
-D RADIOLIB_EXCLUDE_MORSE=1
|
||||
-D RADIOLIB_EXCLUDE_RTTY=1
|
||||
-D RADIOLIB_EXCLUDE_SSTV=1
|
||||
-D RADIOLIB_EXCLUDE_APRS=1
|
||||
-D RADIOLIB_EXCLUDE_LORAWAN=1
|
||||
-D RADIOLIB_EXCLUDE_PAGER=1
|
||||
-D RADIOLIB_EXCLUDE_FSK4=1
|
||||
-D RADIOLIB_EXCLUDE_BELL=1
|
||||
lib_deps =
|
||||
${heltec_v4_oled.lib_deps}
|
||||
knolleary/PubSubClient@^2.8
|
||||
lib_ignore =
|
||||
ESP32 BLE Arduino
|
||||
AsyncTCP
|
||||
RPAsyncTCP
|
||||
ESPAsyncWebServer
|
||||
AsyncElegantOTA
|
||||
ESP32-audioI2S
|
||||
esp32_codec2_arduino
|
||||
board_build.partitions = default_16MB.csv
|
||||
board_build.filesystem = spiffs
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Heltec V4 WiFi Remote Repeater — HEADLESS (no display)
|
||||
; ---------------------------------------------------------------------------
|
||||
[env:meck_wifi_repeater_heltec_v4_headless]
|
||||
extends = Heltec_lora32_v4
|
||||
upload_port = /dev/cu.usbmodem101
|
||||
build_src_filter = ${Heltec_lora32_v4.build_src_filter}
|
||||
+<helpers/esp32/*.cpp>
|
||||
-<helpers/esp32/SerialBLEInterface.cpp>
|
||||
+<../examples/simple_repeater/*.cpp>
|
||||
build_flags =
|
||||
${Heltec_lora32_v4.build_flags}
|
||||
-D ESP32_CPU_FREQ=240
|
||||
-D FIRMWARE_VERSION='"Meck HV4 WiFi Rptr v0.1"'
|
||||
-D FIRMWARE_BUILD_DATE='"5 Apr 2026"'
|
||||
-D ADVERT_NAME='"Heltec Repeater"'
|
||||
-D ADMIN_PASSWORD='"password"'
|
||||
-D MECK_WIFI_REMOTE
|
||||
-D MECK_REMOTE_REPEATER=1
|
||||
-D DISABLE_WIFI_OTA=1
|
||||
-D MAX_NEIGHBOURS=50
|
||||
-D RADIOLIB_EXCLUDE_CC1101=1
|
||||
-D RADIOLIB_EXCLUDE_NRF24=1
|
||||
-D RADIOLIB_EXCLUDE_RF69=1
|
||||
-D RADIOLIB_EXCLUDE_SX1231=1
|
||||
-D RADIOLIB_EXCLUDE_SX1233=1
|
||||
-D RADIOLIB_EXCLUDE_SI443X=1
|
||||
-D RADIOLIB_EXCLUDE_RFM2X=1
|
||||
-D RADIOLIB_EXCLUDE_SX127X=1
|
||||
-D RADIOLIB_EXCLUDE_SX1272=1
|
||||
-D RADIOLIB_EXCLUDE_SX1278=1
|
||||
-D RADIOLIB_EXCLUDE_STM32WLX=1
|
||||
-D RADIOLIB_EXCLUDE_LR11X0=1
|
||||
-D RADIOLIB_EXCLUDE_LLCC68=1
|
||||
-D RADIOLIB_EXCLUDE_SX128X=1
|
||||
-D RADIOLIB_EXCLUDE_AFSK=1
|
||||
-D RADIOLIB_EXCLUDE_AX25=1
|
||||
-D RADIOLIB_EXCLUDE_HELLSCHREIBER=1
|
||||
-D RADIOLIB_EXCLUDE_MORSE=1
|
||||
-D RADIOLIB_EXCLUDE_RTTY=1
|
||||
-D RADIOLIB_EXCLUDE_SSTV=1
|
||||
-D RADIOLIB_EXCLUDE_APRS=1
|
||||
-D RADIOLIB_EXCLUDE_LORAWAN=1
|
||||
-D RADIOLIB_EXCLUDE_PAGER=1
|
||||
-D RADIOLIB_EXCLUDE_FSK4=1
|
||||
-D RADIOLIB_EXCLUDE_BELL=1
|
||||
lib_deps =
|
||||
${Heltec_lora32_v4.lib_deps}
|
||||
knolleary/PubSubClient@^2.8
|
||||
lib_ignore =
|
||||
ESP32 BLE Arduino
|
||||
AsyncTCP
|
||||
RPAsyncTCP
|
||||
ESPAsyncWebServer
|
||||
AsyncElegantOTA
|
||||
ESP32-audioI2S
|
||||
esp32_codec2_arduino
|
||||
board_build.partitions = default_16MB.csv
|
||||
board_build.filesystem = spiffs
|
||||
@@ -0,0 +1,61 @@
|
||||
#include <Arduino.h>
|
||||
#include "target.h"
|
||||
|
||||
HeltecV4Board board;
|
||||
|
||||
#if defined(P_LORA_SCLK)
|
||||
static SPIClass spi;
|
||||
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi);
|
||||
#else
|
||||
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY);
|
||||
#endif
|
||||
|
||||
WRAPPER_CLASS radio_driver(radio, board);
|
||||
|
||||
ESP32RTCClock fallback_clock;
|
||||
AutoDiscoverRTCClock rtc_clock(fallback_clock);
|
||||
|
||||
#if ENV_INCLUDE_GPS
|
||||
#include <helpers/sensors/MicroNMEALocationProvider.h>
|
||||
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
|
||||
EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
|
||||
#else
|
||||
EnvironmentSensorManager sensors;
|
||||
#endif
|
||||
|
||||
#ifdef DISPLAY_CLASS
|
||||
DISPLAY_CLASS display(NULL);
|
||||
MomentaryButton user_btn(PIN_USER_BTN, 1000, true);
|
||||
#endif
|
||||
|
||||
bool radio_init() {
|
||||
fallback_clock.begin();
|
||||
rtc_clock.begin(Wire);
|
||||
|
||||
#if defined(P_LORA_SCLK)
|
||||
return radio.std_init(&spi);
|
||||
#else
|
||||
return radio.std_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t radio_get_rng_seed() {
|
||||
return radio.random(0x7FFFFFFF);
|
||||
}
|
||||
|
||||
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
|
||||
radio.setFrequency(freq);
|
||||
radio.setSpreadingFactor(sf);
|
||||
radio.setBandwidth(bw);
|
||||
radio.setCodingRate(cr);
|
||||
}
|
||||
|
||||
void radio_set_tx_power(int8_t dbm) {
|
||||
radio.setOutputPower(dbm);
|
||||
}
|
||||
|
||||
mesh::LocalIdentity radio_new_identity() {
|
||||
RadioNoiseListener rng(radio);
|
||||
return mesh::LocalIdentity(&rng); // create new random identity
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#define RADIOLIB_STATIC_ONLY 1
|
||||
#include <RadioLib.h>
|
||||
#include <helpers/radiolib/RadioLibWrappers.h>
|
||||
#include <HeltecV4Board.h>
|
||||
#include <helpers/radiolib/CustomSX1262Wrapper.h>
|
||||
#include <helpers/AutoDiscoverRTCClock.h>
|
||||
#include <helpers/SensorManager.h>
|
||||
#include <helpers/sensors/EnvironmentSensorManager.h>
|
||||
#ifdef DISPLAY_CLASS
|
||||
#ifdef HELTEC_LORA_V4_OLED
|
||||
#include <helpers/ui/SSD1306Display.h>
|
||||
#elif defined(HELTEC_LORA_V4_TFT)
|
||||
#include <helpers/ui/ST7789LCDDisplay.h>
|
||||
#endif
|
||||
#include <helpers/ui/MomentaryButton.h>
|
||||
#endif
|
||||
|
||||
extern HeltecV4Board board;
|
||||
extern WRAPPER_CLASS radio_driver;
|
||||
extern AutoDiscoverRTCClock rtc_clock;
|
||||
extern EnvironmentSensorManager sensors;
|
||||
|
||||
#ifdef DISPLAY_CLASS
|
||||
extern DISPLAY_CLASS display;
|
||||
extern MomentaryButton user_btn;
|
||||
#endif
|
||||
|
||||
bool radio_init();
|
||||
uint32_t radio_get_rng_seed();
|
||||
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr);
|
||||
void radio_set_tx_power(int8_t dbm);
|
||||
mesh::LocalIdentity radio_new_identity();
|
||||
|
||||
@@ -8,9 +8,10 @@
|
||||
// 240 MHz ~70-80 mA
|
||||
// 160 MHz ~50-60 mA
|
||||
// 80 MHz ~30-40 mA
|
||||
// 40 MHz ~15-20 mA (low-power / lock screen mode)
|
||||
//
|
||||
// SPI peripherals and UART use their own clock dividers from the APB clock,
|
||||
// so LoRa, e-ink, and GPS serial all work fine at 80MHz.
|
||||
// so LoRa, e-ink, and GPS serial all work fine at 80MHz and 40MHz.
|
||||
|
||||
#ifdef ESP32
|
||||
|
||||
@@ -22,23 +23,36 @@
|
||||
#define CPU_FREQ_BOOST 240 // MHz — heavy processing
|
||||
#endif
|
||||
|
||||
#ifndef CPU_FREQ_LOW_POWER
|
||||
#define CPU_FREQ_LOW_POWER 80 // MHz — lock screen / idle standby (40 MHz breaks I2C)
|
||||
#endif
|
||||
|
||||
#ifndef CPU_BOOST_TIMEOUT_MS
|
||||
#define CPU_BOOST_TIMEOUT_MS 10000 // 10 seconds
|
||||
#endif
|
||||
|
||||
class CPUPowerManager {
|
||||
public:
|
||||
CPUPowerManager() : _boosted(false), _boost_started(0) {}
|
||||
CPUPowerManager() : _boosted(false), _lowPower(false), _boost_started(0) {}
|
||||
|
||||
void begin() {
|
||||
setCpuFrequencyMhz(CPU_FREQ_IDLE);
|
||||
_boosted = false;
|
||||
_lowPower = false;
|
||||
MESH_DEBUG_PRINTLN("CPU power: idle at %d MHz", CPU_FREQ_IDLE);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (_boosted && (millis() - _boost_started >= CPU_BOOST_TIMEOUT_MS)) {
|
||||
setIdle();
|
||||
// Return to low-power if locked, otherwise normal idle
|
||||
if (_lowPower) {
|
||||
setCpuFrequencyMhz(CPU_FREQ_LOW_POWER);
|
||||
MESH_DEBUG_PRINTLN("CPU power: boost expired, returning to low-power %d MHz", CPU_FREQ_LOW_POWER);
|
||||
} else {
|
||||
setCpuFrequencyMhz(CPU_FREQ_IDLE);
|
||||
MESH_DEBUG_PRINTLN("CPU power: idle at %d MHz", CPU_FREQ_IDLE);
|
||||
}
|
||||
_boosted = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,13 +71,42 @@ public:
|
||||
_boosted = false;
|
||||
MESH_DEBUG_PRINTLN("CPU power: idle at %d MHz", CPU_FREQ_IDLE);
|
||||
}
|
||||
if (_lowPower) {
|
||||
_lowPower = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Low-power mode — drops CPU to 40 MHz for lock screen standby.
|
||||
// If currently boosted, the boost timeout will return to 40 MHz
|
||||
// instead of 80 MHz.
|
||||
void setLowPower() {
|
||||
_lowPower = true;
|
||||
if (!_boosted) {
|
||||
setCpuFrequencyMhz(CPU_FREQ_LOW_POWER);
|
||||
MESH_DEBUG_PRINTLN("CPU power: low-power at %d MHz", CPU_FREQ_LOW_POWER);
|
||||
}
|
||||
// If boosted, the loop() timeout will drop to low-power instead of idle
|
||||
}
|
||||
|
||||
// Exit low-power mode — returns to normal idle (80 MHz).
|
||||
// If currently boosted, the boost timeout will return to idle
|
||||
// instead of low-power.
|
||||
void clearLowPower() {
|
||||
_lowPower = false;
|
||||
if (!_boosted) {
|
||||
setCpuFrequencyMhz(CPU_FREQ_IDLE);
|
||||
MESH_DEBUG_PRINTLN("CPU power: idle at %d MHz (low-power cleared)", CPU_FREQ_IDLE);
|
||||
}
|
||||
// If boosted, the loop() timeout will drop to idle as normal
|
||||
}
|
||||
|
||||
bool isBoosted() const { return _boosted; }
|
||||
bool isLowPower() const { return _lowPower; }
|
||||
uint32_t getFrequencyMHz() const { return getCpuFrequencyMhz(); }
|
||||
|
||||
private:
|
||||
bool _boosted;
|
||||
bool _lowPower;
|
||||
unsigned long _boost_started;
|
||||
};
|
||||
|
||||
|
||||
@@ -188,9 +188,15 @@ int16_t T5S3Board::getBattTemperature() {
|
||||
}
|
||||
|
||||
// ---- BQ27220 Design Capacity configuration ----
|
||||
// Identical procedure to TDeckBoard — sets 1500 mAh for T5S3's larger cell.
|
||||
// The BQ27220 ships with 3000 mAh default. This writes once on first boot
|
||||
// and persists in battery-backed RAM.
|
||||
// The BQ27220 ships with a 3000 mAh default. T5S3 uses a 1500 mAh cell.
|
||||
// This function checks on boot and writes the correct value via the
|
||||
// MAC Data Memory interface if needed. The value persists in battery-backed
|
||||
// RAM, so this typically only writes once (or after a full battery disconnect).
|
||||
//
|
||||
// When DC and DE are already correct but FCC is stuck (common after initial
|
||||
// flash), the root cause is Qmax Cell 0 (0x9106) and stored FCC (0x929D)
|
||||
// retaining factory 3000 mAh defaults. This function detects and fixes all
|
||||
// three layers: DC/DE, Qmax, and stored FCC.
|
||||
|
||||
bool T5S3Board::configureFuelGauge(uint16_t designCapacity_mAh) {
|
||||
#if HAS_BQ27220
|
||||
@@ -198,23 +204,169 @@ bool T5S3Board::configureFuelGauge(uint16_t designCapacity_mAh) {
|
||||
Serial.printf("BQ27220: Design Capacity = %d mAh (target %d)\n", currentDC, designCapacity_mAh);
|
||||
|
||||
if (currentDC == designCapacity_mAh) {
|
||||
// Design Capacity correct, but check if Full Charge Capacity is sane.
|
||||
uint16_t fcc = bq27220_read16(BQ27220_REG_FULL_CAP);
|
||||
Serial.printf("BQ27220: Design Capacity correct, FCC=%d mAh\n", fcc);
|
||||
if (fcc < designCapacity_mAh * 3 / 2) {
|
||||
return true; // FCC is sane, nothing to do
|
||||
Serial.printf("BQ27220: Design Capacity already correct, FCC=%d mAh\n", fcc);
|
||||
if (fcc >= designCapacity_mAh * 3 / 2) {
|
||||
// FCC is >=150% of design — stale from factory defaults (typically 3000 mAh).
|
||||
uint16_t designEnergy = (uint16_t)((uint32_t)designCapacity_mAh * 37 / 10);
|
||||
Serial.printf("BQ27220: FCC %d >> DC %d, checking Design Energy (target %d mWh)\n",
|
||||
fcc, designCapacity_mAh, designEnergy);
|
||||
|
||||
// Unseal to read data memory and issue RESET
|
||||
bq27220_writeControl(0x0414); delay(2);
|
||||
bq27220_writeControl(0x3672); delay(2);
|
||||
// Full Access
|
||||
bq27220_writeControl(0xFFFF); delay(2);
|
||||
bq27220_writeControl(0xFFFF); delay(2);
|
||||
|
||||
// Enter CFG_UPDATE to access data memory
|
||||
bq27220_writeControl(0x0090);
|
||||
bool ready = false;
|
||||
for (int i = 0; i < 50; i++) {
|
||||
delay(20);
|
||||
uint16_t opSt = bq27220_read16(BQ27220_REG_OP_STATUS);
|
||||
if (opSt & 0x0400) { ready = true; break; }
|
||||
}
|
||||
if (ready) {
|
||||
// Read Design Energy at data memory address 0x92A1
|
||||
Wire.beginTransmission(BQ27220_I2C_ADDR);
|
||||
Wire.write(0x3E); Wire.write(0xA1); Wire.write(0x92);
|
||||
Wire.endTransmission();
|
||||
delay(10);
|
||||
uint8_t oldMSB = bq27220_read8(0x40);
|
||||
uint8_t oldLSB = bq27220_read8(0x41);
|
||||
uint16_t currentDE = (oldMSB << 8) | oldLSB;
|
||||
|
||||
if (currentDE != designEnergy) {
|
||||
// Design Energy actually needs updating — write it
|
||||
uint8_t oldChk = bq27220_read8(0x60);
|
||||
uint8_t dLen = bq27220_read8(0x61);
|
||||
uint8_t newMSB = (designEnergy >> 8) & 0xFF;
|
||||
uint8_t newLSB = designEnergy & 0xFF;
|
||||
uint8_t temp = (255 - oldChk - oldMSB - oldLSB);
|
||||
uint8_t newChk = 255 - ((temp + newMSB + newLSB) & 0xFF);
|
||||
|
||||
Serial.printf("BQ27220: DE old=%d new=%d mWh, writing\n", currentDE, designEnergy);
|
||||
|
||||
Wire.beginTransmission(BQ27220_I2C_ADDR);
|
||||
Wire.write(0x3E); Wire.write(0xA1); Wire.write(0x92);
|
||||
Wire.write(newMSB); Wire.write(newLSB);
|
||||
Wire.endTransmission();
|
||||
delay(5);
|
||||
Wire.beginTransmission(BQ27220_I2C_ADDR);
|
||||
Wire.write(0x60); Wire.write(newChk); Wire.write(dLen);
|
||||
Wire.endTransmission();
|
||||
delay(10);
|
||||
|
||||
// Exit with reinit since we actually changed data
|
||||
bq27220_writeControl(0x0091); // EXIT_CFG_UPDATE_REINIT
|
||||
delay(200);
|
||||
Serial.println("BQ27220: Design Energy written, exited CFG_UPDATE");
|
||||
} else {
|
||||
// DC and DE are both correct, but FCC is stuck.
|
||||
// Root cause: Qmax Cell 0 (0x9106) and stored FCC (0x929D) retain
|
||||
// factory 3000 mAh defaults. Overwrite both with designCapacity_mAh.
|
||||
Serial.printf("BQ27220: DE correct (%d mWh) — fixing Qmax + stored FCC\n", currentDE);
|
||||
|
||||
// --- Helper lambda for MAC data memory 2-byte write ---
|
||||
// Reads old value + checksum, computes differential checksum, writes new value.
|
||||
auto writeDM16 = [](uint16_t addr, uint16_t newVal) -> bool {
|
||||
// Select address
|
||||
Wire.beginTransmission(BQ27220_I2C_ADDR);
|
||||
Wire.write(0x3E);
|
||||
Wire.write(addr & 0xFF);
|
||||
Wire.write((addr >> 8) & 0xFF);
|
||||
Wire.endTransmission();
|
||||
delay(10);
|
||||
|
||||
uint8_t oldMSB = bq27220_read8(0x40);
|
||||
uint8_t oldLSB = bq27220_read8(0x41);
|
||||
uint8_t oldChk = bq27220_read8(0x60);
|
||||
uint8_t dLen = bq27220_read8(0x61);
|
||||
uint16_t oldVal = (oldMSB << 8) | oldLSB;
|
||||
|
||||
if (oldVal == newVal) {
|
||||
Serial.printf("BQ27220: [0x%04X] already %d, skip\n", addr, newVal);
|
||||
return true; // already correct
|
||||
}
|
||||
|
||||
uint8_t newMSB = (newVal >> 8) & 0xFF;
|
||||
uint8_t newLSB = newVal & 0xFF;
|
||||
uint8_t temp = (255 - oldChk - oldMSB - oldLSB);
|
||||
uint8_t newChk = 255 - ((temp + newMSB + newLSB) & 0xFF);
|
||||
|
||||
Serial.printf("BQ27220: [0x%04X] %d -> %d\n", addr, oldVal, newVal);
|
||||
|
||||
// Write new value
|
||||
Wire.beginTransmission(BQ27220_I2C_ADDR);
|
||||
Wire.write(0x3E);
|
||||
Wire.write(addr & 0xFF);
|
||||
Wire.write((addr >> 8) & 0xFF);
|
||||
Wire.write(newMSB);
|
||||
Wire.write(newLSB);
|
||||
Wire.endTransmission();
|
||||
delay(5);
|
||||
|
||||
// Write checksum
|
||||
Wire.beginTransmission(BQ27220_I2C_ADDR);
|
||||
Wire.write(0x60);
|
||||
Wire.write(newChk);
|
||||
Wire.write(dLen);
|
||||
Wire.endTransmission();
|
||||
delay(10);
|
||||
return true;
|
||||
};
|
||||
|
||||
// Overwrite Qmax Cell 0 (IT Cfg) — this is what FCC is derived from
|
||||
writeDM16(0x9106, designCapacity_mAh);
|
||||
|
||||
// Overwrite stored FCC reference (Gas Gauging, 2 bytes before DC)
|
||||
writeDM16(0x929D, designCapacity_mAh);
|
||||
|
||||
// Exit with reinit to apply the new values
|
||||
bq27220_writeControl(0x0091); // EXIT_CFG_UPDATE_REINIT
|
||||
delay(200);
|
||||
Serial.println("BQ27220: Qmax + stored FCC updated, exited CFG_UPDATE");
|
||||
}
|
||||
} else {
|
||||
Serial.println("BQ27220: Failed to enter CFG_UPDATE for DE check");
|
||||
}
|
||||
|
||||
// Seal first, then issue RESET.
|
||||
// RESET forces the gauge to fully reinitialize its Impedance Track
|
||||
// algorithm and recalculate FCC from the current DC/DE values.
|
||||
bq27220_writeControl(0x0030); // SEAL
|
||||
delay(5);
|
||||
Serial.println("BQ27220: Issuing RESET to force FCC recalculation...");
|
||||
bq27220_writeControl(0x0041); // RESET
|
||||
delay(2000); // Full reset needs generous settle time
|
||||
|
||||
fcc = bq27220_read16(BQ27220_REG_FULL_CAP);
|
||||
Serial.printf("BQ27220: FCC after RESET: %d mAh (target <= %d)\n", fcc, designCapacity_mAh);
|
||||
|
||||
if (fcc > designCapacity_mAh * 3 / 2) {
|
||||
// RESET didn't fix FCC — the gauge IT algorithm is stubbornly
|
||||
// retaining its learned value. This typically resolves after one
|
||||
// full charge/discharge cycle. Software clamp in
|
||||
// getFullChargeCapacity() ensures correct display regardless.
|
||||
Serial.printf("BQ27220: FCC still stale at %d — software clamp active\n", fcc);
|
||||
}
|
||||
}
|
||||
// FCC is stale from factory — fall through to reconfigure
|
||||
Serial.printf("BQ27220: FCC %d >> DC %d, reconfiguring\n", fcc, designCapacity_mAh);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Unseal
|
||||
Serial.printf("BQ27220: Updating Design Capacity from %d to %d mAh\n", currentDC, designCapacity_mAh);
|
||||
|
||||
// Step 1: Unseal (default unseal keys)
|
||||
bq27220_writeControl(0x0414); delay(2);
|
||||
bq27220_writeControl(0x3672); delay(2);
|
||||
// Full Access
|
||||
|
||||
// Step 2: Full Access
|
||||
bq27220_writeControl(0xFFFF); delay(2);
|
||||
bq27220_writeControl(0xFFFF); delay(2);
|
||||
|
||||
// Enter CFG_UPDATE
|
||||
// Step 3: Enter CFG_UPDATE
|
||||
bq27220_writeControl(0x0090);
|
||||
bool cfgReady = false;
|
||||
for (int i = 0; i < 50; i++) {
|
||||
@@ -229,7 +381,7 @@ bool T5S3Board::configureFuelGauge(uint16_t designCapacity_mAh) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Write Design Capacity at 0x929F
|
||||
// Step 4: Write Design Capacity at 0x929F
|
||||
Wire.beginTransmission(BQ27220_I2C_ADDR);
|
||||
Wire.write(0x3E); Wire.write(0x9F); Wire.write(0x92);
|
||||
Wire.endTransmission();
|
||||
@@ -255,7 +407,7 @@ bool T5S3Board::configureFuelGauge(uint16_t designCapacity_mAh) {
|
||||
Wire.endTransmission();
|
||||
delay(10);
|
||||
|
||||
// Write Design Energy at 0x92A1
|
||||
// Step 4a: Write Design Energy at 0x92A1
|
||||
{
|
||||
uint16_t designEnergy = (uint16_t)((uint32_t)designCapacity_mAh * 37 / 10);
|
||||
Wire.beginTransmission(BQ27220_I2C_ADDR);
|
||||
@@ -271,6 +423,9 @@ bool T5S3Board::configureFuelGauge(uint16_t designCapacity_mAh) {
|
||||
uint8_t deTemp = (255 - deOldChk - deOldMSB - deOldLSB);
|
||||
uint8_t deNewChk = 255 - ((deTemp + deNewMSB + deNewLSB) & 0xFF);
|
||||
|
||||
Serial.printf("BQ27220: Design Energy: old=%d new=%d mWh\n",
|
||||
(deOldMSB << 8) | deOldLSB, designEnergy);
|
||||
|
||||
Wire.beginTransmission(BQ27220_I2C_ADDR);
|
||||
Wire.write(0x3E); Wire.write(0xA1); Wire.write(0x92);
|
||||
Wire.write(deNewMSB); Wire.write(deNewLSB);
|
||||
@@ -282,16 +437,17 @@ bool T5S3Board::configureFuelGauge(uint16_t designCapacity_mAh) {
|
||||
delay(10);
|
||||
}
|
||||
|
||||
// Exit CFG_UPDATE with reinit
|
||||
// Step 5: Exit CFG_UPDATE with reinit
|
||||
bq27220_writeControl(0x0091);
|
||||
Serial.println("BQ27220: Sent EXIT_CFG_UPDATE_REINIT, waiting...");
|
||||
delay(200);
|
||||
|
||||
// Seal
|
||||
// Step 6: Seal
|
||||
bq27220_writeControl(0x0030);
|
||||
delay(5);
|
||||
|
||||
// Force RESET to reinitialize FCC
|
||||
bq27220_writeControl(0x0041);
|
||||
// Step 7: Force RESET to reinitialize FCC from new DC/DE
|
||||
bq27220_writeControl(0x0041); // RESET
|
||||
delay(1000);
|
||||
|
||||
uint16_t verifyDC = bq27220_read16(BQ27220_REG_DESIGN_CAP);
|
||||
@@ -302,4 +458,4 @@ bool T5S3Board::configureFuelGauge(uint16_t designCapacity_mAh) {
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -63,23 +63,28 @@ build_src_filter = ${esp32_base.build_src_filter}
|
||||
+<../variants/LilyGo_T5S3_EPaper_Pro>
|
||||
lib_deps =
|
||||
${esp32_base.lib_deps}
|
||||
WebServer
|
||||
DNSServer
|
||||
Update
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; T5S3 standalone — touch UI (stub), verify display rendering
|
||||
; Uses FastEPD for parallel e-ink, Adafruit GFX for drawing
|
||||
; OTA enabled: WiFi AP activates only during user-initiated firmware updates.
|
||||
; ---------------------------------------------------------------------------
|
||||
[env:meck_t5s3_standalone]
|
||||
extends = LilyGo_T5S3_EPaper_Pro
|
||||
build_flags =
|
||||
${LilyGo_T5S3_EPaper_Pro.build_flags}
|
||||
-I examples/companion_radio/ui-new
|
||||
-D MAX_CONTACTS=1500
|
||||
-D MAX_CONTACTS=2000
|
||||
-D MAX_GROUP_CHANNELS=20
|
||||
-D OFFLINE_QUEUE_SIZE=1
|
||||
-D CHANNEL_MSG_HISTORY_SIZE=800
|
||||
-D DISPLAY_CLASS=FastEPDDisplay
|
||||
-D USE_EINK
|
||||
; Font family: comment/uncomment to toggle (delete .indexes on SD after switching)
|
||||
-D MECK_CARDKB
|
||||
-D MECK_OTA_UPDATE=1
|
||||
; -D MECK_SERIF_FONT ; FreeSerif (Times New Roman-like)
|
||||
; ; Default (no flag): FreeSans (Arial-like)
|
||||
build_src_filter = ${LilyGo_T5S3_EPaper_Pro.build_src_filter}
|
||||
@@ -98,6 +103,7 @@ lib_deps =
|
||||
; ---------------------------------------------------------------------------
|
||||
; T5S3 BLE companion — touch UI, BLE phone bridging
|
||||
; Connect via MeshCore iOS/Android app over Bluetooth
|
||||
; OTA enabled: WiFi AP activates only during user-initiated firmware updates.
|
||||
; Flash: pio run -e meck_t5s3_ble -t upload
|
||||
; ---------------------------------------------------------------------------
|
||||
[env:meck_t5s3_ble]
|
||||
@@ -105,12 +111,14 @@ extends = LilyGo_T5S3_EPaper_Pro
|
||||
build_flags =
|
||||
${LilyGo_T5S3_EPaper_Pro.build_flags}
|
||||
-I examples/companion_radio/ui-new
|
||||
-D MAX_CONTACTS=500
|
||||
-D MAX_CONTACTS=2000
|
||||
-D MAX_GROUP_CHANNELS=20
|
||||
-D BLE_PIN_CODE=123456
|
||||
-D OFFLINE_QUEUE_SIZE=256
|
||||
-D DISPLAY_CLASS=FastEPDDisplay
|
||||
-D USE_EINK
|
||||
-D MECK_CARDKB
|
||||
-D MECK_OTA_UPDATE=1
|
||||
; -D MECK_SERIF_FONT
|
||||
build_src_filter = ${LilyGo_T5S3_EPaper_Pro.build_src_filter}
|
||||
+<helpers/esp32/*.cpp>
|
||||
@@ -136,14 +144,16 @@ extends = LilyGo_T5S3_EPaper_Pro
|
||||
build_flags =
|
||||
${LilyGo_T5S3_EPaper_Pro.build_flags}
|
||||
-I examples/companion_radio/ui-new
|
||||
-D MAX_CONTACTS=1500
|
||||
-D MAX_CONTACTS=2000
|
||||
-D MAX_GROUP_CHANNELS=20
|
||||
-D MECK_WIFI_COMPANION=1
|
||||
-D MECK_WEB_READER=1
|
||||
-D MECK_OTA_UPDATE=1
|
||||
-D TCP_PORT=5000
|
||||
-D OFFLINE_QUEUE_SIZE=256
|
||||
-D DISPLAY_CLASS=FastEPDDisplay
|
||||
-D USE_EINK
|
||||
-D MECK_CARDKB
|
||||
; -D MECK_SERIF_FONT
|
||||
build_src_filter = ${LilyGo_T5S3_EPaper_Pro.build_src_filter}
|
||||
+<helpers/esp32/*.cpp>
|
||||
@@ -158,3 +168,67 @@ lib_deps =
|
||||
https://github.com/mverch67/FastEPD/archive/0df1bff329b6fc782e062f611758880762340647.zip
|
||||
https://github.com/lewisxhe/SensorLib/archive/refs/tags/v0.3.4.zip
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; T5S3 WiFi Remote Repeater — WiFi MQTT backhaul, remote management
|
||||
; Same MQTT protocol as T-Deck Pro remote repeater builds.
|
||||
; Uses FastEPD for parallel e-ink display.
|
||||
; Flash: pio run -e meck_wifi_repeater_t5s3 -t upload
|
||||
; ---------------------------------------------------------------------------
|
||||
[env:meck_wifi_repeater_t5s3]
|
||||
extends = LilyGo_T5S3_EPaper_Pro
|
||||
build_src_filter = ${LilyGo_T5S3_EPaper_Pro.build_src_filter}
|
||||
+<helpers/esp32/*.cpp>
|
||||
-<helpers/esp32/SerialBLEInterface.cpp>
|
||||
+<helpers/ui/MomentaryButton.cpp>
|
||||
+<helpers/ui/FastEPDDisplay.cpp>
|
||||
+<../examples/simple_repeater/*.cpp>
|
||||
build_flags =
|
||||
${LilyGo_T5S3_EPaper_Pro.build_flags}
|
||||
-D FIRMWARE_VERSION='"Meck T5S3 WiFi Rptr v0.1"'
|
||||
-D FIRMWARE_BUILD_DATE='"5 Apr 2026"'
|
||||
-D DISPLAY_CLASS=FastEPDDisplay
|
||||
-D USE_EINK
|
||||
-D MECK_WIFI_REMOTE
|
||||
-D MECK_REMOTE_REPEATER=1
|
||||
-D DISABLE_WIFI_OTA=1
|
||||
-D MAX_NEIGHBOURS=50
|
||||
-D HAS_SDCARD=1
|
||||
-D RADIOLIB_EXCLUDE_CC1101=1
|
||||
-D RADIOLIB_EXCLUDE_NRF24=1
|
||||
-D RADIOLIB_EXCLUDE_RF69=1
|
||||
-D RADIOLIB_EXCLUDE_SX1231=1
|
||||
-D RADIOLIB_EXCLUDE_SX1233=1
|
||||
-D RADIOLIB_EXCLUDE_SI443X=1
|
||||
-D RADIOLIB_EXCLUDE_RFM2X=1
|
||||
-D RADIOLIB_EXCLUDE_SX127X=1
|
||||
-D RADIOLIB_EXCLUDE_SX1272=1
|
||||
-D RADIOLIB_EXCLUDE_SX1278=1
|
||||
-D RADIOLIB_EXCLUDE_STM32WLX=1
|
||||
-D RADIOLIB_EXCLUDE_LR11X0=1
|
||||
-D RADIOLIB_EXCLUDE_LLCC68=1
|
||||
-D RADIOLIB_EXCLUDE_SX128X=1
|
||||
-D RADIOLIB_EXCLUDE_AFSK=1
|
||||
-D RADIOLIB_EXCLUDE_AX25=1
|
||||
-D RADIOLIB_EXCLUDE_HELLSCHREIBER=1
|
||||
-D RADIOLIB_EXCLUDE_MORSE=1
|
||||
-D RADIOLIB_EXCLUDE_RTTY=1
|
||||
-D RADIOLIB_EXCLUDE_SSTV=1
|
||||
-D RADIOLIB_EXCLUDE_APRS=1
|
||||
-D RADIOLIB_EXCLUDE_LORAWAN=1
|
||||
-D RADIOLIB_EXCLUDE_PAGER=1
|
||||
-D RADIOLIB_EXCLUDE_FSK4=1
|
||||
-D RADIOLIB_EXCLUDE_BELL=1
|
||||
lib_deps =
|
||||
${LilyGo_T5S3_EPaper_Pro.lib_deps}
|
||||
knolleary/PubSubClient@^2.8
|
||||
adafruit/Adafruit GFX Library@^1.11.0
|
||||
https://github.com/mverch67/FastEPD/archive/0df1bff329b6fc782e062f611758880762340647.zip
|
||||
https://github.com/lewisxhe/SensorLib/archive/refs/tags/v0.3.4.zip
|
||||
lib_ignore =
|
||||
ESP32 BLE Arduino
|
||||
AsyncTCP
|
||||
RPAsyncTCP
|
||||
ESPAsyncWebServer
|
||||
AsyncElegantOTA
|
||||
ESP32-audioI2S
|
||||
esp32_codec2_arduino
|
||||
@@ -29,6 +29,7 @@
|
||||
#define I2C_ADDR_BQ27220 0x55 // Fuel gauge
|
||||
#define I2C_ADDR_BQ25896 0x6B // Battery charger
|
||||
#define I2C_ADDR_TPS65185 0x68 // E-ink power driver
|
||||
#define CARDKB_I2C_ADDR 0x5F // M5Stack CardKB (external, via QWIIC)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// SPI Bus — shared by LoRa and SD card
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
#include <Arduino.h>
|
||||
#include "TDeckBoard.h"
|
||||
|
||||
uint32_t deviceOnline = 0x00;
|
||||
|
||||
void TDeckBoard::begin() {
|
||||
|
||||
ESP32Board::begin();
|
||||
|
||||
// Enable peripheral power
|
||||
pinMode(PIN_PERF_POWERON, OUTPUT);
|
||||
digitalWrite(PIN_PERF_POWERON, HIGH);
|
||||
|
||||
// Configure user button
|
||||
pinMode(PIN_USER_BTN, INPUT);
|
||||
|
||||
// Configure LoRa Pins
|
||||
pinMode(P_LORA_MISO, INPUT_PULLUP);
|
||||
// pinMode(P_LORA_DIO_1, INPUT_PULLUP);
|
||||
|
||||
#ifdef P_LORA_TX_LED
|
||||
digitalWrite(P_LORA_TX_LED, HIGH); // inverted pin for SX1276 - HIGH for off
|
||||
#endif
|
||||
|
||||
esp_reset_reason_t reason = esp_reset_reason();
|
||||
if (reason == ESP_RST_DEEPSLEEP) {
|
||||
long wakeup_source = esp_sleep_get_ext1_wakeup_status();
|
||||
if (wakeup_source & (1 << P_LORA_DIO_1)) {
|
||||
startup_reason = BD_STARTUP_RX_PACKET; // received a LoRa packet (while in deep sleep)
|
||||
}
|
||||
|
||||
rtc_gpio_hold_dis((gpio_num_t)P_LORA_NSS);
|
||||
rtc_gpio_deinit((gpio_num_t)P_LORA_DIO_1);
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Wire.h>
|
||||
#include <Arduino.h>
|
||||
#include "helpers/ESP32Board.h"
|
||||
#include <driver/rtc_io.h>
|
||||
|
||||
#define PIN_VBAT_READ 4
|
||||
#define BATTERY_SAMPLES 8
|
||||
#define ADC_MULTIPLIER (2.0f * 3.3f * 1000)
|
||||
|
||||
class TDeckBoard : public ESP32Board {
|
||||
public:
|
||||
void begin();
|
||||
|
||||
#ifdef P_LORA_TX_LED
|
||||
void onBeforeTransmit() override{
|
||||
digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED on - invert pin for SX1276
|
||||
}
|
||||
|
||||
void onAfterTransmit() override{
|
||||
digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED off - invert pin for SX1276
|
||||
}
|
||||
#endif
|
||||
|
||||
void enterDeepSleep(uint32_t secs, int pin_wake_btn) {
|
||||
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
|
||||
|
||||
// Make sure the DIO1 and NSS GPIOs are hold on required levels during deep sleep
|
||||
rtc_gpio_set_direction((gpio_num_t)P_LORA_DIO_1, RTC_GPIO_MODE_INPUT_ONLY);
|
||||
rtc_gpio_pulldown_en((gpio_num_t)P_LORA_DIO_1);
|
||||
|
||||
rtc_gpio_hold_en((gpio_num_t)P_LORA_NSS);
|
||||
|
||||
if (pin_wake_btn < 0) {
|
||||
esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet
|
||||
} else {
|
||||
esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1) | (1L << pin_wake_btn), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet OR wake btn
|
||||
}
|
||||
|
||||
if (secs > 0) {
|
||||
esp_sleep_enable_timer_wakeup(secs * 1000000);
|
||||
}
|
||||
|
||||
// Finally set ESP32 into sleep
|
||||
esp_deep_sleep_start(); // CPU halts here and never returns!
|
||||
}
|
||||
|
||||
uint16_t getBattMilliVolts() {
|
||||
#if defined(PIN_VBAT_READ) && defined(ADC_MULTIPLIER)
|
||||
analogReadResolution(12);
|
||||
|
||||
uint32_t raw = 0;
|
||||
for (int i = 0; i < BATTERY_SAMPLES; i++) {
|
||||
raw += analogRead(PIN_VBAT_READ);
|
||||
}
|
||||
|
||||
raw = raw / BATTERY_SAMPLES;
|
||||
return (ADC_MULTIPLIER * raw) / 4096;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* getManufacturerName() const{
|
||||
return "LilyGo T-Deck";
|
||||
}
|
||||
};
|
||||
@@ -1,115 +0,0 @@
|
||||
[LilyGo_TDeck]
|
||||
extends = esp32_base
|
||||
board = t-deck
|
||||
build_flags =
|
||||
${esp32_base.build_flags}
|
||||
${sensor_base.build_flags}
|
||||
-I variants/lilygo_tdeck
|
||||
-D LILYGO_TDECK
|
||||
-D BOARD_HAS_PSRAM=1
|
||||
-D CORE_DEBUG_LEVEL=1
|
||||
-D ARDUINO_USB_CDC_ON_BOOT=1
|
||||
-D PIN_USER_BTN=0 ; Trackball button
|
||||
-D PIN_PERF_POWERON=10 ; Peripheral power pin
|
||||
-D RADIO_CLASS=CustomSX1262
|
||||
-D WRAPPER_CLASS=CustomSX1262Wrapper
|
||||
-D LORA_TX_POWER=22
|
||||
-D SX126X_DIO2_AS_RF_SWITCH=false
|
||||
-D SX126X_CURRENT_LIMIT=140
|
||||
-D SX126X_RX_BOOSTED_GAIN=1
|
||||
-D SX126X_DIO3_TCXO_VOLTAGE=1.8f
|
||||
-D P_LORA_DIO_1=45 ; LORA IRQ pin
|
||||
-D ENV_INCLUDE_GPS=1
|
||||
-D ENV_INCLUDE_AHTX0=0
|
||||
-D ENV_INCLUDE_BME280=0
|
||||
-D ENV_INCLUDE_BMP280=0
|
||||
-D ENV_INCLUDE_SHTC3=0
|
||||
-D ENV_INCLUDE_SHT4X=0
|
||||
-D ENV_INCLUDE_LPS22HB=0
|
||||
-D ENV_INCLUDE_INA3221=0
|
||||
-D ENV_INCLUDE_INA219=0
|
||||
-D ENV_INCLUDE_INA226=0
|
||||
-D ENV_INCLUDE_INA260=0
|
||||
-D ENV_INCLUDE_MLX90614=0
|
||||
-D ENV_INCLUDE_VL53L0X=0
|
||||
-D ENV_INCLUDE_BME680=0
|
||||
-D ENV_INCLUDE_BMP085=0
|
||||
-D P_LORA_NSS=9 ; LORA SS pin
|
||||
-D P_LORA_RESET=17 ; LORA RST pin
|
||||
-D P_LORA_BUSY=13 ; LORA Busy pin
|
||||
-D P_LORA_SCLK=40 ; LORA SCLK pin
|
||||
-D P_LORA_MISO=38 ; LORA MISO pin
|
||||
-D P_LORA_MOSI=41 ; LORA MOSI pin
|
||||
-D DISPLAY_CLASS=ST7789LCDDisplay
|
||||
-D DISPLAY_SCALE_X=2.5
|
||||
-D DISPLAY_SCALE_Y=3.75
|
||||
-D PIN_TFT_RST=-1
|
||||
-D PIN_TFT_VDD_CTL=-1
|
||||
-D PIN_TFT_LEDA_CTL=42
|
||||
-D PIN_TFT_CS=12
|
||||
-D PIN_TFT_DC=11
|
||||
-D PIN_TFT_SCL=40
|
||||
-D PIN_TFT_SDA=41
|
||||
-D PIN_GPS_RX=43
|
||||
-D PIN_GPS_TX=44
|
||||
-D GPS_BAUD_RATE=38400
|
||||
build_src_filter = ${esp32_base.build_src_filter}
|
||||
+<../variants/lilygo_tdeck>
|
||||
+<helpers/sensors/*.cpp>
|
||||
lib_deps =
|
||||
${esp32_base.lib_deps}
|
||||
${sensor_base.lib_deps}
|
||||
adafruit/Adafruit ST7735 and ST7789 Library @ ^1.11.0
|
||||
|
||||
[env:LilyGo_TDeck_companion_radio_usb]
|
||||
extends = LilyGo_TDeck
|
||||
build_flags =
|
||||
${LilyGo_TDeck.build_flags}
|
||||
-I examples/companion_radio/ui-new
|
||||
-D MAX_CONTACTS=350
|
||||
-D MAX_GROUP_CHANNELS=40
|
||||
-D OFFLINE_QUEUE_SIZE=256
|
||||
build_src_filter = ${LilyGo_TDeck.build_src_filter}
|
||||
+<helpers/esp32/*.cpp>
|
||||
+<helpers/ui/MomentaryButton.cpp>
|
||||
+<../examples/companion_radio/*.cpp>
|
||||
+<../examples/companion_radio/ui-new/*.cpp>
|
||||
+<helpers/ui/ST7789LCDDisplay.cpp>
|
||||
lib_deps =
|
||||
${LilyGo_TDeck.lib_deps}
|
||||
densaugeo/base64 @ ~1.4.0
|
||||
|
||||
[env:LilyGo_TDeck_companion_radio_ble]
|
||||
extends = LilyGo_TDeck
|
||||
build_flags =
|
||||
${LilyGo_TDeck.build_flags}
|
||||
-I examples/companion_radio/ui-new
|
||||
-D MAX_CONTACTS=350
|
||||
-D MAX_GROUP_CHANNELS=40
|
||||
-D BLE_PIN_CODE=123456
|
||||
-D OFFLINE_QUEUE_SIZE=256
|
||||
build_src_filter = ${LilyGo_TDeck.build_src_filter}
|
||||
+<helpers/esp32/*.cpp>
|
||||
+<helpers/ui/MomentaryButton.cpp>
|
||||
+<../examples/companion_radio/*.cpp>
|
||||
+<../examples/companion_radio/ui-new/*.cpp>
|
||||
+<helpers/ui/ST7789LCDDisplay.cpp>
|
||||
lib_deps =
|
||||
${LilyGo_TDeck.lib_deps}
|
||||
densaugeo/base64 @ ~1.4.0
|
||||
|
||||
[env:LilyGo_TDeck_repeater]
|
||||
extends = LilyGo_TDeck
|
||||
build_flags =
|
||||
${LilyGo_TDeck.build_flags}
|
||||
-D ADVERT_NAME='"TDeck Repeater"'
|
||||
-D ADVERT_LAT=0.0
|
||||
-D ADVERT_LON=0.0
|
||||
-D ADMIN_PASSWORD='"password"'
|
||||
-D MAX_NEIGHBOURS=50
|
||||
build_src_filter = ${LilyGo_TDeck.build_src_filter}
|
||||
+<../examples/simple_repeater>
|
||||
+<helpers/ui/ST7789LCDDisplay.cpp>
|
||||
lib_deps =
|
||||
${LilyGo_TDeck.lib_deps}
|
||||
${esp32_ota.lib_deps}
|
||||
@@ -8,9 +8,10 @@
|
||||
// 240 MHz ~70-80 mA
|
||||
// 160 MHz ~50-60 mA
|
||||
// 80 MHz ~30-40 mA
|
||||
// 40 MHz ~15-20 mA (low-power / lock screen mode)
|
||||
//
|
||||
// SPI peripherals and UART use their own clock dividers from the APB clock,
|
||||
// so LoRa, e-ink, and GPS serial all work fine at 80MHz.
|
||||
// so LoRa, e-ink, and GPS serial all work fine at 80MHz and 40MHz.
|
||||
|
||||
#ifdef ESP32
|
||||
|
||||
@@ -22,23 +23,36 @@
|
||||
#define CPU_FREQ_BOOST 240 // MHz — heavy processing
|
||||
#endif
|
||||
|
||||
#ifndef CPU_FREQ_LOW_POWER
|
||||
#define CPU_FREQ_LOW_POWER 80 // MHz — lock screen / idle standby (40 MHz breaks I2C)
|
||||
#endif
|
||||
|
||||
#ifndef CPU_BOOST_TIMEOUT_MS
|
||||
#define CPU_BOOST_TIMEOUT_MS 10000 // 10 seconds
|
||||
#endif
|
||||
|
||||
class CPUPowerManager {
|
||||
public:
|
||||
CPUPowerManager() : _boosted(false), _boost_started(0) {}
|
||||
CPUPowerManager() : _boosted(false), _lowPower(false), _boost_started(0) {}
|
||||
|
||||
void begin() {
|
||||
setCpuFrequencyMhz(CPU_FREQ_IDLE);
|
||||
_boosted = false;
|
||||
_lowPower = false;
|
||||
MESH_DEBUG_PRINTLN("CPU power: idle at %d MHz", CPU_FREQ_IDLE);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (_boosted && (millis() - _boost_started >= CPU_BOOST_TIMEOUT_MS)) {
|
||||
setIdle();
|
||||
// Return to low-power if locked, otherwise normal idle
|
||||
if (_lowPower) {
|
||||
setCpuFrequencyMhz(CPU_FREQ_LOW_POWER);
|
||||
MESH_DEBUG_PRINTLN("CPU power: boost expired, returning to low-power %d MHz", CPU_FREQ_LOW_POWER);
|
||||
} else {
|
||||
setCpuFrequencyMhz(CPU_FREQ_IDLE);
|
||||
MESH_DEBUG_PRINTLN("CPU power: idle at %d MHz", CPU_FREQ_IDLE);
|
||||
}
|
||||
_boosted = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,13 +71,42 @@ public:
|
||||
_boosted = false;
|
||||
MESH_DEBUG_PRINTLN("CPU power: idle at %d MHz", CPU_FREQ_IDLE);
|
||||
}
|
||||
if (_lowPower) {
|
||||
_lowPower = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Low-power mode — drops CPU to 40 MHz for lock screen standby.
|
||||
// If currently boosted, the boost timeout will return to 40 MHz
|
||||
// instead of 80 MHz.
|
||||
void setLowPower() {
|
||||
_lowPower = true;
|
||||
if (!_boosted) {
|
||||
setCpuFrequencyMhz(CPU_FREQ_LOW_POWER);
|
||||
MESH_DEBUG_PRINTLN("CPU power: low-power at %d MHz", CPU_FREQ_LOW_POWER);
|
||||
}
|
||||
// If boosted, the loop() timeout will drop to low-power instead of idle
|
||||
}
|
||||
|
||||
// Exit low-power mode — returns to normal idle (80 MHz).
|
||||
// If currently boosted, the boost timeout will return to idle
|
||||
// instead of low-power.
|
||||
void clearLowPower() {
|
||||
_lowPower = false;
|
||||
if (!_boosted) {
|
||||
setCpuFrequencyMhz(CPU_FREQ_IDLE);
|
||||
MESH_DEBUG_PRINTLN("CPU power: idle at %d MHz (low-power cleared)", CPU_FREQ_IDLE);
|
||||
}
|
||||
// If boosted, the loop() timeout will drop to idle as normal
|
||||
}
|
||||
|
||||
bool isBoosted() const { return _boosted; }
|
||||
bool isLowPower() const { return _lowPower; }
|
||||
uint32_t getFrequencyMHz() const { return getCpuFrequencyMhz(); }
|
||||
|
||||
private:
|
||||
bool _boosted;
|
||||
bool _lowPower;
|
||||
unsigned long _boost_started;
|
||||
};
|
||||
|
||||
|
||||
@@ -199,11 +199,16 @@ bool TDeckBoard::configureFuelGauge(uint16_t designCapacity_mAh) {
|
||||
// Design Capacity correct, but check if Full Charge Capacity is sane.
|
||||
uint16_t fcc = bq27220_read16(BQ27220_REG_FULL_CAP);
|
||||
Serial.printf("BQ27220: Design Capacity already correct, FCC=%d mAh\n", fcc);
|
||||
if (fcc >= designCapacity_mAh * 3 / 2) {
|
||||
// Check if FCC is outside an acceptable band around design capacity.
|
||||
// Catches both: FCC too high (stale factory 3000mAh) and FCC too low
|
||||
// (gauge learned on a smaller battery, e.g. 1400mAh on a 2500mAh pack).
|
||||
uint16_t fccLo = (designCapacity_mAh > 100) ? designCapacity_mAh - 100 : 0;
|
||||
uint16_t fccHi = designCapacity_mAh + 100;
|
||||
if (fcc < fccLo || fcc > fccHi) {
|
||||
// FCC is >=150% of design — stale from factory defaults (typically 3000 mAh).
|
||||
uint16_t designEnergy = (uint16_t)((uint32_t)designCapacity_mAh * 37 / 10);
|
||||
Serial.printf("BQ27220: FCC %d >> DC %d, checking Design Energy (target %d mWh)\n",
|
||||
fcc, designCapacity_mAh, designEnergy);
|
||||
Serial.printf("BQ27220: FCC %d outside target band [%d..%d], checking Design Energy (target %d mWh)\n",
|
||||
fcc, fccLo, fccHi, designEnergy);
|
||||
|
||||
// Unseal to read data memory and issue RESET
|
||||
bq27220_writeControl(0x0414); delay(2);
|
||||
@@ -344,7 +349,7 @@ bool TDeckBoard::configureFuelGauge(uint16_t designCapacity_mAh) {
|
||||
fcc = bq27220_read16(BQ27220_REG_FULL_CAP);
|
||||
Serial.printf("BQ27220: FCC after RESET: %d mAh (target <= %d)\n", fcc, designCapacity_mAh);
|
||||
|
||||
if (fcc > designCapacity_mAh * 3 / 2) {
|
||||
if (fcc > designCapacity_mAh) {
|
||||
// RESET didn't fix FCC — the gauge IT algorithm is stubbornly
|
||||
// retaining its learned value. This typically resolves after one
|
||||
// full charge/discharge cycle. Software clamp in
|
||||
|
||||
@@ -21,7 +21,9 @@
|
||||
#define KB_KEY_BACKSPACE '\b'
|
||||
#define KB_KEY_ENTER '\r'
|
||||
#define KB_KEY_SPACE ' '
|
||||
#define KB_KEY_EMOJI 0x01 // Non-printable code for $ key (emoji picker)
|
||||
#define KB_KEY_EMOJI 0x01 // Non-printable code for $ key (emoji picker)
|
||||
#define KB_KEY_MIC 0x02 // Mic key press (PTT start / voice screen open)
|
||||
#define KB_KEY_MIC_RELEASE 0x03 // Mic key release (PTT stop)
|
||||
|
||||
class TCA8418Keyboard {
|
||||
private:
|
||||
@@ -34,7 +36,10 @@ private:
|
||||
bool _shiftUsedWhileHeld; // Was shift consumed by any key while held
|
||||
bool _altActive; // Sticky alt (one-shot)
|
||||
bool _symActive; // Sticky sym (one-shot)
|
||||
bool _micHeld; // Mic key physically held down (for PTT release detection)
|
||||
unsigned long _lastShiftTime; // For Shift+key combos
|
||||
bool _enterHeld; // Enter key physically held down
|
||||
unsigned long _enterPressTime; // millis() when Enter was pressed
|
||||
|
||||
uint8_t readReg(uint8_t reg) {
|
||||
_wire->beginTransmission(_addr);
|
||||
@@ -151,7 +156,8 @@ private:
|
||||
public:
|
||||
TCA8418Keyboard(uint8_t addr = 0x34, TwoWire* wire = &Wire)
|
||||
: _addr(addr), _wire(wire), _initialized(false),
|
||||
_shiftActive(false), _shiftConsumed(false), _shiftHeld(false), _shiftUsedWhileHeld(false), _altActive(false), _symActive(false), _lastShiftTime(0) {}
|
||||
_shiftActive(false), _shiftConsumed(false), _shiftHeld(false), _shiftUsedWhileHeld(false), _altActive(false), _symActive(false), _micHeld(false), _lastShiftTime(0),
|
||||
_enterHeld(false), _enterPressTime(0) {}
|
||||
|
||||
bool begin() {
|
||||
// Check if device responds
|
||||
@@ -161,24 +167,47 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
// Configure keyboard matrix (8 rows x 10 cols)
|
||||
// --- Warm-reboot safe init sequence ---
|
||||
// The TCA8418 stays powered across ESP32 resets (no dedicated RST pin),
|
||||
// so the scanner may still be active from the previous session.
|
||||
// We must disable it before reconfiguring the matrix.
|
||||
|
||||
// 1. Disable scanner — stop all scanning before touching config
|
||||
writeReg(TCA8418_REG_CFG, 0x00);
|
||||
|
||||
// 2. Drain any stale events from the previous session
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if ((readReg(TCA8418_REG_KEY_LCK_EC) & 0x0F) == 0) break;
|
||||
readReg(TCA8418_REG_KEY_EVENT_A);
|
||||
}
|
||||
writeReg(TCA8418_REG_INT_STAT, 0x1F); // Clear all interrupt flags
|
||||
|
||||
// 3. Explicitly clear GPI event masks (prevent phantom GPI events)
|
||||
writeReg(TCA8418_REG_GPI_EM1, 0x00);
|
||||
writeReg(TCA8418_REG_GPI_EM2, 0x00);
|
||||
writeReg(TCA8418_REG_GPI_EM3, 0x00);
|
||||
|
||||
// 4. Configure keyboard matrix (8 rows x 10 cols)
|
||||
writeReg(TCA8418_REG_KP_GPIO1, 0xFF); // Rows 0-7 as keypad
|
||||
writeReg(TCA8418_REG_KP_GPIO2, 0xFF); // Cols 0-7 as keypad
|
||||
writeReg(TCA8418_REG_KP_GPIO3, 0x03); // Cols 8-9 as keypad
|
||||
|
||||
// Enable keypad with FIFO overflow detection
|
||||
writeReg(TCA8418_REG_CFG, 0x11); // KE_IEN + INT_CFG
|
||||
|
||||
// Set debounce
|
||||
// 5. Set debounce
|
||||
writeReg(TCA8418_REG_DEBOUNCE, 0x03);
|
||||
|
||||
// Clear any pending interrupts
|
||||
// 6. Final pre-enable cleanup
|
||||
writeReg(TCA8418_REG_INT_STAT, 0x1F);
|
||||
|
||||
// Flush the FIFO
|
||||
while (readReg(TCA8418_REG_KEY_LCK_EC) & 0x0F) {
|
||||
// 7. Enable scanner — matrix config is stable, safe to start scanning
|
||||
writeReg(TCA8418_REG_CFG, 0x11); // KE_IEN + INT_CFG
|
||||
|
||||
// 8. Let scanner stabilise, then flush any spurious first-scan events
|
||||
delay(5);
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if ((readReg(TCA8418_REG_KEY_LCK_EC) & 0x0F) == 0) break;
|
||||
readReg(TCA8418_REG_KEY_EVENT_A);
|
||||
}
|
||||
writeReg(TCA8418_REG_INT_STAT, 0x1F);
|
||||
|
||||
_initialized = true;
|
||||
Serial.println("TCA8418: Keyboard initialized OK");
|
||||
@@ -219,7 +248,22 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Track mic key release — return KB_KEY_MIC_RELEASE for PTT stop
|
||||
if (!pressed && keyCode == 34) {
|
||||
if (_micHeld) {
|
||||
_micHeld = false;
|
||||
Serial.println("KB: Mic released -> KB_KEY_MIC_RELEASE");
|
||||
return KB_KEY_MIC_RELEASE;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Only act on key press, not release
|
||||
// (Enter release tracked for long-press detection)
|
||||
if (!pressed && keyCode == 21) {
|
||||
_enterHeld = false;
|
||||
return 0;
|
||||
}
|
||||
if (!pressed || keyCode == 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -243,6 +287,13 @@ public:
|
||||
Serial.println("KB: Sym activated");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Track Enter press for long-press detection
|
||||
if (keyCode == 21) {
|
||||
_enterHeld = true;
|
||||
_enterPressTime = millis();
|
||||
// Fall through to normal processing — '\r' is returned below
|
||||
}
|
||||
|
||||
// Handle dedicated $ key (key code 22, next to M)
|
||||
// Bare press = emoji picker, Sym+$ = literal '$'
|
||||
@@ -256,12 +307,17 @@ public:
|
||||
return KB_KEY_EMOJI;
|
||||
}
|
||||
|
||||
// Handle Mic key - always produces '0' (silk-screened on key)
|
||||
// Sym+Mic also produces '0' (consumes sym so it doesn't leak)
|
||||
// Handle Mic key — bare press returns KB_KEY_MIC for PTT / voice screen
|
||||
// Sym+Mic produces '0' (silk-screened on key) for text input
|
||||
if (keyCode == 34) {
|
||||
_symActive = false;
|
||||
Serial.println("KB: Mic -> '0'");
|
||||
return '0';
|
||||
if (_symActive) {
|
||||
_symActive = false;
|
||||
Serial.println("KB: Sym+Mic -> '0'");
|
||||
return '0';
|
||||
}
|
||||
_micHeld = true;
|
||||
Serial.println("KB: Mic -> KB_KEY_MIC");
|
||||
return KB_KEY_MIC;
|
||||
}
|
||||
|
||||
// Get the character
|
||||
@@ -315,6 +371,7 @@ public:
|
||||
}
|
||||
|
||||
bool isReady() const { return _initialized; }
|
||||
bool isMicHeld() const { return _micHeld; }
|
||||
|
||||
// Check if shift was pressed within the last N milliseconds
|
||||
bool wasShiftRecentlyPressed(unsigned long withinMs = 500) const {
|
||||
@@ -326,4 +383,10 @@ public:
|
||||
bool wasShiftConsumed() const {
|
||||
return _shiftConsumed;
|
||||
}
|
||||
|
||||
// Enter long-press detection
|
||||
bool isEnterHeld() const { return _enterHeld; }
|
||||
unsigned long enterHeldMs() const {
|
||||
return _enterHeld ? (millis() - _enterPressTime) : 0;
|
||||
}
|
||||
};
|
||||
@@ -83,6 +83,8 @@ build_flags =
|
||||
-D PIN_DISPLAY_MOSI=33
|
||||
-D PIN_DISPLAY_BL=45
|
||||
-D PIN_USER_BTN=0
|
||||
-D HAS_TOUCHSCREEN=1
|
||||
-D CST328_PIN_INT=12
|
||||
-D CST328_PIN_RST=38
|
||||
-D ARDUINO_LOOP_STACK_SIZE=32768
|
||||
build_src_filter = ${esp32_base.build_src_filter}
|
||||
@@ -94,24 +96,30 @@ lib_deps =
|
||||
zinggjm/GxEPD2@^1.5.9
|
||||
adafruit/Adafruit GFX Library@^1.11.0
|
||||
bitbank2/PNGdec@^1.0.1
|
||||
WebServer
|
||||
DNSServer
|
||||
Update
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Meck unified builds — one codebase, six variants via build flags
|
||||
; ---------------------------------------------------------------------------
|
||||
|
||||
; Audio + BLE companion (audio-player hardware with BLE phone bridging)
|
||||
; MAX_CONTACTS=500 is near BLE protocol ceiling (MAX_CONTACTS/2 sent as uint8_t, max 510)
|
||||
; MAX_CONTACTS=2000 — protocol v11+ sends true capacity in extended DEVICE_INFO field.
|
||||
; Older apps see 510 (sentinel 0xFF in legacy byte) and still work correctly.
|
||||
; Contact + sort arrays allocated in PSRAM via BaseChatMesh::initContacts().
|
||||
[env:meck_audio_ble]
|
||||
extends = LilyGo_TDeck_Pro
|
||||
build_flags =
|
||||
${LilyGo_TDeck_Pro.build_flags}
|
||||
-I examples/companion_radio/ui-new
|
||||
-D MAX_CONTACTS=500
|
||||
-D MAX_CONTACTS=2000
|
||||
-D MAX_GROUP_CHANNELS=20
|
||||
-D BLE_PIN_CODE=123456
|
||||
-D OFFLINE_QUEUE_SIZE=256
|
||||
-D MECK_AUDIO_VARIANT
|
||||
-D MECK_WEB_READER=1
|
||||
-D MECK_OTA_UPDATE=1
|
||||
build_src_filter = ${LilyGo_TDeck_Pro.build_src_filter}
|
||||
+<helpers/esp32/*.cpp>
|
||||
+<helpers/ui/MomentaryButton.cpp>
|
||||
@@ -123,6 +131,10 @@ lib_deps =
|
||||
densaugeo/base64 @ ~1.4.0
|
||||
https://github.com/schreibfaul1/ESP32-audioI2S.git#2.0.6
|
||||
bitbank2/JPEGDEC
|
||||
https://github.com/sh123/esp32_codec2_arduino.git
|
||||
lib_ignore =
|
||||
AsyncTCP
|
||||
ESPAsyncWebServer
|
||||
|
||||
; Audio + WiFi companion (audio-player hardware with WiFi app bridging)
|
||||
; No BLE — WiFi companion uses SerialWifiInterface (TCP socket on port 5000).
|
||||
@@ -136,7 +148,7 @@ extends = LilyGo_TDeck_Pro
|
||||
build_flags =
|
||||
${LilyGo_TDeck_Pro.build_flags}
|
||||
-I examples/companion_radio/ui-new
|
||||
-D MAX_CONTACTS=1500
|
||||
-D MAX_CONTACTS=2000
|
||||
-D MAX_GROUP_CHANNELS=20
|
||||
-D MECK_WIFI_COMPANION=1
|
||||
-D TCP_PORT=5000
|
||||
@@ -144,9 +156,11 @@ build_flags =
|
||||
-D OFFLINE_QUEUE_SIZE=256
|
||||
-D MECK_AUDIO_VARIANT
|
||||
-D MECK_WEB_READER=1
|
||||
-D FIRMWARE_VERSION='"Meck v1.0.WiFi"'
|
||||
-D MECK_OTA_UPDATE=1
|
||||
-D FIRMWARE_VERSION='"Meck v1.7.WiFi"'
|
||||
build_src_filter = ${LilyGo_TDeck_Pro.build_src_filter}
|
||||
+<helpers/esp32/*.cpp>
|
||||
-<helpers/esp32/SerialBLEInterface.cpp>
|
||||
+<helpers/ui/MomentaryButton.cpp>
|
||||
+<../examples/companion_radio/*.cpp>
|
||||
+<../examples/companion_radio/ui-new/*.cpp>
|
||||
@@ -156,21 +170,29 @@ lib_deps =
|
||||
densaugeo/base64 @ ~1.4.0
|
||||
https://github.com/schreibfaul1/ESP32-audioI2S.git#2.0.6
|
||||
bitbank2/JPEGDEC
|
||||
https://github.com/sh123/esp32_codec2_arduino.git
|
||||
lib_ignore =
|
||||
AsyncTCP
|
||||
ESPAsyncWebServer
|
||||
ESP32 BLE Arduino
|
||||
|
||||
; Audio standalone (audio-player hardware, no BLE/WiFi — maximum battery life)
|
||||
; No MECK_WEB_READER: WiFi power draw conflicts with zero-radio-power design.
|
||||
; OTA enabled: WiFi AP activates only during user-initiated firmware updates.
|
||||
; Contacts and sort arrays allocated in PSRAM — 1500 contacts uses ~290KB of 8MB.
|
||||
[env:meck_audio_standalone]
|
||||
extends = LilyGo_TDeck_Pro
|
||||
build_flags =
|
||||
${LilyGo_TDeck_Pro.build_flags}
|
||||
-I examples/companion_radio/ui-new
|
||||
-D MAX_CONTACTS=1500
|
||||
-D MAX_CONTACTS=2000
|
||||
-D MAX_GROUP_CHANNELS=20
|
||||
-D OFFLINE_QUEUE_SIZE=1
|
||||
-D MECK_AUDIO_VARIANT
|
||||
-D MECK_OTA_UPDATE=1
|
||||
build_src_filter = ${LilyGo_TDeck_Pro.build_src_filter}
|
||||
+<helpers/esp32/*.cpp>
|
||||
-<helpers/esp32/SerialBLEInterface.cpp>
|
||||
+<helpers/ui/MomentaryButton.cpp>
|
||||
+<../examples/companion_radio/*.cpp>
|
||||
+<../examples/companion_radio/ui-new/*.cpp>
|
||||
@@ -180,21 +202,29 @@ lib_deps =
|
||||
densaugeo/base64 @ ~1.4.0
|
||||
https://github.com/schreibfaul1/ESP32-audioI2S.git#2.0.6
|
||||
bitbank2/JPEGDEC
|
||||
https://github.com/sh123/esp32_codec2_arduino.git
|
||||
lib_ignore =
|
||||
AsyncTCP
|
||||
ESPAsyncWebServer
|
||||
ESP32 BLE Arduino
|
||||
|
||||
; 4G + BLE companion (4G modem hardware, no audio — GPIO conflict with PCM5102A)
|
||||
; MAX_CONTACTS=500 is near BLE protocol ceiling (MAX_CONTACTS/2 sent as uint8_t, max 510)
|
||||
; MAX_CONTACTS=2000 — protocol v11+ sends true capacity in extended DEVICE_INFO field.
|
||||
; Older apps see 510 (sentinel 0xFF in legacy byte) and still work correctly.
|
||||
; Contact + sort arrays allocated in PSRAM via BaseChatMesh::initContacts().
|
||||
[env:meck_4g_ble]
|
||||
extends = LilyGo_TDeck_Pro
|
||||
build_flags =
|
||||
${LilyGo_TDeck_Pro.build_flags}
|
||||
-I examples/companion_radio/ui-new
|
||||
-D MAX_CONTACTS=500
|
||||
-D MAX_CONTACTS=2000
|
||||
-D MAX_GROUP_CHANNELS=20
|
||||
-D BLE_PIN_CODE=123456
|
||||
-D OFFLINE_QUEUE_SIZE=256
|
||||
-D HAS_4G_MODEM=1
|
||||
-D MECK_WEB_READER=1
|
||||
-D FIRMWARE_VERSION='"Meck v1.0.4G"'
|
||||
-D MECK_OTA_UPDATE=1
|
||||
-D FIRMWARE_VERSION='"Meck v1.7.4G"'
|
||||
build_src_filter = ${LilyGo_TDeck_Pro.build_src_filter}
|
||||
+<helpers/esp32/*.cpp>
|
||||
+<helpers/ui/MomentaryButton.cpp>
|
||||
@@ -204,6 +234,11 @@ build_src_filter = ${LilyGo_TDeck_Pro.build_src_filter}
|
||||
lib_deps =
|
||||
${LilyGo_TDeck_Pro.lib_deps}
|
||||
densaugeo/base64 @ ~1.4.0
|
||||
lib_ignore =
|
||||
AsyncTCP
|
||||
ESPAsyncWebServer
|
||||
ESP32-audioI2S
|
||||
esp32_codec2_arduinov
|
||||
|
||||
; 4G + WiFi companion (4G modem hardware with WiFi app bridging, no audio)
|
||||
; No BLE — WiFi companion uses SerialWifiInterface (TCP socket on port 5000).
|
||||
@@ -216,7 +251,7 @@ extends = LilyGo_TDeck_Pro
|
||||
build_flags =
|
||||
${LilyGo_TDeck_Pro.build_flags}
|
||||
-I examples/companion_radio/ui-new
|
||||
-D MAX_CONTACTS=1500
|
||||
-D MAX_CONTACTS=2000
|
||||
-D MAX_GROUP_CHANNELS=20
|
||||
-D MECK_WIFI_COMPANION=1
|
||||
-D TCP_PORT=5000
|
||||
@@ -224,9 +259,11 @@ build_flags =
|
||||
-D OFFLINE_QUEUE_SIZE=256
|
||||
-D HAS_4G_MODEM=1
|
||||
-D MECK_WEB_READER=1
|
||||
-D FIRMWARE_VERSION='"Meck v1.0.4G.WiFi"'
|
||||
-D MECK_OTA_UPDATE=1
|
||||
-D FIRMWARE_VERSION='"Meck v1.7.4G.WiFi"'
|
||||
build_src_filter = ${LilyGo_TDeck_Pro.build_src_filter}
|
||||
+<helpers/esp32/*.cpp>
|
||||
-<helpers/esp32/SerialBLEInterface.cpp>
|
||||
+<helpers/ui/MomentaryButton.cpp>
|
||||
+<../examples/companion_radio/*.cpp>
|
||||
+<../examples/companion_radio/ui-new/*.cpp>
|
||||
@@ -234,6 +271,12 @@ build_src_filter = ${LilyGo_TDeck_Pro.build_src_filter}
|
||||
lib_deps =
|
||||
${LilyGo_TDeck_Pro.lib_deps}
|
||||
densaugeo/base64 @ ~1.4.0
|
||||
lib_ignore =
|
||||
AsyncTCP
|
||||
ESPAsyncWebServer
|
||||
ESP32-audioI2S
|
||||
esp32_codec2_arduino
|
||||
ESP32 BLE Arduino
|
||||
|
||||
; 4G standalone (4G modem hardware, no BLE — maximum battery + cellular features)
|
||||
; No BLE_PIN_CODE: BLE never initializes, saving ~30KB heap + radio power.
|
||||
@@ -245,18 +288,146 @@ extends = LilyGo_TDeck_Pro
|
||||
build_flags =
|
||||
${LilyGo_TDeck_Pro.build_flags}
|
||||
-I examples/companion_radio/ui-new
|
||||
-D MAX_CONTACTS=1500
|
||||
-D MAX_CONTACTS=2000
|
||||
-D MAX_GROUP_CHANNELS=20
|
||||
-D OFFLINE_QUEUE_SIZE=1
|
||||
-D HAS_4G_MODEM=1
|
||||
-D MECK_WEB_READER=1
|
||||
-D FIRMWARE_VERSION='"Meck v1.0.4G.SA"'
|
||||
-D MECK_OTA_UPDATE=1
|
||||
-D FIRMWARE_VERSION='"Meck v1.7.4G.SA"'
|
||||
build_src_filter = ${LilyGo_TDeck_Pro.build_src_filter}
|
||||
+<helpers/esp32/*.cpp>
|
||||
-<helpers/esp32/SerialBLEInterface.cpp>
|
||||
+<helpers/ui/MomentaryButton.cpp>
|
||||
+<../examples/companion_radio/*.cpp>
|
||||
+<../examples/companion_radio/ui-new/*.cpp>
|
||||
+<helpers/ui/GxEPDDisplay.cpp>
|
||||
lib_deps =
|
||||
${LilyGo_TDeck_Pro.lib_deps}
|
||||
densaugeo/base64 @ ~1.4.0
|
||||
densaugeo/base64 @ ~1.4.0
|
||||
lib_ignore =
|
||||
AsyncTCP
|
||||
ESPAsyncWebServer
|
||||
ESP32-audioI2S
|
||||
esp32_codec2_arduino
|
||||
ESP32 BLE Arduino
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Remote Repeater (T-Deck Pro 4G, cellular MQTT remote management)
|
||||
;
|
||||
; MeshCore repeater firmware + A7682E cellular MQTT for remote admin.
|
||||
; No BLE, no SMS/calls, no companion protocol. All management via MQTT
|
||||
; or USB serial CLI.
|
||||
;
|
||||
; SD card config required: /remote/mqtt.cfg (broker, port, user, pass)
|
||||
; Optional: /remote/apn.cfg (APN override)
|
||||
;
|
||||
; Add this block to the bottom of platformio.ini
|
||||
; Flash with: pio run -e meck_remote_repeater
|
||||
; ---------------------------------------------------------------------------
|
||||
[env:meck_remote_repeater]
|
||||
extends = LilyGo_TDeck_Pro
|
||||
build_flags =
|
||||
${LilyGo_TDeck_Pro.build_flags}
|
||||
-I examples/simple_repeater
|
||||
-D ADMIN_PASSWORD='"admin"'
|
||||
-D HAS_4G_MODEM=1
|
||||
-D DISABLE_WIFI_OTA=1
|
||||
-D MECK_REMOTE_REPEATER=1
|
||||
-D MAX_NEIGHBOURS=50
|
||||
-D FIRMWARE_VERSION='"Meck RemRptr v0.3"'
|
||||
-D FIRMWARE_BUILD_DATE='"5 April 2026"'
|
||||
-D RADIOLIB_EXCLUDE_CC1101=1
|
||||
-D RADIOLIB_EXCLUDE_NRF24=1
|
||||
-D RADIOLIB_EXCLUDE_RF69=1
|
||||
-D RADIOLIB_EXCLUDE_SX1231=1
|
||||
-D RADIOLIB_EXCLUDE_SX1233=1
|
||||
-D RADIOLIB_EXCLUDE_SI443X=1
|
||||
-D RADIOLIB_EXCLUDE_RFM2X=1
|
||||
-D RADIOLIB_EXCLUDE_SX127X=1
|
||||
-D RADIOLIB_EXCLUDE_SX1272=1
|
||||
-D RADIOLIB_EXCLUDE_SX1278=1
|
||||
-D RADIOLIB_EXCLUDE_STM32WLX=1
|
||||
-D RADIOLIB_EXCLUDE_LR11X0=1
|
||||
-D RADIOLIB_EXCLUDE_LLCC68=1
|
||||
-D RADIOLIB_EXCLUDE_SX128X=1
|
||||
-D RADIOLIB_EXCLUDE_AFSK=1
|
||||
-D RADIOLIB_EXCLUDE_AX25=1
|
||||
-D RADIOLIB_EXCLUDE_HELLSCHREIBER=1
|
||||
-D RADIOLIB_EXCLUDE_MORSE=1
|
||||
-D RADIOLIB_EXCLUDE_RTTY=1
|
||||
-D RADIOLIB_EXCLUDE_SSTV=1
|
||||
-D RADIOLIB_EXCLUDE_APRS=1
|
||||
-D RADIOLIB_EXCLUDE_LORAWAN=1
|
||||
-D RADIOLIB_EXCLUDE_PAGER=1
|
||||
-D RADIOLIB_EXCLUDE_FSK4=1
|
||||
-D RADIOLIB_EXCLUDE_BELL=1
|
||||
build_src_filter = ${LilyGo_TDeck_Pro.build_src_filter}
|
||||
+<helpers/esp32/*.cpp>
|
||||
-<helpers/esp32/SerialBLEInterface.cpp>
|
||||
+<helpers/ui/MomentaryButton.cpp>
|
||||
+<helpers/ui/GxEPDDisplay.cpp>
|
||||
+<../examples/simple_repeater/*.cpp>
|
||||
lib_deps =
|
||||
${LilyGo_TDeck_Pro.lib_deps}
|
||||
lib_ignore =
|
||||
ESP32 BLE Arduino
|
||||
NimBLE-Arduino
|
||||
AsyncTCP
|
||||
ESPAsyncWebServer
|
||||
AsyncElegantOTA
|
||||
ESP32-audioI2S
|
||||
esp32_codec2_arduino
|
||||
|
||||
[env:meck_wifi_repeater]
|
||||
extends = LilyGo_TDeck_Pro
|
||||
build_src_filter = ${LilyGo_TDeck_Pro.build_src_filter}
|
||||
+<helpers/esp32/*.cpp>
|
||||
-<helpers/esp32/SerialBLEInterface.cpp>
|
||||
+<helpers/ui/MomentaryButton.cpp>
|
||||
+<helpers/ui/GxEPDDisplay.cpp>
|
||||
+<../examples/simple_repeater/*.cpp>
|
||||
build_flags =
|
||||
${LilyGo_TDeck_Pro.build_flags}
|
||||
-D FIRMWARE_VERSION='"Meck WiFi Rptr v0.3"'
|
||||
-D FIRMWARE_BUILD_DATE='"5 April 2026"'
|
||||
-D MAX_NEIGHBOURS=50
|
||||
-D MECK_WIFI_REMOTE
|
||||
-D MECK_REMOTE_REPEATER=1
|
||||
-D DISABLE_WIFI_OTA=1
|
||||
-D RADIOLIB_EXCLUDE_CC1101=1
|
||||
-D RADIOLIB_EXCLUDE_NRF24=1
|
||||
-D RADIOLIB_EXCLUDE_RF69=1
|
||||
-D RADIOLIB_EXCLUDE_SX1231=1
|
||||
-D RADIOLIB_EXCLUDE_SX1233=1
|
||||
-D RADIOLIB_EXCLUDE_SI443X=1
|
||||
-D RADIOLIB_EXCLUDE_RFM2X=1
|
||||
-D RADIOLIB_EXCLUDE_SX127X=1
|
||||
-D RADIOLIB_EXCLUDE_SX1272=1
|
||||
-D RADIOLIB_EXCLUDE_SX1278=1
|
||||
-D RADIOLIB_EXCLUDE_STM32WLX=1
|
||||
-D RADIOLIB_EXCLUDE_LR11X0=1
|
||||
-D RADIOLIB_EXCLUDE_LLCC68=1
|
||||
-D RADIOLIB_EXCLUDE_SX128X=1
|
||||
-D RADIOLIB_EXCLUDE_AFSK=1
|
||||
-D RADIOLIB_EXCLUDE_AX25=1
|
||||
-D RADIOLIB_EXCLUDE_HELLSCHREIBER=1
|
||||
-D RADIOLIB_EXCLUDE_MORSE=1
|
||||
-D RADIOLIB_EXCLUDE_RTTY=1
|
||||
-D RADIOLIB_EXCLUDE_SSTV=1
|
||||
-D RADIOLIB_EXCLUDE_APRS=1
|
||||
-D RADIOLIB_EXCLUDE_LORAWAN=1
|
||||
-D RADIOLIB_EXCLUDE_PAGER=1
|
||||
-D RADIOLIB_EXCLUDE_FSK4=1
|
||||
-D RADIOLIB_EXCLUDE_BELL=1
|
||||
lib_deps =
|
||||
${LilyGo_TDeck_Pro.lib_deps}
|
||||
knolleary/PubSubClient@^2.8
|
||||
lib_ignore =
|
||||
ESP32 BLE Arduino
|
||||
AsyncTCP
|
||||
RPAsyncTCP
|
||||
ESPAsyncWebServer
|
||||
AsyncElegantOTA
|
||||
ESP32-audioI2S
|
||||
esp32_codec2_arduino
|
||||
@@ -0,0 +1,347 @@
|
||||
#include <Arduino.h>
|
||||
#include "variant.h"
|
||||
#include "TDeckProMaxBoard.h"
|
||||
#include <Mesh.h> // For MESH_DEBUG_PRINTLN
|
||||
|
||||
// LEDC channel for e-ink backlight PWM (Arduino ESP32 core 2.x channel-based API)
|
||||
#ifdef PIN_EINK_BL
|
||||
#define EINK_BL_LEDC_CHANNEL 0
|
||||
#endif
|
||||
|
||||
// =============================================================================
|
||||
// TDeckProMaxBoard::begin() — Boot sequence for T-Deck Pro MAX V0.1
|
||||
//
|
||||
// Critical ordering:
|
||||
// 1. I2C bus init (XL9555, BQ27220, and all sensors share this bus)
|
||||
// 2. XL9555 init (must be up before ANY peripheral that depends on it)
|
||||
// 3. Touch reset pulse via XL9555 (needed before touch driver init)
|
||||
// 4. Keyboard reset pulse via XL9555 (clean keyboard state)
|
||||
// 5. LoRa power enable via XL9555 (must be on before SPI radio init)
|
||||
// 6. GPS power + UART init
|
||||
// 7. Parent class init (ESP32Board::begin)
|
||||
// 8. LoRa SPI pin config + deep sleep wake handling
|
||||
// 9. BQ27220 fuel gauge check
|
||||
// 10. Low-voltage protection
|
||||
//
|
||||
// NOTE: We do NOT call TDeckBoard::begin() — we reimplement the boot sequence
|
||||
// to handle XL9555-routed pins. BQ27220 methods are inherited unchanged.
|
||||
// =============================================================================
|
||||
|
||||
void TDeckProMaxBoard::begin() {
|
||||
|
||||
MESH_DEBUG_PRINTLN("TDeckProMaxBoard::begin() - T-Deck Pro MAX V0.1");
|
||||
|
||||
// ------ Step 1: I2C bus ------
|
||||
// All I2C devices (XL9555, BQ27220, TCA8418, CST328, DRV2605, ES8311,
|
||||
// BQ25896, BHI260AP) share SDA=13, SCL=14.
|
||||
Wire.begin(I2C_SDA, I2C_SCL);
|
||||
Wire.setClock(100000); // 100kHz — safe for all devices on the bus
|
||||
MESH_DEBUG_PRINTLN(" I2C initialized (SDA=%d SCL=%d)", I2C_SDA, I2C_SCL);
|
||||
|
||||
// ------ Step 2: XL9555 I/O Expander ------
|
||||
// This must happen before anything that needs peripheral power or resets.
|
||||
if (!xl9555_init()) {
|
||||
Serial.println("CRITICAL: XL9555 init failed — peripherals will not work!");
|
||||
// Continue anyway; some things (display, keyboard INT) might still work
|
||||
// without XL9555, but LoRa/GPS/modem will be dead.
|
||||
}
|
||||
|
||||
// ------ Step 3: Touch reset pulse ------
|
||||
// The touch controller (CST328) needs a clean reset via XL9555 IO07
|
||||
// before the touch driver tries to communicate with it.
|
||||
touchReset();
|
||||
|
||||
// ------ Step 4: Keyboard reset pulse ------
|
||||
keyboardReset();
|
||||
|
||||
// ------ Step 5: Parent class init ------
|
||||
// ESP32Board::begin() handles common ESP32 setup.
|
||||
// We skip TDeckBoard::begin() because it uses PIN_PERF_POWERON and
|
||||
// direct GPIO for LoRa/GPS power that don't exist on MAX.
|
||||
ESP32Board::begin();
|
||||
|
||||
// ------ Step 6: GPS UART init ------
|
||||
// GPS power was already enabled by XL9555 boot defaults (GPS_EN HIGH).
|
||||
// Now init the UART with the MAX-specific pins.
|
||||
#if HAS_GPS
|
||||
Serial2.begin(GPS_BAUDRATE, SERIAL_8N1, GPS_RX_PIN, GPS_TX_PIN);
|
||||
MESH_DEBUG_PRINTLN(" GPS Serial2 initialized (RX=%d TX=%d @ %d baud)",
|
||||
GPS_RX_PIN, GPS_TX_PIN, GPS_BAUDRATE);
|
||||
#endif
|
||||
|
||||
// ------ Step 7: Configure user button ------
|
||||
pinMode(PIN_USER_BTN, INPUT);
|
||||
|
||||
// ------ Step 8: Configure LoRa SPI pins ------
|
||||
// LoRa power is already enabled via XL9555 (LORA_EN HIGH in boot defaults).
|
||||
pinMode(P_LORA_MISO, INPUT_PULLUP);
|
||||
|
||||
// ------ Step 9: Handle wake from deep sleep ------
|
||||
esp_reset_reason_t reason = esp_reset_reason();
|
||||
if (reason == ESP_RST_DEEPSLEEP) {
|
||||
uint64_t wakeup_source = esp_sleep_get_ext1_wakeup_status();
|
||||
if (wakeup_source & (1ULL << P_LORA_DIO_1)) {
|
||||
startup_reason = BD_STARTUP_RX_PACKET;
|
||||
}
|
||||
rtc_gpio_hold_dis((gpio_num_t)P_LORA_NSS);
|
||||
rtc_gpio_deinit((gpio_num_t)P_LORA_DIO_1);
|
||||
}
|
||||
|
||||
// ------ Step 10: BQ27220 fuel gauge ------
|
||||
#if HAS_BQ27220
|
||||
uint16_t voltage = getBattMilliVolts();
|
||||
MESH_DEBUG_PRINTLN(" Battery voltage: %d mV", voltage);
|
||||
configureFuelGauge(); // Inherited from TDeckBoard — sets 1500 mAh
|
||||
#endif
|
||||
|
||||
// ------ Step 11: Early low-voltage protection ------
|
||||
#if HAS_BQ27220 && defined(AUTO_SHUTDOWN_MILLIVOLTS)
|
||||
{
|
||||
uint16_t bootMv = getBattMilliVolts();
|
||||
if (bootMv > 0 && bootMv < AUTO_SHUTDOWN_MILLIVOLTS) {
|
||||
Serial.printf("CRITICAL: Boot voltage %dmV < %dmV — sleeping immediately\n",
|
||||
bootMv, AUTO_SHUTDOWN_MILLIVOLTS);
|
||||
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL);
|
||||
esp_sleep_enable_ext1_wakeup(1ULL << PIN_USER_BTN, ESP_EXT1_WAKEUP_ANY_HIGH);
|
||||
esp_deep_sleep_start();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// ------ Step 12: E-ink backlight (working on MAX!) ------
|
||||
// Configure LEDC PWM for backlight brightness control.
|
||||
// Start with backlight OFF — UI code can enable it when needed.
|
||||
#ifdef PIN_EINK_BL
|
||||
// Arduino ESP32 core 2.x uses channel-based LEDC API
|
||||
ledcSetup(EINK_BL_LEDC_CHANNEL, 1000, 8); // Channel 0, 1kHz, 8-bit resolution
|
||||
ledcAttachPin(PIN_EINK_BL, EINK_BL_LEDC_CHANNEL);
|
||||
ledcWrite(EINK_BL_LEDC_CHANNEL, 0); // Off by default
|
||||
MESH_DEBUG_PRINTLN(" Backlight PWM configured on IO%d", PIN_EINK_BL);
|
||||
#endif
|
||||
|
||||
MESH_DEBUG_PRINTLN("TDeckProMaxBoard::begin() - complete");
|
||||
}
|
||||
|
||||
|
||||
// =============================================================================
|
||||
// XL9555 I/O Expander — Lightweight I2C Driver
|
||||
// =============================================================================
|
||||
|
||||
bool TDeckProMaxBoard::xl9555_writeReg(uint8_t reg, uint8_t val) {
|
||||
Wire.beginTransmission(I2C_ADDR_XL9555);
|
||||
Wire.write(reg);
|
||||
Wire.write(val);
|
||||
return Wire.endTransmission() == 0;
|
||||
}
|
||||
|
||||
uint8_t TDeckProMaxBoard::xl9555_readReg(uint8_t reg) {
|
||||
Wire.beginTransmission(I2C_ADDR_XL9555);
|
||||
Wire.write(reg);
|
||||
Wire.endTransmission(false);
|
||||
Wire.requestFrom((uint8_t)I2C_ADDR_XL9555, (uint8_t)1);
|
||||
return Wire.available() ? Wire.read() : 0xFF;
|
||||
}
|
||||
|
||||
bool TDeckProMaxBoard::xl9555_init() {
|
||||
MESH_DEBUG_PRINTLN(" XL9555: Initializing I/O expander at 0x%02X", I2C_ADDR_XL9555);
|
||||
|
||||
// Verify XL9555 is present on the bus
|
||||
Wire.beginTransmission(I2C_ADDR_XL9555);
|
||||
if (Wire.endTransmission() != 0) {
|
||||
Serial.println(" XL9555: NOT FOUND on I2C bus!");
|
||||
_xlReady = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set ALL pins as outputs (config register: 0 = output)
|
||||
// Port 0 (pins 0-7): all output
|
||||
if (!xl9555_writeReg(XL9555_REG_CONFIG_0, 0x00)) return false;
|
||||
// Port 1 (pins 8-15): all output
|
||||
if (!xl9555_writeReg(XL9555_REG_CONFIG_1, 0x00)) return false;
|
||||
|
||||
// Apply boot defaults
|
||||
_xlPort0 = XL9555_BOOT_PORT0;
|
||||
_xlPort1 = XL9555_BOOT_PORT1;
|
||||
if (!xl9555_writeReg(XL9555_REG_OUTPUT_0, _xlPort0)) return false;
|
||||
if (!xl9555_writeReg(XL9555_REG_OUTPUT_1, _xlPort1)) return false;
|
||||
|
||||
_xlReady = true;
|
||||
|
||||
MESH_DEBUG_PRINTLN(" XL9555: Ready (Port0=0x%02X Port1=0x%02X)", _xlPort0, _xlPort1);
|
||||
MESH_DEBUG_PRINTLN(" XL9555: LoRa=%s GPS=%s 1V8=%s Modem=%s Antenna=%s",
|
||||
(_xlPort0 & (1 << XL_PIN_LORA_EN)) ? "ON" : "OFF",
|
||||
(_xlPort0 & (1 << XL_PIN_GPS_EN)) ? "ON" : "OFF",
|
||||
(_xlPort0 & (1 << XL_PIN_1V8_EN)) ? "ON" : "OFF",
|
||||
(_xlPort0 & (1 << XL_PIN_6609_EN)) ? "ON" : "OFF",
|
||||
(_xlPort0 & (1 << XL_PIN_LORA_SEL)) ? "internal" : "external");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void TDeckProMaxBoard::xl9555_digitalWrite(uint8_t pin, bool value) {
|
||||
if (!_xlReady) return;
|
||||
|
||||
if (pin < 8) {
|
||||
// Port 0
|
||||
if (value) _xlPort0 |= (1 << pin);
|
||||
else _xlPort0 &= ~(1 << pin);
|
||||
xl9555_writeReg(XL9555_REG_OUTPUT_0, _xlPort0);
|
||||
} else if (pin < 16) {
|
||||
// Port 1 (subtract 8 for bit position)
|
||||
uint8_t bit = pin - 8;
|
||||
if (value) _xlPort1 |= (1 << bit);
|
||||
else _xlPort1 &= ~(1 << bit);
|
||||
xl9555_writeReg(XL9555_REG_OUTPUT_1, _xlPort1);
|
||||
}
|
||||
}
|
||||
|
||||
bool TDeckProMaxBoard::xl9555_digitalRead(uint8_t pin) const {
|
||||
if (pin < 8) return (_xlPort0 >> pin) & 1;
|
||||
if (pin < 16) return (_xlPort1 >> (pin - 8)) & 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
void TDeckProMaxBoard::xl9555_writePort0(uint8_t val) {
|
||||
_xlPort0 = val;
|
||||
if (_xlReady) xl9555_writeReg(XL9555_REG_OUTPUT_0, val);
|
||||
}
|
||||
|
||||
void TDeckProMaxBoard::xl9555_writePort1(uint8_t val) {
|
||||
_xlPort1 = val;
|
||||
if (_xlReady) xl9555_writeReg(XL9555_REG_OUTPUT_1, val);
|
||||
}
|
||||
|
||||
|
||||
// =============================================================================
|
||||
// High-level peripheral control
|
||||
// =============================================================================
|
||||
|
||||
// ---- Modem (A7682E) ----
|
||||
|
||||
void TDeckProMaxBoard::modemPowerOn() {
|
||||
MESH_DEBUG_PRINTLN(" XL9555: Modem power ON (6609_EN HIGH)");
|
||||
xl9555_digitalWrite(XL_PIN_6609_EN, HIGH);
|
||||
delay(100); // Allow SGM6609 boost to stabilise
|
||||
}
|
||||
|
||||
void TDeckProMaxBoard::modemPowerOff() {
|
||||
MESH_DEBUG_PRINTLN(" XL9555: Modem power OFF (6609_EN LOW)");
|
||||
xl9555_digitalWrite(XL_PIN_6609_EN, LOW);
|
||||
}
|
||||
|
||||
void TDeckProMaxBoard::modemPwrkeyPulse() {
|
||||
// A7682E power-on sequence: pulse PWRKEY LOW for >= 500ms
|
||||
// (Some datasheets say pull HIGH then LOW; LilyGo factory sets HIGH then toggles.)
|
||||
MESH_DEBUG_PRINTLN(" XL9555: Modem PWRKEY pulse");
|
||||
xl9555_digitalWrite(XL_PIN_PWRKEY_EN, HIGH);
|
||||
delay(100);
|
||||
xl9555_digitalWrite(XL_PIN_PWRKEY_EN, LOW);
|
||||
delay(1200);
|
||||
xl9555_digitalWrite(XL_PIN_PWRKEY_EN, HIGH);
|
||||
}
|
||||
|
||||
// ---- Audio output selection ----
|
||||
|
||||
void TDeckProMaxBoard::selectAudioES8311() {
|
||||
MESH_DEBUG_PRINTLN(" XL9555: Audio select → ES8311");
|
||||
xl9555_digitalWrite(XL_PIN_AUDIO_SEL, LOW);
|
||||
}
|
||||
|
||||
void TDeckProMaxBoard::selectAudioModem() {
|
||||
MESH_DEBUG_PRINTLN(" XL9555: Audio select → A7682E");
|
||||
xl9555_digitalWrite(XL_PIN_AUDIO_SEL, HIGH);
|
||||
}
|
||||
|
||||
void TDeckProMaxBoard::amplifierEnable() {
|
||||
xl9555_digitalWrite(XL_PIN_AMPLIFIER, HIGH);
|
||||
}
|
||||
|
||||
void TDeckProMaxBoard::amplifierDisable() {
|
||||
xl9555_digitalWrite(XL_PIN_AMPLIFIER, LOW);
|
||||
}
|
||||
|
||||
// ---- LoRa antenna selection ----
|
||||
|
||||
void TDeckProMaxBoard::loraAntennaInternal() {
|
||||
MESH_DEBUG_PRINTLN(" XL9555: LoRa antenna → internal");
|
||||
xl9555_digitalWrite(XL_PIN_LORA_SEL, HIGH);
|
||||
}
|
||||
|
||||
void TDeckProMaxBoard::loraAntennaExternal() {
|
||||
MESH_DEBUG_PRINTLN(" XL9555: LoRa antenna → external");
|
||||
xl9555_digitalWrite(XL_PIN_LORA_SEL, LOW);
|
||||
}
|
||||
|
||||
// ---- Motor (DRV2605) ----
|
||||
|
||||
void TDeckProMaxBoard::motorEnable() {
|
||||
xl9555_digitalWrite(XL_PIN_MOTOR_EN, HIGH);
|
||||
}
|
||||
|
||||
void TDeckProMaxBoard::motorDisable() {
|
||||
xl9555_digitalWrite(XL_PIN_MOTOR_EN, LOW);
|
||||
}
|
||||
|
||||
// ---- Touch reset ----
|
||||
|
||||
void TDeckProMaxBoard::touchReset() {
|
||||
if (!_xlReady) return;
|
||||
MESH_DEBUG_PRINTLN(" XL9555: Touch reset pulse");
|
||||
xl9555_digitalWrite(XL_PIN_TOUCH_RST, LOW);
|
||||
delay(20);
|
||||
xl9555_digitalWrite(XL_PIN_TOUCH_RST, HIGH);
|
||||
delay(50); // Allow touch controller to come out of reset
|
||||
}
|
||||
|
||||
// ---- Keyboard reset ----
|
||||
|
||||
void TDeckProMaxBoard::keyboardReset() {
|
||||
if (!_xlReady) return;
|
||||
MESH_DEBUG_PRINTLN(" XL9555: Keyboard reset pulse");
|
||||
xl9555_digitalWrite(XL_PIN_KEY_RST, LOW);
|
||||
delay(20);
|
||||
xl9555_digitalWrite(XL_PIN_KEY_RST, HIGH);
|
||||
delay(50);
|
||||
}
|
||||
|
||||
// ---- GPS power ----
|
||||
|
||||
void TDeckProMaxBoard::gpsPowerOn() {
|
||||
xl9555_digitalWrite(XL_PIN_GPS_EN, HIGH);
|
||||
delay(100);
|
||||
}
|
||||
|
||||
void TDeckProMaxBoard::gpsPowerOff() {
|
||||
xl9555_digitalWrite(XL_PIN_GPS_EN, LOW);
|
||||
}
|
||||
|
||||
// ---- LoRa power ----
|
||||
|
||||
void TDeckProMaxBoard::loraPowerOn() {
|
||||
xl9555_digitalWrite(XL_PIN_LORA_EN, HIGH);
|
||||
delay(10);
|
||||
}
|
||||
|
||||
void TDeckProMaxBoard::loraPowerOff() {
|
||||
xl9555_digitalWrite(XL_PIN_LORA_EN, LOW);
|
||||
}
|
||||
|
||||
// ---- E-ink backlight (working on MAX!) ----
|
||||
|
||||
void TDeckProMaxBoard::backlightOn() {
|
||||
#ifdef PIN_EINK_BL
|
||||
ledcWrite(EINK_BL_LEDC_CHANNEL, 255);
|
||||
#endif
|
||||
}
|
||||
|
||||
void TDeckProMaxBoard::backlightOff() {
|
||||
#ifdef PIN_EINK_BL
|
||||
ledcWrite(EINK_BL_LEDC_CHANNEL, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void TDeckProMaxBoard::backlightSetBrightness(uint8_t duty) {
|
||||
#ifdef PIN_EINK_BL
|
||||
ledcWrite(EINK_BL_LEDC_CHANNEL, duty);
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
#pragma once
|
||||
|
||||
// =============================================================================
|
||||
// TDeckProMaxBoard — Board support for LilyGo T-Deck Pro MAX V0.1
|
||||
//
|
||||
// Extends TDeckBoard (which provides all BQ27220 fuel gauge methods) with:
|
||||
// - XL9555 I/O expander initialisation and control
|
||||
// - XL9555-routed peripheral power management
|
||||
// - Touch/keyboard reset via XL9555
|
||||
// - Modem power/PWRKEY via XL9555
|
||||
// - LoRa antenna selection via XL9555
|
||||
// - Audio output mux (ES8311 vs A7682E) via XL9555
|
||||
// - Speaker amplifier enable via XL9555
|
||||
//
|
||||
// The XL9555 must be initialised before LoRa, GPS, modem, or touch are used.
|
||||
// All power enables, resets, and switches go through I2C — not direct GPIO.
|
||||
// =============================================================================
|
||||
|
||||
#include "variant.h"
|
||||
#include "TDeckBoard.h" // Inherits BQ27220 fuel gauge, deep sleep, power management
|
||||
|
||||
class TDeckProMaxBoard : public TDeckBoard {
|
||||
public:
|
||||
void begin();
|
||||
|
||||
const char* getManufacturerName() const {
|
||||
return "LilyGo T-Deck Pro MAX";
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XL9555 I/O Expander — lightweight inline driver
|
||||
//
|
||||
// The XL9555 has 16 I/O pins across two 8-bit ports.
|
||||
// Pin 0-7 = Port 0, Pin 8-15 = Port 1.
|
||||
// We shadow the output state in _xlPort0/_xlPort1 to allow
|
||||
// single-bit set/clear without read-modify-write over I2C.
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
// Initialise XL9555: set all used pins as outputs, apply boot defaults.
|
||||
// Returns true if I2C communication with XL9555 succeeded.
|
||||
bool xl9555_init();
|
||||
|
||||
// Set a single XL9555 pin HIGH or LOW (pin 0-15).
|
||||
void xl9555_digitalWrite(uint8_t pin, bool value);
|
||||
|
||||
// Read the current output state of a pin (from shadow, not I2C read).
|
||||
bool xl9555_digitalRead(uint8_t pin) const;
|
||||
|
||||
// Write raw port values (for batch updates).
|
||||
void xl9555_writePort0(uint8_t val);
|
||||
void xl9555_writePort1(uint8_t val);
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// High-level peripheral control (delegates to XL9555)
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
// Modem (A7682E) power control
|
||||
void modemPowerOn(); // Enable SGM6609 boost (6609_EN HIGH)
|
||||
void modemPowerOff(); // Disable SGM6609 boost (6609_EN LOW)
|
||||
void modemPwrkeyPulse(); // Toggle PWRKEY: HIGH 100ms → LOW 1200ms → HIGH
|
||||
|
||||
// Audio output selection
|
||||
void selectAudioES8311(); // AUDIO_SEL LOW → ES8311 output to speaker/headphones
|
||||
void selectAudioModem(); // AUDIO_SEL HIGH → A7682E output to speaker/headphones
|
||||
void amplifierEnable(); // NS4150B amplifier ON (louder speaker)
|
||||
void amplifierDisable(); // NS4150B amplifier OFF (saves power)
|
||||
|
||||
// LoRa antenna selection (SKY13453 RF switch)
|
||||
void loraAntennaInternal(); // LORA_SEL HIGH → internal PCB antenna (default)
|
||||
void loraAntennaExternal(); // LORA_SEL LOW → external IPEX antenna
|
||||
|
||||
// Motor (DRV2605) power
|
||||
void motorEnable(); // MOTOR_EN HIGH
|
||||
void motorDisable(); // MOTOR_EN LOW
|
||||
|
||||
// Touch controller reset via XL9555
|
||||
void touchReset(); // Pulse TOUCH_RST: LOW 20ms → HIGH, then 50ms settle
|
||||
|
||||
// Keyboard reset via XL9555
|
||||
void keyboardReset(); // Pulse KEY_RST: LOW 20ms → HIGH, then 50ms settle
|
||||
|
||||
// GPS power control via XL9555
|
||||
void gpsPowerOn(); // GPS_EN HIGH
|
||||
void gpsPowerOff(); // GPS_EN LOW
|
||||
|
||||
// LoRa power control via XL9555
|
||||
void loraPowerOn(); // LORA_EN HIGH
|
||||
void loraPowerOff(); // LORA_EN LOW
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// E-ink front-light control
|
||||
// On MAX, IO41 has a working backlight circuit (boost converter + LEDs).
|
||||
// PWM control for brightness is possible via ledc.
|
||||
// -------------------------------------------------------------------------
|
||||
void backlightOn();
|
||||
void backlightOff();
|
||||
void backlightSetBrightness(uint8_t duty); // 0-255, via LEDC PWM
|
||||
|
||||
private:
|
||||
// Shadow registers for XL9555 output ports (avoid I2C read-modify-write)
|
||||
uint8_t _xlPort0 = XL9555_BOOT_PORT0;
|
||||
uint8_t _xlPort1 = XL9555_BOOT_PORT1;
|
||||
bool _xlReady = false;
|
||||
|
||||
// Low-level I2C helpers
|
||||
bool xl9555_writeReg(uint8_t reg, uint8_t val);
|
||||
uint8_t xl9555_readReg(uint8_t reg);
|
||||
};
|
||||
@@ -0,0 +1,360 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
|
||||
// TCA8418 Register addresses
|
||||
#define TCA8418_REG_CFG 0x01
|
||||
#define TCA8418_REG_INT_STAT 0x02
|
||||
#define TCA8418_REG_KEY_LCK_EC 0x03
|
||||
#define TCA8418_REG_KEY_EVENT_A 0x04
|
||||
#define TCA8418_REG_KP_GPIO1 0x1D
|
||||
#define TCA8418_REG_KP_GPIO2 0x1E
|
||||
#define TCA8418_REG_KP_GPIO3 0x1F
|
||||
#define TCA8418_REG_DEBOUNCE 0x29
|
||||
#define TCA8418_REG_GPI_EM1 0x20
|
||||
#define TCA8418_REG_GPI_EM2 0x21
|
||||
#define TCA8418_REG_GPI_EM3 0x22
|
||||
|
||||
// Key codes for special keys
|
||||
#define KB_KEY_NONE 0
|
||||
#define KB_KEY_BACKSPACE '\b'
|
||||
#define KB_KEY_ENTER '\r'
|
||||
#define KB_KEY_SPACE ' '
|
||||
#define KB_KEY_EMOJI 0x01 // Non-printable code for $ key (emoji picker)
|
||||
#define KB_KEY_BACKLIGHT 0x02 // Non-printable code for Alt+B (backlight toggle, MAX only)
|
||||
|
||||
class TCA8418Keyboard {
|
||||
private:
|
||||
uint8_t _addr;
|
||||
TwoWire* _wire;
|
||||
bool _initialized;
|
||||
bool _shiftActive; // Sticky shift (one-shot or held)
|
||||
bool _shiftConsumed; // Was shift active for the last returned key
|
||||
bool _shiftHeld; // Shift key physically held down
|
||||
bool _shiftUsedWhileHeld; // Was shift consumed by any key while held
|
||||
bool _altActive; // Sticky alt (one-shot)
|
||||
bool _symActive; // Sticky sym (one-shot)
|
||||
unsigned long _lastShiftTime; // For Shift+key combos
|
||||
|
||||
uint8_t readReg(uint8_t reg) {
|
||||
_wire->beginTransmission(_addr);
|
||||
_wire->write(reg);
|
||||
_wire->endTransmission();
|
||||
_wire->requestFrom(_addr, (uint8_t)1);
|
||||
return _wire->available() ? _wire->read() : 0;
|
||||
}
|
||||
|
||||
void writeReg(uint8_t reg, uint8_t val) {
|
||||
_wire->beginTransmission(_addr);
|
||||
_wire->write(reg);
|
||||
_wire->write(val);
|
||||
_wire->endTransmission();
|
||||
}
|
||||
|
||||
// Map raw key codes to characters (from working reader firmware)
|
||||
char getKeyChar(uint8_t keyCode) {
|
||||
switch (keyCode) {
|
||||
// Row 1 - QWERTYUIOP
|
||||
case 10: return 'q'; // Q (was 97 on different hardware)
|
||||
case 9: return 'w';
|
||||
case 8: return 'e';
|
||||
case 7: return 'r';
|
||||
case 6: return 't';
|
||||
case 5: return 'y';
|
||||
case 4: return 'u';
|
||||
case 3: return 'i';
|
||||
case 2: return 'o';
|
||||
case 1: return 'p';
|
||||
|
||||
// Row 2 - ASDFGHJKL + Backspace
|
||||
case 20: return 'a'; // A (was 98 on different hardware)
|
||||
case 19: return 's';
|
||||
case 18: return 'd';
|
||||
case 17: return 'f';
|
||||
case 16: return 'g';
|
||||
case 15: return 'h';
|
||||
case 14: return 'j';
|
||||
case 13: return 'k';
|
||||
case 12: return 'l';
|
||||
case 11: return '\b'; // Backspace
|
||||
|
||||
// Row 3 - Alt ZXCVBNM Sym Enter
|
||||
case 30: return 0; // Alt - handled separately
|
||||
case 29: return 'z';
|
||||
case 28: return 'x';
|
||||
case 27: return 'c';
|
||||
case 26: return 'v';
|
||||
case 25: return 'b';
|
||||
case 24: return 'n';
|
||||
case 23: return 'm';
|
||||
case 22: return 0; // Symbol key - handled separately
|
||||
case 21: return '\r'; // Enter
|
||||
|
||||
// Row 4 - Shift Mic Space Sym Shift
|
||||
case 35: return 0; // Left shift - handled separately
|
||||
case 34: return 0; // Mic
|
||||
case 33: return ' '; // Space
|
||||
case 32: return 0; // Sym - handled separately
|
||||
case 31: return 0; // Right shift - handled separately
|
||||
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Map key with Alt modifier - same as Sym for this keyboard
|
||||
char getAltChar(uint8_t keyCode) {
|
||||
return getSymChar(keyCode); // Alt does same as Sym
|
||||
}
|
||||
|
||||
// Map key with Sym modifier - based on actual T-Deck Pro keyboard silk-screen
|
||||
char getSymChar(uint8_t keyCode) {
|
||||
switch (keyCode) {
|
||||
// Row 1: Q W E R T Y U I O P
|
||||
case 10: return '#'; // Q -> #
|
||||
case 9: return '1'; // W -> 1
|
||||
case 8: return '2'; // E -> 2
|
||||
case 7: return '3'; // R -> 3
|
||||
case 6: return '('; // T -> (
|
||||
case 5: return ')'; // Y -> )
|
||||
case 4: return '_'; // U -> _
|
||||
case 3: return '-'; // I -> -
|
||||
case 2: return '+'; // O -> +
|
||||
case 1: return '@'; // P -> @
|
||||
|
||||
// Row 2: A S D F G H J K L
|
||||
case 20: return '*'; // A -> *
|
||||
case 19: return '4'; // S -> 4
|
||||
case 18: return '5'; // D -> 5
|
||||
case 17: return '6'; // F -> 6
|
||||
case 16: return '/'; // G -> /
|
||||
case 15: return ':'; // H -> :
|
||||
case 14: return ';'; // J -> ;
|
||||
case 13: return '\''; // K -> '
|
||||
case 12: return '"'; // L -> "
|
||||
|
||||
// Row 3: Z X C V B N M
|
||||
case 29: return '7'; // Z -> 7
|
||||
case 28: return '8'; // X -> 8
|
||||
case 27: return '9'; // C -> 9
|
||||
case 26: return '?'; // V -> ?
|
||||
case 25: return '!'; // B -> !
|
||||
case 24: return ','; // N -> ,
|
||||
case 23: return '.'; // M -> .
|
||||
|
||||
// Row 4: Mic key -> 0
|
||||
case 34: return '0'; // Mic -> 0
|
||||
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
TCA8418Keyboard(uint8_t addr = 0x34, TwoWire* wire = &Wire)
|
||||
: _addr(addr), _wire(wire), _initialized(false),
|
||||
_shiftActive(false), _shiftConsumed(false), _shiftHeld(false), _shiftUsedWhileHeld(false), _altActive(false), _symActive(false), _lastShiftTime(0) {}
|
||||
|
||||
bool begin() {
|
||||
// Check if device responds
|
||||
_wire->beginTransmission(_addr);
|
||||
if (_wire->endTransmission() != 0) {
|
||||
Serial.println("TCA8418: Device not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
// --- Warm-reboot safe init sequence ---
|
||||
// The TCA8418 stays powered across ESP32 resets (no dedicated RST pin),
|
||||
// so the scanner may still be active from the previous session.
|
||||
// We must disable it before reconfiguring the matrix.
|
||||
|
||||
// 1. Disable scanner — stop all scanning before touching config
|
||||
writeReg(TCA8418_REG_CFG, 0x00);
|
||||
|
||||
// 2. Drain any stale events from the previous session
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if ((readReg(TCA8418_REG_KEY_LCK_EC) & 0x0F) == 0) break;
|
||||
readReg(TCA8418_REG_KEY_EVENT_A);
|
||||
}
|
||||
writeReg(TCA8418_REG_INT_STAT, 0x1F); // Clear all interrupt flags
|
||||
|
||||
// 3. Explicitly clear GPI event masks (prevent phantom GPI events)
|
||||
writeReg(TCA8418_REG_GPI_EM1, 0x00);
|
||||
writeReg(TCA8418_REG_GPI_EM2, 0x00);
|
||||
writeReg(TCA8418_REG_GPI_EM3, 0x00);
|
||||
|
||||
// 4. Configure keyboard matrix (8 rows x 10 cols)
|
||||
writeReg(TCA8418_REG_KP_GPIO1, 0xFF); // Rows 0-7 as keypad
|
||||
writeReg(TCA8418_REG_KP_GPIO2, 0xFF); // Cols 0-7 as keypad
|
||||
writeReg(TCA8418_REG_KP_GPIO3, 0x03); // Cols 8-9 as keypad
|
||||
|
||||
// 5. Set debounce
|
||||
writeReg(TCA8418_REG_DEBOUNCE, 0x03);
|
||||
|
||||
// 6. Final pre-enable cleanup
|
||||
writeReg(TCA8418_REG_INT_STAT, 0x1F);
|
||||
|
||||
// 7. Enable scanner — matrix config is stable, safe to start scanning
|
||||
writeReg(TCA8418_REG_CFG, 0x11); // KE_IEN + INT_CFG
|
||||
|
||||
// 8. Let scanner stabilise, then flush any spurious first-scan events
|
||||
delay(5);
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if ((readReg(TCA8418_REG_KEY_LCK_EC) & 0x0F) == 0) break;
|
||||
readReg(TCA8418_REG_KEY_EVENT_A);
|
||||
}
|
||||
writeReg(TCA8418_REG_INT_STAT, 0x1F);
|
||||
|
||||
_initialized = true;
|
||||
Serial.println("TCA8418: Keyboard initialized OK");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Read a key press - returns character or 0 if no key
|
||||
char readKey() {
|
||||
if (!_initialized) return 0;
|
||||
|
||||
// Check for key events in FIFO
|
||||
uint8_t keyCount = readReg(TCA8418_REG_KEY_LCK_EC) & 0x0F;
|
||||
if (keyCount == 0) return 0;
|
||||
|
||||
// Read key event from FIFO
|
||||
uint8_t keyEvent = readReg(TCA8418_REG_KEY_EVENT_A);
|
||||
|
||||
// Bit 7: 1 = press, 0 = release
|
||||
bool pressed = (keyEvent & 0x80) != 0;
|
||||
uint8_t keyCode = keyEvent & 0x7F;
|
||||
|
||||
// Clear interrupt
|
||||
writeReg(TCA8418_REG_INT_STAT, 0x1F);
|
||||
|
||||
Serial.printf("KB raw: event=0x%02X code=%d pressed=%d count=%d\n",
|
||||
keyEvent, keyCode, pressed, keyCount);
|
||||
|
||||
// Track shift release (before the general release-ignore)
|
||||
if (!pressed && (keyCode == 35 || keyCode == 31)) {
|
||||
_shiftHeld = false;
|
||||
// If shift was used while held (e.g. cursor nav), clear it completely
|
||||
// so the next bare keypress isn't treated as shifted.
|
||||
// If shift was NOT used (tap-then-release), keep _shiftActive for one-shot.
|
||||
if (_shiftUsedWhileHeld) {
|
||||
_shiftActive = false;
|
||||
}
|
||||
_shiftUsedWhileHeld = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Only act on key press, not release
|
||||
if (!pressed || keyCode == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Handle modifier keys - set sticky state and return 0
|
||||
if (keyCode == 35 || keyCode == 31) { // Shift keys
|
||||
_shiftActive = true;
|
||||
_shiftHeld = true;
|
||||
_shiftUsedWhileHeld = false;
|
||||
_lastShiftTime = millis();
|
||||
Serial.println("KB: Shift activated");
|
||||
return 0;
|
||||
}
|
||||
if (keyCode == 30) { // Alt key
|
||||
_altActive = true;
|
||||
Serial.println("KB: Alt activated");
|
||||
return 0;
|
||||
}
|
||||
if (keyCode == 32) { // Sym key (bottom row)
|
||||
_symActive = true;
|
||||
Serial.println("KB: Sym activated");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Handle dedicated $ key (key code 22, next to M)
|
||||
// Bare press = emoji picker, Sym+$ = literal '$'
|
||||
if (keyCode == 22) {
|
||||
if (_symActive) {
|
||||
_symActive = false;
|
||||
Serial.println("KB: Sym+$ -> '$'");
|
||||
return '$';
|
||||
}
|
||||
Serial.println("KB: $ key -> emoji");
|
||||
return KB_KEY_EMOJI;
|
||||
}
|
||||
|
||||
// Handle Mic key - always produces '0' (silk-screened on key)
|
||||
// Sym+Mic also produces '0' (consumes sym so it doesn't leak)
|
||||
if (keyCode == 34) {
|
||||
_symActive = false;
|
||||
Serial.println("KB: Mic -> '0'");
|
||||
return '0';
|
||||
}
|
||||
|
||||
// Get the character
|
||||
char c = 0;
|
||||
|
||||
// Alt+B -> backlight toggle (T-Deck Pro MAX only — working front-light on IO41)
|
||||
if (_altActive && keyCode == 25) { // keyCode 25 = B
|
||||
_altActive = false;
|
||||
Serial.println("KB: Alt+B -> backlight toggle");
|
||||
return KB_KEY_BACKLIGHT;
|
||||
}
|
||||
|
||||
if (_altActive) {
|
||||
c = getAltChar(keyCode);
|
||||
_altActive = false; // Reset sticky alt
|
||||
if (c != 0) {
|
||||
Serial.printf("KB: Alt+key -> '%c'\n", c);
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
if (_symActive) {
|
||||
c = getSymChar(keyCode);
|
||||
_symActive = false; // Reset sticky sym
|
||||
if (c != 0) {
|
||||
Serial.printf("KB: Sym+key -> '%c'\n", c);
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
c = getKeyChar(keyCode);
|
||||
|
||||
if (c != 0 && _shiftActive) {
|
||||
// Apply shift - uppercase letters
|
||||
if (c >= 'a' && c <= 'z') {
|
||||
c = c - 'a' + 'A';
|
||||
}
|
||||
// Track that shift was used while physically held
|
||||
if (_shiftHeld) {
|
||||
_shiftUsedWhileHeld = true;
|
||||
}
|
||||
// Only clear shift if it's one-shot (tap), not held down
|
||||
if (!_shiftHeld) {
|
||||
_shiftActive = false;
|
||||
}
|
||||
_shiftConsumed = true; // Record that shift was active for this key
|
||||
} else {
|
||||
_shiftConsumed = false;
|
||||
}
|
||||
|
||||
if (c != 0) {
|
||||
Serial.printf("KB: code %d -> '%c' (0x%02X)\n", keyCode, c >= 32 ? c : '?', c);
|
||||
} else {
|
||||
Serial.printf("KB: code %d -> UNMAPPED\n", keyCode);
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
bool isReady() const { return _initialized; }
|
||||
|
||||
// Check if shift was pressed within the last N milliseconds
|
||||
bool wasShiftRecentlyPressed(unsigned long withinMs = 500) const {
|
||||
return (millis() - _lastShiftTime) < withinMs;
|
||||
}
|
||||
|
||||
// Check if shift was active when the most recent key was produced
|
||||
// (immune to e-ink refresh timing unlike wasShiftRecentlyPressed)
|
||||
bool wasShiftConsumed() const {
|
||||
return _shiftConsumed;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,232 @@
|
||||
; =============================================================================
|
||||
; T-Deck Pro MAX V0.1 — Meck Build Environments
|
||||
;
|
||||
; Hardware: ESP32-S3 + XL9555 I/O expander + combined 4G (A7682E) + Audio (ES8311)
|
||||
;
|
||||
; Key differences from LilyGo_TDeck_Pro (V1.1):
|
||||
; - Peripheral power controlled via XL9555 (not direct GPIO)
|
||||
; - 4G modem and ES8311 audio coexist (no longer mutually exclusive)
|
||||
; - ES8311 I2C codec replaces PCM5102A (different I2S pins, needs I2C config)
|
||||
; - Several GPIO reassignments (see variant.h for full map)
|
||||
; - 1500 mAh battery (was 1400)
|
||||
; - Working e-ink front-light on IO41
|
||||
;
|
||||
; WHAT WORKS OUT OF THE BOX:
|
||||
; LoRa mesh, keyboard, e-ink display, GPS, touchscreen, battery management,
|
||||
; SD card, text reader, notes, contacts, channels, settings, discovery,
|
||||
; last heard, repeater admin, web reader (WiFi builds), OTA update.
|
||||
;
|
||||
; NEEDS ADAPTATION (future work):
|
||||
; - HAS_4G_MODEM: ModemManager uses direct GPIO for MODEM_POWER_EN/PWRKEY
|
||||
; which are XL9555-routed on MAX. Needs board.modemPowerOn() etc.
|
||||
; - MECK_AUDIO_VARIANT: ES8311 needs I2C codec init (PCM5102A didn't).
|
||||
; I2S pins are different. AudiobookPlayerScreen needs ES8311 driver.
|
||||
; - Combined 4G+audio: existing #ifdef guards treat them as mutually
|
||||
; exclusive. Needs restructuring for coexistence.
|
||||
; =============================================================================
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Base environment for T-Deck Pro MAX
|
||||
; ---------------------------------------------------------------------------
|
||||
[LilyGo_TDeck_Pro_Max]
|
||||
extends = esp32_base
|
||||
extra_scripts = post:merge_firmware.py
|
||||
board = t-deck_pro_max
|
||||
board_build.flash_mode = qio
|
||||
board_build.f_flash = 80000000L
|
||||
board_build.arduino.memory_type = qio_qspi
|
||||
board_upload.flash_size = 16MB
|
||||
build_flags =
|
||||
${esp32_base.build_flags}
|
||||
${sensor_base.build_flags}
|
||||
; Include MAX variant first (for variant.h, target.h, TDeckProMaxBoard.h)
|
||||
; then V1.1 variant (for TDeckBoard.h, which TDeckProMaxBoard inherits from)
|
||||
-I variants/LilyGo_TDeck_Pro_Max
|
||||
-I variants/LilyGo_TDeck_Pro
|
||||
; Both defines needed: LilyGo_TDeck_Pro for existing UI code guards,
|
||||
; LilyGo_TDeck_Pro_Max for MAX-specific code paths
|
||||
-D LilyGo_TDeck_Pro
|
||||
-D LilyGo_TDeck_Pro_Max
|
||||
-D HAS_XL9555=1
|
||||
-D HAS_GPS=1
|
||||
-D BOARD_HAS_PSRAM=1
|
||||
-D CORE_DEBUG_LEVEL=1
|
||||
-D FORMAT_SPIFFS_IF_FAILED=1
|
||||
-D FORMAT_LITTLEFS_IF_FAILED=1
|
||||
-D ARDUINO_USB_CDC_ON_BOOT=1
|
||||
-D RADIO_CLASS=CustomSX1262
|
||||
-D WRAPPER_CLASS=CustomSX1262Wrapper
|
||||
-D LORA_TX_POWER=22
|
||||
-D SX126X_DIO2_AS_RF_SWITCH
|
||||
-D SX126X_CURRENT_LIMIT=140
|
||||
-D SX126X_RX_BOOSTED_GAIN=1
|
||||
-D SX126X_DIO3_TCXO_VOLTAGE=2.4f
|
||||
; LoRa SPI pins (direct GPIO — unchanged from V1.1)
|
||||
-D P_LORA_DIO_1=5
|
||||
-D P_LORA_NSS=3
|
||||
-D P_LORA_RESET=4
|
||||
-D P_LORA_BUSY=6
|
||||
-D P_LORA_SCLK=36
|
||||
-D P_LORA_MISO=47
|
||||
-D P_LORA_MOSI=33
|
||||
; P_LORA_EN deliberately NOT defined — LoRa power via XL9555 in board.begin()
|
||||
; GPS pins (direct GPIO — changed from V1.1!)
|
||||
-D ENV_INCLUDE_GPS=1
|
||||
-D ENV_SKIP_GPS_DETECT=1
|
||||
-D PIN_GPS_RX=2
|
||||
-D PIN_GPS_TX=16
|
||||
-D GPS_BAUD_RATE=38400
|
||||
; Sensor exclusions (same as V1.1)
|
||||
-D ENV_INCLUDE_AHTX0=0
|
||||
-D ENV_INCLUDE_BME280=0
|
||||
-D ENV_INCLUDE_BMP280=0
|
||||
-D ENV_INCLUDE_SHTC3=0
|
||||
-D ENV_INCLUDE_SHT4X=0
|
||||
-D ENV_INCLUDE_LPS22HB=0
|
||||
-D ENV_INCLUDE_INA3221=0
|
||||
-D ENV_INCLUDE_INA219=0
|
||||
-D ENV_INCLUDE_INA226=0
|
||||
-D ENV_INCLUDE_INA260=0
|
||||
-D ENV_INCLUDE_MLX90614=0
|
||||
-D ENV_INCLUDE_VL53L0X=0
|
||||
-D ENV_INCLUDE_BME680=0
|
||||
-D ENV_INCLUDE_BMP085=0
|
||||
; E-ink display (pin changes from V1.1: RST=9, BL=41)
|
||||
-D USE_EINK
|
||||
-D DISPLAY_CLASS=GxEPDDisplay
|
||||
-D EINK_DISPLAY_MODEL=GxEPD2_310_GDEQ031T10
|
||||
-D EINK_WIDTH=240
|
||||
-D EINK_HEIGHT=320
|
||||
-D EINK_CS=34
|
||||
-D EINK_DC=35
|
||||
-D EINK_RST=9
|
||||
-D EINK_BUSY=37
|
||||
-D EINK_SCLK=36
|
||||
-D EINK_MOSI=33
|
||||
-D EINK_BL=41
|
||||
-D EINK_NOT_HIBERNATE=1
|
||||
; Battery (1500 mAh on MAX, was 1400 on V1.1)
|
||||
-D HAS_BQ27220=1
|
||||
-D AUTO_SHUTDOWN_MILLIVOLTS=2800
|
||||
; Display rendering parameters
|
||||
-D EINK_LIMIT_FASTREFRESH=10
|
||||
-D EINK_LIMIT_GHOSTING_PX=2000
|
||||
-D DISPLAY_ROTATION=0
|
||||
-D EINK_ROTATION=0
|
||||
-D EINK_SCALE_X=1.875f
|
||||
-D EINK_SCALE_Y=2.5f
|
||||
-D EINK_X_OFFSET=0
|
||||
-D EINK_Y_OFFSET=5
|
||||
; Legacy display pin aliases (for GxEPDDisplay.cpp)
|
||||
-D PIN_DISPLAY_CS=34
|
||||
-D PIN_DISPLAY_DC=35
|
||||
-D PIN_DISPLAY_RST=9
|
||||
-D PIN_DISPLAY_BUSY=37
|
||||
-D PIN_DISPLAY_SCLK=36
|
||||
-D PIN_DISPLAY_MISO=-1
|
||||
-D PIN_DISPLAY_MOSI=33
|
||||
-D PIN_DISPLAY_BL=41
|
||||
-D PIN_USER_BTN=0
|
||||
; Touch (INT is direct GPIO; RST is XL9555, handled by board class)
|
||||
-D HAS_TOUCHSCREEN=1
|
||||
-D CST328_PIN_INT=12
|
||||
-D CST328_PIN_RST=-1
|
||||
-D ARDUINO_LOOP_STACK_SIZE=32768
|
||||
build_src_filter = ${esp32_base.build_src_filter}
|
||||
; Include TDeckBoard.cpp from V1.1 (parent class with BQ27220 code)
|
||||
+<../variants/LilyGo_TDeck_Pro/TDeckBoard.cpp>
|
||||
; Include MAX variant (target.cpp + TDeckProMaxBoard.cpp)
|
||||
+<../variants/LilyGo_TDeck_Pro_Max>
|
||||
+<helpers/sensors/*.cpp>
|
||||
lib_deps =
|
||||
${esp32_base.lib_deps}
|
||||
${sensor_base.lib_deps}
|
||||
zinggjm/GxEPD2@^1.5.9
|
||||
adafruit/Adafruit GFX Library@^1.11.0
|
||||
bitbank2/PNGdec@^1.0.1
|
||||
WebServer
|
||||
Update
|
||||
|
||||
|
||||
; ===========================================================================
|
||||
; Meck MAX builds — LoRa mesh works out of the box on all variants.
|
||||
; 4G modem and ES8311 audio need adaptation before they can be enabled.
|
||||
; ===========================================================================
|
||||
|
||||
; MAX + BLE companion (standard BLE phone bridging)
|
||||
; Both 4G + audio hardware present but not yet enabled in firmware.
|
||||
; BLE_PIN_CODE limit: MAX_CONTACTS=500 (BLE protocol ceiling).
|
||||
[env:meck_max_ble]
|
||||
extends = LilyGo_TDeck_Pro_Max
|
||||
build_flags =
|
||||
${LilyGo_TDeck_Pro_Max.build_flags}
|
||||
-I examples/companion_radio/ui-new
|
||||
-D MAX_CONTACTS=500
|
||||
-D MAX_GROUP_CHANNELS=20
|
||||
-D BLE_PIN_CODE=123456
|
||||
-D OFFLINE_QUEUE_SIZE=256
|
||||
-D MECK_WEB_READER=1
|
||||
-D MECK_OTA_UPDATE=1
|
||||
-D FIRMWARE_VERSION='"Meck v1.3.MAX"'
|
||||
build_src_filter = ${LilyGo_TDeck_Pro_Max.build_src_filter}
|
||||
+<helpers/esp32/*.cpp>
|
||||
+<helpers/ui/MomentaryButton.cpp>
|
||||
+<../examples/companion_radio/*.cpp>
|
||||
+<../examples/companion_radio/ui-new/*.cpp>
|
||||
+<helpers/ui/GxEPDDisplay.cpp>
|
||||
lib_deps =
|
||||
${LilyGo_TDeck_Pro_Max.lib_deps}
|
||||
densaugeo/base64 @ ~1.4.0
|
||||
https://github.com/schreibfaul1/ESP32-audioI2S.git#2.0.6
|
||||
bitbank2/JPEGDEC
|
||||
|
||||
; MAX + WiFi companion (WiFi app bridging — no BLE, higher contact limit)
|
||||
; WiFi credentials loaded from SD card (/web/wifi.cfg).
|
||||
; Connect via MeshCore web app, meshcore.js, or Python CLI.
|
||||
[env:meck_max_wifi]
|
||||
extends = LilyGo_TDeck_Pro_Max
|
||||
build_flags =
|
||||
${LilyGo_TDeck_Pro_Max.build_flags}
|
||||
-I examples/companion_radio/ui-new
|
||||
-D MAX_CONTACTS=1500
|
||||
-D MAX_GROUP_CHANNELS=20
|
||||
-D MECK_WIFI_COMPANION=1
|
||||
-D TCP_PORT=5000
|
||||
-D WIFI_DEBUG_LOGGING=1
|
||||
-D OFFLINE_QUEUE_SIZE=256
|
||||
-D MECK_WEB_READER=1
|
||||
-D MECK_OTA_UPDATE=1
|
||||
-D FIRMWARE_VERSION='"Meck v1.3.MAX.WiFi"'
|
||||
build_src_filter = ${LilyGo_TDeck_Pro_Max.build_src_filter}
|
||||
+<helpers/esp32/*.cpp>
|
||||
+<helpers/ui/MomentaryButton.cpp>
|
||||
+<../examples/companion_radio/*.cpp>
|
||||
+<../examples/companion_radio/ui-new/*.cpp>
|
||||
+<helpers/ui/GxEPDDisplay.cpp>
|
||||
lib_deps =
|
||||
${LilyGo_TDeck_Pro_Max.lib_deps}
|
||||
densaugeo/base64 @ ~1.4.0
|
||||
https://github.com/schreibfaul1/ESP32-audioI2S.git#2.0.6
|
||||
bitbank2/JPEGDEC
|
||||
|
||||
; MAX standalone (no BLE/WiFi — maximum battery life, LoRa mesh only)
|
||||
; Contacts in PSRAM (1500 capacity). OTA enabled (WiFi AP on demand).
|
||||
[env:meck_max_standalone]
|
||||
extends = LilyGo_TDeck_Pro_Max
|
||||
build_flags =
|
||||
${LilyGo_TDeck_Pro_Max.build_flags}
|
||||
-I examples/companion_radio/ui-new
|
||||
-D MAX_CONTACTS=1500
|
||||
-D MAX_GROUP_CHANNELS=20
|
||||
-D OFFLINE_QUEUE_SIZE=1
|
||||
-D MECK_OTA_UPDATE=1
|
||||
-D FIRMWARE_VERSION='"Meck v1.3.MAX.SA"'
|
||||
build_src_filter = ${LilyGo_TDeck_Pro_Max.build_src_filter}
|
||||
+<helpers/esp32/*.cpp>
|
||||
+<helpers/ui/MomentaryButton.cpp>
|
||||
+<../examples/companion_radio/*.cpp>
|
||||
+<../examples/companion_radio/ui-new/*.cpp>
|
||||
+<helpers/ui/GxEPDDisplay.cpp>
|
||||
lib_deps =
|
||||
${LilyGo_TDeck_Pro_Max.lib_deps}
|
||||
densaugeo/base64 @ ~1.4.0
|
||||
@@ -0,0 +1,91 @@
|
||||
#include <Arduino.h>
|
||||
#include "variant.h"
|
||||
#include "target.h"
|
||||
|
||||
TDeckProMaxBoard board;
|
||||
|
||||
#if defined(P_LORA_SCLK)
|
||||
static SPIClass loraSpi(HSPI);
|
||||
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, loraSpi);
|
||||
#else
|
||||
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY);
|
||||
#endif
|
||||
|
||||
WRAPPER_CLASS radio_driver(radio, board);
|
||||
|
||||
ESP32RTCClock fallback_clock;
|
||||
AutoDiscoverRTCClock rtc_clock(fallback_clock);
|
||||
|
||||
#if HAS_GPS
|
||||
// Wrap Serial2 with a sentence counter so the UI can show NMEA throughput.
|
||||
// MicroNMEALocationProvider reads through this wrapper transparently.
|
||||
GPSStreamCounter gpsStream(Serial2);
|
||||
MicroNMEALocationProvider gps(gpsStream, &rtc_clock);
|
||||
EnvironmentSensorManager sensors(gps);
|
||||
#else
|
||||
SensorManager sensors;
|
||||
#endif
|
||||
|
||||
#ifdef DISPLAY_CLASS
|
||||
DISPLAY_CLASS display;
|
||||
MomentaryButton user_btn(PIN_USER_BTN, 1000, true);
|
||||
#endif
|
||||
|
||||
bool radio_init() {
|
||||
MESH_DEBUG_PRINTLN("radio_init() - starting");
|
||||
|
||||
// NOTE: board.begin() is called by main.cpp setup() before radio_init()
|
||||
// I2C is already initialized there with correct pins
|
||||
|
||||
fallback_clock.begin();
|
||||
MESH_DEBUG_PRINTLN("radio_init() - fallback_clock started");
|
||||
|
||||
// Wire already initialized in board.begin() - just use it for RTC
|
||||
rtc_clock.begin(Wire);
|
||||
MESH_DEBUG_PRINTLN("radio_init() - rtc_clock started");
|
||||
|
||||
#if defined(P_LORA_SCLK)
|
||||
MESH_DEBUG_PRINTLN("radio_init() - initializing LoRa SPI...");
|
||||
loraSpi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI, P_LORA_NSS);
|
||||
MESH_DEBUG_PRINTLN("radio_init() - SPI initialized, calling radio.std_init()...");
|
||||
bool result = radio.std_init(&loraSpi);
|
||||
MESH_DEBUG_PRINTLN("radio_init() - radio.std_init() returned: %s", result ? "SUCCESS" : "FAILED");
|
||||
return result;
|
||||
#else
|
||||
MESH_DEBUG_PRINTLN("radio_init() - calling radio.std_init() without custom SPI...");
|
||||
bool result = radio.std_init();
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t radio_get_rng_seed() {
|
||||
return radio.random(0x7FFFFFFF);
|
||||
}
|
||||
|
||||
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
|
||||
radio.setFrequency(freq);
|
||||
radio.setSpreadingFactor(sf);
|
||||
radio.setBandwidth(bw);
|
||||
radio.setCodingRate(cr);
|
||||
|
||||
// Longer preamble for low SF improves reliability — each symbol is shorter
|
||||
// at low SF, so more symbols are needed for reliable detection.
|
||||
// SF <= 8 gets 32 symbols (~65ms at SF7/62.5kHz); SF >= 9 keeps 16 (already ~131ms+).
|
||||
// See: https://github.com/meshcore-dev/MeshCore/pull/1954
|
||||
uint16_t preamble = (sf <= 8) ? 32 : 16;
|
||||
radio.setPreambleLength(preamble);
|
||||
MESH_DEBUG_PRINTLN("radio_set_params() - bw=%.1f sf=%u preamble=%u", bw, sf, preamble);
|
||||
}
|
||||
|
||||
void radio_set_tx_power(uint8_t dbm) {
|
||||
radio.setOutputPower(dbm);
|
||||
}
|
||||
|
||||
mesh::LocalIdentity radio_new_identity() {
|
||||
RadioNoiseListener rng(radio);
|
||||
return mesh::LocalIdentity(&rng);
|
||||
}
|
||||
|
||||
void radio_reset_agc() {
|
||||
radio.setRxBoostedGainMode(true);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
// Include variant.h first to ensure all board-specific defines are available
|
||||
#include "variant.h"
|
||||
|
||||
#define RADIOLIB_STATIC_ONLY 1
|
||||
#include <RadioLib.h>
|
||||
#include <helpers/radiolib/RadioLibWrappers.h>
|
||||
#include <helpers/radiolib/CustomSX1262Wrapper.h>
|
||||
#include <TDeckProMaxBoard.h>
|
||||
#include <helpers/AutoDiscoverRTCClock.h>
|
||||
|
||||
#ifdef DISPLAY_CLASS
|
||||
#include <helpers/ui/GxEPDDisplay.h>
|
||||
#include <helpers/ui/MomentaryButton.h>
|
||||
#endif
|
||||
|
||||
#if HAS_GPS
|
||||
#include "helpers/sensors/EnvironmentSensorManager.h"
|
||||
#include "helpers/sensors/MicroNMEALocationProvider.h"
|
||||
#include "GPSStreamCounter.h"
|
||||
#else
|
||||
#include <helpers/SensorManager.h>
|
||||
#endif
|
||||
|
||||
extern TDeckProMaxBoard board;
|
||||
extern WRAPPER_CLASS radio_driver;
|
||||
extern AutoDiscoverRTCClock rtc_clock;
|
||||
|
||||
#if HAS_GPS
|
||||
extern GPSStreamCounter gpsStream;
|
||||
extern EnvironmentSensorManager sensors;
|
||||
#else
|
||||
extern SensorManager sensors;
|
||||
#endif
|
||||
|
||||
#ifdef DISPLAY_CLASS
|
||||
extern DISPLAY_CLASS display;
|
||||
extern MomentaryButton user_btn;
|
||||
#endif
|
||||
|
||||
bool radio_init();
|
||||
uint32_t radio_get_rng_seed();
|
||||
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr);
|
||||
void radio_set_tx_power(uint8_t dbm);
|
||||
mesh::LocalIdentity radio_new_identity();
|
||||
void radio_reset_agc();
|
||||
@@ -0,0 +1,301 @@
|
||||
#pragma once
|
||||
|
||||
// =============================================================================
|
||||
// LilyGo T-Deck Pro MAX V0.1 - Pin Definitions
|
||||
// Hardware revision: HD-V3-250911
|
||||
//
|
||||
// KEY DIFFERENCES FROM T-Deck Pro V1.1:
|
||||
// - XL9555 I/O expander (0x20) controls peripheral power, resets, and switches
|
||||
// (LoRa EN, GPS EN, modem power, touch RST, keyboard RST, antenna sel, etc.)
|
||||
// - 4G (A7682E) and audio (ES8311) coexist on ONE board — no longer mutually exclusive
|
||||
// - ES8311 I2C codec replaces PCM5102A (needs I2C config, different I2S pins)
|
||||
// - E-ink RST moved: IO9 (was IO16)
|
||||
// - E-ink BL moved: IO41 (was IO45, now has working front-light hardware!)
|
||||
// - GPS UART moved: RX=IO2, TX=IO16 (was RX=IO44, TX=IO43)
|
||||
// - GPS/LoRa power via XL9555 (was direct GPIO 39/46)
|
||||
// - Touch RST via XL9555 IO07 (was GPIO 38)
|
||||
// - Modem power/PWRKEY via XL9555 (was direct GPIO 41/40)
|
||||
// - No PIN_PERF_POWERON (IO10 is now modem UART RX)
|
||||
// - Battery: 1500 mAh (was 1400 mAh)
|
||||
// - LoRa antenna switch (SKY13453) controlled by XL9555 IO04
|
||||
// - Audio output mux (A7682E vs ES8311) controlled by XL9555 IO12
|
||||
// - Speaker amplifier (NS4150B) enable via XL9555 IO06
|
||||
// =============================================================================
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// E-Ink Display (GDEQ031T10 - 240x320)
|
||||
// E-ink SHARES the SPI bus with LoRa and SD card (SCK=36, MOSI=33, MISO=47)
|
||||
// They use different chip selects: E-ink CS=34, LoRa CS=3, SD CS=48
|
||||
// -----------------------------------------------------------------------------
|
||||
#define PIN_EINK_CS 34
|
||||
#define PIN_EINK_DC 35
|
||||
#define PIN_EINK_RES 9 // MAX: IO9 (was IO16 on V1.1)
|
||||
#define PIN_EINK_BUSY 37
|
||||
#define PIN_EINK_SCLK 36 // Shared with LoRa + SD
|
||||
#define PIN_EINK_MOSI 33 // Shared with LoRa + SD
|
||||
#define PIN_EINK_BL 41 // MAX: IO41 — working front-light! (was IO45 non-functional on V1.1)
|
||||
|
||||
// Legacy aliases for MeshCore compatibility
|
||||
#define PIN_DISPLAY_CS PIN_EINK_CS
|
||||
#define PIN_DISPLAY_DC PIN_EINK_DC
|
||||
#define PIN_DISPLAY_RST PIN_EINK_RES
|
||||
#define PIN_DISPLAY_BUSY PIN_EINK_BUSY
|
||||
#define PIN_DISPLAY_SCLK PIN_EINK_SCLK
|
||||
#define PIN_DISPLAY_MOSI PIN_EINK_MOSI
|
||||
|
||||
// Display dimensions - native resolution of GDEQ031T10
|
||||
#define LCD_HOR_SIZE 240
|
||||
#define LCD_VER_SIZE 320
|
||||
|
||||
// E-ink model for GxEPD2
|
||||
#define EINK_DISPLAY_MODEL GxEPD2_310_GDEQ031T10
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// SPI Bus - Shared by LoRa, SD Card, AND E-ink display
|
||||
// -----------------------------------------------------------------------------
|
||||
#define BOARD_SPI_SCLK 36
|
||||
#define BOARD_SPI_MISO 47
|
||||
#define BOARD_SPI_MOSI 33
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// I2C Bus
|
||||
// -----------------------------------------------------------------------------
|
||||
#define I2C_SDA 13
|
||||
#define I2C_SCL 14
|
||||
|
||||
// Aliases for ESP32Board base class compatibility
|
||||
#define PIN_BOARD_SDA I2C_SDA
|
||||
#define PIN_BOARD_SCL I2C_SCL
|
||||
|
||||
// I2C Device Addresses
|
||||
#define I2C_ADDR_ES8311 0x18 // ES8311 audio codec (NEW on MAX)
|
||||
#define I2C_ADDR_TOUCH 0x1A // CST328
|
||||
#define I2C_ADDR_XL9555 0x20 // XL9555 I/O expander (NEW on MAX)
|
||||
#define I2C_ADDR_GYROSCOPE 0x28 // BHI260AP
|
||||
#define I2C_ADDR_KEYBOARD 0x34 // TCA8418
|
||||
#define I2C_ADDR_BQ27220 0x55 // Fuel gauge
|
||||
#define I2C_ADDR_DRV2605 0x5A // Motor driver (haptic)
|
||||
#define I2C_ADDR_BQ25896 0x6B // Charger
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// XL9555 I/O Expander — Pin Assignments
|
||||
//
|
||||
// The XL9555 replaces direct GPIO control of peripheral power enables,
|
||||
// resets, and switches. It must be initialised over I2C before LoRa, GPS,
|
||||
// modem, or touch can be used.
|
||||
//
|
||||
// Port 0: pins 0-7, registers 0x02 (output) / 0x06 (direction)
|
||||
// Port 1: pins 8-15, registers 0x03 (output) / 0x07 (direction)
|
||||
// Direction: 0 = output, 1 = input
|
||||
// -----------------------------------------------------------------------------
|
||||
#define HAS_XL9555 1
|
||||
|
||||
// XL9555 I2C registers
|
||||
#define XL9555_REG_INPUT_0 0x00
|
||||
#define XL9555_REG_INPUT_1 0x01
|
||||
#define XL9555_REG_OUTPUT_0 0x02
|
||||
#define XL9555_REG_OUTPUT_1 0x03
|
||||
#define XL9555_REG_INVERT_0 0x04
|
||||
#define XL9555_REG_INVERT_1 0x05
|
||||
#define XL9555_REG_CONFIG_0 0x06 // 0=output, 1=input
|
||||
#define XL9555_REG_CONFIG_1 0x07
|
||||
|
||||
// XL9555 pin assignments (0-7 = Port 0, 8-15 = Port 1)
|
||||
#define XL_PIN_6609_EN 0 // HIGH: Enable A7682E power supply (SGM6609 boost)
|
||||
#define XL_PIN_LORA_EN 1 // HIGH: Enable SX1262 power supply
|
||||
#define XL_PIN_GPS_EN 2 // HIGH: Enable GPS power supply
|
||||
#define XL_PIN_1V8_EN 3 // HIGH: Enable BHI260AP 1.8V power supply
|
||||
#define XL_PIN_LORA_SEL 4 // HIGH: internal antenna, LOW: external antenna (SKY13453)
|
||||
#define XL_PIN_MOTOR_EN 5 // HIGH: Enable DRV2605 power supply
|
||||
#define XL_PIN_AMPLIFIER 6 // HIGH: Enable NS4150B speaker power amplifier
|
||||
#define XL_PIN_TOUCH_RST 7 // LOW: Reset touch controller (active-low)
|
||||
#define XL_PIN_PWRKEY_EN 8 // HIGH: A7682E POWERKEY toggle
|
||||
#define XL_PIN_KEY_RST 9 // LOW: Reset keyboard (active-low)
|
||||
#define XL_PIN_AUDIO_SEL 10 // HIGH: A7682E audio out, LOW: ES8311 audio out
|
||||
// Pins 11-15 are reserved
|
||||
|
||||
// Default XL9555 output state at boot (all power enables ON, resets de-asserted)
|
||||
// Bit layout: [P07..P00] = TOUCH_RST=1, AMP=0, MOTOR_EN=0, LORA_SEL=1, 1V8=1, GPS=1, LORA=1, 6609=0
|
||||
// [P17..P10] = reserved=0, AUDIO_SEL=0, KEY_RST=1, PWRKEY=0
|
||||
//
|
||||
// Conservative boot defaults for Meck:
|
||||
// - LoRa ON, GPS ON, 1.8V ON, internal antenna
|
||||
// - Modem OFF (6609_EN LOW), PWRKEY LOW (toggled later if needed)
|
||||
// - Motor OFF, Amplifier OFF (saves power, enabled on demand)
|
||||
// - Touch RST HIGH (not resetting), Keyboard RST HIGH (not resetting)
|
||||
// - Audio select LOW (ES8311 by default — Meck controls this when needed)
|
||||
#define XL9555_BOOT_PORT0 0b10011110 // 0x9E: T_RST=1, AMP=0, MOT=0, LSEL=1, 1V8=1, GPS=1, LORA=1, 6609=0
|
||||
#define XL9555_BOOT_PORT1 0b00000010 // 0x02: ..., ASEL=0, KRST=1, PKEY=0
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Touch Controller (CST328)
|
||||
// NOTE: Touch RST is via XL9555 pin 7, NOT a direct GPIO!
|
||||
// CST328_PIN_RST is defined as -1 to signal "not a direct GPIO".
|
||||
// The board class handles touch reset via XL9555 in begin().
|
||||
// -----------------------------------------------------------------------------
|
||||
#define HAS_TOUCHSCREEN 1
|
||||
#define CST328_PIN_INT 12
|
||||
#define CST328_PIN_RST -1 // MAX: Routed through XL9555 IO07 — handled by board class
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// GPS
|
||||
// NOTE: GPS power enable is via XL9555 pin 2, NOT a direct GPIO!
|
||||
// PIN_GPS_EN is intentionally NOT defined — the board class handles it via XL9555.
|
||||
// -----------------------------------------------------------------------------
|
||||
#define HAS_GPS 1
|
||||
#define GPS_BAUDRATE 38400
|
||||
// #define PIN_GPS_EN — NOT a direct GPIO on MAX (XL9555 IO02)
|
||||
#define GPS_RX_PIN 2 // MAX: IO2 (was IO44 on V1.1) — ESP32 receives from GPS
|
||||
#define GPS_TX_PIN 16 // MAX: IO16 (was IO43 on V1.1) — ESP32 sends to GPS
|
||||
#define PIN_GPS_PPS 1
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Buttons & Controls
|
||||
// -----------------------------------------------------------------------------
|
||||
#define BUTTON_PIN 0
|
||||
#define PIN_USER_BTN 0
|
||||
|
||||
// Vibration Motor — DRV2605 driver (same as V1.1)
|
||||
// Motor power enable is via XL9555 pin 5, not a direct GPIO.
|
||||
#define HAS_DRV2605 1
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// SD Card
|
||||
// -----------------------------------------------------------------------------
|
||||
#define HAS_SDCARD
|
||||
#define SDCARD_USE_SPI1
|
||||
#define SPI_MOSI 33
|
||||
#define SPI_SCK 36
|
||||
#define SPI_MISO 47
|
||||
#define SPI_CS 48
|
||||
#define SDCARD_CS SPI_CS
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Keyboard (TCA8418)
|
||||
// NOTE: Keyboard RST is via XL9555 pin 9 (active-low).
|
||||
// The board class handles keyboard reset via XL9555 in begin().
|
||||
// -----------------------------------------------------------------------------
|
||||
#define KB_BL_PIN 42
|
||||
#define BOARD_KEYBOARD_INT 15
|
||||
#define HAS_PHYSICAL_KEYBOARD 1
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Audio — ES8311 I2C Codec (NEW on MAX — replaces PCM5102A)
|
||||
//
|
||||
// ES8311 is an I2C-controlled audio codec (unlike PCM5102A which needed no config).
|
||||
// It requires I2C register setup for input source, gain, volume, etc.
|
||||
// Speaker/headphone output is shared with A7682E modem audio, selected via
|
||||
// XL9555 pin AUDIO_SEL: LOW = ES8311, HIGH = A7682E.
|
||||
// Power amplifier (NS4150B) for speaker enabled via XL9555 pin AMPLIFIER.
|
||||
//
|
||||
// I2S pin mapping for ES8311 (completely different from V1.1 PCM5102A!):
|
||||
// MCLK = IO38 (master clock — ES8311 needs this, PCM5102A didn't)
|
||||
// SCLK = IO39 (bit clock, aka BCLK)
|
||||
// LRCK = IO18 (word select, aka LRC/WS)
|
||||
// DSDIN = IO17 (DAC serial data in — ESP32 sends audio TO codec)
|
||||
// ASDOUT= IO40 (ADC serial data out — codec sends mic audio TO ESP32)
|
||||
// -----------------------------------------------------------------------------
|
||||
#define HAS_ES8311_AUDIO 1
|
||||
|
||||
#define BOARD_ES8311_MCLK 38
|
||||
#define BOARD_ES8311_SCLK 39
|
||||
#define BOARD_ES8311_LRCK 18
|
||||
#define BOARD_ES8311_DSDIN 17 // ESP32 → ES8311 (speaker/headphone output)
|
||||
#define BOARD_ES8311_ASDOUT 40 // ES8311 → ESP32 (microphone input)
|
||||
|
||||
// Compatibility aliases for ESP32-audioI2S library (setPinout expects BCLK, LRC, DOUT)
|
||||
#define BOARD_I2S_BCLK BOARD_ES8311_SCLK // IO39
|
||||
#define BOARD_I2S_LRC BOARD_ES8311_LRCK // IO18
|
||||
#define BOARD_I2S_DOUT BOARD_ES8311_DSDIN // IO17
|
||||
#define BOARD_I2S_MCLK BOARD_ES8311_MCLK // IO38 (ESP32-audioI2S may need setMCLK)
|
||||
|
||||
// Microphone — ES8311 built-in ADC (replaces separate PDM mic on V1.1)
|
||||
// Mic data comes through I2S ASDOUT pin, not a separate PDM interface.
|
||||
#define BOARD_MIC_I2S_DIN BOARD_ES8311_ASDOUT // IO40
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Sensors
|
||||
// -----------------------------------------------------------------------------
|
||||
#define HAS_BHI260AP // Gyroscope/IMU (1.8V power via XL9555 IO03)
|
||||
#define BOARD_GYRO_INT 21
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Power Management
|
||||
// -----------------------------------------------------------------------------
|
||||
#define HAS_BQ27220 1
|
||||
#define BQ27220_I2C_ADDR 0x55
|
||||
#define BQ27220_I2C_SDA I2C_SDA
|
||||
#define BQ27220_I2C_SCL I2C_SCL
|
||||
#define BQ27220_DESIGN_CAPACITY 1500 // MAX: 1500 mAh (was 1400 on V1.1)
|
||||
#define BQ27220_DESIGN_CAPACITY_MAH 1500 // Alias used by TDeckBoard.h
|
||||
|
||||
#define HAS_PPM 1
|
||||
#define XPOWERS_CHIP_BQ25896
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// LoRa Radio (SX1262)
|
||||
// NOTE: LoRa power enable is via XL9555 pin 1, NOT GPIO 46!
|
||||
// The board class enables LoRa power via XL9555 in begin().
|
||||
// P_LORA_EN is intentionally NOT defined here — handled by board class.
|
||||
// Antenna selection: XL9555 pin 4 (HIGH=internal, LOW=external via SKY13453).
|
||||
// -----------------------------------------------------------------------------
|
||||
#define USE_SX1262
|
||||
#define USE_SX1268
|
||||
|
||||
// LORA_EN is NOT a direct GPIO on MAX — omit the define entirely.
|
||||
// If any code references P_LORA_EN, it must be guarded with #ifndef HAS_XL9555.
|
||||
// #define LORA_EN — NOT DEFINED (was GPIO 46 on V1.1)
|
||||
|
||||
#define LORA_SCK 36
|
||||
#define LORA_MISO 47
|
||||
#define LORA_MOSI 33 // Shared with e-ink and SD card
|
||||
#define LORA_CS 3
|
||||
#define LORA_RESET 4
|
||||
#define LORA_DIO0 -1 // Not connected on SX1262
|
||||
#define LORA_DIO1 5 // SX1262 IRQ
|
||||
#define LORA_DIO2 6 // SX1262 BUSY
|
||||
|
||||
// SX126X driver aliases (Meshtastic compatibility)
|
||||
#define SX126X_CS LORA_CS
|
||||
#define SX126X_DIO1 LORA_DIO1
|
||||
#define SX126X_BUSY LORA_DIO2
|
||||
#define SX126X_RESET LORA_RESET
|
||||
|
||||
// RadioLib/MeshCore compatibility aliases
|
||||
#define P_LORA_NSS LORA_CS
|
||||
#define P_LORA_DIO_1 LORA_DIO1
|
||||
#define P_LORA_RESET LORA_RESET
|
||||
#define P_LORA_BUSY LORA_DIO2
|
||||
#define P_LORA_SCLK LORA_SCK
|
||||
#define P_LORA_MISO LORA_MISO
|
||||
#define P_LORA_MOSI LORA_MOSI
|
||||
// P_LORA_EN is NOT defined — LoRa power is via XL9555, handled in board begin()
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// 4G Modem — A7682E (ALWAYS PRESENT on MAX — no longer optional!)
|
||||
//
|
||||
// On V1.1, 4G and audio were mutually exclusive hardware configurations.
|
||||
// On MAX, both coexist. The XL9555 controls:
|
||||
// - 6609_EN (XL pin 0): modem power supply (SGM6609 boost converter)
|
||||
// - PWRKEY (XL pin 8): modem power key toggle
|
||||
// Audio output from modem vs ES8311 is selected by AUDIO_SEL (XL pin 10).
|
||||
//
|
||||
// MODEM_POWER_EN and MODEM_PWRKEY are NOT direct GPIOs — ModemManager
|
||||
// needs MAX-aware paths (see integration guide).
|
||||
// MODEM_RST does not exist on MAX (IO9 is now LCD_RST).
|
||||
// -----------------------------------------------------------------------------
|
||||
// Direct GPIO modem pins (still accessible as regular GPIO):
|
||||
#define MODEM_RI 7 // Ring indicator (interrupt input)
|
||||
#define MODEM_DTR 8 // Data terminal ready (output)
|
||||
#define MODEM_RX 10 // UART RX (ESP32 receives from modem)
|
||||
#define MODEM_TX 11 // UART TX (ESP32 sends to modem)
|
||||
|
||||
// XL9555-routed modem pins — these are NOT direct GPIO!
|
||||
// MODEM_POWER_EN and MODEM_PWRKEY are intentionally NOT defined.
|
||||
// Existing code guarded by #ifdef MODEM_POWER_EN / #ifdef HAS_4G_MODEM will
|
||||
// be skipped. Use board.modemPowerOn()/modemPwrkeyPulse() instead.
|
||||
// MODEM_RST does not exist on MAX (IO9 is LCD_RST).
|
||||
|
||||
// Compatibility: PIN_PERF_POWERON does not exist on MAX (IO10 is modem UART RX).
|
||||
// Defined as -1 so TDeckBoard.cpp compiles (parent class), but never used at runtime.
|
||||
#define PIN_PERF_POWERON -1
|
||||
@@ -0,0 +1,169 @@
|
||||
// =============================================================================
|
||||
// TechoCardBoard — Implementation for LilyGo T-Echo Card
|
||||
// =============================================================================
|
||||
|
||||
#include "TechoCardBoard.h"
|
||||
#include "variant.h"
|
||||
|
||||
// nRF52840 SAADC includes
|
||||
#include "nrf.h"
|
||||
|
||||
void TechoCardBoard::begin() {
|
||||
NRF52BoardDCDC::begin();
|
||||
|
||||
// Configure battery ADC pin as analog input
|
||||
pinMode(PIN_VBAT_READ, INPUT);
|
||||
|
||||
// Configure button(s)
|
||||
pinMode(PIN_BUTTON_A, INPUT_PULLUP);
|
||||
pinMode(PIN_BUTTON_BOOT, INPUT_PULLUP);
|
||||
|
||||
// Buzzer off
|
||||
#if defined(HAS_BUZZER) && PIN_BUZZER >= 0
|
||||
pinMode(PIN_BUZZER, OUTPUT);
|
||||
digitalWrite(PIN_BUZZER, LOW);
|
||||
#endif
|
||||
|
||||
// RGB LED off at boot
|
||||
#if defined(HAS_RGB_LED)
|
||||
ledOff();
|
||||
#endif
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Battery voltage reading via nRF52840 SAADC
|
||||
//
|
||||
// The T-Echo Card has a voltage divider on AIN0 (P0.02).
|
||||
// nRF52840 SAADC: 12-bit, internal 0.6V reference, configurable gain.
|
||||
// With 1/6 gain: input range 0–3.6V. Multiply by divider ratio (ADC_MULTIPLIER).
|
||||
//
|
||||
// NOTE: The T-Echo Lite has a known issue reading 100% / 6.00V constantly.
|
||||
// This is likely caused by incorrect SAADC configuration (wrong gain, wrong
|
||||
// reference, or the pin being pulled high by the charging circuit).
|
||||
// We use explicit SAADC register programming to avoid that issue.
|
||||
// -----------------------------------------------------------------------------
|
||||
float TechoCardBoard::getBatteryVoltage() {
|
||||
uint32_t now = millis();
|
||||
|
||||
// Cache battery reading — only read every 10 seconds
|
||||
if (_cached_battery_mv > 0 && (now - _last_battery_read) < 10000) {
|
||||
return _cached_battery_mv;
|
||||
}
|
||||
|
||||
// Configure SAADC for single-shot reading
|
||||
NRF_SAADC->RESOLUTION = SAADC_RESOLUTION_VAL_12bit;
|
||||
|
||||
// Channel 0: AIN0 (P0.02), 1/6 gain, internal 0.6V reference
|
||||
// Effective range: 0 – 3.6V
|
||||
NRF_SAADC->CH[0].PSELP = SAADC_CH_PSELP_PSELP_AnalogInput0; // AIN0
|
||||
NRF_SAADC->CH[0].PSELN = SAADC_CH_PSELN_PSELN_NC; // Single-ended
|
||||
NRF_SAADC->CH[0].CONFIG =
|
||||
(SAADC_CH_CONFIG_GAIN_Gain1_6 << SAADC_CH_CONFIG_GAIN_Pos) |
|
||||
(SAADC_CH_CONFIG_REFSEL_Internal << SAADC_CH_CONFIG_REFSEL_Pos) |
|
||||
(SAADC_CH_CONFIG_TACQ_40us << SAADC_CH_CONFIG_TACQ_Pos) |
|
||||
(SAADC_CH_CONFIG_MODE_SE << SAADC_CH_CONFIG_MODE_Pos) |
|
||||
(SAADC_CH_CONFIG_BURST_Disabled << SAADC_CH_CONFIG_BURST_Pos) |
|
||||
(SAADC_CH_CONFIG_RESP_Bypass << SAADC_CH_CONFIG_RESP_Pos) |
|
||||
(SAADC_CH_CONFIG_RESN_Bypass << SAADC_CH_CONFIG_RESN_Pos);
|
||||
|
||||
// Set up result buffer
|
||||
volatile int16_t result = 0;
|
||||
NRF_SAADC->RESULT.PTR = (uint32_t)&result;
|
||||
NRF_SAADC->RESULT.MAXCNT = 1;
|
||||
|
||||
// Enable, calibrate on first use
|
||||
NRF_SAADC->ENABLE = SAADC_ENABLE_ENABLE_Enabled;
|
||||
|
||||
// Start and wait for sample
|
||||
NRF_SAADC->EVENTS_END = 0;
|
||||
NRF_SAADC->TASKS_START = 1;
|
||||
while (!NRF_SAADC->EVENTS_STARTED);
|
||||
NRF_SAADC->EVENTS_STARTED = 0;
|
||||
|
||||
NRF_SAADC->TASKS_SAMPLE = 1;
|
||||
while (!NRF_SAADC->EVENTS_END);
|
||||
NRF_SAADC->EVENTS_END = 0;
|
||||
|
||||
NRF_SAADC->TASKS_STOP = 1;
|
||||
while (!NRF_SAADC->EVENTS_STOPPED);
|
||||
NRF_SAADC->EVENTS_STOPPED = 0;
|
||||
|
||||
// Disable SAADC to save power
|
||||
NRF_SAADC->ENABLE = SAADC_ENABLE_ENABLE_Disabled;
|
||||
|
||||
// Convert: voltage = (result / 4096) * 3.6V * ADC_MULTIPLIER * 1000 (mV)
|
||||
if (result < 0) result = 0;
|
||||
float voltage_mv = ((float)result / 4096.0f) * 3600.0f * _adc_multiplier;
|
||||
|
||||
_cached_battery_mv = voltage_mv;
|
||||
_last_battery_read = now;
|
||||
|
||||
return voltage_mv;
|
||||
}
|
||||
|
||||
uint8_t TechoCardBoard::getBatteryPercent() {
|
||||
float mv = getBatteryVoltage();
|
||||
if (mv <= 0) return 0;
|
||||
|
||||
// Simple linear approximation for single-cell LiPo
|
||||
// 3200 mV = 0%, 4200 mV = 100%
|
||||
if (mv >= 4200.0f) return 100;
|
||||
if (mv <= 3200.0f) return 0;
|
||||
return (uint8_t)(((mv - 3200.0f) / 1000.0f) * 100.0f);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// GPS power control
|
||||
// -----------------------------------------------------------------------------
|
||||
void TechoCardBoard::enableGPS(bool enable) {
|
||||
#if defined(HAS_GPS) && PIN_GPS_EN >= 0
|
||||
digitalWrite(PIN_GPS_EN, enable ? HIGH : LOW);
|
||||
#endif
|
||||
#if defined(HAS_GPS) && PIN_GPS_RF_EN >= 0
|
||||
digitalWrite(PIN_GPS_RF_EN, enable ? HIGH : LOW);
|
||||
#endif
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Speaker power control
|
||||
// -----------------------------------------------------------------------------
|
||||
void TechoCardBoard::enableSpeaker(bool enable) {
|
||||
#if defined(HAS_SPEAKER)
|
||||
digitalWrite(PIN_SPK_EN, enable ? HIGH : LOW);
|
||||
#if PIN_SPK_EN2 >= 0
|
||||
digitalWrite(PIN_SPK_EN2, enable ? HIGH : LOW);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// RGB LED — WS2812 via NeoPixel protocol
|
||||
// Simple bit-bang implementation for nRF52840 at 64MHz
|
||||
// -----------------------------------------------------------------------------
|
||||
void TechoCardBoard::setLED(uint8_t r, uint8_t g, uint8_t b) {
|
||||
#if defined(HAS_RGB_LED)
|
||||
// TODO: Implement WS2812 bit-bang or use Adafruit_NeoPixel library
|
||||
// For initial bringup, just use the Adafruit_NeoPixel library
|
||||
// which is available in the Adafruit nRF52 Arduino core
|
||||
(void)r; (void)g; (void)b;
|
||||
#endif
|
||||
}
|
||||
|
||||
void TechoCardBoard::ledOff() {
|
||||
setLED(0, 0, 0);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Buzzer — PWM tone generation
|
||||
// -----------------------------------------------------------------------------
|
||||
void TechoCardBoard::buzz(uint16_t freq_hz, uint16_t duration_ms) {
|
||||
#if defined(HAS_BUZZER) && PIN_BUZZER >= 0
|
||||
if (freq_hz == 0 || duration_ms == 0) {
|
||||
noTone(PIN_BUZZER);
|
||||
return;
|
||||
}
|
||||
tone(PIN_BUZZER, freq_hz, duration_ms);
|
||||
#else
|
||||
(void)freq_hz; (void)duration_ms;
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
#pragma once
|
||||
|
||||
// =============================================================================
|
||||
// TechoCardBoard — Board class for LilyGo T-Echo Card
|
||||
//
|
||||
// Extends NRF52BoardDCDC with:
|
||||
// - Battery ADC (AIN0, P0.02) with solar charging via BQ25896
|
||||
// - GPS power control (L76K)
|
||||
// - Speaker/mic enable
|
||||
// - RGB LED control
|
||||
// - Buzzer
|
||||
// - NFC NDEF contact sharing
|
||||
// =============================================================================
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <helpers/NRF52Board.h>
|
||||
#include "variant.h"
|
||||
|
||||
#ifdef NRF52_POWER_MANAGEMENT
|
||||
// Power management config for T-Echo Card
|
||||
// AIN0 (P0.02) for battery voltage sensing
|
||||
// REFSEL=4 → 5/8 VDD ≈ 2.0625V threshold (with 2:1 divider → ~4.125V cell)
|
||||
static const PowerMgtConfig TECHO_CARD_POWER_CONFIG = {
|
||||
.lpcomp_ain_channel = BATTERY_ADC_AIN, // AIN0
|
||||
.lpcomp_refsel = 4, // 5/8 VDD
|
||||
.voltage_bootlock = 3100, // Don't boot below 3.1V
|
||||
};
|
||||
#endif
|
||||
|
||||
class TechoCardBoard : public NRF52BoardDCDC {
|
||||
private:
|
||||
float _adc_multiplier;
|
||||
uint32_t _last_battery_read;
|
||||
float _cached_battery_mv;
|
||||
|
||||
public:
|
||||
TechoCardBoard()
|
||||
: _adc_multiplier(ADC_MULTIPLIER),
|
||||
_last_battery_read(0),
|
||||
_cached_battery_mv(0) {}
|
||||
|
||||
void begin() override;
|
||||
|
||||
// Battery
|
||||
float getBatteryVoltage() override;
|
||||
uint8_t getBatteryPercent() override;
|
||||
float getAdcMultiplier() override { return _adc_multiplier; }
|
||||
void setAdcMultiplier(float mult) { _adc_multiplier = mult; }
|
||||
|
||||
// GPS power control
|
||||
void enableGPS(bool enable);
|
||||
|
||||
// Speaker power control
|
||||
void enableSpeaker(bool enable);
|
||||
|
||||
// RGB LED
|
||||
void setLED(uint8_t r, uint8_t g, uint8_t b);
|
||||
void ledOff();
|
||||
|
||||
// Buzzer
|
||||
void buzz(uint16_t freq_hz, uint16_t duration_ms);
|
||||
|
||||
#ifdef NRF52_POWER_MANAGEMENT
|
||||
const PowerMgtConfig* getPowerConfig() const override {
|
||||
return &TECHO_CARD_POWER_CONFIG;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
// =============================================================================
|
||||
// Arduino pin compatibility header for LilyGo T-Echo Card
|
||||
//
|
||||
// This file provides Arduino-standard pin name aliases for the nRF52840 GPIOs.
|
||||
// Only needed if creating a custom board variant inside the Adafruit nRF52
|
||||
// Arduino framework package. If using build flag overrides in platformio.ini,
|
||||
// this file is optional.
|
||||
// =============================================================================
|
||||
|
||||
// On nRF52840, Arduino digital pin numbers map 1:1 to nRF GPIO numbers
|
||||
// (0–47 for port 0 and port 1).
|
||||
|
||||
// LED
|
||||
#define LED_BUILTIN PIN_LED1
|
||||
#define PIN_LED1 39 // WS2812 RGB LED data (1, 7)
|
||||
#define LED_STATE_ON 1
|
||||
|
||||
// Buttons
|
||||
#define PIN_BUTTON1 42 // Button A — orange front button (1, 10)
|
||||
#define PIN_BUTTON2 24 // Boot button (0, 24)
|
||||
|
||||
// Serial (USB CDC)
|
||||
// nRF52840 native USB — no UART pin assignment needed for Serial
|
||||
// Serial1 is used for GPS
|
||||
#define PIN_SERIAL1_RX 21 // GPS TX → nRF RX (0, 21)
|
||||
#define PIN_SERIAL1_TX 19 // nRF TX → GPS RX (0, 19)
|
||||
|
||||
// I2C
|
||||
#define PIN_WIRE_SDA 36 // (1, 4)
|
||||
#define PIN_WIRE_SCL 34 // (1, 2)
|
||||
|
||||
// SPI (LoRa — directly mapped, RadioLib handles pin control)
|
||||
#define PIN_SPI_MISO 17 // (0, 17)
|
||||
#define PIN_SPI_MOSI 15 // (0, 15)
|
||||
#define PIN_SPI_SCK 13 // (0, 13)
|
||||
|
||||
// Analog
|
||||
#define PIN_A0 2 // (0, 2) — Battery ADC / AIN0
|
||||
|
||||
// QSPI Flash (ZD25WQ32CEIGR 4MB)
|
||||
// nRF52840 QSPI uses fixed pins — framework handles these
|
||||
// #define PIN_QSPI_SCK 19 // Conflict with GPS TX — check if QSPI is on different pins
|
||||
// NOTE: QSPI pin mapping needs verification on actual hardware.
|
||||
// The T-Echo Card may use SPI (not QSPI) for external flash.
|
||||
|
||||
// NFC (dedicated nRF52840 NFC pins — not GPIO-assignable)
|
||||
// NFC1 = P0.09, NFC2 = P0.10
|
||||
// These are only usable as NFC when NFC is enabled in UICR.
|
||||
// If NFC is disabled, they become GPIO9 and GPIO10.
|
||||
|
||||
// PDM Microphone
|
||||
#define PIN_PDM_CLK 35 // (1, 3)
|
||||
#define PIN_PDM_DIN 37 // (1, 5)
|
||||
|
||||
// I2S Speaker (MAX98357)
|
||||
#define PIN_I2S_SCK 16 // BCLK (0, 16)
|
||||
#define PIN_I2S_LRCK 22 // LRCK / WS (0, 22)
|
||||
#define PIN_I2S_SDOUT 20 // DATA (0, 20)
|
||||
@@ -0,0 +1,106 @@
|
||||
; =============================================================================
|
||||
; LilyGo T-Echo Card — Meck variant configuration
|
||||
;
|
||||
; nRF52840 + SX1262 (HPB16B3) + SSD1315 OLED (72×40) + L76K GPS
|
||||
; + MAX98357 Speaker + MP34DT05 PDM Mic + ICM20948 IMU + Solar + NFC
|
||||
;
|
||||
; Platform: nRF52 (Adafruit nRF52 Arduino)
|
||||
; =============================================================================
|
||||
|
||||
; --- Base configuration for all T-Echo Card builds ---
|
||||
[lilygo_techo_card]
|
||||
extends = nrf52_base
|
||||
platform = https://github.com/maxgerhardt/platform-nordicnrf52.git
|
||||
board = lilygo_techo_card
|
||||
board_check = false
|
||||
extra_scripts =
|
||||
create-uf2.py
|
||||
build_flags = ${nrf52_base.build_flags}
|
||||
-I variants/lilygo_techo_card
|
||||
-D LILYGO_TECHO_CARD
|
||||
-D NRF52_POWER_MANAGEMENT
|
||||
; I2C
|
||||
-D PIN_BOARD_SDA=36
|
||||
-D PIN_BOARD_SCL=34
|
||||
; LoRa SX1262 (HPB16B3 module)
|
||||
-D RADIO_CLASS=CustomSX1262
|
||||
-D WRAPPER_CLASS=CustomSX1262Wrapper
|
||||
-D P_LORA_NSS=11
|
||||
-D P_LORA_DIO_1=40
|
||||
-D P_LORA_RESET=7
|
||||
-D P_LORA_BUSY=14
|
||||
-D P_LORA_SCLK=13
|
||||
-D P_LORA_MISO=17
|
||||
-D P_LORA_MOSI=15
|
||||
-D LORA_TX_POWER=22
|
||||
-D SX126X_CURRENT_LIMIT=140
|
||||
-D SX126X_RX_BOOSTED_GAIN=1
|
||||
-D SX126X_DIO2_AS_RF_SWITCH=1
|
||||
; Display — SSD1315 OLED (72×40, I2C, SSD1306-compatible)
|
||||
-D DISPLAY_CLASS=SSD1306Display
|
||||
-D PIN_OLED_RESET=-1
|
||||
; GPS — L76K
|
||||
-D HAS_GPS=1
|
||||
-D PIN_GPS_TX=19
|
||||
-D PIN_GPS_RX=21
|
||||
-D PIN_GPS_EN=47
|
||||
-D GPS_BAUDRATE=9600
|
||||
-D ENV_INCLUDE_GPS=1
|
||||
; Battery ADC
|
||||
-D PIN_VBAT_READ=2
|
||||
; User button
|
||||
-D PIN_USER_BTN=42
|
||||
; Board class
|
||||
-D BOARD_CLASS=TechoCardBoard
|
||||
build_src_filter = ${nrf52_base.build_src_filter}
|
||||
+<../variants/lilygo_techo_card/*.cpp>
|
||||
lib_deps = ${nrf52_base.lib_deps}
|
||||
olikraus/U8g2 @ ^2.35.19
|
||||
stevemarple/MicroNMEA @ ^2.0.6
|
||||
|
||||
; =============================================================================
|
||||
; Build Environments
|
||||
; =============================================================================
|
||||
|
||||
; --- BLE Companion Radio ---
|
||||
; Pairs with MeshCore companion app (Android/iOS/Web) over Bluetooth.
|
||||
; Includes GPS for location and time sync.
|
||||
[env:meck_techo_card_companion_radio_ble]
|
||||
extends = lilygo_techo_card
|
||||
build_flags = ${lilygo_techo_card.build_flags}
|
||||
-D FIRMWARE_NAME='"Meck T-Echo Card BLE"'
|
||||
; Debug (disable for release)
|
||||
; -D MESH_DEBUG
|
||||
; -D BLE_DEBUG_LOGGING
|
||||
build_src_filter = ${lilygo_techo_card.build_src_filter}
|
||||
+<../examples/companion_radio/*.cpp>
|
||||
|
||||
; --- Repeater ---
|
||||
; Standalone LoRa repeater node. GPS for position adverts.
|
||||
; OLED shows status. Solar + 800mAh battery for outdoor deployment.
|
||||
[env:meck_techo_card_repeater]
|
||||
extends = lilygo_techo_card
|
||||
build_flags = ${lilygo_techo_card.build_flags}
|
||||
-D FIRMWARE_NAME='"Meck T-Echo Card Repeater"'
|
||||
; -D MESH_DEBUG
|
||||
build_src_filter = ${lilygo_techo_card.build_src_filter}
|
||||
+<../examples/simple_repeater/*.cpp>
|
||||
|
||||
; --- Room Server ---
|
||||
; BBS-style message board node.
|
||||
[env:meck_techo_card_room_server]
|
||||
extends = lilygo_techo_card
|
||||
build_flags = ${lilygo_techo_card.build_flags}
|
||||
-D FIRMWARE_NAME='"Meck T-Echo Card Room"'
|
||||
build_src_filter = ${lilygo_techo_card.build_src_filter}
|
||||
+<../examples/simple_room_server/*.cpp>
|
||||
|
||||
; --- Sensor Node ---
|
||||
; Telemetry node with GPS position reporting.
|
||||
; IMU data (ICM20948) can be added as a custom sensor source.
|
||||
[env:meck_techo_card_sensor]
|
||||
extends = lilygo_techo_card
|
||||
build_flags = ${lilygo_techo_card.build_flags}
|
||||
-D FIRMWARE_NAME='"Meck T-Echo Card Sensor"'
|
||||
build_src_filter = ${lilygo_techo_card.build_src_filter}
|
||||
+<../examples/simple_sensor/*.cpp>
|
||||
@@ -0,0 +1,95 @@
|
||||
// =============================================================================
|
||||
// MeshCore target implementation for LilyGo T-Echo Card
|
||||
//
|
||||
// nRF52840 + SX1262 (HPB16B3 module) + SSD1315 OLED + L76K GPS
|
||||
// =============================================================================
|
||||
|
||||
#include "target.h"
|
||||
#include "variant.h"
|
||||
|
||||
// --- SPI for LoRa radio (software SPI on nRF52) ---
|
||||
// The HPB16B3 SX1262 module uses dedicated SPI pins, not shared with anything else.
|
||||
// RadioLib Module handles the SPI internally when given pin numbers.
|
||||
static Module radio_module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY);
|
||||
|
||||
// --- Radio driver ---
|
||||
RADIO_CLASS radio_driver(&radio_module);
|
||||
WRAPPER_CLASS radio_wrapper(radio_driver);
|
||||
|
||||
// --- Board ---
|
||||
TechoCardBoard board;
|
||||
|
||||
// --- Display (SSD1306-compatible, SSD1315 at 0x3C, 72x40) ---
|
||||
#ifdef DISPLAY_CLASS
|
||||
DISPLAY_CLASS display(OLED_WIDTH, OLED_HEIGHT);
|
||||
#endif
|
||||
|
||||
// --- MeshCore stores ---
|
||||
mesh::IdentityStore identity_store;
|
||||
mesh::NodePrefs node_prefs;
|
||||
mesh::DataStore data_store;
|
||||
|
||||
// --- Sensor manager ---
|
||||
#if defined(ENV_INCLUDE_GPS) && ENV_INCLUDE_GPS
|
||||
#include <helpers/sensors/MicroNMEALocationProvider.h>
|
||||
static MicroNMEALocationProvider gps_provider(Serial1);
|
||||
EnvironmentSensorManager sensor_manager(gps_provider);
|
||||
#else
|
||||
EnvironmentSensorManager sensor_manager;
|
||||
#endif
|
||||
|
||||
// --- Target initialization ---
|
||||
void target_setup() {
|
||||
// Enable OLED power
|
||||
#if PIN_OLED_EN >= 0
|
||||
pinMode(PIN_OLED_EN, OUTPUT);
|
||||
digitalWrite(PIN_OLED_EN, HIGH);
|
||||
delay(10);
|
||||
#endif
|
||||
|
||||
// Enable GPS power
|
||||
#if defined(HAS_GPS) && PIN_GPS_EN >= 0
|
||||
pinMode(PIN_GPS_EN, OUTPUT);
|
||||
digitalWrite(PIN_GPS_EN, HIGH);
|
||||
delay(10);
|
||||
#endif
|
||||
|
||||
// GPS RF/LNA enable
|
||||
#if defined(HAS_GPS) && PIN_GPS_RF_EN >= 0
|
||||
pinMode(PIN_GPS_RF_EN, OUTPUT);
|
||||
digitalWrite(PIN_GPS_RF_EN, HIGH);
|
||||
#endif
|
||||
|
||||
// Initialize GPS UART
|
||||
#if defined(HAS_GPS)
|
||||
Serial1.setPins(PIN_GPS_RX, PIN_GPS_TX);
|
||||
Serial1.begin(GPS_BAUDRATE);
|
||||
#endif
|
||||
|
||||
// Speaker off by default (save power)
|
||||
#if defined(HAS_SPEAKER)
|
||||
pinMode(PIN_SPK_EN, OUTPUT);
|
||||
digitalWrite(PIN_SPK_EN, LOW);
|
||||
#if PIN_SPK_EN2 >= 0
|
||||
pinMode(PIN_SPK_EN2, OUTPUT);
|
||||
digitalWrite(PIN_SPK_EN2, LOW);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Initialize I2C
|
||||
Wire.setPins(I2C_SDA, I2C_SCL);
|
||||
Wire.begin();
|
||||
Wire.setClock(400000);
|
||||
|
||||
// Initialize display
|
||||
#ifdef DISPLAY_CLASS
|
||||
display.begin(OLED_I2C_ADDR);
|
||||
#endif
|
||||
|
||||
// Board-level init
|
||||
board.begin();
|
||||
|
||||
// Initialize LoRa radio
|
||||
// SX1262 DIO2 as RF switch control (common for HPB16B3 modules)
|
||||
radio_driver.setDio2AsRfSwitch(true);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
// =============================================================================
|
||||
// MeshCore target declarations for LilyGo T-Echo Card
|
||||
// =============================================================================
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <RadioLib.h>
|
||||
#include <helpers/ArduinoHelpers.h>
|
||||
#include <helpers/RadioLibWrappers.h>
|
||||
#include <helpers/NRF52Board.h>
|
||||
#include <helpers/CustomSX1262Wrapper.h>
|
||||
#include <helpers/IdentityStore.h>
|
||||
#include <helpers/NodePrefs.h>
|
||||
#include <helpers/DataStore.h>
|
||||
#include <helpers/SensorManager.h>
|
||||
|
||||
#ifdef DISPLAY_CLASS
|
||||
#include <helpers/ui/DisplaySSD1306.h>
|
||||
#endif
|
||||
|
||||
#include "TechoCardBoard.h"
|
||||
|
||||
// Hardware object declarations (instantiated in target.cpp)
|
||||
extern RADIO_CLASS radio_driver;
|
||||
extern WRAPPER_CLASS radio_wrapper;
|
||||
extern TechoCardBoard board;
|
||||
|
||||
#ifdef DISPLAY_CLASS
|
||||
extern DISPLAY_CLASS display;
|
||||
#endif
|
||||
|
||||
extern mesh::IdentityStore identity_store;
|
||||
extern mesh::NodePrefs node_prefs;
|
||||
extern mesh::DataStore data_store;
|
||||
extern EnvironmentSensorManager sensor_manager;
|
||||
|
||||
// Target initialization
|
||||
void target_setup();
|
||||
@@ -0,0 +1,193 @@
|
||||
#pragma once
|
||||
|
||||
// =============================================================================
|
||||
// LilyGo T-Echo Card — Pin Definitions for Meck Firmware
|
||||
//
|
||||
// nRF52840 + SX1262 + SSD1315 (72×40 OLED) + L76K GPS + MAX98357 Speaker
|
||||
// + MP34DT05 PDM Microphone + ICM20948 IMU + BQ25896 Charger + Solar
|
||||
//
|
||||
// Pin notation from LilyGo pinmap: (port, pin) → nRF GPIO = port*32 + pin
|
||||
// =============================================================================
|
||||
|
||||
#define LILYGO_TECHO_CARD
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// I2C Bus (shared: OLED, IMU ICM20948, fuel gauge BQ27220 if present)
|
||||
// -----------------------------------------------------------------------------
|
||||
#define I2C_SDA 36 // (1, 4)
|
||||
#define I2C_SCL 34 // (1, 2)
|
||||
#define PIN_BOARD_SDA I2C_SDA
|
||||
#define PIN_BOARD_SCL I2C_SCL
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// SX1262 LoRa Radio (SPI bit-bang on nRF52)
|
||||
// -----------------------------------------------------------------------------
|
||||
#define P_LORA_NSS 11 // (0, 11) — CS
|
||||
#define P_LORA_RESET 7 // (0, 7) — RST
|
||||
#define P_LORA_SCLK 13 // (0, 13) — SCK
|
||||
#define P_LORA_MOSI 15 // (0, 15) — MOSI
|
||||
#define P_LORA_MISO 17 // (0, 17) — MISO
|
||||
#define P_LORA_BUSY 14 // (0, 14) — BUSY
|
||||
#define P_LORA_DIO_1 40 // (1, 8) — DIO1 / interrupt
|
||||
|
||||
// RF switch control (HPB16B3 module)
|
||||
#define LORA_DIO2 5 // (0, 5) — DIO2 (TXCO / RF switch)
|
||||
#define LORA_RF_VC1 27 // (0, 27) — RF_VC1
|
||||
#define LORA_RF_VC2 33 // (1, 1) — RF_VC2
|
||||
|
||||
// LoRa radio power enable (from schematic: LORA_EN drives RT9080 for LORA_VDD)
|
||||
// NOTE: Confirm actual GPIO — pinmap shows dedicated enable pin
|
||||
// For now use -1 if always powered
|
||||
#define PIN_LORA_EN -1
|
||||
|
||||
// Default radio settings (Australia)
|
||||
#ifndef LORA_TX_POWER
|
||||
#define LORA_TX_POWER 22
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// 0.42" OLED Display — SSD1315 (SSD1306-compatible), 72×40, I2C
|
||||
// -----------------------------------------------------------------------------
|
||||
#define HAS_OLED 1
|
||||
#define OLED_I2C_ADDR 0x3C
|
||||
#define OLED_WIDTH 72
|
||||
#define OLED_HEIGHT 40
|
||||
#define OLED_SDA I2C_SDA
|
||||
#define OLED_SCL I2C_SCL
|
||||
|
||||
// OLED power control via RT9080 enable pin
|
||||
#define PIN_OLED_EN 30 // (0, 30) — RT9080_EN
|
||||
|
||||
// No hardware reset pin for OLED on T-Echo Card
|
||||
#define PIN_OLED_RESET -1
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// GPS — L76K Multi-GNSS (GPS, GLONASS, BeiDou, QZSS)
|
||||
// -----------------------------------------------------------------------------
|
||||
#define HAS_GPS 1
|
||||
#define GPS_BAUDRATE 9600
|
||||
#define PIN_GPS_TX 19 // (0, 19) — nRF TX → GPS RX
|
||||
#define PIN_GPS_RX 21 // (0, 21) — nRF RX ← GPS TX
|
||||
#define PIN_GPS_EN 47 // (1, 15) — GPS power enable
|
||||
#define PIN_GPS_WAKEUP 25 // (0, 25) — GPS wakeup
|
||||
#define PIN_GPS_1PPS 23 // (0, 23) — 1PPS time pulse
|
||||
#define PIN_GPS_RF_EN 29 // (0, 29) — GPS RF / LNA enable
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Battery & Power
|
||||
// -----------------------------------------------------------------------------
|
||||
#define PIN_VBAT_READ 2 // (0, 2) = AIN0 — battery voltage ADC
|
||||
#define BATTERY_ADC_AIN 0 // nRF SAADC AIN channel number
|
||||
#define BATTERY_CAPACITY_MAH 800
|
||||
|
||||
// Battery voltage divider calibration
|
||||
// The T-Echo Lite has issues reading battery correctly — we'll need to
|
||||
// calibrate this with actual hardware. Starting with a reasonable default.
|
||||
// nRF52840 SAADC: 0.6V internal ref, 1/6 gain → 0–3.6V range
|
||||
// If there's a voltage divider (e.g. 2:1), multiply by 2.
|
||||
// Adjust ADC_MULTIPLIER after measuring real voltage vs ADC reading.
|
||||
#ifndef ADC_MULTIPLIER
|
||||
#define ADC_MULTIPLIER 2.0f
|
||||
#endif
|
||||
|
||||
// BQ25896 charger is on I2C but managed by hardware — no software control needed
|
||||
// Solar panel input: 0.25W 5V via VBUS
|
||||
|
||||
// Auto-shutdown threshold (millivolts)
|
||||
#define AUTO_SHUTDOWN_MILLIVOLTS 3200
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Speaker — MAX98357 I2S Class-D Mono Amp (8Ω, 1W)
|
||||
// -----------------------------------------------------------------------------
|
||||
#define HAS_SPEAKER 1
|
||||
#define PIN_SPK_EN 43 // (1, 11) — speaker amplifier enable
|
||||
#define PIN_SPK_EN2 3 // (0, 3) — secondary enable
|
||||
#define PIN_SPK_BCLK 16 // (0, 16) — I2S bit clock
|
||||
#define PIN_SPK_DATA 20 // (0, 20) — I2S data out
|
||||
#define PIN_SPK_LRCK 22 // (0, 22) — I2S word select / LRCK
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Microphone — MP34DT05 Digital MEMS PDM
|
||||
// -----------------------------------------------------------------------------
|
||||
#define HAS_MICROPHONE 1
|
||||
#define PIN_MIC_CLK 35 // (1, 3) — PDM clock
|
||||
#define PIN_MIC_DATA 37 // (1, 5) — PDM data
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Buttons
|
||||
// -----------------------------------------------------------------------------
|
||||
#define PIN_BUTTON_A 42 // (1, 10) — orange button (front, main user button)
|
||||
#define PIN_BUTTON_BOOT 24 // (0, 24) — boot button (nRF52840 BOOT)
|
||||
#define PIN_USER_BTN PIN_BUTTON_A
|
||||
|
||||
// Button_B is RESET — hardware only, no GPIO
|
||||
|
||||
// Active LOW for nRF52 buttons (internal pull-up, press = LOW)
|
||||
#define BUTTON_ACTIVE_LOW 1
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Buzzer
|
||||
// -----------------------------------------------------------------------------
|
||||
#define HAS_BUZZER 1
|
||||
#define PIN_BUZZER 38 // (1, 6) — piezo buzzer data / PWM
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// WS2812 RGB LED (3 LEDs in series)
|
||||
// -----------------------------------------------------------------------------
|
||||
#define HAS_RGB_LED 1
|
||||
#define PIN_RGB_LED_1 39 // (1, 7) — WS2812 data 1
|
||||
#define PIN_RGB_LED_2 44 // (1, 12) — WS2812 data 2
|
||||
#define PIN_RGB_LED_3 28 // (0, 28) — WS2812 data 3
|
||||
// Typically only one data pin drives the chain; confirm wiring on hardware
|
||||
#define PIN_NEOPIXEL PIN_RGB_LED_1
|
||||
#define NUM_NEOPIXELS 3
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// IMU — ICM20948 9-axis MotionTracking (accelerometer + gyro + compass)
|
||||
// -----------------------------------------------------------------------------
|
||||
#define HAS_IMU 1
|
||||
#define IMU_I2C_ADDR 0x68
|
||||
#define IMU_SDA I2C_SDA
|
||||
#define IMU_SCL I2C_SCL
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// NFC — nRF52840 NFC-A (Type 2 Tag)
|
||||
// NFC uses dedicated NFC1/NFC2 pins on nRF52840 (P0.09 / P0.10)
|
||||
// These are fixed by silicon — no GPIO config needed.
|
||||
// NFC is handled by the nRF52 SDK nfc_t2t_lib.
|
||||
// -----------------------------------------------------------------------------
|
||||
#define HAS_NFC 1
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// External Flash — ZD25WQ32CEIGR (4MB SPI Flash)
|
||||
// Uses QSPI interface on nRF52840
|
||||
// Pin mapping from nRF52840 QSPI peripheral (typically fixed)
|
||||
// -----------------------------------------------------------------------------
|
||||
#define HAS_EXT_FLASH 1
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// No SD Card on T-Echo Card (unlike T-Echo which has e-paper + no SD either)
|
||||
// Settings stored in LittleFS on internal/external flash
|
||||
// -----------------------------------------------------------------------------
|
||||
// #define HAS_SDCARD
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// No dedicated RTC chip — time from GPS or BLE companion sync
|
||||
// nRF52840 has a 32.768 kHz RTC peripheral for timekeeping while running
|
||||
// -----------------------------------------------------------------------------
|
||||
// #define HAS_PCF85063_RTC
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Misc / Compatibility
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// No e-ink display
|
||||
// #define HAS_EINK
|
||||
|
||||
// This board has no physical keyboard
|
||||
// #define HAS_PHYSICAL_KEYBOARD
|
||||
|
||||
// Fallback for code that references GPS_BAUDRATE without HAS_GPS guard
|
||||
#ifndef GPS_BAUDRATE
|
||||
#define GPS_BAUDRATE 9600
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user