void JoystickHandler::_ThreadFunc() { Gamepad_eventDispatcher()->registerForEvent(Gamepad_eventDispatcher(), GAMEPAD_EVENT_DEVICE_ATTACHED, _OnDeviceAttached, this); Gamepad_eventDispatcher()->registerForEvent(Gamepad_eventDispatcher(), GAMEPAD_EVENT_DEVICE_REMOVED, _OnDeviceRemoved, this); Gamepad_init(); //Gamepad_RunLoop(); }
GHID::GHID() { gid_ = g_NextId(); players.clear(); Gamepad_deviceAttachFunc(ghid_onConnected, (void *) 0x1); Gamepad_deviceRemoveFunc(ghid_onDisconnected, (void *) 0x2); Gamepad_buttonDownFunc(ghid_onButtonDown, (void *) 0x3); Gamepad_buttonUpFunc(ghid_onButtonUp, (void *) 0x4); Gamepad_axisMoveFunc(ghid_onAxisMoved, (void *) 0x5); Gamepad_init(); gevent_AddCallback(onEnterFrame, this); }
/* * Class: org_gamepad4j_desktop_GamepadJniWrapper * Method: natInit * Signature: ()V */ JNIEXPORT void JNICALL Java_org_gamepad4j_desktop_GamepadJniWrapper_natInit (JNIEnv *env, jobject obj) { printf("Initialize native Gamepad API.\n"); Gamepad_init(); }
//"initialization code is here, in its own function..." static void initGamepad() { Gamepad_eventDispatcher()->registerForEvent(Gamepad_eventDispatcher(), GAMEPAD_EVENT_DEVICE_ATTACHED, onDeviceAttached, NULL); Gamepad_eventDispatcher()->registerForEvent(Gamepad_eventDispatcher(), GAMEPAD_EVENT_DEVICE_REMOVED, onDeviceRemoved, NULL); Gamepad_init(); }
int main(int argc, char *argv[]) { #ifdef __MINGW32__ SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); // Set the timer resolution on Windows TIMECAPS tc; UINT wTimerRes; if(timeGetDevCaps(&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR) { std::cerr << "FATAL ERROR: Could not determine supported timer resolutions." << std::endl; return 1; } wTimerRes = std::min(std::max((UINT) tc.wPeriodMin, (UINT) TARGET_RESOLUTION), (UINT) tc.wPeriodMax); timeBeginPeriod(wTimerRes); #endif // Parse command line options with boost::program_options boost::program_options::options_description desc("Available options"); desc.add_options() ("help", "show help message") ("drone", boost::program_options::value<std::string>(), "set which drone to use (ARDrone2 or Bebop, default is ARDrone2)") ("script", boost::program_options::value<std::string>(), "load a python script") ("script-args", boost::program_options::value<std::vector<std::string>>()->multitoken(), "arguments for the python script") ("ip-address", boost::program_options::value<std::string>(), "an alternative IP address for the drone (default is 192.168.1.1 for AR.Drone 2.0 and 192.168.42.1 for Bebop)") ("stream-resolution", boost::program_options::value<std::string>(), "resolution for the live video stream (360P default, can be set to 720P)") ; boost::program_options::variables_map vm; boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm); boost::program_options::notify(vm); if(vm.count("help")) { std::cout << desc << std::endl; return 1; } drone_type drone_type = BEBOP; std::string ip_address = bebop::DEFAULT_IP; std::string stream_res = "360P"; // Detect which drone to use if(vm.count("drone")) { std::string drone_name = vm["drone"].as<std::string>(); std::transform(drone_name.begin(), drone_name.end(), drone_name.begin(), ::tolower); if(drone_name == "ardrone2") { std::cout << "Using AR.Drone 2.0" << std::endl; ip_address = ardrone2::DEFAULT_IP; drone_type = ARDRONE2; } else if(drone_name == "bebop") { std::cout << "Using Bebop Drone" << std::endl; ip_address = bebop::DEFAULT_IP; drone_type = BEBOP; } else { std::cout << "Drone not supported. Currently only Parrot's AR.Drone 2.0 and Bebop are supported." << std::endl; } } if(vm.count("ip-address")) { ip_address = vm["ip-address"].as<std::string>(); std::cout << "Drone IP address manually set to " << ip_address << std::endl; } else { std::cout << "Using default Drone IP address ("<< ip_address <<"). Use the --ip-address option to choose a different address." << std::endl; } if(vm.count("stream-resolution")) { stream_res = vm["stream-resolution"].as<std::string>(); } std::cout << "Starting AutoFlight...\n"; Gamepad_init(); Gamepad_detectDevices(); AutoFlight af(drone_type, ip_address); // TODO: Allow setting stream resolution /* if(stream_res == "720P") { af.ardrone2()->setDefaultLiveStreamCodec(ardrone2::config::codec::H264_720P); std::cout << "AR.Drone 2.0 live video stream resolution manually set to " << stream_res << std::endl; } */ QApplication gui(argc, argv); AFMainWindow w(&af); w.show(); if(vm.count("script")) { std::string script = vm["script"].as<std::string>(); std::vector<std::string> args; if(vm.count("script-args")) { args = vm["script-args"].as<std::vector<std::string>>(); } w.launchAutoScriptIDE(script, args); } gui.exec(); Gamepad_shutdown(); //Py_Finalize(); #ifdef __MINGW32__ timeEndPeriod(wTimerRes); #endif std::cout << "Closing...\n"; return 0; }