Initialize m_time_start, add m_size increment
authorLukáš Jiřiště <jiriste@icpf.cas.cz>
Tue, 12 Nov 2024 10:58:43 +0000 (11:58 +0100)
committerLukáš Jiřiště <jiriste@icpf.cas.cz>
Tue, 12 Nov 2024 10:58:43 +0000 (11:58 +0100)
The m_time_start should be initialized, so that the time measurement
does not overflow sooner then 49 days after the start. Additionally the
m_time_start is reset in clear() method for the same reason.

The m_size was not adjusted upon creating a new measurement. This means
that no measurement but the last is was saved. This is now fixed.

Measurement.ino

index b882ade16d0565afb792eb4e61ab1f1c00a1832d..082a45acea099eba3ee9d86ae36352bec1f6867b 100644 (file)
@@ -4,6 +4,7 @@ Measurement::Measurement(const PressureSensor &sensor)
        : m_size{0}
        , m_sensor{sensor}
        , m_interval_ms{START_INTERVAL_MS}
+       , m_start_time{millis()}
 {
 }
 
@@ -17,6 +18,7 @@ void  Measurement::get_measurement()
                thin_out();
        m_pressure[m_size] = m_sensor.get_pressure();
        m_time[m_size] = millis() - m_start_time;
+       ++m_size;
 }
 
 void   Measurement::thin_out()
@@ -33,6 +35,7 @@ void  Measurement::thin_out()
 void   Measurement::clear()
 {
        m_size = 0;
+       m_start_time = millis();
 }
 
 // The function calls get_measurement repeatedly. It uses these measurements to