mirror of
https://github.com/m5stack/M5Unit-METER.git
synced 2026-05-20 11:27:46 -07:00
Change .clang-format to the latest M5 one
This commit is contained in:
+3
-3
@@ -1,7 +1,7 @@
|
||||
---
|
||||
Language: Cpp
|
||||
BasedOnStyle: Google
|
||||
AccessModifierOffset: -1
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveMacros: true
|
||||
AlignConsecutiveAssignments: true
|
||||
@@ -29,7 +29,7 @@ BraceWrapping:
|
||||
AfterClass: false
|
||||
AfterControlStatement: false
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterFunction: true
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
@@ -42,7 +42,7 @@ BraceWrapping:
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeBraces: Custom
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakInheritanceList: BeforeColon
|
||||
BreakBeforeTernaryOperators: true
|
||||
|
||||
@@ -28,7 +28,8 @@ Sampling rate{Sampling::Rate32};
|
||||
|
||||
} // namespace
|
||||
|
||||
void setup() {
|
||||
void setup()
|
||||
{
|
||||
M5.begin();
|
||||
|
||||
// Settings
|
||||
@@ -79,7 +80,8 @@ void setup() {
|
||||
lcd.clear(TFT_DARKGREEN);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
void loop()
|
||||
{
|
||||
M5.update();
|
||||
Units.update();
|
||||
if (unit.updated()) {
|
||||
|
||||
@@ -28,7 +28,8 @@ Sampling rate{Sampling::Rate32};
|
||||
|
||||
} // namespace
|
||||
|
||||
void setup() {
|
||||
void setup()
|
||||
{
|
||||
M5.begin();
|
||||
|
||||
// Settings
|
||||
@@ -79,7 +80,8 @@ void setup() {
|
||||
lcd.clear(TFT_DARKGREEN);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
void loop()
|
||||
{
|
||||
M5.update();
|
||||
Units.update();
|
||||
if (unit.updated()) {
|
||||
|
||||
@@ -23,7 +23,8 @@ const types::uid_t UnitADS1113::uid{"UnitADS1113"_mmh3};
|
||||
const types::uid_t UnitADS1113::attr{0};
|
||||
|
||||
bool UnitADS1113::start_periodic_measurement(const ads111x::Sampling rate, const ads111x::Mux, const ads111x::Gain,
|
||||
const ads111x::ComparatorQueue) {
|
||||
const ads111x::ComparatorQueue)
|
||||
{
|
||||
M5_LIB_LOGW("mux, gain, and comp_que not support");
|
||||
return writeSamplingRate(rate) && UnitADS111x::start_periodic_measurement();
|
||||
}
|
||||
|
||||
+18
-10
@@ -21,41 +21,49 @@ namespace unit {
|
||||
class UnitADS1113 : public UnitADS111x {
|
||||
M5_UNIT_COMPONENT_HPP_BUILDER(UnitADS1113, 0x00);
|
||||
|
||||
public:
|
||||
explicit UnitADS1113(const uint8_t addr = DEFAULT_ADDRESS) : UnitADS111x(addr) {
|
||||
public:
|
||||
explicit UnitADS1113(const uint8_t addr = DEFAULT_ADDRESS) : UnitADS111x(addr)
|
||||
{
|
||||
}
|
||||
virtual ~UnitADS1113() {
|
||||
virtual ~UnitADS1113()
|
||||
{
|
||||
}
|
||||
|
||||
///@name Configration
|
||||
///@{
|
||||
/*! @brief Not support @warning Not support */
|
||||
virtual bool writeMultiplexer(const ads111x::Mux) override {
|
||||
virtual bool writeMultiplexer(const ads111x::Mux) override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//! @brief Not support @warning Not support
|
||||
virtual bool writeGain(const ads111x::Gain) override {
|
||||
virtual bool writeGain(const ads111x::Gain) override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//! @brief Not support @warning Not support
|
||||
virtual bool writeComparatorMode(const bool) override {
|
||||
virtual bool writeComparatorMode(const bool) override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//! @brief Not support @warning Not support
|
||||
virtual bool writeComparatorPolarity(const bool) override {
|
||||
virtual bool writeComparatorPolarity(const bool) override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//! @brief Not support @warning Not support
|
||||
virtual bool writeLatchingComparator(const bool) override {
|
||||
virtual bool writeLatchingComparator(const bool) override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//! @brief Not support @warning Not support
|
||||
virtual bool writeComparatorQueue(const ads111x::ComparatorQueue) override {
|
||||
virtual bool writeComparatorQueue(const ads111x::ComparatorQueue) override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
///@}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
virtual bool start_periodic_measurement(const ads111x::Sampling rate, const ads111x::Mux mux,
|
||||
const ads111x::Gain gain, const ads111x::ComparatorQueue comp_que) override;
|
||||
};
|
||||
|
||||
@@ -23,7 +23,8 @@ const types::uid_t UnitADS1114::uid{"UnitADS1114"_mmh3};
|
||||
const types::uid_t UnitADS1114::attr{0};
|
||||
|
||||
bool UnitADS1114::start_periodic_measurement(const ads111x::Sampling rate, const ads111x::Mux, const ads111x::Gain gain,
|
||||
const ads111x::ComparatorQueue comp_que) {
|
||||
const ads111x::ComparatorQueue comp_que)
|
||||
{
|
||||
M5_LIB_LOGW("mux is not support");
|
||||
return writeSamplingRate(_cfg.rate) && writeGain(_cfg.gain) && writeComparatorQueue(_cfg.comp_que) &&
|
||||
UnitADS111x::start_periodic_measurement();
|
||||
|
||||
+18
-10
@@ -21,41 +21,49 @@ namespace unit {
|
||||
class UnitADS1114 : public UnitADS111x {
|
||||
M5_UNIT_COMPONENT_HPP_BUILDER(UnitADS1114, 0x00);
|
||||
|
||||
public:
|
||||
explicit UnitADS1114(const uint8_t addr = DEFAULT_ADDRESS) : UnitADS111x(addr) {
|
||||
public:
|
||||
explicit UnitADS1114(const uint8_t addr = DEFAULT_ADDRESS) : UnitADS111x(addr)
|
||||
{
|
||||
}
|
||||
virtual ~UnitADS1114() {
|
||||
virtual ~UnitADS1114()
|
||||
{
|
||||
}
|
||||
|
||||
///@name Configration
|
||||
///@{
|
||||
/*! @brief Not support @warning Not support */
|
||||
virtual bool writeMultiplexer(const ads111x::Mux) override {
|
||||
virtual bool writeMultiplexer(const ads111x::Mux) override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//! @brief Write the programmable gain amplifier
|
||||
virtual bool writeGain(const ads111x::Gain gain) override {
|
||||
virtual bool writeGain(const ads111x::Gain gain) override
|
||||
{
|
||||
return write_gain(gain);
|
||||
}
|
||||
//! @brief Write the comparator mode
|
||||
virtual bool writeComparatorMode(const bool b) override {
|
||||
virtual bool writeComparatorMode(const bool b) override
|
||||
{
|
||||
return write_comparator_mode(b);
|
||||
}
|
||||
//! @brief Write the comparator polarity
|
||||
virtual bool writeComparatorPolarity(const bool b) override {
|
||||
virtual bool writeComparatorPolarity(const bool b) override
|
||||
{
|
||||
return write_comparator_polarity(b);
|
||||
}
|
||||
//! @brief Write the latching comparator
|
||||
virtual bool writeLatchingComparator(const bool b) override {
|
||||
virtual bool writeLatchingComparator(const bool b) override
|
||||
{
|
||||
return write_latching_comparator(b);
|
||||
}
|
||||
//! @brief Write the comparator queue
|
||||
virtual bool writeComparatorQueue(const ads111x::ComparatorQueue c) override {
|
||||
virtual bool writeComparatorQueue(const ads111x::ComparatorQueue c) override
|
||||
{
|
||||
return write_comparator_queue(c);
|
||||
}
|
||||
///@}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
virtual bool start_periodic_measurement(const ads111x::Sampling rate, const ads111x::Mux mux,
|
||||
const ads111x::Gain gain, const ads111x::ComparatorQueue comp_que) override;
|
||||
};
|
||||
|
||||
@@ -28,7 +28,8 @@ const char UnitADS1115::name[] = "UnitADS1115";
|
||||
const types::uid_t UnitADS1115::uid{"UnitADS1115"_mmh3};
|
||||
const types::uid_t UnitADS1115::attr{0};
|
||||
bool UnitADS1115::start_periodic_measurement(const ads111x::Sampling rate, const ads111x::Mux mux,
|
||||
const ads111x::Gain gain, const ads111x::ComparatorQueue comp_que) {
|
||||
const ads111x::Gain gain, const ads111x::ComparatorQueue comp_que)
|
||||
{
|
||||
return writeSamplingRate(_cfg.rate) && writeMultiplexer(_cfg.mux) && writeGain(_cfg.gain) &&
|
||||
writeComparatorQueue(_cfg.comp_que) && UnitADS111x::start_periodic_measurement();
|
||||
}
|
||||
@@ -38,8 +39,8 @@ const char UnitAVmeterBase::name[] = "UnitAVmeterBase";
|
||||
const types::uid_t UnitAVmeterBase::uid{"UnitAVmeterBase"_mmh3};
|
||||
const types::uid_t UnitAVmeterBase::attr{0};
|
||||
|
||||
UnitAVmeterBase::UnitAVmeterBase(const uint8_t addr, const uint8_t eepromAddr)
|
||||
: UnitADS1115(addr), _eeprom(eepromAddr) {
|
||||
UnitAVmeterBase::UnitAVmeterBase(const uint8_t addr, const uint8_t eepromAddr) : UnitADS1115(addr), _eeprom(eepromAddr)
|
||||
{
|
||||
// Form a parent-child relationship
|
||||
auto cfg = component_config();
|
||||
cfg.max_children = 1;
|
||||
@@ -47,7 +48,8 @@ UnitAVmeterBase::UnitAVmeterBase(const uint8_t addr, const uint8_t eepromAddr)
|
||||
_valid = add(_eeprom, 0) && m5::utility::isValidI2CAddress(_eeprom.address());
|
||||
}
|
||||
|
||||
bool UnitAVmeterBase::begin() {
|
||||
bool UnitAVmeterBase::begin()
|
||||
{
|
||||
if (!validChild()) {
|
||||
M5_LIB_LOGE("Child unit is invalid %x", _eeprom.address());
|
||||
return false;
|
||||
@@ -60,7 +62,8 @@ bool UnitAVmeterBase::begin() {
|
||||
return UnitADS111x::begin();
|
||||
}
|
||||
|
||||
bool UnitAVmeterBase::writeGain(const ads111x::Gain gain) {
|
||||
bool UnitAVmeterBase::writeGain(const ads111x::Gain gain)
|
||||
{
|
||||
if (UnitADS1115::writeGain(gain)) {
|
||||
apply_calibration(gain);
|
||||
return true;
|
||||
@@ -68,7 +71,8 @@ bool UnitAVmeterBase::writeGain(const ads111x::Gain gain) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Adapter* UnitAVmeterBase::duplicate_adapter(const uint8_t ch) {
|
||||
Adapter* UnitAVmeterBase::duplicate_adapter(const uint8_t ch)
|
||||
{
|
||||
if (ch != 0) {
|
||||
M5_LIB_LOGE("Invalid channel %u", ch);
|
||||
return nullptr;
|
||||
@@ -77,7 +81,8 @@ Adapter* UnitAVmeterBase::duplicate_adapter(const uint8_t ch) {
|
||||
return myadapter ? myadapter->duplicate(_eeprom.address()) : nullptr;
|
||||
}
|
||||
|
||||
void UnitAVmeterBase::apply_calibration(const Gain gain) {
|
||||
void UnitAVmeterBase::apply_calibration(const Gain gain)
|
||||
{
|
||||
_calibrationFactor = _eeprom.calibrationFactor(gain);
|
||||
}
|
||||
|
||||
|
||||
+28
-17
@@ -22,41 +22,49 @@ namespace unit {
|
||||
class UnitADS1115 : public UnitADS111x {
|
||||
M5_UNIT_COMPONENT_HPP_BUILDER(UnitADS1115, 0x00);
|
||||
|
||||
public:
|
||||
explicit UnitADS1115(const uint8_t addr = DEFAULT_ADDRESS) : UnitADS111x(addr) {
|
||||
public:
|
||||
explicit UnitADS1115(const uint8_t addr = DEFAULT_ADDRESS) : UnitADS111x(addr)
|
||||
{
|
||||
}
|
||||
virtual ~UnitADS1115() {
|
||||
virtual ~UnitADS1115()
|
||||
{
|
||||
}
|
||||
|
||||
///@name Configration
|
||||
///@{
|
||||
/*! @brief Write the input multiplexer */
|
||||
virtual bool writeMultiplexer(const ads111x::Mux mux) override {
|
||||
virtual bool writeMultiplexer(const ads111x::Mux mux) override
|
||||
{
|
||||
return write_multiplexer(mux);
|
||||
}
|
||||
//! @brief Write the programmable gain amplifier
|
||||
virtual bool writeGain(const ads111x::Gain gain) override {
|
||||
virtual bool writeGain(const ads111x::Gain gain) override
|
||||
{
|
||||
return write_gain(gain);
|
||||
}
|
||||
//! @brief Write the comparator mode
|
||||
virtual bool writeComparatorMode(const bool b) override {
|
||||
virtual bool writeComparatorMode(const bool b) override
|
||||
{
|
||||
return write_comparator_mode(b);
|
||||
}
|
||||
//! @brief Write the comparator polarity
|
||||
virtual bool writeComparatorPolarity(const bool b) override {
|
||||
virtual bool writeComparatorPolarity(const bool b) override
|
||||
{
|
||||
return write_comparator_polarity(b);
|
||||
}
|
||||
//! @brief Write the latching comparator
|
||||
virtual bool writeLatchingComparator(const bool b) override {
|
||||
virtual bool writeLatchingComparator(const bool b) override
|
||||
{
|
||||
return write_latching_comparator(b);
|
||||
}
|
||||
//! @brief Write the comparator queue
|
||||
virtual bool writeComparatorQueue(const ads111x::ComparatorQueue c) override {
|
||||
virtual bool writeComparatorQueue(const ads111x::ComparatorQueue c) override
|
||||
{
|
||||
return write_comparator_queue(c);
|
||||
}
|
||||
///@}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
virtual bool start_periodic_measurement(const ads111x::Sampling rate, const ads111x::Mux mux,
|
||||
const ads111x::Gain gain, const ads111x::ComparatorQueue comp_que) override;
|
||||
};
|
||||
@@ -68,30 +76,33 @@ class UnitADS1115 : public UnitADS111x {
|
||||
class UnitAVmeterBase : public UnitADS1115 {
|
||||
M5_UNIT_COMPONENT_HPP_BUILDER(UnitAVmeterBase, 0x00);
|
||||
|
||||
public:
|
||||
public:
|
||||
explicit UnitAVmeterBase(const uint8_t addr = DEFAULT_ADDRESS, const uint8_t eepromAddr = 0x00);
|
||||
virtual ~UnitAVmeterBase() {
|
||||
virtual ~UnitAVmeterBase()
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool begin() override;
|
||||
|
||||
inline float calibrationFactor() const {
|
||||
inline float calibrationFactor() const
|
||||
{
|
||||
return _calibrationFactor;
|
||||
}
|
||||
|
||||
virtual bool writeGain(const ads111x::Gain gain) override;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
virtual Adapter* duplicate_adapter(const uint8_t ch) override;
|
||||
void apply_calibration(const ads111x::Gain gain);
|
||||
bool validChild() const {
|
||||
bool validChild() const
|
||||
{
|
||||
return _valid;
|
||||
}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
m5::unit::meter::UnitEEPROM _eeprom{};
|
||||
|
||||
private:
|
||||
private:
|
||||
float _calibrationFactor{1.0f};
|
||||
bool _valid{}; // Did the constructor correctly add the child unit?
|
||||
};
|
||||
|
||||
+46
-23
@@ -53,7 +53,8 @@ const char UnitADS111x::name[] = "UnitADS111x";
|
||||
const types::uid_t UnitADS111x::uid{"UnitADS111x"_mmh3};
|
||||
const types::uid_t UnitADS111x::attr{0};
|
||||
|
||||
bool UnitADS111x::begin() {
|
||||
bool UnitADS111x::begin()
|
||||
{
|
||||
auto ssize = stored_size();
|
||||
assert(ssize && "stored_size must be greater than zero");
|
||||
if (ssize != _data->capacity()) {
|
||||
@@ -81,7 +82,8 @@ bool UnitADS111x::begin() {
|
||||
: stopPeriodicMeasurement();
|
||||
}
|
||||
|
||||
void UnitADS111x::update(const bool force) {
|
||||
void UnitADS111x::update(const bool force)
|
||||
{
|
||||
_updated = false;
|
||||
if (inPeriodic()) {
|
||||
elapsed_time_t at{m5::utility::millis()};
|
||||
@@ -99,11 +101,13 @@ void UnitADS111x::update(const bool force) {
|
||||
}
|
||||
}
|
||||
|
||||
Gain UnitADS111x::gain() const {
|
||||
Gain UnitADS111x::gain() const
|
||||
{
|
||||
return gain_table[m5::stl::to_underlying(_ads_cfg.pga())];
|
||||
}
|
||||
|
||||
bool UnitADS111x::writeSamplingRate(ads111x::Sampling rate) {
|
||||
bool UnitADS111x::writeSamplingRate(ads111x::Sampling rate)
|
||||
{
|
||||
Config c{};
|
||||
if (read_config(c)) {
|
||||
c.dr(rate);
|
||||
@@ -115,7 +119,8 @@ bool UnitADS111x::writeSamplingRate(ads111x::Sampling rate) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UnitADS111x::start_periodic_measurement() {
|
||||
bool UnitADS111x::start_periodic_measurement()
|
||||
{
|
||||
if (inPeriodic()) {
|
||||
return false;
|
||||
}
|
||||
@@ -131,7 +136,8 @@ bool UnitADS111x::start_periodic_measurement() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UnitADS111x::stop_periodic_measurement() {
|
||||
bool UnitADS111x::stop_periodic_measurement()
|
||||
{
|
||||
Config c{};
|
||||
if (read_config(c)) {
|
||||
c.mode(true);
|
||||
@@ -143,7 +149,8 @@ bool UnitADS111x::stop_periodic_measurement() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UnitADS111x::measureSingleshot(ads111x::Data& d, const uint32_t timeoutMillis) {
|
||||
bool UnitADS111x::measureSingleshot(ads111x::Data& d, const uint32_t timeoutMillis)
|
||||
{
|
||||
if (inPeriodic()) {
|
||||
M5_LIB_LOGW("Periodic measurements are running");
|
||||
return false;
|
||||
@@ -162,7 +169,8 @@ bool UnitADS111x::measureSingleshot(ads111x::Data& d, const uint32_t timeoutMill
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UnitADS111x::start_single_measurement() {
|
||||
bool UnitADS111x::start_single_measurement()
|
||||
{
|
||||
if (inPeriodic()) {
|
||||
M5_LIB_LOGW("Periodic measurements are running");
|
||||
return false;
|
||||
@@ -179,19 +187,22 @@ bool UnitADS111x::start_single_measurement() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UnitADS111x::in_conversion() {
|
||||
bool UnitADS111x::in_conversion()
|
||||
{
|
||||
Config c{};
|
||||
return read_config(c) && !c.os();
|
||||
}
|
||||
|
||||
bool UnitADS111x::read_adc_raw(ads111x::Data& d) {
|
||||
bool UnitADS111x::read_adc_raw(ads111x::Data& d)
|
||||
{
|
||||
if (readRegister16(CONVERSION_REG, d.raw, 0)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UnitADS111x::generalReset() {
|
||||
bool UnitADS111x::generalReset()
|
||||
{
|
||||
uint8_t cmd{0x06}; // reset command
|
||||
generalCall(&cmd, 1);
|
||||
|
||||
@@ -214,7 +225,8 @@ bool UnitADS111x::generalReset() {
|
||||
return done;
|
||||
}
|
||||
|
||||
bool UnitADS111x::readThreshold(int16_t& high, int16_t& low) {
|
||||
bool UnitADS111x::readThreshold(int16_t& high, int16_t& low)
|
||||
{
|
||||
uint16_t hh{}, ll{};
|
||||
if (readRegister16(HIGH_THRESHOLD_REG, hh, 0) && readRegister16(LOW_THRESHOLD_REG, ll, 0)) {
|
||||
high = hh;
|
||||
@@ -224,7 +236,8 @@ bool UnitADS111x::readThreshold(int16_t& high, int16_t& low) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UnitADS111x::writeThreshold(const int16_t high, const int16_t low) {
|
||||
bool UnitADS111x::writeThreshold(const int16_t high, const int16_t low)
|
||||
{
|
||||
if (high <= low) {
|
||||
M5_LIB_LOGW("high must be greater than low");
|
||||
return false;
|
||||
@@ -233,11 +246,13 @@ bool UnitADS111x::writeThreshold(const int16_t high, const int16_t low) {
|
||||
}
|
||||
|
||||
//
|
||||
bool UnitADS111x::read_config(ads111x::Config& c) {
|
||||
bool UnitADS111x::read_config(ads111x::Config& c)
|
||||
{
|
||||
return readRegister16(CONFIG_REG, c.value, 0);
|
||||
}
|
||||
|
||||
bool UnitADS111x::write_config(const ads111x::Config& c) {
|
||||
bool UnitADS111x::write_config(const ads111x::Config& c)
|
||||
{
|
||||
if (writeRegister16(CONFIG_REG, c.value)) {
|
||||
_ads_cfg = c;
|
||||
return true;
|
||||
@@ -245,20 +260,23 @@ bool UnitADS111x::write_config(const ads111x::Config& c) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void UnitADS111x::apply_interval(const ads111x::Sampling rate) {
|
||||
void UnitADS111x::apply_interval(const ads111x::Sampling rate)
|
||||
{
|
||||
auto idx = m5::stl::to_underlying(rate);
|
||||
assert(idx < m5::stl::size(interval_table) && "Illegal value");
|
||||
_interval = interval_table[idx];
|
||||
M5_LIB_LOGV("interval %u", _interval);
|
||||
}
|
||||
|
||||
void UnitADS111x::apply_coefficient(const ads111x::Gain gain) {
|
||||
void UnitADS111x::apply_coefficient(const ads111x::Gain gain)
|
||||
{
|
||||
auto idx = m5::stl::to_underlying(gain);
|
||||
assert(idx < m5::stl::size(coefficient_table) && "Illegal value");
|
||||
_coefficient = coefficient_table[idx];
|
||||
}
|
||||
|
||||
bool UnitADS111x::write_multiplexer(const ads111x::Mux mux) {
|
||||
bool UnitADS111x::write_multiplexer(const ads111x::Mux mux)
|
||||
{
|
||||
Config c{};
|
||||
if (read_config(c)) {
|
||||
c.mux(mux);
|
||||
@@ -267,7 +285,8 @@ bool UnitADS111x::write_multiplexer(const ads111x::Mux mux) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UnitADS111x::write_gain(const ads111x::Gain gain) {
|
||||
bool UnitADS111x::write_gain(const ads111x::Gain gain)
|
||||
{
|
||||
Config c{};
|
||||
if (read_config(c)) {
|
||||
c.pga(gain);
|
||||
@@ -279,7 +298,8 @@ bool UnitADS111x::write_gain(const ads111x::Gain gain) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UnitADS111x::write_comparator_mode(const bool b) {
|
||||
bool UnitADS111x::write_comparator_mode(const bool b)
|
||||
{
|
||||
Config c{};
|
||||
if (read_config(c)) {
|
||||
c.comp_mode(b);
|
||||
@@ -288,7 +308,8 @@ bool UnitADS111x::write_comparator_mode(const bool b) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UnitADS111x::write_comparator_polarity(const bool b) {
|
||||
bool UnitADS111x::write_comparator_polarity(const bool b)
|
||||
{
|
||||
Config c{};
|
||||
if (read_config(c)) {
|
||||
c.comp_pol(b);
|
||||
@@ -297,7 +318,8 @@ bool UnitADS111x::write_comparator_polarity(const bool b) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UnitADS111x::write_latching_comparator(const bool b) {
|
||||
bool UnitADS111x::write_latching_comparator(const bool b)
|
||||
{
|
||||
Config c{};
|
||||
if (read_config(c)) {
|
||||
c.comp_lat(b);
|
||||
@@ -306,7 +328,8 @@ bool UnitADS111x::write_latching_comparator(const bool b) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UnitADS111x::write_comparator_queue(const ads111x::ComparatorQueue q) {
|
||||
bool UnitADS111x::write_comparator_queue(const ads111x::ComparatorQueue q)
|
||||
{
|
||||
Config c{};
|
||||
if (read_config(c)) {
|
||||
c.comp_que(q);
|
||||
|
||||
+71
-37
@@ -90,88 +90,106 @@ struct Config {
|
||||
///@name Getter
|
||||
///@{
|
||||
/*! @brief Operational status */
|
||||
inline bool os() const {
|
||||
inline bool os() const
|
||||
{
|
||||
return value & (1U << 15);
|
||||
}
|
||||
/*!
|
||||
@brief Input multiplexer
|
||||
@warning This feature serve nofunction on the ADS1113 and ADS1114
|
||||
*/
|
||||
inline Mux mux() const {
|
||||
inline Mux mux() const
|
||||
{
|
||||
return static_cast<Mux>((value >> 12) & 0x07);
|
||||
}
|
||||
/*!
|
||||
@brief Programmable gain amplifier
|
||||
@warning This feature serve nofunction on the ADS1113
|
||||
*/
|
||||
inline Gain pga() const {
|
||||
inline Gain pga() const
|
||||
{
|
||||
return static_cast<Gain>((value >> 9) & 0x07);
|
||||
}
|
||||
//! @brief Device operating mode
|
||||
inline bool mode() const {
|
||||
inline bool mode() const
|
||||
{
|
||||
return value & (1U << 8);
|
||||
}
|
||||
//! @brief Sampling rate
|
||||
inline Sampling dr() const {
|
||||
inline Sampling dr() const
|
||||
{
|
||||
return static_cast<Sampling>((value >> 5) & 0x07);
|
||||
}
|
||||
/*!
|
||||
@brief Comparator mode
|
||||
@warning This feature serve nofunction on the ADS1113
|
||||
*/
|
||||
inline bool comp_mode() const {
|
||||
inline bool comp_mode() const
|
||||
{
|
||||
return value & (1U << 4);
|
||||
}
|
||||
/*!
|
||||
@brief Comparator polarity
|
||||
@warning This feature serve nofunction on the ADS1113
|
||||
*/
|
||||
inline bool comp_pol() const {
|
||||
inline bool comp_pol() const
|
||||
{
|
||||
return value & (1U << 3);
|
||||
}
|
||||
/*!
|
||||
@brief Latching comparator
|
||||
@warning This feature serve nofunction on the ADS1113
|
||||
*/
|
||||
inline bool comp_lat() const {
|
||||
inline bool comp_lat() const
|
||||
{
|
||||
return value & (1U << 2);
|
||||
}
|
||||
/*!
|
||||
@brief Comparator queue
|
||||
@warning This feature serve nofunction on the ADS1113
|
||||
*/
|
||||
inline ComparatorQueue comp_que() const {
|
||||
inline ComparatorQueue comp_que() const
|
||||
{
|
||||
return static_cast<ComparatorQueue>(value & 0x03);
|
||||
}
|
||||
///@}
|
||||
|
||||
///@name Setter
|
||||
///@{
|
||||
inline void os(const bool b) {
|
||||
inline void os(const bool b)
|
||||
{
|
||||
value = (value & ~(1U << 15)) | ((b ? 1U : 0) << 15);
|
||||
}
|
||||
inline void mux(const Mux m) {
|
||||
inline void mux(const Mux m)
|
||||
{
|
||||
value = (value & ~(0x07 << 12)) | ((m5::stl::to_underlying(m) & 0x07) << 12);
|
||||
}
|
||||
inline void pga(const Gain g) {
|
||||
inline void pga(const Gain g)
|
||||
{
|
||||
value = (value & ~(0x07 << 9)) | ((m5::stl::to_underlying(g) & 0x07) << 9);
|
||||
}
|
||||
inline void mode(const bool b) {
|
||||
inline void mode(const bool b)
|
||||
{
|
||||
value = (value & ~(1U << 8)) | ((b ? 1U : 0) << 8);
|
||||
}
|
||||
inline void dr(const Sampling r) {
|
||||
inline void dr(const Sampling r)
|
||||
{
|
||||
value = (value & ~(0x07 << 5)) | ((m5::stl::to_underlying(r) & 0x07) << 5);
|
||||
}
|
||||
inline void comp_mode(const bool b) {
|
||||
inline void comp_mode(const bool b)
|
||||
{
|
||||
value = (value & ~(1U << 4)) | ((b ? 1U : 0) << 4);
|
||||
}
|
||||
inline void comp_pol(const bool b) {
|
||||
inline void comp_pol(const bool b)
|
||||
{
|
||||
value = (value & ~(1U << 3)) | ((b ? 1U : 0) << 3);
|
||||
}
|
||||
inline void comp_lat(const bool b) {
|
||||
inline void comp_lat(const bool b)
|
||||
{
|
||||
value = (value & ~(1U << 2)) | ((b ? 1U : 0) << 2);
|
||||
}
|
||||
inline void comp_que(const ComparatorQueue c) {
|
||||
inline void comp_que(const ComparatorQueue c)
|
||||
{
|
||||
value = (value & ~0x03U) | (m5::stl::to_underlying(c) & 0x03);
|
||||
}
|
||||
///@}
|
||||
@@ -186,7 +204,8 @@ struct Config {
|
||||
struct Data {
|
||||
uint16_t raw{};
|
||||
//! @brief ADC
|
||||
inline int16_t adc() const {
|
||||
inline int16_t adc() const
|
||||
{
|
||||
return static_cast<int16_t>(raw);
|
||||
}
|
||||
};
|
||||
@@ -200,7 +219,7 @@ struct Data {
|
||||
class UnitADS111x : public Component, public PeriodicMeasurementAdapter<UnitADS111x, ads111x::Data> {
|
||||
M5_UNIT_COMPONENT_HPP_BUILDER(UnitADS111x, 0x00);
|
||||
|
||||
public:
|
||||
public:
|
||||
/*!
|
||||
@struct config_t
|
||||
@brief Settings for begin
|
||||
@@ -219,12 +238,14 @@ class UnitADS111x : public Component, public PeriodicMeasurementAdapter<UnitADS1
|
||||
};
|
||||
|
||||
explicit UnitADS111x(const uint8_t addr = DEFAULT_ADDRESS)
|
||||
: Component(addr), _data{new m5::container::CircularBuffer<ads111x::Data>(1)} {
|
||||
: Component(addr), _data{new m5::container::CircularBuffer<ads111x::Data>(1)}
|
||||
{
|
||||
auto ccfg = component_config();
|
||||
ccfg.clock = 400 * 1000U;
|
||||
component_config(ccfg);
|
||||
}
|
||||
virtual ~UnitADS111x() {
|
||||
virtual ~UnitADS111x()
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool begin() override;
|
||||
@@ -233,11 +254,13 @@ class UnitADS111x : public Component, public PeriodicMeasurementAdapter<UnitADS1
|
||||
///@name Settings for begin
|
||||
///@{
|
||||
/*! @brief Gets the configration */
|
||||
inline config_t config() {
|
||||
inline config_t config()
|
||||
{
|
||||
return _cfg;
|
||||
}
|
||||
//! @brief Set the configration
|
||||
inline void config(const config_t& cfg) {
|
||||
inline void config(const config_t& cfg)
|
||||
{
|
||||
_cfg = cfg;
|
||||
}
|
||||
///@}
|
||||
@@ -248,7 +271,8 @@ class UnitADS111x : public Component, public PeriodicMeasurementAdapter<UnitADS1
|
||||
@brief Coefficient value
|
||||
@note Changes as gain changes
|
||||
*/
|
||||
inline float coefficient() const {
|
||||
inline float coefficient() const
|
||||
{
|
||||
return _coefficient;
|
||||
}
|
||||
///@}
|
||||
@@ -256,7 +280,8 @@ class UnitADS111x : public Component, public PeriodicMeasurementAdapter<UnitADS1
|
||||
///@name Measurement data by periodic
|
||||
///@{
|
||||
//! @brief Oldest measured ADC
|
||||
inline int16_t adc() const {
|
||||
inline int16_t adc() const
|
||||
{
|
||||
return !empty() ? oldest().adc() : std::numeric_limits<int16_t>::min();
|
||||
}
|
||||
///@}
|
||||
@@ -267,7 +292,8 @@ class UnitADS111x : public Component, public PeriodicMeasurementAdapter<UnitADS1
|
||||
@brief Start periodic measurement in the current settings
|
||||
@return True if successful
|
||||
*/
|
||||
inline bool startPeriodicMeasurement() {
|
||||
inline bool startPeriodicMeasurement()
|
||||
{
|
||||
return PeriodicMeasurementAdapter<UnitADS111x, ads111x::Data>::startPeriodicMeasurement();
|
||||
}
|
||||
/*!
|
||||
@@ -279,7 +305,8 @@ class UnitADS111x : public Component, public PeriodicMeasurementAdapter<UnitADS1
|
||||
@return True if successful
|
||||
*/
|
||||
inline bool startPeriodicMeasurement(const ads111x::Sampling rate, const ads111x::Mux mux, const ads111x::Gain gain,
|
||||
const ads111x::ComparatorQueue comp_que) {
|
||||
const ads111x::ComparatorQueue comp_que)
|
||||
{
|
||||
return PeriodicMeasurementAdapter<UnitADS111x, ads111x::Data>::startPeriodicMeasurement(rate, mux, gain,
|
||||
comp_que);
|
||||
}
|
||||
@@ -287,7 +314,8 @@ class UnitADS111x : public Component, public PeriodicMeasurementAdapter<UnitADS1
|
||||
@brief Stop periodic measurement
|
||||
@return True if successful
|
||||
*/
|
||||
inline bool stopPeriodicMeasurement() {
|
||||
inline bool stopPeriodicMeasurement()
|
||||
{
|
||||
return PeriodicMeasurementAdapter<UnitADS111x, ads111x::Data>::stopPeriodicMeasurement();
|
||||
}
|
||||
///@}
|
||||
@@ -296,13 +324,15 @@ class UnitADS111x : public Component, public PeriodicMeasurementAdapter<UnitADS1
|
||||
///@name Configration
|
||||
///@{
|
||||
/*! @brief Gets the input multiplexer */
|
||||
inline ads111x::Mux multiplexer() const {
|
||||
inline ads111x::Mux multiplexer() const
|
||||
{
|
||||
return _ads_cfg.mux();
|
||||
}
|
||||
//! @brief Gets the programmable gain amplifier
|
||||
ads111x::Gain gain() const;
|
||||
//! @brief Gets the sampling rate
|
||||
inline ads111x::Sampling samplingRate() const {
|
||||
inline ads111x::Sampling samplingRate() const
|
||||
{
|
||||
return _ads_cfg.dr();
|
||||
}
|
||||
/*!
|
||||
@@ -310,7 +340,8 @@ class UnitADS111x : public Component, public PeriodicMeasurementAdapter<UnitADS1
|
||||
@retval true Window comparator
|
||||
@retval false Traditional comparator
|
||||
*/
|
||||
inline bool comparatorMode() const {
|
||||
inline bool comparatorMode() const
|
||||
{
|
||||
return _ads_cfg.comp_mode();
|
||||
}
|
||||
/*!
|
||||
@@ -318,7 +349,8 @@ class UnitADS111x : public Component, public PeriodicMeasurementAdapter<UnitADS1
|
||||
@retval true Active high
|
||||
@retval false Active low
|
||||
*/
|
||||
inline bool comparatorPolarity() const {
|
||||
inline bool comparatorPolarity() const
|
||||
{
|
||||
return _ads_cfg.comp_pol();
|
||||
}
|
||||
/*!
|
||||
@@ -326,11 +358,13 @@ class UnitADS111x : public Component, public PeriodicMeasurementAdapter<UnitADS1
|
||||
@retval true Latching comparator
|
||||
@retval false Nonlatching comparator
|
||||
*/
|
||||
inline bool latchingComparator() const {
|
||||
inline bool latchingComparator() const
|
||||
{
|
||||
return _ads_cfg.comp_lat();
|
||||
}
|
||||
//! @brief Gets the comparator queue
|
||||
inline ads111x::ComparatorQueue comparatorQueue() const {
|
||||
inline ads111x::ComparatorQueue comparatorQueue() const
|
||||
{
|
||||
return _ads_cfg.comp_que();
|
||||
}
|
||||
|
||||
@@ -395,7 +429,7 @@ class UnitADS111x : public Component, public PeriodicMeasurementAdapter<UnitADS1
|
||||
*/
|
||||
bool generalReset();
|
||||
|
||||
protected:
|
||||
protected:
|
||||
bool start_periodic_measurement();
|
||||
virtual bool start_periodic_measurement(const ads111x::Sampling rate, const ads111x::Mux mux,
|
||||
const ads111x::Gain gain, const ads111x::ComparatorQueue comp_que) = 0;
|
||||
@@ -419,7 +453,7 @@ class UnitADS111x : public Component, public PeriodicMeasurementAdapter<UnitADS1
|
||||
|
||||
M5_UNIT_COMPONENT_PERIODIC_MEASUREMENT_ADAPTER_HPP_BUILDER(UnitADS111x, ads111x::Data);
|
||||
|
||||
protected:
|
||||
protected:
|
||||
std::unique_ptr<m5::container::CircularBuffer<ads111x::Data>> _data{};
|
||||
float _coefficient{};
|
||||
ads111x::Config _ads_cfg{};
|
||||
|
||||
@@ -20,7 +20,8 @@ const char UnitAmeter::name[] = "UnitAmeter";
|
||||
const types::uid_t UnitAmeter::uid{"UnitAmeter"_mmh3};
|
||||
const types::uid_t UnitAmeter::attr{0};
|
||||
|
||||
void UnitAmeter::apply_coefficient(const ads111x::Gain gain) {
|
||||
void UnitAmeter::apply_coefficient(const ads111x::Gain gain)
|
||||
{
|
||||
UnitADS111x::apply_coefficient(gain);
|
||||
_correction = resolution() * calibrationFactor();
|
||||
}
|
||||
|
||||
@@ -22,35 +22,40 @@ namespace unit {
|
||||
class UnitAmeter : public UnitAVmeterBase {
|
||||
M5_UNIT_COMPONENT_HPP_BUILDER(UnitAmeter, 0x48);
|
||||
|
||||
public:
|
||||
public:
|
||||
constexpr static uint8_t DEFAULT_EEPROM_ADDRESS{0x51};
|
||||
constexpr static float PRESSURE_COEFFICIENT{0.05f};
|
||||
|
||||
explicit UnitAmeter(const uint8_t addr = DEFAULT_ADDRESS, const uint8_t eepromAddr = DEFAULT_EEPROM_ADDRESS)
|
||||
: UnitAVmeterBase(addr, eepromAddr) {
|
||||
: UnitAVmeterBase(addr, eepromAddr)
|
||||
{
|
||||
// component_config().clock is set at ADS111x constructor
|
||||
}
|
||||
virtual ~UnitAmeter() {
|
||||
virtual ~UnitAmeter()
|
||||
{
|
||||
}
|
||||
|
||||
//! @brief Resolution of 1 LSB
|
||||
inline float resolution() const {
|
||||
inline float resolution() const
|
||||
{
|
||||
return coefficient() / PRESSURE_COEFFICIENT;
|
||||
}
|
||||
//! @brief Gets the correction value
|
||||
inline float correction() const {
|
||||
inline float correction() const
|
||||
{
|
||||
return _correction;
|
||||
}
|
||||
|
||||
//! @brief Oldest current (mA)
|
||||
inline float current() const {
|
||||
inline float current() const
|
||||
{
|
||||
return !empty() ? correction() * adc() : std::numeric_limits<float>::quiet_NaN();
|
||||
}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
virtual void apply_coefficient(const ads111x::Gain gain) override;
|
||||
|
||||
private:
|
||||
private:
|
||||
float _correction{1.0f};
|
||||
};
|
||||
} // namespace unit
|
||||
|
||||
@@ -28,7 +28,8 @@ const char UnitEEPROM::name[] = "UnitEEPROMforMeter";
|
||||
const types::uid_t UnitEEPROM::uid{"UnitEEPROMforMeter"_mmh3};
|
||||
const types::uid_t UnitEEPROM::attr{0};
|
||||
|
||||
bool UnitEEPROM::readCalibration() {
|
||||
bool UnitEEPROM::readCalibration()
|
||||
{
|
||||
int idx{};
|
||||
_calibration.fill({});
|
||||
|
||||
@@ -45,7 +46,8 @@ bool UnitEEPROM::readCalibration() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UnitEEPROM::read_calibration(const Gain gain, int16_t& hope, int16_t& actual) {
|
||||
bool UnitEEPROM::read_calibration(const Gain gain, int16_t& hope, int16_t& actual)
|
||||
{
|
||||
uint8_t reg = DATA_ADDRESS + m5::stl::to_underlying(gain) * 8;
|
||||
std::array<uint8_t, 8> buf{};
|
||||
hope = actual = 1;
|
||||
|
||||
@@ -31,28 +31,33 @@ namespace meter {
|
||||
class UnitEEPROM : public Component {
|
||||
M5_UNIT_COMPONENT_HPP_BUILDER(UnitEEPROM, 0x00);
|
||||
|
||||
public:
|
||||
explicit UnitEEPROM(const uint8_t addr = DEFAULT_ADDRESS) : Component(addr) {
|
||||
public:
|
||||
explicit UnitEEPROM(const uint8_t addr = DEFAULT_ADDRESS) : Component(addr)
|
||||
{
|
||||
}
|
||||
virtual ~UnitEEPROM() {
|
||||
virtual ~UnitEEPROM()
|
||||
{
|
||||
}
|
||||
|
||||
inline int16_t hope(m5::unit::ads111x::Gain gain) const {
|
||||
inline int16_t hope(m5::unit::ads111x::Gain gain) const
|
||||
{
|
||||
return _calibration[m5::stl::to_underlying(gain)].hope;
|
||||
}
|
||||
inline int16_t actual(m5::unit::ads111x::Gain gain) const {
|
||||
inline int16_t actual(m5::unit::ads111x::Gain gain) const
|
||||
{
|
||||
return _calibration[m5::stl::to_underlying(gain)].actual;
|
||||
}
|
||||
inline float calibrationFactor(m5::unit::ads111x::Gain gain) const {
|
||||
inline float calibrationFactor(m5::unit::ads111x::Gain gain) const
|
||||
{
|
||||
return actual(gain) ? (float)hope(gain) / actual(gain) : 1.0f;
|
||||
}
|
||||
|
||||
bool readCalibration();
|
||||
|
||||
protected:
|
||||
protected:
|
||||
bool read_calibration(const m5::unit::ads111x::Gain gain, int16_t& hope, int16_t& actual);
|
||||
|
||||
private:
|
||||
private:
|
||||
struct Calibration {
|
||||
int16_t hope{1};
|
||||
int16_t actual{1};
|
||||
|
||||
@@ -20,7 +20,8 @@ const char UnitVmeter::name[] = "UnitVmeter";
|
||||
const types::uid_t UnitVmeter::uid{"UnitVmeter"_mmh3};
|
||||
const types::uid_t UnitVmeter::attr{0};
|
||||
|
||||
void UnitVmeter::apply_coefficient(const ads111x::Gain gain) {
|
||||
void UnitVmeter::apply_coefficient(const ads111x::Gain gain)
|
||||
{
|
||||
UnitADS111x::apply_coefficient(gain);
|
||||
_correction = resolution() * _eeprom.calibrationFactor(gain);
|
||||
}
|
||||
|
||||
@@ -22,36 +22,41 @@ namespace unit {
|
||||
class UnitVmeter : public UnitAVmeterBase {
|
||||
M5_UNIT_COMPONENT_HPP_BUILDER(UnitVmeter, 0x49);
|
||||
|
||||
public:
|
||||
public:
|
||||
constexpr static uint8_t DEFAULT_EEPROM_ADDRESS{0x53};
|
||||
constexpr static float PRESSURE_COEFFICIENT{0.01591895f};
|
||||
|
||||
explicit UnitVmeter(const uint8_t addr = DEFAULT_ADDRESS, const uint8_t eepromAddr = DEFAULT_EEPROM_ADDRESS)
|
||||
: UnitAVmeterBase(addr, eepromAddr) {
|
||||
: UnitAVmeterBase(addr, eepromAddr)
|
||||
{
|
||||
// component_config().clock is set at ADS111x constructor
|
||||
}
|
||||
virtual ~UnitVmeter() {
|
||||
virtual ~UnitVmeter()
|
||||
{
|
||||
}
|
||||
|
||||
//! @brief Resolution of 1 LSB
|
||||
inline float resolution() const {
|
||||
inline float resolution() const
|
||||
{
|
||||
return coefficient() / PRESSURE_COEFFICIENT;
|
||||
}
|
||||
|
||||
//! @brief Gets the correction value
|
||||
inline float correction() const {
|
||||
inline float correction() const
|
||||
{
|
||||
return _correction;
|
||||
}
|
||||
|
||||
//! @brief Oldest voltage (mV)
|
||||
inline float voltage() const {
|
||||
inline float voltage() const
|
||||
{
|
||||
return !empty() ? correction() * adc() : std::numeric_limits<float>::quiet_NaN();
|
||||
}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
virtual void apply_coefficient(const ads111x::Gain gain) override;
|
||||
|
||||
private:
|
||||
private:
|
||||
float _correction{1.0f};
|
||||
};
|
||||
} // namespace unit
|
||||
|
||||
@@ -42,7 +42,8 @@
|
||||
If the Arduino framework is used, the framework library main is used.
|
||||
*/
|
||||
#if !defined(ARDUINO)
|
||||
int main(int argc, char **argv) {
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
#ifdef GTEST_FILTER
|
||||
|
||||
@@ -31,8 +31,9 @@ using namespace m5::unit;
|
||||
using namespace m5::unit::ads111x;
|
||||
|
||||
class TestADS1115 : public ComponentTestBase<UnitAVmeterBase, TestParams> {
|
||||
protected:
|
||||
virtual UnitAVmeterBase* get_instance() override {
|
||||
protected:
|
||||
virtual UnitAVmeterBase* get_instance() override
|
||||
{
|
||||
TestParams tp = GetParam();
|
||||
auto ptr = new m5::unit::UnitAVmeterBase(tp.reg, tp.reg_eeprom);
|
||||
if (ptr) {
|
||||
@@ -42,24 +43,28 @@ class TestADS1115 : public ComponentTestBase<UnitAVmeterBase, TestParams> {
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
virtual bool is_using_hal() const override {
|
||||
virtual bool is_using_hal() const override
|
||||
{
|
||||
return GetParam().hal;
|
||||
};
|
||||
};
|
||||
|
||||
namespace {
|
||||
inline void check_measurement_values(m5::unit::UnitAVmeterBase* u) {
|
||||
inline void check_measurement_values(m5::unit::UnitAVmeterBase* u)
|
||||
{
|
||||
EXPECT_NE(u->adc(), std::numeric_limits<int16_t>::min());
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_P(TestADS1115, Address) {
|
||||
TEST_P(TestADS1115, Address)
|
||||
{
|
||||
SCOPED_TRACE(ustr);
|
||||
m5::unit::UnitAVmeterBase tmp(0x00, 0x00);
|
||||
EXPECT_FALSE(tmp.begin());
|
||||
}
|
||||
|
||||
TEST_P(TestADS1115, GeneralReset) {
|
||||
TEST_P(TestADS1115, GeneralReset)
|
||||
{
|
||||
SCOPED_TRACE(ustr);
|
||||
|
||||
EXPECT_TRUE(unit->stopPeriodicMeasurement());
|
||||
@@ -95,7 +100,8 @@ TEST_P(TestADS1115, GeneralReset) {
|
||||
EXPECT_EQ(low, default_low);
|
||||
}
|
||||
|
||||
TEST_P(TestADS1115, Configration) {
|
||||
TEST_P(TestADS1115, Configration)
|
||||
{
|
||||
SCOPED_TRACE(ustr);
|
||||
|
||||
uint16_t prev{}, now{};
|
||||
@@ -264,7 +270,8 @@ TEST_P(TestADS1115, Configration) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(TestADS1115, Periodic) {
|
||||
TEST_P(TestADS1115, Periodic)
|
||||
{
|
||||
SCOPED_TRACE(ustr);
|
||||
|
||||
std::tuple<const char*, Sampling> table[] = {
|
||||
@@ -301,7 +308,8 @@ TEST_P(TestADS1115, Periodic) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(TestADS1115, SingleShot) {
|
||||
TEST_P(TestADS1115, SingleShot)
|
||||
{
|
||||
SCOPED_TRACE(ustr);
|
||||
|
||||
m5::unit::ads111x::Data d{};
|
||||
|
||||
@@ -23,11 +23,13 @@ namespace {
|
||||
auto& lcd = M5.Display;
|
||||
} // namespace
|
||||
|
||||
void test() {
|
||||
void test()
|
||||
{
|
||||
lcd.fillRect(0, 0, lcd.width() >> 1, lcd.height(), RUN_ALL_TESTS() ? TFT_RED : TFT_GREEN);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
void setup()
|
||||
{
|
||||
delay(1500);
|
||||
|
||||
M5.begin();
|
||||
@@ -46,7 +48,8 @@ void setup() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void loop() {
|
||||
void loop()
|
||||
{
|
||||
test();
|
||||
#if 0
|
||||
delay(1000);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user