From 5d7b864947d58b38ff569167ef5ee84d14a6802f Mon Sep 17 00:00:00 2001 From: GOB Date: Tue, 17 Sep 2024 03:26:37 +0900 Subject: [PATCH] Some tweaks --- .../MultipleDevices/main/MultipleDevices.cpp | 20 ++++++++----------- src/M5UnitComponent.hpp | 19 +++++++----------- src/M5UnitUnified.cpp | 2 +- src/M5UnitUnified.hpp | 19 ++++++++++++------ src/googletest/test_helper.hpp | 2 +- src/googletest/test_template.hpp | 2 +- 6 files changed, 31 insertions(+), 33 deletions(-) diff --git a/examples/demo/MultipleDevices/main/MultipleDevices.cpp b/examples/demo/MultipleDevices/main/MultipleDevices.cpp index b43e173..19397f0 100644 --- a/examples/demo/MultipleDevices/main/MultipleDevices.cpp +++ b/examples/demo/MultipleDevices/main/MultipleDevices.cpp @@ -37,7 +37,6 @@ #include "ui/ui_UnitTVOC.hpp" #include "ui/ui_UnitVmeter.hpp" #include "ui/ui_UnitENV3.hpp" -// #include "ui/ui_UnitCO2.hpp" using namespace m5::unit; @@ -112,7 +111,7 @@ void prepare() { // Setup fro begin auto cfg = unitQMP6988.config(); cfg.standby_time = - m5::unit::qmp6988::StandbyTime::Time50ms; // about 16 mps (Calculated from other parameters and this value + m5::unit::qmp6988::Standby::Time50ms; // about 16 mps (Calculated from other parameters and this value unitQMP6988.config(cfg); } @@ -128,7 +127,7 @@ void prepare() { tvocSmallUI.construct(); vmeterSmallUI.construct(); env3SmallUI.construct(); - heartSmallUI.heartRate().setSamplingRate(m5::max30100::HeartRate::getSamplingRate(unitHeart.config().samplingRate)); + heartSmallUI.heartRate().setSampleRate(m5::max30100::HeartRate::getSampleRate(unitHeart.config().sample_rate)); } // task for Vmeter @@ -161,7 +160,7 @@ void update_vmeter(void*) { auto now = m5::utility::millis(); if (now >= start_at + 1000) { mps = fcnt; - M5_LOGW("Vmeter:%u (%u)", mps, mcnt); + M5_LOGD("Vmeter:%u (%u)", mps, mcnt); fcnt = mcnt = 0; start_at = now; } @@ -211,7 +210,7 @@ void update_tvoc(void*) { auto now = m5::utility::millis(); if (now >= start_at + 1000) { mps = fcnt; - M5_LOGW("TVOC:%u (%u)", mps, mcnt); + M5_LOGD("TVOC:%u (%u)", mps, mcnt); fcnt = mcnt = 0; start_at = now; } @@ -247,7 +246,7 @@ void update_sht30(void*) { auto now = m5::utility::millis(); if (now >= start_at + 1000) { mps = fcnt; - M5_LOGW("SHT30:%u (%u)", mps, mcnt); + M5_LOGD("SHT30:%u (%u)", mps, mcnt); fcnt = mcnt = 0; start_at = now; } @@ -283,7 +282,7 @@ void update_qmp6988(void*) { auto now = m5::utility::millis(); if (now >= start_at + 1000) { mps = fcnt; - M5_LOGW("QMP6988:%u (%u)", mps, mcnt); + M5_LOGD("QMP6988:%u (%u)", mps, mcnt); fcnt = mcnt = 0; start_at = now; } @@ -320,7 +319,7 @@ void update_heart(void*) { auto now = m5::utility::millis(); if (now >= start_at + 1000) { mps = fcnt; - M5_LOGW("Heart:%u (%u)", mps, mcnt); + M5_LOGD("Heart:%u (%u)", mps, mcnt); fcnt = mcnt = 0; start_at = now; } @@ -336,12 +335,9 @@ void drawUI(LovyanGFX& dst, const uint32_t x, const uint32_t yoffset) { } // namespace void setup() { - m5::utility::delay(1500); - M5.begin(); lcd.startWrite(); lcd.clear(TFT_DARKGRAY); - // strip_height = lcd.height() / SPLIT_NUM; uint32_t cnt{}; @@ -402,7 +398,7 @@ void loop() { auto now = m5::utility::millis(); if (now >= start_at + 1000) { fps = fpsCnt; - M5_LOGW("FPS:%u", fps); + M5_LOGD("FPS:%u", fps); fpsCnt = 0; start_at = now; } diff --git a/src/M5UnitComponent.hpp b/src/M5UnitComponent.hpp index e332914..aebffb2 100644 --- a/src/M5UnitComponent.hpp +++ b/src/M5UnitComponent.hpp @@ -52,13 +52,6 @@ class Component { uint8_t max_children{0}; }; - /*! - @struct config_t - @brief Base settings for begin - @note Derived classes are defined by deriving their own config_t from this - */ - struct config_t {}; - ///@warning Define the same name and type in the derived class. ///@name Fixed parameters for class ///@{ @@ -89,11 +82,11 @@ class Component { ///@name Component settings ///@{ - /*! @brief Gets the configuration */ + /*! @brief Gets the common configurations in each unit */ inline component_config_t component_config() { return _component_cfg; } - //! @brief Set the configuration + //! @brief Set the common configurations in each unit inline void component_config(const component_config_t& cfg) { _component_cfg = cfg; } @@ -366,7 +359,7 @@ class Component { /*! @class PeriodicMeasurementAdapter - @brief Interface class for periodic measurement + @brief Interface class for periodic measurement (CRTP) @details Common interface for accumulated periodic measurement data @details Provide a common interface for periodic measurements for each unit @tparam Derived Derived class @@ -393,7 +386,8 @@ class PeriodicMeasurementAdapter { @note Call Derived::start_periodic_measurement */ template - bool startPeriodicMeasurement(Args&&... args) { + inline bool startPeriodicMeasurement(Args&&... args) { + // Prepare for future common initiation preprocessing needs return static_cast(this)->start_periodic_measurement(std::forward(args)...); } /*! @@ -403,7 +397,8 @@ class PeriodicMeasurementAdapter { @note Call Derived::stop_periodic_measurement */ template - bool stopPeriodicMeasurement(Args&&... args) { + inline bool stopPeriodicMeasurement(Args&&... args) { + // Prepare for future common stopping preprocessing needs return static_cast(this)->stop_periodic_measurement(std::forward(args)...); } ///@} diff --git a/src/M5UnitUnified.cpp b/src/M5UnitUnified.cpp index d2f66ec..aa9faf5 100644 --- a/src/M5UnitUnified.cpp +++ b/src/M5UnitUnified.cpp @@ -83,7 +83,7 @@ bool UnitUnified::add_children(Component& u) { M5_LIB_LOGV("%s duplicate %u", u.deviceName(), ch); auto ad = u.duplicate_adapter(ch); if (!ad) { - M5_LIB_LOGE("Failed to ensure_adapter() %s:%u", u.deviceName(), ch); + M5_LIB_LOGE("Failed to duplicate_adapter() %s:%u", u.deviceName(), ch); return false; } if (!add(*it, ad)) { diff --git a/src/M5UnitUnified.hpp b/src/M5UnitUnified.hpp index ac19a9f..d88f62f 100644 --- a/src/M5UnitUnified.hpp +++ b/src/M5UnitUnified.hpp @@ -8,7 +8,10 @@ @brief Main header of M5UnitUnified @mainpage M5UnitUnified - Library for abstracted M5 units. C++11 or later + M5UnitUnified is a library for unified handling of various M5 unit products. + - Unified APIs + - Unified Connections + - Unified Licensing */ #ifndef M5_UNIT_UNIFIED_HPP #define M5_UNIT_UNIFIED_HPP @@ -40,18 +43,20 @@ class UnitUnified { public: using container_type = std::vector; + ///@warning COPY PROHIBITED ///@name Constructor ///@{ - UnitUnified() = default; - UnitUnified(const UnitUnified&) = delete; - UnitUnified(UnitUnified&&) = default; + UnitUnified() = default; + UnitUnified(const UnitUnified&) = delete; + UnitUnified(UnitUnified&&) noexcept = default; ///@} + ///@warning COPY PROHIBITED ///@name Assignment ///@{ UnitUnified& operator=(const UnitUnified&) = delete; - UnitUnified& operator=(UnitUnified&&) = default; + UnitUnified& operator=(UnitUnified&&) noexcept = default; ///@} ///@name Adding unit to be managed @@ -63,7 +68,9 @@ class UnitUnified { bool add(Component& u, TwoWire& wire); ///@} + //! @brief Begin of all units under management bool begin(); + //! @brief Update of all units under management void update(); //! @brief Output information for debug @@ -76,7 +83,7 @@ class UnitUnified { std::string make_unit_info(const Component* u, const uint8_t indent = 0) const; protected: - container_type _units; + container_type _units{}; private: static uint32_t _registerCount; diff --git a/src/googletest/test_helper.hpp b/src/googletest/test_helper.hpp index 7053bed..3a6a009 100644 --- a/src/googletest/test_helper.hpp +++ b/src/googletest/test_helper.hpp @@ -5,7 +5,7 @@ */ /*! @file test_helper.hpp - @brief Helper for testing m5::unit::Component-derived classes + @brief Helper for testing UnitComponent @note Depends on GoogleTest */ #ifndef M5_UNIT_COMPONENT_GOOGLETEST_HELPER_HPP diff --git a/src/googletest/test_template.hpp b/src/googletest/test_template.hpp index 6fa8b6a..4f52952 100644 --- a/src/googletest/test_template.hpp +++ b/src/googletest/test_template.hpp @@ -5,7 +5,7 @@ */ /*! @file test_template.hpp - @brief Template for testing m5::unit::Component-derived classes + @brief Helper for testing UnitComponent @note Depends on GoogleTest */ #ifndef M5_UNIT_COMPONENT_GOOGLETEST_TEMPLATE_HPP