Skip to content
GitLab
Menu
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
9e5ee737
Commit
9e5ee737
authored
Aug 25, 2019
by
Stefan Haun
Browse files
Add battery capacity to python API
parent
8754406d
Pipeline
#3503
failed with stages
in 45 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Documentation/pycardium/power.rst
View file @
9e5ee737
...
...
@@ -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 @
9e5ee737
...
...
@@ -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,7 +108,9 @@ 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_chargein_voltage
),
{
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
),
MP_ROM_PTR
(
&
power_read_chargein_current_obj
)
},
...
...
pycardium/modules/qstrdefs.h
View file @
9e5ee737
...
...
@@ -76,6 +76,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
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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