Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterfacePlusHostname NTPClient Onewire RdWebServer SDFileSystem-RTOS mbed-rtos mbed-src
GasUseCounter.h
- Committer:
- Bobty
- Date:
- 2015-10-13
- Revision:
- 20:7933076df5af
- Parent:
- 19:0367cb46d003
File content as of revision 20:7933076df5af:
#ifndef __GASUSECOUNTER__H
#define __GASUSECOUNTER__H
#include "mbed.h"
#include "PulsePin.h"
#include "SDFileSystem.h"
#include "Logger.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* gasUseFilename1, const char* gasUseFilename2, DigitalIn& gasPulsePin, Logger &logger, Mutex &sdCardMutex) :
_gasPulsePin(gasPulsePin), _logger(logger), _sdCardMutex(sdCardMutex)
{
_gasUseFilename1 = gasUseFilename1;
_gasUseFilename2 = gasUseFilename2;
_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* _gasUseFilename1;
const char* _gasUseFilename2;
int _curGasCount;
int _lastWrittenGasCount;
char _gasCountStr [MAX_GAS_COUNT_STR_LEN];
DigitalIn& _gasPulsePin;
PulsePin* _pulseDetector;
Logger &_logger;
Mutex &_sdCardMutex;
};
#endif