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 2727#include <string.h>
2828
2929#include "py/obj.h"
30+ #include "py/runtime.h"
3031#include "shared-bindings/precise_time/__init__.h"
3132
3233//| :mod: `precise_time` --- integer time and timing related functions
@@ -54,10 +55,27 @@ STATIC mp_obj_t precise_time_monotonic(void) {
5455}
5556MP_DEFINE_CONST_FUN_OBJ_0 (precise_time_monotonic_obj , precise_time_monotonic );
5657
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+
5774STATIC const mp_rom_map_elem_t precise_time_module_globals_table [] = {
5875 { MP_ROM_QSTR (MP_QSTR__name__ ), MP_ROM_QSTR (MP_QSTR_precise_time ) },
5976
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 ) }
6179};
6280
6381STATIC 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