@@ -59,6 +59,13 @@ class WipperSnapper_I2C_Driver_SGP30 : public WipperSnapper_I2C_Driver {
59
59
return true ;
60
60
}
61
61
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
+ /* ******************************************************************************/
62
69
bool getEventECO2 (sensors_event_t *senseEvent) override {
63
70
if (!_sgp30)
64
71
return false ;
@@ -68,6 +75,13 @@ class WipperSnapper_I2C_Driver_SGP30 : public WipperSnapper_I2C_Driver {
68
75
return ok;
69
76
}
70
77
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
+ /* ******************************************************************************/
71
85
bool getEventTVOC (sensors_event_t *senseEvent) override {
72
86
if (!_sgp30)
73
87
return false ;
@@ -77,6 +91,13 @@ class WipperSnapper_I2C_Driver_SGP30 : public WipperSnapper_I2C_Driver {
77
91
return ok;
78
92
}
79
93
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
+ /* ******************************************************************************/
80
101
void fastTick () override {
81
102
if (!iaqEnabled ())
82
103
return ; // nothing enabled, save cycles
@@ -95,15 +116,21 @@ class WipperSnapper_I2C_Driver_SGP30 : public WipperSnapper_I2C_Driver {
95
116
Adafruit_SGP30 *_sgp30; // /< Pointer to SGP30 sensor object
96
117
97
118
// 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.
102
123
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
+ /* ******************************************************************************/
103
130
inline bool iaqEnabled () {
104
131
// Enable IAQ background reads if either metric is requested
105
132
return (getSensorECO2Period () > 0 ) || (getSensorTVOCPeriod () > 0 );
106
133
}
107
134
};
108
135
109
- #endif // WipperSnapper_I2C_Driver_SGP30
136
+ #endif // WipperSnapper_I2C_Driver_SGP30_H
0 commit comments