-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBattery.h
171 lines (136 loc) · 5.28 KB
/
Battery.h
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
* Battery.h
*
* Created on: 30.04.2014
* Author: niklausd
*/
#ifndef BATTERY_H_
#define BATTERY_H_
//-----------------------------------------------------------------------------
class Battery;
class BatteryAdapter
{
private:
#if defined (__arm__) && defined (__SAM3X8E__) // Arduino Due
const float s_V_ADC_FULLRANGE = 3.3;
const unsigned int s_N_ADC_FULLRANGE = 1023;
#elif defined (ARDUINO_ARCH_SAMD) && defined (__SAMD21G18A__) // Adafruit Feather M0
const float s_V_ADC_FULLRANGE = 3.3;
const unsigned int s_N_ADC_FULLRANGE = 1023;
#elif defined (__AVR__)
const float s_V_ADC_FULLRANGE = 5.0;
const unsigned int s_N_ADC_FULLRANGE = 1023;
#elif defined ESP8266
const float s_V_ADC_FULLRANGE = 1.0;
const unsigned int s_N_ADC_FULLRANGE = 1023;
#else
const float s_V_ADC_FULLRANGE = 3.1;
const unsigned int s_N_ADC_FULLRANGE = 4095;
#endif
Battery* m_battery;
public:
virtual void notifyBattVoltageOk();
virtual void notifyBattVoltageBelowWarnThreshold();
virtual void notifyBattVoltageBelowStopThreshold();
virtual void notifyBattVoltageBelowShutdownThreshold();
virtual void notifyBattStateAnyChange();
virtual float readBattVoltageSenseFactor();
virtual unsigned int readRawBattSenseValue() = 0;
virtual float getVAdcFullrange()
{
return s_V_ADC_FULLRANGE;
}
virtual unsigned int getNAdcFullrange()
{
return s_N_ADC_FULLRANGE;
}
virtual ~BatteryAdapter() { }
void attachBattery(Battery* battery);
Battery* battery();
protected:
BatteryAdapter();
private: // forbidden default functions
BatteryAdapter& operator = (const BatteryAdapter& src); // assignment operator
BatteryAdapter(const BatteryAdapter& src); // copy constructor
};
//-----------------------------------------------------------------------------
class BatteryImpl;
//-----------------------------------------------------------------------------
struct BatteryThresholdConfig
{
float battWarnThreshd; /// Battery Voltage Warn Threshold [V]
float battStopThrshd; /// Battery Voltage Stop Actors Threshold[V]
float battShutThrshd; /// Battery Voltage Shutdown Threshold[V]
float battHyst; /// Battery Voltage Hysteresis around Threshold levels[V]
};
//-----------------------------------------------------------------------------
class Battery
{
public:
/**
* Constructor.
* @param adapter Pointer to a specific BatteryAdapter object, default: 0 (none)
*/
Battery(BatteryAdapter* adapter = 0, BatteryThresholdConfig batteryThresholdConfig = {Battery::s_BATT_WARN_THRSHD, Battery::s_BATT_STOP_THRSHD, Battery::s_BATT_SHUT_THRSHD, Battery::s_BATT_HYST});
/**
* Destructor.
*/
virtual ~Battery();
/**
* Attach a specific BatteryAdapter object.
* @param adapter Pointer to a specific BatteryAdapter object.
*/
void attachAdapter(BatteryAdapter* adapter);
/**
* Get the pointer to the currently attached specific BatteryAdapter object.
* @return BatteryAdapter object pointer, might be 0 if none is attached.
*/
BatteryAdapter* adapter();
const char* getCurrentStateName();
const char* getPreviousStateName();
/**
* Notify Battery Voltage Sense Factor has changed in the Inventory Management Data.
* The Battery component shall read the new value and adjust the signal conversion accordingly.
*/
void battVoltageSensFactorChanged();
/**
* Read the currently measured Battery Voltage.
* @return Currently measured Battery Voltage [V].
*/
float getBatteryVoltage();
/**
* Check if the currently measured Battery Voltage is ok.
* @return true, if voltage is above the warning threshold level, false otherwise.
*/
bool isBattVoltageOk();
/**
* Check if the currently measured Battery Voltage is below the warning threshold level.
* @return true, if voltage is below the warning threshold level, false otherwise.
*/
bool isBattVoltageBelowWarnThreshold();
/**
* Check if the currently measured Battery Voltage is below the stop threshold level.
* @return true, if voltage is below the stop threshold level, false otherwise.
*/
bool isBattVoltageBelowStopThreshold();
/**
* Check if the currently measured Battery Voltage is below the shutdown threshold level.
* @return true, if voltage is below the shutdown threshold level, false otherwise.
*/
bool isBattVoltageBelowShutdownThreshold();
/**
* Evaluate Battery state, execute asynchronously (detached from the caller)
*/
void evaluateBatteryStateAsync();
static const float s_BATT_WARN_THRSHD; /// default Battery Voltage Warn Threshold [V]
static const float s_BATT_STOP_THRSHD; /// default Battery Voltage Stop Actors Threshold [V]
static const float s_BATT_SHUT_THRSHD; /// default Battery Voltage Shutdown Threshold [V]
static const float s_BATT_HYST; /// default Battery Voltage Hysteresis around Threshold levels [V]
private:
BatteryImpl* m_impl; /// Pointer to the private implementation of the Battery component object.
private: // forbidden default functions
Battery& operator = (const Battery& src); // assignment operator
Battery(const Battery& src); // copy constructor
};
//-----------------------------------------------------------------------------
#endif /* BATTERY_H_ */