Monitor for central heating system (e.g. 2zones+hw) Supports up to 15 temp probes (DS18B20/DS18S20) 3 valve monitors Gas pulse meter recording Use stand-alone or with nodeEnergyServer See http://robdobson.com/2015/09/central-heating-monitor

Dependencies:   EthernetInterfacePlusHostname NTPClient Onewire RdWebServer SDFileSystem-RTOS mbed-rtos mbed-src

Revision:
5:5bccf48799d4
Parent:
4:0d3a207680b0
Child:
10:72eb217def1f
--- a/PulsePin.cpp	Mon Feb 02 16:24:30 2015 +0000
+++ b/PulsePin.cpp	Tue Feb 17 21:33:39 2015 +0000
@@ -13,12 +13,27 @@
     _lastStableTimeMs = _pinTimer.read_ms();
     _firstEdgeDetected = false;
     _timeBetweenEdgesMs = 0;
+    _pulseCount = 0;
+    _pinTimerMinutes = 0;
 }
 
 bool PulsePin::Service()
 {
     // Check time since last edge - looking for stability
     int timeNowMs = _pinTimer.read_ms();
+    
+    // Check if over 1 minute (as the timer wraps around after 30 mins)
+    if (timeNowMs > 60000)
+    {
+        _pinTimerMinutes++;
+        _pinTimer.reset();
+        timeNowMs -= 60000;
+    }
+    
+    // Get the real time elapsed (still wraps but now only after about 500 hours)
+    timeNowMs = _pinTimerMinutes*60000 + timeNowMs;
+    
+    // Check for pin stabilization    
     if (timeNowMs < _lastStableTimeMs + _waitForPinStabilisationMs)
         return false;
 
@@ -36,6 +51,7 @@
         
     // Reset the timer to avoid wrap around problems
     bool firstEdgeDetected = _firstEdgeDetected;
+    _pinTimerMinutes = 0;
     _pinTimer.reset();
     _firstEdgeDetected = true;
     _lastStableTimeMs = 0;
@@ -44,10 +60,21 @@
     if (!firstEdgeDetected)
         return false;
     _timeBetweenEdgesMs = timeNowMs;
+    _pulseCount++;
     return true;
 }
 
-int PulsePin::GetLastCycleTimeMs()
+int PulsePin::GetPulseRateMs()
 {
     return _timeBetweenEdgesMs;
 }
+
+int PulsePin::GetPulseCount()
+{
+    return _pulseCount;
+}
+
+void PulsePin::SetPulseCount(int pulseCount)
+{
+    _pulseCount = pulseCount;
+}