Add "ion.battery()" for obtain the current voltage of the battery

Ion.battery() return a float with the current battery voltage

TODO : Update the translation of the toolbox (only FR and EN currently)
This commit is contained in:
FaustinM
2021-06-23 16:57:42 +02:00
parent 80587f35f1
commit cf9142b5a2
15 changed files with 25 additions and 3 deletions

View File

@@ -323,6 +323,7 @@ Q(zip)
// Ion QSTR
Q(ion)
Q(keydown)
Q(battery)
Q(KEY_LEFT)
Q(KEY_UP)
Q(KEY_DOWN)

View File

@@ -12,3 +12,7 @@ mp_obj_t modion_keyboard_keydown(mp_obj_t key_o) {
micropython_port_interrupt_if_needed();
return mp_obj_new_bool(state.keyDown(key));
}
mp_obj_t modion_battery() {
return mp_obj_new_float(Ion::Battery::voltage());
}

View File

@@ -1,4 +1,5 @@
#include <py/obj.h>
mp_obj_t modion_keyboard_keydown(mp_obj_t key_o);
extern const mp_obj_type_t file_type;
mp_obj_t modion_battery();
extern const mp_obj_type_t file_type;

View File

@@ -16,8 +16,14 @@ const mp_obj_fun_builtin_fixed_t modion_keyboard_keydown_obj = {
{(mp_fun_0_t)modion_keyboard_keydown}
};
const mp_obj_fun_builtin_fixed_t modion_battery_obj = {
{&mp_type_fun_builtin_0},
{(mp_fun_0_t)modion_battery}
};
extern "C" const mp_rom_map_elem_t modion_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ion) },
{ MP_ROM_QSTR(MP_QSTR_battery), MP_ROM_PTR(&modion_battery_obj) },
{ MP_ROM_QSTR(MP_QSTR_keydown), MP_ROM_PTR(&modion_keyboard_keydown_obj) },
{ MP_ROM_QSTR(MP_QSTR_KEY_LEFT), MP_OBJ_NEW_SMALL_INT(Ion::Keyboard::Key::Left) },
{ MP_ROM_QSTR(MP_QSTR_KEY_UP), MP_OBJ_NEW_SMALL_INT(Ion::Keyboard::Key::Up) },

View File

@@ -111,5 +111,4 @@ mp_obj_t modos_listdir(void) {
}
return list;
}
}