mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[python] Clean the time module
- Export micropython_port_should_interrupt and micropython_port_interruptible_msleep in Emscripten - Make micropython_port_interruptible_msleep available in a helper
This commit is contained in:
@@ -29,3 +29,10 @@ bool micropython_port_should_interrupt() {
|
||||
Ion::Keyboard::Key interruptKey = static_cast<Ion::Keyboard::Key>(mp_interrupt_char);
|
||||
return scan.keyDown(interruptKey);
|
||||
}
|
||||
|
||||
void micropython_port_interruptible_msleep(uint32_t delay) {
|
||||
uint32_t start = Ion::Timing::millis();
|
||||
while (Ion::Timing::millis() - start < delay && !micropython_port_should_interrupt()) {
|
||||
Ion::Timing::msleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,13 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
void micropython_port_vm_hook_loop();
|
||||
bool micropython_port_should_interrupt();
|
||||
void micropython_port_interruptible_msleep(uint32_t delay);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -2,26 +2,19 @@ extern "C" {
|
||||
#include "modtime.h"
|
||||
}
|
||||
#include <ion/timing.h>
|
||||
|
||||
#include "py/smallint.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
static void delay_ms(mp_uint_t delay) {
|
||||
uint32_t start = Ion::Timing::millis();
|
||||
while (Ion::Timing::millis() - start < delay && !micropython_port_should_interrupt()) {
|
||||
Ion::Timing::msleep(1);
|
||||
}
|
||||
}
|
||||
#include "../../helpers.h"
|
||||
#include <py/smallint.h>
|
||||
#include <py/runtime.h>
|
||||
|
||||
mp_obj_t modtime_sleep(mp_obj_t seconds_o) {
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
delay_ms((mp_uint_t)(1000 * mp_obj_get_float(seconds_o)));
|
||||
micropython_port_interruptible_msleep(1000 * mp_obj_get_float(seconds_o));
|
||||
#else
|
||||
delay_ms(1000 * mp_obj_get_int(seconds_o));
|
||||
micropython_port_interruptible_msleep(1000 * mp_obj_get_int(seconds_o));
|
||||
#endif
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t modtime_monotonic(void) {
|
||||
mp_obj_t modtime_monotonic() {
|
||||
return mp_obj_new_float(Ion::Timing::millis() / 1000.0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user