M5Unit-METER 0.0.3 git rev:c518ea3
Loading...
Searching...
No Matches
unit_EEPROM.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_EEPROM_HPP
11#define M5_UNIT_METER_UNIT_EEPROM_HPP
12
13#include "unit_ADS111x.hpp"
14#include <M5UnitComponent.hpp>
15#include <m5_utility/stl/extension.hpp>
16#include <array>
17
18namespace m5 {
19namespace unit {
24namespace meter {
25
31class UnitEEPROM : public Component {
32 M5_UNIT_COMPONENT_HPP_BUILDER(UnitEEPROM, 0x00);
33
34public:
35 explicit UnitEEPROM(const uint8_t addr = DEFAULT_ADDRESS) : Component(addr)
36 {
37 }
38 virtual ~UnitEEPROM()
39 {
40 }
41
42 inline int16_t hope(m5::unit::ads111x::Gain gain) const
43 {
44 return _calibration[m5::stl::to_underlying(gain)].hope;
45 }
46 inline int16_t actual(m5::unit::ads111x::Gain gain) const
47 {
48 return _calibration[m5::stl::to_underlying(gain)].actual;
49 }
50 inline float calibrationFactor(m5::unit::ads111x::Gain gain) const
51 {
52 return actual(gain) ? (float)hope(gain) / actual(gain) : 1.0f;
53 }
54
55 bool readCalibration();
56
57protected:
58 bool read_calibration(const m5::unit::ads111x::Gain gain, int16_t& hope, int16_t& actual);
59
60private:
61 struct Calibration {
62 int16_t hope{1};
63 int16_t actual{1};
64 };
65 std::array<Calibration, 8 /*Gain*/> _calibration{};
66};
67
68} // namespace meter
69} // namespace unit
70} // namespace m5
71#endif
Accessor unit to EEPROM that holds calibration data.
Definition unit_EEPROM.hpp:31
Top level namespace of M5stack.
namespace for Meter
Unit-related namespace.
Base class for ADS111x families.
Gain
Programmable gain amplifier.
Definition unit_ADS111x.hpp:47