Skip to content

refactor(daplink_flash): Split into daplink_bridge + daplink_flash layers.#285

Merged
nedseb merged 4 commits into
mainfrom
refactor/split-daplink-bridge
Mar 28, 2026
Merged

refactor(daplink_flash): Split into daplink_bridge + daplink_flash layers.#285
nedseb merged 4 commits into
mainfrom
refactor/split-daplink-bridge

Conversation

@nedseb
Copy link
Copy Markdown
Contributor

@nedseb nedseb commented Mar 28, 2026

Summary

Split the monolithic daplink_flash module 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)

  • Takes a DaplinkBridge instead of i2c
  • set_filename(), get_filename()
  • clear_flash(), write(), write_line()
  • read_sector(), read()

steami_config (updated)

  • Takes a DaplinkBridge instead of DaplinkFlash

Migration

# Before
flash = DaplinkFlash(i2c)

# After
bridge = DaplinkBridge(i2c)
flash = DaplinkFlash(bridge)
config = SteamiConfig(bridge)

Files changed (24)

  • New: lib/daplink_bridge/ (4 files), tests/scenarios/daplink_bridge.yaml
  • Refactored: daplink_flash (const.py, device.py), steami_config (device.py)
  • Updated: 11 examples, 2 test scenarios, pyrightconfig.json, .vscode/settings.json

BREAKING CHANGE: DaplinkFlash and SteamiConfig constructors changed.

Closes #256

Test plan

  • make ci passes (196 mock tests + 271 example validations)
  • ruff check passes
  • Hardware tests on STeaMi board

…yers.

DaplinkFlash now takes a DaplinkBridge instead of i2c.
SteamiConfig now takes a DaplinkBridge instead of DaplinkFlash.
Copilot AI review requested due to automatic review settings March 28, 2026 17:13
@@ -0,0 +1,135 @@
from time import sleep_ms

from daplink_bridge.const import *
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_bridge driver (device + constants + manifest) and a dedicated scenario test.
  • Refactored daplink_flash to accept/use a DaplinkBridge and removed config-zone operations from the flash layer.
  • Updated steami_config, scenario tests, and multiple examples to use DaplinkBridge.

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 DaplinkBridgeDaplinkFlash.
lib/wsen-hids/examples/data_logger.py Migrates example construction to DaplinkBridgeDaplinkFlash.
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 DaplinkBridgeDaplinkFlash.
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 DaplinkBridgeDaplinkFlash.
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.

Comment on lines 56 to 60
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
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +85 to +87
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)
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@nedseb
Copy link
Copy Markdown
Contributor Author

nedseb commented Mar 28, 2026

Commentaires Copilot traités dans c187d3f et 20f415c :

  1. import * dans daplink_bridge — c'est la convention du projet (documentée dans CLAUDE.md, ruff F403/F405 désactivés). Tous les drivers utilisent ce pattern. Non modifié.

  2. et 3. Accès direct à bridge.i2c / bridge.address dans daplink_flash — corrigé. Ajouté _writeto() et _readfrom() dans DaplinkBridge pour encapsuler les opérations I2C brutes. DaplinkFlash n'accède plus aux attributs internes du bridge.

Aussi mis à jour les READMEs (steami_config et racine) pour refléter la nouvelle architecture.

@nedseb nedseb merged commit 5057387 into main Mar 28, 2026
9 checks passed
@nedseb nedseb deleted the refactor/split-daplink-bridge branch March 28, 2026 17:33
@semantic-release-updater
Copy link
Copy Markdown

🎉 This PR is included in version 0.2.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: Split daplink_flash into daplink_bridge + daplink_flash layers.

2 participants