M5Unit-METER 0.0.3 git rev:c518ea3
Loading...
Searching...
No Matches
unit_Vmeter.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_V_METER_HPP
11#define M5_UNIT_METER_UNIT_V_METER_HPP
12
13#include "unit_ADS1115.hpp"
14#include <limits> // NaN
15
16namespace m5 {
17namespace unit {
23 M5_UNIT_COMPONENT_HPP_BUILDER(UnitVmeter, 0x49);
24
25public:
26 constexpr static uint8_t DEFAULT_EEPROM_ADDRESS{0x53};
27 constexpr static float PRESSURE_COEFFICIENT{0.01591895f};
28
29 explicit UnitVmeter(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 ~UnitVmeter()
35 {
36 }
37
39 inline float resolution() const
40 {
41 return coefficient() / PRESSURE_COEFFICIENT;
42 }
43
45 inline float correction() const
46 {
47 return _correction;
48 }
49
51 inline float voltage() const
52 {
53 return !empty() ? correction() * adc() : std::numeric_limits<float>::quiet_NaN();
54 }
55
56protected:
57 virtual void apply_coefficient(const ads111x::Gain gain) override;
58
59private:
60 float _correction{1.0f};
61};
62} // namespace unit
63} // namespace m5
64#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
Voltmeter Unit is a voltage meter that can monitor the voltage in real time.
Definition unit_Vmeter.hpp:22
float correction() const
Gets the correction value.
Definition unit_Vmeter.hpp:45
float resolution() const
Resolution of 1 LSB.
Definition unit_Vmeter.hpp:39
float voltage() const
Oldest voltage (mV)
Definition unit_Vmeter.hpp:51
Top level namespace of M5stack.
Unit-related namespace.
ADS1115 Unit for M5UnitUnified.
Gain
Programmable gain amplifier.
Definition unit_ADS111x.hpp:47