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@19:0367cb46d003, 2015-10-05 (annotated)
- Committer:
- Bobty
- Date:
- Mon Oct 05 14:05:33 2015 +0000
- Revision:
- 19:0367cb46d003
- Parent:
- 5:5bccf48799d4
- Child:
- 20:7933076df5af
Added retries on getting addresses from thermometers; Doubled up on non-volatile storage of latest gas count
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 | 19:0367cb46d003 | 15 | GasUseCounter(const char* gasUseFilename1, const char* gasUseFilename2, DigitalIn& gasPulsePin, RawSerial &pc) : |
Bobty | 5:5bccf48799d4 | 16 | _gasPulsePin(gasPulsePin), _pc(pc) |
Bobty | 5:5bccf48799d4 | 17 | { |
Bobty | 19:0367cb46d003 | 18 | _gasUseFilename1 = gasUseFilename1; |
Bobty | 19:0367cb46d003 | 19 | _gasUseFilename2 = gasUseFilename2; |
Bobty | 5:5bccf48799d4 | 20 | _lastWrittenGasCount = 0; |
Bobty | 5:5bccf48799d4 | 21 | _pulseDetector = new PulsePin(_gasPulsePin, false, 200); |
Bobty | 5:5bccf48799d4 | 22 | } |
Bobty | 5:5bccf48799d4 | 23 | |
Bobty | 5:5bccf48799d4 | 24 | // Init (get count from NV) |
Bobty | 5:5bccf48799d4 | 25 | void Init(); |
Bobty | 5:5bccf48799d4 | 26 | |
Bobty | 5:5bccf48799d4 | 27 | // Callback from web server to handle getting current gas count |
Bobty | 5:5bccf48799d4 | 28 | char* getGasUseCallback(char* cmdStr, char* argStr); |
Bobty | 5:5bccf48799d4 | 29 | |
Bobty | 5:5bccf48799d4 | 30 | // Service function to detect pulses |
Bobty | 5:5bccf48799d4 | 31 | bool Service(); |
Bobty | 5:5bccf48799d4 | 32 | |
Bobty | 5:5bccf48799d4 | 33 | // Read/Write current gas count |
Bobty | 5:5bccf48799d4 | 34 | void GetGasCountFromSD(); |
Bobty | 5:5bccf48799d4 | 35 | void WriteGasCountToSD(); |
Bobty | 5:5bccf48799d4 | 36 | |
Bobty | 5:5bccf48799d4 | 37 | // Get Count |
Bobty | 5:5bccf48799d4 | 38 | int GetCount() |
Bobty | 5:5bccf48799d4 | 39 | { |
Bobty | 5:5bccf48799d4 | 40 | return _pulseDetector->GetPulseCount(); |
Bobty | 5:5bccf48799d4 | 41 | } |
Bobty | 5:5bccf48799d4 | 42 | |
Bobty | 5:5bccf48799d4 | 43 | // Set Count |
Bobty | 5:5bccf48799d4 | 44 | void SetCount(int gasUseCount) |
Bobty | 5:5bccf48799d4 | 45 | { |
Bobty | 5:5bccf48799d4 | 46 | _pulseDetector->SetPulseCount(gasUseCount); |
Bobty | 5:5bccf48799d4 | 47 | WriteGasCountToSD(); |
Bobty | 5:5bccf48799d4 | 48 | } |
Bobty | 5:5bccf48799d4 | 49 | |
Bobty | 5:5bccf48799d4 | 50 | // Get inter-pulse time |
Bobty | 5:5bccf48799d4 | 51 | int GetPulseRateMs() |
Bobty | 5:5bccf48799d4 | 52 | { |
Bobty | 5:5bccf48799d4 | 53 | return _pulseDetector->GetPulseRateMs(); |
Bobty | 5:5bccf48799d4 | 54 | } |
Bobty | 5:5bccf48799d4 | 55 | |
Bobty | 5:5bccf48799d4 | 56 | private: |
Bobty | 5:5bccf48799d4 | 57 | // Gas use filename for non-volatile |
Bobty | 19:0367cb46d003 | 58 | const char* _gasUseFilename1; |
Bobty | 19:0367cb46d003 | 59 | const char* _gasUseFilename2; |
Bobty | 5:5bccf48799d4 | 60 | int _curGasCount; |
Bobty | 5:5bccf48799d4 | 61 | int _lastWrittenGasCount; |
Bobty | 5:5bccf48799d4 | 62 | char _gasCountStr [MAX_GAS_COUNT_STR_LEN]; |
Bobty | 5:5bccf48799d4 | 63 | DigitalIn& _gasPulsePin; |
Bobty | 5:5bccf48799d4 | 64 | PulsePin* _pulseDetector; |
Bobty | 5:5bccf48799d4 | 65 | RawSerial& _pc; |
Bobty | 5:5bccf48799d4 | 66 | }; |
Bobty | 5:5bccf48799d4 | 67 | |
Bobty | 5:5bccf48799d4 | 68 | |
Bobty | 5:5bccf48799d4 | 69 | |
Bobty | 5:5bccf48799d4 | 70 | |
Bobty | 5:5bccf48799d4 | 71 | #endif |