Skip to content

Commit

Permalink
Change .clang-format to the latest M5 one
Browse files Browse the repository at this point in the history
  • Loading branch information
GOB52 committed Sep 25, 2024
1 parent 1a4bd9e commit bcef0f4
Show file tree
Hide file tree
Showing 22 changed files with 294 additions and 162 deletions.
6 changes: 3 additions & 3 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
Language: Cpp
BasedOnStyle: Google
AccessModifierOffset: -1
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: true
AlignConsecutiveAssignments: true
Expand Down Expand Up @@ -29,7 +29,7 @@ BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
Expand All @@ -42,7 +42,7 @@ BraceWrapping:
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ Sampling rate{Sampling::Rate32};

} // namespace

void setup() {
void setup()
{
M5.begin();

// Settings
Expand Down Expand Up @@ -79,7 +80,8 @@ void setup() {
lcd.clear(TFT_DARKGREEN);
}

void loop() {
void loop()
{
M5.update();
Units.update();
if (unit.updated()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ Sampling rate{Sampling::Rate32};

} // namespace

void setup() {
void setup()
{
M5.begin();

// Settings
Expand Down Expand Up @@ -79,7 +80,8 @@ void setup() {
lcd.clear(TFT_DARKGREEN);
}

void loop() {
void loop()
{
M5.update();
Units.update();
if (unit.updated()) {
Expand Down
3 changes: 2 additions & 1 deletion src/unit/unit_ADS1113.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
28 changes: 18 additions & 10 deletions src/unit/unit_ADS1113.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
3 changes: 2 additions & 1 deletion src/unit/unit_ADS1114.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
28 changes: 18 additions & 10 deletions src/unit/unit_ADS1114.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
19 changes: 12 additions & 7 deletions src/unit/unit_ADS1115.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -38,16 +39,17 @@ 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;
component_config(cfg);
_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;
Expand All @@ -60,15 +62,17 @@ 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;
}
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;
Expand All @@ -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);
}

Expand Down
45 changes: 28 additions & 17 deletions src/unit/unit_ADS1115.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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?
};
Expand Down
Loading

0 comments on commit bcef0f4

Please sign in to comment.