File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed
shared-bindings/precise_time Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change 27
27
#include <string.h>
28
28
29
29
#include "py/obj.h"
30
+ #include "py/runtime.h"
30
31
#include "shared-bindings/precise_time/__init__.h"
31
32
32
33
//| :mod: `precise_time` --- integer time and timing related functions
@@ -54,10 +55,27 @@ STATIC mp_obj_t precise_time_monotonic(void) {
54
55
}
55
56
MP_DEFINE_CONST_FUN_OBJ_0 (precise_time_monotonic_obj , precise_time_monotonic );
56
57
58
+ //| .. method:: sleep(milliseconds)
59
+ //|
60
+ //| Sleep for a given number of milliseconds.
61
+ //|
62
+ //| :param int seconds: the time to sleep in milliseconds
63
+ //|
64
+ STATIC mp_obj_t precise_time_sleep (mp_obj_t milliseconds_o ) {
65
+ int milliseconds = mp_obj_get_int (milliseconds_o );
66
+ if (milliseconds < 0 ) {
67
+ mp_raise_ValueError ("sleep length must be non-negative" );
68
+ }
69
+ common_hal_precise_time_delay_ms (milliseconds );
70
+ return mp_const_none ;
71
+ }
72
+ MP_DEFINE_CONST_FUN_OBJ_1 (precise_time_sleep_obj , precise_time_sleep );
73
+
57
74
STATIC const mp_rom_map_elem_t precise_time_module_globals_table [] = {
58
75
{ MP_ROM_QSTR (MP_QSTR__name__ ), MP_ROM_QSTR (MP_QSTR_precise_time ) },
59
76
60
- { MP_ROM_QSTR (MP_QSTR_monotonic ), MP_ROM_PTR (& precise_time_monotonic_obj ) }
77
+ { MP_ROM_QSTR (MP_QSTR_monotonic ), MP_ROM_PTR (& precise_time_monotonic_obj ) },
78
+ { MP_ROM_QSTR (MP_QSTR_sleep ), MP_ROM_PTR (& precise_time_sleep_obj ) }
61
79
};
62
80
63
81
STATIC MP_DEFINE_CONST_DICT (precise_time_module_globals , precise_time_module_globals_table );
You can’t perform that action at this time.
0 commit comments