コード例 #1
0
ファイル: CInput.cpp プロジェクト: iamnilay3/openlierox
void CInput::InitJoysticksTemp() {
	if(!bJoystickSupport) return;
	notes << "Initing joysticks temporary..." << endl;
	notes << "Amout of available joysticks: " << SDL_NumJoysticks() << endl;
	initJoystick(0, true);
	initJoystick(1, true);
}
コード例 #2
0
ファイル: input.c プロジェクト: ex/urquan-masters
int 
TFB_InitInput (int driver, int flags)
{
	(void)driver;
	(void)flags;

	SDL_EnableUNICODE(1);
	(void)SDL_GetKeyState (&num_keys);
	kbdstate = (int *)HMalloc (sizeof (int) * (num_keys + 1));
	

#ifdef HAVE_JOYSTICK
	initJoystick ();
#endif /* HAVE_JOYSTICK */

	in_character_mode = FALSE;
	resetKeyboardState ();

	/* Prepare the Virtual Controller system. */
	VControl_Init ();

	initKeyConfig ();
	
	VControl_ResetInput ();
	InputInitialized = TRUE;

	return 0;
}
コード例 #3
0
ファイル: qjoystick.cpp プロジェクト: DanTsai2014/rayaairbot
bool QJoystick::open(int stick)
{
  if ( isOpen() )
    close();

  if(SDL_NumJoysticks() == 0)
      return false;

  joystick = SDL_JoystickOpen(stick);
  if ( joystick ) {
    joystickNameSelected = stick + 1;
    numAxes = SDL_JoystickNumAxes(joystick);
    numButtons = SDL_JoystickNumButtons(joystick);
    numHats = SDL_JoystickNumHats(joystick);
    numTrackballs = SDL_JoystickNumBalls(joystick);
    qWarning("DEBUG: SDL joystick %d opened; axes = %d, buttons = %d, hats = %d, trackballs = %d", stick, numAxes, numButtons, numHats, numTrackballs);

    axis_old_values.clear();
    for(int i=0; i < numAxes; i++)
        axis_old_values.append(0);

    emit initJoystick(numAxes, numButtons, numHats, joystickNames.at(stick));
    joystickTimer.start(eventTimeout);
    return true;
  } else {
    qWarning("ERROR: couldn't open SDL joystick %d", stick);
    return false;
  }
}
コード例 #4
0
ファイル: ui.c プロジェクト: jeremysrand/a2bejwld
void initUI(void)
{
    bool optionsLoaded;
    bool mouseInitialized;
    
    initMachine();
    
    optionsLoaded = loadOptions();
    
    initGameEngine(&gCallbacks);
    mouseInitialized = initMouse(&gMouseCallbacks);
    
    // If we couldn't initialize a mouse and it was enabled on the options, then disable it.
    if ((!mouseInitialized) &&
        (gGameOptions.enableMouse)) {
        gGameOptions.enableMouse = false;
        gGameOptions.optionsSaved = false;
        
        // If there were no options loaded, then let's turn on the joystick instead.
        if (!optionsLoaded) {
            gGameOptions.enableJoystick = true;
        }
    }
    
    initJoystick(&gJoyCallbacks);
    
    if (gGameOptions.enableSound) {
        soundInit(gGameOptions.mockingBoardSlot, gGameOptions.enableSpeechChip);
    }
    
    if (!gGameOptions.optionsSaved) {
        saveOptions();
    }
}
コード例 #5
0
ファイル: input.c プロジェクト: Dalan94/Super_Martin
void initInput(Input *in)
{
    int i;

    for(i = 0; i<SDLK_LAST ; i++)
        in->key[i] = 0;

    in->quit = 0;
    in->space = 0;

    initJoystick(in);
}
コード例 #6
0
ファイル: ninepin.c プロジェクト: fourks/ninepin
int main(int argc, char *argv[])
{
  int dosfd, joyfd;
  fd_set rd, ex;

  
  /* FIXME - read CLI arguments */

  if (!geteuid())
    joyfd = initJoystick();
  else {
    fprintf(stderr, "Must be root to do GPIO for joystick\n");
    joyfd = -1;
  }
  
  dosfd = open("/dev/iec8", O_RDWR);
  if (dosfd < 0)
    fprintf(stderr, "Unable to open IEC device\n");

  for (; dosfd >= 0 || joyfd >= 0;) {
    FD_ZERO(&rd);
    if (joyfd >= 0)
      FD_SET(joyfd, &rd);
    if (dosfd >= 0)
      FD_SET(dosfd, &rd);
    ex = rd;
    select(NOFILE, &rd, NULL, &ex, NULL);

    if (FD_ISSET(joyfd, &rd))
      joystickHandleIO(joyfd);
    if (FD_ISSET(dosfd, &rd))
      dosHandleIO(dosfd);

    if (FD_ISSET(joyfd, &ex)) {
      fprintf(stderr, "Error with joystick\n");
      close(joyfd);
      joyfd = -1;
    }
    if (FD_ISSET(dosfd, &ex)) {
      fprintf(stderr, "Error with IEC\n");
      close(dosfd);
      dosfd = -1;
    }
  }
  
  exit(0);
}
コード例 #7
0
ファイル: CInput.cpp プロジェクト: iamnilay3/openlierox
///////////////////
// Setup
int CInput::Setup(const std::string& string)
{
	unsigned int n;

	m_EventName = string;
	resetEachFrame = true;

	// Check if it's a mouse
	if(string.substr(0,2) == "ms") {
		Type = INP_MOUSE;
		Data = atoi(string.substr(2).c_str());
		if( Data == 3 ) Data = 2;
		else if( Data == 2 ) Data = 3;
		return true;
	}

#ifdef HAVE_JOYSTICK
	// Check if it's a joystick #1
	// TODO: allow more joysticks
	if(string.substr(0,5) == "joy1_") {
		Type = INP_JOYSTICK1;
		Data = 0;

		// Make sure there is a joystick present
		if(SDL_NumJoysticks()<=0) {
			SetError("Could not open joystick1");
			return false;
		}

		// Open the joystick if it hasn't been already opened
		initJoystick(0, false);

		// Go through the joystick list
		for(n=0;n<sizeof(Joysticks) / sizeof(joystick_t);n++) {
			if(Joysticks[n].text == string) {
				Data = Joysticks[n].value;
				Extra = Joysticks[n].extra;
				return true;
			}
		}
	}
	
	// Check if it's a joystick #2
	if(string.substr(0,5) == "joy2_") {
		Type = INP_JOYSTICK2;
		Data = 0;

		// Make sure there is a joystick present
		if(SDL_NumJoysticks()<=1)
			return false;

		// Open the joystick if it hasn't been already opened
		initJoystick(1, false);

		// Go through the joystick list
		for(n=0;n<sizeof(Joysticks) / sizeof(joystick_t);n++) {
			if(Joysticks[n].text == string) {
				Data = Joysticks[n].value;
				Extra = Joysticks[n].extra;
				return true;
			}
		}
	}
#endif // HAVE_JOYSTICK


	// Must be a keyboard character
	Type = INP_KEYBOARD;
	Data = 0;

	// Go through the key list checking with piece of text it was
	for(n=0;n<sizeof(Keys) / sizeof(keys_t);n++) {
		if(Keys[n].text == string) {
			Data = Keys[n].value;
			return true;
		}
	}

	// Try if SDL knows the key
	for(n=0; n < SDLK_LAST; n++)  {
		if (string == SDL_GetKeyName((SDLKey)n))  {
			Data = n;
			return true;
		}
	}

	return false;
}
コード例 #8
0
ファイル: hardware.cpp プロジェクト: jharvey/rusefi
void initHardware(Logging *l) {
	efiAssertVoid(CUSTOM_IH_STACK, getRemainingStack(chThdGetSelfX()) > 256, "init h");
	sharedLogger = l;
	engine_configuration_s *engineConfiguration = engine->engineConfigurationPtr;
	efiAssertVoid(CUSTOM_EC_NULL, engineConfiguration!=NULL, "engineConfiguration");
	board_configuration_s *boardConfiguration = &engineConfiguration->bc;

	printMsg(sharedLogger, "initHardware()");
	// todo: enable protection. it's disabled because it takes
	// 10 extra seconds to re-flash the chip
	//flashProtect();

	chMtxObjectInit(&spiMtx);

#if EFI_HISTOGRAMS
	/**
	 * histograms is a data structure for CPU monitor, it does not depend on configuration
	 */
	initHistogramsModule();
#endif /* EFI_HISTOGRAMS */

	/**
	 * We need the LED_ERROR pin even before we read configuration
	 */
	initPrimaryPins();

	if (hasFirmwareError()) {
		return;
	}

#if EFI_INTERNAL_FLASH

	palSetPadMode(CONFIG_RESET_SWITCH_PORT, CONFIG_RESET_SWITCH_PIN, PAL_MODE_INPUT_PULLUP);

	initFlash(sharedLogger);
	/**
	 * this call reads configuration from flash memory or sets default configuration
	 * if flash state does not look right.
	 */
	if (SHOULD_INGORE_FLASH()) {
		engineConfiguration->engineType = DEFAULT_ENGINE_TYPE;
		resetConfigurationExt(sharedLogger, engineConfiguration->engineType PASS_ENGINE_PARAMETER_SUFFIX);
		writeToFlashNow();
	} else {
		readFromFlash();
	}
#else
	engineConfiguration->engineType = DEFAULT_ENGINE_TYPE;
	resetConfigurationExt(sharedLogger, engineConfiguration->engineType PASS_ENGINE_PARAMETER_SUFFIX);
#endif /* EFI_INTERNAL_FLASH */

#if EFI_HD44780_LCD
//	initI2Cmodule();
	lcd_HD44780_init(sharedLogger);
	if (hasFirmwareError())
		return;

	lcd_HD44780_print_string(VCS_VERSION);

#endif /* EFI_HD44780_LCD */

	if (hasFirmwareError()) {
		return;
	}

#if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__)
	initTriggerDecoder();
#endif

	bool isBoardTestMode_b;
	if (CONFIGB(boardTestModeJumperPin) != GPIO_UNASSIGNED) {
		efiSetPadMode("board test", CONFIGB(boardTestModeJumperPin),
		PAL_MODE_INPUT_PULLUP);
		isBoardTestMode_b = (!efiReadPin(CONFIGB(boardTestModeJumperPin)));

		// we can now relese this pin, it is actually used as output sometimes
		unmarkPin(CONFIGB(boardTestModeJumperPin));
	} else {
		isBoardTestMode_b = false;
	}

#if HAL_USE_ADC || defined(__DOXYGEN__)
	initAdcInputs(isBoardTestMode_b);
#endif

	if (isBoardTestMode_b) {
		// this method never returns
		initBoardTest();
	}

	initRtc();

	initOutputPins();

#if EFI_MAX_31855
	initMax31855(sharedLogger, getSpiDevice(CONFIGB(max31855spiDevice)), CONFIGB(max31855_cs));
#endif /* EFI_MAX_31855 */

#if EFI_CAN_SUPPORT
	initCan();
#endif /* EFI_CAN_SUPPORT */

//	init_adc_mcp3208(&adcState, &SPID2);
//	requestAdcValue(&adcState, 0);

#if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__)
	// todo: figure out better startup logic
	initTriggerCentral(sharedLogger);
#endif /* EFI_SHAFT_POSITION_INPUT */

	turnOnHardware(sharedLogger);


#if HAL_USE_SPI || defined(__DOXYGEN__)
	initSpiModules(boardConfiguration);
#endif

#if EFI_HIP_9011 || defined(__DOXYGEN__)
	initHip9011(sharedLogger);
#endif /* EFI_HIP_9011 */

#if EFI_FILE_LOGGING || defined(__DOXYGEN__)
	initMmcCard();
#endif /* EFI_FILE_LOGGING */

#if EFI_MEMS || defined(__DOXYGEN__)
	initAccelerometer(PASS_ENGINE_PARAMETER_SIGNATURE);
#endif
//	initFixedLeds();


#if EFI_BOSCH_YAW || defined(__DOXYGEN__)
	initBoschYawRateSensor();
#endif /* EFI_BOSCH_YAW */

	//	initBooleanInputs();

#if EFI_UART_GPS || defined(__DOXYGEN__)
	initGps();
#endif

#if EFI_SERVO
	initServo();
#endif

#if ADC_SNIFFER || defined(__DOXYGEN__)
	initAdcDriver();
#endif

#if HAL_USE_I2C || defined(__DOXYGEN__)
	addConsoleActionII("i2c", sendI2Cbyte);
#endif


//	USBMassStorageDriver UMSD1;

//	while (true) {
//		for (int addr = 0x20; addr < 0x28; addr++) {
//			sendI2Cbyte(addr, 0);
//			int err = i2cGetErrors(&I2CD1);
//			print("I2C: err=%x from %d\r\n", err, addr);
//			chThdSleepMilliseconds(5);
//			sendI2Cbyte(addr, 255);
//			chThdSleepMilliseconds(5);
//		}
//	}

#if EFI_VEHICLE_SPEED || defined(__DOXYGEN__)
	initVehicleSpeed(sharedLogger);
#endif

#if EFI_CDM_INTEGRATION
	cdmIonInit();
#endif

#if HAL_USE_EXT || defined(__DOXYGEN__)
	initJoystick(sharedLogger);
#endif

	calcFastAdcIndexes();

	printMsg(sharedLogger, "initHardware() OK!");
}
コード例 #9
0
void SDLInputState::handle() {
	InputState::handle();

	SDL_Event event;
	int bind_button = 0;
	bool joy_hat_event = false;

	/* Check for events */
	while (SDL_PollEvent (&event)) {

		if (dump_event) {
			std::cout << event << std::endl;
		}

		// grab symbol keys
		if (event.type == SDL_TEXTINPUT) {
			inkeys += event.text.text;
		}

		switch (event.type) {
			case SDL_MOUSEMOTION:
				if (!PlatformOptions.is_mobile_device) {
					mouse.x = event.motion.x;
					mouse.y = event.motion.y;

					if (!curs->show_cursor)
						render_device->showMouseCursor();
				}
				break;
			case SDL_MOUSEWHEEL:
				if (!PlatformOptions.is_mobile_device) {
					if (event.wheel.y > 0) {
						scroll_up = true;
					} else if (event.wheel.y < 0) {
						scroll_down = true;
					}
				}
				break;
			case SDL_MOUSEBUTTONDOWN:
				if (!PlatformOptions.is_mobile_device) {
					mouse.x = event.button.x;
					mouse.y = event.button.y;
					bind_button = (event.button.button + MOUSE_BIND_OFFSET) * (-1);
					for (int key=0; key<key_count; key++) {
						if (bind_button == binding[key] || bind_button == binding_alt[key]) {
							pressing[key] = true;
							un_press[key] = false;
						}
					}
				}
				break;
			case SDL_MOUSEBUTTONUP:
				if (!PlatformOptions.is_mobile_device) {
					mouse.x = event.button.x;
					mouse.y = event.button.y;
					bind_button = (event.button.button + MOUSE_BIND_OFFSET) * (-1);
					for (int key=0; key<key_count; key++) {
						if (bind_button == binding[key] || bind_button == binding_alt[key]) {
							un_press[key] = true;
						}
					}
					last_button = bind_button;
				}
				break;
			case SDL_WINDOWEVENT:
				if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
					resize_ticks = MAX_FRAMES_PER_SEC/4;
				}
				else if (PlatformOptions.is_mobile_device) {
					// detect restoring hidden Mobile app to bypass frameskip
					if (event.window.event == SDL_WINDOWEVENT_MINIMIZED) {
						logInfo("Minimizing app, saving...");
						save_load->saveGame();
						logInfo("Game saved");
						window_minimized = true;
						snd->pauseAll();
					}
					else if (event.window.event == SDL_WINDOWEVENT_RESTORED) {
						window_restored = true;
						snd->resumeAll();
					}
				}
				break;

			// Mobile touch events
			// NOTE Should these be limited to mobile only?
			case SDL_FINGERMOTION:
				if (PlatformOptions.is_mobile_device) {
					mouse.x = static_cast<int>((event.tfinger.x + event.tfinger.dx) * VIEW_W);
					mouse.y = static_cast<int>((event.tfinger.y + event.tfinger.dy) * VIEW_H);

					if (event.tfinger.dy > 0) {
						scroll_up = true;
					} else if (event.tfinger.dy < 0) {
						scroll_down = true;
					}
				}
				break;
			case SDL_FINGERDOWN:
				if (PlatformOptions.is_mobile_device) {
					touch_locked = true;
					mouse.x = static_cast<int>(event.tfinger.x * VIEW_W);
					mouse.y = static_cast<int>(event.tfinger.y * VIEW_H);
					pressing[MAIN1] = true;
					un_press[MAIN1] = false;
				}
				break;
			case SDL_FINGERUP:
				if (PlatformOptions.is_mobile_device) {
					touch_locked = false;
					un_press[MAIN1] = true;
					last_button = binding[MAIN1];
				}
				break;

			case SDL_KEYDOWN:
				for (int key=0; key<key_count; key++) {
					if (event.key.keysym.sym == binding[key] || event.key.keysym.sym == binding_alt[key]) {
						pressing[key] = true;
						un_press[key] = false;
					}
				}

				if (event.key.keysym.sym == SDLK_UP) pressing_up = true;
				if (event.key.keysym.sym == SDLK_DOWN) pressing_down = true;
				break;
			case SDL_KEYUP:
				for (int key=0; key<key_count; key++) {
					if (event.key.keysym.sym == binding[key] || event.key.keysym.sym == binding_alt[key]) {
						un_press[key] = true;
					}
				}
				last_key = event.key.keysym.sym;

				if (event.key.keysym.sym == SDLK_UP) pressing_up = false;
				if (event.key.keysym.sym == SDLK_DOWN) pressing_down = false;
				break;
				/*
				case SDL_JOYAXISMOTION:
					// Reading joystick from SDL_JOYAXISMOTION is slow. Joystick analog input is handled by SDL_JoystickGetAxis() now.
					break;
				*/
			case SDL_JOYHATMOTION:
				if (joy && SDL_JoystickInstanceID(joy) == event.jhat.which && ENABLE_JOYSTICK) {
					render_device->hideMouseCursor();
					joy_hat_event = true;
					switch (event.jhat.value) {
						case SDL_HAT_CENTERED:
							un_press[UP] = true;
							un_press[DOWN] = true;
							un_press[LEFT] = true;
							un_press[RIGHT] = true;
							break;
						case SDL_HAT_UP:
							pressing[UP] = true;
							un_press[UP] = false;
							pressing[DOWN] = false;
							lock[DOWN] = false;
							pressing[LEFT] = false;
							lock[LEFT] = false;
							pressing[RIGHT] = false;
							lock[RIGHT] = false;
							break;
						case SDL_HAT_DOWN:
							pressing[UP] = false;
							lock[UP] = false;
							pressing[DOWN] = true;
							un_press[DOWN] = false;
							pressing[LEFT] = false;
							lock[LEFT] = false;
							pressing[RIGHT] = false;
							lock[RIGHT] = false;
							break;
						case SDL_HAT_LEFT:
							pressing[UP] = false;
							lock[UP] = false;
							pressing[DOWN] = false;
							lock[DOWN] = false;
							pressing[LEFT] = true;
							un_press[LEFT] = false;
							pressing[RIGHT] = false;
							lock[RIGHT] = false;
							break;
						case SDL_HAT_RIGHT:
							pressing[UP] = false;
							lock[UP] = false;
							pressing[DOWN] = false;
							lock[DOWN] = false;
							pressing[LEFT] = false;
							lock[LEFT] = false;
							pressing[RIGHT] = true;
							un_press[RIGHT] = false;
							break;
						case SDL_HAT_LEFTUP:
							pressing[UP] = true;
							un_press[UP] = false;
							pressing[DOWN] = false;
							lock[DOWN] = false;
							pressing[LEFT] = true;
							un_press[LEFT] = false;
							pressing[RIGHT] = false;
							lock[RIGHT] = false;
							break;
						case SDL_HAT_LEFTDOWN:
							pressing[UP] = false;
							lock[UP] = false;
							pressing[DOWN] = true;
							un_press[DOWN] = false;
							pressing[LEFT] = true;
							un_press[LEFT] = false;
							pressing[RIGHT] = false;
							lock[RIGHT] = false;
							break;
						case SDL_HAT_RIGHTUP:
							pressing[UP] = true;
							un_press[UP] = false;
							pressing[DOWN] = false;
							lock[DOWN] = false;
							pressing[LEFT] = false;
							lock[LEFT] = false;
							pressing[RIGHT] = true;
							un_press[RIGHT] = false;
							break;
						case SDL_HAT_RIGHTDOWN:
							pressing[UP] = false;
							lock[UP] = false;
							pressing[DOWN] = true;
							un_press[DOWN] = false;
							pressing[LEFT] = false;
							lock[LEFT] = false;
							pressing[RIGHT] = true;
							un_press[RIGHT] = false;
							break;
					}
				}
				break;
			case SDL_JOYBUTTONDOWN:
				if (joy && SDL_JoystickInstanceID(joy) == event.jbutton.which && ENABLE_JOYSTICK) {
					for (int key=0; key<key_count; key++) {
						if (event.jbutton.button == binding_joy[key]) {
							render_device->hideMouseCursor();
							pressing[key] = true;
							un_press[key] = false;
						}
					}
				}
				break;
			case SDL_JOYBUTTONUP:
				if (joy && SDL_JoystickInstanceID(joy) == event.jbutton.which && ENABLE_JOYSTICK) {
					for (int key=0; key<key_count; key++) {
						if (event.jbutton.button == binding_joy[key]) {
							un_press[key] = true;
						}
						last_joybutton = event.jbutton.button;
					}
				}
				break;
			case SDL_JOYDEVICEADDED:
				if (!joystick_init) {
					joystick_init = true;
				}
				else {
					logInfo("SDLInputState: Joystick added.");
					joysticks_changed = true;
					initJoystick();
				}
				break;
			case SDL_JOYDEVICEREMOVED:
				logInfo("SDLInputState: Joystick removed.");
				joysticks_changed = true;
				ENABLE_JOYSTICK = false;
				initJoystick();
				break;
			case SDL_QUIT:
				done = 1;
				break;
			default:
				break;
		}
	}

	// joystick analog input
	if(ENABLE_JOYSTICK && joy_axis_num > 0 && !joy_hat_event) {
		std::vector<bool> joy_axis_pressed;
		joy_axis_pressed.resize(joy_axis_num*2, false);
		last_joyaxis = -1;

		for (int i=0; i<joy_axis_num*2; i++) {
			int axis = SDL_JoystickGetAxis(joy, i/2);

			joy_axis_deltas[i] = (axis - joy_axis_prev[i])/2;
			joy_axis_prev[i] = axis;

			if (i % 2 == 0) {
				if (axis < -JOY_DEADZONE)
					joy_axis_pressed[i] = true;
				else if (axis <= JOY_DEADZONE)
					joy_axis_pressed[i] = false;
			}
			else {
				if (axis > JOY_DEADZONE)
					joy_axis_pressed[i] = true;
				else if (axis >= -JOY_DEADZONE)
					joy_axis_pressed[i] = false;
			}
		}
		for (int i=0; i<joy_axis_num*2; i++) {
			int bind_axis = (i+JOY_AXIS_OFFSET) * (-1);
			for (int key=0; key<key_count; key++) {
				if (bind_axis == binding_joy[key]) {
					if (joy_axis_pressed[i]) {
						pressing[key] = true;
						un_press[key] = false;
					}
					else {
						if (pressing[key]) {
							un_press[key] = true;
						}
						pressing[key] = false;
						lock[key] = false;
					}
				}
			}

			if (joy_axis_pressed[i] && joy_axis_deltas[i] != 0) {
				render_device->hideMouseCursor();
				last_joyaxis = (i+JOY_AXIS_OFFSET) * (-1);
			}
		}
	}

	if (resize_ticks > 0) {
		resize_ticks--;
	}
	if (resize_ticks == 0) {
		resize_ticks = -1;
		window_resized = true;
		render_device->windowResize();
	}

	// this flag is used to guard against removing and then adding an already connected controller on startup
	// once this function runs once, it is assumed startup is finished
	if (!joystick_init)
		joystick_init = true;
}
コード例 #10
0
ファイル: Joystick.cpp プロジェクト: eiaeii/Tank
Joystick* Joystick::createJoystick(cocos2d::Vec2 oPos, float fRadius, cocos2d::Sprite* pJsSprite, cocos2d::Sprite* pJsBg, bool bFollowRole)
{
	auto joy = Joystick::create();
	joy->initJoystick(oPos, fRadius, pJsSprite, pJsBg, bFollowRole);
	return joy;
}