diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 53ccd03f..f466af41 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -28,7 +28,7 @@ add_executable (nrf8001-broadcast-example nrf8001_broadcast.cxx) add_executable (nrf8001-helloworld-example nrf8001_helloworld.cxx) add_executable (lpd8806-example lpd8806-example.cxx) add_executable (mlx90614-example mlx90614-example.cxx) -add_executable (ecs1030-example ecs1030-example.cxx) +add_executable (ecs1030-example ecs1030.cxx) add_executable (mq2-example mq2-example.cxx) add_executable (mq3-example mq3-example.cxx) add_executable (mq5-example mq5-example.cxx) diff --git a/examples/ecs1030-example.cxx b/examples/ecs1030.cxx similarity index 100% rename from examples/ecs1030-example.cxx rename to examples/ecs1030.cxx diff --git a/src/ecs1030/ecs1030.h b/src/ecs1030/ecs1030.h index 5588db18..aa450a03 100644 --- a/src/ecs1030/ecs1030.h +++ b/src/ecs1030/ecs1030.h @@ -28,6 +28,8 @@ #include #include +namespace upm { + #define NUMBER_OF_SAMPLES 500 #define ADC_RESOLUTION 1024 #define SUPPLYVOLTAGE 5100 @@ -39,59 +41,64 @@ #define TRUE HIGH #define FALSE LOW -namespace upm { - class ECS1030 { - public: - static const uint8_t DELAY_MS = 20000 / NUMBER_OF_SAMPLES; /* 1/50Hz is 20ms period */ - static const uint8_t VOLT_M = 5.1 / 1023; - static const uint8_t R_LOAD = 2000.0 / CURRENT_RATIO; +/** + * @brief C++ API for ECS1030 (electricity sensor) + * + * @snippet ecs1030.cxx Interesting + */ - /** - * Instanciates a ECS1030 (current sensor) object - * - * @param pinNumber number of the data pin - */ - ECS1030 (uint8_t pinNumber); +class ECS1030 { + public: + static const uint8_t DELAY_MS = 20000 / NUMBER_OF_SAMPLES; /* 1/50Hz is 20ms period */ + static const uint8_t VOLT_M = 5.1 / 1023; + static const uint8_t R_LOAD = 2000.0 / CURRENT_RATIO; - /** - * ECS1030 object destructor, basicaly it close the GPIO. - */ - ~ECS1030 (); + /** + * Instanciates a ECS1030 (current sensor) object + * + * @param pinNumber number of the data pin + */ + ECS1030 (uint8_t pinNumber); - /** - * Return currency data for the sampled period - */ - double getCurrency_A (); + /** + * ECS1030 object destructor, basicaly it close the GPIO. + */ + ~ECS1030 (); - /** - * Return power data for the sampled period - */ - double getPower_A (); + /** + * Return currency data for the sampled period + */ + double getCurrency_A (); - /** - * Return currency data for the sampled period - */ - double getCurrency_B (); + /** + * Return power data for the sampled period + */ + double getPower_A (); - /** - * Return power data for the sampled period - */ - double getPower_B (); + /** + * Return currency data for the sampled period + */ + double getCurrency_B (); - /** - * Return name of the component - */ - std::string name() { - return m_name; - } - private: - std::string m_name; - mraa_aio_context m_dataPinCtx; + /** + * Return power data for the sampled period + */ + double getPower_B (); - double m_calibration; - int m_lastSample; - double m_lastFilter; - int m_sample; - double m_filteredSample; - }; + /** + * Return name of the component + */ + std::string name() { + return m_name; + } + private: + std::string m_name; + mraa_aio_context m_dataPinCtx; + + double m_calibration; + int m_lastSample; + double m_lastFilter; + int m_sample; + double m_filteredSample; +}; }