-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathscript.c
123 lines (95 loc) · 2.13 KB
/
script.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/** \file
* Python Script loader.
*/
#include "dryos.h"
#include "menu.h"
#include "tasks.h"
#include "bmp.h"
#include "pm.h" // PyMite
static void
list_files( void * priv )
{
struct fio_file file;
struct fio_dirent * dirent = FIO_FindFirstEx( "A:/", &file );
if( IS_ERROR(dirent) )
{
bmp_printf( FONT_LARGE, 40, 40,
"%s: dirent=%08x!",
__func__,
(unsigned) dirent
);
return;
}
unsigned x = 0;
unsigned y = 40;
int count = 0;
bmp_printf( FONT_SMALL, x, y, "Dirent: %08x", (unsigned) dirent );
do {
y += fontspec_height( FONT_SMALL );
bmp_printf( FONT_SMALL, x, y,
"%02x %08x %08x %08x '%s'",
file.mode,
file.off_0x04,
file.timestamp,
file.off_0x0c,
file.name
);
} while( FIO_FindNextEx( dirent, &file ) == 0 );
}
static void
run_script( void * priv )
{
gui_stop_menu();
msleep( 500 );
const char * filename = "A:/test.pym";
size_t size;
if( FIO_GetFileSize( filename, &size ) != 0 )
goto getfilesize_fail;
DebugMsg( DM_MAGIC, 3, "File '%s' size %d bytes",
filename,
size
);
uint8_t * buf = malloc( size );
if( !buf )
{
DebugMsg( DM_MAGIC, 3, "%s: malloc failed", filename );
goto malloc_fail;
}
size_t rc = read_file( filename, buf, size );
if( rc == -1 )
goto read_fail;
img_appendToPath( MEMSPACE_PROG, buf );
//free( buf );
bmp_printf( FONT_SMALL, 0, 300, "Starting script" );
pm_run( (uint8_t*) "test" );
return;
read_fail:
free( buf );
malloc_fail:
getfilesize_fail:
return;
}
static struct menu_entry file_menus[] = {
{
.priv = "List files",
.display = menu_print,
.select = list_files,
},
{
.priv = "Run test",
.display = menu_print,
.select = run_script,
},
};
static void
script_init( void )
{
menu_add( "Script", file_menus, COUNT(file_menus) );
//msleep( 5000 );
//bmp_printf( FONT_SMALL, 0, 300, "Starting scripting" );
extern const unsigned char usrlib_img[];
pm_init( MEMSPACE_PROG, usrlib_img );
// Do anything necessary to start the main task
pm_run( (uint8_t*) "main" );
}
INIT_FUNC( __FILE__, script_init );