Skip to content

Commit cb7797c

Browse files
committed
Child class review
1 parent 7a5b224 commit cb7797c

File tree

4 files changed

+394
-306
lines changed

4 files changed

+394
-306
lines changed

NodeManager.ino

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ to save some storage for your code. To enable/disable a buil-in feature:
101101
* Install the required library if any
102102
* Enable the corresponding feature by setting it to ON in the main sketch. To
103103
disable it, set it to OFF
104+
* When a feature is enabled additional functions may be made available. Have a look
105+
at the API documentation for details
104106
105107
A list of buil-in features and the required dependencies is presented below:
106108
@@ -376,9 +378,6 @@ NodeManager node;
376378
void before() {
377379
// setup the serial port baud rate
378380
Serial.begin(MY_BAUD_RATE);
379-
380-
381-
382381
/*
383382
* Configure your sensors below
384383
*/
@@ -398,7 +397,6 @@ void before() {
398397
//analog.children.get(1)->min_threshold = 40;
399398
// power all the nodes through dedicated pins
400399
//node.setPowerManager(power);
401-
402400
/*
403401
* Configure your sensors above
404402
*/

NodeManagerLibrary.h

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
#if defined (MYBOARDNRF5)
5151
#define CHIP_NRF5
5252
#endif
53-
5453
#if !defined(CHIP_ESP8266) && !defined(CHIP_STM32) && !defined(CHIP_NRF5)
5554
#define CHIP_AVR
5655
#endif
@@ -449,48 +448,64 @@ class Child {
449448
public:
450449
Child();
451450
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();
466465
#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);
474474
#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();
475481
protected:
476482
int _samples = 0;
477483
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
478495
};
479496

480497
class ChildInt: public Child {
481498
public:
482499
ChildInt(Sensor* sensor, int child_id, int presentation, int type, const char* description = "");
483500
void setValueInt(int value);
484501
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();
490505
private:
491506
int _value;
492507
#if FEATURE_CONDITIONAL_REPORT == ON
493-
int _last_value;
508+
int _last_value = -256;
494509
#endif
495510
int _total = 0;
496511
};
@@ -500,15 +515,13 @@ class ChildFloat: public Child {
500515
ChildFloat(Sensor* sensor, int child_id, int presentation, int type, const char* description = "");
501516
void setValueFloat(float value);
502517
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();
508521
private:
509522
float _value;
510523
#if FEATURE_CONDITIONAL_REPORT == ON
511-
float _last_value;
524+
float _last_value = -256;
512525
#endif
513526
float _total = 0;
514527
};
@@ -518,15 +531,13 @@ class ChildDouble: public Child {
518531
ChildDouble(Sensor* sensor, int child_id, int presentation, int type, const char* description = "");
519532
void setValueDouble(double value);
520533
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();
526537
private:
527538
double _value;
528539
#if FEATURE_CONDITIONAL_REPORT == ON
529-
double _last_value;
540+
double _last_value = -256;
530541
#endif
531542
double _total = 0;
532543
};
@@ -536,11 +547,9 @@ class ChildString: public Child {
536547
ChildString(Sensor* sensor, int child_id, int presentation, int type, const char* description = "");
537548
void setValueString(const char* value);
538549
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();
544553
private:
545554
const char* _value = "";
546555
#if FEATURE_CONDITIONAL_REPORT == ON
@@ -565,12 +574,6 @@ class Sensor {
565574
void setSamples(int value);
566575
// [6] If more then one sample has to be taken, set the interval in milliseconds between measurements (default: 0)
567576
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
574577
#if FEATURE_POWER_MANAGER == ON
575578
// to save battery the sensor can be optionally connected to two pins which will act as vcc and ground and activated on demand
576579
void setPowerPins(int ground_pin, int vcc_pin, int wait_time = 50);
@@ -639,9 +642,6 @@ class Sensor {
639642
int _pin = -1;
640643
int _samples = 1;
641644
int _samples_interval = 0;
642-
#if FEATURE_CONDITIONAL_REPORT == ON
643-
bool _track_last_value = false;
644-
#endif
645645
#if FEATURE_INTERRUPTS == ON
646646
int _interrupt_pin = -1;
647647
#endif

0 commit comments

Comments
 (0)