From 38614a849f2c4a5e494e1075cf3cae758c95002f Mon Sep 17 00:00:00 2001 From: Yaya-Cout <67095734+Yaya-Cout@users.noreply.github.com> Date: Tue, 25 Jan 2022 18:58:25 +0100 Subject: [PATCH] [apps/python] Add set_brightness and get_brightness in Ion module (#132) --- apps/code/catalog.de.i18n | 2 ++ apps/code/catalog.en.i18n | 2 ++ apps/code/catalog.es.i18n | 2 ++ apps/code/catalog.fr.i18n | 4 +++- apps/code/catalog.hu.i18n | 2 ++ apps/code/catalog.it.i18n | 4 +++- apps/code/catalog.nl.i18n | 4 +++- apps/code/catalog.pt.i18n | 2 ++ apps/code/catalog.universal.i18n | 2 ++ apps/code/python_toolbox.cpp | 2 ++ python/port/genhdr/qstrdefs.in.h | 4 +++- python/port/mod/ion/modion.cpp | 16 ++++++++++++++++ python/port/mod/ion/modion.h | 2 ++ python/port/mod/ion/modion_table.cpp | 12 ++++++++++++ 14 files changed, 56 insertions(+), 4 deletions(-) diff --git a/apps/code/catalog.de.i18n b/apps/code/catalog.de.i18n index 403c914a1..e66c309a7 100644 --- a/apps/code/catalog.de.i18n +++ b/apps/code/catalog.de.i18n @@ -105,6 +105,8 @@ PythonIsKeyDown = "Wahr, wenn die Taste k gedrückt ist" PythonBattery = "Rückgabe der Batteriespannung" PythonBatteryLevel = "Gibt den Batteriestand zurück" PythonBatteryIscharging = "Gibt zurück, ob die Batterie geladen wird" +PythonSetBrightness = "Helligkeitsstufe festlegen" +PythonGetBrightness = "Helligkeitsstufe abrufen" PythonKandinskyFunction = "Kandinsky-Modul Funktionspräfix" PythonLdexp = "Liefert x*(2**i), Inverse von frexp" PythonLength = "Länge eines Objekts" diff --git a/apps/code/catalog.en.i18n b/apps/code/catalog.en.i18n index 472ba88cc..651954ffb 100644 --- a/apps/code/catalog.en.i18n +++ b/apps/code/catalog.en.i18n @@ -90,6 +90,8 @@ PythonIsKeyDown = "Return True if the k key is down" PythonBattery = "Return battery voltage" PythonBatteryLevel = "Return battery level" PythonBatteryIscharging = "Return if battery is charging" +PythonSetBrightness = "Set brightness level" +PythonGetBrightness = "Get brightness level" PythonIsNaN = "Check if x is a NaN" PythonKandinskyFunction = "kandinsky module function prefix" PythonLdexp = "Return x*(2**i), inverse of frexp" diff --git a/apps/code/catalog.es.i18n b/apps/code/catalog.es.i18n index 4b7401d3e..c58b97e80 100644 --- a/apps/code/catalog.es.i18n +++ b/apps/code/catalog.es.i18n @@ -90,6 +90,8 @@ PythonIsKeyDown = "Return True if the k key is down" PythonBattery = "Rückgabe der Batteriespannung" PythonBatteryLevel = "Gibt den Batteriestand zurück" PythonBatteryIscharging = "Gibt zurück, ob die Batterie geladen wird" +PythonSetBrightness = "Establecer nivel de brillo" +PythonGetBrightness = "Obtener nivel de brillo" PythonIsNaN = "Check if x is a NaN" PythonKandinskyFunction = "kandinsky module function prefix" PythonLdexp = "Return x*(2**i), inverse of frexp" diff --git a/apps/code/catalog.fr.i18n b/apps/code/catalog.fr.i18n index 0fc97fd74..1e348cda3 100644 --- a/apps/code/catalog.fr.i18n +++ b/apps/code/catalog.fr.i18n @@ -90,6 +90,8 @@ PythonIsKeyDown = "Renvoie True si touche k enfoncée" PythonBattery = "Renvoie le voltage de la batterie" PythonBatteryLevel = "Renvoie le niveau de la batterie" PythonBatteryIscharging = "Chargement en cours" +PythonSetBrightness = "Définir le niveau de luminosité" +PythonGetBrightness = "Obtenir le niveau de luminosité" PythonIsNaN = "Teste si x est NaN" PythonKandinskyFunction = "Préfixe fonction module kandinsky" PythonLdexp = "Inverse de frexp : x*(2**i)" @@ -127,7 +129,7 @@ PythonRandrange = "Nombre dans range(start,stop)" PythonRangeStartStop = "Liste de start à stop-1" PythonRangeStop = "Liste de 0 à stop-1" PythonRect = "Conversion en algébrique" -PythonRemove = "Supprime le premier x de la liste" +PythonRemove = "Supprime le premier x de la liste" PythonReverse = "Inverse les éléments de la liste" PythonRound = "Arrondi à n décimales" PythonScatter = "Nuage des points (x,y)" diff --git a/apps/code/catalog.hu.i18n b/apps/code/catalog.hu.i18n index 136541807..c3c8cb00e 100644 --- a/apps/code/catalog.hu.i18n +++ b/apps/code/catalog.hu.i18n @@ -90,6 +90,8 @@ PythonIsKeyDown = "True-t válaszol ha a k gomb le van nyomva" PythonBattery = "Az akkumulátor feszültségének visszaadása" PythonBatteryLevel = "Az akkumulátor töltöttségi szintjének visszaadása" PythonBatteryIscharging = "Visszaadja, ha az akkumulátor töltődik" +PythonSetBrightness = "Fényerőszint beállítása" +PythonGetBrightness = "Get brightness level" PythonIsNaN = "Ellenörizze hogy x nem NaN" PythonKandinskyFunction = "kandinsky modul funkció elötag" PythonLdexp = "frexp ellentéte : x*(2**i)" diff --git a/apps/code/catalog.it.i18n b/apps/code/catalog.it.i18n index f525e7297..c029afabc 100644 --- a/apps/code/catalog.it.i18n +++ b/apps/code/catalog.it.i18n @@ -104,6 +104,8 @@ PythonIsKeyDown = "Restituisce True premendo tasto k" PythonBattery = "Restituisce la tensione della batteria" PythonBatteryLevel = "Restituisce il livello della batteria" PythonBatteryIscharging = "Restituisce se la batteria è in carica" +PythonSetBrightness = "Imposta livello di luminosità" +PythonGetBrightness = "Ottieni livello di luminosità" PythonIsNaN = "Testa se x è NaN" PythonKandinskyFunction = "Prefisso funzione modulo kandinsky" PythonLdexp = "Inversa di frexp : x*(2**i)" @@ -141,7 +143,7 @@ PythonRandrange = "Numero dentro il range(start, stop)" PythonRangeStartStop = "Lista da start a stop-1" PythonRangeStop = "Lista da 0 a stop-1" PythonRect = "Converte in coordinate algebriche" -PythonRemove = "Cancella la prima x dalla lista" +PythonRemove = "Cancella la prima x dalla lista" PythonReverse = "Inverte gli elementi della lista" PythonRound = "Arrotondato a n cifre decimali" PythonScatter = "Diagramma dispersione y in f. di x" diff --git a/apps/code/catalog.nl.i18n b/apps/code/catalog.nl.i18n index 2a1373594..66a9b9344 100644 --- a/apps/code/catalog.nl.i18n +++ b/apps/code/catalog.nl.i18n @@ -105,6 +105,8 @@ PythonIsKeyDown = "Geef True als k toets omlaag is" PythonBattery = "Return batterijspanning" PythonBatteryLevel = "Batterijniveau teruggeven" PythonBatteryIscharging = "Keer terug als de batterij wordt opgeladen" +PythonSetBrightness = "Set brightness level" +PythonGetBrightness = "Get brightness level" PythonIsNaN = "Controleer of x geen getal is" PythonKandinskyFunction = "kandinsky module voorvoegsel" PythonLdexp = "Geeft x*(2**i), inversie van frexp" @@ -149,7 +151,7 @@ PythonScatter = "Teken scatterplot van y versus x" PythonSeed = "Start willek. getallengenerator" PythonSetPixel = "Kleur pixel (x,y)" PythonShow = "Figuur weergeven" -PythonSin= "Sinus" +PythonSin = "Sinus" PythonSinh = "Sinus hyperbolicus" PythonSleep = "Stel executie voor t seconden uit" PythonLocalTime = "Zet tijd om in tuple" diff --git a/apps/code/catalog.pt.i18n b/apps/code/catalog.pt.i18n index ba1a27311..c7f8e2ab4 100644 --- a/apps/code/catalog.pt.i18n +++ b/apps/code/catalog.pt.i18n @@ -90,6 +90,8 @@ PythonIsKeyDown = "Devolve True se tecla k pressionada" PythonBattery = "Retornar a voltagem da bateria" PythonBatteryLevel = "Retornar nível de bateria" PythonBatteryIscharging = "Retorne se a bateria estiver carregando" +PythonSetBrightness = "Definir nível de brilho" +PythonGetBrightness = "Obter nível de brilho" PythonIsNaN = "Verificar se x é um NaN" PythonKandinskyFunction = "Prefixo da função do módulo kandinsky" PythonLdexp = "Devolve x*(2**i), inverso de frexp" diff --git a/apps/code/catalog.universal.i18n b/apps/code/catalog.universal.i18n index be9ca2f03..967125d72 100644 --- a/apps/code/catalog.universal.i18n +++ b/apps/code/catalog.universal.i18n @@ -163,6 +163,8 @@ PythonCommandIsKeyDown = "keydown(k)" PythonCommandBattery = "battery()" PythonCommandBatteryLevel = "battery_level()" PythonCommandBatteryIscharging = "battery_ischarging()" +PythonCommandSetBrightness = "set_brightness()" +PythonCommandGetBrightness = "get_brightness()" PythonCommandLdexp = "ldexp(x,i)" PythonCommandLength = "len(object)" PythonCommandLgamma = "lgamma(x)" diff --git a/apps/code/python_toolbox.cpp b/apps/code/python_toolbox.cpp index f08bdcacd..3f073401e 100644 --- a/apps/code/python_toolbox.cpp +++ b/apps/code/python_toolbox.cpp @@ -376,6 +376,8 @@ const ToolboxMessageTree IonModuleChildren[] = { ToolboxMessageTree::Leaf(I18n::Message::PythonCommandBattery, I18n::Message::PythonBattery), ToolboxMessageTree::Leaf(I18n::Message::PythonCommandBatteryLevel, I18n::Message::PythonBatteryLevel), ToolboxMessageTree::Leaf(I18n::Message::PythonCommandBatteryIscharging, I18n::Message::PythonBatteryIscharging), + ToolboxMessageTree::Leaf(I18n::Message::PythonCommandSetBrightness, I18n::Message::PythonSetBrightness), + ToolboxMessageTree::Leaf(I18n::Message::PythonCommandGetBrightness, I18n::Message::PythonGetBrightness), ToolboxMessageTree::Leaf(I18n::Message::IonSelector, I18n::Message::IonSelector) }; diff --git a/python/port/genhdr/qstrdefs.in.h b/python/port/genhdr/qstrdefs.in.h index 4e3b493ce..322b23c0c 100644 --- a/python/port/genhdr/qstrdefs.in.h +++ b/python/port/genhdr/qstrdefs.in.h @@ -9,7 +9,7 @@ * - "cat build/genhdr/qstrdefs.preprocessed.h|grep '^Q'|uniq". CAUTION: the * order is important, don't sort. * - Insert the result below in the MicroPython QSTRs section - * - remove "QSTR(urandom)" as we renamed it to random + * - remove "QSTR(urandom)" as we renamed it to random * - remove "QSTR(usys)" as we renamed it to sys */ // Global configuration @@ -346,6 +346,8 @@ Q(keydown) Q(battery) Q(battery_level) Q(battery_ischarging) +Q(set_brightness) +Q(get_brightness) Q(KEY_LEFT) Q(KEY_UP) Q(KEY_DOWN) diff --git a/python/port/mod/ion/modion.cpp b/python/port/mod/ion/modion.cpp index a631ebef8..c9694a69e 100644 --- a/python/port/mod/ion/modion.cpp +++ b/python/port/mod/ion/modion.cpp @@ -4,6 +4,8 @@ extern "C" { #include } #include +#include "apps/apps_container.h" +#include "apps/global_preferences.h" #include "port.h" mp_obj_t modion_keyboard_keydown(mp_obj_t key_o) { @@ -103,3 +105,17 @@ mp_obj_t modion_get_keys() { return result; } + +mp_obj_t modion_set_brightness(mp_obj_t brightness_mp){ + uint8_t brightness = static_cast(mp_obj_get_int(brightness_mp)); + GlobalPreferences::sharedGlobalPreferences()->setBrightnessLevel(brightness); + Ion::Backlight::setBrightness(brightness); + micropython_port_interrupt_if_needed(); + return mp_const_none; +} + +mp_obj_t modion_get_brightness(){ + uint8_t brightness = GlobalPreferences::sharedGlobalPreferences()->brightnessLevel(); + micropython_port_interrupt_if_needed(); + return mp_obj_new_int((int)brightness); +} diff --git a/python/port/mod/ion/modion.h b/python/port/mod/ion/modion.h index 88367300c..a1431ecf3 100644 --- a/python/port/mod/ion/modion.h +++ b/python/port/mod/ion/modion.h @@ -5,4 +5,6 @@ mp_obj_t modion_battery(); mp_obj_t modion_battery_level(); mp_obj_t modion_battery_ischarging(); mp_obj_t modion_get_keys(); +mp_obj_t modion_set_brightness(mp_obj_t brightness_mp); +mp_obj_t modion_get_brightness(); extern const mp_obj_type_t file_type; diff --git a/python/port/mod/ion/modion_table.cpp b/python/port/mod/ion/modion_table.cpp index aa496a955..dfe266abf 100644 --- a/python/port/mod/ion/modion_table.cpp +++ b/python/port/mod/ion/modion_table.cpp @@ -36,6 +36,16 @@ const mp_obj_fun_builtin_fixed_t modion_battery_ischarging_obj = { {(mp_fun_0_t)modion_battery_ischarging} }; +const mp_obj_fun_builtin_fixed_t modion_set_brightness_obj = { + {&mp_type_fun_builtin_1}, + {(mp_fun_0_t)modion_set_brightness} +}; + +const mp_obj_fun_builtin_fixed_t modion_get_brightness_obj = { + {&mp_type_fun_builtin_0}, + {(mp_fun_0_t)modion_get_brightness} +}; + 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) }, @@ -43,6 +53,8 @@ extern "C" const mp_rom_map_elem_t modion_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_battery_ischarging), MP_ROM_PTR(&modion_battery_ischarging_obj) }, { MP_ROM_QSTR(MP_QSTR_keydown), MP_ROM_PTR(&modion_keyboard_keydown_obj) }, { MP_ROM_QSTR(MP_QSTR_get_keys), MP_ROM_PTR(&modion_get_keys_obj) }, + { MP_ROM_QSTR(MP_QSTR_set_brightness), MP_ROM_PTR(&modion_set_brightness_obj) }, + { MP_ROM_QSTR(MP_QSTR_get_brightness), MP_ROM_PTR(&modion_get_brightness_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) }, { MP_ROM_QSTR(MP_QSTR_KEY_DOWN), MP_OBJ_NEW_SMALL_INT(Ion::Keyboard::Key::Down) },