50
50
#if defined (MYBOARDNRF5)
51
51
#define CHIP_NRF5
52
52
#endif
53
-
54
53
#if !defined(CHIP_ESP8266) && !defined(CHIP_STM32) && !defined(CHIP_NRF5)
55
54
#define CHIP_AVR
56
55
#endif
@@ -449,48 +448,64 @@ class Child {
449
448
public:
450
449
Child ();
451
450
Child (Sensor* sensor, int child_id, int presentation, int type, const char * description = " " );
452
- // child id used to communicate with the gateway/controller
453
- int child_id ;
454
- // Sensor presentation (default: S_CUSTOM)
455
- int presentation = S_CUSTOM;
456
- // Sensor type (default: V_CUSTOM)
457
- int type = V_CUSTOM ;
458
- // how many decimal digits to use (default: 2 for ChildFloat, 4 for ChildDouble )
459
- int float_precision ;
460
- // Sensor description
461
- const char * description = " " ;
462
- // send the current value to the gateway
463
- virtual void sendValue ();
464
- // print the current value on a LCD display
465
- virtual void printOn (Print& p );
451
+ // set child id used to communicate with the gateway/controller
452
+ void setChildId ( int value) ;
453
+ int getChildId ();
454
+ // set sensor presentation (default: S_CUSTOM)
455
+ void setPresentation ( int value);
456
+ int getPresentation () ;
457
+ // set sensor type (default: V_CUSTOM )
458
+ void setType ( int value) ;
459
+ int getType ();
460
+ // set how many decimal digits to use (default: 2 for ChildFloat, 4 for ChildDouble)
461
+ void setFloatPrecision ( int value);
462
+ // set sensor description
463
+ void setDescription ( const char * value);
464
+ const char * getDescription ( );
466
465
#if FEATURE_CONDITIONAL_REPORT == ON
467
- Timer* force_update_timer;
468
- // return true if the current value is new/different compared to the previous one
469
- virtual bool isNewValue ();
470
- // minimum threshold for reporting the value to the controller
471
- float min_threshold = FLT_MIN;
472
- // maximum threshold for reporting the value to the controller
473
- float max_threshold = FLT_MAX;
466
+ // force to send an update after the configured number of minutes
467
+ void setForceUpdateMinutes (int value);
468
+ // never report values below this threshold (default: FLT_MIN)
469
+ void setMinThreshold (float value);
470
+ // never report values above this threshold (default: FLT_MAX)
471
+ void setMaxThreshold (float value);
472
+ // do not report values if too close to the previous one (default: 0)
473
+ void setValueDelta (float value);
474
474
#endif
475
+ // send the current value to the gateway
476
+ virtual void sendValue (bool force);
477
+ // print the current value on a LCD display
478
+ virtual void print (Print& device);
479
+ // reset all the counters
480
+ virtual void reset ();
475
481
protected:
476
482
int _samples = 0 ;
477
483
Sensor* _sensor;
484
+ int _child_id;
485
+ int _presentation = S_CUSTOM;
486
+ int _type = V_CUSTOM;
487
+ int _float_precision;
488
+ const char * _description = " " ;
489
+ #if FEATURE_CONDITIONAL_REPORT == ON
490
+ Timer* _force_update_timer;
491
+ float _min_threshold = FLT_MIN;
492
+ float _max_threshold = FLT_MAX;
493
+ float _value_delta = 0 ;
494
+ #endif
478
495
};
479
496
480
497
class ChildInt : public Child {
481
498
public:
482
499
ChildInt (Sensor* sensor, int child_id, int presentation, int type, const char * description = " " );
483
500
void setValueInt (int value);
484
501
int getValueInt ();
485
- void sendValue ();
486
- void printOn (Print& p);
487
- #if FEATURE_CONDITIONAL_REPORT == ON
488
- bool isNewValue ();
489
- #endif
502
+ void sendValue (bool force);
503
+ void print (Print& device);
504
+ void reset ();
490
505
private:
491
506
int _value;
492
507
#if FEATURE_CONDITIONAL_REPORT == ON
493
- int _last_value;
508
+ int _last_value = - 256 ;
494
509
#endif
495
510
int _total = 0 ;
496
511
};
@@ -500,15 +515,13 @@ class ChildFloat: public Child {
500
515
ChildFloat (Sensor* sensor, int child_id, int presentation, int type, const char * description = " " );
501
516
void setValueFloat (float value);
502
517
float getValueFloat ();
503
- void sendValue ();
504
- void printOn (Print& p);
505
- #if FEATURE_CONDITIONAL_REPORT == ON
506
- bool isNewValue ();
507
- #endif
518
+ void sendValue (bool force);
519
+ void print (Print& device);
520
+ void reset ();
508
521
private:
509
522
float _value;
510
523
#if FEATURE_CONDITIONAL_REPORT == ON
511
- float _last_value;
524
+ float _last_value = - 256 ;
512
525
#endif
513
526
float _total = 0 ;
514
527
};
@@ -518,15 +531,13 @@ class ChildDouble: public Child {
518
531
ChildDouble (Sensor* sensor, int child_id, int presentation, int type, const char * description = " " );
519
532
void setValueDouble (double value);
520
533
double getValueDouble ();
521
- void sendValue ();
522
- void printOn (Print& p);
523
- #if FEATURE_CONDITIONAL_REPORT == ON
524
- bool isNewValue ();
525
- #endif
534
+ void sendValue (bool force);
535
+ void print (Print& device);
536
+ void reset ();
526
537
private:
527
538
double _value;
528
539
#if FEATURE_CONDITIONAL_REPORT == ON
529
- double _last_value;
540
+ double _last_value = - 256 ;
530
541
#endif
531
542
double _total = 0 ;
532
543
};
@@ -536,11 +547,9 @@ class ChildString: public Child {
536
547
ChildString (Sensor* sensor, int child_id, int presentation, int type, const char * description = " " );
537
548
void setValueString (const char * value);
538
549
const char * getValueString ();
539
- void sendValue ();
540
- void printOn (Print& p);
541
- #if FEATURE_CONDITIONAL_REPORT == ON
542
- bool isNewValue ();
543
- #endif
550
+ void sendValue (bool force);
551
+ void print (Print& device);
552
+ void reset ();
544
553
private:
545
554
const char * _value = " " ;
546
555
#if FEATURE_CONDITIONAL_REPORT == ON
@@ -565,12 +574,6 @@ class Sensor {
565
574
void setSamples (int value);
566
575
// [6] If more then one sample has to be taken, set the interval in milliseconds between measurements (default: 0)
567
576
void setSamplesInterval (int value);
568
- #if FEATURE_CONDITIONAL_REPORT == ON
569
- // [7] if true will report the measure only if different than the previous one (default: false)
570
- void setTrackLastValue (bool value);
571
- // [9] if track last value is enabled, force to send an update after the configured number of minutes
572
- void setForceUpdateMinutes (int value);
573
- #endif
574
577
#if FEATURE_POWER_MANAGER == ON
575
578
// to save battery the sensor can be optionally connected to two pins which will act as vcc and ground and activated on demand
576
579
void setPowerPins (int ground_pin, int vcc_pin, int wait_time = 50 );
@@ -639,9 +642,6 @@ class Sensor {
639
642
int _pin = -1 ;
640
643
int _samples = 1 ;
641
644
int _samples_interval = 0 ;
642
- #if FEATURE_CONDITIONAL_REPORT == ON
643
- bool _track_last_value = false ;
644
- #endif
645
645
#if FEATURE_INTERRUPTS == ON
646
646
int _interrupt_pin = -1 ;
647
647
#endif
0 commit comments