mirror of
https://github.com/markqvist/RNode_Firmware.git
synced 2026-04-27 14:30:33 +00:00
Add SD card file listing via debug command F
Implements gui_list_files_fn callback to list SD card contents as JSON via the serial debug protocol. Replaces the stub that returned "use_log_command".
This commit is contained in:
parent
782710e52e
commit
9edf5a953c
2 changed files with 29 additions and 5 deletions
12
Gui.h
12
Gui.h
|
|
@ -158,6 +158,9 @@ extern volatile uint32_t imu_step_count;
|
|||
// Sensor logger toggle — set by .ino after IMULogger.h is included
|
||||
typedef bool (*gui_log_toggle_fn_t)();
|
||||
static gui_log_toggle_fn_t gui_log_toggle_fn = NULL;
|
||||
// SD file listing — set by .ino after SD is available
|
||||
typedef void (*gui_list_files_fn_t)();
|
||||
static gui_list_files_fn_t gui_list_files_fn = NULL;
|
||||
static bool gui_imu_logging = false;
|
||||
// Forward declarations for IMULogger.h variables (defined later in compilation)
|
||||
extern bool imu_logging;
|
||||
|
|
@ -1322,13 +1325,12 @@ static void gui_cmd_execute() {
|
|||
break;
|
||||
}
|
||||
|
||||
case 'F': { // List files on SD card (handled via function pointer)
|
||||
case 'F': { // List files on SD card
|
||||
Serial.write(hdr, 4);
|
||||
if (gui_log_toggle_fn) {
|
||||
// Reuse the SD infrastructure from IMU logger
|
||||
Serial.println("{\"error\":\"use_log_command\"}");
|
||||
if (gui_list_files_fn) {
|
||||
gui_list_files_fn();
|
||||
} else {
|
||||
Serial.println("{\"error\":\"not_available\"}");
|
||||
Serial.println("{\"error\":\"no_sd\"}");
|
||||
}
|
||||
Serial.flush();
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -2236,6 +2236,28 @@ void loop() {
|
|||
return false;
|
||||
}
|
||||
};
|
||||
gui_list_files_fn = []() {
|
||||
if (shared_spi_mutex) xSemaphoreTake(shared_spi_mutex, portMAX_DELAY);
|
||||
SPI.begin(SD_CLK, SD_MISO, SD_MOSI, SD_CS);
|
||||
if (SD.begin(SD_CS, SPI, 4000000, "/sd", 5)) {
|
||||
Serial.print("{\"files\":[");
|
||||
File root = SD.open("/");
|
||||
bool first = true;
|
||||
File f;
|
||||
while ((f = root.openNextFile())) {
|
||||
if (!first) Serial.print(",");
|
||||
Serial.printf("{\"name\":\"%s\",\"size\":%lu}", f.name(), (unsigned long)f.size());
|
||||
first = false;
|
||||
f.close();
|
||||
}
|
||||
root.close();
|
||||
SD.end();
|
||||
Serial.println("]}");
|
||||
} else {
|
||||
Serial.println("{\"error\":\"sd_init_failed\"}");
|
||||
}
|
||||
if (shared_spi_mutex) xSemaphoreGive(shared_spi_mutex);
|
||||
};
|
||||
#endif
|
||||
|
||||
// Enable step counter (low power, always-on)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue