1 /*
2  * Copyright (c) 2018-2019 Peter Bigot Consulting, LLC
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef APPLICATION_BATTERY_H_
8 #define APPLICATION_BATTERY_H_
9 
10 /** Enable or disable measurement of the battery voltage.
11  *
12  * @param enable true to enable, false to disable
13  *
14  * @return zero on success, or a negative error code.
15  */
16 int battery_measure_enable(bool enable);
17 
18 /** Measure the battery voltage.
19  *
20  * @return the battery voltage in millivolts, or a negative error
21  * code.
22  */
23 int battery_sample(void);
24 
25 /** A point in a battery discharge curve sequence.
26  *
27  * A discharge curve is defined as a sequence of these points, where
28  * the first point has #lvl_pptt set to 10000 and the last point has
29  * #lvl_pptt set to zero.  Both #lvl_pptt and #lvl_mV should be
30  * monotonic decreasing within the sequence.
31  */
32 struct battery_level_point {
33 	/** Remaining life at #lvl_mV. */
34 	uint16_t lvl_pptt;
35 
36 	/** Battery voltage at #lvl_pptt remaining life. */
37 	uint16_t lvl_mV;
38 };
39 
40 /** Calculate the estimated battery level based on a measured voltage.
41  *
42  * @param batt_mV a measured battery voltage level.
43  *
44  * @param curve the discharge curve for the type of battery installed
45  * on the system.
46  *
47  * @return the estimated remaining capacity in parts per ten
48  * thousand.
49  */
50 unsigned int battery_level_pptt(unsigned int batt_mV,
51 				const struct battery_level_point *curve);
52 
53 #endif /* APPLICATION_BATTERY_H_ */
54