Adding the battery controller IC charging, charged and unplugged status detection, work in progress
This commit is contained in:
parent
60cf47b142
commit
a752c9765d
@ -29,6 +29,10 @@ static void watch_peripherals_io_init(void)
|
||||
/* We initialize the output pin for the vibration motor enable pin */
|
||||
tls_gpio_cfg(VIBRATION_MOTOR_ENABLE, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_FLOATING);
|
||||
tls_gpio_write(VIBRATION_MOTOR_ENABLE, 0);
|
||||
|
||||
/* We initialize the pins used to read the battery controller IC charging and charged statuses */
|
||||
tls_gpio_cfg(BATTERY_CONTROLLER_CHARGING_STATUS, WM_GPIO_DIR_INPUT, WM_GPIO_ATTR_FLOATING);
|
||||
tls_gpio_cfg(BATTERY_CONTROLLER_CHARGED_STATUS, WM_GPIO_DIR_INPUT, WM_GPIO_ATTR_FLOATING);
|
||||
}
|
||||
|
||||
void watch_peripherals_init(int8_t adcOffset)
|
||||
@ -94,6 +98,19 @@ uint8_t battery_voltage_to_percentage(uint16_t voltage_in_mV)
|
||||
return (i+1) * 5;
|
||||
}
|
||||
|
||||
battery_controller_status_e watch_peripherals_get_battery_controller_status(void)
|
||||
{
|
||||
bool charging = tls_gpio_read(BATTERY_CONTROLLER_CHARGING_STATUS) == 0;
|
||||
bool charged = tls_gpio_read(BATTERY_CONTROLLER_CHARGED_STATUS) == 0;
|
||||
|
||||
if(charging && !charged)
|
||||
return BATTERY_CHARGING;
|
||||
else if(!charging && charged)
|
||||
return BATTERY_CHARGED;
|
||||
|
||||
return BATTERY_STATUS_ERROR;
|
||||
}
|
||||
|
||||
void watch_peripherals_vibrate(uint8_t strength, uint32_t durationMs)
|
||||
{
|
||||
APP_LOG_DEBUG("Vibration started");
|
||||
|
@ -12,6 +12,13 @@ typedef enum Battery_Unit
|
||||
Battery_Unit_percent
|
||||
} Battery_Unit_e;
|
||||
|
||||
typedef enum battery_controller_status
|
||||
{
|
||||
BATTERY_CHARGING = 0,
|
||||
BATTERY_CHARGED,
|
||||
BATTERY_STATUS_ERROR
|
||||
} battery_controller_status_e;
|
||||
|
||||
/**
|
||||
* @brief Inits the watch peripherals driver.
|
||||
* This must be called before using the API.
|
||||
@ -39,6 +46,14 @@ uint16_t watch_peripherals_get_battery_voltage(Battery_Unit_e unit);
|
||||
*/
|
||||
uint8_t battery_voltage_to_percentage(uint16_t voltage_in_mV);
|
||||
|
||||
/**
|
||||
* @brief Returns the current battery controller IC status.
|
||||
* It can be one of the following
|
||||
*
|
||||
* @return battery_controller_status_e
|
||||
*/
|
||||
battery_controller_status_e watch_peripherals_get_battery_controller_status(void);
|
||||
|
||||
/**
|
||||
* @brief Triggers the vibration motor to vibrate at the provided strength for the set duration in ms.
|
||||
*
|
||||
|
@ -351,9 +351,10 @@ void gfx_task(void *param)
|
||||
BMP280_trigger_measurement();
|
||||
battery_voltage = watch_peripherals_get_battery_voltage(Battery_Unit_mV);
|
||||
battery_percentage = battery_voltage_to_percentage(battery_voltage);
|
||||
APP_LOG_DEBUG("GFX thread, temp : %0.2f °C, press : %0.2f hPa, bat : %u mV <-> %u %%",
|
||||
APP_LOG_DEBUG("GFX thread, temp : %0.2f °C, press : %0.2f hPa, bat(%d) : %u mV <-> %u %%",
|
||||
temperature,
|
||||
pressure/100,
|
||||
watch_peripherals_get_battery_controller_status(),
|
||||
battery_voltage,
|
||||
battery_percentage);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user