Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
15fcb08441 | ||
|
|
48863a13aa | ||
|
|
98addc5bd3 | ||
|
|
a10ce4e7ca | ||
|
|
dcb59f2e33 | ||
|
|
9e40dc7f30 | ||
|
|
5ed1edc287 | ||
|
|
ba057c8aad | ||
|
|
8e91327230 | ||
|
|
7444a34e5a | ||
|
|
17bad1ddf7 | ||
|
|
a4c86d2d31 | ||
|
|
8dd661246a | ||
|
|
f07032182e | ||
|
|
1d39d9f314 | ||
|
|
a4285d2f24 | ||
|
|
fad548b995 | ||
|
|
aa2e1af999 | ||
|
|
472b0ee662 | ||
|
|
1f5cbbd4db | ||
|
|
f451b49226 | ||
|
|
d10aa2c571 | ||
|
|
a2e099f095 | ||
|
|
e5e41ff50b | ||
|
|
2dc6977c20 | ||
|
|
5c540e9092 | ||
|
|
670efa75b0 | ||
|
|
3a486832c8 | ||
|
|
7f75ea8309 | ||
|
|
ddfe05ad20 | ||
|
|
d51ca6db0b | ||
|
|
3ab8191d19 | ||
|
|
546ce55c2b | ||
|
|
1f46bc1970 | ||
|
|
db8a73004e | ||
|
|
209a2f1693 |
78
Audiobook Player Guide.md
Normal file
78
Audiobook Player Guide.md
Normal file
@@ -0,0 +1,78 @@
|
||||
## Audiobook Player (Audio variant only)
|
||||
|
||||
Press **P** from the home screen to open the audiobook player.
|
||||
Place `.mp3`, `.m4b`, `.m4a`, or `.wav` files in `/audiobooks/` on the SD card.
|
||||
Files can be organised into subfolders (e.g. by author) — use **Enter** to
|
||||
browse into folders and **.. (up)** to go back.
|
||||
|
||||
| Key | Action |
|
||||
|-----|--------|
|
||||
| W / S | Scroll file list / Volume up-down |
|
||||
| Enter | Select book or folder / Play-Pause |
|
||||
| A | Seek back 30 seconds |
|
||||
| D | Seek forward 30 seconds |
|
||||
| [ | Previous chapter (M4B only) |
|
||||
| ] | Next chapter (M4B only) |
|
||||
| Q | Leave player (audio continues) / Close book (when paused) / Exit (from file list) |
|
||||
|
||||
### Recommended Format
|
||||
|
||||
**MP3 is the recommended format.** M4B/M4A files are supported but currently
|
||||
have playback issues with the ESP32-audioI2S library — some files may fail to
|
||||
decode or produce silence. MP3 files play reliably and are the safest choice.
|
||||
|
||||
MP3 files should be encoded at a **44100 Hz sample rate**. Lower sample rates
|
||||
(e.g. 22050 Hz) can cause distortion or playback failure due to ESP32-S3 I2S
|
||||
hardware limitations.
|
||||
|
||||
**Bookmarks** are saved automatically every 30 seconds during playback and when
|
||||
you stop or exit. Reopening a book resumes from your last position.
|
||||
|
||||
**Cover art** from M4B files is displayed as dithered monochrome on the e-ink
|
||||
screen, along with title, author, and chapter information.
|
||||
|
||||
**Metadata caching** — the first time you open the audiobook player, it reads
|
||||
title and author tags from each file (which can take a few seconds with many
|
||||
files). This metadata is cached to the SD card so subsequent visits load
|
||||
near-instantly. If you add or remove files the cache updates automatically.
|
||||
|
||||
### Background Playback
|
||||
|
||||
Audio continues playing when you leave the audiobook player screen. Press **Q**
|
||||
while audio is playing to return to the home screen — a **>>** indicator will
|
||||
appear in the status bar next to the battery icon to show that audio is active
|
||||
in the background. Press **P** at any time to return to the player screen and
|
||||
resume control.
|
||||
|
||||
If you pause or stop playback first and then press **Q**, the book is closed
|
||||
and you're returned to the file list instead.
|
||||
|
||||
### Audio Hardware
|
||||
|
||||
The audiobook player uses the PCM5102A I2S DAC on the audio variant of the
|
||||
T-Deck Pro (I2S pins: BCLK=7, DOUT=8, LRC=9). Audio is output via the 3.5mm
|
||||
headphone jack.
|
||||
|
||||
> **Note:** The audiobook player is not available on the 4G modem variant
|
||||
> due to I2S pin conflicts.
|
||||
|
||||
### SD Card Folder Structure
|
||||
|
||||
```
|
||||
SD Card
|
||||
├── audiobooks/
|
||||
│ ├── .bookmarks/ (auto-created, stores resume positions)
|
||||
│ │ ├── mybook.bmk
|
||||
│ │ └── another.bmk
|
||||
│ ├── .metacache (auto-created, speeds up file list loading)
|
||||
│ ├── Ann Leckie/
|
||||
│ │ ├── Ancillary Justice.mp3
|
||||
│ │ └── Ancillary Sword.mp3
|
||||
│ ├── Iain M. Banks/
|
||||
│ │ └── The Algebraist.mp3
|
||||
│ ├── mybook.mp3
|
||||
│ └── podcast.mp3
|
||||
├── books/ (existing — text reader)
|
||||
│ └── ...
|
||||
└── ...
|
||||
```
|
||||
@@ -525,11 +525,11 @@ void MyMesh::onCommandDataRecv(const ContactInfo &from, mesh::Packet *pkt, uint3
|
||||
queueMessage(from, TXT_TYPE_CLI_DATA, pkt, sender_timestamp, NULL, 0, text);
|
||||
|
||||
// Forward CLI response to UI admin screen if admin session is active
|
||||
#ifdef DISPLAY_CLASS
|
||||
#ifdef DISPLAY_CLASS
|
||||
if (_admin_contact_idx >= 0 && _ui) {
|
||||
_ui->onAdminCliResponse(from.name, text);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void MyMesh::onSignedMessageRecv(const ContactInfo &from, mesh::Packet *pkt, uint32_t sender_timestamp,
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
#define FIRMWARE_VER_CODE 8
|
||||
|
||||
#ifndef FIRMWARE_BUILD_DATE
|
||||
#define FIRMWARE_BUILD_DATE "15 Feb 2026"
|
||||
#define FIRMWARE_BUILD_DATE "17 Feb 2026"
|
||||
#endif
|
||||
|
||||
#ifndef FIRMWARE_VERSION
|
||||
#define FIRMWARE_VERSION "Meck v0.8.9"
|
||||
#define FIRMWARE_VERSION "Meck v0.9.1A-NB"
|
||||
#endif
|
||||
|
||||
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
||||
|
||||
@@ -48,6 +48,13 @@
|
||||
// Notes mode state
|
||||
static bool notesMode = false;
|
||||
|
||||
// Audiobook player — Audio object is heap-allocated on first use to avoid
|
||||
// consuming ~40KB of DMA/decode buffers at boot (starves BLE stack).
|
||||
#include "AudiobookPlayerScreen.h"
|
||||
#include "Audio.h"
|
||||
Audio* audio = nullptr;
|
||||
static bool audiobookMode = false;
|
||||
|
||||
// Power management
|
||||
#if HAS_GPS
|
||||
GPSDutyCycle gpsDuty;
|
||||
@@ -321,6 +328,9 @@ void setup() {
|
||||
}
|
||||
MESH_DEBUG_PRINTLN("setup() - radio_init() done");
|
||||
|
||||
// CPU frequency scaling — drop to 80 MHz for idle mesh listening
|
||||
cpuPower.begin();
|
||||
|
||||
MESH_DEBUG_PRINTLN("setup() - about to call fast_rng.begin()");
|
||||
fast_rng.begin(radio_get_rng_seed());
|
||||
MESH_DEBUG_PRINTLN("setup() - fast_rng.begin() done");
|
||||
@@ -405,7 +415,7 @@ void setup() {
|
||||
MESH_DEBUG_PRINTLN("setup() - SPIFFS.begin() done");
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Early SD card init  needed BEFORE the_mesh.begin() so we can restore
|
||||
// Early SD card init  needed BEFORE the_mesh.begin() so we can restore
|
||||
// settings from a previous firmware flash. The display SPI bus is already
|
||||
// up (display.begin() ran earlier), so SD can share it now.
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -519,6 +529,11 @@ void setup() {
|
||||
notesScr->setSDReady(true);
|
||||
}
|
||||
|
||||
// Audiobook player screen creation is deferred to first use (case 'p' in
|
||||
// handleKeyboardInput) to avoid allocating Audio I2S/DMA buffers at boot,
|
||||
// which would starve BLE of heap memory.
|
||||
MESH_DEBUG_PRINTLN("setup() - Audiobook player deferred (lazy init on first use)");
|
||||
|
||||
// Do an initial settings backup to SD (captures any first-boot defaults)
|
||||
backupSettingsToSD();
|
||||
}
|
||||
@@ -541,7 +556,7 @@ void setup() {
|
||||
}
|
||||
#endif
|
||||
|
||||
// GPS duty cycle  honour saved pref, default to enabled on first boot
|
||||
// GPS duty cycle — honour saved pref, default to enabled on first boot
|
||||
#if HAS_GPS
|
||||
{
|
||||
bool gps_wanted = the_mesh.getNodePrefs()->gps_enabled;
|
||||
@@ -556,9 +571,6 @@ void setup() {
|
||||
}
|
||||
#endif
|
||||
|
||||
// CPU frequency scaling  drop to 80 MHz for idle mesh listening
|
||||
cpuPower.begin();
|
||||
|
||||
// T-Deck Pro: BLE starts disabled for standalone-first operation
|
||||
// User can toggle it on from the Bluetooth home page (Enter or long-press)
|
||||
#if defined(LilyGo_TDeck_Pro) && defined(BLE_PIN_CODE)
|
||||
@@ -566,13 +578,15 @@ void setup() {
|
||||
MESH_DEBUG_PRINTLN("setup() - BLE disabled at boot (standalone mode)");
|
||||
#endif
|
||||
|
||||
Serial.printf("setup() complete — free heap: %d, largest block: %d\n",
|
||||
ESP.getFreeHeap(), ESP.getMaxAllocHeap());
|
||||
MESH_DEBUG_PRINTLN("=== setup() - COMPLETE ===");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
the_mesh.loop();
|
||||
|
||||
// GPS duty cycle  check for fix and manage power state
|
||||
// GPS duty cycle — check for fix and manage power state
|
||||
#if HAS_GPS
|
||||
{
|
||||
bool gps_hw_on = gpsDuty.loop();
|
||||
@@ -589,6 +603,19 @@ void loop() {
|
||||
|
||||
// CPU frequency auto-timeout back to idle
|
||||
cpuPower.loop();
|
||||
|
||||
// Audiobook: service audio decode regardless of which screen is active
|
||||
{
|
||||
AudiobookPlayerScreen* abPlayer =
|
||||
(AudiobookPlayerScreen*)ui_task.getAudiobookScreen();
|
||||
if (abPlayer) {
|
||||
abPlayer->audioTick();
|
||||
// Keep CPU at high freq during active audio decode
|
||||
if (abPlayer->isAudioActive()) {
|
||||
cpuPower.setBoost();
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef DISPLAY_CLASS
|
||||
// Skip UITask rendering when in compose mode to prevent flickering
|
||||
#if defined(LilyGo_TDeck_Pro)
|
||||
@@ -616,9 +643,10 @@ void loop() {
|
||||
composeNeedsRefresh = false;
|
||||
}
|
||||
}
|
||||
// Track reader/notes mode state for key routing
|
||||
// Track reader/notes/audiobook mode state for key routing
|
||||
readerMode = ui_task.isOnTextReader();
|
||||
notesMode = ui_task.isOnNotesScreen();
|
||||
audiobookMode = ui_task.isOnAudiobookPlayer();
|
||||
#else
|
||||
ui_task.loop();
|
||||
#endif
|
||||
@@ -808,6 +836,40 @@ void handleKeyboardInput() {
|
||||
return;
|
||||
}
|
||||
|
||||
// *** AUDIOBOOK MODE ***
|
||||
if (audiobookMode) {
|
||||
AudiobookPlayerScreen* abPlayer =
|
||||
(AudiobookPlayerScreen*)ui_task.getAudiobookScreen();
|
||||
|
||||
// Q key: behavior depends on playback state
|
||||
// - Playing: navigate home, audio continues in background
|
||||
// - Paused/stopped: close book, return to file list
|
||||
// - File list: exit player entirely
|
||||
if (key == 'q') {
|
||||
if (abPlayer->isBookOpen()) {
|
||||
if (abPlayer->isAudioActive()) {
|
||||
// Audio is playing — leave screen, audio continues via audioTick()
|
||||
Serial.println("Leaving audiobook player (audio continues in background)");
|
||||
ui_task.gotoHomeScreen();
|
||||
} else {
|
||||
// Paused or stopped — close book, show file list
|
||||
abPlayer->closeCurrentBook();
|
||||
Serial.println("Closed audiobook (was paused/stopped)");
|
||||
// Stay on audiobook screen showing file list
|
||||
}
|
||||
} else {
|
||||
abPlayer->exitPlayer();
|
||||
Serial.println("Exiting audiobook player");
|
||||
ui_task.gotoHomeScreen();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// All other keys pass through to the player screen
|
||||
ui_task.injectKey(key);
|
||||
return;
|
||||
}
|
||||
|
||||
// *** TEXT READER MODE ***
|
||||
if (readerMode) {
|
||||
TextReaderScreen* reader = (TextReaderScreen*)ui_task.getTextReaderScreen();
|
||||
@@ -983,7 +1045,7 @@ void handleKeyboardInput() {
|
||||
return;
|
||||
}
|
||||
|
||||
// All other keys → settings screen via injectKey
|
||||
// All other keys → settings screen via injectKey
|
||||
ui_task.injectKey(key);
|
||||
return;
|
||||
}
|
||||
@@ -1058,6 +1120,21 @@ void handleKeyboardInput() {
|
||||
ui_task.gotoTextReader();
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
// Open audiobook player — lazy-init Audio + screen on first use
|
||||
Serial.println("Opening audiobook player");
|
||||
if (!ui_task.getAudiobookScreen()) {
|
||||
Serial.printf("Audiobook: lazy init — free heap: %d, largest block: %d\n",
|
||||
ESP.getFreeHeap(), ESP.getMaxAllocHeap());
|
||||
audio = new Audio();
|
||||
AudiobookPlayerScreen* abScreen = new AudiobookPlayerScreen(&ui_task, audio);
|
||||
abScreen->setSDReady(sdCardReady);
|
||||
ui_task.setAudiobookScreen(abScreen);
|
||||
Serial.printf("Audiobook: init complete — free heap: %d\n", ESP.getFreeHeap());
|
||||
}
|
||||
ui_task.gotoAudiobookPlayer();
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
// Open notes
|
||||
Serial.println("Opening notes");
|
||||
@@ -1114,7 +1191,7 @@ void handleKeyboardInput() {
|
||||
|
||||
case '\r':
|
||||
// Select/Enter - if on contacts screen, enter DM compose for chat contacts
|
||||
// or repeater admin for repeater contacts
|
||||
// or repeater admin for repeater contacts
|
||||
if (ui_task.isOnContactsScreen()) {
|
||||
ContactsScreen* cs = (ContactsScreen*)ui_task.getContactsScreen();
|
||||
int idx = cs->getSelectedContactIdx();
|
||||
@@ -1367,4 +1444,23 @@ void sendComposedMessage() {
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// ESP32-audioI2S CALLBACKS
|
||||
// ============================================================================
|
||||
// The audio library calls these global functions — must be defined at file scope.
|
||||
|
||||
void audio_info(const char *info) {
|
||||
Serial.printf("Audio: %s\n", info);
|
||||
}
|
||||
|
||||
void audio_eof_mp3(const char *info) {
|
||||
Serial.printf("Audio: End of file - %s\n", info);
|
||||
// Signal the player screen for auto-advance to next track
|
||||
AudiobookPlayerScreen* abPlayer =
|
||||
(AudiobookPlayerScreen*)ui_task.getAudiobookScreen();
|
||||
if (abPlayer) {
|
||||
abPlayer->onEOF();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // LilyGo_TDeck_Pro
|
||||
1802
examples/companion_radio/ui-new/Audiobookplayerscreen.h
Normal file
1802
examples/companion_radio/ui-new/Audiobookplayerscreen.h
Normal file
File diff suppressed because it is too large
Load Diff
@@ -30,7 +30,7 @@ private:
|
||||
|
||||
// Cached filtered contact indices for efficient scrolling
|
||||
// We rebuild this on filter change or when entering the screen
|
||||
static const int MAX_VISIBLE = 400; // matches MAX_CONTACTS build flag
|
||||
static const int MAX_VISIBLE = 700; // must be >= MAX_CONTACTS build flag
|
||||
uint16_t _filteredIdx[MAX_VISIBLE]; // indices into contact table
|
||||
uint32_t _filteredTs[MAX_VISIBLE]; // cached last_advert_timestamp for sorting
|
||||
int _filteredCount; // how many contacts match current filter
|
||||
@@ -88,7 +88,7 @@ private:
|
||||
}
|
||||
}
|
||||
// Sort by last_advert_timestamp descending (most recently seen first)
|
||||
// Simple insertion sort — fine for up to 400 entries on ESP32
|
||||
// Simple insertion sort - fine for up to 700 entries on ESP32
|
||||
for (int i = 1; i < _filteredCount; i++) {
|
||||
uint16_t tmpIdx = _filteredIdx[i];
|
||||
uint32_t tmpTs = _filteredTs[i];
|
||||
|
||||
651
examples/companion_radio/ui-new/M4BMetadata.h
Normal file
651
examples/companion_radio/ui-new/M4BMetadata.h
Normal file
@@ -0,0 +1,651 @@
|
||||
#pragma once
|
||||
|
||||
// =============================================================================
|
||||
// M4BMetadata.h - Lightweight MP4/M4B atom parser for metadata extraction
|
||||
//
|
||||
// Walks the MP4 atom (box) tree to extract:
|
||||
// - Title (moov/udta/meta/ilst/©nam)
|
||||
// - Author (moov/udta/meta/ilst/©ART)
|
||||
// - Cover art (moov/udta/meta/ilst/covr) - JPEG offset+size within file
|
||||
// - Duration (moov/mvhd timescale + duration)
|
||||
// - Chapter markers (moov/udta/chpl) - Nero-style chapter list
|
||||
//
|
||||
// Designed for embedded use: no dynamic allocation, reads directly from SD
|
||||
// via Arduino File API, uses a small stack buffer for atom headers.
|
||||
//
|
||||
// Usage:
|
||||
// M4BMetadata meta;
|
||||
// File f = SD.open("/audiobooks/mybook.m4b");
|
||||
// if (meta.parse(f)) {
|
||||
// Serial.printf("Title: %s\n", meta.title);
|
||||
// Serial.printf("Author: %s\n", meta.author);
|
||||
// if (meta.hasCoverArt) {
|
||||
// // JPEG data is at meta.coverOffset, meta.coverSize bytes
|
||||
// }
|
||||
// }
|
||||
// f.close();
|
||||
// =============================================================================
|
||||
|
||||
#include <SD.h>
|
||||
|
||||
// Maximum metadata string lengths (including null terminator)
|
||||
#define M4B_MAX_TITLE 128
|
||||
#define M4B_MAX_AUTHOR 64
|
||||
#define M4B_MAX_CHAPTERS 100
|
||||
|
||||
struct M4BChapter {
|
||||
uint32_t startMs; // Chapter start time in milliseconds
|
||||
char name[48]; // Chapter title (truncated to fit)
|
||||
};
|
||||
|
||||
class M4BMetadata {
|
||||
public:
|
||||
// Extracted metadata
|
||||
char title[M4B_MAX_TITLE];
|
||||
char author[M4B_MAX_AUTHOR];
|
||||
bool hasCoverArt;
|
||||
uint32_t coverOffset; // Byte offset of JPEG/PNG data within file
|
||||
uint32_t coverSize; // Size of cover image data in bytes
|
||||
uint8_t coverFormat; // 13=JPEG, 14=PNG (from MP4 well-known type)
|
||||
uint32_t durationMs; // Total duration in milliseconds
|
||||
uint32_t sampleRate; // Audio sample rate (from audio stsd)
|
||||
uint32_t bitrate; // Approximate bitrate in bps
|
||||
|
||||
// Chapter data
|
||||
M4BChapter chapters[M4B_MAX_CHAPTERS];
|
||||
int chapterCount;
|
||||
|
||||
M4BMetadata() { clear(); }
|
||||
|
||||
void clear() {
|
||||
title[0] = '\0';
|
||||
author[0] = '\0';
|
||||
hasCoverArt = false;
|
||||
coverOffset = 0;
|
||||
coverSize = 0;
|
||||
coverFormat = 0;
|
||||
durationMs = 0;
|
||||
sampleRate = 44100;
|
||||
bitrate = 0;
|
||||
chapterCount = 0;
|
||||
}
|
||||
|
||||
// Parse an open file. Returns true if at least title or duration was found.
|
||||
// File position is NOT preserved — caller should seek as needed afterward.
|
||||
bool parse(File& file) {
|
||||
clear();
|
||||
if (!file || file.size() < 8) return false;
|
||||
|
||||
_fileSize = file.size();
|
||||
|
||||
// Walk top-level atoms looking for 'moov'
|
||||
uint32_t pos = 0;
|
||||
while (pos < _fileSize) {
|
||||
AtomHeader hdr;
|
||||
if (!readAtomHeader(file, pos, hdr)) break;
|
||||
if (hdr.size < 8) break;
|
||||
|
||||
if (hdr.type == ATOM_MOOV) {
|
||||
parseMoov(file, hdr.dataOffset, hdr.dataOffset + hdr.dataSize);
|
||||
break; // moov found and parsed, we're done
|
||||
}
|
||||
|
||||
// Skip to next top-level atom
|
||||
pos += hdr.size;
|
||||
if (hdr.size == 0) break; // size=0 means "extends to EOF"
|
||||
}
|
||||
|
||||
return (title[0] != '\0' || durationMs > 0);
|
||||
}
|
||||
|
||||
// Get chapter index for a given playback position (milliseconds).
|
||||
// Returns -1 if no chapters or position is before first chapter.
|
||||
int getChapterForPosition(uint32_t positionMs) const {
|
||||
if (chapterCount == 0) return -1;
|
||||
int ch = 0;
|
||||
for (int i = 1; i < chapterCount; i++) {
|
||||
if (chapters[i].startMs > positionMs) break;
|
||||
ch = i;
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
|
||||
// Get the start position of the next chapter after the given position.
|
||||
// Returns 0 if no next chapter.
|
||||
uint32_t getNextChapterMs(uint32_t positionMs) const {
|
||||
for (int i = 0; i < chapterCount; i++) {
|
||||
if (chapters[i].startMs > positionMs) return chapters[i].startMs;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get the start position of the current or previous chapter.
|
||||
uint32_t getPrevChapterMs(uint32_t positionMs) const {
|
||||
uint32_t prev = 0;
|
||||
for (int i = 0; i < chapterCount; i++) {
|
||||
if (chapters[i].startMs >= positionMs) break;
|
||||
prev = chapters[i].startMs;
|
||||
}
|
||||
return prev;
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t _fileSize;
|
||||
|
||||
// MP4 atom type codes (big-endian FourCC)
|
||||
static constexpr uint32_t ATOM_MOOV = 0x6D6F6F76; // 'moov'
|
||||
static constexpr uint32_t ATOM_MVHD = 0x6D766864; // 'mvhd'
|
||||
static constexpr uint32_t ATOM_UDTA = 0x75647461; // 'udta'
|
||||
static constexpr uint32_t ATOM_META = 0x6D657461; // 'meta'
|
||||
static constexpr uint32_t ATOM_ILST = 0x696C7374; // 'ilst'
|
||||
static constexpr uint32_t ATOM_NAM = 0xA96E616D; // '©nam'
|
||||
static constexpr uint32_t ATOM_ART = 0xA9415254; // '©ART'
|
||||
static constexpr uint32_t ATOM_COVR = 0x636F7672; // 'covr'
|
||||
static constexpr uint32_t ATOM_DATA = 0x64617461; // 'data'
|
||||
static constexpr uint32_t ATOM_CHPL = 0x6368706C; // 'chpl' (Nero chapters)
|
||||
static constexpr uint32_t ATOM_TRAK = 0x7472616B; // 'trak'
|
||||
static constexpr uint32_t ATOM_MDIA = 0x6D646961; // 'mdia'
|
||||
static constexpr uint32_t ATOM_MDHD = 0x6D646864; // 'mdhd'
|
||||
static constexpr uint32_t ATOM_HDLR = 0x68646C72; // 'hdlr'
|
||||
|
||||
struct AtomHeader {
|
||||
uint32_t type;
|
||||
uint64_t size; // Total atom size including header
|
||||
uint32_t dataOffset; // File offset where data begins (after header)
|
||||
uint64_t dataSize; // size - header_length
|
||||
};
|
||||
|
||||
// Read a 32-bit big-endian value from file at current position
|
||||
static uint32_t readU32BE(File& file) {
|
||||
uint8_t buf[4];
|
||||
file.read(buf, 4);
|
||||
return ((uint32_t)buf[0] << 24) | ((uint32_t)buf[1] << 16) |
|
||||
((uint32_t)buf[2] << 8) | buf[3];
|
||||
}
|
||||
|
||||
// Read a 64-bit big-endian value
|
||||
static uint64_t readU64BE(File& file) {
|
||||
uint32_t hi = readU32BE(file);
|
||||
uint32_t lo = readU32BE(file);
|
||||
return ((uint64_t)hi << 32) | lo;
|
||||
}
|
||||
|
||||
// Read a 16-bit big-endian value
|
||||
static uint16_t readU16BE(File& file) {
|
||||
uint8_t buf[2];
|
||||
file.read(buf, 2);
|
||||
return ((uint16_t)buf[0] << 8) | buf[1];
|
||||
}
|
||||
|
||||
// Read atom header at given file offset
|
||||
bool readAtomHeader(File& file, uint32_t offset, AtomHeader& hdr) {
|
||||
if (offset + 8 > _fileSize) return false;
|
||||
|
||||
file.seek(offset);
|
||||
uint32_t size32 = readU32BE(file);
|
||||
hdr.type = readU32BE(file);
|
||||
|
||||
if (size32 == 1) {
|
||||
// 64-bit extended size
|
||||
if (offset + 16 > _fileSize) return false;
|
||||
hdr.size = readU64BE(file);
|
||||
hdr.dataOffset = offset + 16;
|
||||
hdr.dataSize = (hdr.size > 16) ? hdr.size - 16 : 0;
|
||||
} else if (size32 == 0) {
|
||||
// Atom extends to end of file
|
||||
hdr.size = _fileSize - offset;
|
||||
hdr.dataOffset = offset + 8;
|
||||
hdr.dataSize = hdr.size - 8;
|
||||
} else {
|
||||
hdr.size = size32;
|
||||
hdr.dataOffset = offset + 8;
|
||||
hdr.dataSize = (size32 > 8) ? size32 - 8 : 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Parse the moov container atom
|
||||
void parseMoov(File& file, uint32_t start, uint32_t end) {
|
||||
uint32_t pos = start;
|
||||
while (pos < end) {
|
||||
AtomHeader hdr;
|
||||
if (!readAtomHeader(file, pos, hdr)) break;
|
||||
if (hdr.size < 8) break;
|
||||
|
||||
switch (hdr.type) {
|
||||
case ATOM_MVHD:
|
||||
parseMvhd(file, hdr.dataOffset, (uint32_t)hdr.dataSize);
|
||||
break;
|
||||
case ATOM_UDTA:
|
||||
parseUdta(file, hdr.dataOffset, hdr.dataOffset + (uint32_t)hdr.dataSize);
|
||||
break;
|
||||
case ATOM_TRAK:
|
||||
break;
|
||||
}
|
||||
|
||||
pos += (uint32_t)hdr.size;
|
||||
}
|
||||
}
|
||||
|
||||
// Parse mvhd (movie header) for duration
|
||||
void parseMvhd(File& file, uint32_t offset, uint32_t size) {
|
||||
file.seek(offset);
|
||||
uint8_t version = file.read();
|
||||
|
||||
if (version == 0) {
|
||||
file.seek(offset + 4); // skip version(1) + flags(3)
|
||||
/* create_time */ readU32BE(file);
|
||||
/* modify_time */ readU32BE(file);
|
||||
uint32_t timescale = readU32BE(file);
|
||||
uint32_t duration = readU32BE(file);
|
||||
if (timescale > 0) {
|
||||
durationMs = (uint32_t)((uint64_t)duration * 1000 / timescale);
|
||||
}
|
||||
} else if (version == 1) {
|
||||
file.seek(offset + 4);
|
||||
/* create_time */ readU64BE(file);
|
||||
/* modify_time */ readU64BE(file);
|
||||
uint32_t timescale = readU32BE(file);
|
||||
uint64_t duration = readU64BE(file);
|
||||
if (timescale > 0) {
|
||||
durationMs = (uint32_t)(duration * 1000 / timescale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Parse udta container — contains meta and/or chpl
|
||||
void parseUdta(File& file, uint32_t start, uint32_t end) {
|
||||
uint32_t pos = start;
|
||||
while (pos < end) {
|
||||
AtomHeader hdr;
|
||||
if (!readAtomHeader(file, pos, hdr)) break;
|
||||
if (hdr.size < 8) break;
|
||||
|
||||
if (hdr.type == ATOM_META) {
|
||||
parseMeta(file, hdr.dataOffset + 4,
|
||||
hdr.dataOffset + (uint32_t)hdr.dataSize);
|
||||
} else if (hdr.type == ATOM_CHPL) {
|
||||
parseChpl(file, hdr.dataOffset, (uint32_t)hdr.dataSize);
|
||||
}
|
||||
|
||||
pos += (uint32_t)hdr.size;
|
||||
}
|
||||
}
|
||||
|
||||
// Parse meta container — contains hdlr + ilst
|
||||
void parseMeta(File& file, uint32_t start, uint32_t end) {
|
||||
uint32_t pos = start;
|
||||
while (pos < end) {
|
||||
AtomHeader hdr;
|
||||
if (!readAtomHeader(file, pos, hdr)) break;
|
||||
if (hdr.size < 8) break;
|
||||
|
||||
if (hdr.type == ATOM_ILST) {
|
||||
parseIlst(file, hdr.dataOffset, hdr.dataOffset + (uint32_t)hdr.dataSize);
|
||||
}
|
||||
|
||||
pos += (uint32_t)hdr.size;
|
||||
}
|
||||
}
|
||||
|
||||
// Parse ilst (iTunes metadata list) — contains ©nam, ©ART, covr etc.
|
||||
void parseIlst(File& file, uint32_t start, uint32_t end) {
|
||||
uint32_t pos = start;
|
||||
while (pos < end) {
|
||||
AtomHeader hdr;
|
||||
if (!readAtomHeader(file, pos, hdr)) break;
|
||||
if (hdr.size < 8) break;
|
||||
|
||||
switch (hdr.type) {
|
||||
case ATOM_NAM:
|
||||
extractTextData(file, hdr.dataOffset,
|
||||
hdr.dataOffset + (uint32_t)hdr.dataSize,
|
||||
title, M4B_MAX_TITLE);
|
||||
break;
|
||||
case ATOM_ART:
|
||||
extractTextData(file, hdr.dataOffset,
|
||||
hdr.dataOffset + (uint32_t)hdr.dataSize,
|
||||
author, M4B_MAX_AUTHOR);
|
||||
break;
|
||||
case ATOM_COVR:
|
||||
extractCoverData(file, hdr.dataOffset,
|
||||
hdr.dataOffset + (uint32_t)hdr.dataSize);
|
||||
break;
|
||||
}
|
||||
|
||||
pos += (uint32_t)hdr.size;
|
||||
}
|
||||
}
|
||||
|
||||
// Extract text from a 'data' sub-atom within an ilst entry.
|
||||
void extractTextData(File& file, uint32_t start, uint32_t end,
|
||||
char* dest, int maxLen) {
|
||||
uint32_t pos = start;
|
||||
while (pos < end) {
|
||||
AtomHeader hdr;
|
||||
if (!readAtomHeader(file, pos, hdr)) break;
|
||||
if (hdr.size < 8) break;
|
||||
|
||||
if (hdr.type == ATOM_DATA && hdr.dataSize > 8) {
|
||||
uint32_t textOffset = hdr.dataOffset + 8;
|
||||
uint32_t textLen = (uint32_t)hdr.dataSize - 8;
|
||||
if (textLen > (uint32_t)(maxLen - 1)) textLen = maxLen - 1;
|
||||
|
||||
file.seek(textOffset);
|
||||
file.read((uint8_t*)dest, textLen);
|
||||
dest[textLen] = '\0';
|
||||
return;
|
||||
}
|
||||
|
||||
pos += (uint32_t)hdr.size;
|
||||
}
|
||||
}
|
||||
|
||||
// Extract cover art location from 'data' sub-atom within covr.
|
||||
void extractCoverData(File& file, uint32_t start, uint32_t end) {
|
||||
uint32_t pos = start;
|
||||
while (pos < end) {
|
||||
AtomHeader hdr;
|
||||
if (!readAtomHeader(file, pos, hdr)) break;
|
||||
if (hdr.size < 8) break;
|
||||
|
||||
if (hdr.type == ATOM_DATA && hdr.dataSize > 8) {
|
||||
file.seek(hdr.dataOffset);
|
||||
uint32_t typeIndicator = readU32BE(file);
|
||||
uint8_t wellKnownType = typeIndicator & 0xFF;
|
||||
|
||||
coverOffset = hdr.dataOffset + 8;
|
||||
coverSize = (uint32_t)hdr.dataSize - 8;
|
||||
coverFormat = wellKnownType; // 13=JPEG, 14=PNG
|
||||
hasCoverArt = (coverSize > 0);
|
||||
|
||||
Serial.printf("M4B: Cover art found - %s, %u bytes at offset %u\n",
|
||||
wellKnownType == 13 ? "JPEG" :
|
||||
wellKnownType == 14 ? "PNG" : "unknown",
|
||||
coverSize, coverOffset);
|
||||
return;
|
||||
}
|
||||
|
||||
pos += (uint32_t)hdr.size;
|
||||
}
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// ID3v2 Parser for MP3 files
|
||||
// =====================================================================
|
||||
public:
|
||||
// Parse ID3v2 tags from an MP3 file. Extracts title (TIT2), artist
|
||||
// (TPE1), and cover art (APIC). Fills the same metadata fields as
|
||||
// the M4B parser so decodeCoverArt() works unchanged.
|
||||
bool parseID3v2(File& file) {
|
||||
clear();
|
||||
if (!file || file.size() < 10) return false;
|
||||
|
||||
file.seek(0);
|
||||
uint8_t hdr[10];
|
||||
if (file.read(hdr, 10) != 10) return false;
|
||||
|
||||
// Verify "ID3" magic
|
||||
if (hdr[0] != 'I' || hdr[1] != 'D' || hdr[2] != '3') {
|
||||
Serial.println("ID3: No ID3v2 header found");
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t versionMajor = hdr[3]; // 3 = ID3v2.3, 4 = ID3v2.4
|
||||
bool v24 = (versionMajor == 4);
|
||||
bool hasExtHeader = (hdr[5] & 0x40) != 0;
|
||||
|
||||
// Tag size is syncsafe integer (4 x 7-bit bytes)
|
||||
uint32_t tagSize = ((uint32_t)(hdr[6] & 0x7F) << 21) |
|
||||
((uint32_t)(hdr[7] & 0x7F) << 14) |
|
||||
((uint32_t)(hdr[8] & 0x7F) << 7) |
|
||||
(hdr[9] & 0x7F);
|
||||
|
||||
uint32_t tagEnd = 10 + tagSize;
|
||||
if (tagEnd > file.size()) tagEnd = file.size();
|
||||
|
||||
Serial.printf("ID3: v2.%d, %u bytes\n", versionMajor, tagSize);
|
||||
|
||||
// Skip extended header if present
|
||||
uint32_t pos = 10;
|
||||
if (hasExtHeader && pos + 4 < tagEnd) {
|
||||
file.seek(pos);
|
||||
uint32_t extSize;
|
||||
if (v24) {
|
||||
uint8_t eb[4];
|
||||
file.read(eb, 4);
|
||||
extSize = ((uint32_t)(eb[0] & 0x7F) << 21) |
|
||||
((uint32_t)(eb[1] & 0x7F) << 14) |
|
||||
((uint32_t)(eb[2] & 0x7F) << 7) |
|
||||
(eb[3] & 0x7F);
|
||||
} else {
|
||||
extSize = readU32BE(file) + 4;
|
||||
}
|
||||
pos += extSize;
|
||||
}
|
||||
|
||||
// Walk ID3v2 frames
|
||||
bool foundTitle = false, foundArtist = false, foundCover = false;
|
||||
|
||||
while (pos + 10 < tagEnd) {
|
||||
file.seek(pos);
|
||||
uint8_t fhdr[10];
|
||||
if (file.read(fhdr, 10) != 10) break;
|
||||
|
||||
if (fhdr[0] == 0) break;
|
||||
|
||||
char frameId[5] = { (char)fhdr[0], (char)fhdr[1],
|
||||
(char)fhdr[2], (char)fhdr[3], '\0' };
|
||||
|
||||
uint32_t frameSize;
|
||||
if (v24) {
|
||||
frameSize = ((uint32_t)(fhdr[4] & 0x7F) << 21) |
|
||||
((uint32_t)(fhdr[5] & 0x7F) << 14) |
|
||||
((uint32_t)(fhdr[6] & 0x7F) << 7) |
|
||||
(fhdr[7] & 0x7F);
|
||||
} else {
|
||||
frameSize = ((uint32_t)fhdr[4] << 24) | ((uint32_t)fhdr[5] << 16) |
|
||||
((uint32_t)fhdr[6] << 8) | fhdr[7];
|
||||
}
|
||||
|
||||
if (frameSize == 0 || pos + 10 + frameSize > tagEnd) break;
|
||||
|
||||
uint32_t dataStart = pos + 10;
|
||||
|
||||
// --- TIT2 (Title) ---
|
||||
if (!foundTitle && strcmp(frameId, "TIT2") == 0 && frameSize > 1) {
|
||||
id3ExtractText(file, dataStart, frameSize, title, M4B_MAX_TITLE);
|
||||
foundTitle = (title[0] != '\0');
|
||||
}
|
||||
// --- TPE1 (Artist/Author) ---
|
||||
if (!foundArtist && strcmp(frameId, "TPE1") == 0 && frameSize > 1) {
|
||||
id3ExtractText(file, dataStart, frameSize, author, M4B_MAX_AUTHOR);
|
||||
foundArtist = (author[0] != '\0');
|
||||
}
|
||||
// --- APIC (Attached Picture) ---
|
||||
if (!foundCover && strcmp(frameId, "APIC") == 0 && frameSize > 20) {
|
||||
id3ExtractAPIC(file, dataStart, frameSize);
|
||||
foundCover = hasCoverArt;
|
||||
}
|
||||
|
||||
pos = dataStart + frameSize;
|
||||
|
||||
// Early exit once we have everything
|
||||
if (foundTitle && foundArtist && foundCover) break;
|
||||
}
|
||||
|
||||
if (foundTitle) Serial.printf("ID3: Title: %s\n", title);
|
||||
if (foundArtist) Serial.printf("ID3: Author: %s\n", author);
|
||||
return (foundTitle || foundCover);
|
||||
}
|
||||
|
||||
private:
|
||||
// Extract text from a TIT2/TPE1 frame.
|
||||
// Format: encoding(1) + text data
|
||||
void id3ExtractText(File& file, uint32_t offset, uint32_t size,
|
||||
char* dest, int maxLen) {
|
||||
file.seek(offset);
|
||||
uint8_t encoding = file.read();
|
||||
uint32_t textLen = size - 1;
|
||||
if (textLen == 0) return;
|
||||
|
||||
if (encoding == 0 || encoding == 3) {
|
||||
// ISO-8859-1 or UTF-8 — read directly
|
||||
uint32_t readLen = (textLen < (uint32_t)(maxLen - 1))
|
||||
? textLen : (uint32_t)(maxLen - 1);
|
||||
file.read((uint8_t*)dest, readLen);
|
||||
dest[readLen] = '\0';
|
||||
// Strip trailing nulls
|
||||
while (readLen > 0 && dest[readLen - 1] == '\0') readLen--;
|
||||
dest[readLen] = '\0';
|
||||
}
|
||||
else if (encoding == 1 || encoding == 2) {
|
||||
// UTF-16 (with or without BOM) — crude ASCII extraction
|
||||
// Static buffer to avoid stack overflow (loopTask has limited stack)
|
||||
static uint8_t u16buf[128];
|
||||
uint32_t readLen = (textLen > sizeof(u16buf)) ? sizeof(u16buf) : textLen;
|
||||
file.read(u16buf, readLen);
|
||||
|
||||
uint32_t srcStart = 0;
|
||||
// Skip BOM if present
|
||||
if (readLen >= 2 && ((u16buf[0] == 0xFF && u16buf[1] == 0xFE) ||
|
||||
(u16buf[0] == 0xFE && u16buf[1] == 0xFF))) {
|
||||
srcStart = 2;
|
||||
}
|
||||
bool littleEndian = (srcStart >= 2 && u16buf[0] == 0xFF);
|
||||
|
||||
int dstIdx = 0;
|
||||
for (uint32_t i = srcStart; i + 1 < readLen && dstIdx < maxLen - 1; i += 2) {
|
||||
uint8_t lo = littleEndian ? u16buf[i] : u16buf[i + 1];
|
||||
uint8_t hi = littleEndian ? u16buf[i + 1] : u16buf[i];
|
||||
if (lo == 0 && hi == 0) break; // null terminator
|
||||
if (hi == 0 && lo >= 0x20 && lo < 0x7F) {
|
||||
dest[dstIdx++] = (char)lo;
|
||||
} else {
|
||||
dest[dstIdx++] = '?';
|
||||
}
|
||||
}
|
||||
dest[dstIdx] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
// Extract APIC (cover art) frame.
|
||||
// Format: encoding(1) + MIME(null-term) + picType(1) + desc(null-term) + imageData
|
||||
void id3ExtractAPIC(File& file, uint32_t offset, uint32_t frameSize) {
|
||||
file.seek(offset);
|
||||
uint8_t encoding = file.read();
|
||||
|
||||
// Read MIME type (null-terminated ASCII)
|
||||
char mime[32] = {0};
|
||||
int mimeLen = 0;
|
||||
while (mimeLen < 31) {
|
||||
int b = file.read();
|
||||
if (b < 0) return; // Read error
|
||||
if (b == 0) break; // Null terminator = end of MIME string
|
||||
mime[mimeLen++] = (char)b;
|
||||
}
|
||||
mime[mimeLen] = '\0';
|
||||
|
||||
// Picture type (1 byte)
|
||||
uint8_t picType = file.read();
|
||||
(void)picType;
|
||||
|
||||
// Skip description (null-terminated, encoding-dependent)
|
||||
if (encoding == 0 || encoding == 3) {
|
||||
// Single-byte null terminator
|
||||
while (true) {
|
||||
int b = file.read();
|
||||
if (b < 0) return; // Read error
|
||||
if (b == 0) break; // Null terminator
|
||||
}
|
||||
} else {
|
||||
// UTF-16: double-null terminator
|
||||
while (true) {
|
||||
int b1 = file.read();
|
||||
int b2 = file.read();
|
||||
if (b1 < 0 || b2 < 0) return; // Read error
|
||||
if (b1 == 0 && b2 == 0) break; // Double-null terminator
|
||||
}
|
||||
}
|
||||
|
||||
// Everything from here to end of frame is image data
|
||||
uint32_t imgOffset = file.position();
|
||||
uint32_t imgEnd = offset + frameSize;
|
||||
if (imgOffset >= imgEnd) return;
|
||||
|
||||
uint32_t imgSize = imgEnd - imgOffset;
|
||||
|
||||
// Determine format from MIME type
|
||||
bool isJpeg = (strstr(mime, "jpeg") || strstr(mime, "jpg"));
|
||||
bool isPng = (strstr(mime, "png") != nullptr);
|
||||
|
||||
// Also detect by magic bytes if MIME is generic
|
||||
if (!isJpeg && !isPng && imgSize > 4) {
|
||||
file.seek(imgOffset);
|
||||
uint8_t magic[4];
|
||||
file.read(magic, 4);
|
||||
if (magic[0] == 0xFF && magic[1] == 0xD8) isJpeg = true;
|
||||
else if (magic[0] == 0x89 && magic[1] == 'P' &&
|
||||
magic[2] == 'N' && magic[3] == 'G') isPng = true;
|
||||
}
|
||||
|
||||
coverOffset = imgOffset;
|
||||
coverSize = imgSize;
|
||||
coverFormat = isJpeg ? 13 : (isPng ? 14 : 0);
|
||||
hasCoverArt = (imgSize > 100 && (isJpeg || isPng));
|
||||
|
||||
if (hasCoverArt) {
|
||||
Serial.printf("ID3: Cover %s, %u bytes\n",
|
||||
isJpeg ? "JPEG" : "PNG", imgSize);
|
||||
}
|
||||
}
|
||||
|
||||
// Parse Nero-style chapter list (chpl atom).
|
||||
void parseChpl(File& file, uint32_t offset, uint32_t size) {
|
||||
if (size < 9) return;
|
||||
|
||||
file.seek(offset);
|
||||
uint8_t version = file.read();
|
||||
file.read(); // flags byte 1
|
||||
file.read(); // flags byte 2
|
||||
file.read(); // flags byte 3
|
||||
|
||||
file.read(); // reserved
|
||||
|
||||
uint32_t count;
|
||||
if (version == 1) {
|
||||
count = readU32BE(file);
|
||||
} else {
|
||||
count = file.read();
|
||||
}
|
||||
|
||||
if (count > M4B_MAX_CHAPTERS) count = M4B_MAX_CHAPTERS;
|
||||
|
||||
chapterCount = 0;
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
if (!file.available()) break;
|
||||
|
||||
uint64_t timestamp = readU64BE(file);
|
||||
uint32_t startMs = (uint32_t)(timestamp / 10000); // 100ns -> ms
|
||||
|
||||
uint8_t nameLen = file.read();
|
||||
if (nameLen == 0 || !file.available()) break;
|
||||
|
||||
M4BChapter& ch = chapters[chapterCount];
|
||||
ch.startMs = startMs;
|
||||
|
||||
uint8_t readLen = (nameLen < sizeof(ch.name) - 1) ? nameLen : sizeof(ch.name) - 1;
|
||||
file.read((uint8_t*)ch.name, readLen);
|
||||
ch.name[readLen] = '\0';
|
||||
|
||||
if (nameLen > readLen) {
|
||||
file.seek(file.position() + (nameLen - readLen));
|
||||
}
|
||||
|
||||
chapterCount++;
|
||||
}
|
||||
|
||||
Serial.printf("M4B: Found %d chapters\n", chapterCount);
|
||||
}
|
||||
};
|
||||
@@ -468,7 +468,7 @@ public:
|
||||
break;
|
||||
|
||||
case ROW_MSG_NOTIFY:
|
||||
snprintf(tmp, sizeof(tmp), "Msg Flash: %s",
|
||||
snprintf(tmp, sizeof(tmp), "Msg Rcvd LED Light Pulse: %s",
|
||||
_prefs->kb_flash_notify ? "ON" : "OFF");
|
||||
display.print(tmp);
|
||||
break;
|
||||
|
||||
@@ -182,8 +182,10 @@ private:
|
||||
|
||||
// File list state
|
||||
std::vector<String> _fileList;
|
||||
std::vector<String> _dirList; // Subdirectories at current path
|
||||
std::vector<FileCache> _fileCache;
|
||||
int _selectedFile;
|
||||
String _currentPath; // Current browsed directory
|
||||
|
||||
// Reading state
|
||||
File _file;
|
||||
@@ -391,8 +393,8 @@ private:
|
||||
idxFile.read(&fullyFlag, 1);
|
||||
idxFile.read((uint8_t*)&lastRead, 4);
|
||||
|
||||
// Verify file hasn't changed - try BOOKS_FOLDER first, then epub cache
|
||||
String fullPath = String(BOOKS_FOLDER) + "/" + filename;
|
||||
// Verify file hasn't changed - try current path first, then epub cache
|
||||
String fullPath = _currentPath + "/" + filename;
|
||||
File txtFile = SD.open(fullPath.c_str(), FILE_READ);
|
||||
if (!txtFile) {
|
||||
// Fallback: check epub cache directory
|
||||
@@ -482,33 +484,94 @@ private:
|
||||
|
||||
// ---- File Scanning ----
|
||||
|
||||
// ---- Folder Navigation Helpers ----
|
||||
|
||||
bool isAtBooksRoot() const {
|
||||
return _currentPath == String(BOOKS_FOLDER);
|
||||
}
|
||||
|
||||
// Number of non-file entries at the start of the visual list
|
||||
int dirEntryCount() const {
|
||||
int count = _dirList.size();
|
||||
if (!isAtBooksRoot()) count++; // ".." entry
|
||||
return count;
|
||||
}
|
||||
|
||||
// Total items in the visual list (parent + dirs + files)
|
||||
int totalListItems() const {
|
||||
return dirEntryCount() + (int)_fileList.size();
|
||||
}
|
||||
|
||||
// What type of entry is at visual list index idx?
|
||||
// Returns: 0 = ".." parent, 1 = directory, 2 = file
|
||||
int itemTypeAt(int idx) const {
|
||||
bool hasParent = !isAtBooksRoot();
|
||||
if (hasParent && idx == 0) return 0; // ".."
|
||||
int dirStart = hasParent ? 1 : 0;
|
||||
if (idx < dirStart + (int)_dirList.size()) return 1; // directory
|
||||
return 2; // file
|
||||
}
|
||||
|
||||
// Get directory name for visual index (only valid when itemTypeAt == 1)
|
||||
const String& dirNameAt(int idx) const {
|
||||
int dirStart = isAtBooksRoot() ? 0 : 1;
|
||||
return _dirList[idx - dirStart];
|
||||
}
|
||||
|
||||
// Get file list index for visual index (only valid when itemTypeAt == 2)
|
||||
int fileIndexAt(int idx) const {
|
||||
return idx - dirEntryCount();
|
||||
}
|
||||
|
||||
void navigateToParent() {
|
||||
int lastSlash = _currentPath.lastIndexOf('/');
|
||||
if (lastSlash > 0) {
|
||||
_currentPath = _currentPath.substring(0, lastSlash);
|
||||
} else {
|
||||
_currentPath = BOOKS_FOLDER;
|
||||
}
|
||||
}
|
||||
|
||||
void navigateToChild(const String& dirName) {
|
||||
_currentPath = _currentPath + "/" + dirName;
|
||||
}
|
||||
|
||||
// ---- File Scanning ----
|
||||
|
||||
void scanFiles() {
|
||||
_fileList.clear();
|
||||
_dirList.clear();
|
||||
if (!SD.exists(BOOKS_FOLDER)) {
|
||||
SD.mkdir(BOOKS_FOLDER);
|
||||
Serial.printf("TextReader: Created %s\n", BOOKS_FOLDER);
|
||||
}
|
||||
|
||||
File root = SD.open(BOOKS_FOLDER);
|
||||
File root = SD.open(_currentPath.c_str());
|
||||
if (!root || !root.isDirectory()) return;
|
||||
|
||||
File f = root.openNextFile();
|
||||
while (f && _fileList.size() < READER_MAX_FILES) {
|
||||
if (!f.isDirectory()) {
|
||||
String name = String(f.name());
|
||||
int slash = name.lastIndexOf('/');
|
||||
if (slash >= 0) name = name.substring(slash + 1);
|
||||
while (f && (_fileList.size() + _dirList.size()) < READER_MAX_FILES) {
|
||||
String name = String(f.name());
|
||||
int slash = name.lastIndexOf('/');
|
||||
if (slash >= 0) name = name.substring(slash + 1);
|
||||
|
||||
if (!name.startsWith(".") &&
|
||||
(name.endsWith(".txt") || name.endsWith(".TXT") ||
|
||||
name.endsWith(".epub") || name.endsWith(".EPUB"))) {
|
||||
_fileList.push_back(name);
|
||||
}
|
||||
// Skip hidden files/dirs
|
||||
if (name.startsWith(".")) {
|
||||
f = root.openNextFile();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (f.isDirectory()) {
|
||||
_dirList.push_back(name);
|
||||
} else if (name.endsWith(".txt") || name.endsWith(".TXT") ||
|
||||
name.endsWith(".epub") || name.endsWith(".EPUB")) {
|
||||
_fileList.push_back(name);
|
||||
}
|
||||
f = root.openNextFile();
|
||||
}
|
||||
root.close();
|
||||
Serial.printf("TextReader: Found %d files\n", _fileList.size());
|
||||
Serial.printf("TextReader: %s — %d dirs, %d files\n",
|
||||
_currentPath.c_str(), (int)_dirList.size(), (int)_fileList.size());
|
||||
}
|
||||
|
||||
// ---- Book Open/Close ----
|
||||
@@ -518,7 +581,7 @@ private:
|
||||
|
||||
// ---- EPUB auto-conversion ----
|
||||
String actualFilename = filename;
|
||||
String actualFullPath = String(BOOKS_FOLDER) + "/" + filename;
|
||||
String actualFullPath = _currentPath + "/" + filename;
|
||||
bool isEpub = filename.endsWith(".epub") || filename.endsWith(".EPUB");
|
||||
|
||||
if (isEpub) {
|
||||
@@ -755,15 +818,26 @@ private:
|
||||
display.setCursor(0, 0);
|
||||
display.setTextSize(1);
|
||||
display.setColor(DisplayDriver::GREEN);
|
||||
display.print("Text Reader");
|
||||
if (isAtBooksRoot()) {
|
||||
display.print("Text Reader");
|
||||
} else {
|
||||
// Show current subfolder name
|
||||
int lastSlash = _currentPath.lastIndexOf('/');
|
||||
String folderName = (lastSlash >= 0) ? _currentPath.substring(lastSlash + 1) : _currentPath;
|
||||
char hdrBuf[20];
|
||||
strncpy(hdrBuf, folderName.c_str(), 17);
|
||||
hdrBuf[17] = '\0';
|
||||
display.print(hdrBuf);
|
||||
}
|
||||
|
||||
sprintf(tmp, "[%d]", (int)_fileList.size());
|
||||
int totalItems = totalListItems();
|
||||
sprintf(tmp, "[%d]", totalItems);
|
||||
display.setCursor(display.width() - display.getTextWidth(tmp) - 2, 0);
|
||||
display.print(tmp);
|
||||
|
||||
display.drawRect(0, 11, display.width(), 1);
|
||||
|
||||
if (_fileList.size() == 0) {
|
||||
if (totalItems == 0) {
|
||||
display.setCursor(0, 18);
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.print("No files found");
|
||||
@@ -780,8 +854,8 @@ private:
|
||||
if (maxVisible > 15) maxVisible = 15;
|
||||
|
||||
int startIdx = max(0, min(_selectedFile - maxVisible / 2,
|
||||
(int)_fileList.size() - maxVisible));
|
||||
int endIdx = min((int)_fileList.size(), startIdx + maxVisible);
|
||||
totalItems - maxVisible));
|
||||
int endIdx = min(totalItems, startIdx + maxVisible);
|
||||
|
||||
int y = startY;
|
||||
for (int i = startIdx; i < endIdx; i++) {
|
||||
@@ -800,27 +874,41 @@ private:
|
||||
// Set cursor AFTER fillRect so text draws on top of highlight
|
||||
display.setCursor(0, y);
|
||||
|
||||
// Build display string: "> filename.txt *" (asterisk if has bookmark)
|
||||
int type = itemTypeAt(i);
|
||||
String line = selected ? "> " : " ";
|
||||
String name = _fileList[i];
|
||||
|
||||
// Check for resume indicator
|
||||
String suffix = "";
|
||||
for (int j = 0; j < (int)_fileCache.size(); j++) {
|
||||
if (_fileCache[j].filename == name && _fileCache[j].lastReadPage > 0) {
|
||||
suffix = " *";
|
||||
break;
|
||||
if (type == 0) {
|
||||
// ".." parent directory
|
||||
line += ".. (up)";
|
||||
} 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);
|
||||
String name = _fileList[fi];
|
||||
|
||||
// Check for resume indicator
|
||||
String suffix = "";
|
||||
if (fi < (int)_fileCache.size()) {
|
||||
if (_fileCache[fi].filename == name && _fileCache[fi].lastReadPage > 0) {
|
||||
suffix = " *";
|
||||
}
|
||||
}
|
||||
|
||||
// Truncate if needed
|
||||
int maxLen = _charsPerLine - 4 - suffix.length();
|
||||
if ((int)name.length() > maxLen) {
|
||||
name = name.substring(0, maxLen - 3) + "...";
|
||||
}
|
||||
line += name + 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());
|
||||
|
||||
y += listLineH;
|
||||
}
|
||||
display.setTextSize(1); // Restore
|
||||
@@ -928,7 +1016,8 @@ public:
|
||||
_bootIndexed(false), _display(nullptr),
|
||||
_charsPerLine(38), _linesPerPage(22), _lineHeight(5),
|
||||
_headerHeight(14), _footerHeight(14),
|
||||
_selectedFile(0), _fileOpen(false), _currentPage(0), _totalPages(0),
|
||||
_selectedFile(0), _currentPath(BOOKS_FOLDER),
|
||||
_fileOpen(false), _currentPage(0), _totalPages(0),
|
||||
_pageBufLen(0), _contentDirty(true) {
|
||||
}
|
||||
|
||||
@@ -1068,8 +1157,8 @@ public:
|
||||
indexProgress++;
|
||||
drawBootSplash(indexProgress, needsIndexCount, _fileList[i]);
|
||||
|
||||
// Try BOOKS_FOLDER first, then epub cache fallback
|
||||
String fullPath = String(BOOKS_FOLDER) + "/" + _fileList[i];
|
||||
// Try current path first, then epub cache fallback
|
||||
String fullPath = _currentPath + "/" + _fileList[i];
|
||||
File file = SD.open(fullPath.c_str(), FILE_READ);
|
||||
if (!file) {
|
||||
String cacheFallback = String("/books/.epub_cache/") + _fileList[i];
|
||||
@@ -1166,6 +1255,8 @@ public:
|
||||
}
|
||||
|
||||
bool handleFileListInput(char c) {
|
||||
int total = totalListItems();
|
||||
|
||||
// W - scroll up
|
||||
if (c == 'w' || c == 'W' || c == 0xF2) {
|
||||
if (_selectedFile > 0) {
|
||||
@@ -1177,18 +1268,36 @@ public:
|
||||
|
||||
// S - scroll down
|
||||
if (c == 's' || c == 'S' || c == 0xF1) {
|
||||
if (_selectedFile < (int)_fileList.size() - 1) {
|
||||
if (_selectedFile < total - 1) {
|
||||
_selectedFile++;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Enter - open selected file
|
||||
// Enter - open selected item (directory or file)
|
||||
if (c == '\r' || c == 13) {
|
||||
if (_fileList.size() > 0 && _selectedFile < (int)_fileList.size()) {
|
||||
openBook(_fileList[_selectedFile]);
|
||||
if (total == 0 || _selectedFile >= total) return false;
|
||||
|
||||
int type = itemTypeAt(_selectedFile);
|
||||
|
||||
if (type == 0) {
|
||||
// ".." — navigate to parent
|
||||
navigateToParent();
|
||||
rescanAndIndex();
|
||||
return true;
|
||||
} else if (type == 1) {
|
||||
// Subdirectory — navigate into it
|
||||
navigateToChild(dirNameAt(_selectedFile));
|
||||
rescanAndIndex();
|
||||
return true;
|
||||
} else {
|
||||
// File — open it
|
||||
int fi = fileIndexAt(_selectedFile);
|
||||
if (fi >= 0 && fi < (int)_fileList.size()) {
|
||||
openBook(_fileList[fi]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1196,6 +1305,53 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
// Rescan current directory and re-index its files.
|
||||
// Called when navigating into or out of a subfolder.
|
||||
void rescanAndIndex() {
|
||||
scanFiles();
|
||||
_selectedFile = 0;
|
||||
|
||||
// Rebuild file cache for the new directory's files
|
||||
_fileCache.clear();
|
||||
_fileCache.resize(_fileList.size());
|
||||
|
||||
for (int i = 0; i < (int)_fileList.size(); i++) {
|
||||
if (!loadIndex(_fileList[i], _fileCache[i])) {
|
||||
// Not cached — skip EPUB auto-indexing here (it happens on open)
|
||||
// For .txt files, index now
|
||||
if (!(_fileList[i].endsWith(".epub") || _fileList[i].endsWith(".EPUB"))) {
|
||||
String fullPath = _currentPath + "/" + _fileList[i];
|
||||
File file = SD.open(fullPath.c_str(), FILE_READ);
|
||||
if (!file) {
|
||||
// Try epub cache fallback
|
||||
String cacheFallback = String("/books/.epub_cache/") + _fileList[i];
|
||||
file = SD.open(cacheFallback.c_str(), FILE_READ);
|
||||
}
|
||||
if (file) {
|
||||
FileCache& cache = _fileCache[i];
|
||||
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);
|
||||
cache.fullyIndexed = !file.available();
|
||||
file.close();
|
||||
saveIndex(cache.filename, cache.pagePositions, cache.fileSize,
|
||||
cache.fullyIndexed, 0);
|
||||
}
|
||||
} else {
|
||||
_fileCache[i].filename = "";
|
||||
}
|
||||
}
|
||||
yield(); // Feed WDT between files
|
||||
}
|
||||
digitalWrite(SDCARD_CS, HIGH);
|
||||
}
|
||||
|
||||
bool handleReadingInput(char c) {
|
||||
// W/A - previous page
|
||||
if (c == 'w' || c == 'W' || c == 'a' || c == 'A' || c == 0xF2) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <helpers/TxtDataHelpers.h>
|
||||
#include "../MyMesh.h"
|
||||
#include "NotesScreen.h"
|
||||
#include "RepeaterAdminScreen.h"
|
||||
#include "target.h"
|
||||
#include "GPSDutyCycle.h"
|
||||
#ifdef WIFI_SSID
|
||||
@@ -36,7 +37,7 @@
|
||||
#include "ContactsScreen.h"
|
||||
#include "TextReaderScreen.h"
|
||||
#include "SettingsScreen.h"
|
||||
#include "RepeaterAdminScreen.h"
|
||||
#include "AudiobookPlayerScreen.h"
|
||||
|
||||
class SplashScreen : public UIScreen {
|
||||
UITask* _task;
|
||||
@@ -117,12 +118,8 @@ class HomeScreen : public UIScreen {
|
||||
|
||||
|
||||
void renderBatteryIndicator(DisplayDriver& display, uint16_t batteryMilliVolts, int* outIconX = nullptr) {
|
||||
// Use voltage-based estimation to match BLE app readings
|
||||
uint8_t batteryPercentage = 0;
|
||||
#if HAS_BQ27220
|
||||
// Use fuel gauge SOC directly — accurate across the full discharge curve
|
||||
batteryPercentage = board.getBatteryPercent();
|
||||
#else
|
||||
// Fallback: voltage-based linear estimation for boards without fuel gauge
|
||||
if (batteryMilliVolts > 0) {
|
||||
const int minMilliVolts = 3000;
|
||||
const int maxMilliVolts = 4200;
|
||||
@@ -131,7 +128,6 @@ void renderBatteryIndicator(DisplayDriver& display, uint16_t batteryMilliVolts,
|
||||
if (pct > 100) pct = 100;
|
||||
batteryPercentage = (uint8_t)pct;
|
||||
}
|
||||
#endif
|
||||
|
||||
display.setColor(DisplayDriver::GREEN);
|
||||
|
||||
@@ -150,6 +146,8 @@ void renderBatteryIndicator(DisplayDriver& display, uint16_t batteryMilliVolts,
|
||||
int iconX = display.width() - totalWidth;
|
||||
int iconY = 0; // vertically align with node name text
|
||||
|
||||
if (outIconX) *outIconX = iconX;
|
||||
|
||||
// battery outline
|
||||
display.drawRect(iconX, iconY, iconWidth, iconHeight);
|
||||
|
||||
@@ -169,6 +167,22 @@ void renderBatteryIndicator(DisplayDriver& display, uint16_t batteryMilliVolts,
|
||||
display.setTextSize(1); // restore default text size
|
||||
}
|
||||
|
||||
// ---- Audio background playback indicator ----
|
||||
// Shows a small play symbol to the left of the battery icon when an
|
||||
// audiobook is actively playing in the background.
|
||||
// Uses the font renderer (not manual pixel drawing) since it handles
|
||||
// the e-ink coordinate scaling correctly.
|
||||
void renderAudioIndicator(DisplayDriver& display, int batteryLeftX) {
|
||||
if (!_task->isAudioPlayingInBackground()) return;
|
||||
|
||||
display.setColor(DisplayDriver::GREEN);
|
||||
display.setTextSize(0); // tiny font (same as clock & battery %)
|
||||
int x = batteryLeftX - display.getTextWidth(">>") - 2;
|
||||
display.setCursor(x, -3); // align vertically with battery text
|
||||
display.print(">>");
|
||||
display.setTextSize(1); // restore
|
||||
}
|
||||
|
||||
CayenneLPP sensors_lpp;
|
||||
int sensors_nb = 0;
|
||||
bool sensors_scroll = false;
|
||||
@@ -226,7 +240,11 @@ public:
|
||||
display.print(filtered_name);
|
||||
|
||||
// battery voltage
|
||||
renderBatteryIndicator(display, _task->getBattMilliVolts());
|
||||
int battLeftX = display.width(); // default if battery doesn't render
|
||||
renderBatteryIndicator(display, _task->getBattMilliVolts(), &battLeftX);
|
||||
|
||||
// audio background playback indicator (>> icon next to battery)
|
||||
renderAudioIndicator(display, battLeftX);
|
||||
|
||||
// centered clock (tinyfont) - only show when time is valid
|
||||
{
|
||||
@@ -300,11 +318,11 @@ public:
|
||||
display.setTextSize(0); // tinyfont 6x8 monospaced
|
||||
display.drawTextCentered(display.width() / 2, y, "Press:");
|
||||
y += 12;
|
||||
display.drawTextCentered(display.width() / 2, y, "[M] Messages [C] Contacts");
|
||||
display.drawTextCentered(display.width() / 2, y, "[M] Messages [C] Contacts ");
|
||||
y += 10;
|
||||
display.drawTextCentered(display.width() / 2, y, "[N] Notes [S] Settings");
|
||||
display.drawTextCentered(display.width() / 2, y, "[N] Notes [S] Settings ");
|
||||
y += 10;
|
||||
display.drawTextCentered(display.width() / 2, y, "[E] Reader ");
|
||||
display.drawTextCentered(display.width() / 2, y, "[E] Reader [P] Audiobooks");
|
||||
y += 14;
|
||||
|
||||
// Nav hint
|
||||
@@ -413,7 +431,7 @@ public:
|
||||
display.drawTextRightAlign(display.width()-1, y, buf);
|
||||
y = y + 12;
|
||||
|
||||
// NMEA sentence counter  confirms baud rate and data flow
|
||||
// NMEA sentence counter  confirms baud rate and data flow
|
||||
display.drawTextLeftAlign(0, y, "sentences");
|
||||
if (gpsDuty.isHardwareOn()) {
|
||||
uint16_t sps = gpsStream.getSentencesPerSec();
|
||||
@@ -588,6 +606,13 @@ public:
|
||||
display.drawTextLeftAlign(0, y, "voltage");
|
||||
sprintf(buf, "%d.%03d V", mv / 1000, mv % 1000);
|
||||
display.drawTextRightAlign(display.width()-1, y, buf);
|
||||
y += 10;
|
||||
|
||||
// Remaining capacity
|
||||
uint16_t remCap = board.getRemainingCapacity();
|
||||
display.drawTextLeftAlign(0, y, "remaining cap");
|
||||
sprintf(buf, "%d mAh", remCap);
|
||||
display.drawTextRightAlign(display.width()-1, y, buf);
|
||||
#endif
|
||||
} else if (_page == HomePage::SHUTDOWN) {
|
||||
display.setColor(DisplayDriver::GREEN);
|
||||
@@ -842,7 +867,7 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* no
|
||||
text_reader = new TextReaderScreen(this);
|
||||
notes_screen = new NotesScreen(this);
|
||||
settings_screen = new SettingsScreen(this, &rtc_clock, node_prefs);
|
||||
repeater_admin = new RepeaterAdminScreen(this, &rtc_clock);
|
||||
repeater_admin = nullptr; // Lazy-initialized on first use to preserve heap for audio
|
||||
audiobook_screen = nullptr; // Created and assigned from main.cpp if audio hardware present
|
||||
setCurrScreen(splash);
|
||||
}
|
||||
@@ -885,7 +910,7 @@ switch(t){
|
||||
|
||||
void UITask::msgRead(int msgcount) {
|
||||
_msgcount = msgcount;
|
||||
if (msgcount == 0) {
|
||||
if (msgcount == 0 && curr == msg_preview) {
|
||||
gotoHomeScreen();
|
||||
}
|
||||
}
|
||||
@@ -914,9 +939,12 @@ void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text, i
|
||||
#if defined(LilyGo_TDeck_Pro)
|
||||
// T-Deck Pro: Don't interrupt user with popup - just show brief notification
|
||||
// Messages are stored in channel history, accessible via 'M' key
|
||||
char alertBuf[40];
|
||||
snprintf(alertBuf, sizeof(alertBuf), "New: %s", from_name);
|
||||
showAlert(alertBuf, 2000);
|
||||
// Suppress alert entirely on admin screen - it needs focused interaction
|
||||
if (!isOnRepeaterAdmin()) {
|
||||
char alertBuf[40];
|
||||
snprintf(alertBuf, sizeof(alertBuf), "New: %s", from_name);
|
||||
showAlert(alertBuf, 2000);
|
||||
}
|
||||
#else
|
||||
// Other devices: Show full preview screen (legacy behavior)
|
||||
setCurrScreen(msg_preview);
|
||||
@@ -1192,13 +1220,13 @@ void UITask::toggleGPS() {
|
||||
|
||||
if (_sensors != NULL) {
|
||||
if (_node_prefs->gps_enabled) {
|
||||
// Disable GPS  cut hardware power
|
||||
// Disable GPS  cut hardware power
|
||||
_sensors->setSettingValue("gps", "0");
|
||||
_node_prefs->gps_enabled = 0;
|
||||
gpsDuty.disable();
|
||||
notify(UIEventType::ack);
|
||||
} else {
|
||||
// Enable GPS  start duty cycle
|
||||
// Enable GPS  start duty cycle
|
||||
_sensors->setSettingValue("gps", "1");
|
||||
_node_prefs->gps_enabled = 1;
|
||||
gpsDuty.enable();
|
||||
@@ -1331,6 +1359,10 @@ void UITask::gotoOnboarding() {
|
||||
|
||||
void UITask::gotoAudiobookPlayer() {
|
||||
if (audiobook_screen == nullptr) return; // No audio hardware
|
||||
AudiobookPlayerScreen* abPlayer = (AudiobookPlayerScreen*)audiobook_screen;
|
||||
if (_display != NULL) {
|
||||
abPlayer->enter(*_display);
|
||||
}
|
||||
setCurrScreen(audiobook_screen);
|
||||
if (_display != NULL && !_display->isOn()) {
|
||||
_display->turnOn();
|
||||
@@ -1339,26 +1371,6 @@ void UITask::gotoAudiobookPlayer() {
|
||||
_next_refresh = 100;
|
||||
}
|
||||
|
||||
void UITask::gotoRepeaterAdmin(int contactIdx) {
|
||||
// Get contact name for the screen header
|
||||
ContactInfo contact;
|
||||
char name[32] = "Unknown";
|
||||
if (the_mesh.getContactByIdx(contactIdx, contact)) {
|
||||
strncpy(name, contact.name, sizeof(name) - 1);
|
||||
name[sizeof(name) - 1] = '\0';
|
||||
}
|
||||
|
||||
RepeaterAdminScreen* admin = (RepeaterAdminScreen*)repeater_admin;
|
||||
admin->openForContact(contactIdx, name);
|
||||
setCurrScreen(repeater_admin);
|
||||
|
||||
if (_display != NULL && !_display->isOn()) {
|
||||
_display->turnOn();
|
||||
}
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||
_next_refresh = 100;
|
||||
}
|
||||
|
||||
uint8_t UITask::getChannelScreenViewIdx() const {
|
||||
return ((ChannelScreen *) channel_screen)->getViewChannelIdx();
|
||||
}
|
||||
@@ -1372,16 +1384,53 @@ void UITask::addSentChannelMessage(uint8_t channel_idx, const char* sender, cons
|
||||
((ChannelScreen *) channel_screen)->addMessage(channel_idx, 0, sender, formattedMsg);
|
||||
}
|
||||
|
||||
void UITask::gotoRepeaterAdmin(int contactIdx) {
|
||||
// Lazy-initialize on first use (same pattern as audiobook player)
|
||||
if (repeater_admin == nullptr) {
|
||||
repeater_admin = new RepeaterAdminScreen(this, &rtc_clock);
|
||||
}
|
||||
|
||||
// Get contact name for the screen header
|
||||
ContactInfo contact;
|
||||
char name[32] = "Unknown";
|
||||
if (the_mesh.getContactByIdx(contactIdx, contact)) {
|
||||
strncpy(name, contact.name, sizeof(name) - 1);
|
||||
name[sizeof(name) - 1] = '\0';
|
||||
}
|
||||
|
||||
RepeaterAdminScreen* admin = (RepeaterAdminScreen*)repeater_admin;
|
||||
admin->openForContact(contactIdx, name);
|
||||
setCurrScreen(repeater_admin);
|
||||
|
||||
if (_display != NULL && !_display->isOn()) {
|
||||
_display->turnOn();
|
||||
}
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||
_next_refresh = 100;
|
||||
}
|
||||
|
||||
void UITask::onAdminLoginResult(bool success, uint8_t permissions, uint32_t server_time) {
|
||||
if (isOnRepeaterAdmin()) {
|
||||
if (repeater_admin && isOnRepeaterAdmin()) {
|
||||
((RepeaterAdminScreen*)repeater_admin)->onLoginResult(success, permissions, server_time);
|
||||
_next_refresh = 100; // trigger re-render
|
||||
}
|
||||
}
|
||||
|
||||
void UITask::onAdminCliResponse(const char* from_name, const char* text) {
|
||||
if (isOnRepeaterAdmin()) {
|
||||
if (repeater_admin && isOnRepeaterAdmin()) {
|
||||
((RepeaterAdminScreen*)repeater_admin)->onCliResponse(text);
|
||||
_next_refresh = 100; // trigger re-render
|
||||
}
|
||||
}
|
||||
|
||||
bool UITask::isAudioPlayingInBackground() const {
|
||||
if (!audiobook_screen) return false;
|
||||
AudiobookPlayerScreen* player = (AudiobookPlayerScreen*)audiobook_screen;
|
||||
return player->isAudioActive();
|
||||
}
|
||||
|
||||
bool UITask::isAudioPausedInBackground() const {
|
||||
if (!audiobook_screen) return false;
|
||||
AudiobookPlayerScreen* player = (AudiobookPlayerScreen*)audiobook_screen;
|
||||
return player->isBookOpen() && !player->isAudioActive();
|
||||
}
|
||||
@@ -57,8 +57,8 @@ class UITask : public AbstractUITask {
|
||||
UIScreen* text_reader; // *** NEW: Text reader screen ***
|
||||
UIScreen* notes_screen; // Notes editor screen
|
||||
UIScreen* settings_screen; // Settings/onboarding screen
|
||||
UIScreen* repeater_admin; // Repeater admin screen
|
||||
UIScreen* audiobook_screen; // Audiobook player screen (null if not available)
|
||||
UIScreen* repeater_admin; // Repeater admin screen
|
||||
UIScreen* curr;
|
||||
|
||||
void userLedHandler();
|
||||
@@ -89,7 +89,7 @@ public:
|
||||
void gotoSettingsScreen(); // Navigate to settings
|
||||
void gotoOnboarding(); // Navigate to settings in onboarding mode
|
||||
void gotoAudiobookPlayer(); // Navigate to audiobook player
|
||||
void gotoRepeaterAdmin(int contactIdx); // Navigate to repeater admin
|
||||
void gotoRepeaterAdmin(int contactIdx); // Navigate to repeater admin
|
||||
void showAlert(const char* text, int duration_millis) override;
|
||||
void forceRefresh() override { _next_refresh = 100; }
|
||||
int getMsgCount() const { return _msgcount; }
|
||||
@@ -102,6 +102,10 @@ public:
|
||||
bool isOnSettingsScreen() const { return curr == settings_screen; }
|
||||
bool isOnAudiobookPlayer() const { return curr == audiobook_screen; }
|
||||
bool isOnRepeaterAdmin() const { return curr == repeater_admin; }
|
||||
|
||||
// Check if audio is playing/paused in the background (for status indicators)
|
||||
bool isAudioPlayingInBackground() const;
|
||||
bool isAudioPausedInBackground() const;
|
||||
uint8_t getChannelScreenViewIdx() const;
|
||||
|
||||
void toggleBuzzer();
|
||||
@@ -116,6 +120,10 @@ public:
|
||||
|
||||
// Add a sent message to the channel screen history
|
||||
void addSentChannelMessage(uint8_t channel_idx, const char* sender, const char* text) override;
|
||||
|
||||
// Repeater admin callbacks
|
||||
void onAdminLoginResult(bool success, uint8_t permissions, uint32_t server_time) override;
|
||||
void onAdminCliResponse(const char* from_name, const char* text) override;
|
||||
|
||||
// Get current screen for checking state
|
||||
UIScreen* getCurrentScreen() const { return curr; }
|
||||
@@ -126,8 +134,8 @@ public:
|
||||
UIScreen* getChannelScreen() const { return channel_screen; }
|
||||
UIScreen* getSettingsScreen() const { return settings_screen; }
|
||||
UIScreen* getAudiobookScreen() const { return audiobook_screen; }
|
||||
UIScreen* getRepeaterAdminScreen() const { return repeater_admin; }
|
||||
void setAudiobookScreen(UIScreen* s) { audiobook_screen = s; }
|
||||
UIScreen* getRepeaterAdminScreen() const { return repeater_admin; }
|
||||
|
||||
// from AbstractUITask
|
||||
void msgRead(int msgcount) override;
|
||||
@@ -135,9 +143,5 @@ public:
|
||||
void notify(UIEventType t = UIEventType::none) override;
|
||||
void loop() override;
|
||||
|
||||
// Repeater admin callbacks (from MyMesh via AbstractUITask)
|
||||
void onAdminLoginResult(bool success, uint8_t permissions, uint32_t server_time) override;
|
||||
void onAdminCliResponse(const char* from_name, const char* text) override;
|
||||
|
||||
void shutdown(bool restart = false);
|
||||
};
|
||||
@@ -80,7 +80,8 @@ build_flags =
|
||||
-D PIN_DISPLAY_BL=45
|
||||
-D PIN_USER_BTN=0
|
||||
-D CST328_PIN_RST=38
|
||||
-D FIRMWARE_VERSION='"Meck v0.8.9"'
|
||||
-D FIRMWARE_VERSION='"Meck v0.9.1A"'
|
||||
-D ARDUINO_LOOP_STACK_SIZE=32768
|
||||
build_src_filter = ${esp32_base.build_src_filter}
|
||||
+<../variants/LilyGo_TDeck_Pro>
|
||||
+<helpers/sensors/*.cpp>
|
||||
@@ -127,6 +128,40 @@ build_src_filter = ${LilyGo_TDeck_Pro.build_src_filter}
|
||||
lib_deps =
|
||||
${LilyGo_TDeck_Pro.lib_deps}
|
||||
densaugeo/base64 @ ~1.4.0
|
||||
https://github.com/schreibfaul1/ESP32-audioI2S.git#2.0.6
|
||||
bitbank2/JPEGDEC
|
||||
|
||||
[env:LilyGo_TDeck_Pro_standalone]
|
||||
extends = LilyGo_TDeck_Pro
|
||||
build_flags =
|
||||
${LilyGo_TDeck_Pro.build_flags}
|
||||
-I examples/companion_radio/ui-new
|
||||
-D MAX_CONTACTS=700
|
||||
-D MAX_GROUP_CHANNELS=20
|
||||
-D OFFLINE_QUEUE_SIZE=256
|
||||
-D NO_OTA=1
|
||||
-D FIRMWARE_VERSION='"Meck v0.9.1A-NB"'
|
||||
; === NO BLE_PIN_CODE, NO WIFI_SSID ===
|
||||
; By omitting these, the preprocessor selects ArduinoSerialInterface (USB only).
|
||||
; The BLE stack is never initialized, never linked, and the ESP32-S3 BT/WiFi
|
||||
; radio hardware stays in its boot-default OFF state — zero RF power draw.
|
||||
; This is the ONLY reliable way to fully disable BLE on the ESP32-S3.
|
||||
; Calling esp_bt_controller_disable() after init does NOT fully power off the radio.
|
||||
build_src_filter = ${LilyGo_TDeck_Pro.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.lib_deps}
|
||||
densaugeo/base64 @ ~1.4.0
|
||||
https://github.com/schreibfaul1/ESP32-audioI2S.git#2.0.6
|
||||
bitbank2/JPEGDEC
|
||||
; Audio libs included because AudiobookPlayerScreen.h unconditionally #includes
|
||||
; Audio.h when LilyGo_TDeck_Pro is defined. No power cost — the Audio object is
|
||||
; only heap-allocated when user presses 'P'. Without BLE competing for heap,
|
||||
; audiobook playback actually works better in standalone mode.
|
||||
|
||||
[env:LilyGo_TDeck_Pro_repeater]
|
||||
extends = LilyGo_TDeck_Pro
|
||||
|
||||
Reference in New Issue
Block a user