Skip to content

Commit

Permalink
Some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
FredM67 committed Mar 15, 2024
1 parent 41b9ec6 commit 3e4e999
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
5 changes: 2 additions & 3 deletions Mk2_3phase_RFdatalog_temp/dualtariff.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class _rg_OffsetForce
{
public:
constexpr _rg_OffsetForce()
: _rg()
{
constexpr uint16_t uiPeakDurationInSec{ OffPeakDuration * 3600 };
// calculates offsets for force start and stop of each load
Expand All @@ -51,13 +50,13 @@ class _rg_OffsetForce
}
}
}
const uint32_t (&operator[](uint8_t i) const)[2]
const auto (&operator[](uint8_t i) const)
{
return _rg[i];
}

private:
uint32_t _rg[N][2];
uint32_t _rg[N][2]{};
};

inline uint32_t ul_TimeOffPeak; /**< 'timestamp' for start of off-peak period */
Expand Down
2 changes: 1 addition & 1 deletion Mk2_3phase_RFdatalog_temp/movingAvg.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class movingAvg
return _ar[idx];
}

constexpr uint8_t getSize() const
[[nodiscard]] constexpr uint8_t getSize() const
{
return DURATION_IN_MINUTES;
}
Expand Down
4 changes: 2 additions & 2 deletions Mk2_3phase_RFdatalog_temp/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ build_unflags =
extra_scripts = pre:inject_sketch_name.py
check_tool = cppcheck, clangtidy
check_flags =
cppcheck: --enable=all
clangtidy: --fix --checks=*,-llvmlibc-callee-namespace,-llvmlibc-implementation-in-namespace,-clang-diagnostic-c++17-extensions
cppcheck: --enable=all --std=c++17 --suppress=missingIncludeSystem
clangtidy: --fix --extra-arg=-std=c++17 --checks=*,-llvmlibc-callee-namespace,-llvmlibc-implementation-in-namespace,-clang-diagnostic-c++17-extensions,-llvm-header-guard
check_skip_packages = yes
check_src_filters = +<*>
monitor_filters =
Expand Down
13 changes: 8 additions & 5 deletions Mk2_3phase_RFdatalog_temp/processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ void initializeOptionalPins()
}
}

#if !defined(__DOXYGEN__)
void updatePortsStates() __attribute__((optimize("-O3")));
#endif
/**
* @brief update the control ports for each of the physical loads
*
Expand Down Expand Up @@ -262,13 +265,13 @@ void updatePhysicalLoadStates()
}

const bool bDiversionOff{ b_diversionOff };
uint8_t i{ NO_OF_DUMPLOADS };
uint8_t idx{ NO_OF_DUMPLOADS };
do
{
--i;
const auto iLoad{ loadPrioritiesAndState[i] & loadStateMask };
physicalLoadState[iLoad] = !bDiversionOff && (b_overrideLoadOn[iLoad] || (loadPrioritiesAndState[i] & loadStateOnBit)) ? LoadStates::LOAD_ON : LoadStates::LOAD_OFF;
} while (i);
--idx;
const auto iLoad{ loadPrioritiesAndState[idx] & loadStateMask };
physicalLoadState[iLoad] = !bDiversionOff && (b_overrideLoadOn[iLoad] || (loadPrioritiesAndState[idx] & loadStateOnBit)) ? LoadStates::LOAD_ON : LoadStates::LOAD_OFF;
} while (idx);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Mk2_3phase_RFdatalog_temp/utils_dualtariff.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class pairForceLoad
{
}

constexpr int16_t getStartOffset() const
[[nodiscard]] constexpr int16_t getStartOffset() const
{
return iStartOffset;
}
constexpr uint16_t getDuration() const
[[nodiscard]] constexpr uint16_t getDuration() const
{
return uiDuration;
}
Expand Down
10 changes: 5 additions & 5 deletions Mk2_3phase_RFdatalog_temp/utils_relay.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class relayOutput
* @param _relay_pin Control pin for the relay
*/
explicit constexpr relayOutput(const uint8_t _relay_pin)
: relay_pin(_relay_pin)
: relay_pin{_relay_pin}
{
}

Expand All @@ -48,7 +48,7 @@ class relayOutput
* @param _importThreshold Import threshold to turn relay OFF
*/
constexpr relayOutput(uint8_t _relay_pin, int16_t _surplusThreshold, int16_t _importThreshold)
: relay_pin(_relay_pin), surplusThreshold(-abs(_surplusThreshold)), importThreshold(abs(_importThreshold))
: relay_pin{_relay_pin}, surplusThreshold{-abs(_surplusThreshold)}, importThreshold{abs(_importThreshold)}
{
}

Expand All @@ -62,7 +62,7 @@ class relayOutput
* @param _minOFF Minimum duration in minutes to leave relay OFF
*/
constexpr relayOutput(uint8_t _relay_pin, int16_t _surplusThreshold, int16_t _importThreshold, uint16_t _minON, uint16_t _minOFF)
: relay_pin(_relay_pin), surplusThreshold(-abs(_surplusThreshold)), importThreshold(abs(_importThreshold)), minON(_minON * 60), minOFF(_minOFF * 60)
: relay_pin{_relay_pin}, surplusThreshold{-abs(_surplusThreshold)}, importThreshold{abs(_importThreshold)}, minON{_minON * 60}, minOFF{_minOFF * 60}
{
}

Expand Down Expand Up @@ -151,7 +151,7 @@ class relayOutput
{
return try_turnON();
}
else if (currentAvgPower > importThreshold)
if (currentAvgPower > importThreshold)
{
return try_turnOFF();
}
Expand Down Expand Up @@ -255,7 +255,7 @@ class RelayEngine
* @brief Construct a list of relays
*
*/
constexpr RelayEngine(const relayOutput (&ref)[N])
explicit constexpr RelayEngine(const relayOutput (&ref)[N])
: relay(ref)
{
}
Expand Down

0 comments on commit 3e4e999

Please sign in to comment.