int main(int argc, const char* argv[]) { signal(SIGINT, intHandler); sensors_initialize(&keep_running); motors_initialize(); command_initialize(); ball_initialize(); for (int i=3; i>0; i--) { printf("Still %d seconds left to make your choice\n", i); sleep(1); } if (sensors_is_button_pressed(BUTTON_CODE_UP)) { // // Test scenario // if (sensors_is_button_pressed(BUTTON_CODE_LEFT)) { execute(test_move); } else if (sensors_is_button_pressed(BUTTON_CODE_RIGHT)) { execute(test_rotate); } else if (sensors_is_button_pressed(BUTTON_CODE_DOWN)) { execute(test_shoot); } } else { // // Normal scenario // if (sensors_is_button_pressed(BUTTON_CODE_LEFT)) { // Run through maze execute(maze_execute); } if (sensors_is_button_pressed(BUTTON_CODE_RIGHT)) { // Throw balls execute(ball_execute); } } ball_terminate(); command_terminate(); motors_terminate(); sensors_terminate(&keep_running); return 0; }
int command_main(int argc, char *argv[]) { char *p; int size; int num = 0; char *cmd[COMMAND_WORD_NUM]; int cmd_len = 0; int i, j; send_use(SERIAL_DEFAULT_DEVICE); command_init( cmd ); file_init(); while (1) { send_write("command> "); /* プロンプト表示 */ /* コマンド格納バッファを0クリアする */ for( j = 0; j < COMMAND_WORD_NUM; j++ ){ memset( cmd[j], 0, COMMAND_WORD_LENGTH ); } /* コンソールからの受信文字列を受け取る */ kz_recv(MSGBOX_ID_CONSINPUT, &size, &p); p[size] = '\0'; /* 入力文字列を分解する */ if( ( num = command_split( p, cmd ) ) == 0 ){ send_write("input nothing\n"); continue; } /* コマンドの実行 */ cmd_len = strlen( cmd[0] ); for( i = 0; command_table[i].cmd != NULL; i++ ){ if( !strncmp( cmd[0], command_table[i].cmd, (cmd_len>command_table[i].size?cmd_len:command_table[i].size) ) ){ command_table[i].func( num, cmd ); break; } } if( command_table[i].cmd == NULL ){ send_write("unknown.\n"); } kz_kmfree(p); } command_terminate( cmd ); return 0; }