## Summary Fix https://github.com/crosspoint-reader/crosspoint-reader/issues/1137 Introducing `HalFile`, a thin wrapper around `FsFile` that uses a global mutex to protect file operations. To test this PR, place the code below somewhere in the code base (I placed it in `onGoToRecentBooks`) ```cpp static auto testTask = [](void* param) { for (int i = 0; i < 10; i++) { String json = Storage.readFile("/.crosspoint/settings.json"); LOG_DBG("TEST_TASK", "Read settings.json, bytes read: %u", json.length()); } vTaskDelete(nullptr); }; xTaskCreate(testTask, "test0", 8192, nullptr, 1, nullptr); xTaskCreate(testTask, "test1", 8192, nullptr, 1, nullptr); xTaskCreate(testTask, "test2", 8192, nullptr, 1, nullptr); xTaskCreate(testTask, "test3", 8192, nullptr, 1, nullptr); delay(1000); ``` It will reliably lead to crash on `master`, but will function correctly with this PR. A macro renaming trick is used to avoid changing too many downstream code files. --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? **PARTIALLY**, only to help with tedious copy-paste tasks --------- Co-authored-by: Zach Nelson <zach@zdnelson.com>
21 lines
945 B
C++
21 lines
945 B
C++
#pragma once
|
|
|
|
#include <HalStorage.h>
|
|
|
|
class Print;
|
|
class ZipFile;
|
|
|
|
class JpegToBmpConverter {
|
|
static unsigned char jpegReadCallback(unsigned char* pBuf, unsigned char buf_size,
|
|
unsigned char* pBytes_actually_read, void* pCallback_data);
|
|
static bool jpegFileToBmpStreamInternal(FsFile& jpegFile, Print& bmpOut, int targetWidth, int targetHeight,
|
|
bool oneBit, bool crop = true);
|
|
|
|
public:
|
|
static bool jpegFileToBmpStream(FsFile& jpegFile, Print& bmpOut, bool crop = true);
|
|
// Convert with custom target size (for thumbnails)
|
|
static bool jpegFileToBmpStreamWithSize(FsFile& jpegFile, Print& bmpOut, int targetMaxWidth, int targetMaxHeight);
|
|
// Convert to 1-bit BMP (black and white only, no grays) for fast home screen rendering
|
|
static bool jpegFileTo1BitBmpStreamWithSize(FsFile& jpegFile, Print& bmpOut, int targetMaxWidth, int targetMaxHeight);
|
|
};
|