12static_assert(__cplusplus >= 201703L,
"**** Please define 'gnu++17' in 'platform.txt' ! ****");
13static_assert(__cplusplus >= 201703L,
"See also : https://github.com/FredM67/PVRouter-3-phase/blob/main/Mk2_fasterControl_Full/README.md");
62 static uint8_t previousState{ HIGH };
63 if (previousState != pinState)
65 DBUGLN(!pinState ? F(
"Trigger override!") : F(
"End override!"));
68 previousState = pinState;
73 bOverrideLoad = !pinState;
145 static bool pinOffPeakState{ HIGH };
148 if (pinOffPeakState && !pinNewState)
151 DBUGLN(F(
"Change to off-peak period!"));
162 const auto ulElapsedTime{
static_cast< uint32_t
>(millis() -
ul_TimeOffPeak) };
179 if (!pinOffPeakState && pinNewState)
181 DBUGLN(F(
"Change to peak period!"));
184 pinOffPeakState = pinNewState;
186 return (LOW == pinOffPeakState);
225 static uint8_t pinRotationState{ HIGH };
228 if (pinRotationState && !pinNewState)
230 DBUGLN(F(
"Trigger rotation!"));
234 pinRotationState = pinNewState;
250 bOverrideLoad = !pinState;
277 static auto previousState{ HIGH };
278 if (previousState != pinState)
280 DBUG(F(
"Trigger - diversion turned "));
281 DBUGLN(!pinState ? F(
"'OFF'!") : F(
"'ON'!"));
284 previousState = pinState;
322 if (8500 == tmp && (abs(tmp -
tx_data.temperature_x100[idx]) > 500))
327 tx_data.temperature_x100[idx] = tmp;
395 DEBUG_PORT.begin(9600);
415 DBUG(F(
">>free RAM = "));
489 static bool initLoop{
true };
490 static uint8_t perSecondTimer{ 0 };
491 static bool bOffPeak{
false };
492 static uint8_t timerForDisplayUpdate{ 0 };
493 static int16_t iTemperature_x100{ 0 };
502 timerForDisplayUpdate = 0;
Calibration values definition.
constexpr float f_voltageCal
constexpr float powerCal_grid
constexpr float powerCal_diverted
Configuration values to be set by the end-user.
constexpr bool RELAY_DIVERSION
constexpr bool OVERRIDE_PIN_PRESENT
constexpr uint8_t dualTariffPin
constexpr TemperatureSensing temperatureSensing
constexpr uint8_t forcePin
constexpr RelayEngine relays
constexpr bool DUAL_TARIFF
constexpr uint8_t diversionPin
constexpr SerialOutputType SERIAL_OUTPUT_TYPE
constexpr bool EMONESP_CONTROL
constexpr uint16_t ROTATION_AFTER_SECONDS
constexpr uint8_t NO_OF_DUMPLOADS
constexpr bool TEMP_SENSOR_PRESENT
constexpr int16_t iTemperatureThreshold
constexpr bool WATCHDOG_PIN_PRESENT
constexpr bool DIVERSION_PIN_PRESENT
constexpr uint8_t rotationPin
constexpr uint8_t watchDogPin
constexpr uint8_t DATALOG_PERIOD_IN_SECONDS
constexpr uint16_t delayBeforeSerialStarts
constexpr uint8_t SUPPLY_FREQUENCY
constexpr int16_t DEVICE_DISCONNECTED_RAW
constexpr auto rg_OffsetForce
void sendResults(bool bOffPeak)
Prints or sends telemetry data logs based on the selected output format.
void logLoadPriorities()
Prints the load priorities to the Serial output.
void printConfiguration()
Print the configuration during startup.
void initializeProcessing()
Initializes the processing engine, including ports, load states, and ADC setup.
void updateWatchdog()
Update the watchdog on the display.
void setupOLED()
Setup the OLED display.
void updateOLED(uint16_t value)
Update the OLED display with the given value.
void clearDisplay()
Clear the display.
void initializeDisplay()
Initializes the display for hardware-driven 7-segment displays.
void configureValueForDisplay(const bool _EDD_isActive, const uint16_t _ValueToDisplay, const bool _diversionEnabled=false, const bool _loadForced=false)
Configures the value for display on a 7-segment display.
void handlePerSecondTasks(bool &bOffPeak, int16_t iTemperature_x100)
Handles tasks that need to be executed every second.
void processCalculationsForLogging()
Performs calculations on data for logging purposes.
void checkDiversionOnOff()
Checks and updates the diversion state.
void setup()
Called once during startup.
bool forceFullPower()
Forces all loads to full power.
bool proceedLoadPrioritiesAndOverridingDualTariff(const int16_t currentTemperature_x100)
Handles load priority in combination with dual tariff.
void proceedRotation()
Rotates the load priorities.
bool proceedLoadPrioritiesAndOverriding(const int16_t currentTemperature_x100)
Handles load priority rotation and overriding logic.
void updateTemperature()
Updates the temperature readings and sends a new request for the next cycle.
void loop()
Main processor loop.
volatile uint16_t copyOf_divertedEnergyTotal_Wh_forDL
volatile int32_t copyOf_sum_Vsquared
volatile int32_t copyOf_sumP_grid_overDL_Period
volatile bool b_datalogEventPending
volatile bool b_overrideLoadOn[NO_OF_DUMPLOADS]
volatile bool b_reOrderLoads
volatile uint16_t copyOf_sampleSetsDuringThisDatalogPeriod
volatile int32_t copyOf_sumP_diverted_overDL_Period
volatile uint16_t copyOf_divertedEnergyTotal_Wh
volatile bool EDD_isActive
volatile uint16_t absenceOfDivertedEnergyCountInSeconds
volatile bool b_diversionEnabled
Public functions/variables of processing engine.
Some basics classes/types.
int freeRam()
Get the available RAM during setup.
7-segments display functions
constexpr uint8_t UPDATE_PERIOD_FOR_DISPLAYED_DATA
Some utility functions for OLED display.
constexpr bool getPinState(uint8_t pin)
Get the Pin State.
constexpr void togglePin(uint8_t pin)
Toggle the specified pin.
Some utility functions for the relay output feature.
Provides utilities for managing temperature sensors.