Commit d5f9b2ac authored by Stefan Haun's avatar Stefan Haun
Browse files

Add battery capacity to python API

parent 4a910df1
Pipeline #3892 passed with stages
in 48 seconds
...@@ -32,6 +32,13 @@ in your scripts. ...@@ -32,6 +32,13 @@ in your scripts.
.. versionadded:: 1.4 .. versionadded:: 1.4
.. py:function:: read_battery_capacity()
Calculate the remaining battery capacity in percent.
Uses 42 logarithmic values from a look-up table to estimate
the remaining capacity in percent based on the battery voltage.
.. py:function:: read_chargein_voltage() .. py:function:: read_chargein_voltage()
Read the charge voltage in V. Read the charge voltage in V.
......
...@@ -32,6 +32,20 @@ static MP_DEFINE_CONST_FUN_OBJ_0( ...@@ -32,6 +32,20 @@ static MP_DEFINE_CONST_FUN_OBJ_0(
power_read_battery_current_obj, mp_power_read_battery_current power_read_battery_current_obj, mp_power_read_battery_current
); );
static mp_obj_t mp_power_read_battery_capacity()
{
float result;
int status = epic_read_battery_capacity(&result);
if (status < 0) {
mp_raise_OSError(-status);
return mp_const_none;
}
return mp_obj_new_float(result);
}
static MP_DEFINE_CONST_FUN_OBJ_0(
power_read_battery_capacity_obj, mp_power_read_battery_capacity
);
static mp_obj_t mp_power_read_chargein_voltage() static mp_obj_t mp_power_read_chargein_voltage()
{ {
float result; float result;
...@@ -94,6 +108,8 @@ static const mp_rom_map_elem_t power_module_globals_table[] = { ...@@ -94,6 +108,8 @@ static const mp_rom_map_elem_t power_module_globals_table[] = {
MP_ROM_PTR(&power_read_battery_voltage_obj) }, MP_ROM_PTR(&power_read_battery_voltage_obj) },
{ MP_ROM_QSTR(MP_QSTR_read_battery_current), { MP_ROM_QSTR(MP_QSTR_read_battery_current),
MP_ROM_PTR(&power_read_battery_current_obj) }, MP_ROM_PTR(&power_read_battery_current_obj) },
{ MP_ROM_QSTR(MP_QSTR_read_battery_capacity),
MP_ROM_PTR(&power_read_battery_capacity_obj) },
{ MP_ROM_QSTR(MP_QSTR_read_chargein_voltage), { MP_ROM_QSTR(MP_QSTR_read_chargein_voltage),
MP_ROM_PTR(&power_read_chargein_voltage_obj) }, MP_ROM_PTR(&power_read_chargein_voltage_obj) },
{ MP_ROM_QSTR(MP_QSTR_read_chargein_current), { MP_ROM_QSTR(MP_QSTR_read_chargein_current),
......
...@@ -79,6 +79,7 @@ Q(z) ...@@ -79,6 +79,7 @@ Q(z)
Q(power) Q(power)
Q(read_battery_voltage) Q(read_battery_voltage)
Q(read_battery_current) Q(read_battery_current)
Q(read_battery_capacity)
Q(read_chargein_voltage) Q(read_chargein_voltage)
Q(read_chargein_current) Q(read_chargein_current)
Q(read_system_voltage) Q(read_system_voltage)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment