Skip to content

Commit 773d2d3

Browse files
committed
Reintroduce averaging made of double values. Use and fix usage of strcmp_P and snprintf_P. Update doc. Release.
1 parent bd376e2 commit 773d2d3

File tree

81 files changed

+464
-240
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+464
-240
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
aWXIron.layout
12
doxygen/latex/*
23
bin/*
34
*.save

aDSEngine.cpp

Lines changed: 145 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,136 @@ static int8_t getNumericalLength(int16_t n)
350350
{
351351
char buf[16];
352352

353-
return (static_cast<int8_t>(snprintf(buf, sizeof(buf) - 1, "%d", n)));
353+
return (static_cast<int8_t>(snprintf_P(buf, sizeof(buf) - 1, PSTR("%d"), n)));
354354
}
355355

356356
//
357357
// Begin of Class aDSTemperatureAveraging
358358
//
359+
#ifdef DOUBLE_AVERAGE
360+
/// \brief ValueAveraging class constructor
361+
///
362+
///
363+
ValueAveraging::ValueAveraging() :
364+
m_average(ARRAY_SIZE_MAX)
365+
{
366+
// ctor
367+
ResetValues();
368+
}
369+
370+
/// \brief ValueAveraging class destructor
371+
///
372+
///
373+
ValueAveraging::~ValueAveraging()
374+
{
375+
// dtor
376+
}
377+
378+
/// \brief Stacks the value to an array, used to compute an averaged value
379+
///
380+
/// \param value int16_t : value to stack
381+
/// \return void
382+
///
383+
///
384+
template<typename T>
385+
void ValueAveraging::StackValue(T value)
386+
{
387+
if (value > 0)
388+
{
389+
m_offset = (m_offset + 1) % m_average;
390+
391+
m_values[m_offset] = static_cast<double>(value);
392+
}
393+
}
394+
395+
/// \brief Returns the averaged value, computed from stacked values
396+
///
397+
/// \return int16_t : averaged value
398+
///
399+
///
400+
template<typename T>
401+
T ValueAveraging::GetValue()
402+
{
403+
uint16_t n = 0;
404+
double sum = 0.0;
405+
406+
for (uint16_t i = 0; i < m_average; i++)
407+
{
408+
if (isnan(m_values[i]))
409+
break;
410+
411+
if (m_values[i] > 0)
412+
{
413+
sum += m_values[i];
414+
n++;
415+
}
416+
}
417+
418+
// No usable value found.
419+
if (n == 0)
420+
return 0;
421+
422+
return static_cast<T>((sum / double(n)) + 0.5); // ceil
423+
}
424+
425+
426+
/// \brief Set how many values will be used to compute the average
427+
///
428+
/// \param v uint16_t : values used for averaging
429+
/// \return bool : true on success
430+
///
431+
///
432+
bool ValueAveraging::SetAverage(uint16_t v)
433+
{
434+
bool ret = false;
435+
436+
if ((v >= 0) && (v <= ARRAY_SIZE_MAX))
437+
{
438+
// Zeroing the array
439+
ResetValues();
440+
441+
m_average = v;
442+
443+
ret = true;
444+
}
445+
446+
return ret;
447+
}
448+
449+
/// \brief Get how many values will be used to compute the average
450+
///
451+
/// \return uint16_t : values used for averaging
452+
///
453+
///
454+
uint16_t ValueAveraging::GetAverage()
455+
{
456+
return m_average;
457+
}
458+
459+
/// \brief Get max value that can be used to build the average
460+
///
461+
/// \return uint16_t : max values used for averaging
462+
///
463+
///
464+
uint16_t ValueAveraging::GetMaxAverage()
465+
{
466+
return ARRAY_SIZE_MAX;
467+
}
468+
469+
/// \brief Reset the array used to store values to be averaged
470+
///
471+
/// \return void
472+
///
473+
///
474+
void ValueAveraging::ResetValues()
475+
{
476+
477+
for (uint16_t i = 0; i < ARRAY_SIZE_MAX; i++)
478+
m_values[i] = NAN;
479+
480+
m_offset = ARRAY_SIZE_MAX - 1;
481+
}
482+
#else
359483
/// \brief ValueAveraging class constructor
360484
///
361485
///
@@ -476,6 +600,7 @@ void ValueAveraging::ResetValues()
476600

477601
m_offset = ARRAY_SIZE_MAX - 1;
478602
}
603+
#endif
479604
//
480605
// End of Class ValueAveraging
481606
//
@@ -604,7 +729,16 @@ bool aDSChannel::hasFocus()
604729
///
605730
uint16_t aDSChannel::getTemperature(OperationMode_t mode)
606731
{
607-
return (mode == OPERATION_MODE_READ) ? m_avrTemp.GetValue() : m_targetTemp;
732+
return (mode == OPERATION_MODE_READ) ?
733+
734+
#ifdef DOUBLE_AVERAGE
735+
m_avrTemp.GetValue<int16_t>()
736+
#else
737+
m_avrTemp.GetValue()
738+
#endif // DOUBLE_AVERAGE
739+
740+
741+
: m_targetTemp;
608742
}
609743

610744
/// \brief Set current temperature accordingly from the given mode (SET/READ)
@@ -1255,7 +1389,7 @@ void aDSChannels::_showBanner()
12551389
//
12561390
// Reflect Dual or Single running version
12571391
//
1258-
snprintf_P(buf, sizeof(buf), PSTR("%s %s"), PSTR("aWXIrons"), (IS_DATA_ENABLED(DATA_CHANNEL2_ENABLED) ? PSTR("Dual") : PSTR("Single")));
1392+
snprintf_P(buf, sizeof(buf), PSTR("%s %s"), "aWXIrons", (IS_DATA_ENABLED(DATA_CHANNEL2_ENABLED) ? "Dual" : "Single"));
12591393
m_lcd.setCursor((LCD_COLS - strlen(buf)) / 2, 0);
12601394
m_lcd.print(buf);
12611395

@@ -1275,14 +1409,14 @@ void aDSChannels::_showBanner()
12751409
//
12761410
// FOSS - FOSH licenses
12771411
//
1278-
snprintf_P(buf, sizeof(buf), PSTR("%s"), PSTR("FOSS - FOSH"));
1412+
snprintf_P(buf, sizeof(buf), PSTR("%s"), "FOSS - FOSH");
12791413
m_lcd.setCursor((LCD_COLS - strlen(buf)) / 2, 0);
12801414
m_lcd.print(buf);
12811415

12821416
//
12831417
// Author
12841418
//
1285-
snprintf_P(buf, sizeof(buf), PSTR("%s 2015-%d"), PSTR("F1RMB"), PROGRAM_YEAR);
1419+
snprintf_P(buf, sizeof(buf), PSTR("%s 2015-%d"), "F1RMB", PROGRAM_YEAR);
12861420
m_lcd.setCursor((LCD_COLS - strlen(buf)) / 2, 1);
12871421
m_lcd.print(buf);
12881422

@@ -2590,22 +2724,22 @@ void aDSEngine::_handleSerialInput()
25902724

25912725
Serial.print(':');
25922726

2593-
if (!strcmp_P((const char *)cmd, PSTR("CAL"))) // Calibration
2727+
if (strcmp_P((const char *)cmd, PSTR("CAL")) == 0) // Calibration
25942728
{
25952729
valid = true;
25962730

2597-
if (!strcmp((const char *)arg, "OFF")) // Off : no calibation value stored into EEPROM
2731+
if (strcmp_P((const char *)arg, PSTR("OFF")) == 0) // Off : no calibation value stored into EEPROM
25982732
{
25992733
m_channels.setCalibrationMode(false);
26002734
m_channels.restoreCalibationValues();
26012735
}
2602-
else if (!strcmp_P((const char *)arg, PSTR("SAVE"))) // Store calibation value into EEPROM, then leave calibration mode
2736+
else if (strcmp_P((const char *)arg, PSTR("SAVE")) == 0) // Store calibation value into EEPROM, then leave calibration mode
26032737
{
26042738
m_channels.setCalibrationMode(false);
26052739
m_channels.saveCalibrationValues(aDSChannels::CHANNEL_ONE);
26062740
m_channels.saveCalibrationValues(aDSChannels::CHANNEL_TWO);
26072741
}
2608-
else if (!strcmp((const char *)arg, PSTR("DUMP"))) // Dump calibration values
2742+
else if (strcmp_P((const char *)arg, PSTR("DUMP")) == 0) // Dump calibration values
26092743
{
26102744
aDSChannel::CalibrationData_t cal;
26112745
aDSChannel chans[aDSChannels::CHANNEL_MAX];
@@ -2661,9 +2795,9 @@ void aDSEngine::_handleSerialInput()
26612795
cal.slope = atof((char *)pV1);
26622796
cal.offset = atof((char *)pV2);
26632797

2664-
if (!strcmp_P((const char *)cmd2, PSTR("1")))
2798+
if (strcmp_P((const char *)cmd2, PSTR("1")) == 0)
26652799
m_channels.setCalibrationValues(aDSChannels::CHANNEL_ONE, cal);
2666-
else if (!strcmp_P((const char *)cmd2, PSTR("2")))
2800+
else if (strcmp_P((const char *)cmd2, PSTR("2")) == 0)
26672801
m_channels.setCalibrationValues(aDSChannels::CHANNEL_TWO, cal);
26682802
else
26692803
valid = false;

aDSEngine.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
//#define SIMU 1 ///< Define this to run in simulation mode (temperature will raise/lower automatically, !! DO NOT PLUG ANY IRON TIP !!)
3333
//#define CHANNEL_COUNTING 1 ///< Define this to trace channel counting, debug purpose
3434
//#define LCD_CHANNELS_LEDS 1 ///< Define this if you want channels LEDs displayed on the LCD
35+
#define DOUBLE_AVERAGE 1 ///< Define this if you want to use averaging based on double values (more SRAM used)
3536

3637
static const uint8_t CHANNEL2_ENABLE_PIN = 13; ///< Pin to check from if channel 2 is wired
3738

@@ -78,6 +79,31 @@ typedef enum
7879

7980
/// \brief ValueAveraging class
8081
///
82+
#ifdef DOUBLE_AVERAGE
83+
class ValueAveraging
84+
{
85+
protected:
86+
static const uint16_t ARRAY_SIZE_MAX = 10; ///< Averaging is performed using n values
87+
88+
public:
89+
ValueAveraging();
90+
~ValueAveraging();
91+
92+
template<typename T>
93+
void StackValue(T value);
94+
template<typename T>
95+
T GetValue();
96+
bool SetAverage(uint16_t v);
97+
uint16_t GetAverage();
98+
uint16_t GetMaxAverage();
99+
void ResetValues();
100+
101+
private:
102+
double m_values[ARRAY_SIZE_MAX]; ///< values array storage
103+
uint16_t m_offset; ///< offset in m_values[]
104+
uint16_t m_average; ///< max values used from m_values[] to build average value
105+
};
106+
#else
81107
class ValueAveraging
82108
{
83109
protected:
@@ -99,6 +125,7 @@ class ValueAveraging
99125
uint16_t m_offset; ///< offset in m_values[]
100126
uint16_t m_average; ///< max values used from m_values[] to build average value
101127
};
128+
#endif
102129

103130
/// \brief aDSChannel class
104131
///

aWXIron.depend

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -930,14 +930,14 @@
930930
<LiquidCrystal.h>
931931
"aDSEngine.h"
932932

933-
1485697927 /home/daniel/src/Arduino/aWXIrons/aDSEngine.h
933+
1485758280 /home/daniel/src/Arduino/aWXIrons/aDSEngine.h
934934
<Arduino.h>
935935
<LiquidCrystal.h>
936936
<EEPROM.h>
937937
"TimerOne.h"
938938
"ClickEncoder.h"
939939

940-
1485697802 source:/home/daniel/src/Arduino/aWXIrons/aDSEngine.cpp
940+
1485756079 source:/home/daniel/src/Arduino/aWXIrons/aDSEngine.cpp
941941
"aDSEngine.h"
942942
<wiring_private.h>
943943

doc/aWXIronsCalibration.ods

-7.74 KB
Binary file not shown.

doxygen/html/UI.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ <h1><a class="anchor" id="standby"></a>
221221
<!-- start footer part -->
222222
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
223223
<ul>
224-
<li class="footer">Generated on Sun Jan 29 2017 14:53:10 for aWXIron by
224+
<li class="footer">Generated on Mon Jan 30 2017 07:42:28 for aWXIron by
225225
<a href="http://www.doxygen.org/index.html">
226226
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
227227
</ul>

doxygen/html/_c_d_c_8cpp.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
116116
<ul>
117117
<li class="navelem"><a class="el" href="dir_51d9c9f08f6806a0f97badf342e5b4d7.html">cores</a></li><li class="navelem"><a class="el" href="_c_d_c_8cpp.html">CDC.cpp</a></li>
118-
<li class="footer">Generated on Sun Jan 29 2017 14:53:10 for aWXIron by
118+
<li class="footer">Generated on Mon Jan 30 2017 07:42:28 for aWXIron by
119119
<a href="http://www.doxygen.org/index.html">
120120
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
121121
</ul>

doxygen/html/_h_i_d_8cpp.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
116116
<ul>
117117
<li class="navelem"><a class="el" href="dir_51d9c9f08f6806a0f97badf342e5b4d7.html">cores</a></li><li class="navelem"><a class="el" href="_h_i_d_8cpp.html">HID.cpp</a></li>
118-
<li class="footer">Generated on Sun Jan 29 2017 14:53:10 for aWXIron by
118+
<li class="footer">Generated on Mon Jan 30 2017 07:42:28 for aWXIron by
119119
<a href="http://www.doxygen.org/index.html">
120120
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
121121
</ul>

doxygen/html/_hardware_serial_8cpp.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
116116
<ul>
117117
<li class="navelem"><a class="el" href="dir_51d9c9f08f6806a0f97badf342e5b4d7.html">cores</a></li><li class="navelem"><a class="el" href="_hardware_serial_8cpp.html">HardwareSerial.cpp</a></li>
118-
<li class="footer">Generated on Sun Jan 29 2017 14:53:10 for aWXIron by
118+
<li class="footer">Generated on Mon Jan 30 2017 07:42:28 for aWXIron by
119119
<a href="http://www.doxygen.org/index.html">
120120
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
121121
</ul>

doxygen/html/_i_p_address_8cpp.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
116116
<ul>
117117
<li class="navelem"><a class="el" href="dir_51d9c9f08f6806a0f97badf342e5b4d7.html">cores</a></li><li class="navelem"><a class="el" href="_i_p_address_8cpp.html">IPAddress.cpp</a></li>
118-
<li class="footer">Generated on Sun Jan 29 2017 14:53:10 for aWXIron by
118+
<li class="footer">Generated on Mon Jan 30 2017 07:42:28 for aWXIron by
119119
<a href="http://www.doxygen.org/index.html">
120120
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
121121
</ul>

0 commit comments

Comments
 (0)