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
GasUseCounter.h@5:5bccf48799d4, 2015-02-17 (annotated)
- Committer:
- Bobty
- Date:
- Tue Feb 17 21:33:39 2015 +0000
- Revision:
- 5:5bccf48799d4
- Child:
- 19:0367cb46d003
Tidied up - but is unstable - web server crashes after some time
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Bobty | 5:5bccf48799d4 | 1 | #ifndef __GASUSECOUNTER__H |
Bobty | 5:5bccf48799d4 | 2 | #define __GASUSECOUNTER__H |
Bobty | 5:5bccf48799d4 | 3 | #include "mbed.h" |
Bobty | 5:5bccf48799d4 | 4 | #include "PulsePin.h" |
Bobty | 5:5bccf48799d4 | 5 | #include "SDFileSystem.h" |
Bobty | 5:5bccf48799d4 | 6 | #include <RawSerial.h> |
Bobty | 5:5bccf48799d4 | 7 | |
Bobty | 5:5bccf48799d4 | 8 | const int MAX_GAS_COUNT_STR_LEN = 50; |
Bobty | 5:5bccf48799d4 | 9 | const int MAX_PULSES_BEFORE_STORE_NV = 1; // Store at each pulse |
Bobty | 5:5bccf48799d4 | 10 | |
Bobty | 5:5bccf48799d4 | 11 | class GasUseCounter |
Bobty | 5:5bccf48799d4 | 12 | { |
Bobty | 5:5bccf48799d4 | 13 | public: |
Bobty | 5:5bccf48799d4 | 14 | // Constructor |
Bobty | 5:5bccf48799d4 | 15 | GasUseCounter(const char* gasUseFilename, DigitalIn& gasPulsePin, RawSerial &pc) : |
Bobty | 5:5bccf48799d4 | 16 | _gasPulsePin(gasPulsePin), _pc(pc) |
Bobty | 5:5bccf48799d4 | 17 | { |
Bobty | 5:5bccf48799d4 | 18 | _gasUseFilename = gasUseFilename; |
Bobty | 5:5bccf48799d4 | 19 | _lastWrittenGasCount = 0; |
Bobty | 5:5bccf48799d4 | 20 | _pulseDetector = new PulsePin(_gasPulsePin, false, 200); |
Bobty | 5:5bccf48799d4 | 21 | } |
Bobty | 5:5bccf48799d4 | 22 | |
Bobty | 5:5bccf48799d4 | 23 | // Init (get count from NV) |
Bobty | 5:5bccf48799d4 | 24 | void Init(); |
Bobty | 5:5bccf48799d4 | 25 | |
Bobty | 5:5bccf48799d4 | 26 | // Callback from web server to handle getting current gas count |
Bobty | 5:5bccf48799d4 | 27 | char* getGasUseCallback(char* cmdStr, char* argStr); |
Bobty | 5:5bccf48799d4 | 28 | |
Bobty | 5:5bccf48799d4 | 29 | // Service function to detect pulses |
Bobty | 5:5bccf48799d4 | 30 | bool Service(); |
Bobty | 5:5bccf48799d4 | 31 | |
Bobty | 5:5bccf48799d4 | 32 | // Read/Write current gas count |
Bobty | 5:5bccf48799d4 | 33 | void GetGasCountFromSD(); |
Bobty | 5:5bccf48799d4 | 34 | void WriteGasCountToSD(); |
Bobty | 5:5bccf48799d4 | 35 | |
Bobty | 5:5bccf48799d4 | 36 | // Get Count |
Bobty | 5:5bccf48799d4 | 37 | int GetCount() |
Bobty | 5:5bccf48799d4 | 38 | { |
Bobty | 5:5bccf48799d4 | 39 | return _pulseDetector->GetPulseCount(); |
Bobty | 5:5bccf48799d4 | 40 | } |
Bobty | 5:5bccf48799d4 | 41 | |
Bobty | 5:5bccf48799d4 | 42 | // Set Count |
Bobty | 5:5bccf48799d4 | 43 | void SetCount(int gasUseCount) |
Bobty | 5:5bccf48799d4 | 44 | { |
Bobty | 5:5bccf48799d4 | 45 | _pulseDetector->SetPulseCount(gasUseCount); |
Bobty | 5:5bccf48799d4 | 46 | WriteGasCountToSD(); |
Bobty | 5:5bccf48799d4 | 47 | } |
Bobty | 5:5bccf48799d4 | 48 | |
Bobty | 5:5bccf48799d4 | 49 | // Get inter-pulse time |
Bobty | 5:5bccf48799d4 | 50 | int GetPulseRateMs() |
Bobty | 5:5bccf48799d4 | 51 | { |
Bobty | 5:5bccf48799d4 | 52 | return _pulseDetector->GetPulseRateMs(); |
Bobty | 5:5bccf48799d4 | 53 | } |
Bobty | 5:5bccf48799d4 | 54 | |
Bobty | 5:5bccf48799d4 | 55 | private: |
Bobty | 5:5bccf48799d4 | 56 | // Gas use filename for non-volatile |
Bobty | 5:5bccf48799d4 | 57 | const char* _gasUseFilename; |
Bobty | 5:5bccf48799d4 | 58 | int _curGasCount; |
Bobty | 5:5bccf48799d4 | 59 | int _lastWrittenGasCount; |
Bobty | 5:5bccf48799d4 | 60 | char _gasCountStr [MAX_GAS_COUNT_STR_LEN]; |
Bobty | 5:5bccf48799d4 | 61 | DigitalIn& _gasPulsePin; |
Bobty | 5:5bccf48799d4 | 62 | PulsePin* _pulseDetector; |
Bobty | 5:5bccf48799d4 | 63 | RawSerial& _pc; |
Bobty | 5:5bccf48799d4 | 64 | }; |
Bobty | 5:5bccf48799d4 | 65 | |
Bobty | 5:5bccf48799d4 | 66 | |
Bobty | 5:5bccf48799d4 | 67 | |
Bobty | 5:5bccf48799d4 | 68 | |
Bobty | 5:5bccf48799d4 | 69 | #endif |