From e826d15fc96baefa3912b84b06e044d37cd39a76 Mon Sep 17 00:00:00 2001
From: user2684 <you@example.com>
Date: Fri, 31 Mar 2017 11:51:03 +0200
Subject: [PATCH] For SENSOR_MOTION, pull up is wrongly set to HIGH in
 registerSensor() #27

---
 NodeManagerTemplate/NodeManager.cpp | 13 ++++++++++---
 NodeManagerTemplate/NodeManager.h   |  4 ++++
 NodeManagerTemplate/config.h        |  2 +-
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/NodeManagerTemplate/NodeManager.cpp b/NodeManagerTemplate/NodeManager.cpp
index 56d4e6a..c747f8c 100644
--- a/NodeManagerTemplate/NodeManager.cpp
+++ b/NodeManagerTemplate/NodeManager.cpp
@@ -704,14 +704,18 @@ void SensorSwitch::setMode(int value) {
 int SensorSwitch::getMode() {
   return _mode;
 }
-// setter/getter
 void SensorSwitch::setDebounce(int value) {
   _debounce = value;
 }
-// setter/getter
 void SensorSwitch::setTriggerTime(int value) {
   _trigger_time = value;
 }
+void SensorSwitch::setInitial(int value) {
+  _initial = value;
+}
+int SensorSwitch::getInitial() {
+  return _initial;
+}
 
 // what do to during setup
 void SensorSwitch::onBefore() {
@@ -763,6 +767,8 @@ SensorMotion::SensorMotion(int child_id, int pin): SensorSwitch(child_id,pin) {
   setPresentation(S_MOTION);
   // capture only when it triggers
   setMode(RISING);
+  // set initial value to LOW
+  setInitial(LOW);
 }
 
 /*
@@ -1013,7 +1019,8 @@ int NodeManager::registerSensor(int sensor_type, int pin, int child_id) {
       else if (sensor_type == SENSOR_DOOR) index = registerSensor(new SensorDoor(child_id, pin));
       else if (sensor_type == SENSOR_MOTION) index = registerSensor(new SensorMotion(child_id, pin));
       // set an interrupt on the pin and activate internal pull up
-      setInterrupt(pin,((SensorSwitch*)get(index))->getMode(),HIGH);
+      SensorSwitch* sensor = (SensorSwitch*)get(index);
+      setInterrupt(pin,sensor->getMode(),sensor->getInitial());
       return index;
     }
   #endif
diff --git a/NodeManagerTemplate/NodeManager.h b/NodeManagerTemplate/NodeManager.h
index b259b08..def4712 100644
--- a/NodeManagerTemplate/NodeManager.h
+++ b/NodeManagerTemplate/NodeManager.h
@@ -496,6 +496,9 @@ class SensorSwitch: public Sensor {
     void setDebounce(int value);
     // time to wait in milliseconds after a change is detected to allow the signal to be restored to its normal value (default: 0)
     void setTriggerTime(int value);
+    // Set initial value on the interrupt pin (default: HIGH)
+    void setInitial(int value);
+    int getInitial();
     // define what to do at each stage of the sketch
     void onBefore();
     void onLoop();
@@ -504,6 +507,7 @@ class SensorSwitch: public Sensor {
     int _debounce = 0;
     int _trigger_time = 0;
     int _mode = CHANGE;
+    int _initial = HIGH;
 };
 
 /*
diff --git a/NodeManagerTemplate/config.h b/NodeManagerTemplate/config.h
index c0ae2be..32e5296 100644
--- a/NodeManagerTemplate/config.h
+++ b/NodeManagerTemplate/config.h
@@ -6,7 +6,7 @@
  */
 
 #define SKETCH_NAME "NodeManagerTemplate"
-#define SKETCH_VERSION "1.2"
+#define SKETCH_VERSION "1.3-dev"
 
 /**********************************
  * MySensors configuration
-- 
GitLab