I did a ugly picoc port to ML before, base on a very old version of ML.
Testing on my 50D is OK.
How can I upload an attachment ?
#ifdef CONFIG_PICOC
/* script functions */
#define SCRIPT_NUM 5
#define LINE_BUF_SIZE 30
#define PICOC_HEAP_SIZE (30*1024)
char *script_list[SCRIPT_NUM]={NULL};
int script_selected=0;
int script_cnt = 0;
/*
int * script_read_line(const char *script_source, char *buf, int line)
{
int line_pos = 0;
char *pos, *line_start;
line_start = pos = script_source;
while (*pos != '\0') {
if (*pos == '\n') {
if (++line_pos == line) {
my_memcpy(buf, line_start,pos-line_start);
buf[pos-line_start] = '\0';
return pos-line_start;
} else {
line_start = pos + 1;
}
}
pos++;
}
return 0;
}
*/
/* modify from is_valid_cropmark_filename */
int is_valid_script_filename(char* filename)
{
int n = strlen(filename);
if ((n > 2) && (streq(filename + n - 2, ".C") || streq(filename + n - 2, ".c")) && (filename[0] != '.') && (filename[0] != '_'))
return 1;
return 0;
}
static void find_scripts(void)
{
char buf[LINE_BUF_SIZE];
struct fio_file file;
struct fio_dirent * dirent = FIO_FindFirstEx( CARD_DRIVE "scripts/", &file );
if( IS_ERROR(dirent) )
{
NotifyBox(2000, "Scripts dir missing" );
msleep(100);
NotifyBox(2000, "Please copy all ML files!" );
return;
}
script_cnt = 0;
do {
if ((file.mode & 0x20) && is_valid_script_filename(file.name)) {
/* get the full path of the script */
snprintf(buf,LINE_BUF_SIZE,"%s%s%s%c",CARD_DRIVE,"scripts/",file.name,'\0');
int len = strlen(buf);
script_list[script_cnt] = (char *)AllocateMemory(len+1);
strncpy(script_list[script_cnt], buf, len);
script_list[script_cnt++][len] = '\0';
if (script_cnt >= SCRIPT_NUM)
break;
}
} while( FIO_FindNextEx( dirent, &file ) == 0);
FIO_CleanupAfterFindNext_maybe(dirent);
}
static void
script_select_display( void * priv, int x, int y, int selected )
{
bmp_printf(
selected ? MENU_FONT_SEL : MENU_FONT,
x, y,
"Scripts(%d/%d): %s",script_selected,script_cnt,
script_selected==0?"OFF":(script_list[script_selected-1]+strlen(CARD_DRIVE"scripts/"))
);
}
static void script_select(void)
{
if (script_cnt == 0)
find_scripts();
if (++script_selected > script_cnt)
script_selected = 0;
}
void run_script(const char *script)
{
extern int PicocExitBuf[];
PicocInitialise(PICOC_HEAP_SIZE);
PicocExitBuf[40] = 0;
setjmp(PicocExitBuf);
PlatformScanFile(script_list[script_selected-1]);
PicocCleanup();
}
void script_run_fun(void)
{
if (script_selected == 0)
return;
task_create("run_script", 0x1c, 0, run_script, 0);
}
/* end script functions */
#endif
//for the menu
#ifdef CONFIG_PICOC
{
.priv = &script_selected,
.display = script_select_display,
.select = script_select,
},
{
.priv = "Run script",
.display = menu_print,
.select = script_run_fun,
},
#endif