Skip to content

Commit

Permalink
Some tiny refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
FredM67 committed Mar 14, 2024
1 parent d34d9ab commit 6d1bb8c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
6 changes: 3 additions & 3 deletions Mk2_3phase_RFdatalog_temp/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ Activez la ligne suivante en supprimant le commentaire :
#define TEMP_ENABLED
```

Si la bibliothèque OneWire n'est pas installée, installez-la via le menu **Outils** => **Gérer les bibliothèques...**.
Recherchez "Onewire" et installez "**OneWire** par Jim Studt, ..." en version **2.3.7** ou plus récente.
Si la bibliothèque OneWire n'est pas installée, installez-la via le menu **Outils** => **Gérer les bibliothèques**.
Recherchez "Onewire" et installez "**OneWire** par Jim Studt, " en version **2.3.7** ou plus récente.

#### Avec Visual Studio Code et PlatformIO
Sélectionnez la configuration "**env:temperature (Mk2_3phase_RFdatalog_temp)**".
Expand Down Expand Up @@ -280,7 +280,7 @@ inline constexpr pairForceLoad rg_ForceLoad[NO_OF_DUMPLOADS]{ { 0, 0 },
La rotation des priorités est utile lors de l'alimentation d'un chauffe-eau triphasé.
Elle permet d'équilibrer la durée de fonctionnement des différentes résistances sur une période prolongée.

Mais elle peut aussi être intéressante si on veut permuter les priorités de deux appareils chaque jour (deux chauffe-eau, ...).
Mais elle peut aussi être intéressante si on veut permuter les priorités de deux appareils chaque jour (deux chauffe-eau, ).

Une fois n'est pas coutume, l'activation de cette fonction possède 2 modes :
- **automatique**, on spécifiera alors
Expand Down
33 changes: 17 additions & 16 deletions Mk2_3phase_RFdatalog_temp/processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,18 @@ void updatePortsStates()
*/
void updatePhysicalLoadStates()
{
uint8_t i{ 0 };

if constexpr (PRIORITY_ROTATION != RotationModes::OFF)
{
if (b_reOrderLoads)
{
const auto temp{ loadPrioritiesAndState[0] };
for (i = 0; i < NO_OF_DUMPLOADS - 1; ++i)
uint8_t i{ NO_OF_DUMPLOADS - 1 };
do
{
loadPrioritiesAndState[i] = loadPrioritiesAndState[i + 1];
}
loadPrioritiesAndState[i] = temp;
loadPrioritiesAndState[i] = loadPrioritiesAndState[i - 1];
--i;
} while (i);
loadPrioritiesAndState[0] = temp;

b_reOrderLoads = false;
}
Expand All @@ -262,11 +262,13 @@ void updatePhysicalLoadStates()
}

const bool bDiversionOff{ b_diversionOff };
for (i = 0; i < NO_OF_DUMPLOADS; ++i)
uint8_t i{ 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);
}

/**
Expand Down Expand Up @@ -334,9 +336,7 @@ void confirmPolarity(const uint8_t phase)
return;
}

++count[phase];

if (count[phase] > PERSISTENCE_FOR_POLARITY_CHANGE)
if (++count[phase] > PERSISTENCE_FOR_POLARITY_CHANGE)
{
count[phase] = 0;
polarityConfirmed[phase] = polarityOfMostRecentSampleV[phase];
Expand Down Expand Up @@ -608,8 +608,7 @@ uint8_t nextLogicalLoadToBeRemoved()
uint8_t index{ NO_OF_DUMPLOADS };
do
{
--index;
if (loadPrioritiesAndState[index] & loadStateOnBit)
if (loadPrioritiesAndState[--index] & loadStateOnBit)
{
return (index);
}
Expand Down Expand Up @@ -732,10 +731,12 @@ void processPlusHalfCycle(const uint8_t phase)
void processRawSamples(const uint8_t phase)
{
// The raw V and I samples are processed in "phase pairs"
const auto &lastPolarity{ polarityConfirmedOfLastSampleV[phase] };

if (Polarities::POSITIVE == polarityConfirmed[phase])
{
// the polarity of this sample is positive
if (Polarities::POSITIVE != polarityConfirmedOfLastSampleV[phase])
if (Polarities::POSITIVE != lastPolarity)
{
// This is the start of a new +ve half cycle, for this phase, just after the zero-crossing point.
if (beyondStartUpPeriod)
Expand All @@ -759,13 +760,13 @@ void processRawSamples(const uint8_t phase)
else
{
// the polarity of this sample is negative
if (Polarities::NEGATIVE != polarityConfirmedOfLastSampleV[phase])
if (Polarities::NEGATIVE != lastPolarity)
{
// This is the start of a new -ve half cycle (just after the zero-crossing point)
processMinusHalfCycle(phase);
}
}
} // end of processRawSamples()
}

/**
* @brief Process the current voltage raw sample for the specific phase
Expand Down
19 changes: 14 additions & 5 deletions Mk2_3phase_RFdatalog_temp/utils_temp.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ inline constexpr bool TEMP_SENSOR_PRESENT{ true }; /**< set it to 'true' if temp
inline constexpr bool TEMP_SENSOR_PRESENT{ false }; /**< set it to 'true' if temperature sensing is needed */
#endif

/**
* @struct DeviceAddress
* @brief Structure representing the address of a device.
*
* This structure is used to store the unique address of a device, such as a DS18B20 temperature sensor.
* The address is an array of 8 bytes, typically represented in hexadecimal.
*/
struct DeviceAddress
{
uint8_t addr[8]; /**< The address of the device as an array of 8 bytes. */
};

/**
* @brief This class implements the temperature sensing feature
*
Expand All @@ -35,12 +47,9 @@ class TemperatureSensing
{
using ScratchPad = uint8_t[9];

struct DeviceAddress
{
uint8_t addr[8];
};

public:
constexpr TemperatureSensing() = delete;

/**
* @brief Construct a new Temperature Sensing object
*
Expand Down

0 comments on commit 6d1bb8c

Please sign in to comment.