예제 #1
0
void quit_menu(struct menu *self)
{
	if (self->entry != self->quit_entry) {
		leave_menu_entry(self);
		self->entry = self->quit_entry;
		enter_menu_entry(self);
	}
	select_menu_entry(self);
}
예제 #2
0
ER application_load_menu() {
	load_success = false;
	show_cli_menu(&climenu_main);
	const CliMenuEntry *cme = select_menu_entry(&climenu_main);
	if(cme != NULL && cme->handler != NULL) {
		if (try_acquire_mmcsd() == E_OK) {
			cme->handler(cme->exinf);
			if (load_success) return E_OK; // MMCSD will be released on unloading
			release_mmcsd();
		} else {
			show_message_box("Error", "Please eject USB");
		}
	}
	return E_PAR;
}
예제 #3
0
static void menu_controller_handle_key_pressed(struct menu *menu,
					       enum controller_key key)
{
	switch (key) {
	case CTRLK_UP:
		previous_menu_entry(menu);
		break;
	case CTRLK_DOWN:
		next_menu_entry(menu);
		break;
	case CTRLK_RETURN:
	case CTRLK_ENTER:
		select_menu_entry(menu);
		break;
	case CTRLK_ESCAPE:
		quit_menu(menu);
		break;
	default:
		break;
	}
}
예제 #4
0
static
void test_sd_loader(intptr_t unused) {
#define TMAX_FILE_NUM (100)

	static FILINFO fileinfos[TMAX_FILE_NUM];
	static char    filenames[TMAX_FILE_NUM][_MAX_LFN + 1];
	for (int i = 0; i < TMAX_FILE_NUM; ++i) {
		fileinfos[i].lfname = filenames[i];
		fileinfos[i].lfsize = _MAX_LFN + 1;
	}

	int filenos = 0;

	// Open directory
	static DIR dir;
    FRESULT fres = f_opendir(&dir, SD_APP_FOLDER);
	if (fres != FR_OK) {
		show_message_box("Error", "Open application folder '" SD_APP_FOLDER "' failed.");
//		syslog(LOG_ERROR, "%s(): Open application folder '%s' failed, FRESULT: %d.", __FUNCTION__, SD_APP_FOLDER, fres);
//		tslp_tsk(500);
		return;
	}
//	int dirid = ev3_filesystem_opendir(SD_APP_FOLDER);

	// Read directory
	while (filenos < TMAX_FILE_NUM && f_readdir(&dir, &fileinfos[filenos]) == FR_OK) {
		if (fileinfos[filenos].fname[0] == '\0') // No more file
			break;
		else if (!(fileinfos[filenos].fattrib & AM_DIR)) { // Normal file
			if (fileinfos[filenos].lfname[0] == '\0')
				strcpy(fileinfos[filenos].lfname, fileinfos[filenos].fname);

            // Check extension (hard-coded)
            static const char *non_app_exts[] = { ".rb", ".wav", NULL };
            const char *ext = strrchr(fileinfos[filenos].lfname, '.');
            if (ext != NULL) {
                bool_t not_app = false;
                for (const char **non_app_ext = non_app_exts; *non_app_ext != NULL; non_app_ext++)
                    if (strcasecmp(*non_app_ext, ext) == 0) {
                        not_app = true;
                        break;
                    }
                if (not_app) continue; // ignore this file
            }

			filenos++;
		}
	}
	if (f_closedir(&dir) != FR_OK) {
		show_message_box("Error", "Close application folder '" SD_APP_FOLDER "' failed.");
//		syslog(LOG_ERROR, "%s(): Close application folder '%s' failed.", __FUNCTION__, SD_APP_FOLDER);
//		tslp_tsk(500);
		return;
	}
#if 0
	while (filenos < TMAX_FILE_NUM && ev3_filesystem_readdir(dirid, &fileinfos[filenos]) == E_OK) {
		if (fileinfos[filenos].fname[0] != '\0') {
			filenos++;
		} else break;
	}
	ev3_filesystem_closedir(dirid);
#endif

	static CliMenuEntry entry_tab[TMAX_FILE_NUM + 1];
	for (int i = 0; i < filenos; ++i) {
		entry_tab[i].key = '1' + i;
		entry_tab[i].title = fileinfos[i].lfname;
		entry_tab[i].exinf = i;
	}
	entry_tab[filenos].key = 'Q';
	entry_tab[filenos].title = "Cancel";
	entry_tab[filenos].exinf = -1;

	static CliMenu climenu = {
		.title     = "EV3RT App Loader",
		.msg       = "Select app:",
		.entry_tab = entry_tab,
		.entry_num = sizeof(entry_tab) / sizeof(CliMenuEntry),
	};
	climenu.entry_num = filenos + 1;

	static char filepath[256 * 2];
	while(1) {
		fio_clear_screen();
		show_cli_menu(&climenu);
		const CliMenuEntry* cme = select_menu_entry(&climenu);
		if(cme != NULL) {
			switch(cme->exinf) {
			case -1:
				return;

			default: {
				strcpy(filepath, SD_APP_FOLDER);
				strcat(filepath, "/");
				strcat(filepath, fileinfos[cme->exinf].lfname);

				syslog(LOG_NOTICE, "Start to load the application file '%s'.", filepath);

				// Open
				static FIL fil;
				FRESULT res = f_open(&fil, filepath, FA_READ);
				assert(res == FR_OK);

				// Read
                uint32_t filesz = f_size(&fil);
                if (filesz > TMAX_APP_BINARY_SIZE) {
					show_message_box("Error", "Application is too large.");
                    return;
                }

				UINT br;
				res = f_read(&fil, app_binary_buf, filesz, &br);
                assert(res == FR_OK);
                assert(br == filesz);

				res = f_close(&fil);
				assert(res == FR_OK);

				syslog(LOG_NOTICE, "Loading file completed, file size: %d.", filesz);

				ER ercd = load_application(app_binary_buf, filesz);
				if (ercd == E_OK) {
					load_success = true;
					return;
                } else if (ercd == E_NOSPT) {
					show_message_box("Error", "App ver. before\n"PIL_VERSION_STRING" must be\nrecompiled.");
				} else {
					syslog(LOG_NOTICE, "Load application failed, ercd: %d.", ercd);
					show_message_box("Error", "Failed to load application.");
//					tslp_tsk(500);
				}
			}
			}
		}
	}
}

static
void test_serial_loader(intptr_t portid) {
	ER   ercd;
	SIZE filesz;

	syslog(LOG_NOTICE, "Start to receive an application file using ZMODEM protocol.");
	platform_pause_application(false); // Ensure the priority of Bluetooth  task
	ercd = zmodem_recv_file(portid, app_binary_buf, sizeof(app_binary_buf), &filesz);
	platform_pause_application(true); // Ensure the priority of Bluetooth  task

	if (ercd != E_OK) {
		syslog(LOG_NOTICE, "Receiving file failed, ercd: %d.", ercd);
		show_message_box("Error", "Receiving application file failed.");
//		tslp_tsk(500);
		return;
	}

	syslog(LOG_NOTICE, "Receiving file completed, file size: %d bytes", filesz);
	show_message_box("App Received", "Click the CENTER button to run.");

	ercd = load_application(app_binary_buf, filesz);
	if (ercd == E_OK) {
		load_success = true;
	} else {
		syslog(LOG_NOTICE, "Load application failed, ercd: %d.", ercd);
		show_message_box("Error", "Failed to load application.");
//		tslp_tsk(500);
	}
}
예제 #5
0
	static const CliMenuEntry entry_tab[] = {
		{ .key = '1', .title = "Motor port A", .exinf = EV3_PORT_A },
		{ .key = '2', .title = "Motor port B", .exinf = EV3_PORT_B },
		{ .key = '3', .title = "Motor port C", .exinf = EV3_PORT_C },
		{ .key = '4', .title = "Motor port D", .exinf = EV3_PORT_D },
		{ .key = 'Q', .title = "Cancel", .exinf = -1 },
	};

	static const CliMenu climenu = {
		.title     = "Select Port",
		.entry_tab = entry_tab,
		.entry_num = sizeof(entry_tab) / sizeof(CliMenuEntry),
	};

	show_cli_menu(&climenu, 0, MENU_FONT_HEIGHT * 0, MENU_FONT);
	const CliMenuEntry* cme = select_menu_entry(&climenu, 0, MENU_FONT_HEIGHT * 1, MENU_FONT);

#if 1
	return cme;
#else
	show_cli_menu(&climenu);

	return select_menu_entry(&climenu);
#endif
}

void connect_motor(intptr_t unused) {
	const CliMenuEntry* cme_port = NULL;
	while(cme_port == NULL) {
//		fio_clear_screen();
//		fprintf(fio, "--- Connect Motor ---\n");