summaryrefslogtreecommitdiff
path: root/shared-bindings/time
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2020-02-07 10:24:11 -0500
committerDan Halbert <halbert@halwitz.org>2020-02-07 10:24:11 -0500
commitcbd519bfa6bb3e2f56a07e977c47159059f1fc8d (patch)
treeb4309b2faea29cbc6d441c580d295ff45389fc83 /shared-bindings/time
parent857d8ab40a6e4ef7d0cc78f481511070c1af15e3 (diff)
time.sleep() rounds to nearest msec
Diffstat (limited to 'shared-bindings/time')
-rw-r--r--shared-bindings/time/__init__.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/shared-bindings/time/__init__.c b/shared-bindings/time/__init__.c
index 2c1aebc2e..8d7f2f3fd 100644
--- a/shared-bindings/time/__init__.c
+++ b/shared-bindings/time/__init__.c
@@ -70,14 +70,16 @@ MP_DEFINE_CONST_FUN_OBJ_0(time_monotonic_obj, time_monotonic);
//|
STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) {
#if MICROPY_PY_BUILTINS_FLOAT
- float seconds = mp_obj_get_float(seconds_o);
+ mp_float_t seconds = mp_obj_get_float(seconds_o);
+ mp_float_t msecs = 1000.0f * seconds + 0.5f;
#else
- int seconds = mp_obj_get_int(seconds_o);
+ mp_int_t seconds = mp_obj_get_int(seconds_o);
+ mp_int_t msecs = 1000 * seconds;
#endif
if (seconds < 0) {
mp_raise_ValueError(translate("sleep length must be non-negative"));
}
- common_hal_time_delay_ms(1000 * seconds);
+ common_hal_time_delay_ms(msecs);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_obj, time_sleep);