M5Unit-METER 0.0.3 git rev:c518ea3
Loading...
Searching...
No Matches
unit_ADS1115.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_ADS1115_HPP
11#define M5_UNIT_METER_UNIT_ADS1115_HPP
12
13#include "unit_ADS111x.hpp"
14#include "unit_EEPROM.hpp"
15
16namespace m5 {
17namespace unit {
22class UnitADS1115 : public UnitADS111x {
23 M5_UNIT_COMPONENT_HPP_BUILDER(UnitADS1115, 0x00);
24
25public:
26 explicit UnitADS1115(const uint8_t addr = DEFAULT_ADDRESS) : UnitADS111x(addr)
27 {
28 }
29 virtual ~UnitADS1115()
30 {
31 }
32
35
36 virtual bool writeMultiplexer(const ads111x::Mux mux) override
37 {
38 return write_multiplexer(mux);
39 }
41 virtual bool writeGain(const ads111x::Gain gain) override
42 {
43 return write_gain(gain);
44 }
46 virtual bool writeComparatorMode(const bool b) override
47 {
48 return write_comparator_mode(b);
49 }
51 virtual bool writeComparatorPolarity(const bool b) override
52 {
53 return write_comparator_polarity(b);
54 }
56 virtual bool writeLatchingComparator(const bool b) override
57 {
58 return write_latching_comparator(b);
59 }
61 virtual bool writeComparatorQueue(const ads111x::ComparatorQueue c) override
62 {
63 return write_comparator_queue(c);
64 }
66
67protected:
68 virtual bool start_periodic_measurement(const ads111x::Sampling rate, const ads111x::Mux mux,
69 const ads111x::Gain gain, const ads111x::ComparatorQueue comp_que) override;
70};
71
77 M5_UNIT_COMPONENT_HPP_BUILDER(UnitAVmeterBase, 0x00);
78
79public:
80 explicit UnitAVmeterBase(const uint8_t addr = DEFAULT_ADDRESS, const uint8_t eepromAddr = 0x00);
81 virtual ~UnitAVmeterBase()
82 {
83 }
84
85 virtual bool begin() override;
86
87 inline float calibrationFactor() const
88 {
89 return _calibrationFactor;
90 }
91
92 virtual bool writeGain(const ads111x::Gain gain) override;
93
94protected:
95 virtual Adapter* duplicate_adapter(const uint8_t ch) override;
96 void apply_calibration(const ads111x::Gain gain);
97 bool validChild() const
98 {
99 return _valid;
100 }
101
102protected:
104
105private:
106 float _calibrationFactor{1.0f};
107 bool _valid{}; // Did the constructor correctly add the child unit?
108};
109
110} // namespace unit
111} // namespace m5
112#endif
ADS1115 unit.
Definition unit_ADS1115.hpp:22
virtual bool writeMultiplexer(const ads111x::Mux mux) override
Write the input multiplexer.
Definition unit_ADS1115.hpp:36
virtual bool writeGain(const ads111x::Gain gain) override
Write the programmable gain amplifier.
Definition unit_ADS1115.hpp:41
virtual bool writeLatchingComparator(const bool b) override
Write the latching comparator.
Definition unit_ADS1115.hpp:56
virtual bool writeComparatorMode(const bool b) override
Write the comparator mode.
Definition unit_ADS1115.hpp:46
virtual bool writeComparatorQueue(const ads111x::ComparatorQueue c) override
Write the comparator queue.
Definition unit_ADS1115.hpp:61
virtual bool writeComparatorPolarity(const bool b) override
Write the comparator polarity.
Definition unit_ADS1115.hpp:51
Base class for ADS111x series.
Definition unit_ADS111x.hpp:219
ads111x::Gain gain() const
Gets the programmable gain amplifier.
Definition unit_ADS111x.cpp:104
ADS1115 with EEPROM.
Definition unit_ADS1115.hpp:76
virtual bool writeGain(const ads111x::Gain gain) override
Write the programmable gain amplifier.
Definition unit_ADS1115.cpp:65
Accessor unit to EEPROM that holds calibration data.
Definition unit_EEPROM.hpp:31
Top level namespace of M5stack.
Unit-related namespace.
Base class for ADS111x families.
Sampling
Data rate setting (samples per second)
Definition unit_ADS111x.hpp:61
Mux
Input multiplexer.
Definition unit_ADS111x.hpp:31
ComparatorQueue
the value determines the number of successive conversions exceeding the upper orlower threshold requi...
Definition unit_ADS111x.hpp:77
Gain
Programmable gain amplifier.
Definition unit_ADS111x.hpp:47
Accessor unit to EEPROM that holds calibration information.