Skip to content

Commit 3a4ce01

Browse files
committed
Merge branch 'develop'
2 parents 2ae611f + 8c0b77e commit 3a4ce01

22 files changed

+173
-179
lines changed

examples/UnitUnified/UnitAmeter/PlotToSerial/main/PlotToSerial.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,17 @@ void setup()
8383
void loop()
8484
{
8585
M5.update();
86+
auto touch = M5.Touch.getDetail();
87+
8688
Units.update();
8789
if (unit.updated()) {
8890
while (unit.available()) {
89-
M5_LOGI("\n>Current:%f", unit.current());
91+
M5.Log.printf(">Current:%f\n", unit.current());
9092
unit.discard();
9193
}
9294
}
9395

94-
if (M5.BtnA.wasClicked()) {
96+
if (M5.BtnA.wasClicked() || touch.wasClicked()) {
9597
rate = static_cast<Sampling>((m5::stl::to_underlying(rate) + 1) & 0x07);
9698
if (!unit.writeSamplingRate(rate)) {
9799
M5_LOGE("Failed to writeSamplingRate");

examples/UnitUnified/UnitVmeter/PlotToSerial/main/PlotToSerial.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,17 @@ void setup()
8383
void loop()
8484
{
8585
M5.update();
86+
auto touch = M5.Touch.getDetail();
87+
8688
Units.update();
8789
if (unit.updated()) {
8890
while (unit.available()) {
89-
M5_LOGI("\n>Voltage:%f", unit.voltage());
91+
M5.Log.printf(">Voltage:%f\n", unit.voltage());
9092
unit.discard();
9193
}
9294
}
9395

94-
if (M5.BtnA.wasClicked()) {
96+
if (M5.BtnA.wasClicked() || touch.wasClicked()) {
9597
rate = static_cast<Sampling>((m5::stl::to_underlying(rate) + 1) & 0x07);
9698
if (!unit.writeSamplingRate(rate)) {
9799
M5_LOGE("Failed to writeSamplingRate");

library.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
"url": "https://github.com/m5stack/M5Unit-METER.git"
1212
},
1313
"dependencies": {
14-
"M5UnitUnified": "https://github.com/m5stack/M5UnitUnified.git@^0.0.5"
14+
"m5stack/M5UnitUnified": ">=0.1.0"
1515
},
16-
"version": "0.1.0",
16+
"version": "0.2.0",
1717
"frameworks": [
1818
"arduino"
1919
],

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=M5Unit-METER
2-
version=0.1.0
2+
version=0.2.0
33
author=M5Stack
44
maintainer=M5Stack
55
sentence=Library for M5Stack UNIT METER using M5UnitUnified

src/unit/unit_ADS1113.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace unit {
2020
// class UnitADS1113
2121
const char UnitADS1113::name[] = "UnitADS1113";
2222
const types::uid_t UnitADS1113::uid{"UnitADS1113"_mmh3};
23-
const types::uid_t UnitADS1113::attr{0};
23+
const types::attr_t UnitADS1113::attr{attribute::AccessI2C};
2424

2525
bool UnitADS1113::start_periodic_measurement(const ads111x::Sampling rate, const ads111x::Mux, const ads111x::Gain,
2626
const ads111x::ComparatorQueue)

src/unit/unit_ADS1113.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
namespace m5 {
1616
namespace unit {
1717
/*!
18-
@class UnitADS1113
18+
@class m5::unit::UnitADS1113
1919
@brief ADS1113 unit
2020
*/
2121
class UnitADS1113 : public UnitADS111x {

src/unit/unit_ADS1114.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace unit {
2020
// class UnitADS1114
2121
const char UnitADS1114::name[] = "UnitADS1114";
2222
const types::uid_t UnitADS1114::uid{"UnitADS1114"_mmh3};
23-
const types::uid_t UnitADS1114::attr{0};
23+
const types::attr_t UnitADS1114::attr{attribute::AccessI2C};
2424

2525
bool UnitADS1114::start_periodic_measurement(const ads111x::Sampling rate, const ads111x::Mux, const ads111x::Gain gain,
2626
const ads111x::ComparatorQueue comp_que)

src/unit/unit_ADS1114.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
namespace m5 {
1616
namespace unit {
1717
/*!
18-
@class UnitADS1114
18+
@class m5::unit::UnitADS1114
1919
@brief ADS1114 unit
2020
*/
2121
class UnitADS1114 : public UnitADS111x {

src/unit/unit_ADS1115.cpp

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -15,76 +15,19 @@ using namespace m5::unit::types;
1515
using namespace m5::unit::ads111x;
1616
using namespace m5::unit::ads111x::command;
1717

18-
namespace {
19-
constexpr Gain gain_table[] = {
20-
Gain::PGA_6144, Gain::PGA_4096, Gain::PGA_2048, Gain::PGA_1024, Gain::PGA_512, Gain::PGA_256,
21-
};
22-
}
23-
2418
namespace m5 {
2519
namespace unit {
2620
// class UnitADS1115
2721
const char UnitADS1115::name[] = "UnitADS1115";
2822
const types::uid_t UnitADS1115::uid{"UnitADS1115"_mmh3};
29-
const types::uid_t UnitADS1115::attr{0};
23+
const types::attr_t UnitADS1115::attr{attribute::AccessI2C};
24+
3025
bool UnitADS1115::start_periodic_measurement(const ads111x::Sampling rate, const ads111x::Mux mux,
3126
const ads111x::Gain gain, const ads111x::ComparatorQueue comp_que)
3227
{
3328
return writeSamplingRate(_cfg.rate) && writeMultiplexer(_cfg.mux) && writeGain(_cfg.gain) &&
3429
writeComparatorQueue(_cfg.comp_que) && UnitADS111x::start_periodic_measurement();
3530
}
3631

37-
// class UnitAVmeterBase
38-
const char UnitAVmeterBase::name[] = "UnitAVmeterBase";
39-
const types::uid_t UnitAVmeterBase::uid{"UnitAVmeterBase"_mmh3};
40-
const types::uid_t UnitAVmeterBase::attr{0};
41-
42-
UnitAVmeterBase::UnitAVmeterBase(const uint8_t addr, const uint8_t eepromAddr) : UnitADS1115(addr), _eeprom(eepromAddr)
43-
{
44-
// Form a parent-child relationship
45-
auto cfg = component_config();
46-
cfg.max_children = 1;
47-
component_config(cfg);
48-
_valid = add(_eeprom, 0) && m5::utility::isValidI2CAddress(_eeprom.address());
49-
}
50-
51-
bool UnitAVmeterBase::begin()
52-
{
53-
if (!validChild()) {
54-
M5_LIB_LOGE("Child unit is invalid %x", _eeprom.address());
55-
return false;
56-
}
57-
if (!_eeprom.readCalibration()) {
58-
return false;
59-
}
60-
apply_calibration(_ads_cfg.pga());
61-
62-
return UnitADS111x::begin();
63-
}
64-
65-
bool UnitAVmeterBase::writeGain(const ads111x::Gain gain)
66-
{
67-
if (UnitADS1115::writeGain(gain)) {
68-
apply_calibration(gain);
69-
return true;
70-
}
71-
return false;
72-
}
73-
74-
Adapter* UnitAVmeterBase::duplicate_adapter(const uint8_t ch)
75-
{
76-
if (ch != 0) {
77-
M5_LIB_LOGE("Invalid channel %u", ch);
78-
return nullptr;
79-
}
80-
auto myadapter = adapter();
81-
return myadapter ? myadapter->duplicate(_eeprom.address()) : nullptr;
82-
}
83-
84-
void UnitAVmeterBase::apply_calibration(const Gain gain)
85-
{
86-
_calibrationFactor = _eeprom.calibrationFactor(gain);
87-
}
88-
8932
} // namespace unit
9033
} // namespace m5

src/unit/unit_ADS1115.hpp

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
#define M5_UNIT_METER_UNIT_ADS1115_HPP
1212

1313
#include "unit_ADS111x.hpp"
14-
#include "unit_EEPROM.hpp"
1514

1615
namespace m5 {
1716
namespace unit {
1817
/*!
19-
@class UnitADS1115
18+
@class m5::unit::UnitADS1115
2019
@brief ADS1115 unit
2120
*/
2221
class UnitADS1115 : public UnitADS111x {
@@ -69,44 +68,6 @@ class UnitADS1115 : public UnitADS111x {
6968
const ads111x::Gain gain, const ads111x::ComparatorQueue comp_que) override;
7069
};
7170

72-
/*!
73-
@class UnitAVmeterBase
74-
@brief ADS1115 with EEPROM
75-
*/
76-
class UnitAVmeterBase : public UnitADS1115 {
77-
M5_UNIT_COMPONENT_HPP_BUILDER(UnitAVmeterBase, 0x00);
78-
79-
public:
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-
94-
protected:
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-
102-
protected:
103-
m5::unit::meter::UnitEEPROM _eeprom{};
104-
105-
private:
106-
float _calibrationFactor{1.0f};
107-
bool _valid{}; // Did the constructor correctly add the child unit?
108-
};
109-
11071
} // namespace unit
11172
} // namespace m5
11273
#endif

0 commit comments

Comments
 (0)