Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stefan Haun
firmware
Commits
d5f9b2ac
Commit
d5f9b2ac
authored
Aug 25, 2019
by
Stefan Haun
Browse files
Add battery capacity to python API
parent
4a910df1
Pipeline
#3892
passed with stages
in 48 seconds
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Documentation/pycardium/power.rst
View file @
d5f9b2ac
...
...
@@ -32,6 +32,13 @@ in your scripts.
.. 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()
Read the charge voltage in V.
...
...
pycardium/modules/power.c
View file @
d5f9b2ac
...
...
@@ -32,6 +32,20 @@ static MP_DEFINE_CONST_FUN_OBJ_0(
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
()
{
float
result
;
...
...
@@ -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_QSTR
(
MP_QSTR_read_battery_current
),
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_PTR
(
&
power_read_chargein_voltage_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_read_chargein_current
),
...
...
pycardium/modules/qstrdefs.h
View file @
d5f9b2ac
...
...
@@ -79,6 +79,7 @@ Q(z)
Q
(
power
)
Q
(
read_battery_voltage
)
Q
(
read_battery_current
)
Q
(
read_battery_capacity
)
Q
(
read_chargein_voltage
)
Q
(
read_chargein_current
)
Q
(
read_system_voltage
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment