Skip to content

Commit 52dcc77

Browse files
committed
Refactor floating-point literals to use lowercase 'f' for consistency across multiple files
1 parent d5177e7 commit 52dcc77

15 files changed

Lines changed: 63 additions & 53 deletions

Mk2_fasterControl_Full/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ Vous pouvez commencer à lire la documentation ici [1-phase routeur](https://fre
100100
Les valeurs d'étalonnage se trouvent dans le fichier **calibration.h**.
101101
Il s'agit des lignes :
102102
```cpp
103-
inline constexpr float powerCal_grid{ 0.0435F };
104-
inline constexpr float powerCal_diverted{ 0.0435F };
103+
inline constexpr float powerCal_grid{ 0.0435f };
104+
inline constexpr float powerCal_diverted{ 0.0435f };
105105
```
106106
107107
Ces valeurs par défaut n'entrent pas en jeux dans le fonctionnement du routeur.

Mk2_fasterControl_Full/calibration.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
// powerCal is the RECIPROCAL of the power conversion rate. A good value
3232
// to start with is therefore 1/20 = 0.05 (Watts per ADC-step squared)
3333
//
34-
inline constexpr float powerCal_grid{ 0.0436F }; // for CT1
35-
inline constexpr float powerCal_diverted{ 0.04446F }; // for CT2
34+
inline constexpr float powerCal_grid{ 0.0436f }; // for CT1
35+
inline constexpr float powerCal_diverted{ 0.04446f }; // for CT2
3636

37-
inline constexpr float f_voltageCal{ 0.805653F }; /**< compared with Sentron PAC 4200 */
37+
inline constexpr float f_voltageCal{ 0.805653f }; /**< compared with Sentron PAC 4200 */
3838

3939
inline constexpr float lpf_gain{ 9 }; /**< setting this to 0 disables this extra processing */
4040
inline constexpr float alpha{ 0.0011 };

Mk2_fasterControl_Full/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,6 @@ inline constexpr int16_t iTemperatureThreshold{ 100 }; /**< the temperature thre
8989
inline constexpr TemperatureSensing temperatureSensing{ 0xff,
9090
{ { 0x28, 0x1B, 0xD7, 0x6A, 0x09, 0x00, 0x00, 0xB7 } } }; /**< list of temperature sensor Addresses */
9191

92-
inline constexpr uint16_t ROTATION_AFTER_SECONDS{ 8U * 3600U }; /**< rotates load priorities after this period of inactivity */
92+
inline constexpr uint16_t ROTATION_AFTER_SECONDS{ 8u * 3600u }; /**< rotates load priorities after this period of inactivity */
9393

9494
#endif /* CONFIG_H */

Mk2_fasterControl_Full/config_system.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ inline constexpr typename conditional< DATALOG_PERIOD_IN_SECONDS * SUPPLY_FREQUE
3939
DATALOG_PERIOD_IN_MAINS_CYCLES{ DATALOG_PERIOD_IN_SECONDS * SUPPLY_FREQUENCY }; /**< Period of datalogging in cycles */
4040

4141
// Computes inverse value at compile time to use '*' instead of '/'
42-
inline constexpr float invSUPPLY_FREQUENCY{ 1.0F / SUPPLY_FREQUENCY };
43-
inline constexpr float invDATALOG_PERIOD_IN_MAINS_CYCLES{ 1.0F / DATALOG_PERIOD_IN_MAINS_CYCLES };
42+
inline constexpr float invSUPPLY_FREQUENCY{ 1.0f / SUPPLY_FREQUENCY };
43+
inline constexpr float invDATALOG_PERIOD_IN_MAINS_CYCLES{ 1.0f / DATALOG_PERIOD_IN_MAINS_CYCLES };
4444

4545
inline constexpr uint16_t delayBeforeSerialStarts{ 1000 }; /**< in milli-seconds, to allow Serial window to be opened */
4646
inline constexpr uint16_t startUpPeriod{ 3000 }; /**< in milli-seconds, to allow LP filter to settle */

Mk2_fasterControl_Full/dualtariff.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ inline void printDualTariffConfiguration()
106106
Serial.println(F(" hour/minute(s)."));
107107
}
108108
Serial.print(F("\t\tCalculated offset in seconds: "));
109-
Serial.println(rg_OffsetForce[i][0] * 0.001F);
109+
Serial.println(rg_OffsetForce[i][0] * 0.001f);
110110
Serial.print(F("\t\tCalculated duration in seconds: "));
111-
Serial.println(rg_OffsetForce[i][1] * 0.001F);
111+
Serial.println(rg_OffsetForce[i][1] * 0.001f);
112112
}
113113
}
114114

Mk2_fasterControl_Full/ewma_avg.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
*/
4545
constexpr uint8_t round_up_to_power_of_2(uint16_t v)
4646
{
47-
if (__builtin_popcount(v) == 1) { return __builtin_ctz(v) - 1; }
47+
if (__builtin_popcount(v) == 1) { return static_cast<uint8_t>(__builtin_ctz(v) - 1u); }
4848

4949
uint8_t next_pow_of_2{ 0 };
5050

Mk2_fasterControl_Full/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,11 @@ void processCalculationsForLogging()
356356

357357
if constexpr (DATALOG_PERIOD_IN_SECONDS > 10)
358358
{
359-
tx_data.Vrms_L_x100 = static_cast< int32_t >((100 << 2) * f_voltageCal * sqrt(Shared::copyOf_sum_Vsquared / Shared::copyOf_sampleSetsDuringThisDatalogPeriod));
359+
tx_data.Vrms_L_x100 = static_cast< int32_t >((100 << 2) * f_voltageCal * sqrtf(Shared::copyOf_sum_Vsquared / Shared::copyOf_sampleSetsDuringThisDatalogPeriod));
360360
}
361361
else
362362
{
363-
tx_data.Vrms_L_x100 = static_cast< int32_t >(100 * f_voltageCal * sqrt(Shared::copyOf_sum_Vsquared / Shared::copyOf_sampleSetsDuringThisDatalogPeriod));
363+
tx_data.Vrms_L_x100 = static_cast< int32_t >(100 * f_voltageCal * sqrtf(Shared::copyOf_sum_Vsquared / Shared::copyOf_sampleSetsDuringThisDatalogPeriod));
364364
}
365365
}
366366

Mk2_fasterControl_Full/movingAvg.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class movingAvg
5050

5151
if constexpr (is_floating_point< T >::value)
5252
{
53-
_sum = 0.0F;
53+
_sum = 0.0f;
5454
}
5555
else
5656
{
@@ -62,7 +62,7 @@ class movingAvg
6262
--i;
6363
if constexpr (is_floating_point< T >::value)
6464
{
65-
_ar[i] = 0.0F;
65+
_ar[i] = 0.0f;
6666
}
6767
else
6868
{
@@ -135,7 +135,7 @@ class movingAvg
135135
if (idx >= DURATION_IN_MINUTES)
136136
{
137137
if constexpr (is_floating_point< T >::value)
138-
return 0.0F;
138+
return 0.0f;
139139
else
140140
return (T)0;
141141
}
@@ -154,15 +154,15 @@ class movingAvg
154154
_sub_idx = 0;
155155

156156
if constexpr (is_floating_point< T >::value)
157-
_sub_sum = 0.0F;
157+
_sub_sum = 0.0f;
158158
else
159159
_sub_sum = 0;
160160

161161
uint8_t i{ VALUES_PER_MINUTE };
162162
do {
163163
--i;
164164
if constexpr (is_floating_point< T >::value)
165-
_sub_ar[i] = 0.0F;
165+
_sub_ar[i] = 0.0f;
166166
else
167167
_sub_ar[i] = 0;
168168
} while (i);

Mk2_fasterControl_Full/platformio.ini

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ build_flags =
2020
build_unflags =
2121
-std=c++11
2222
-std=gnu++11
23+
build_src_flags =
24+
-Wall
25+
-Wextra
26+
-Wpedantic
27+
-Wshadow
28+
-Wdouble-promotion
29+
-Wformat=2
30+
-Wcast-align
2331
lib_deps =
2432
bblanchon/ArduinoJson @ ^6.*
2533
paulstoffregen/OneWire @ ^2.3.8
@@ -35,6 +43,8 @@ build_flags =
3543
${common.build_flags}
3644
build_unflags =
3745
${common.build_unflags}
46+
build_src_flags =
47+
${common.build_src_flags}
3848
lib_deps =
3949
${common.lib_deps}
4050

Mk2_fasterControl_Full/processing.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ constexpr int32_t DCoffset_V_max{ (512L + 100) * 256 }; /**< mid-point of ADC pl
3030

3131
constexpr int16_t DCoffset_I{ 512 }; /**< nominal mid-point value of ADC @ x1 scale */
3232

33-
constexpr int32_t capacityOfEnergyBucket_long{ static_cast< int32_t >(WORKING_ZONE_IN_JOULES * SUPPLY_FREQUENCY * (1.0F / powerCal_grid)) }; /**< main energy bucket for single-phase use, with units of Joules * SUPPLY_FREQUENCY */
33+
constexpr int32_t capacityOfEnergyBucket_long{ static_cast< int32_t >(WORKING_ZONE_IN_JOULES * SUPPLY_FREQUENCY * (1.0f / powerCal_grid)) }; /**< main energy bucket for single-phase use, with units of Joules * SUPPLY_FREQUENCY */
3434

3535
constexpr int32_t midPointOfEnergyBucket_long{ capacityOfEnergyBucket_long >> 1 }; /**< for resetting flexible thresholds */
3636

3737
constexpr int32_t lowerThreshold_default{ midPointOfEnergyBucket_long }; /**< default lower threshold for the energy bucket (50% of capacity) */
3838
constexpr int32_t upperThreshold_default{ midPointOfEnergyBucket_long }; /**< default upper threshold for the energy bucket (50% of capacity) */
3939

40-
constexpr int32_t antiCreepLimit_inIEUperMainsCycle{ static_cast< int32_t >(ANTI_CREEP_LIMIT * (1.0F / powerCal_diverted)) }; /**< threshold value in Integer Energy Units (IEU) that prevents small measurement noise from being incorrectly registered as diverted energy */
41-
constexpr int32_t requiredExportPerMainsCycle_inIEU{ static_cast< int32_t >(REQUIRED_EXPORT_IN_WATTS * (1.0F / powerCal_grid)) }; /**< target amount of energy to be exported to the grid during each mains cycle, expressed in Integer Energy Units (IEU) */
40+
constexpr int32_t antiCreepLimit_inIEUperMainsCycle{ static_cast< int32_t >(ANTI_CREEP_LIMIT * (1.0f / powerCal_diverted)) }; /**< threshold value in Integer Energy Units (IEU) that prevents small measurement noise from being incorrectly registered as diverted energy */
41+
constexpr int32_t requiredExportPerMainsCycle_inIEU{ static_cast< int32_t >(REQUIRED_EXPORT_IN_WATTS * (1.0f / powerCal_grid)) }; /**< target amount of energy to be exported to the grid during each mains cycle, expressed in Integer Energy Units (IEU) */
4242
// When using integer maths, calibration values that have supplied in floating point
4343
// form need to be rescaled.
4444

@@ -67,7 +67,7 @@ uint16_t divertedEnergyTotal_Wh{ 0 }; /**< WattHour register of 63K range */
6767
// accumulator's value is decremented accordingly. The calculation below is to determine
6868
// the scaling for this accumulator.
6969

70-
constexpr int32_t IEU_per_Wh_diverted{ static_cast< int32_t >(JOULES_PER_WATT_HOUR * SUPPLY_FREQUENCY * (1.0F / powerCal_diverted)) }; // depends on powerCal, frequency & the 'sweetzone' size.
70+
constexpr int32_t IEU_per_Wh_diverted{ static_cast< int32_t >(JOULES_PER_WATT_HOUR * SUPPLY_FREQUENCY * (1.0f / powerCal_diverted)) }; // depends on powerCal, frequency & the 'sweetzone' size.
7171

7272
bool recentTransition{ false }; /**< a load state has been recently toggled */
7373
uint8_t postTransitionCount{ 0 }; /**< counts the number of cycle since last transition */

0 commit comments

Comments
 (0)