From 7ad3d6c5f262e3a2acdb206f21a75b482deff423 Mon Sep 17 00:00:00 2001
From: user2684 <you@example.com>
Date: Tue, 23 May 2017 18:21:13 +0200
Subject: [PATCH] Add option to retrieve the latest value of a sensor #104

---
 NodeManager.cpp | 12 ++++++++++++
 NodeManager.h   |  5 +++++
 README.md       | 12 ++++++++++++
 3 files changed, 29 insertions(+)

diff --git a/NodeManager.cpp b/NodeManager.cpp
index 333fe5b..0624c7a 100644
--- a/NodeManager.cpp
+++ b/NodeManager.cpp
@@ -152,6 +152,9 @@ void Sensor::setForceUpdate(int value) {
 void Sensor::setValueType(int value) {
   _value_type = value;
 }
+int Sensor::getValueType() {
+  return _value_type;
+}
 void Sensor::setFloatPrecision(int value) {
   _float_precision = value;
 }
@@ -178,6 +181,15 @@ void Sensor::setInterruptPin(int value) {
 int Sensor::getInterruptPin() {
   return _interrupt_pin;
 }
+int Sensor::getValueInt() {
+  return _last_value_int;
+}
+float Sensor::getValueFloat() {
+  return _last_value_float;
+}
+char* Sensor::getValueString() {
+  return _last_value_string;
+}
 
 // present the sensor to the gateway and controller
 void Sensor::presentation() {
diff --git a/NodeManager.h b/NodeManager.h
index e5170ed..6e3ed5e 100644
--- a/NodeManager.h
+++ b/NodeManager.h
@@ -345,6 +345,7 @@ class Sensor {
     void setForceUpdate(int value);
     // the value type of this sensor (default: TYPE_INTEGER)
     void setValueType(int value);
+    int getValueType();
     // for float values, set the float precision (default: 2)
     void setFloatPrecision(int value);
     // optionally sleep interval in milliseconds before sending each message to the radio network (default: 0)
@@ -362,6 +363,10 @@ class Sensor {
       // manually turn the power off
       void powerOff();
     #endif
+    // get the latest recorded value from the sensor
+    int getValueInt();
+    float getValueFloat();
+    char* getValueString();
     // define what to do at each stage of the sketch
     virtual void before();
     virtual void presentation();
diff --git a/README.md b/README.md
index 846f7e3..cac0859 100644
--- a/README.md
+++ b/README.md
@@ -343,12 +343,16 @@ The following methods are available for all the sensors:
 ~~~c
     // where the sensor is attached to (default: not set)
     void setPin(int value);
+	int getPin();
     // child_id of this sensor (default: not set)
     void setChildId(int value);
+	int getChildId();
     // presentation of this sensor (default: S_CUSTOM)
     void setPresentation(int value);
+	int getPresentation();
     // type of this sensor (default: V_CUSTOM)
     void setType(int value);
+	int getType();
     // description of the sensor (default: '')
     void setDescription(char *value);
     // set this to true if you want destination node to send ack back to this node (default: false)
@@ -365,10 +369,14 @@ The following methods are available for all the sensors:
     void setForceUpdate(int value);
     // the value type of this sensor (default: TYPE_INTEGER)
     void setValueType(int value);
+	int getValueType();
 	// for float values, set the float precision (default: 2)
     void setFloatPrecision(int value);
     // optionally sleep interval in milliseconds before sending each message to the radio network (default: 0)
     void setSleepBetweenSend(int value);
+    // set the interrupt pin the sensor is attached to so its loop() will be executed only upon that interrupt (default: -1)
+    void setInterruptPin(int value);
+    int getInterruptPin();
     #if POWER_MANAGER == 1
       // to save battery the sensor can be optionally connected to two pins which will act as vcc and ground and activated on demand
       void setPowerPins(int ground_pin, int vcc_pin, long wait = 0);
@@ -379,6 +387,10 @@ The following methods are available for all the sensors:
       // manually turn the power off
       void powerOff();
     #endif
+    // get the latest value from the sensor
+    int getValueInt();
+    float getValueFloat();
+    char* getValueString();
 ~~~
 
 ### Sensor's specific configuration
-- 
GitLab