M5Unit-METER 0.2.0 git rev:3a4ce01
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_AMETER_HPP
11#define M5_UNIT_METER_UNIT_AMETER_HPP
12
13#include "unit_av_base.hpp"
14#include <limits> // NaN
15
16namespace m5 {
17namespace unit {
22class UnitAmeter : public UnitAVmeterBase {
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:237
int16_t adc() const
Oldest measured ADC.
Definition unit_ADS111x.hpp:246
ads111x::Gain gain() const
Gets the programmable gain amplifier.
Definition unit_ADS111x.cpp:104
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.
Gain
Programmable gain amplifier.
Definition unit_ADS111x.hpp:47
A/Vmeter base class for M5UnitUnified.