|
| 1 | +/* |
| 2 | + * This file is part of the MicroPython project, http://micropython.org/ |
| 3 | + * |
| 4 | + * The MIT License (MIT) |
| 5 | + * |
| 6 | + * Copyright (c) 2018 Michael Schroeder |
| 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/objproperty.h" |
| 29 | +#include "shared-bindings/supervisor/Status.h" |
| 30 | + |
| 31 | +//TODO: add USB, REPL to description once they're operational |
| 32 | +//| .. currentmodule:: status |
| 33 | +//| |
| 34 | +//| :class:`Status` --- Supervisor Status information |
| 35 | +//| ------------------------------------------------- |
| 36 | +//| |
| 37 | +//| Get current status of the serial connection. |
| 38 | +//| |
| 39 | +//| Usage:: |
| 40 | +//| |
| 41 | +//| import supervisor |
| 42 | +//| if supervisor.serial_connected: |
| 43 | +//| print("Hello World!") |
| 44 | +//| |
| 45 | + |
| 46 | +//| .. attribute:: serial_connected |
| 47 | +//| |
| 48 | +//| Returns the serial communication status (read-only) |
| 49 | +//| |
| 50 | +STATIC mp_obj_t supervisor_get_serial_connected(mp_obj_t self){ |
| 51 | + if (!common_hal_get_serial_connected()) { |
| 52 | + return mp_const_false; |
| 53 | + } |
| 54 | + else { |
| 55 | + return mp_const_true; |
| 56 | + } |
| 57 | +} |
| 58 | +MP_DEFINE_CONST_FUN_OBJ_1(supervisor_get_serial_connected_obj, supervisor_get_serial_connected); |
| 59 | + |
| 60 | +const mp_obj_property_t supervisor_serial_connected_obj = { |
| 61 | + .base.type = &mp_type_property, |
| 62 | + .proxy = {(mp_obj_t)&supervisor_get_serial_connected_obj, |
| 63 | + (mp_obj_t)&mp_const_none_obj, |
| 64 | + (mp_obj_t)&mp_const_none_obj}, |
| 65 | +}; |
| 66 | + |
| 67 | +STATIC const mp_rom_map_elem_t supervisor_status_locals_dict_table[] = { |
| 68 | + { MP_ROM_QSTR(MP_QSTR_serial_connected), MP_ROM_PTR(&supervisor_serial_connected_obj) }, |
| 69 | +}; |
| 70 | + |
| 71 | +STATIC MP_DEFINE_CONST_DICT(supervisor_status_locals_dict, supervisor_status_locals_dict_table); |
| 72 | + |
| 73 | +const mp_obj_type_t supervisor_status_type = { |
| 74 | + .base = { &mp_type_type }, |
| 75 | + .name = MP_QSTR_Status, |
| 76 | + .locals_dict = (mp_obj_t)&supervisor_status_locals_dict, |
| 77 | +}; |
0 commit comments