81 lines
2.3 KiB
C
Executable File
81 lines
2.3 KiB
C
Executable File
/**
|
|
* @file include/di_fw/battery.h
|
|
* @brief battery header file
|
|
* @date August 24, 2016
|
|
* @author A.A.W.M. Ruijs
|
|
* @copyright 2016 Dual Inventive Technology Centre B.V.
|
|
*/
|
|
#ifndef INCLUDE_DI_FW_BATTERY_H_
|
|
#define INCLUDE_DI_FW_BATTERY_H_
|
|
|
|
#include <di/constants/device/battery.h>
|
|
|
|
/**
|
|
* Enum of batteries that can be selected
|
|
* Note: entries are used as index in an array, do not change values
|
|
*/
|
|
enum di_fw_batteries {
|
|
DI_FW_BATTERY_1 = 0,
|
|
#ifdef DI_FW_BATTERY_ADC_CHANNEL2
|
|
DI_FW_BATTERY_2,
|
|
#endif
|
|
DI_FW_BATTERY_COUNT,
|
|
|
|
};
|
|
|
|
struct di_fw_battery_data {
|
|
di_time_t last_update;
|
|
float current_voltage;
|
|
float previous_voltage;
|
|
const enum di_fw_batteries battery_num;
|
|
enum di_device_battery_state current_state;
|
|
enum di_device_battery_state previous_state;
|
|
};
|
|
|
|
/**
|
|
* ADC conversion groep for battery measurements
|
|
*/
|
|
extern const ADCConversionGroup di_fw_battery_adc_conversion_group;
|
|
|
|
/**
|
|
* convert raw ADC value to voltage
|
|
* @param val the adc sample that need to be converted to voltage
|
|
*/
|
|
float di_fw_battery_calculate_voltage(adcsample_t val);
|
|
|
|
/**
|
|
* Check if device "release" transition is allowed ("idle" -> "armed") by checking battery #1
|
|
* state for HALF or FULL state.
|
|
* @return true When release is allowed, false otherwise
|
|
*/
|
|
bool di_fw_battery_is_device_release_allowed(void);
|
|
|
|
/**
|
|
* return battery state of requested battery
|
|
* @param id requested battery
|
|
*
|
|
* @return enum di_device_battery_state current battery state or DI_DEVICE_BATTERY_STATE_UNKNOWN
|
|
* in case of an invalid battery id
|
|
*/
|
|
enum di_device_battery_state di_fw_battery_get_battery_state(enum di_fw_batteries id);
|
|
|
|
/**
|
|
* take one battery voltage sample. Provide your own bufer
|
|
*
|
|
* @param adc_buffer pointer to 'adc_sample' type of buffer to receive the samples
|
|
*
|
|
* @return DNOK when sample was taken, DNE_PARAM or DNE_IOFAILED otherwise
|
|
*/
|
|
di_errno_t di_fw_battery_take_sample(adcsample_t *adc_buffer);
|
|
|
|
/**
|
|
* configure ADC for measurement and start the thread for measuring
|
|
* @param powersafe_mode: boolean that indicates the powersafe mode. When TRUE the powersafe mode
|
|
* is active and no periodic thread will be spawned and no battery data will be published
|
|
* When FALSE the module will function in normal operation and data will be
|
|
* published
|
|
*/
|
|
void di_fw_battery_init(bool powersafe_mode);
|
|
|
|
#endif /* INCLUDE_DI_FW_BATTERY_H_ */
|