microReticulumTbeam/exercises/07_SD_Startup_Watcher/README.md

51 lines
1.5 KiB
Markdown

## Exercise 07: SD Startup Watcher
This exercise is derived from `Exercise 05` and keeps that original exercise intact.
The focus here is isolating reusable SD startup and hot-insert watcher logic into a library-style structure.
This exercise now has two parts:
1. A reusable SD startup/watcher library in `lib/startup_sd`.
2. A harness app in `src/main.cpp` that demonstrates how to use that library.
Watcher behavior:
1. Initializes PMU and enables SD power rail (AXP2101 BLDO1).
2. Polls for card changes with debounced state transitions.
3. Emits events only on change:
- `EVENT: card inserted/mounted`
- `EVENT: card removed/unavailable`
- `EVENT: no card detected`
4. On mount event, emits callback status (`SdEvent`) and runs SD write workflow.
5. Every 15 seconds while mounted, runs a periodic write/permission check.
6. Uses fast preferred probe (`HSPI @ 400k`) and occasional full fallback scan.
Status callback usage:
- `SdEvent::NO_CARD` -> show "Missing SD card / Please insert card to proceed"
- `SdEvent::CARD_MOUNTED` -> card ready
- `SdEvent::CARD_REMOVED` -> card removed, wait for insert
Files used in this exercise:
- `/Exercise_07_test.txt`
- `/test/testsub1/testsubsub1/Exercise_07_test.txt`
## Build
```bash
source /home/jlpoole/rnsenv/bin/activate
pio run -e node_a
```
## Upload
```bash
source /home/jlpoole/rnsenv/bin/activate
pio run -e node_a -t upload --upload-port /dev/ttyACM0
```
## Monitor
```bash
screen /dev/ttyACM0 115200
```