[Enhancement] Properties Library: Selectable CS Pin, Bypass SD.begin(), and Proper LittleFS Support [Testing]
enhancementauto-responsechildauto-processedai-training
## Enhancement Request: Properties Library [Parent issue]
### Overview
Two related improvements are needed for the `Properties` library to make it more flexible and compatible with projects that already manage their own SD or filesystem initialization.
---
### 1. Selectable CS Pin & Ability to Bypass `SD.begin()`
**Current Behavior:**
Every SD-backed method (`saveToSD`, `loadFromSD`, `save`, `load`, `store`, `storeToXML`, `loadFromXML`, etc.) calls `SD.begin(chipSelect)` internally — on **every single operation**. This means:
- If the calling application has already called `SD.begin()`, the library re-initializes the SD card on every call, which can cause conflicts, slow things down, or fail silently.
- There is no way to tell the library "I already initialized the SD card, just use it."
Additionally, one call site in `Properties.cpp` hard-codes `SD.begin(4)` instead of using the configurable `chipSelect` field, so `setChipSelect()` is not consistently respected.
**Requested Changes:**
- Add a `setBypassSDBegin(bool bypass)` flag so the library can skip `SD.begin()` when the caller has already initialized the SD card.
- Fix the hard-coded `SD.begin(4)` to use `chipSelect` consistently everywhere.
- Ensure `setChipSelect()` takes effect in all `SD.begin()` call sites.
**Example Usage:**
```cpp
// User initializes SD themselves
SD.begin(10);
Properties props;
props.setChipSelect(10);
props.setBypassSDBegin(true); // Don't re-initialize SD
props.loadFromSD("/config.properties");
2. Proper LittleFS Support (Dynamic Filesystem Selection)
Current Behavior: A separate LittleFSProperties class exists, but the main Properties class is tightly coupled to SD only. Users wanting LittleFS must use a completely different class with a different API.
Requested Changes:
Add dynamic filesystem selection to the Properties class via an enum + setter (e.g. setFilesystem(FS_SD) / setFilesystem(FS_LITTLEFS)).
All file operation methods (save, load, store, and all format-specific variants) should transparently route to the chosen filesystem.
This makes the existing LittleFSProperties class redundant for most use cases.
Properties props;
// Use LittleFS
props.setFilesystem(Properties::FS_LITTLEFS);
props.load("/config.properties");
// Or use SD
Properties props2;
props2.setFilesystem(Properties::FS_SD);
props2.setChipSelect(10);
props2.load("/config.properties");
Notes
The author has existing code ready to implement these fixes.
Backward compatibility should be preserved — default behavior should remain SD with SD.begin() called automatically, so existing sketches are not broken.
---
**🔗 Duplicate of:** #138
*This issue has been identified as a duplicate and linked to the parent issue above.*
关闭于 2026-07-20 3 条评论