|
| 1 | +/* |
| 2 | + * This file is part of the MicroPython project, http://micropython.org/ |
| 3 | + * |
| 4 | + * The MIT License (MIT) |
| 5 | + * |
| 6 | + * Copyright (c) 2022 by Dan Halbert for Adafruit Industries |
| 7 | + * |
| 8 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | + * of this software and associated documentation files (the "Software"), to deal |
| 10 | + * in the Software without restriction, including without limitation the rights |
| 11 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | + * copies of the Software, and to permit persons to whom the Software is |
| 13 | + * furnished to do so, subject to the following conditions: |
| 14 | + * |
| 15 | + * The above copyright notice and this permission notice shall be included in |
| 16 | + * all copies or substantial portions of the Software. |
| 17 | + * |
| 18 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | + * THE SOFTWARE. |
| 25 | + */ |
| 26 | + |
| 27 | +#include <stdbool.h> |
| 28 | +#include "py/obj.h" |
| 29 | +#include "py/enum.h" |
| 30 | +#include "py/runtime.h" |
| 31 | +#include "py/objproperty.h" |
| 32 | +#include "shared-bindings/supervisor/StatusBar.h" |
| 33 | + |
| 34 | +//| class StatusBar: |
| 35 | +//| """Current status of runtime objects. |
| 36 | +//| |
| 37 | +//| Usage:: |
| 38 | +//| |
| 39 | +//| import supervisor |
| 40 | +//| |
| 41 | +//| supervisor.status_bar.console = False |
| 42 | +//| """ |
| 43 | +//| |
| 44 | + |
| 45 | +//| def __init__(self) -> None: |
| 46 | +//| """You cannot create an instance of `supervisor.StatusBar`. |
| 47 | +//| Use `supervisor.status_bar` to access the sole instance available.""" |
| 48 | +//| ... |
| 49 | +//| |
| 50 | + |
| 51 | +//| console: bool |
| 52 | +//| """Whether status bar information is sent over the console (REPL) serial connection, |
| 53 | +//| using OSC terminal escape codes that change the terminal's title. Default is ``True``. |
| 54 | +//| If set to ``False``, status bar will be cleared and then disabled. |
| 55 | +//| May be set in ``boot.py`` or later. |
| 56 | +//| """ |
| 57 | +//| |
| 58 | +STATIC mp_obj_t supervisor_status_bar_get_console(mp_obj_t self_in) { |
| 59 | + #if CIRCUITPY_STATUS_BAR |
| 60 | + supervisor_status_bar_obj_t *self = MP_OBJ_TO_PTR(self_in); |
| 61 | + return mp_obj_new_bool(shared_module_supervisor_status_bar_get_console(self)); |
| 62 | + #else |
| 63 | + mp_raise_NotImplementedError(NULL); |
| 64 | + #endif |
| 65 | +} |
| 66 | +MP_DEFINE_CONST_FUN_OBJ_1(supervisor_status_bar_get_console_obj, supervisor_status_bar_get_console); |
| 67 | + |
| 68 | +STATIC mp_obj_t supervisor_status_bar_set_console(mp_obj_t self_in, mp_obj_t state_in) { |
| 69 | + #if CIRCUITPY_STATUS_BAR |
| 70 | + supervisor_status_bar_obj_t *self = MP_OBJ_TO_PTR(self_in); |
| 71 | + shared_module_supervisor_status_bar_set_console(self, mp_obj_is_true(state_in)); |
| 72 | + return mp_const_none; |
| 73 | + #else |
| 74 | + mp_raise_NotImplementedError(NULL); |
| 75 | + #endif |
| 76 | +} |
| 77 | +MP_DEFINE_CONST_FUN_OBJ_2(supervisor_status_bar_set_console_obj, supervisor_status_bar_set_console); |
| 78 | + |
| 79 | +MP_PROPERTY_GETSET(supervisor_status_bar_console_obj, |
| 80 | + (mp_obj_t)&supervisor_status_bar_get_console_obj, |
| 81 | + (mp_obj_t)&supervisor_status_bar_set_console_obj); |
| 82 | + |
| 83 | +//| display: bool |
| 84 | +//| """Whether status bar information is displayed on the top line of the display. |
| 85 | +//| Default is ``True``. If set to ``False``, status bar will be cleared and then disabled. |
| 86 | +//| May be set in ``boot.py`` or later. Not available if `terminalio` is not available. |
| 87 | +//| """ |
| 88 | +//| |
| 89 | +STATIC mp_obj_t supervisor_status_bar_get_display(mp_obj_t self_in) { |
| 90 | + #if CIRCUITPY_STATUS_BAR && CIRCUITPY_TERMINALIO |
| 91 | + supervisor_status_bar_obj_t *self = MP_OBJ_TO_PTR(self_in); |
| 92 | + return mp_obj_new_bool(shared_module_supervisor_status_bar_get_display(self)); |
| 93 | + #else |
| 94 | + mp_raise_NotImplementedError(NULL); |
| 95 | + #endif |
| 96 | +} |
| 97 | +MP_DEFINE_CONST_FUN_OBJ_1(supervisor_status_bar_get_display_obj, supervisor_status_bar_get_display); |
| 98 | + |
| 99 | +STATIC mp_obj_t supervisor_status_bar_set_display(mp_obj_t self_in, mp_obj_t state_in) { |
| 100 | + #if CIRCUITPY_STATUS_BAR && CIRCUITPY_TERMINALIO |
| 101 | + supervisor_status_bar_obj_t *self = MP_OBJ_TO_PTR(self_in); |
| 102 | + shared_module_supervisor_status_bar_set_display(self, mp_obj_is_true(state_in)); |
| 103 | + return mp_const_none; |
| 104 | + #else |
| 105 | + mp_raise_NotImplementedError(NULL); |
| 106 | + #endif |
| 107 | +} |
| 108 | +MP_DEFINE_CONST_FUN_OBJ_2(supervisor_status_bar_set_display_obj, supervisor_status_bar_set_display); |
| 109 | + |
| 110 | +MP_PROPERTY_GETSET(supervisor_status_bar_display_obj, |
| 111 | + (mp_obj_t)&supervisor_status_bar_get_display_obj, |
| 112 | + (mp_obj_t)&supervisor_status_bar_set_display_obj); |
| 113 | + |
| 114 | + |
| 115 | +STATIC const mp_rom_map_elem_t supervisor_status_bar_locals_dict_table[] = { |
| 116 | + { MP_ROM_QSTR(MP_QSTR_console), MP_ROM_PTR(&supervisor_status_bar_console_obj) }, |
| 117 | + { MP_ROM_QSTR(MP_QSTR_display), MP_ROM_PTR(&supervisor_status_bar_display_obj) }, |
| 118 | +}; |
| 119 | + |
| 120 | +STATIC MP_DEFINE_CONST_DICT(supervisor_status_bar_locals_dict, supervisor_status_bar_locals_dict_table); |
| 121 | + |
| 122 | +const mp_obj_type_t supervisor_status_bar_type = { |
| 123 | + .base = { &mp_type_type }, |
| 124 | + .name = MP_QSTR_Status_Bar, |
| 125 | + .locals_dict = (mp_obj_dict_t *)&supervisor_status_bar_locals_dict, |
| 126 | +}; |
0 commit comments