diff --git a/.gitignore b/.gitignore index 7d26cd26..fb133f3a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,4 @@ __pycache__ *.1 78e43b91-b6a2-4e0a-99c2-3f6f74828063_ExportBlock-935e0d48-7286-4b74-aa60-ccd18217ac01 node_modules/ -CLAUDE.md \ No newline at end of file +CLAUDE.md diff --git a/lib/wsen-pads/README.md b/lib/wsen-pads/README.md index 0ca4c067..a9dac7c6 100644 --- a/lib/wsen-pads/README.md +++ b/lib/wsen-pads/README.md @@ -443,14 +443,18 @@ This computes a corrected gain and offset so that the measured temperature bette Examples are available in the `examples` directory. -| Example | Description | -| ------------- | ----------------------------------- | -| `basic_reader.py` | Basic pressure and temperature read | -| `continuous_reader.py` | Continuous measurement example | -| `one_shot_reader.py` | One-shot measurement example | -| `altitude.py` | Altitude estimation from pressure | -| `test.py` | Driver test script | - +| Example | Description | +| -------------------------- | --------------------------------------------------------------------------- | +| `basic_reader.py` | Basic pressure and temperature read | +| `continuous_reader.py` | Continuous measurement example | +| `one_shot_reader.py` | One-shot measurement example | +| `altitude.py` | Altitude estimation from pressure | +| `altitude_calibration.py` | Calibrate sea-level pressure from known altitude and compute corrected altitude | +| `floor_detector.py` | Detect floor changes based on altitude variations | +| `pressure_trend.py` | Track pressure changes over time to detect trends | +| `temp_pressure_display.py` | Display formatted temperature and pressure with ASCII bar graphs | +| `threshold_alert.py` | Monitor pressure and trigger an alert when a threshold is crossed | +| `weather_station.py` | Monitor weather condition and register them in a CSV file on the board | --- diff --git a/lib/wsen-pads/examples/altitude.py b/lib/wsen-pads/examples/altitude.py index c60b72ea..23d428ed 100644 --- a/lib/wsen-pads/examples/altitude.py +++ b/lib/wsen-pads/examples/altitude.py @@ -1,6 +1,6 @@ from time import sleep -from machine import I2C, Pin +from machine import I2C from wsen_pads import WSEN_PADS SEA_LEVEL_PRESSURE = 1013.25 # depends on your location, you can adjust it for better altitude estimation diff --git a/lib/wsen-pads/examples/altitude_calibration.py b/lib/wsen-pads/examples/altitude_calibration.py new file mode 100644 index 00000000..0e3b85d8 --- /dev/null +++ b/lib/wsen-pads/examples/altitude_calibration.py @@ -0,0 +1,33 @@ +from time import sleep + +from machine import I2C +from wsen_pads import WSEN_PADS + +# Set your known altitude (in meters) for calibration +KNOWN_ALTITUDE = 12 # Example: your location altitude + +i2c = I2C(1) +sensor = WSEN_PADS(i2c) + + +pressure = sensor.pressure_hpa() + +# Compute sea-level pressure based on known altitude +# Formula derived from barometric equation +sea_level_pressure = pressure / (1 - (KNOWN_ALTITUDE / 44330.0)) ** 5.255 + +print("Calibration:") +print(" Measured pressure: {:.1f} hPa".format(pressure)) +print(" Known altitude: {:.1f} m".format(KNOWN_ALTITUDE)) +print(" Sea-level pressure: {:.1f} hPa".format(sea_level_pressure)) +print("-" * 50) + +while True: + pressure = sensor.pressure_hpa() + + # Compute altitude using calibrated sea-level pressure + altitude = 44330.0 * (1 - (pressure / sea_level_pressure) ** (1 / 5.255)) + + print("Altitude: {:6.1f} m | Pressure: {:6.1f} hPa".format(altitude, pressure)) + + sleep(1) diff --git a/lib/wsen-pads/examples/basic_reader.py b/lib/wsen-pads/examples/basic_reader.py index faef4864..2203c6d7 100644 --- a/lib/wsen-pads/examples/basic_reader.py +++ b/lib/wsen-pads/examples/basic_reader.py @@ -1,6 +1,6 @@ from time import sleep -from machine import I2C, Pin +from machine import I2C from wsen_pads import WSEN_PADS # Update the I2C bus number and pins to match your board diff --git a/lib/wsen-pads/examples/continuous_reader.py b/lib/wsen-pads/examples/continuous_reader.py index b97285be..d0704187 100644 --- a/lib/wsen-pads/examples/continuous_reader.py +++ b/lib/wsen-pads/examples/continuous_reader.py @@ -1,6 +1,6 @@ from time import sleep -from machine import I2C, Pin +from machine import I2C from wsen_pads import WSEN_PADS from wsen_pads.const import ODR_10_HZ diff --git a/lib/wsen-pads/examples/floor_detector.py b/lib/wsen-pads/examples/floor_detector.py new file mode 100644 index 00000000..f6f2989f --- /dev/null +++ b/lib/wsen-pads/examples/floor_detector.py @@ -0,0 +1,46 @@ +"""Measure altitude at startup as baseline, then loop and detect floor changes (each ~3m altitude difference = 1 floor). Print "Floor +1", "Floor -1", etc.""" + +from time import sleep + +from machine import I2C +from wsen_pads import WSEN_PADS +from wsen_pads.const import ODR_10_HZ + +i2c = I2C(1) +sensor = WSEN_PADS(i2c) +sensor.set_continuous(odr=ODR_10_HZ) + +SAMPLES_FOR_BASELINE = 20 +SAMPLES_PER_MEASURE = 10 +METERS_PER_FLOOR = 3.0 + +baseline_pressure_list = [] + +print("Measuring baseline pressure...") +for _ in range(SAMPLES_FOR_BASELINE): + pressure = sensor.pressure_hpa() + baseline_pressure_list.append(pressure) + + sleep(0.5) + +baseline_pressure = sum(baseline_pressure_list) / len(baseline_pressure_list) +print("Baseline pressure:", baseline_pressure, "hPa") + +while True: + pressure_samples = [] + + print("Measuring...") + for _ in range(SAMPLES_PER_MEASURE): + pressure = sensor.pressure_hpa() + pressure_samples.append(pressure) + + sleep(0.5) + + avg_pressure = sum(pressure_samples) / len(pressure_samples) + + # Calculate altitude difference from baseline using barometric formula + altitude_diff = 44330 * (1 - (avg_pressure / baseline_pressure) ** (1/5.255)) + + floor_change = round(altitude_diff / METERS_PER_FLOOR) + + print("Avg Pressure:", avg_pressure, "hPa Altitude Diff:", altitude_diff, "m Floor Change:", floor_change) diff --git a/lib/wsen-pads/examples/one_shot_reader.py b/lib/wsen-pads/examples/one_shot_reader.py index 63951c50..20835714 100644 --- a/lib/wsen-pads/examples/one_shot_reader.py +++ b/lib/wsen-pads/examples/one_shot_reader.py @@ -1,6 +1,6 @@ from time import sleep -from machine import I2C, Pin +from machine import I2C from wsen_pads import WSEN_PADS i2c = I2C(1) diff --git a/lib/wsen-pads/examples/pressure_trend.py b/lib/wsen-pads/examples/pressure_trend.py new file mode 100644 index 00000000..01e06695 --- /dev/null +++ b/lib/wsen-pads/examples/pressure_trend.py @@ -0,0 +1,49 @@ +"""Read pressure every 10s, keep the last 10 values in a list, print whether pressure is rising, falling, or stable (useful for simple weather prediction)""" + +from time import sleep + +from machine import I2C +from wsen_pads import WSEN_PADS +from wsen_pads.const import ODR_10_HZ + +i2c = I2C(1) +sensor = WSEN_PADS(i2c) + +sensor.set_continuous(odr=ODR_10_HZ) + +pressure_history = [] +MAX_VALUES = 10 +THRESHOLD = 0.5 # sensitivity (hPa) + +def get_trend(values): + if len(values) < 2: + return "N/A" + + half = len(values) // 2 + first_half_avg = sum(values[:half]) / len(values[:half]) + second_half_avg = sum(values[half:]) / len(values[half:]) + + diff = second_half_avg - first_half_avg + + if abs(diff) < THRESHOLD: + return "stable" + elif diff > 0: + return "rising" + else: + return "falling" + +while True: + pressure = sensor.pressure_hpa() + + # store value + pressure_history.append(pressure) + + # keep only last 10 values + if len(pressure_history) > MAX_VALUES: + pressure_history.pop(0) + + trend = get_trend(pressure_history) + + print("P:", pressure, "hPa, Pressure is", trend) + + sleep(10) diff --git a/lib/wsen-pads/examples/temp_pressure_display.py b/lib/wsen-pads/examples/temp_pressure_display.py new file mode 100644 index 00000000..bb558bea --- /dev/null +++ b/lib/wsen-pads/examples/temp_pressure_display.py @@ -0,0 +1,41 @@ +""" +Read temperature and pressure, format a nice display with units and a simple bar graph using # characters to visualize pressure (e.g. 1013.2 hPa [##########-----]) +""" +from time import sleep + +from machine import I2C +from wsen_pads import WSEN_PADS + +TEMP_MIN = 15.0 +TEMP_MAX = 30.0 +PRESS_MIN = 960.0 +PRESS_MAX = 1060.0 + + +i2c = I2C(1) +sensor = WSEN_PADS(i2c) + +def bar_graph(value, vmin, vmax, width=20): + # Clamp value + if value < vmin: + value = vmin + elif value > vmax: + value = vmax + + ratio = (value - vmin) / (vmax - vmin) + filled = int(ratio * width) + + return "[" + "#" * filled + "-" * (width - filled) + "]" + +while True: + pressure, temp = sensor.read() + temp_bar = bar_graph(temp, TEMP_MIN, TEMP_MAX) + press_bar = bar_graph(pressure, PRESS_MIN, PRESS_MAX) + + line = "T:{:5.1f}°C {} | P:{:6.1f}hPa {}".format( + temp, temp_bar, pressure, press_bar + ) + + print("\r" + line, end="") + + sleep(1) diff --git a/lib/wsen-pads/examples/test.py b/lib/wsen-pads/examples/test.py deleted file mode 100644 index be356bac..00000000 --- a/lib/wsen-pads/examples/test.py +++ /dev/null @@ -1,292 +0,0 @@ -from time import sleep - -from machine import I2C, Pin -from wsen_pads import WSEN_PADS -from wsen_pads.const import ( - ODR_1_HZ, - ODR_10_HZ, - REG_CTRL_1, - REG_CTRL_2, - REG_INT_SOURCE, - REG_STATUS, -) - - -def print_header(title): - print() - print("=" * 60) - print(title) - print("=" * 60) - - -def print_pass(name): - print("[PASS] {}".format(name)) - - -def print_fail(name, err=None): - if err is None: - print("[FAIL] {}".format(name)) - else: - print("[FAIL] {} -> {}".format(name, err)) - - -def dump_registers(sensor): - ctrl1 = sensor._read_reg(REG_CTRL_1) - ctrl2 = sensor._read_reg(REG_CTRL_2) - int_source = sensor._read_reg(REG_INT_SOURCE) - - print("CTRL_1 = 0x{:02X}".format(ctrl1)) - print("CTRL_2 = 0x{:02X}".format(ctrl2)) - print("data_ready() =", sensor.data_ready()) - print("INT_SOURCE = 0x{:02X}".format(int_source)) - - -def test_i2c_scan(i2c): - print_header("1) I2C scan") - devices = i2c.scan() - print("I2C devices found:", [hex(x) for x in devices]) - - if 0x5C in devices or 0x5D in devices: - print_pass("WSEN-PADS address found") - return True - else: - print_fail("WSEN-PADS address not found") - return False - - -def test_device_id(sensor): - print_header("2) Device ID") - dev_id = sensor.device_id() - print("Device ID:", hex(dev_id)) - - if dev_id == 0xB3: - print_pass("Device ID matches 0xB3") - return True - else: - print_fail("Device ID matches 0xB3", hex(dev_id)) - return False - - -def test_default_registers(sensor): - print_header("3) Default driver configuration") - dump_registers(sensor) - - ctrl1 = sensor._read_reg(REG_CTRL_1) - ctrl2 = sensor._read_reg(REG_CTRL_2) - - # BDU should be enabled by the driver - bdu_ok = bool(ctrl1 & 0x02) - - # IF_ADD_INC should be enabled by the driver - if_add_inc_ok = bool(ctrl2 & 0x10) - - if bdu_ok: - print_pass("BDU enabled") - else: - print_fail("BDU enabled") - - if if_add_inc_ok: - print_pass("IF_ADD_INC enabled") - else: - print_fail("IF_ADD_INC enabled") - - return bdu_ok and if_add_inc_ok - - -def test_soft_reset(sensor): - print_header("4) Soft reset") - try: - sensor.soft_reset() - sleep(0.05) - dump_registers(sensor) - - if sensor.device_id() == 0xB3: - print_pass("Soft reset") - return True - else: - print_fail("Soft reset", "device ID mismatch after reset") - return False - except Exception as err: - print_fail("Soft reset", err) - return False - - -def test_reboot(sensor): - print_header("5) Reboot") - try: - sensor.reboot() - sleep(1) - dump_registers(sensor) - - if sensor.device_id() == 0xB3: - print_pass("Reboot") - return True - else: - print_fail("Reboot", "device ID mismatch after reboot") - return False - except Exception as err: - print_fail("Reboot", err) - return False - - -def test_one_shot(sensor): - print_header("6) One-shot read") - - try: - pressure_hpa, temperature_c = sensor.read_one_shot() - - raw_p = sensor.pressure_raw() - raw_t = sensor.temperature_raw() - - print("Raw pressure :", raw_p) - print("Raw temperature :", raw_t) - print("Pressure : {:.2f} hPa".format(pressure_hpa)) - print("Temperature : {:.2f} °C".format(temperature_c)) - print("data_ready() :", sensor.data_ready()) - - # Basic sanity checks - MIN_PRESSURE = 260.0 - MAX_PRESSURE = 1260.0 - MIN_TEMPERATURE = -40.0 - MAX_TEMPERATURE = 85.0 - pressure_ok = MIN_PRESSURE <= pressure_hpa <= MAX_PRESSURE - temperature_ok = MIN_TEMPERATURE <= temperature_c <= MAX_TEMPERATURE - raw_ok = not (raw_p == 0 and raw_t == 0) - - if raw_ok: - print_pass("Raw data is not all zero") - else: - print_fail("Raw data is not all zero") - - if pressure_ok: - print_pass("Pressure is in a valid range") - else: - print_fail("Pressure is in a valid range", pressure_hpa) - - if temperature_ok: - print_pass("Temperature is in a valid range") - else: - print_fail("Temperature is in a valid range", temperature_c) - - return raw_ok and pressure_ok and temperature_ok - - except Exception as err: - print_fail("One-shot read", err) - return False - - -def test_continuous_mode(sensor, odr, label, wait_s=2): - print_header("7) Continuous mode - {}".format(label)) - - try: - sensor.set_continuous(odr=odr) - print("Waiting {} second(s) for fresh samples...".format(wait_s)) - sleep(wait_s) - - ok = True - - for i in range(5): - pressure_hpa = sensor.pressure_hpa() - temperature_c = sensor.temperature() - raw_p = sensor.pressure_raw() - raw_t = sensor.temperature_raw() - print( - "#{:d} P={:.2f} hPa T={:.2f} °C rawP={} rawT={} ready={}".format( - i + 1, - pressure_hpa, - temperature_c, - raw_p, - raw_t, - sensor.data_ready(), - ) - ) - - if raw_p == 0 and raw_t == 0: - ok = False - - sleep(0.5) - - sensor.power_off() - - if ok: - print_pass("Continuous mode - {}".format(label)) - else: - print_fail("Continuous mode - {}".format(label), "raw data stayed at zero") - - return ok - - except Exception as err: - print_fail("Continuous mode - {}".format(label), err) - return False - - -def test_status_flags(sensor): - print_header("8) STATUS helpers") - - try: - sensor.set_continuous(odr=ODR_1_HZ) - sleep(1.5) - - p_avail = sensor.pressure_ready() - t_avail = sensor.temperature_ready() - ready = sensor.data_ready() - - print("pressure_ready() =", p_avail) - print("temperature_ready() =", t_avail) - print("data_ready() =", ready) - - sensor.power_off() - - if p_avail or t_avail or ready: - print_pass("STATUS helper methods") - return True - else: - print_fail("STATUS helper methods") - return False - - except Exception as err: - print_fail("STATUS helper methods", err) - return False - - -def main(): - print_header("WSEN-PADS full driver test") - - i2c = I2C(1) - - if not test_i2c_scan(i2c): - print() - print("Stop: sensor not found on I2C bus.") - return - - try: - sensor = WSEN_PADS(i2c) - except Exception as err: - print_fail("Driver init", err) - return - - results = [] - - results.append(test_device_id(sensor)) - results.append(test_default_registers(sensor)) - results.append(test_soft_reset(sensor)) - results.append(test_reboot(sensor)) - results.append(test_one_shot(sensor)) - results.append(test_continuous_mode(sensor, ODR_1_HZ, "1 Hz", wait_s=2)) - results.append(test_continuous_mode(sensor, ODR_10_HZ, "10 Hz", wait_s=1)) - results.append(test_status_flags(sensor)) - - print_header("Final result") - - passed = sum(1 for x in results if x) - total = len(results) - - print("Passed: {}/{}".format(passed, total)) - - if passed == total: - print("All tests passed.") - else: - print("Some tests failed.") - - -main() diff --git a/lib/wsen-pads/examples/threshold_alert.py b/lib/wsen-pads/examples/threshold_alert.py new file mode 100644 index 00000000..1aac09d3 --- /dev/null +++ b/lib/wsen-pads/examples/threshold_alert.py @@ -0,0 +1,35 @@ +"""Monitor pressure continuously and print an alert when pressure drops below a configurable threshold (e.g. storm detection).""" + +from time import sleep + +from machine import I2C +from wsen_pads import WSEN_PADS +from wsen_pads.const import ODR_10_HZ + +PRESSURE_ALERT_HPA = 1000 # Alert threshold +READ_INTERVAL_S = 1 # Time between printed readings + +i2c = I2C(1) +sensor = WSEN_PADS(i2c) + +sensor.set_continuous(odr=ODR_10_HZ) + +print("Pressure monitor started") +print("Alert threshold:", PRESSURE_ALERT_HPA, "hPa") + +alert_active = False + +while True: + pressure = sensor.pressure_hpa() + + # Threshold detection + if pressure < PRESSURE_ALERT_HPA: + if not alert_active: + print("ALERT: pressure dropped below", PRESSURE_ALERT_HPA, "hPa") + alert_active = True + else: + if alert_active: + print("INFO: pressure back above", PRESSURE_ALERT_HPA, "hPa") + alert_active = False + + sleep(READ_INTERVAL_S) diff --git a/lib/wsen-pads/examples/weather_station.py b/lib/wsen-pads/examples/weather_station.py new file mode 100644 index 00000000..a4348c8f --- /dev/null +++ b/lib/wsen-pads/examples/weather_station.py @@ -0,0 +1,32 @@ +"""Loop that reads pressure + temperature every 5s, computes altitude, prints a formatted summary, and logs each measurement to a CSV file on the DAPLink flash using daplink_flash (set_filename, write_line). The file can then be read back from USB mass storage.""" + +from time import sleep, sleep_ms + +from daplink_flash import DaplinkFlash +from machine import I2C +from wsen_pads import WSEN_PADS +from wsen_pads.const import ODR_10_HZ + +i2c = I2C(1) + +sensor = WSEN_PADS(i2c) +flash = DaplinkFlash(i2c) + +sensor.set_continuous(odr=ODR_10_HZ) + +# Set filename and erase +flash.set_filename("WSTATION", "CSV") +flash.clear_flash() +sleep_ms(500) +print("Flash erased.") + +flash.write_line("temperature;pressure") + +while True: + pressure = sensor.pressure_hpa() + temperature = sensor.temperature() + + print("P:", pressure, "hPa T:", temperature, "°C") + flash.write_line("{:.1f};{:.1f}".format(temperature, pressure)) + + sleep(5) diff --git a/tests/scenarios/wsen_pads.yaml b/tests/scenarios/wsen_pads.yaml index cf7b214d..b408a27e 100644 --- a/tests/scenarios/wsen_pads.yaml +++ b/tests/scenarios/wsen_pads.yaml @@ -121,3 +121,242 @@ tests: prompt: "Ces valeurs sont-elles cohérentes (pression ~1013 hPa, température ambiante) ?" expect_true: true mode: [hardware] + + # --------------------------------------------------------------------------- + # Init / identification + # --------------------------------------------------------------------------- + + - name: "Device absent raises exception" + action: script + script: | + from wsen_pads import WSEN_PADS + from wsen_pads.exceptions import WSENPADSDeviceNotFound + + try: + i2c.scan = lambda: [] + WSEN_PADS(i2c, address=0x5D) + result = False + except WSENPADSDeviceNotFound: + result = True + except Exception: + result = False + expect_true: true + mode: [mock] + + - name: "Invalid DEVICE_ID raises exception" + action: script + script: | + from wsen_pads import WSEN_PADS + from wsen_pads.exceptions import WSENPADSInvalidDevice + + original = i2c._registers[0x0F] + i2c._registers[0x0F] = bytes([0x00]) + + try: + WSEN_PADS(i2c, address=0x5D) + result = False + except WSENPADSInvalidDevice: + result = True + except Exception: + result = False + + i2c._registers[0x0F] = original + expect_true: true + mode: [mock] + + - name: "Boot timeout raises exception at init" + action: script + script: | + from wsen_pads import WSEN_PADS + from wsen_pads.exceptions import WSENPADSTimeout + + original = i2c._registers[0x24] + i2c._registers[0x24] = bytes([0x80]) # INT_SOURCE_BOOT_ON + + try: + WSEN_PADS(i2c, address=0x5D) + result = False + except WSENPADSTimeout: + result = True + except Exception: + result = False + + i2c._registers[0x24] = original + expect_true: true + mode: [mock] + + # --------------------------------------------------------------------------- + # Continuous mode validation + # --------------------------------------------------------------------------- + + - name: "set_continuous rejects invalid ODR" + action: script + script: | + try: + dev.set_continuous(odr=99) + result = False + except ValueError: + result = True + except Exception: + result = False + expect_true: true + mode: [mock] + + - name: "set_continuous rejects low-noise at 100 Hz" + action: script + script: | + try: + dev.set_continuous(odr=0x06, low_noise=True) + result = False + except ValueError: + result = True + except Exception: + result = False + expect_true: true + mode: [mock] + + - name: "set_continuous rejects low-noise at 200 Hz" + action: script + script: | + try: + dev.set_continuous(odr=0x07, low_noise=True) + result = False + except ValueError: + result = True + except Exception: + result = False + expect_true: true + mode: [mock] + + # --------------------------------------------------------------------------- + # Status helpers + # --------------------------------------------------------------------------- + + - name: "pressure_ready false when status empty" + action: script + script: | + i2c._registers[0x27] = bytes([0x00]) + result = dev.pressure_ready() + i2c._registers[0x27] = bytes([0x03]) + expect_false: true + mode: [mock] + + - name: "temperature_ready false when status empty" + action: script + script: | + i2c._registers[0x27] = bytes([0x00]) + result = dev.temperature_ready() + i2c._registers[0x27] = bytes([0x03]) + expect_false: true + mode: [mock] + + - name: "data_ready false when status empty" + action: script + script: | + i2c._registers[0x27] = bytes([0x00]) + result = dev.data_ready() + i2c._registers[0x27] = bytes([0x03]) + expect_false: true + mode: [mock] + + - name: "pressure_ready true when only pressure available" + action: script + script: | + i2c._registers[0x27] = bytes([0x01]) # STATUS_P_DA + result = dev.pressure_ready() + i2c._registers[0x27] = bytes([0x03]) + expect_true: true + mode: [mock] + + - name: "temperature_ready true when only temperature available" + action: script + script: | + i2c._registers[0x27] = bytes([0x02]) # STATUS_T_DA + result = dev.temperature_ready() + i2c._registers[0x27] = bytes([0x03]) + expect_true: true + mode: [mock] + + - name: "data_ready false when only pressure available" + action: script + script: | + i2c._registers[0x27] = bytes([0x01]) # STATUS_P_DA + result = dev.data_ready() + i2c._registers[0x27] = bytes([0x03]) + expect_false: true + mode: [mock] + + - name: "data_ready false when only temperature available" + action: script + script: | + i2c._registers[0x27] = bytes([0x02]) # STATUS_T_DA + result = dev.data_ready() + i2c._registers[0x27] = bytes([0x03]) + expect_false: true + mode: [mock] + + - name: "data_ready true when pressure and temperature available" + action: script + script: | + i2c._registers[0x27] = bytes([0x03]) # STATUS_P_DA | STATUS_T_DA + result = dev.data_ready() + expect_true: true + mode: [mock] + + # --------------------------------------------------------------------------- + # Reset / reboot + # --------------------------------------------------------------------------- + + - name: "soft_reset reapplies default configuration" + action: script + script: | + dev.set_continuous(odr=0x03, low_noise=True, low_pass=True, low_pass_strong=True) + dev.soft_reset() + + ctrl1 = i2c._registers[0x10][0] + ctrl2 = i2c._registers[0x11][0] + + bdu_ok = (ctrl1 & 0x02) == 0x02 + odr_power_down = (ctrl1 & 0x70) == 0x00 + auto_inc_ok = (ctrl2 & 0x10) == 0x10 + low_noise_off = (ctrl2 & 0x02) == 0x00 + + result = bdu_ok and odr_power_down and auto_inc_ok and low_noise_off + expect_true: true + mode: [mock] + + - name: "reboot reapplies default configuration" + action: script + script: | + dev.set_continuous(odr=0x03, low_noise=False, low_pass=True, low_pass_strong=True) + i2c._registers[0x24] = bytes([0x00]) # boot already finished + dev.reboot() + + ctrl1 = i2c._registers[0x10][0] + ctrl2 = i2c._registers[0x11][0] + + bdu_ok = (ctrl1 & 0x02) == 0x02 + odr_power_down = (ctrl1 & 0x70) == 0x00 + auto_inc_ok = (ctrl2 & 0x10) == 0x10 + low_noise_off = (ctrl2 & 0x02) == 0x00 + + result = bdu_ok and odr_power_down and auto_inc_ok and low_noise_off + expect_true: true + mode: [mock] + + # --------------------------------------------------------------------------- + # Calibration + # --------------------------------------------------------------------------- + + - name: "Temperature calibration rejects identical measured points" + action: script + script: | + try: + dev.calibrate_temperature(20.0, 25.0, 30.0, 25.0) + result = False + except ValueError: + result = True + except Exception: + result = False + expect_true: true + mode: [mock]