Skip to content

Commit fca9c66

Browse files
committed
added Status submodule to shared-bindings/supervisor; issue adafruit#544
1 parent 3642fcb commit fca9c66

3 files changed

Lines changed: 126 additions & 4 deletions

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_SUPERVISOR_STATUS_H
28+
#define MICROPY_INCLUDED_SHARED_BINDINGS_SUPERVISOR_STATUS_H
29+
30+
#include <stdbool.h>
31+
#include "py/obj.h"
32+
33+
//#include "common-hal/supervisor/Status.h"
34+
35+
const mp_obj_type_t supervisor_status_type;
36+
37+
bool common_hal_get_serial_connected(void);
38+
39+
//TODO: placeholders for future functions
40+
//bool common_hal_get_repl_active(void);
41+
//bool common_hal_get_usb_enumerated(void);
42+
43+
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_SUPERVISOR_STATUS_H

shared-bindings/supervisor/__init__.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
#include "py/runtime.h"
2828
#include "supervisor/shared/autoreload.h"
2929
#include "supervisor/shared/rgb_led_status.h"
30-
30+
31+
#include "shared-bindings/supervisor/Status.h"
3132
//| :mod:`supervisor` --- Supervisor settings
3233
//| =================================================
3334
//|
@@ -75,9 +76,10 @@ MP_DEFINE_CONST_FUN_OBJ_1(supervisor_set_rgb_status_brightness_obj, supervisor_s
7576

7677
STATIC const mp_rom_map_elem_t supervisor_module_globals_table[] = {
7778
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_supervisor) },
78-
{ MP_OBJ_NEW_QSTR(MP_QSTR_enable_autoreload), MP_ROM_PTR(&supervisor_enable_autoreload_obj)},
79-
{ MP_OBJ_NEW_QSTR(MP_QSTR_disable_autoreload), MP_ROM_PTR(&supervisor_disable_autoreload_obj)},
80-
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_rgb_status_brightness), MP_ROM_PTR(&supervisor_set_rgb_status_brightness_obj)},
79+
{ MP_OBJ_NEW_QSTR(MP_QSTR_enable_autoreload), MP_ROM_PTR(&supervisor_enable_autoreload_obj) },
80+
{ MP_OBJ_NEW_QSTR(MP_QSTR_disable_autoreload), MP_ROM_PTR(&supervisor_disable_autoreload_obj) },
81+
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_rgb_status_brightness), MP_ROM_PTR(&supervisor_set_rgb_status_brightness_obj) },
82+
{ MP_ROM_QSTR(MP_QSTR_Status), MP_ROM_PTR(&supervisor_status_type) },
8183
};
8284

8385
STATIC MP_DEFINE_CONST_DICT(supervisor_module_globals, supervisor_module_globals_table);

0 commit comments

Comments
 (0)