This repository has been archived by the owner on Apr 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Battery.cpp
50 lines (41 loc) · 1.91 KB
/
Battery.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//- -----------------------------------------------------------------------------------------------------------------------
// AskSin driver implementation
// 2013-08-03 <trilu@gmx.de> Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
//- -----------------------------------------------------------------------------------------------------------------------
//- AskSin battery status functions ---------------------------------------------------------------------------------------
//- with a lot of support from dirk at FHEM forum
//- -----------------------------------------------------------------------------------------------------------------------
//#define BT_DBG
#include "Battery.h"
#include "AS.h"
waitTimer battTmr; // battery timer for duration check
// public: //---------------------------------------------------------------------------------------------------------
void BT::set(uint8_t tenthVolt, uint32_t duration) {
bDuration = duration;
checkTenthVolt = tenthVolt;
poll();
}
// private: //---------------------------------------------------------------------------------------------------------
BT::BT() {
}
void BT::init(AS *ptrMain) {
#ifdef BT_DBG // only if ee debug is set
dbgStart(); // serial setup
dbg << F("BT.\n"); // ...and some information
#endif
pHM = ptrMain;
bMode = 0;
bDuration = 0;
}
void BT::poll(void) {
if (!battTmr.done() ) return; // timer still running
measureTenthVolt = getBatteryVoltage();
bState = (measureTenthVolt < checkTenthVolt) ? 1 : 0; // set the battery status
#ifdef BT_DBG // only if ee debug is set
dbg << "cTV:" << checkTenthVolt << ", mTV:" << measureTenthVolt << " , s:" << bState << '\n';
#endif
battTmr.set(bDuration); // set next check time
}
uint8_t BT::getStatus(void) {
return bState;
}