@@ -237,8 +237,8 @@ void SensorMesh::sendAlert(const char* text) {
237237 }
238238}
239239
240- void SensorMesh::alertIfLow (Trigger& t, float value, float threshold , const char * text) {
241- if (value < threshold ) {
240+ void SensorMesh::alertIf ( bool condition, Trigger& t , const char * text) {
241+ if (condition ) {
242242 if (!t.triggered ) {
243243 t.triggered = true ;
244244 t.time = getRTCClock ()->getCurrentTime ();
@@ -252,65 +252,6 @@ void SensorMesh::alertIfLow(Trigger& t, float value, float threshold, const char
252252 }
253253}
254254
255- void SensorMesh::alertIfHigh (Trigger& t, float value, float threshold, const char * text) {
256- if (value > threshold) {
257- if (!t.triggered ) {
258- t.triggered = true ;
259- t.time = getRTCClock ()->getCurrentTime ();
260- sendAlert (text);
261- }
262- } else {
263- if (t.triggered ) {
264- t.triggered = false ;
265- // TODO: apply debounce logic
266- }
267- }
268- }
269-
270- void SensorMesh::recordData (TimeSeriesData& data, float value) {
271- uint32_t now = getRTCClock ()->getCurrentTime ();
272- if (now >= data.last_timestamp + data.interval_secs ) {
273- data.last_timestamp = now;
274-
275- data.data [data.next ] = value; // append to cycle table
276- data.next = (data.next + 1 ) % data.num_slots ;
277- }
278- }
279-
280- void SensorMesh::calcDataMinMaxAvg (const TimeSeriesData& data, uint32_t start_secs_ago, uint32_t end_secs_ago, MinMaxAvg* dest, uint8_t channel, uint8_t lpp_type) {
281- int i = data.next , n = data.num_slots ;
282- uint32_t ago = data.interval_secs * data.num_slots ;
283- int num_values = 0 ;
284- float total = 0 .0f ;
285-
286- dest->_channel = channel;
287- dest->_lpp_type = lpp_type;
288-
289- // start at earliest recording, through to most recent
290- while (n > 0 ) {
291- n--;
292- i = (i + 1 ) % data.num_slots ;
293- if (ago >= end_secs_ago && ago < start_secs_ago) {
294- float v = data.data [i];
295- num_values++;
296- total += v;
297- if (num_values == 1 ) {
298- dest->_max = dest->_min = v;
299- } else {
300- if (v < dest->_min ) dest->_min = v;
301- if (v > dest->_max ) dest->_max = v;
302- }
303- }
304- ago -= data.interval_secs ;
305- }
306- // calc average
307- if (num_values > 0 ) {
308- dest->_avg = total / num_values;
309- } else {
310- dest->_avg = NAN;
311- }
312- }
313-
314255float SensorMesh::getAirtimeBudgetFactor () const {
315256 return _prefs.airtime_factor ;
316257}
0 commit comments