Ejemplo n.º 1
0
void CWinEventsAndroid::Process()
{
  uint32_t timeout = 10;
  uint32_t holdTimeout = 500;
  uint32_t repeatTimeout = 100;
  uint32_t repeatDuration = 0;

  XBMC_Event cur_event;
  int state = EVENT_STATE_TEST;
  while (!m_bStop)
  {
    // run a 10ms (timeout) wait cycle
    Sleep(timeout);

    CSingleLock lock(m_lasteventCond);

    switch(state)
    {
      default:
      case EVENT_STATE_TEST:
        // check for axis action events
        if (!m_lastevent.empty())
        {
          if ((m_lastevent.front().type == XBMC_JOYAXISMOTION && fabs(m_lastevent.front().jaxis.fvalue) >= ALMOST_ZERO)
              || (m_lastevent.front().type == XBMC_JOYHATMOTION && m_lastevent.front().jhat.value > XBMC_HAT_CENTERED))
          {
            // new active event
            cur_event = m_lastevent.front();
            #if DEBUG_MESSAGEPUMP
            CLog::Log(LOGDEBUG, "test   -> hold, size(%d), fvalue(%f)",
              m_lastevent.size(), m_lastevent.front().jaxis.fvalue);
            #endif
            m_lastevent.pop();
            repeatDuration = 0;
            state = EVENT_STATE_HOLD;
            break;
          }
          #if DEBUG_MESSAGEPUMP
          CLog::Log(LOGDEBUG, "munch     test, size(%d), fvalue(%f)",
            m_lastevent.size(), m_lastevent.front().jaxis.fvalue);
          #endif
          // non-active event, eat it
          m_lastevent.pop();
        }
        break;

      case EVENT_STATE_HOLD:
        repeatDuration += timeout;
        if (!m_lastevent.empty())
        {
          if (different_event(cur_event, m_lastevent.front()))
          {
            // different axis event, cycle back to test
            state = EVENT_STATE_TEST;
            break;
          }
          #if DEBUG_MESSAGEPUMP
          CLog::Log(LOGDEBUG, "munch     hold, size(%d), fvalue(%f)",
            m_lastevent.size(), m_lastevent.front().jaxis.fvalue);
          #endif
          // same axis event, eat it
          m_lastevent.pop();
        }
        if (repeatDuration >= holdTimeout)
        {
          CLog::Log(LOGDEBUG, "hold  ->repeat, size(%d), repeatDuration(%d)", m_lastevent.size(), repeatDuration);
          state = EVENT_STATE_REPEAT;
        }
        break;

      case EVENT_STATE_REPEAT:
        repeatDuration += timeout;
        if (!m_lastevent.empty())
        {
          if (different_event(cur_event, m_lastevent.front()))
          {
            // different axis event, cycle back to test
            state = EVENT_STATE_TEST;
            #if DEBUG_MESSAGEPUMP
            CLog::Log(LOGDEBUG, "repeat->  test, size(%d), fvalue(%f)",
              m_lastevent.size(), m_lastevent.front().jaxis.fvalue);
            #endif
            break;
          }
          #if DEBUG_MESSAGEPUMP
          CLog::Log(LOGDEBUG, "munch   repeat, size(%d), fvalue(%f)",
            m_lastevent.size(), m_lastevent.front().jaxis.fvalue);
          #endif
          // same axis event, eat it
          m_lastevent.pop();
        }
        if (repeatDuration >= holdTimeout)
        {
          // this is a repeat, push it
          MessagePushRepeat(&cur_event);
          // assuming holdTimeout > repeatTimeout,
          // just subtract the repeatTimeout
          // to get the next cycle time
          repeatDuration -= repeatTimeout;
        }
        break;
    }
  }
}
Ejemplo n.º 2
0
void CWinEventsAndroid::Process()
{
  uint32_t timeout = 10;
  uint32_t holdTimeout = 500;
  uint32_t repeatTimeout = 100;
  uint32_t repeatDuration = 0;

  XBMC_Event cur_event;
  int state = EVENT_STATE_TEST;
  while (!m_bStop)
  {
    // run a 10ms (timeout) wait cycle
    Sleep(timeout);

    CSingleLock lock(m_lasteventCond);

    switch(state)
    {
      default:
      case EVENT_STATE_TEST:
        // non-active event, eat it
        if (!m_lastevent.empty())
          m_lastevent.pop();
        break;

      case EVENT_STATE_HOLD:
        repeatDuration += timeout;
        if (!m_lastevent.empty())
        {
          if (different_event(cur_event, m_lastevent.front()))
          {
            // different event, cycle back to test
            state = EVENT_STATE_TEST;
            break;
          }

          // same event, eat it
          m_lastevent.pop();
        }

        if (repeatDuration >= holdTimeout)
        {
          CLog::Log(LOGDEBUG, "hold  ->repeat, size(%d), repeatDuration(%d)", m_lastevent.size(), repeatDuration);
          state = EVENT_STATE_REPEAT;
        }
        break;

      case EVENT_STATE_REPEAT:
        repeatDuration += timeout;
        if (!m_lastevent.empty())
        {
          if (different_event(cur_event, m_lastevent.front()))
          {
            // different event, cycle back to test
            state = EVENT_STATE_TEST;
            break;
          }

          // same event, eat it
          m_lastevent.pop();
        }

        if (repeatDuration >= holdTimeout)
        {
          // this is a repeat, push it
          MessagePushRepeat(&cur_event);
          // assuming holdTimeout > repeatTimeout,
          // just subtract the repeatTimeout
          // to get the next cycle time
          repeatDuration -= repeatTimeout;
        }
        break;
    }
  }
}