M5Unit-METER 0.3.0 git rev:2c09d95
Loading...
Searching...
No Matches
unit_av_base.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
3 *
4 * SPDX-License-Identifier: MIT
5 */
10#ifndef M5_UNIT_METER_UNIT_AV_BASE_HPP
11#define M5_UNIT_METER_UNIT_AV_BASE_HPP
12
13#include "unit_ADS1115.hpp"
14#include "unit_EEPROM.hpp"
15
16namespace m5 {
17namespace unit {
18
23class UnitAVmeterBase : public UnitADS1115 {
24 M5_UNIT_COMPONENT_HPP_BUILDER(UnitAVmeterBase, 0x00);
25
26public:
30 explicit UnitAVmeterBase(const uint8_t addr = DEFAULT_ADDRESS, const uint8_t eepromAddr = 0x00);
31 virtual ~UnitAVmeterBase()
32 {
33 }
34
35 virtual bool begin() override;
36
39 inline float calibrationFactor() const
40 {
41 return _calibrationFactor;
42 }
43
47 virtual bool writeGain(const ads111x::Gain gain) override;
48
49protected:
50 std::shared_ptr<Adapter> ensure_adapter(const uint8_t ch);
51 void apply_calibration(const ads111x::Gain gain);
52 bool validChild() const
53 {
54 return _valid;
55 }
56
57protected:
59
60private:
61 float _calibrationFactor{1.0f};
62 bool _valid{}; // Did the constructor correctly add the child unit?
63};
64
65} // namespace unit
66} // namespace m5
67#endif
ads111x::Gain gain() const
Gets the programmable gain amplifier.
Definition unit_ADS111x.cpp:104
virtual bool writeGain(const ads111x::Gain gain) override
Write the gain and update calibration factor.
Definition unit_av_base.cpp:48
float calibrationFactor() const
Gets the calibration factor for the current gain setting.
Definition unit_av_base.hpp:39
UnitAVmeterBase(const uint8_t addr=DEFAULT_ADDRESS, const uint8_t eepromAddr=0x00)
Constructor.
Definition unit_av_base.cpp:25
Accessor unit to EEPROM that holds calibration data.
Top level namespace of M5stack.
Unit-related namespace.
ADS1115 Unit for M5UnitUnified.
Gain
Programmable gain amplifier.
Definition unit_ADS111x.hpp:47
Accessor unit to EEPROM that holds calibration information.