Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit bf73705
Author: Frédéric Metrich <[email protected]>
Date:   Sat Mar 2 13:45:14 2024 +0100

    Fix doc

commit 866f94a
Author: Frédéric Metrich <[email protected]>
Date:   Sat Mar 2 13:38:46 2024 +0100

    Refactoring temp (#84)

    * Refactoring temp

    * Fix refactoring temperature

commit af1fe84
Author: Frédéric Metrich <[email protected]>
Date:   Fri Mar 1 08:33:35 2024 +0100

    Update Readme.fr.md (#83)

    Signed-off-by: Frédéric Metrich <[email protected]>

commit c73c567
Author: Frédéric Metrich <[email protected]>
Date:   Mon Feb 26 11:11:24 2024 +0100

    Add some alias for type_trait

commit eb53c16
Author: Frédéric Metrich <[email protected]>
Date:   Mon Feb 26 11:10:55 2024 +0100

    Update color in schematic

commit eac769e
Author: Frédéric Metrich <[email protected]>
Date:   Thu Feb 15 21:29:47 2024 +0100

    Update Readme.md (#82)

commit 82d84ee
Author: Frédéric Metrich <[email protected]>
Date:   Tue Feb 13 14:37:48 2024 +0100

    Added Thermostat_tri_HC.pdf

commit fad5e19
Author: Frédéric Metrich <[email protected]>
Date:   Tue Feb 13 14:36:53 2024 +0100

    Update Thermostat_tri_HC.drawio

commit f03b4ca
Author: Frédéric Metrich <[email protected]>
Date:   Mon Feb 12 11:07:04 2024 +0100

    WIP: 1772479 Fix mvAvg

commit 5e5646a
Author: Frédéric Metrich <[email protected]>
Date:   Mon Feb 5 00:04:30 2024 +0100

    Update CodeQL

commit 4684e01
Author: Frédéric Metrich <[email protected]>
Date:   Sun Feb 4 23:35:01 2024 +0100

    Upt readme

commit d957494
Author: Frédéric Metrich <[email protected]>
Date:   Sun Feb 4 23:32:24 2024 +0100

    Try again

commit 46884f3
Author: Frédéric Metrich <[email protected]>
Date:   Sun Feb 4 23:30:21 2024 +0100

    Try fix

commit c7db21e
Author: Frédéric Metrich <[email protected]>
Date:   Sun Feb 4 23:28:09 2024 +0100

    Fix readme

commit 248a89a
Author: Frédéric Metrich <[email protected]>
Date:   Sun Feb 4 23:23:14 2024 +0100

    Reorganize readmes

commit fff68e0
Author: Frédéric Metrich <[email protected]>
Date:   Sun Feb 4 23:11:19 2024 +0100

    Fix branch name

commit 656308b
Author: Frédéric Metrich <[email protected]>
Date:   Sun Feb 4 23:10:39 2024 +0100

    Fix filenames

commit b911d8d
Author: Frédéric Metrich <[email protected]>
Date:   Sun Feb 4 23:08:55 2024 +0100

    Fix links

commit 83d5591
Author: Frédéric Metrich <[email protected]>
Date:   Sun Feb 4 23:07:18 2024 +0100

    Multilinugal readme + more details

commit 1772479
Author: Frédéric Metrich <[email protected]>
Date:   Fri Feb 2 11:39:13 2024 +0100

    Fix mvAvg

commit 90204aa
Author: Frédéric Metrich <[email protected]>
Date:   Mon Jan 22 22:02:08 2024 +0100

    Fix relay template

commit eef84ea
Author: Frédéric Metrich <[email protected]>
Date:   Mon Jan 22 16:36:28 2024 +0100

    Enhanced sliding average...
  • Loading branch information
FredM67 committed Mar 3, 2024
1 parent ac7075d commit 769b79e
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 74 deletions.
5 changes: 2 additions & 3 deletions Mk2_3phase_RFdatalog_temp/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,15 @@ inline constexpr uint8_t rotationPin{ 0xff }; /**< if LOW, trigger a load prio
inline constexpr uint8_t forcePin{ 0xff }; /**< for 3-phase PCB, force pin */
inline constexpr uint8_t watchDogPin{ 4 }; /**< watch dog LED */

inline constexpr uint8_t tempSensorPin{ 10 }; /**< for 3-phase PCB, sensor pin */

inline constexpr relayOutput relay_Output{ relayPin, 1000, 200, 1, 1 }; /**< config for relay diversion, see class definition for defaults and advanced options */

inline constexpr uint8_t ul_OFF_PEAK_DURATION{ 8 }; /**< Duration of the off-peak period in hours */
inline constexpr pairForceLoad rg_ForceLoad[NO_OF_DUMPLOADS]{ { -3, 2 } }; /**< force config for load #1 ONLY for dual tariff */

inline constexpr int16_t iTemperatureThreshold{ 100 }; /**< the temperature threshold to stop overriding in °C */

inline constexpr DeviceAddress sensorAddrs[]{ { 0x28, 0xE9, 0xD1, 0xB0, 0x1B, 0x13, 0x01, 0xCF } }; /**< list of temperature sensor Addresses */
inline constexpr TemperatureSensing temperatureSensing{ 0xff,
{ { 0x28, 0xE9, 0xD1, 0xB0, 0x1B, 0x13, 0x01, 0xCF } } }; /**< list of temperature sensor Addresses */

inline constexpr uint32_t ROTATION_AFTER_CYCLES{ 8UL * 3600UL * SUPPLY_FREQUENCY }; /**< rotates load priorities after this period of inactivity */

Expand Down
6 changes: 3 additions & 3 deletions Mk2_3phase_RFdatalog_temp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ void setup()

if constexpr (TEMP_SENSOR_PRESENT)
{
initTemperatureSensors();
temperatureSensing.initTemperatureSensors();
}

DBUG(F(">>free RAM = "));
Expand Down Expand Up @@ -415,7 +415,7 @@ void loop()
for (uint8_t idx = 0; idx < size(tx_data.temperature_x100); ++idx)
{
static int16_t tmp;
tmp = readTemperature(sensorAddrs[idx]);
tmp = temperatureSensing.readTemperature(idx);

// if read temperature is 85 and the delta with previous is greater than 5, skip the value
if (8500 == tmp && (abs(tmp - tx_data.temperature_x100[idx]) > 500))
Expand All @@ -425,7 +425,7 @@ void loop()

tx_data.temperature_x100[idx] = tmp;
}
requestTemperatures(); // for use next time around
temperatureSensing.requestTemperatures(); // for use next time around
}

sendResults(bOffPeak);
Expand Down
2 changes: 1 addition & 1 deletion Mk2_3phase_RFdatalog_temp/processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ inline volatile uint16_t copyOf_sampleSetsDuringThisDatalogPeriod; /**< copy of
inline volatile uint16_t copyOf_countLoadON[NO_OF_DUMPLOADS]; /**< copy of number of cycle the load was ON (over 1 datalog period) */

#ifdef TEMP_ENABLED
inline PayloadTx_struct< NO_OF_PHASES, size(sensorAddrs) > tx_data; /**< logging data */
inline PayloadTx_struct< NO_OF_PHASES, temperatureSensing.get_size() > tx_data; /**< logging data */
#else
inline PayloadTx_struct< NO_OF_PHASES > tx_data; /**< logging data */
#endif
Expand Down
5 changes: 4 additions & 1 deletion Mk2_3phase_RFdatalog_temp/type_traits/enable_if.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ template< typename T >
struct enable_if< true, T >
{
typedef T type;
};
};

template< bool B, class T = void >
using enable_if_t = typename enable_if< B, T >::type;
5 changes: 4 additions & 1 deletion Mk2_3phase_RFdatalog_temp/type_traits/is_same.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ struct is_same : false_type
template< typename T >
struct is_same< T, T > : true_type
{
};
};

template< class T, class U >
inline constexpr bool is_same_v = is_same< T, U >::value;
169 changes: 112 additions & 57 deletions Mk2_3phase_RFdatalog_temp/utils_temp.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @version 0.1
* @date 2023-02-09
*
* @copyright Copyright (c) 2023
* @copyright Copyright (c) 2024
*
*/

Expand All @@ -17,83 +17,138 @@
#include "constants.h"
#include "config.h"

using ScratchPad = uint8_t[9];
using DeviceAddress = uint8_t[8];

inline int16_t readTemperature(const DeviceAddress &deviceAddress);
inline void requestTemperatures();
inline void initTemperatureSensors();

#ifdef TEMP_ENABLED
#include <OneWire.h> // for temperature sensing

inline constexpr bool TEMP_SENSOR_PRESENT{ true };

inline OneWire oneWire(tempSensorPin); /**< For temperature sensing */
inline constexpr bool TEMP_SENSOR_PRESENT{ true }; /**< set it to 'true' if temperature sensing is needed */
#include <OneWire.h> // for temperature sensing
#else
inline constexpr bool TEMP_SENSOR_PRESENT{ false }; /**< set it to 'true' if temperature sensing is needed */
#endif

/**
* @brief Read temperature of a specific device
*
* @param deviceAddress The address of the device
* @return int16_t Temperature * 100
* @brief This class implements the temperature sensing feature
*
* @tparam N Number of sensors, automatically deduced
*/
int16_t readTemperature(const DeviceAddress &deviceAddress)
template< uint8_t N >
class TemperatureSensing
{
static ScratchPad buf;
using ScratchPad = uint8_t[9];

if (!oneWire.reset())
struct DeviceAddress
{
uint8_t addr[8];
};

public:
/**
* @brief Construct a new Temperature Sensing object
*
* @param pin Pin of the temperature sensor(s)
* @param ref The list of temperature sensor(s)
*/
constexpr TemperatureSensing(uint8_t pin, const DeviceAddress (&ref)[N])
: sensorPin{ pin }, sensorAddrs(ref)
{
return DEVICE_DISCONNECTED_RAW;
}
oneWire.select(deviceAddress);
oneWire.write(READ_SCRATCHPAD);

for (auto &buf_elem : buf)
/**
* @brief Request temperature for all sensors
*
*/
void requestTemperatures()
{
buf_elem = oneWire.read();
#ifdef TEMP_ENABLED
oneWire.reset();
oneWire.skip();
oneWire.write(CONVERT_TEMPERATURE);
#endif
}

if (!oneWire.reset())
/**
* @brief Initialize the Dallas sensors
*
*/
void initTemperatureSensors()
{
return DEVICE_DISCONNECTED_RAW;
#ifdef TEMP_ENABLED
oneWire.begin(sensorPin);
requestTemperatures();
#endif
}
if (oneWire.crc8(buf, 8) != buf[8])

/**
* @brief Get the number of sensors
*
* @return constexpr auto
*/
constexpr auto get_size() const
{
return DEVICE_DISCONNECTED_RAW;
return N;
}

// result is temperature x16, multiply by 6.25 to convert to temperature x100
int16_t result = (buf[1] << 8) | buf[0];
result = (result * 6) + (result >> 2);
if (result <= TEMP_RANGE_LOW || result >= TEMP_RANGE_HIGH)
/**
* @brief Get the pin of the sensor(s)
*
* @return constexpr auto
*/
constexpr auto get_pin() const
{
return OUTOFRANGE_TEMPERATURE; // return value ('Out of range')
return sensorPin;
}

return result;
}
/**
* @brief Read temperature of a specific device
*
* @param deviceAddress The address of the device
* @return int16_t Temperature * 100
*/
int16_t readTemperature(const uint8_t idx)
{
static ScratchPad buf;

/**
* @brief Request temperature for all sensors
*
*/
void requestTemperatures()
{
oneWire.reset();
oneWire.skip();
oneWire.write(CONVERT_TEMPERATURE);
}
#ifdef TEMP_ENABLED
if (!oneWire.reset())
{
return DEVICE_DISCONNECTED_RAW;
}
oneWire.select(sensorAddrs[idx].addr);
oneWire.write(READ_SCRATCHPAD);

for (auto &buf_elem : buf)
{
buf_elem = oneWire.read();
}

if (!oneWire.reset())
{
return DEVICE_DISCONNECTED_RAW;
}
if (oneWire.crc8(buf, 8) != buf[8])
{
return DEVICE_DISCONNECTED_RAW;
}

#endif

// result is temperature x16, multiply by 6.25 to convert to temperature x100
int16_t result = (buf[1] << 8) | buf[0];
result = (result * 6) + (result >> 2);
if (result <= TEMP_RANGE_LOW || result >= TEMP_RANGE_HIGH)
{
return OUTOFRANGE_TEMPERATURE; // return value ('Out of range')
}

return result;
}

/**
* @brief Initialize the Dallas sensors
*
*/
void initTemperatureSensors()
{
requestTemperatures();
}
#else
inline constexpr bool TEMP_SENSOR_PRESENT{ false };
#endif // TEMP_SENSOR_PRESENT
private:
const uint8_t sensorPin; /**< The pin of the sensor(s) */

const DeviceAddress sensorAddrs[N]; /**< Array of sensors */

#ifdef TEMP_ENABLED
static inline OneWire oneWire; /**< For temperature sensing */
#endif
};

#endif // _UTILS_TEMP_H
9 changes: 6 additions & 3 deletions Mk2_3phase_RFdatalog_temp/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

static_assert(DATALOG_PERIOD_IN_SECONDS <= 40, "**** Data log duration is too long and will lead to overflow ! ****");

static_assert(TEMP_SENSOR_PRESENT ^ (tempSensorPin == 0xff), "******** Wrong pin value for temperature sensor(s). Please check your config.h ! ********");
static_assert(TEMP_SENSOR_PRESENT ^ (temperatureSensing.get_pin() == 0xff), "******** Wrong pin value for temperature sensor(s). Please check your config.h ! ********");
static_assert(DIVERSION_PIN_PRESENT ^ (diversionPin == 0xff), "******** Wrong pin value for diversion command. Please check your config.h ! ********");
static_assert((PRIORITY_ROTATION == RotationModes::PIN) ^ (rotationPin == 0xff), "******** Wrong pin value for rotation command. Please check your config.h ! ********");
static_assert(OVERRIDE_PIN_PRESENT ^ (forcePin == 0xff), "******** Wrong pin value for override command. Please check your config.h ! ********");
Expand All @@ -49,8 +49,11 @@ check_pins()
{
uint16_t used_pins{ 0 };

if (tempSensorPin != 0xff)
bit_set(used_pins, tempSensorPin);
if constexpr (TEMP_SENSOR_PRESENT)
{
if (temperatureSensing.get_pin() != 0xff)
bit_set(used_pins, temperatureSensing.get_pin());
}

if (diversionPin != 0xff)
{
Expand Down
2 changes: 1 addition & 1 deletion Readme.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Pour l’instant, uniquement lecture. Il sera utilisé pour optimiser la pleine

Lorsque le profil zéro-export est activé, le système PV réduit la production d’énergie si la production du système dépasse les besoins de consommation du site. Cela garantit zéro injection dans le réseau.

Comme effet secondaire, le diverteur ne verra pas à aucun moment un surplus d’énergie.
Comme effet secondaire, le diverteur ne verra jamais, à aucun moment, un surplus d’énergie.
L’idée est donc d’appliquer un certain décalage à l’énergie mesurée par le diverteur.
Comme il est déjà commenté dans le code, après l'assignation d’une valeur négative à *REQUIRED_EXPORT_IN_WATTS*, le diverter agira comme un générateur PV.
Si vous définissez une valeur de *-20*, chaque fois que le diverter mesure le flux d’énergie, il ajoutera *-20* aux mesures.
Expand Down
8 changes: 4 additions & 4 deletions docs/Thermostat_tri_HC.drawio
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<mxfile host="app.diagrams.net" modified="2024-02-13T13:36:49.513Z" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0" etag="4HU_JDSqmKL5v_IIGpIX" version="23.1.4" type="github">
<mxfile host="Electron" modified="2024-02-14T04:30:20.028Z" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/23.0.2 Chrome/120.0.6099.109 Electron/28.1.0 Safari/537.36" etag="iVjm-mYdH-duEn0P2vt2" version="23.0.2" type="device">
<diagram name="Page-1" id="EFBq-0LIcU1qHeVKH0p9">
<mxGraphModel dx="965" dy="-620" grid="1" gridSize="5" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<mxGraphModel dx="2074" dy="35" grid="1" gridSize="5" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
Expand Down Expand Up @@ -72,7 +72,7 @@
<mxPoint x="16" y="-12" as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="KkkmOenbDuF3j0n2GC9D-23" value="" style="html=1;strokeWidth=4;fillColor=#0050ef;strokeColor=#cccccc;endArrow=none;endFill=0;" parent="1" edge="1">
<mxCell id="KkkmOenbDuF3j0n2GC9D-23" value="" style="html=1;strokeWidth=4;fillColor=#0050ef;strokeColor=#B3B3B3;endArrow=none;endFill=0;" parent="1" edge="1">
<mxGeometry x="-177.5" y="-534" width="100" as="geometry">
<mxPoint x="92.5" y="1360" as="sourcePoint" />
<mxPoint x="92.5" y="1392" as="targetPoint" />
Expand Down Expand Up @@ -391,7 +391,7 @@
<mxPoint x="16" y="-12" as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="Jmvh7IhSwtnf9PzCsuwB-12" value="" style="html=1;strokeWidth=4;fillColor=#0050ef;strokeColor=#cccccc;endArrow=none;endFill=0;" parent="1" edge="1">
<mxCell id="Jmvh7IhSwtnf9PzCsuwB-12" value="" style="html=1;strokeWidth=4;fillColor=#0050ef;strokeColor=#B3B3B3;endArrow=none;endFill=0;" parent="1" edge="1">
<mxGeometry x="-177.5" y="-534" width="100" as="geometry">
<mxPoint x="80" y="2531" as="sourcePoint" />
<mxPoint x="80" y="2563" as="targetPoint" />
Expand Down

0 comments on commit 769b79e

Please sign in to comment.