-
Notifications
You must be signed in to change notification settings - Fork 6
/
upython.c
68 lines (50 loc) · 1.57 KB
/
upython.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <furi.h>
#include <storage/storage.h>
#include <mp_flipper_runtime.h>
#include <mp_flipper_compiler.h>
#include "upython.h"
volatile Action action = ActionNone;
FuriString* file_path = NULL;
volatile FuriThreadStdoutWriteCallback stdout_callback = NULL;
static void write_to_log_output(const char* data, size_t size) {
furi_log_tx((const uint8_t*)data, size);
}
void upython_reset_file_path() {
furi_string_set(file_path, APP_ASSETS_PATH("upython"));
}
int32_t upython(void* args) {
upython_cli_register(args);
do {
switch(action) {
case ActionNone:
action = upython_splash_screen();
break;
case ActionOpen:
if(upython_select_python_file(file_path)) {
stdout_callback = write_to_log_output;
action = ActionExec;
} else {
upython_reset_file_path();
action = ActionNone;
}
break;
case ActionRepl:
break;
case ActionExec:
furi_thread_set_stdout_callback(stdout_callback);
upython_file_execute(file_path);
upython_reset_file_path();
action = ActionNone;
furi_thread_set_stdout_callback(stdout_callback = NULL);
break;
case ActionExit:
action = upython_confirm_exit_action() ? ActionTerm : ActionNone;
break;
case ActionTerm:
break;
}
furi_delay_ms(1);
} while(action != ActionTerm);
upython_cli_unregister(args);
return 0;
}