forked from Lephenixnoir/PythonExtra
pe: interrupt computations with AC/ON
This commit is contained in:
parent
bfa5de2cf9
commit
99f2156e5e
|
@ -14,6 +14,7 @@
|
|||
#include "shared/runtime/pyexec.h"
|
||||
|
||||
#include <gint/display.h>
|
||||
#include <gint/drivers/keydev.h>
|
||||
#include <gint/keyboard.h>
|
||||
#include <gint/fs.h>
|
||||
|
||||
|
@ -84,6 +85,50 @@ static bool py_file_filter(struct dirent const *ent)
|
|||
return strendswith(ent->d_name, ".py");
|
||||
}
|
||||
|
||||
static void shell_write_char(int c)
|
||||
{
|
||||
pyexec_event_repl_process_char(c);
|
||||
}
|
||||
static void shell_write_str(char const *str)
|
||||
{
|
||||
while(*str)
|
||||
pyexec_event_repl_process_char(*str++);
|
||||
}
|
||||
|
||||
static char *path_to_module(char const *path)
|
||||
{
|
||||
if(path[0] == '/')
|
||||
path++;
|
||||
|
||||
int i, n = strlen(path);
|
||||
char *module = malloc(n + 1);
|
||||
if(!module)
|
||||
return NULL;
|
||||
|
||||
for(i = 0; i < n; i++) {
|
||||
if(i == n - 3 && !strcmp(path + i, ".py"))
|
||||
break;
|
||||
module[i] = (path[i] == '/') ? '.' : path[i];
|
||||
}
|
||||
module[i] = 0;
|
||||
return module;
|
||||
}
|
||||
|
||||
/* Filter AC/ON push events asynchronously from the keyboard driver and
|
||||
interrupt MicroPython instead. */
|
||||
static bool async_filter(key_event_t ev)
|
||||
{
|
||||
if(mp_interrupt_char < 0)
|
||||
return true;
|
||||
if(ev.type == KEYEV_DOWN && ev.key == KEY_ACON) {
|
||||
/* This function is designed to be called asynchronously. */
|
||||
mp_sched_keyboard_interrupt();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
#if DEBUG
|
||||
|
@ -93,6 +138,8 @@ int main(int argc, char **argv)
|
|||
|
||||
//=== Init sequence ===//
|
||||
|
||||
keydev_set_async_filter(keydev_std(), async_filter);
|
||||
|
||||
pe_shell_console = console_create(8192);
|
||||
|
||||
/* Set up standard streams */
|
||||
|
|
|
@ -7,9 +7,7 @@
|
|||
|
||||
#include <gint/clock.h>
|
||||
#include <time.h>
|
||||
|
||||
/* Set the interrupt character in the terminal. */
|
||||
void mp_hal_set_interrupt_char(char c);
|
||||
#include "shared/runtime/interrupt_char.h"
|
||||
|
||||
/* Receive a single character from shell (blocking). */
|
||||
int mp_hal_stdin_rx_chr(void);
|
||||
|
|
Loading…
Reference in New Issue