@@ -59,6 +59,13 @@ class WipperSnapper_I2C_Driver_SGP30 : public WipperSnapper_I2C_Driver {
5959 return true ;
6060 }
6161
62+ /* ******************************************************************************/
63+ /* !
64+ @brief Reads the current eCO2 value (ppm).
65+ @param senseEvent Pointer to event to fill.
66+ @returns True if a value was obtained, False otherwise.
67+ */
68+ /* ******************************************************************************/
6269 bool getEventECO2 (sensors_event_t *senseEvent) override {
6370 if (!_sgp30)
6471 return false ;
@@ -68,6 +75,13 @@ class WipperSnapper_I2C_Driver_SGP30 : public WipperSnapper_I2C_Driver {
6875 return ok;
6976 }
7077
78+ /* ******************************************************************************/
79+ /* !
80+ @brief Reads the current TVOC value (ppb).
81+ @param senseEvent Pointer to event to fill.
82+ @returns True if a value was obtained, False otherwise.
83+ */
84+ /* ******************************************************************************/
7185 bool getEventTVOC (sensors_event_t *senseEvent) override {
7286 if (!_sgp30)
7387 return false ;
@@ -77,6 +91,13 @@ class WipperSnapper_I2C_Driver_SGP30 : public WipperSnapper_I2C_Driver {
7791 return ok;
7892 }
7993
94+ /* ******************************************************************************/
95+ /* !
96+ @brief Background sampler to maintain ~1 Hz IAQ reads and accumulate
97+ samples for later averaging at publish time.
98+ @note Must be non-blocking; invoked once per update loop.
99+ */
100+ /* ******************************************************************************/
80101 void fastTick () override {
81102 if (!iaqEnabled ())
82103 return ; // nothing enabled, save cycles
@@ -95,15 +116,21 @@ class WipperSnapper_I2C_Driver_SGP30 : public WipperSnapper_I2C_Driver {
95116 Adafruit_SGP30 *_sgp30; // /< Pointer to SGP30 sensor object
96117
97118 // Fast sampling state
98- uint32_t _lastFastMs = 0 ;
99- uint32_t _n = 0 ;
100- uint32_t _eco2Sum = 0 ;
101- uint32_t _tvocSum = 0 ;
119+ uint32_t _lastFastMs = 0 ; // /< Last millisecond timestamp of a fastTick sample.
120+ uint32_t _n = 0 ; // /< Number of accumulated background samples.
121+ uint32_t _eco2Sum = 0 ; // /< Sum of eCO2 samples for averaging.
122+ uint32_t _tvocSum = 0 ; // /< Sum of TVOC samples for averaging.
102123
124+ /* ******************************************************************************/
125+ /* !
126+ @brief Indicates whether IAQ background sampling should run.
127+ @returns True if either eCO2 or TVOC periods are enabled; otherwise false.
128+ */
129+ /* ******************************************************************************/
103130 inline bool iaqEnabled () {
104131 // Enable IAQ background reads if either metric is requested
105132 return (getSensorECO2Period () > 0 ) || (getSensorTVOCPeriod () > 0 );
106133 }
107134};
108135
109- #endif // WipperSnapper_I2C_Driver_SGP30
136+ #endif // WipperSnapper_I2C_Driver_SGP30_H
0 commit comments