diff --git a/lib/M5Unit-ENV/src/unit/unit_BME688.cpp b/lib/M5Unit-ENV/src/unit/unit_BME688.cpp index 854b25e..26650e0 100644 --- a/lib/M5Unit-ENV/src/unit/unit_BME688.cpp +++ b/lib/M5Unit-ENV/src/unit/unit_BME688.cpp @@ -284,6 +284,12 @@ void UnitBME688::update_bme688() { return; } break; + case Mode::Sequential: + if (!_num_of_data) { + _updated = false; + return; + } + break; default: _updated = false; return; @@ -604,9 +610,6 @@ bool UnitBME688::measureSingleShot(bme68xData& data) { auto interval_us = calculateMeasurementInterval(_mode, _tphConf) + (_heaterConf.heatr_dur * 1000); auto interval_ms = interval_us / 1000 + ((interval_us % 1000) != 0); - M5_LIB_LOGE(">>>>>> %u/%u/%u %ld", _tphConf.os_temp, _tphConf.os_pres, - _tphConf.os_hum, interval_ms); - m5::utility::delay(interval_ms); uint32_t retry{10}; @@ -657,6 +660,11 @@ bool UnitBME688::startPeriodicMeasurement(const Mode m) { } bool UnitBME688::stopPeriodicMeasurement() { + if (_bsec2_subscription) { + M5_LIB_LOGW("During bsec2 operations"); + return false; + } + if (setMode(Mode::Sleep)) { _periodic = false; } diff --git a/lib/M5Unit-ENV/src/unit/unit_BME688.hpp b/lib/M5Unit-ENV/src/unit/unit_BME688.hpp index 1c108b1..9ee12a9 100644 --- a/lib/M5Unit-ENV/src/unit/unit_BME688.hpp +++ b/lib/M5Unit-ENV/src/unit/unit_BME688.hpp @@ -523,12 +523,12 @@ class UnitBME688 : public Component { @param m Mode for measurement @return True if successful @pre Calibration,TPH and heater must already be set up - @warning In Forced mode the intervals are constant, but not in other - modes + @warning Measurement intervals are not constant in Parallel mode */ bool startPeriodicMeasurement(const bme688::Mode m); /*! - @brief Stopt periodic measurement + @brief Stop periodic measurement + @return True if successful */ bool stopPeriodicMeasurement(); ///@} diff --git a/test/embedded/test_bme688/bme688_test.cpp b/test/embedded/test_bme688/bme688_test.cpp index d41d83d..4bc2d39 100644 --- a/test/embedded/test_bme688/bme688_test.cpp +++ b/test/embedded/test_bme688/bme688_test.cpp @@ -185,7 +185,6 @@ TEST_P(TestBME688, Settings) { #if defined(UNIT_BME688_USING_BSEC2) TEST_P(TestBME688, BSEC2) { SCOPED_TRACE(ustr); - return; uint8_t cfg[BSEC_MAX_PROPERTY_BLOB_SIZE]{}; uint8_t state[BSEC_MAX_STATE_BLOB_SIZE]{}; @@ -298,7 +297,6 @@ TEST_P(TestBME688, BSEC2) { } // TODO: call directly in bsec2 - } #endif @@ -392,7 +390,8 @@ TEST_P(TestBME688, PeriodicParallel) { SCOPED_TRACE(ustr); uint16_t temp_prof[10] = {320, 100, 100, 100, 200, 200, 200, 320, 320, 320}; - uint16_t dur_prof[10] = {5, 2, 10, 30, 5, 5, 5, 5, 5, 5}; + /* Multiplier to the shared heater duration */ + uint16_t mul_prof[10] = {5, 2, 10, 30, 5, 5, 5, 5, 5, 5}; bme68xConf tph{}; tph.os_temp = m5::stl::to_underlying(Oversampling::x2); @@ -405,7 +404,7 @@ TEST_P(TestBME688, PeriodicParallel) { bme68xHeatrConf hs{}; hs.enable = true; memcpy(hs.temp_prof, temp_prof, sizeof(temp_prof)); - memcpy(hs.dur_prof, dur_prof, sizeof(dur_prof)); + memcpy(hs.dur_prof, mul_prof, sizeof(mul_prof)); hs.shared_heatr_dur = (uint16_t)(140 - (unit->calculateMeasurementInterval( Mode::Parallel, tph) / 1000)); @@ -421,7 +420,70 @@ TEST_P(TestBME688, PeriodicParallel) { auto interval = unit->interval(); uint32_t cnt{8}; auto prev = unit->updatedMillis(); - auto timeout_at = m5::utility::millis() + (cnt + 1) * 1000; + auto timeout_at = m5::utility::millis() + (interval * 10 * (cnt + 1)); + while (cnt && m5::utility::millis() <= timeout_at) { + unit->update(); + if (unit->updated()) { + --cnt; + auto um = unit->updatedMillis(); + auto duration = um - prev; + prev = um; + // EXPECT_LE(duration, interval); + // M5_LOGW("raw:%u", unit->numberOfRawData()); + for (uint8_t i = 0; i < unit->numberOfRawData(); ++i) { + auto d = unit->data(i); + EXPECT_TRUE(d != nullptr); + if (d) { + M5_LOGI("dur:%ld %f/%f/%f/%f", duration, d->temperature, + d->pressure, d->humidity, d->gas_resistance); + EXPECT_TRUE(std::isfinite(d->temperature)); + EXPECT_TRUE(std::isfinite(d->pressure)); + EXPECT_TRUE(std::isfinite(d->humidity)); + EXPECT_TRUE(std::isfinite(d->gas_resistance)); + } + } + } + m5::utility::delay(1); + } + EXPECT_EQ(cnt, 0U); + + EXPECT_TRUE(unit->stopPeriodicMeasurement()); + EXPECT_FALSE(unit->inPeriodic()); + EXPECT_EQ(unit->mode(), Mode::Sleep); +} + +TEST_P(TestBME688, PeriodiSequential) { + SCOPED_TRACE(ustr); + + uint16_t temp_prof[10] = {200, 240, 280, 320, 360, 360, 320, 280, 240, 200}; + /* Heating duration in milliseconds */ + uint16_t dur_prof[10] = {100, 100, 100, 100, 100, 100, 100, 100, 100, 100}; + + bme68xConf tph{}; + tph.os_temp = m5::stl::to_underlying(Oversampling::x2); + tph.os_pres = m5::stl::to_underlying(Oversampling::x1); + tph.os_hum = m5::stl::to_underlying(Oversampling::x16); + tph.filter = m5::stl::to_underlying(Filter::None); + tph.odr = m5::stl::to_underlying(ODR::None); + EXPECT_TRUE(unit->setTPHSetting(tph)); + + bme68xHeatrConf hs{}; + hs.enable = true; + memcpy(hs.temp_prof, temp_prof, sizeof(temp_prof)); + memcpy(hs.dur_prof, dur_prof, sizeof(dur_prof)); + hs.profile_len = 10; + EXPECT_TRUE(unit->setHeaterSetting(Mode::Sequential, hs)); + + // + EXPECT_FALSE(unit->inPeriodic()); + EXPECT_TRUE(unit->startPeriodicMeasurement(Mode::Sequential)); + EXPECT_TRUE(unit->inPeriodic()); + EXPECT_EQ(unit->mode(), Mode::Sequential); + + auto interval = unit->interval(); + uint32_t cnt{8}; + auto prev = unit->updatedMillis(); + auto timeout_at = m5::utility::millis() + (interval * (cnt + 1)); while (cnt && m5::utility::millis() <= timeout_at) { unit->update(); if (unit->updated()) { @@ -455,5 +517,5 @@ TEST_P(TestBME688, PeriodicParallel) { TEST_P(TestBME688, SelfTest) { SCOPED_TRACE(ustr); - // EXPECT_TRUE(unit->selfTest()); + EXPECT_TRUE(unit->selfTest()); }