Compare commits
3 Commits
crosspoint
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c39f253a7d | ||
|
|
fe766f15cb | ||
|
|
0589632f17 |
@ -42,9 +42,9 @@ class EInkDisplay {
|
||||
void cleanupGrayscaleBuffers(const uint8_t* bwBuffer);
|
||||
#endif
|
||||
|
||||
void displayBuffer(RefreshMode mode = FAST_REFRESH, bool turnOffScreen = false);
|
||||
void displayBuffer(RefreshMode mode = FAST_REFRESH);
|
||||
// EXPERIMENTAL: Windowed update - display only a rectangular region
|
||||
void displayWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h, bool turnOffScreen = false);
|
||||
void displayWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
|
||||
void displayGrayBuffer(bool turnOffScreen = false);
|
||||
|
||||
void refreshDisplay(RefreshMode mode = FAST_REFRESH, bool turnOffScreen = false);
|
||||
|
||||
@ -119,12 +119,12 @@ EInkDisplay::EInkDisplay(int8_t sclk, int8_t mosi, int8_t cs, int8_t dc, int8_t
|
||||
frameBufferActive(nullptr),
|
||||
#endif
|
||||
customLutActive(false) {
|
||||
Serial.printf("[%lu] EInkDisplay: Constructor called\n", millis());
|
||||
Serial.printf("[%lu] SCLK=%d, MOSI=%d, CS=%d, DC=%d, RST=%d, BUSY=%d\n", millis(), sclk, mosi, cs, dc, rst, busy);
|
||||
if (Serial) Serial.printf("[%lu] EInkDisplay: Constructor called\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] SCLK=%d, MOSI=%d, CS=%d, DC=%d, RST=%d, BUSY=%d\n", millis(), sclk, mosi, cs, dc, rst, busy);
|
||||
}
|
||||
|
||||
void EInkDisplay::begin() {
|
||||
Serial.printf("[%lu] EInkDisplay: begin() called\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] EInkDisplay: begin() called\n", millis());
|
||||
|
||||
frameBuffer = frameBuffer0;
|
||||
#ifndef EINK_DISPLAY_SINGLE_BUFFER_MODE
|
||||
@ -134,18 +134,18 @@ void EInkDisplay::begin() {
|
||||
// Initialize to white
|
||||
memset(frameBuffer0, 0xFF, BUFFER_SIZE);
|
||||
#ifdef EINK_DISPLAY_SINGLE_BUFFER_MODE
|
||||
Serial.printf("[%lu] Static frame buffer (%lu bytes = 48KB)\n", millis(), BUFFER_SIZE);
|
||||
if (Serial) Serial.printf("[%lu] Static frame buffer (%lu bytes = 48KB)\n", millis(), BUFFER_SIZE);
|
||||
#else
|
||||
memset(frameBuffer1, 0xFF, BUFFER_SIZE);
|
||||
Serial.printf("[%lu] Static frame buffers (2 x %lu bytes = 96KB)\n", millis(), BUFFER_SIZE);
|
||||
if (Serial) Serial.printf("[%lu] Static frame buffers (2 x %lu bytes = 96KB)\n", millis(), BUFFER_SIZE);
|
||||
#endif
|
||||
|
||||
Serial.printf("[%lu] Initializing e-ink display driver...\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] Initializing e-ink display driver...\n", millis());
|
||||
|
||||
// Initialize SPI with custom pins
|
||||
SPI.begin(_sclk, -1, _mosi, _cs);
|
||||
spiSettings = SPISettings(40000000, MSBFIRST, SPI_MODE0); // MODE0 is standard for SSD1677
|
||||
Serial.printf("[%lu] SPI initialized at 40 MHz, Mode 0\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] SPI initialized at 40 MHz, Mode 0\n", millis());
|
||||
|
||||
// Setup GPIO pins
|
||||
pinMode(_cs, OUTPUT);
|
||||
@ -156,7 +156,7 @@ void EInkDisplay::begin() {
|
||||
digitalWrite(_cs, HIGH);
|
||||
digitalWrite(_dc, HIGH);
|
||||
|
||||
Serial.printf("[%lu] GPIO pins configured\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] GPIO pins configured\n", millis());
|
||||
|
||||
// Reset display
|
||||
resetDisplay();
|
||||
@ -164,7 +164,7 @@ void EInkDisplay::begin() {
|
||||
// Initialize display controller
|
||||
initDisplayController();
|
||||
|
||||
Serial.printf("[%lu] E-ink display driver initialized\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] E-ink display driver initialized\n", millis());
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
@ -172,14 +172,14 @@ void EInkDisplay::begin() {
|
||||
// ============================================================================
|
||||
|
||||
void EInkDisplay::resetDisplay() {
|
||||
Serial.printf("[%lu] Resetting display...\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] Resetting display...\n", millis());
|
||||
digitalWrite(_rst, HIGH);
|
||||
delay(20);
|
||||
digitalWrite(_rst, LOW);
|
||||
delay(2);
|
||||
digitalWrite(_rst, HIGH);
|
||||
delay(20);
|
||||
Serial.printf("[%lu] Display reset complete\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] Display reset complete\n", millis());
|
||||
}
|
||||
|
||||
void EInkDisplay::sendCommand(uint8_t command) {
|
||||
@ -214,17 +214,17 @@ void EInkDisplay::waitWhileBusy(const char* comment) {
|
||||
while (digitalRead(_busy) == HIGH) {
|
||||
delay(1);
|
||||
if (millis() - start > 10000) {
|
||||
Serial.printf("[%lu] Timeout waiting for busy%s\n", millis(), comment ? comment : "");
|
||||
if (Serial) Serial.printf("[%lu] Timeout waiting for busy%s\n", millis(), comment ? comment : "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (comment) {
|
||||
Serial.printf("[%lu] Wait complete: %s (%lu ms)\n", millis(), comment, millis() - start);
|
||||
if (Serial) Serial.printf("[%lu] Wait complete: %s (%lu ms)\n", millis(), comment, millis() - start);
|
||||
}
|
||||
}
|
||||
|
||||
void EInkDisplay::initDisplayController() {
|
||||
Serial.printf("[%lu] Initializing SSD1677 controller...\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] Initializing SSD1677 controller...\n", millis());
|
||||
|
||||
const uint8_t TEMP_SENSOR_INTERNAL = 0x80;
|
||||
|
||||
@ -258,7 +258,7 @@ void EInkDisplay::initDisplayController() {
|
||||
// Set up full screen RAM area
|
||||
setRamArea(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT);
|
||||
|
||||
Serial.printf("[%lu] Clearing RAM buffers...\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] Clearing RAM buffers...\n", millis());
|
||||
sendCommand(CMD_AUTO_WRITE_BW_RAM); // Auto write BW RAM
|
||||
sendData(0xF7);
|
||||
waitWhileBusy(" CMD_AUTO_WRITE_BW_RAM");
|
||||
@ -267,7 +267,7 @@ void EInkDisplay::initDisplayController() {
|
||||
sendData(0xF7); // Fill with white pattern
|
||||
waitWhileBusy(" CMD_AUTO_WRITE_RED_RAM");
|
||||
|
||||
Serial.printf("[%lu] SSD1677 controller initialized\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] SSD1677 controller initialized\n", millis());
|
||||
}
|
||||
|
||||
void EInkDisplay::setRamArea(const uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
|
||||
@ -312,7 +312,7 @@ void EInkDisplay::clearScreen(const uint8_t color) const {
|
||||
void EInkDisplay::drawImage(const uint8_t* imageData, const uint16_t x, const uint16_t y, const uint16_t w, const uint16_t h,
|
||||
const bool fromProgmem) const {
|
||||
if (!frameBuffer) {
|
||||
Serial.printf("[%lu] ERROR: Frame buffer not allocated!\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] ERROR: Frame buffer not allocated!\n", millis());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -340,19 +340,19 @@ void EInkDisplay::drawImage(const uint8_t* imageData, const uint16_t x, const ui
|
||||
}
|
||||
}
|
||||
|
||||
Serial.printf("[%lu] Image drawn to frame buffer\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] Image drawn to frame buffer\n", millis());
|
||||
}
|
||||
|
||||
void EInkDisplay::writeRamBuffer(uint8_t ramBuffer, const uint8_t* data, uint32_t size) {
|
||||
const char* bufferName = (ramBuffer == CMD_WRITE_RAM_BW) ? "BW" : "RED";
|
||||
const unsigned long startTime = millis();
|
||||
Serial.printf("[%lu] Writing frame buffer to %s RAM (%lu bytes)...\n", startTime, bufferName, size);
|
||||
if (Serial) Serial.printf("[%lu] Writing frame buffer to %s RAM (%lu bytes)...\n", startTime, bufferName, size);
|
||||
|
||||
sendCommand(ramBuffer);
|
||||
sendData(data, size);
|
||||
|
||||
const unsigned long duration = millis() - startTime;
|
||||
Serial.printf("[%lu] %s RAM write complete (%lu ms)\n", millis(), bufferName, duration);
|
||||
if (Serial) Serial.printf("[%lu] %s RAM write complete (%lu ms)\n", millis(), bufferName, duration);
|
||||
}
|
||||
|
||||
void EInkDisplay::setFramebuffer(const uint8_t* bwBuffer) const {
|
||||
@ -399,34 +399,25 @@ void EInkDisplay::copyGrayscaleBuffers(const uint8_t* lsbBuffer, const uint8_t*
|
||||
#ifdef EINK_DISPLAY_SINGLE_BUFFER_MODE
|
||||
/**
|
||||
* In single buffer mode, this should be called with the previously written BW buffer
|
||||
* to restore proper BW state after a grayscale display.
|
||||
*
|
||||
* The approach: Don't call grayscaleRevert() at all. Instead, just sync the RAMs with
|
||||
* BW data and clear the grayscale mode flag. The physical pixels will stay in their
|
||||
* current grayscale states, but subsequent refreshes will naturally transition them
|
||||
* as the new BW content is displayed.
|
||||
* to reconstruct the RED buffer for proper differential fast refreshes following a
|
||||
* grayscale display.
|
||||
*/
|
||||
void EInkDisplay::cleanupGrayscaleBuffers(const uint8_t* bwBuffer) {
|
||||
// Clear grayscale mode - we don't want grayscaleRevert to be called later
|
||||
// because the RAMs won't have valid grayscale data anymore
|
||||
inGrayscaleMode = false;
|
||||
|
||||
// Sync both RAMs with BW content for proper fast refresh behavior
|
||||
setRamArea(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT);
|
||||
writeRamBuffer(CMD_WRITE_RAM_BW, bwBuffer, BUFFER_SIZE);
|
||||
writeRamBuffer(CMD_WRITE_RAM_RED, bwBuffer, BUFFER_SIZE);
|
||||
}
|
||||
#endif
|
||||
|
||||
void EInkDisplay::displayBuffer(RefreshMode mode, const bool turnOffScreen) {
|
||||
if (!isScreenOn && !turnOffScreen) {
|
||||
void EInkDisplay::displayBuffer(RefreshMode mode) {
|
||||
if (!isScreenOn) {
|
||||
// Force half refresh if screen is off
|
||||
mode = HALF_REFRESH;
|
||||
}
|
||||
|
||||
// If currently in grayscale mode, revert first to black/white
|
||||
if (inGrayscaleMode) {
|
||||
grayscaleRevert(); // grayscaleRevert() sets inGrayscaleMode = false internally
|
||||
inGrayscaleMode = false;
|
||||
grayscaleRevert();
|
||||
}
|
||||
|
||||
// Set up full screen RAM area
|
||||
@ -451,7 +442,7 @@ void EInkDisplay::displayBuffer(RefreshMode mode, const bool turnOffScreen) {
|
||||
#endif
|
||||
|
||||
// Refresh the display
|
||||
refreshDisplay(mode, turnOffScreen);
|
||||
refreshDisplay(mode);
|
||||
|
||||
#ifdef EINK_DISPLAY_SINGLE_BUFFER_MODE
|
||||
// In single buffer mode always sync RED RAM after refresh to prepare for next fast refresh
|
||||
@ -464,36 +455,37 @@ void EInkDisplay::displayBuffer(RefreshMode mode, const bool turnOffScreen) {
|
||||
// EXPERIMENTAL: Windowed update support
|
||||
// Displays only a rectangular region of the frame buffer, preserving the rest of the screen.
|
||||
// Requirements: x and w must be byte-aligned (multiples of 8 pixels)
|
||||
void EInkDisplay::displayWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const bool turnOffScreen) {
|
||||
Serial.printf("[%lu] Displaying window at (%d,%d) size (%dx%d)\n", millis(), x, y, w, h);
|
||||
void EInkDisplay::displayWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
|
||||
if (Serial) Serial.printf("[%lu] Displaying window at (%d,%d) size (%dx%d)\n", millis(), x, y, w, h);
|
||||
|
||||
// Validate bounds
|
||||
if (x + w > DISPLAY_WIDTH || y + h > DISPLAY_HEIGHT) {
|
||||
Serial.printf("[%lu] ERROR: Window bounds exceed display dimensions!\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] ERROR: Window bounds exceed display dimensions!\n", millis());
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate byte alignment
|
||||
if (x % 8 != 0 || w % 8 != 0) {
|
||||
Serial.printf("[%lu] ERROR: Window x and width must be byte-aligned (multiples of 8)!\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] ERROR: Window x and width must be byte-aligned (multiples of 8)!\n", millis());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!frameBuffer) {
|
||||
Serial.printf("[%lu] ERROR: Frame buffer not allocated!\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] ERROR: Frame buffer not allocated!\n", millis());
|
||||
return;
|
||||
}
|
||||
|
||||
// displayWindow is not supported while the rest of the screen has grayscale content, revert it
|
||||
if (inGrayscaleMode) {
|
||||
grayscaleRevert(); // grayscaleRevert() sets inGrayscaleMode = false internally
|
||||
inGrayscaleMode = false;
|
||||
grayscaleRevert();
|
||||
}
|
||||
|
||||
// Calculate window buffer size
|
||||
const uint16_t windowWidthBytes = w / 8;
|
||||
const uint32_t windowBufferSize = windowWidthBytes * h;
|
||||
|
||||
Serial.printf("[%lu] Window buffer size: %lu bytes (%d x %d pixels)\n", millis(), windowBufferSize, w, h);
|
||||
if (Serial) Serial.printf("[%lu] Window buffer size: %lu bytes (%d x %d pixels)\n", millis(), windowBufferSize, w, h);
|
||||
|
||||
// Allocate temporary buffer on stack
|
||||
std::vector<uint8_t> windowBuffer(windowBufferSize);
|
||||
@ -525,7 +517,7 @@ void EInkDisplay::displayWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h,
|
||||
#endif
|
||||
|
||||
// Perform fast refresh
|
||||
refreshDisplay(FAST_REFRESH, turnOffScreen);
|
||||
refreshDisplay(FAST_REFRESH);
|
||||
|
||||
#ifdef EINK_DISPLAY_SINGLE_BUFFER_MODE
|
||||
// Post-refresh: Sync RED RAM with current window (for next fast refresh)
|
||||
@ -533,7 +525,7 @@ void EInkDisplay::displayWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h,
|
||||
writeRamBuffer(CMD_WRITE_RAM_RED, windowBuffer.data(), windowBufferSize);
|
||||
#endif
|
||||
|
||||
Serial.printf("[%lu] Window display complete\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] Window display complete\n", millis());
|
||||
}
|
||||
|
||||
void EInkDisplay::displayGrayBuffer(const bool turnOffScreen) {
|
||||
@ -591,20 +583,20 @@ void EInkDisplay::refreshDisplay(const RefreshMode mode, const bool turnOffScree
|
||||
|
||||
// Power on and refresh display
|
||||
const char* refreshType = (mode == FULL_REFRESH) ? "full" : (mode == HALF_REFRESH) ? "half" : "fast";
|
||||
Serial.printf("[%lu] Powering on display 0x%02X (%s refresh)...\n", millis(), displayMode, refreshType);
|
||||
if (Serial) Serial.printf("[%lu] Powering on display 0x%02X (%s refresh)...\n", millis(), displayMode, refreshType);
|
||||
sendCommand(CMD_DISPLAY_UPDATE_CTRL2);
|
||||
sendData(displayMode);
|
||||
|
||||
sendCommand(CMD_MASTER_ACTIVATION);
|
||||
|
||||
// Wait for display to finish updating
|
||||
Serial.printf("[%lu] Waiting for display refresh...\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] Waiting for display refresh...\n", millis());
|
||||
waitWhileBusy(refreshType);
|
||||
}
|
||||
|
||||
void EInkDisplay::setCustomLUT(const bool enabled, const unsigned char* lutData) {
|
||||
if (enabled) {
|
||||
Serial.printf("[%lu] Loading custom LUT...\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] Loading custom LUT...\n", millis());
|
||||
|
||||
// Load custom LUT (first 105 bytes: VS + TP/RP + frame rate)
|
||||
sendCommand(CMD_WRITE_LUT);
|
||||
@ -625,15 +617,15 @@ void EInkDisplay::setCustomLUT(const bool enabled, const unsigned char* lutData)
|
||||
sendData(pgm_read_byte(&lutData[109]));
|
||||
|
||||
customLutActive = true;
|
||||
Serial.printf("[%lu] Custom LUT loaded\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] Custom LUT loaded\n", millis());
|
||||
} else {
|
||||
customLutActive = false;
|
||||
Serial.printf("[%lu] Custom LUT disabled\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] Custom LUT disabled\n", millis());
|
||||
}
|
||||
}
|
||||
|
||||
void EInkDisplay::deepSleep() {
|
||||
Serial.printf("[%lu] Preparing display for deep sleep...\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] Preparing display for deep sleep...\n", millis());
|
||||
|
||||
// First, power down the display properly
|
||||
// This shuts down the analog power rails and clock
|
||||
@ -653,7 +645,7 @@ void EInkDisplay::deepSleep() {
|
||||
}
|
||||
|
||||
// Now enter deep sleep mode
|
||||
Serial.printf("[%lu] Entering deep sleep mode...\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] Entering deep sleep mode...\n", millis());
|
||||
sendCommand(CMD_DEEP_SLEEP);
|
||||
sendData(0x01); // Enter deep sleep
|
||||
}
|
||||
@ -664,7 +656,7 @@ void EInkDisplay::saveFrameBufferAsPBM(const char* filename) {
|
||||
|
||||
std::ofstream file(filename, std::ios::binary);
|
||||
if (!file) {
|
||||
Serial.printf("Failed to open %s for writing\n", filename);
|
||||
if (Serial) Serial.printf("Failed to open %s for writing\n", filename);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -700,9 +692,9 @@ void EInkDisplay::saveFrameBufferAsPBM(const char* filename) {
|
||||
|
||||
file.write(reinterpret_cast<const char*>(rotatedBuffer.data()), rotatedBuffer.size());
|
||||
file.close();
|
||||
Serial.printf("Saved framebuffer to %s\n", filename);
|
||||
if (Serial) Serial.printf("Saved framebuffer to %s\n", filename);
|
||||
#else
|
||||
(void)filename;
|
||||
Serial.println("saveFrameBufferAsPBM is not supported on Arduino builds.");
|
||||
if (Serial) Serial.println("saveFrameBufferAsPBM is not supported on Arduino builds.");
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
#include <WString.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <SdFat.h>
|
||||
|
||||
class SDCardManager {
|
||||
@ -29,7 +30,7 @@ class SDCardManager {
|
||||
bool exists(const char* path) { return sd.exists(path); }
|
||||
bool remove(const char* path) { return sd.remove(path); }
|
||||
bool rmdir(const char* path) { return sd.rmdir(path); }
|
||||
bool rename(const char* oldPath, const char* newPath) { return sd.rename(oldPath, newPath); }
|
||||
bool rename(const char* path, const char* newPath) { return sd.rename(path, newPath); }
|
||||
|
||||
bool openFileForRead(const char* moduleName, const char* path, FsFile& file);
|
||||
bool openFileForRead(const char* moduleName, const std::string& path, FsFile& file);
|
||||
|
||||
@ -11,10 +11,10 @@ SDCardManager::SDCardManager() : sd() {}
|
||||
|
||||
bool SDCardManager::begin() {
|
||||
if (!sd.begin(SD_CS, SPI_FQ)) {
|
||||
Serial.printf("[%lu] [SD] SD card not detected\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] [SD] SD card not detected\n", millis());
|
||||
initialized = false;
|
||||
} else {
|
||||
Serial.printf("[%lu] [SD] SD card detected\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] [SD] SD card detected\n", millis());
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
@ -28,17 +28,17 @@ bool SDCardManager::ready() const {
|
||||
std::vector<String> SDCardManager::listFiles(const char* path, const int maxFiles) {
|
||||
std::vector<String> ret;
|
||||
if (!initialized) {
|
||||
Serial.printf("[%lu] [SD] not initialized, returning empty list\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] [SD] not initialized, returning empty list\n", millis());
|
||||
return ret;
|
||||
}
|
||||
|
||||
auto root = sd.open(path);
|
||||
if (!root) {
|
||||
Serial.printf("[%lu] [SD] Failed to open directory\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] [SD] Failed to open directory\n", millis());
|
||||
return ret;
|
||||
}
|
||||
if (!root.isDirectory()) {
|
||||
Serial.printf("[%lu] [SD] Path is not a directory\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] [SD] Path is not a directory\n", millis());
|
||||
root.close();
|
||||
return ret;
|
||||
}
|
||||
@ -61,7 +61,7 @@ std::vector<String> SDCardManager::listFiles(const char* path, const int maxFile
|
||||
|
||||
String SDCardManager::readFile(const char* path) {
|
||||
if (!initialized) {
|
||||
Serial.printf("[%lu] [SD] not initialized; cannot read file\n", millis());
|
||||
if (Serial) Serial.printf("[%lu] [SD] not initialized; cannot read file\n", millis());
|
||||
return {""};
|
||||
}
|
||||
|
||||
@ -84,8 +84,8 @@ String SDCardManager::readFile(const char* path) {
|
||||
|
||||
bool SDCardManager::readFileToStream(const char* path, Print& out, const size_t chunkSize) {
|
||||
if (!initialized) {
|
||||
Serial.printf("[%lu] [SD] Path is not a directory\n", millis());
|
||||
Serial.println("SDCardManager: not initialized; cannot read file");
|
||||
if (Serial) Serial.printf("[%lu] [SD] Path is not a directory\n", millis());
|
||||
if (Serial) Serial.println("SDCardManager: not initialized; cannot read file");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -115,8 +115,8 @@ size_t SDCardManager::readFileToBuffer(const char* path, char* buffer, const siz
|
||||
if (!buffer || bufferSize == 0)
|
||||
return 0;
|
||||
if (!initialized) {
|
||||
Serial.printf("[%lu] [SD] Path is not a directory\n", millis());
|
||||
Serial.println("SDCardManager: not initialized; cannot read file");
|
||||
if (Serial) Serial.printf("[%lu] [SD] Path is not a directory\n", millis());
|
||||
if (Serial) Serial.println("SDCardManager: not initialized; cannot read file");
|
||||
buffer[0] = '\0';
|
||||
return 0;
|
||||
}
|
||||
@ -149,8 +149,8 @@ size_t SDCardManager::readFileToBuffer(const char* path, char* buffer, const siz
|
||||
|
||||
bool SDCardManager::writeFile(const char* path, const String& content) {
|
||||
if (!initialized) {
|
||||
Serial.printf("[%lu] [SD] Path is not a directory\n", millis());
|
||||
Serial.println("SDCardManager: not initialized; cannot write file");
|
||||
if (Serial) Serial.printf("[%lu] [SD] Path is not a directory\n", millis());
|
||||
if (Serial) Serial.println("SDCardManager: not initialized; cannot write file");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -161,8 +161,8 @@ bool SDCardManager::writeFile(const char* path, const String& content) {
|
||||
|
||||
FsFile f;
|
||||
if (!openFileForWrite("SD", path, f)) {
|
||||
Serial.printf("[%lu] [SD] Path is not a directory\n", millis());
|
||||
Serial.printf("Failed to open file for write: %s\n", path);
|
||||
if (Serial) Serial.printf("[%lu] [SD] Path is not a directory\n", millis());
|
||||
if (Serial) Serial.printf("Failed to open file for write: %s\n", path);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -173,8 +173,8 @@ bool SDCardManager::writeFile(const char* path, const String& content) {
|
||||
|
||||
bool SDCardManager::ensureDirectoryExists(const char* path) {
|
||||
if (!initialized) {
|
||||
Serial.printf("[%lu] [SD] Path is not a directory\n", millis());
|
||||
Serial.println("SDCardManager: not initialized; cannot create directory");
|
||||
if (Serial) Serial.printf("[%lu] [SD] Path is not a directory\n", millis());
|
||||
if (Serial) Serial.println("SDCardManager: not initialized; cannot create directory");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -183,8 +183,8 @@ bool SDCardManager::ensureDirectoryExists(const char* path) {
|
||||
FsFile dir = sd.open(path);
|
||||
if (dir && dir.isDirectory()) {
|
||||
dir.close();
|
||||
Serial.printf("[%lu] [SD] Path is not a directory\n", millis());
|
||||
Serial.printf("Directory already exists: %s\n", path);
|
||||
if (Serial) Serial.printf("[%lu] [SD] Path is not a directory\n", millis());
|
||||
if (Serial) Serial.printf("Directory already exists: %s\n", path);
|
||||
return true;
|
||||
}
|
||||
dir.close();
|
||||
@ -192,25 +192,25 @@ bool SDCardManager::ensureDirectoryExists(const char* path) {
|
||||
|
||||
// Create the directory
|
||||
if (sd.mkdir(path)) {
|
||||
Serial.printf("[%lu] [SD] Path is not a directory\n", millis());
|
||||
Serial.printf("Created directory: %s\n", path);
|
||||
if (Serial) Serial.printf("[%lu] [SD] Path is not a directory\n", millis());
|
||||
if (Serial) Serial.printf("Created directory: %s\n", path);
|
||||
return true;
|
||||
} else {
|
||||
Serial.printf("[%lu] [SD] Path is not a directory\n", millis());
|
||||
Serial.printf("Failed to create directory: %s\n", path);
|
||||
if (Serial) Serial.printf("[%lu] [SD] Path is not a directory\n", millis());
|
||||
if (Serial) Serial.printf("Failed to create directory: %s\n", path);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool SDCardManager::openFileForRead(const char* moduleName, const char* path, FsFile& file) {
|
||||
if (!sd.exists(path)) {
|
||||
Serial.printf("[%lu] [%s] File does not exist: %s\n", millis(), moduleName, path);
|
||||
if (Serial) Serial.printf("[%lu] [%s] File does not exist: %s\n", millis(), moduleName, path);
|
||||
return false;
|
||||
}
|
||||
|
||||
file = sd.open(path, O_RDONLY);
|
||||
if (!file) {
|
||||
Serial.printf("[%lu] [%s] Failed to open file for reading: %s\n", millis(), moduleName, path);
|
||||
if (Serial) Serial.printf("[%lu] [%s] Failed to open file for reading: %s\n", millis(), moduleName, path);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -227,7 +227,7 @@ bool SDCardManager::openFileForRead(const char* moduleName, const String& path,
|
||||
bool SDCardManager::openFileForWrite(const char* moduleName, const char* path, FsFile& file) {
|
||||
file = sd.open(path, O_RDWR | O_CREAT | O_TRUNC);
|
||||
if (!file) {
|
||||
Serial.printf("[%lu] [%s] Failed to open file for writing: %s\n", millis(), moduleName, path);
|
||||
if (Serial) Serial.printf("[%lu] [%s] Failed to open file for writing: %s\n", millis(), moduleName, path);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user