73 lines
2.2 KiB
C
Executable File
73 lines
2.2 KiB
C
Executable File
/**
|
|
* @file include/di_fw/charger.h
|
|
* @brief charger header file
|
|
* @date September 12, 2016
|
|
* @author R.H. van Lieshout (PragmaLab)
|
|
* @copyright 2016 Dual Inventive Technology Centre B.V.
|
|
*/
|
|
#ifndef INCLUDE_DI_FW_CHARGER_H_
|
|
#define INCLUDE_DI_FW_CHARGER_H_
|
|
|
|
#include <di/device/battery.h>
|
|
|
|
/**
|
|
* Enum of chargers that can be selected
|
|
* Note: for now the charger ID is only used for publishing charger data
|
|
* to the server
|
|
*/
|
|
enum di_fw_charger {
|
|
DI_FW_CHARGER_1 = 0,
|
|
DI_FW_CHARGER_2,
|
|
};
|
|
|
|
/**
|
|
* Charger states
|
|
* We need to assign numbers to this enum since the
|
|
* state is communicated to the backend
|
|
*/
|
|
enum di_fw_charger_state {
|
|
DI_FW_CHARGER_STATE_DISCONNECTED = 0, /**< no charger input voltage */
|
|
DI_FW_CHARGER_STATE_CONNECTED = 1, /**< charger input voltage OK, not charging */
|
|
DI_FW_CHARGER_STATE_CHARGING = 2, /**< charger input voltage OK, charging */
|
|
DI_FW_CHARGER_STATE_ERROR = 3 /**< charger input voltage NOT OK, error */
|
|
};
|
|
|
|
struct di_fw_charger_data {
|
|
uint32_t periodic_id;
|
|
float current_voltage;
|
|
float previous_voltage;
|
|
enum di_fw_charger charger_num;
|
|
enum di_fw_charger_state current_state;
|
|
enum di_fw_charger_state previous_state;
|
|
};
|
|
|
|
#define DI_FW_CHARGER_ZERO_LEVEL 1 /* below this voltage, we assume no charger supply is present */
|
|
|
|
#define DI_FW_CHARGER_MIN_LEVEL 5.5f /* below this voltage, do not charge */
|
|
#define DI_FW_CHARGER_MAX_LEVEL 30.0f /* above this voltage, do not charge */
|
|
|
|
#define DI_FW_BATTERY_MIN_CHARGE_LEVEL 13.0f /* below this voltage, start charging */
|
|
#define DI_FW_BATTERY_MAX_CHARGE_LEVEL 14.2f /* above this voltage, stop charging */
|
|
|
|
#define DI_FW_CHARGER_DELTA 0.1f /* threshold for sending data */
|
|
|
|
/**
|
|
* Set charger module to work
|
|
* @param battery_voltage the battery voltage of the battery that needs to be charged
|
|
*/
|
|
void di_fw_charger_kick_charger(float battery_voltage);
|
|
|
|
/**
|
|
* charger state machine
|
|
* @param battery_val the battery voltage of the battery that needs to be charged
|
|
* @param charger_val the charger voltage
|
|
*/
|
|
void di_fw_charger_fsm(float battery_val, float charger_val);
|
|
|
|
/**
|
|
* init this module
|
|
*/
|
|
void di_fw_charger_init(void);
|
|
|
|
#endif /* INCLUDE_DI_FW_CHARGER_H_ */
|