refactor(daplink_flash): Split into daplink_bridge + daplink_flash layers.#285
Conversation
…yers. DaplinkFlash now takes a DaplinkBridge instead of i2c. SteamiConfig now takes a DaplinkBridge instead of DaplinkFlash.
| @@ -0,0 +1,135 @@ | |||
| from time import sleep_ms | |||
|
|
|||
| from daplink_bridge.const import * | |||
There was a problem hiding this comment.
Pull request overview
Refactors the existing daplink_flash driver into a two-layer design by introducing a new low-level daplink_bridge module for direct I2C/protocol operations, and updating daplink_flash + steami_config to consume the bridge (breaking constructor changes).
Changes:
- Added new
daplink_bridgedriver (device + constants + manifest) and a dedicated scenario test. - Refactored
daplink_flashto accept/use aDaplinkBridgeand removed config-zone operations from the flash layer. - Updated
steami_config, scenario tests, and multiple examples to useDaplinkBridge.
Reviewed changes
Copilot reviewed 23 out of 24 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/scenarios/steami_config.yaml | Updates scenario wiring to inject a bridge into SteamiConfig and adjusts scripts accordingly. |
| tests/scenarios/daplink_flash.yaml | Updates scenario wiring to construct DaplinkFlash via DaplinkBridge; moves config-zone validation out of flash scenario. |
| tests/scenarios/daplink_bridge.yaml | New scenario coverage for bridge-level status/error + config-zone commands. |
| pyrightconfig.json | Adds lib/daplink_bridge to type-check include paths. |
| lib/wsen-pads/examples/weather_station.py | Migrates example construction to DaplinkBridge → DaplinkFlash. |
| lib/wsen-hids/examples/data_logger.py | Migrates example construction to DaplinkBridge → DaplinkFlash. |
| lib/steami_config/steami_config/device.py | Refactors SteamiConfig to use a bridge instead of flash for config-zone I/O. |
| lib/steami_config/examples/show_config.py | Migrates example to pass DaplinkBridge into SteamiConfig. |
| lib/steami_config/examples/calibrate_temperature.py | Migrates example to use DaplinkBridge directly for config persistence. |
| lib/steami_config/examples/calibrate_magnetometer.py | Migrates example to use DaplinkBridge directly for config persistence. |
| lib/lis2mdl/examples/field_logger.py | Migrates example construction to DaplinkBridge → DaplinkFlash. |
| lib/daplink_flash/examples/write_csv.py | Migrates example to use bridge.device_id() and DaplinkFlash(bridge). |
| lib/daplink_flash/examples/sensor_log.py | Migrates example to use bridge.device_id() and DaplinkFlash(bridge). |
| lib/daplink_flash/examples/read_file.py | Migrates example construction to DaplinkBridge → DaplinkFlash. |
| lib/daplink_flash/examples/flash_info.py | Migrates status/error display to DaplinkBridge while keeping filename ops in DaplinkFlash. |
| lib/daplink_flash/examples/erase_flash.py | Migrates error readout to DaplinkBridge while using DaplinkFlash for erase. |
| lib/daplink_flash/daplink_flash/device.py | Refactors flash operations to delegate to a bridge (constructor + internal calls). |
| lib/daplink_flash/daplink_flash/const.py | Removes bridge-level constants, leaving flash-level commands and protocol limits. |
| lib/daplink_bridge/manifest.py | New package manifest for daplink_bridge. |
| lib/daplink_bridge/daplink_bridge/device.py | New bridge implementation encapsulating low-level I2C/register/command + config-zone operations. |
| lib/daplink_bridge/daplink_bridge/const.py | New bridge-level constants for registers/commands/config protocol. |
| lib/daplink_bridge/daplink_bridge/init.py | Exposes DaplinkBridge as package public API. |
| .vscode/settings.json | Adds lib/daplink_bridge to editor paths. |
| .claude/settings.json | Adds Claude permissions config for reading lib/**. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| buf[2 : 2 + chunk_len] = data[offset : offset + chunk_len] | ||
| # Zero-pad remainder | ||
| for i in range(2 + chunk_len, len(buf)): | ||
| buf[i] = 0 | ||
| self.i2c.writeto(self.address, buf) | ||
| self._bridge.i2c.writeto(self._bridge.address, buf) | ||
| offset += chunk_len |
There was a problem hiding this comment.
DaplinkFlash is still writing directly to bridge.i2c/bridge.address here, which couples the high-level layer to the bridge internals and partially defeats the goal of centralizing I2C communication in DaplinkBridge. Consider adding a small bridge-level helper (e.g., a _write_frame(...)/_read(...) method) and using that instead of reaching into i2c and address from this class.
| self._bridge._write_reg(CMD_READ_SECTOR, bytes([sector >> 8, sector & 0xFF])) | ||
| sleep_ms(200) | ||
| return self.i2c.readfrom(self.address, SECTOR_SIZE) | ||
| return self._bridge.i2c.readfrom(self._bridge.address, SECTOR_SIZE) |
There was a problem hiding this comment.
Same layering concern as write(): read_sector() reads via bridge.i2c.readfrom(bridge.address, ...), which makes DaplinkFlash depend on the bridge’s internal transport details. Prefer delegating the raw read to a bridge method so all I2C operations stay encapsulated in DaplinkBridge.
|
Commentaires Copilot traités dans c187d3f et 20f415c :
Aussi mis à jour les READMEs (steami_config et racine) pour refléter la nouvelle architecture. |
|
🎉 This PR is included in version 0.2.2 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Summary
Split the monolithic
daplink_flashmodule into two layers:daplink_bridge(new — low-level bridge communication)device_id(),_status(),_error(),busy(),_wait_busy()_read_reg(),_write_reg(),_write_cmd()read_config(),write_config(),clear_config()daplink_flash(refactored — high-level flash file operations)DaplinkBridgeinstead ofi2cset_filename(),get_filename()clear_flash(),write(),write_line()read_sector(),read()steami_config(updated)DaplinkBridgeinstead ofDaplinkFlashMigration
Files changed (24)
lib/daplink_bridge/(4 files),tests/scenarios/daplink_bridge.yamldaplink_flash(const.py, device.py),steami_config(device.py)BREAKING CHANGE:
DaplinkFlashandSteamiConfigconstructors changed.Closes #256
Test plan
make cipasses (196 mock tests + 271 example validations)ruff checkpasses