mirror of
https://github.com/m5stack/M5Unit-METER.git
synced 2026-05-20 11:27:46 -07:00
Fixes typos, Doxygen comments, and static analysis warnings
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
/*!
|
||||
@file M5UnitUnifiedMETER.h
|
||||
@brief Header for M5UnitUnifiedMETER (C compatible include)
|
||||
*/
|
||||
#ifndef M5_UNIT_UNIFIED_METER_H
|
||||
#define M5_UNIT_UNIFIED_METER_H
|
||||
|
||||
@@ -27,7 +27,7 @@ constexpr float coefficient_table[] = {
|
||||
1024.f / 32767,
|
||||
512.f / 32767,
|
||||
256.f / 32767,
|
||||
// dupicated[6,7]
|
||||
// duplicated[6,7]
|
||||
256.f / 32767,
|
||||
256.f / 32767,
|
||||
};
|
||||
@@ -241,7 +241,8 @@ bool UnitADS111x::writeThreshold(const int16_t high, const int16_t low)
|
||||
M5_LIB_LOGW("high must be greater than low");
|
||||
return false;
|
||||
}
|
||||
return writeRegister16BE(HIGH_THRESHOLD_REG, (uint16_t)high) && writeRegister16BE(LOW_THRESHOLD_REG, (uint16_t)low);
|
||||
return writeRegister16BE(HIGH_THRESHOLD_REG, static_cast<uint16_t>(high)) &&
|
||||
writeRegister16BE(LOW_THRESHOLD_REG, static_cast<uint16_t>(low));
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -286,14 +286,17 @@ public:
|
||||
///@warning ADS1113, ADS1114 and ADS1115 differ in the items that can be set
|
||||
///@name Configuration
|
||||
///@{
|
||||
/*! @brief Gets the input multiplexer */
|
||||
//! @brief Gets the input multiplexer
|
||||
//! @return Current multiplexer setting
|
||||
inline ads111x::Mux multiplexer() const
|
||||
{
|
||||
return _ads_cfg.mux();
|
||||
}
|
||||
//! @brief Gets the programmable gain amplifier
|
||||
//! @return Current gain setting
|
||||
ads111x::Gain gain() const;
|
||||
//! @brief Gets the sampling rate
|
||||
//! @return Current sampling rate
|
||||
inline ads111x::Sampling samplingRate() const
|
||||
{
|
||||
return _ads_cfg.dr();
|
||||
@@ -326,28 +329,43 @@ public:
|
||||
return _ads_cfg.comp_lat();
|
||||
}
|
||||
//! @brief Gets the comparator queue
|
||||
//! @return Current comparator queue setting
|
||||
inline ads111x::ComparatorQueue comparatorQueue() const
|
||||
{
|
||||
return _ads_cfg.comp_que();
|
||||
}
|
||||
|
||||
//! @brief Write the input multiplexer
|
||||
//! @param mux Multiplexer setting
|
||||
//! @return True if successful
|
||||
virtual bool writeMultiplexer(const ads111x::Mux mux) = 0;
|
||||
/*!
|
||||
@brief Write the programmable gain amplifier
|
||||
@param gain Gain setting
|
||||
@return True if successful
|
||||
@warning the threshold values must be updated whenever the PGA settings are changed
|
||||
@sa writeThreshold
|
||||
*/
|
||||
virtual bool writeGain(const ads111x::Gain gain) = 0;
|
||||
/*! @brief Write the data rate */
|
||||
//! @brief Write the data rate
|
||||
//! @param rate Sampling rate
|
||||
//! @return True if successful
|
||||
bool writeSamplingRate(const ads111x::Sampling rate);
|
||||
//! @brief Write the comparator mode
|
||||
//! @param b true: Window comparator, false: Traditional comparator
|
||||
//! @return True if successful
|
||||
virtual bool writeComparatorMode(const bool b) = 0;
|
||||
//! @brief Write the comparator polarity
|
||||
//! @param b true: Active high, false: Active low
|
||||
//! @return True if successful
|
||||
virtual bool writeComparatorPolarity(const bool b) = 0;
|
||||
//! @brief Write the latching comparator
|
||||
//! @param b true: Latching, false: Nonlatching
|
||||
//! @return True if successful
|
||||
virtual bool writeLatchingComparator(const bool b) = 0;
|
||||
//! @brief Write the comparator queue
|
||||
//! @param c Comparator queue setting
|
||||
//! @return True if successful
|
||||
virtual bool writeComparatorQueue(const ads111x::ComparatorQueue c) = 0;
|
||||
///@}
|
||||
|
||||
@@ -363,7 +381,7 @@ public:
|
||||
@warning Until it can be measured, it will be blocked until the timeout
|
||||
time
|
||||
*/
|
||||
bool measureSingleshot(ads111x::Data& d, const uint32_t timeoutMillis = 1000U);
|
||||
bool measureSingleshot(ads111x::Data& data, const uint32_t timeoutMillis = 1000U);
|
||||
///@}
|
||||
|
||||
///@name Threshold
|
||||
|
||||
@@ -50,11 +50,11 @@ struct Data {
|
||||
std::array<uint8_t, 4> raw{}; //!< Raw data
|
||||
Channel channel{}; //!< Which channel?
|
||||
|
||||
//@note Unit depends on setting
|
||||
//! @note Unit depends on setting
|
||||
inline float temperature() const
|
||||
{
|
||||
return static_cast<int32_t>(((uint32_t)raw[3] << 24) | ((uint32_t)raw[2] << 16) | ((uint32_t)raw[1] << 8) |
|
||||
((uint32_t)raw[0] << 0)) *
|
||||
return static_cast<int32_t>((static_cast<uint32_t>(raw[3]) << 24) | (static_cast<uint32_t>(raw[2]) << 16) |
|
||||
(static_cast<uint32_t>(raw[1]) << 8) | static_cast<uint32_t>(raw[0])) *
|
||||
0.01f;
|
||||
}
|
||||
};
|
||||
@@ -99,9 +99,9 @@ public:
|
||||
bool start_periodic{true};
|
||||
//! periodic interval(ms) if start on begin
|
||||
uint32_t interval{100};
|
||||
//! //!< measurement channel if start on begin
|
||||
//!< measurement channel if start on begin
|
||||
dual_kmeter::Channel measurement_channel{dual_kmeter::Channel::One};
|
||||
//! //!< measurement unit if start on begin
|
||||
//!< measurement unit if start on begin
|
||||
dual_kmeter::MeasurementUnit measurement_unit{dual_kmeter::MeasurementUnit::Celsius};
|
||||
};
|
||||
|
||||
@@ -135,17 +135,20 @@ public:
|
||||
|
||||
///@name Properties
|
||||
///@{
|
||||
/*! Gets the measurement unit on periodic measurement */
|
||||
//! @brief Gets the measurement unit on periodic measurement
|
||||
//! @return Current measurement unit
|
||||
dual_kmeter::MeasurementUnit measurementUnit() const
|
||||
{
|
||||
return _munit;
|
||||
}
|
||||
/*! Gets the measurement channel on periodic measurement */
|
||||
//! @brief Gets the measurement channel on periodic measurement
|
||||
//! @return Current measurement channel
|
||||
dual_kmeter::Channel measurementChannel() const
|
||||
{
|
||||
return _channel;
|
||||
}
|
||||
/*! Set the measurement unit on periodic measurement */
|
||||
//! @brief Set the measurement unit on periodic measurement
|
||||
//! @param munit Measurement unit to set
|
||||
void setMeasurementUnit(const dual_kmeter::MeasurementUnit munit)
|
||||
{
|
||||
_munit = munit;
|
||||
@@ -220,18 +223,19 @@ public:
|
||||
@return True if successful
|
||||
@warning During periodic detection runs, an error is returned
|
||||
*/
|
||||
bool measureSingleshot(dual_kmeter::Data& d, const dual_kmeter::Channel channel,
|
||||
bool measureSingleshot(dual_kmeter::Data& data, const dual_kmeter::Channel channel,
|
||||
dual_kmeter::MeasurementUnit munit = dual_kmeter::MeasurementUnit::Celsius,
|
||||
const uint32_t timeoutMs = 100);
|
||||
/*!
|
||||
@brief Measure internal temperature single shot
|
||||
@param[out] data Measured data
|
||||
@param channel Channel to be measured
|
||||
@param munit measurement unit
|
||||
@param timeoutMs Measurement timeout time(ms)
|
||||
@return True if successful
|
||||
@warning During periodic detection runs, an error is returned
|
||||
*/
|
||||
bool measureInternalSingleshot(dual_kmeter::Data& d, const dual_kmeter::Channel channel,
|
||||
bool measureInternalSingleshot(dual_kmeter::Data& data, const dual_kmeter::Channel channel,
|
||||
const dual_kmeter::MeasurementUnit munit = dual_kmeter::MeasurementUnit::Celsius,
|
||||
const uint32_t timeoutMs = 100);
|
||||
///@}
|
||||
|
||||
@@ -39,19 +39,30 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
//! @brief Gets the expected (hope) ADC value for the given gain
|
||||
//! @param gain Gain setting
|
||||
//! @return Expected ADC value
|
||||
inline int16_t hope(m5::unit::ads111x::Gain gain) const
|
||||
{
|
||||
return _calibration[m5::stl::to_underlying(gain)].hope;
|
||||
}
|
||||
//! @brief Gets the actual ADC value for the given gain
|
||||
//! @param gain Gain setting
|
||||
//! @return Actual ADC value
|
||||
inline int16_t actual(m5::unit::ads111x::Gain gain) const
|
||||
{
|
||||
return _calibration[m5::stl::to_underlying(gain)].actual;
|
||||
}
|
||||
//! @brief Gets the calibration factor for the given gain
|
||||
//! @param gain Gain setting
|
||||
//! @return Calibration factor (hope / actual)
|
||||
inline float calibrationFactor(m5::unit::ads111x::Gain gain) const
|
||||
{
|
||||
return actual(gain) ? (float)hope(gain) / actual(gain) : 1.0f;
|
||||
}
|
||||
|
||||
//! @brief Read calibration data from EEPROM
|
||||
//! @return True if successful
|
||||
bool readCalibration();
|
||||
|
||||
protected:
|
||||
|
||||
@@ -221,12 +221,12 @@ struct Mask {
|
||||
uint16_t v{};
|
||||
};
|
||||
|
||||
float caluculate_currentLSB(const float maxCur)
|
||||
float calculate_currentLSB(const float maxCur)
|
||||
{
|
||||
return maxCur / 32767.f;
|
||||
}
|
||||
|
||||
uint16_t caluculate_calibration(const float shuntRes, const float maxCur, const float curLSB)
|
||||
uint16_t calculate_calibration(const float shuntRes, const float maxCur, const float curLSB)
|
||||
{
|
||||
return (0.00512f / (curLSB * shuntRes));
|
||||
}
|
||||
@@ -284,7 +284,7 @@ UnitINA226::UnitINA226(const float shuntRes, const float maxCurA, const float cu
|
||||
ccfg.clock = 400 * 1000U;
|
||||
component_config(ccfg);
|
||||
if (_currentLSB == 0.0f) {
|
||||
_currentLSB = caluculate_currentLSB(maxCurA);
|
||||
_currentLSB = calculate_currentLSB(maxCurA);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,7 +329,7 @@ bool UnitINA226::begin()
|
||||
}
|
||||
|
||||
// Set calibration
|
||||
uint16_t cal = caluculate_calibration(_shuntRes, _maxCurrentA, _currentLSB);
|
||||
uint16_t cal = calculate_calibration(_shuntRes, _maxCurrentA, _currentLSB);
|
||||
if (!writeCalibration(cal)) {
|
||||
M5_LIB_LOGE("Failed to writeCalibration %u", cal);
|
||||
return false;
|
||||
@@ -593,13 +593,13 @@ bool UnitINA226::powerDown()
|
||||
bool UnitINA226::softReset(const bool all)
|
||||
{
|
||||
ModeCfg mc{};
|
||||
uint16_t cal{};
|
||||
_periodic = false;
|
||||
|
||||
if (read_configuration(mc.v)) {
|
||||
mc.reset(true);
|
||||
if (write_configuration(mc.v)) {
|
||||
m5::utility::delay(2);
|
||||
uint16_t cal{};
|
||||
if (read_configuration(mc.v) && mc.v == DEFAULT_CONFIG_VALUE && readCalibration(cal) && cal == 0) {
|
||||
// Default config 0x4127 is ShuntAndBus continuous mode,
|
||||
// but leave _periodic false; caller manages it via powerDown/startPeriodicMeasurement
|
||||
@@ -723,7 +723,7 @@ bool UnitINA226::read_measurement(ina226::Data& d)
|
||||
uint8_t reg{SHUNT_VOLTAGE_REG}; // 0x01
|
||||
for (uint_fast8_t i = 0; i < 4; ++i) {
|
||||
if (_measureBits & (1U << i)) {
|
||||
ret &= readRegister16BE((uint8_t)(reg + i), d.raw[i], 0); // reg 0x01 - 0x04
|
||||
ret &= readRegister16BE(static_cast<uint8_t>(reg + i), d.raw[i], 0); // reg 0x01 - 0x04
|
||||
}
|
||||
}
|
||||
d.currentLSB = _currentLSB;
|
||||
|
||||
@@ -143,7 +143,7 @@ public:
|
||||
protected:
|
||||
/*!
|
||||
@brief Constructor
|
||||
@param shuntRes Shunt resistor (O)
|
||||
@param shuntRes Shunt resistor (Ohm)
|
||||
@param maxCurA Maximum measure current (A)
|
||||
@param curLSB currentLSB
|
||||
*/
|
||||
@@ -173,7 +173,7 @@ public:
|
||||
|
||||
///@name Properties
|
||||
///@{
|
||||
//! @brief Gets the shunt Resistor (O)
|
||||
//! @brief Gets the shunt Resistor (Ohm)
|
||||
inline float shuntResistor() const
|
||||
{
|
||||
return _shuntRes;
|
||||
@@ -229,7 +229,7 @@ public:
|
||||
}
|
||||
/*!
|
||||
@brief Start periodic measurement
|
||||
@param rate Sampling Sampling rate
|
||||
@param rate Sampling rate
|
||||
@param sct Shunt conversion time
|
||||
@param bct Bus conversion time
|
||||
@param current Measure current if true
|
||||
@@ -273,7 +273,7 @@ public:
|
||||
@brief Measurement single shot
|
||||
@details Measuring in the current settings
|
||||
@param[out] data Measured data
|
||||
@param rate Sampling Sampling rate
|
||||
@param rate Sampling rate
|
||||
@param sct Shunt conversion time
|
||||
@param bct Bus conversion time
|
||||
@param current Measure current if true
|
||||
@@ -299,13 +299,13 @@ public:
|
||||
bool readMode(ina226::Mode& mode);
|
||||
/*!
|
||||
@brief Read the sampling rate
|
||||
@param[out] rate Samling rate
|
||||
@param[out] rate Sampling rate
|
||||
@return True if successful
|
||||
*/
|
||||
bool readSamplingRate(ina226::Sampling& rate);
|
||||
/*!
|
||||
@brief Write the sampling rate
|
||||
@param rate Samling rate
|
||||
@param rate Sampling rate
|
||||
@return True if successful
|
||||
@warning During periodic detection runs, an error is returned
|
||||
*/
|
||||
|
||||
@@ -36,11 +36,11 @@ enum class MeasurementUnit : uint8_t {
|
||||
struct Data {
|
||||
std::array<uint8_t, 4> raw{}; //!< Raw data
|
||||
|
||||
//@note Unit depends on setting
|
||||
//! @note Unit depends on setting
|
||||
inline float temperature() const
|
||||
{
|
||||
return static_cast<int32_t>(((uint32_t)raw[3] << 24) | ((uint32_t)raw[2] << 16) | ((uint32_t)raw[1] << 8) |
|
||||
((uint32_t)raw[0] << 0)) *
|
||||
return static_cast<int32_t>((static_cast<uint32_t>(raw[3]) << 24) | (static_cast<uint32_t>(raw[2]) << 16) |
|
||||
(static_cast<uint32_t>(raw[1]) << 8) | static_cast<uint32_t>(raw[0])) *
|
||||
0.01f;
|
||||
}
|
||||
};
|
||||
@@ -63,7 +63,7 @@ public:
|
||||
bool start_periodic{true};
|
||||
//! periodic interval(ms) if start on begin
|
||||
uint32_t interval{100};
|
||||
//! //!< measurement unit if start on begin
|
||||
//!< measurement unit if start on begin
|
||||
kmeter_iso::MeasurementUnit measurement_unit{kmeter_iso::MeasurementUnit::Celsius};
|
||||
};
|
||||
|
||||
@@ -97,12 +97,14 @@ public:
|
||||
|
||||
///@name Properties
|
||||
///@{
|
||||
/*! Gets the measurement unit on periodic measurement */
|
||||
//! @brief Gets the measurement unit on periodic measurement
|
||||
//! @return Current measurement unit
|
||||
kmeter_iso::MeasurementUnit measurementUnit() const
|
||||
{
|
||||
return _munit;
|
||||
}
|
||||
/*! Set the measurement unit on periodic measurement */
|
||||
//! @brief Set the measurement unit on periodic measurement
|
||||
//! @param munit Measurement unit to set
|
||||
void setMeasurementUnit(const kmeter_iso::MeasurementUnit munit)
|
||||
{
|
||||
_munit = munit;
|
||||
@@ -173,7 +175,7 @@ public:
|
||||
@return True if successful
|
||||
@warning During periodic detection runs, an error is returned
|
||||
*/
|
||||
bool measureSingleshot(kmeter_iso::Data& d,
|
||||
bool measureSingleshot(kmeter_iso::Data& data,
|
||||
const kmeter_iso::MeasurementUnit munit = kmeter_iso::MeasurementUnit::Celsius,
|
||||
const uint32_t timeoutMs = 100);
|
||||
/*!
|
||||
@@ -184,7 +186,7 @@ public:
|
||||
@return True if successful
|
||||
@warning During periodic detection runs, an error is returned
|
||||
*/
|
||||
bool measureInternalSingleshot(kmeter_iso::Data& d,
|
||||
bool measureInternalSingleshot(kmeter_iso::Data& data,
|
||||
const kmeter_iso::MeasurementUnit munit = kmeter_iso::MeasurementUnit::Celsius,
|
||||
const uint32_t timeoutMs = 100);
|
||||
///@}
|
||||
|
||||
@@ -24,6 +24,9 @@ class UnitAVmeterBase : public UnitADS1115 {
|
||||
M5_UNIT_COMPONENT_HPP_BUILDER(UnitAVmeterBase, 0x00);
|
||||
|
||||
public:
|
||||
//! @brief Constructor
|
||||
//! @param addr I2C address of the ADC
|
||||
//! @param eepromAddr I2C address of the calibration EEPROM
|
||||
explicit UnitAVmeterBase(const uint8_t addr = DEFAULT_ADDRESS, const uint8_t eepromAddr = 0x00);
|
||||
virtual ~UnitAVmeterBase()
|
||||
{
|
||||
@@ -31,11 +34,16 @@ public:
|
||||
|
||||
virtual bool begin() override;
|
||||
|
||||
//! @brief Gets the calibration factor for the current gain setting
|
||||
//! @return Calibration factor
|
||||
inline float calibrationFactor() const
|
||||
{
|
||||
return _calibrationFactor;
|
||||
}
|
||||
|
||||
//! @brief Write the gain and update calibration factor
|
||||
//! @param gain Gain setting
|
||||
//! @return True if successful
|
||||
virtual bool writeGain(const ads111x::Gain gain) override;
|
||||
|
||||
protected:
|
||||
|
||||
Reference in New Issue
Block a user