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
Diff: GasUseCounter.h
- Revision:
- 5:5bccf48799d4
- Child:
- 19:0367cb46d003
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GasUseCounter.h Tue Feb 17 21:33:39 2015 +0000 @@ -0,0 +1,69 @@ +#ifndef __GASUSECOUNTER__H +#define __GASUSECOUNTER__H +#include "mbed.h" +#include "PulsePin.h" +#include "SDFileSystem.h" +#include <RawSerial.h> + +const int MAX_GAS_COUNT_STR_LEN = 50; +const int MAX_PULSES_BEFORE_STORE_NV = 1; // Store at each pulse + +class GasUseCounter +{ + public: + // Constructor + GasUseCounter(const char* gasUseFilename, DigitalIn& gasPulsePin, RawSerial &pc) : + _gasPulsePin(gasPulsePin), _pc(pc) + { + _gasUseFilename = gasUseFilename; + _lastWrittenGasCount = 0; + _pulseDetector = new PulsePin(_gasPulsePin, false, 200); + } + + // Init (get count from NV) + void Init(); + + // Callback from web server to handle getting current gas count + char* getGasUseCallback(char* cmdStr, char* argStr); + + // Service function to detect pulses + bool Service(); + + // Read/Write current gas count + void GetGasCountFromSD(); + void WriteGasCountToSD(); + + // Get Count + int GetCount() + { + return _pulseDetector->GetPulseCount(); + } + + // Set Count + void SetCount(int gasUseCount) + { + _pulseDetector->SetPulseCount(gasUseCount); + WriteGasCountToSD(); + } + + // Get inter-pulse time + int GetPulseRateMs() + { + return _pulseDetector->GetPulseRateMs(); + } + + private: + // Gas use filename for non-volatile + const char* _gasUseFilename; + int _curGasCount; + int _lastWrittenGasCount; + char _gasCountStr [MAX_GAS_COUNT_STR_LEN]; + DigitalIn& _gasPulsePin; + PulsePin* _pulseDetector; + RawSerial& _pc; +}; + + + + +#endif