Skip to content

Commit

Permalink
Refactor and fixes units
Browse files Browse the repository at this point in the history
  • Loading branch information
GOB52 committed Jul 18, 2024
1 parent 08b6c70 commit 8dc57a1
Show file tree
Hide file tree
Showing 35 changed files with 792 additions and 533 deletions.
16 changes: 8 additions & 8 deletions lib/M5Unit-ENV/src/unit/unit_BME688.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,28 +175,28 @@ bool UnitBME688::begin() {
#endif
}

void UnitBME688::update() {
void UnitBME688::update(const bool force) {
_updated = false;
#if defined(UNIT_BME688_USING_BSEC2)
if (_bsec2_subscription) {
update_bsec2();
update_bsec2(force);
} else {
update_bme688();
update_bme688(force);
}
#else
update_bme688();
update_bme688(force);
#endif
}

#if defined(UNIT_BME688_USING_BSEC2)
// Using BSEC2 library and configration and state
void UnitBME688::update_bsec2() {
void UnitBME688::update_bsec2(const bool force) {
auto now = m5::utility::millis();
int64_t now_ns = now * 1000000ULL; // ms to ns

_bsec2_mode = static_cast<Mode>(_bsec2_settings.op_mode);

if (now_ns < _bsec2_settings.next_call) {
if (!force && now_ns < _bsec2_settings.next_call) {
return;
}

Expand Down Expand Up @@ -257,13 +257,13 @@ void UnitBME688::update_bsec2() {
#endif

// Directly use BME688 (but only raw data can be obtained)
void UnitBME688::update_bme688() {
void UnitBME688::update_bme688(const bool force) {
if (!inPeriodic()) {
return;
}

unsigned long at{m5::utility::millis()};
if (!_latest || at >= _latest + _interval) {
if (force || !_latest || at >= _latest + _interval) {
_updated = read_measurement();
if (_updated) {
switch (_mode) {
Expand Down
6 changes: 3 additions & 3 deletions lib/M5Unit-ENV/src/unit/unit_BME688.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class UnitBME688 : public Component {
}

virtual bool begin() override;
virtual void update() override;
virtual void update(const bool force = false) override;

///@name Properties
///@{
Expand Down Expand Up @@ -665,8 +665,8 @@ class UnitBME688 : public Component {
bool fetch_data();
bool process_data(const int64_t ns, const bme688::bme68xData& data);

void update_bsec2();
void update_bme688();
void update_bsec2(const bool force);
void update_bme688(const bool force);
bool read_measurement();

protected:
Expand Down
7 changes: 3 additions & 4 deletions lib/M5Unit-ENV/src/unit/unit_QMP6988.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,15 @@ bool UnitQMP6988::begin() {
: setPowerMode(qmp6988::PowerMode::Force);
}

void UnitQMP6988::update() {
void UnitQMP6988::update(const bool force) {
_updated = false;
if (inPeriodic()) {
unsigned long at{m5::utility::millis()};
if (!_latest || at >= _latest + _interval) {
if (force || !_latest || at >= _latest + _interval) {
_updated = readMeasurement();
if (_updated) {
_latest = at;
}
} else {
_updated = false;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/M5Unit-ENV/src/unit/unit_QMP6988.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class UnitQMP6988 : public Component {
}

virtual bool begin() override;
virtual void update() override;
virtual void update(const bool force = false) override;

///@name Settings
///@{
Expand Down
Loading

0 comments on commit 8dc57a1

Please sign in to comment.