// sets the default user settings void PREFERENCES::SetDefaultSettings() { TIniFile* storage = new TIniFile( ExtractFilePath( Application->ExeName ) + INIFILENAME_PREFERENCES ); try { storage->WriteInteger( "Various", "DefaultUserLevel", UserLevel ); #define WRITE_SCRIPT( name ) \ if( !mCmdlineSpecified[ name ] ) \ storage->WriteString( "Scripts", #name, Script[ name ] ); WRITE_SCRIPT( AfterModulesConnected ); WRITE_SCRIPT( OnExit ); WRITE_SCRIPT( OnSetConfig ); WRITE_SCRIPT( OnResume ); WRITE_SCRIPT( OnSuspend ); WRITE_SCRIPT( OnStart ); #define WRITE_BUTTON( number ) \ storage->WriteString( "Buttons", "Button" #number "Name", Buttons[ number ].Name ); \ storage->WriteString( "Buttons", "Button" #number "Cmd", Buttons[ number ].Cmd ); WRITE_BUTTON( 1 ); WRITE_BUTTON( 2 ); WRITE_BUTTON( 3 ); WRITE_BUTTON( 4 ); } catch(...) {} delete storage; }
static u32 WII_Run(void *par) { GF_BitStream *bs; char *buf; u32 i, buf_size, count, scan_delay; const char *opt; GF_InputSensorDevice *ifce = (GF_InputSensorDevice *)par; GF_WiiMote *wii = (GF_WiiMote *)ifce->udta; scan_delay = 5; opt = gf_modules_get_option((GF_BaseInterface*)ifce, "WII", "ScanDelay"); if (opt) scan_delay = atoi(opt); /*locate the wiimotes*/ count = wiiuse_find(wii->wiimotes, wii->nb_wiimotes, scan_delay); GF_LOG(GF_LOG_INFO, GF_LOG_MMIO, ("[Wii] Found %d wiimotes\n", count)); count = wiiuse_connect(wii->wiimotes, wii->nb_wiimotes); if (count) { GF_LOG(GF_LOG_INFO, GF_LOG_MMIO, ("[Wii] Connected to %d connected wiimotes\n", count)); } else { GF_LOG(GF_LOG_INFO, GF_LOG_MMIO, ("[Wii] Failed to connect to any wiimote\n")); } opt = gf_modules_get_option((GF_BaseInterface*)ifce, "WII", "MotionSensing"); /*enable motion sensing*/ if (!opt || !strcmp(opt, "yes")) { Float smooth_alpha = 0.5; Float ori_threshold = 10.0; opt = gf_modules_get_option((GF_BaseInterface*)ifce, "WII", "OrientationThreshold"); if (opt) ori_threshold = (Float) atof(opt); opt = gf_modules_get_option((GF_BaseInterface*)ifce, "WII", "SmoothAlpha"); if (opt) { smooth_alpha = (Float) atof(opt); if (smooth_alpha<0) smooth_alpha = 0.5; else if (smooth_alpha>1.0) smooth_alpha=0.5; } GF_LOG(GF_LOG_INFO, GF_LOG_MMIO, ("[Wii] Enabling motion sensing - Alpha smoothing %f - Orientation Threshold %f\n", smooth_alpha, ori_threshold)); for (i=0; i<count; i++) { wiiuse_motion_sensing(wii->wiimotes[i], 1); wiiuse_set_smooth_alpha(wii->wiimotes[i],smooth_alpha); wiiuse_set_orient_threshold(wii->wiimotes[i], ori_threshold); } } while (wii->running) { count = wiiuse_poll(wii->wiimotes, wii->nb_wiimotes); if (!count) { continue; } for (i=0; i<count; i++) { struct wiimote_t* wm = wii->wiimotes[i]; switch (wm->event) { case WIIUSE_EVENT:/* A generic event occured on the wiimote. */ /*create the data frame*/ bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); /*if not the same wiimote write the UID*/ if (wii->prev_id != wm->unid) { gf_bs_write_int(bs, 1, 1); gf_bs_write_int(bs, wm->unid, 32); wii->prev_id = wm->unid; } else { gf_bs_write_int(bs, 0, 1); } /*write buttons state*/ WRITE_BUTTON(WIIMOTE_BUTTON_ONE); WRITE_BUTTON(WIIMOTE_BUTTON_TWO); WRITE_BUTTON(WIIMOTE_BUTTON_A); WRITE_BUTTON(WIIMOTE_BUTTON_B); WRITE_BUTTON(WIIMOTE_BUTTON_MINUS); WRITE_BUTTON(WIIMOTE_BUTTON_HOME); WRITE_BUTTON(WIIMOTE_BUTTON_PLUS); WRITE_BUTTON(WIIMOTE_BUTTON_LEFT); WRITE_BUTTON(WIIMOTE_BUTTON_RIGHT); WRITE_BUTTON(WIIMOTE_BUTTON_DOWN); WRITE_BUTTON(WIIMOTE_BUTTON_UP); /*write yaw-pitch-roll - FIXME: wiiuse seems to output NaN in these values upon init*/ gf_bs_write_int(bs, 1, 1); gf_bs_write_float(bs, WII_PI * wm->orient.yaw / 24 ); gf_bs_write_float(bs, WII_PI * wm->orient.pitch / 180); gf_bs_write_float(bs, WII_PI * wm->orient.roll / 180); /*write gravity - FIXME: wiiuse seems to output NaN in these values upon init*/ gf_bs_write_int(bs, 1, 1); gf_bs_write_float(bs, wm->gforce.x); gf_bs_write_float(bs, wm->gforce.y); gf_bs_write_float(bs, wm->gforce.z); gf_bs_align(bs); gf_bs_get_content(bs, &buf, &buf_size); gf_bs_del(bs); ifce->DispatchFrame(ifce, buf, buf_size); gf_free(buf); break; case WIIUSE_STATUS: /*A status report was obtained from the wiimote. */ break; case WIIUSE_DISCONNECT:/*The wiimote disconnected. */ break; case WIIUSE_READ_DATA:/* Data was returned that was previously requested from the wiimote ROM/registers. */ break; case WIIUSE_NUNCHUK_INSERTED: case WIIUSE_NUNCHUK_REMOVED: case WIIUSE_CLASSIC_CTRL_INSERTED: case WIIUSE_CLASSIC_CTRL_REMOVED: case WIIUSE_GUITAR_HERO_3_CTRL_INSERTED: case WIIUSE_GUITAR_HERO_3_CTRL_REMOVED: break; } } } return 0; }