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@23:fd5a5a9f30bc, 2015-10-16 (annotated)
- Committer:
- Bobty
- Date:
- Fri Oct 16 09:07:04 2015 +0000
- Revision:
- 23:fd5a5a9f30bc
- Parent:
- 20:7933076df5af
Added index.html file to project for completeness
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 | 20:7933076df5af | 6 | #include "Logger.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 | 20:7933076df5af | 15 | GasUseCounter(const char* gasUseFilename1, const char* gasUseFilename2, DigitalIn& gasPulsePin, Logger &logger, Mutex &sdCardMutex) : |
Bobty | 20:7933076df5af | 16 | _gasPulsePin(gasPulsePin), _logger(logger), _sdCardMutex(sdCardMutex) |
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 | 20:7933076df5af | 65 | Logger &_logger; |
Bobty | 20:7933076df5af | 66 | Mutex &_sdCardMutex; |
Bobty | 5:5bccf48799d4 | 67 | }; |
Bobty | 5:5bccf48799d4 | 68 | |
Bobty | 5:5bccf48799d4 | 69 | |
Bobty | 5:5bccf48799d4 | 70 | |
Bobty | 5:5bccf48799d4 | 71 | |
Bobty | 5:5bccf48799d4 | 72 | #endif |