2019-07-24 09:25:07 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the "bluetoothheater" distribution
|
|
|
|
* (https://gitlab.com/mrjones.id.au/bluetoothheater)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 Ray Jones <ray@mrjones.id.au>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "../RTC/RTCStore.h"
|
|
|
|
#include "NVStorage.h"
|
|
|
|
|
|
|
|
class CProtocol;
|
|
|
|
|
|
|
|
class CHourMeter {
|
2019-07-25 20:39:56 +00:00
|
|
|
const int baseSeconds = 60 * 15; // 15 minutes
|
|
|
|
|
2019-07-24 20:06:47 +00:00
|
|
|
float& _RunTime;
|
|
|
|
float& _GlowTime;
|
|
|
|
unsigned long _lastRunTime;
|
|
|
|
unsigned long _lastGlowTime;
|
2019-07-25 20:39:56 +00:00
|
|
|
uint32_t _getLclRunTime(); // volatile persistent variable + RTC stored rollovers
|
|
|
|
uint32_t _getLclGlowTime(); // volatile persistent variable + RTC stored rollovers
|
2019-07-24 09:25:07 +00:00
|
|
|
public:
|
2019-07-24 20:06:47 +00:00
|
|
|
CHourMeter(float &runtime, float& glowtime) :
|
2019-07-24 09:25:07 +00:00
|
|
|
_RunTime(runtime),
|
|
|
|
_GlowTime(glowtime)
|
2019-07-24 20:06:47 +00:00
|
|
|
{
|
|
|
|
_lastRunTime = 0;
|
|
|
|
_lastGlowTime = 0;
|
|
|
|
DebugPort.printf("CHourMeter %f %f\r\n", _RunTime, _GlowTime);
|
|
|
|
};
|
|
|
|
void associate(float &runtime, float& glowtime) {
|
2019-07-24 09:25:07 +00:00
|
|
|
_RunTime = runtime;
|
|
|
|
_GlowTime = glowtime;
|
|
|
|
};
|
2019-07-25 12:31:31 +00:00
|
|
|
void init(bool poweron);
|
2019-07-25 20:39:56 +00:00
|
|
|
void reset();
|
|
|
|
void store(); // transfer current state to permanent NV storage
|
2019-07-24 09:25:07 +00:00
|
|
|
void monitor(const CProtocol& frame);
|
2019-07-25 20:39:56 +00:00
|
|
|
uint32_t getRunTime(); // total time, local tracked + last NV stored value
|
|
|
|
uint32_t getGlowTime(); // total time, local tracked + last NV stored value
|
2019-07-24 09:25:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern CHourMeter* pHourMeter;
|