コード例 #1
0
void Touchpanel_FT5X06::loop()
{
  uint8_t b;
  static uint8_t slowdown = 0;

  if(!power)
    return;

  // check INT pin of touch controller, when no touch press is active/detected
  if(mouseButtonState == 0)
  {
    slowdown++;
    if((slowdown > 8) || (digitalRead(INT_PIN) == 0)) // INT low -> new data
    {
      slowdown = 0;
    }
    else // INT high -> no new data
    {
      return;
    }
  }

  b = i2cReadByte(REG_STATE);
  //#if DEBUG > 2
  //  Serial.print(F("TP: state 0x"));
  //  Serial.println(b, HEX);
  //#endif
  if(b == STATE_WORK)
  {
    b = i2cReadByte(REG_TD_STATUS);
    if((b != 0) && (b != 255)) // no touch points on 0 and 255
    {
      nrPoints = b & 0x0F; //Bit3:0
      readTouchPoint(REG_TOUCH_1, &touch[0]);
      // no multi touch support at the moment
      //readTouchPoint(REG_TOUCH_2, &touch[1]);
      //readTouchPoint(REG_TOUCH_3, &touch[2]);
      //readTouchPoint(REG_TOUCH_4, &touch[3]);
      //readTouchPoint(REG_TOUCH_5, &touch[4]);

      #if DEBUG > 1
        Serial.print(F("TP: Points 0x"));
        Serial.print(nrPoints, HEX);
        Serial.print(F(" ID 0x"));
        Serial.print(touch[0].id, HEX);
        Serial.print(F(" Event 0x"));
        Serial.println(touch[0].event, HEX);
      #endif

      if(nrPoints >= 1 && touch[0].id == 0 && (touch[0].event == 0 || touch[0].event == 2)) // put down or contact
      {
        mouseX = touch[0].x * TOUCHMAX / (settings.data.screenWidth - 1);
        mouseY = touch[0].y * TOUCHMAX / (settings.data.screenHeight - 1);

        if(settings.data.x0 != 0) // add x correction
        {
          int16_t x = settings.data.x0 + mouseX;
          mouseX = x;
        }
        if(settings.data.y0 != 0) // add y correction
        {
          int16_t y = settings.data.y0 + mouseY;
          mouseY = y;
        }

        b = i2cReadByte(REG_GESTURE); // GESTURE_MOVE_UP GESTURE_MOVE_LEFT GESTURE_MOVE_DOWN GESTURE_MOVE_RIGHT GESTURE_ZOOM_IN GESTURE_ZOOM_OUT
        #if DEBUG > 1
          Serial.print(F("TP: Gesture 0x"));
          Serial.println(b, HEX);
        #endif
        if(b == GESTURE_ZOOM_IN)
          mouseZoom = 1;
        else if(b == GESTURE_ZOOM_OUT)
          mouseZoom = -1;
        else
          mouseZoom = 0;

        mouseButtonDown();
      }
      else
      {
        mouseButtonUp();
      }
    }
    else
    {
      mouseButtonUp();
    }
  }
}
コード例 #2
0
ファイル: Event.cpp プロジェクト: enigma-dev/enigma-dev
int SDL_Event_Handler::processEvents() {
  SDL_Event e;

  while (SDL_PollEvent(&e)) {
    switch (e.type) {
      case SDL_WINDOWEVENT:
        windowEvent(&e);
        break;
      case SDL_KEYDOWN:
        keyboardDown(&e);
        break;
      case SDL_KEYUP:
        keyboardUp(&e);
        break;
      case SDL_TEXTEDITING:
        //textEdit(&e);
        break;
      case SDL_TEXTINPUT:
        textInput(&e);
        break;
      case SDL_MOUSEMOTION:
        //mouseMotion(&e);
        break;
      case SDL_MOUSEBUTTONDOWN:
        mouseButtonDown(&e);
        break;
      case SDL_MOUSEBUTTONUP:
        mouseButtonUp(&e);
        break;
      case SDL_MOUSEWHEEL:
        mouseWheel(&e);
        break;
      case SDL_JOYAXISMOTION:
        //joystickAxisMotion(&e);
        break;
      case SDL_JOYBALLMOTION:
        //joyBallAxisMotion(&e);
        break;
      case SDL_JOYHATMOTION:
        //joyHatMotion(&e);
        break;
      case SDL_JOYBUTTONDOWN:
        //joyButtonDown(&e);
        break;
      case SDL_JOYBUTTONUP:
        //joyButtonUp(&e);
        break;
      case SDL_JOYDEVICEADDED:
        joyDeviceAdded(&e);
        break;
      case SDL_JOYDEVICEREMOVED:
        joyDeviceRemoved(&e);
        break;
      case SDL_CONTROLLERAXISMOTION:
        //controllerAxisMotion(&e);
        break;
      case SDL_CONTROLLERBUTTONDOWN:
        controllerButtonDown(&e);
        break;
      case SDL_CONTROLLERBUTTONUP:
        controllerButtonUp(&e);
        break;
      case SDL_CONTROLLERDEVICEADDED:
        //controllerDeviceAdded(&e);
        break;
      case SDL_CONTROLLERDEVICEREMOVED:
        //controllerDeviceRemoved(&e);
        break;
      case SDL_CONTROLLERDEVICEREMAPPED:
        //controllerDeviceRemmaped(&e);
        break;
#if SDL_VERSION_ATLEAST(2, 0, 4)
      case SDL_AUDIODEVICEADDED:
        //audioDeviceAdded(&e);
        break;
      case SDL_AUDIODEVICEREMOVED:
        //audioDeviceRemoved(&e);
        break;
#endif
      case SDL_QUIT:
        quit(&e);
        return 1;
      case SDL_FINGERMOTION:
        //fingerMotion(&e);
        break;
      case SDL_FINGERDOWN:
        //fingerDown(&e);
        break;
      case SDL_FINGERUP:
        //fingerUp(&e);
        break;
      case SDL_MULTIGESTURE:
        //multigesture(&e);
        break;
      case SDL_DOLLARGESTURE:
        //dollarGesture(&e);
        break;
      case SDL_DOLLARRECORD:
        //dollarRecord(&e);
        break;
      case SDL_DROPFILE:
        //dropFile(&e);
        break;
#if SDL_VERSION_ATLEAST(2, 0, 5)
      case SDL_DROPTEXT:
        //dropText(&e);
        break;
      case SDL_DROPBEGIN:
        //dropBegin(&e);
        break;
      case SDL_DROPCOMPLETE:
        //dropEnd(&e);
        break;
#endif
    }
  }

  return 0;
}
コード例 #3
0
ファイル: Engine.cpp プロジェクト: calin014/calinsprojects
void CEngine::handleEvents()
{
	while ( SDL_PollEvent( &event ) ) 
	{
		switch ( event.type ) 
		{
		case SDL_KEYDOWN:			 
			keyPressed( event.key.keysym.sym );
			break;
 
		case SDL_KEYUP:
			keyReleased( event.key.keysym.sym );
			break;
 
		case SDL_QUIT:
			isRunning = true;
			break;
 
		case SDL_MOUSEMOTION:
			if(m_showCursor)
				mouseMoved(
					event.button.button, 
					event.motion.x, 
					event.motion.y, 
					event.motion.xrel, 
					event.motion.yrel);
			break;
 
		case SDL_MOUSEBUTTONUP:
			if(m_showCursor)
				mouseButtonUp(
					event.button.button, 
					event.motion.x, 
					event.motion.y, 
					event.motion.xrel, 
					event.motion.yrel);
			break;
 
		case SDL_MOUSEBUTTONDOWN:
			if(m_showCursor)
				mouseButtonDown(
					event.button.button, 
					event.motion.x, 
					event.motion.y, 
					event.motion.xrel, 
					event.motion.yrel);
			break;
 
		case SDL_ACTIVEEVENT:
			if ( event.active.state & SDL_APPACTIVE ) 
			{
				if ( event.active.gain ) 
				{
					/* Gain focus */

					m_bMinimized = false;
					showNotify();
				} else 
				{
					/* Lost focus */

					m_bMinimized = true;
					hideNotify();
				}
			}
			
			break;
		} 
	}	
}
コード例 #4
0
ファイル: Input.cpp プロジェクト: JonathanPalmerGD/PVGame
//=============================================================================
// Read state of connected controllers and mouse.
//=============================================================================
void Input::readControllers()
{
    DWORD result;
    for( DWORD i = 0; i <MAX_CONTROLLERS; i++)
    {
        if(controllers[i].connected)
        {
            result = XInputGetState(i, &controllers[i].state);
            if(result == ERROR_DEVICE_NOT_CONNECTED)    // if controller disconnected
			{
                controllers[i].connected = false;
				return;
			}
			else // Setup ALL the controls. I don't think there's a way to loop through each button and get the state - if there is, do that, please.
			{
				if (getGamepadDPadUp(i)) gamepadButtonDown(DPadUp);
				else gamepadButtonUp(DPadUp);

				if (getGamepadDPadDown(i)) gamepadButtonDown(DPadDown);
				else gamepadButtonUp(DPadDown);

				if (getGamepadDPadLeft(i)) gamepadButtonDown(DPadLeft);
				else gamepadButtonUp(DPadLeft);

				if (getGamepadDPadRight(i)) gamepadButtonDown(DPadRight);
				else gamepadButtonUp(DPadRight);

				if (getGamepadStart(i)) gamepadButtonDown(StartButton);
				else gamepadButtonUp(StartButton);

				if (getGamepadBack(i)) gamepadButtonDown(BackButton);
				else gamepadButtonUp(BackButton);

				if (getGamepadLeftThumb(i)) gamepadButtonDown(LeftThumbButton);
				else gamepadButtonUp(LeftThumbButton);

				if (getGamepadRightThumb(i)) gamepadButtonDown(RightThumbButton);
				else gamepadButtonUp(RightThumbButton);

				if (getGamepadLeftShoulder(i)) gamepadButtonDown(LeftShoulderButton);
				else gamepadButtonUp(LeftShoulderButton);

				if (getGamepadRightShoulder(i)) gamepadButtonDown(RightShoulderButton);
				else gamepadButtonUp(RightShoulderButton);

				if (getGamepadA(i)) gamepadButtonDown(ButtonA);
				else gamepadButtonUp(ButtonA);

				if (getGamepadB(i)) gamepadButtonDown(ButtonB);
				else gamepadButtonUp(ButtonB);

				if (getGamepadX(i)) gamepadButtonDown(ButtonX);
				else gamepadButtonUp(ButtonX);

				if (getGamepadY(i)) gamepadButtonDown(ButtonY);
				else gamepadButtonUp(ButtonY);
			}
        }
    }

	if (getMouseLButton()) mouseButtonDown(MouseLeft);
	else mouseButtonUp(MouseLeft);

	if (getMouseMButton()) mouseButtonDown(MouseMiddle);
	else mouseButtonUp(MouseMiddle);

	if (getMouseRButton()) mouseButtonDown(MouseRight);
	else mouseButtonUp(MouseRight);
}