feat: add ECMA-419 SHT3x sensor driver by meganetaaan · Pull Request #617 · stack-chan/stack-chan · GitHub
Skip to content

feat: add ECMA-419 SHT3x sensor driver - #617

Open
meganetaaan wants to merge 5 commits into
developfrom
agent/ecma419-sht3x
Open

feat: add ECMA-419 SHT3x sensor driver#617
meganetaaan wants to merge 5 commits into
developfrom
agent/ecma419-sht3x

Conversation

@meganetaaan

@meganetaaan meganetaaan commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add a pure-JavaScript, ECMA-419/TR/109-compatible SHT3x sensor driver for SHT30, SHT31, and SHT35 devices.
  • Migrate the Unit Temperature MOD to the local driver and add reusable I2C conformance coverage.

What Changed

  • Implement the Sensor Class Pattern lifecycle with target, configure(), sample(), idempotent close(), Symbol.dispose, and asynchronous onError() handling.
  • Validate SHT3x CRC bytes, return fresh compound samples, and normalize relative humidity to the ECMA-419 0..1 range.
  • Use the no-clock-stretch single-shot command 0x2400 and wait 16 ms before reading, covering the datasheet's 15.5 ms maximum high-repeatability conversion time.
  • Add a shared MockI2C and XS conformance tests for construction, cleanup, sampling, measurement settling, CRC recovery, and terminal I/O failures.
  • Expand Moddable test discovery from mods/examples to all mods so driver tests run by default.
  • Update the Unit Temperature MOD to display normalized humidity as a percentage and handle both CRC failures and thrown I/O errors locally.

Verification

  • cd firmware && npm run format
  • cd firmware && npm run lint
  • cd firmware && npx biome ci . --error-on-warnings
  • cd firmware && npm run test — 331 tests passed
  • cd firmware && npm run check:legacy-names
  • Other checks were run when relevant
    • npm run check:architecture — passed
    • npm run check:manifest — 6 targets passed
    • npm run test:moddable — all 37 manifests passed, including SHT3x conformance
    • STACKCHAN_MODULE_TEST_FILTER=sht3x-conformance npm run test:moddable — passed after the hardware-derived timing change

Physical hardware

  • M5StackChan CoreS3 on /dev/ttyACM0, with the M5Stack SHT30 Unit connected to Port A
  • 28 consecutive CRC-valid samples with no I/O exceptions
  • Observed range: 24.9680–25.1068 °C and 74.9630–75.3902 %RH
  • The clock-stretch command 0x2C06 failed on this controller. The no-clock-stretch command 0x2400 plus a 16 ms conversion wait produced stable readings.
  • The original XS archive was backed up before testing and restored with flash verification afterward.

Affected Areas

  • firmware
  • web
  • schematics
  • case
  • docs
  • ci/github-actions

Breaking Changes

  • none
  • yes, described below

Release Impact

  • minor — adds a user-visible sensor driver and updates the Unit Temperature MOD.
  • Release note included in .changeset/calm-sensors-sample.md.

Related Issues

  • None

Summary by CodeRabbit

  • New Features
    • Added an ECMA-419-compatible SHT3x sensor driver for Sensirion SHT30/SHT31/SHT35 devices.
  • Improvements
    • Updated the temperature example to use the new driver, display humidity as a percentage, and report sensor read failures clearly.
  • Tests
    • Added comprehensive conformance coverage for sampling, validation, lifecycle behavior, CRC handling, and retry scenarios.
  • Documentation
    • Documented driver configuration, measurements, CRC handling, and runtime behavior.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@firmware/mods/examples/unit_temperature/mod.js`:
- Around line 15-17: Wrap the SHT3x sample call in the relevant targetLoop flow
with try/catch so I2C exceptions trigger the same “Sensor read failed.” balloon
and return path as the existing sample === undefined CRC guard. Preserve the
current CRC handling while ensuring both thrown errors and undefined samples are
handled locally.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 4bc6a19d-72f6-4513-acfd-0bf97d285105

📥 Commits

Reviewing files that changed from the base of the PR and between d4646a8 and d9ed39f.

📒 Files selected for processing (12)
  • .changeset/calm-sensors-sample.md
  • firmware/host/modules/testing/fakes/mock-i2c.ts
  • firmware/host/modules/testing/manifest.json
  • firmware/mods/drivers/sensors/sht3x/README.md
  • firmware/mods/drivers/sensors/sht3x/__tests__/sht3x-conformance/manifest.test.json
  • firmware/mods/drivers/sensors/sht3x/__tests__/sht3x-conformance/sht3x-conformance.test.ts
  • firmware/mods/drivers/sensors/sht3x/__tests__/sht3x-conformance/timer.js
  • firmware/mods/drivers/sensors/sht3x/manifest.json
  • firmware/mods/drivers/sensors/sht3x/sht3x.js
  • firmware/mods/examples/unit_temperature/manifest.json
  • firmware/mods/examples/unit_temperature/mod.js
  • firmware/scripts/run-module-tests.js

Comment thread firmware/mods/examples/unit_temperature/mod.js
@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
firmware/mods/drivers/sensors/sht3x/__tests__/sht3x-conformance/sht3x-conformance.test.ts (1)

120-137: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Re-arm the settling check for every measurement.

minimumSettleTimeElapsed becomes true after the first timer fires and is never reset. The same io.read wrapper handles the second sensor.sample() call, so that read can occur without a new settling delay and still pass. The timer also starts before the measurement write.

Start a fresh timer for each MEASURE write and clear it after the corresponding read, or record the write-to-read interval in MockI2C.

As per path instructions, tests must assert observable behavior or relational invariants.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@firmware/mods/drivers/sensors/sht3x/__tests__/sht3x-conformance/sht3x-conformance.test.ts`
around lines 120 - 137, Update testSampleShapeScaleAndMeasurementSettling so the
settling assertion is re-armed for each MEASURE write and validated only for its
corresponding read. Start the delay timer when each measurement command is
written, clear or reset it after the matching io.read, and preserve coverage for
both sensor.sample() calls without allowing the first timer to satisfy the
second read.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In
`@firmware/mods/drivers/sensors/sht3x/__tests__/sht3x-conformance/sht3x-conformance.test.ts`:
- Around line 120-137: Update testSampleShapeScaleAndMeasurementSettling so the
settling assertion is re-armed for each MEASURE write and validated only for its
corresponding read. Start the delay timer when each measurement command is
written, clear or reset it after the matching io.read, and preserve coverage for
both sensor.sample() calls without allowing the first timer to satisfy the
second read.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6792a50d-7343-492c-a635-53f869f3c626

📥 Commits

Reviewing files that changed from the base of the PR and between 946e59a and 43903ad.

📒 Files selected for processing (3)
  • firmware/mods/drivers/sensors/sht3x/__tests__/sht3x-conformance/sht3x-conformance.test.ts
  • firmware/mods/drivers/sensors/sht3x/sht3x.js
  • firmware/mods/examples/unit_temperature/mod.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • firmware/mods/drivers/sensors/sht3x/sht3x.js

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant