M5Unit-METER 0.0.3 git rev:c518ea3
Loading...
Searching...
No Matches
unit_Ameter.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
3 *
4 * SPDX-License-Identifier: MIT
5 */
10#ifndef M5_UNIT_METER_UNIT_A_METER_HPP
11#define M5_UNIT_METER_UNIT_A_METER_HPP
12
13#include "unit_ADS1115.hpp"
14#include <limits> // NaN
15
16namespace m5 {
17namespace unit {
23 M5_UNIT_COMPONENT_HPP_BUILDER(UnitAmeter, 0x48);
24
25public:
26 constexpr static uint8_t DEFAULT_EEPROM_ADDRESS{0x51};
27 constexpr static float PRESSURE_COEFFICIENT{0.05f};
28
29 explicit UnitAmeter(const uint8_t addr = DEFAULT_ADDRESS, const uint8_t eepromAddr = DEFAULT_EEPROM_ADDRESS)
30 : UnitAVmeterBase(addr, eepromAddr)
31 {
32 // component_config().clock is set at ADS111x constructor
33 }
34 virtual ~UnitAmeter()
35 {
36 }
37
39 inline float resolution() const
40 {
41 return coefficient() / PRESSURE_COEFFICIENT;
42 }
44 inline float correction() const
45 {
46 return _correction;
47 }
48
50 inline float current() const
51 {
52 return !empty() ? correction() * adc() : std::numeric_limits<float>::quiet_NaN();
53 }
54
55protected:
56 virtual void apply_coefficient(const ads111x::Gain gain) override;
57
58private:
59 float _correction{1.0f};
60};
61} // namespace unit
62} // namespace m5
63#endif
float coefficient() const
Coefficient value.
Definition unit_ADS111x.hpp:274
int16_t adc() const
Oldest measured ADC.
Definition unit_ADS111x.hpp:283
ads111x::Gain gain() const
Gets the programmable gain amplifier.
Definition unit_ADS111x.cpp:104
ADS1115 with EEPROM.
Definition unit_ADS1115.hpp:76
Ameter Unit is a current meter that can monitor the current in real time.
Definition unit_Ameter.hpp:22
float current() const
Oldest current (mA)
Definition unit_Ameter.hpp:50
float resolution() const
Resolution of 1 LSB.
Definition unit_Ameter.hpp:39
float correction() const
Gets the correction value.
Definition unit_Ameter.hpp:44
Top level namespace of M5stack.
Unit-related namespace.
ADS1115 Unit for M5UnitUnified.
Gain
Programmable gain amplifier.
Definition unit_ADS111x.hpp:47