-
-
Notifications
You must be signed in to change notification settings - Fork 107
feat: Support SD cards behind a co-processor (SenseCAP Indicator) #342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
caveman99
wants to merge
9
commits into
master
Choose a base branch
from
indicator
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+719
−36
Open
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
dcb45b7
Support SD cards behind a co-processor (SenseCAP Indicator)
caveman99 27e6c0c
Address review: SENSECAP_INDICATOR branches take precedence over gene…
caveman99 1dfc204
Remote SD hardening: chunk coverage guard, no double transfer, stats …
caveman99 3775ba3
Refresh the SD stats display when the co-processor scan completes
caveman99 a4de101
Refresh SD statistics in place, keep SENSECAP ahead of the generic SD…
caveman99 f74a67f
Stop polling SD statistics when the card is gone
caveman99 d5027c2
SD button: mount on tap, eject or format on long press
caveman99 5dbe0ed
SD label: print the used space with snprintf
caveman99 e07779a
Map tiles: one chunk cache for all opens of a file
caveman99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| #pragma once | ||
|
|
||
| #include "graphics/map/TileService.h" | ||
| #include "lvgl.h" | ||
| #include <set> | ||
| #include <stdint.h> | ||
| #include <string> | ||
|
|
||
| /** | ||
| * Statistics of the remote SD card; numeric values match the | ||
| * meshtastic.SdCardInfo interdevice protobuf enums. | ||
| */ | ||
| struct RemoteSdInfo { | ||
| bool present = false; | ||
| uint8_t cardType = 0; // 0 none, 1 MMC, 2 SD, 3 SDHC, 4 SDXC, 5 unknown | ||
| uint8_t fatType = 0; // 0 unknown, 1 FAT16, 2 FAT32, 3 exFAT | ||
| uint64_t cardSize = 0; | ||
| uint64_t usedBytes = 0; | ||
| uint64_t freeBytes = 0; | ||
| }; | ||
|
|
||
| /** | ||
| * Backend transport for RemoteSDService: chunked file access on a filesystem | ||
| * that lives on another MCU (e.g. the SD card behind the SenseCAP Indicator | ||
| * RP2040). Implemented and registered by the firmware before the view loads | ||
| * the map. | ||
| */ | ||
| class IRemoteFS | ||
| { | ||
| public: | ||
| /** | ||
| * Read up to len bytes at offset. Returns false on transport error or | ||
| * missing file. *bytesRead receives the chunk size actually read, | ||
| * *fileSize the total size of the file. | ||
| */ | ||
| virtual bool readChunk(const char *path, uint32_t offset, uint8_t *buf, uint32_t len, uint32_t *bytesRead, | ||
| uint32_t *fileSize) = 0; | ||
| /** | ||
| * Sequential chunked write; create=true starts a new file (offset 0), | ||
| * create=false appends the chunk at offset == current file size. | ||
| */ | ||
| virtual bool writeChunk(const char *path, uint32_t offset, const uint8_t *buf, uint32_t len, bool create) = 0; | ||
| /** | ||
| * List all entries of a directory; subdirectories carry a trailing | ||
| * slash. Returns false on transport error or when path is not a | ||
| * directory. | ||
| */ | ||
| virtual bool listDir(const char *path, std::set<std::string> &entries) = 0; | ||
| /** | ||
| * Card statistics, answered from a cache on the co-processor so the | ||
| * call stays fast. usedBytes/freeBytes may still read zero while the | ||
| * background FAT scan runs; a later call returns real values. | ||
| * Returns false on transport error. | ||
| */ | ||
| virtual bool sdInfo(RemoteSdInfo &info) = 0; | ||
| virtual ~IRemoteFS() {} | ||
| }; | ||
|
|
||
| /** | ||
| * Map tile service for a remote SD card, accessed chunk-wise through an | ||
| * IRemoteFS backend. Registers an LVGL filesystem driver so the image | ||
| * decoder reads tiles like from a local drive. | ||
| */ | ||
| class RemoteSDService : public ITileService | ||
| { | ||
| public: | ||
| static void setBackend(IRemoteFS *fs); | ||
| static IRemoteFS *backend(void); | ||
|
|
||
| RemoteSDService(); | ||
| virtual ~RemoteSDService(); | ||
|
|
||
| bool load(const char *name, void *img) override; | ||
| bool save(const char *name, void *img, size_t len) override; | ||
|
|
||
| protected: | ||
| static void *fs_open(lv_fs_drv_t *drv, const char *path, lv_fs_mode_t mode); | ||
| static lv_fs_res_t fs_close(lv_fs_drv_t *drv, void *file_p); | ||
| static lv_fs_res_t fs_read(lv_fs_drv_t *drv, void *file_p, void *buf, uint32_t btr, uint32_t *br); | ||
| static lv_fs_res_t fs_write(lv_fs_drv_t *drv, void *file_p, const void *buf, uint32_t btw, uint32_t *bw); | ||
| static lv_fs_res_t fs_seek(lv_fs_drv_t *drv, void *file_p, uint32_t pos, lv_fs_whence_t whence); | ||
| static lv_fs_res_t fs_tell(lv_fs_drv_t *drv, void *file_p, uint32_t *pos_p); | ||
|
|
||
| private: | ||
| static IRemoteFS *remoteFS; | ||
|
|
||
| enum { CHUNK_SIZE = 4096 }; // matches FileTransfer.filedata max_size | ||
|
|
||
| typedef struct RemoteFile { | ||
| char path[256]; // full FAT LFN paths round-trip | ||
| uint32_t pos; | ||
| uint32_t size; | ||
| // single chunk read-ahead cache | ||
| uint32_t chunkOffset; | ||
| uint32_t chunkLen; | ||
| uint8_t chunk[CHUNK_SIZE]; | ||
| } RemoteFile; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.