-// Background thread
-////////////////////////////////////////////////////////////////////////////
-void *wxJoystick::Entry(void)
-{
- struct js_event j_evt;
- wxJoystickEvent jwx_event;
- fd_set read_fds;
- struct timeval time_out = {0, 0};
-
- FD_ZERO(&read_fds);
- DeferDestroy(TRUE);
- while (1) {
- TestDestroy();
-
- if (m_polling) {
- FD_SET(m_joystick, &read_fds);
- select(m_joystick+1, &read_fds, NULL, NULL, &time_out);
- if (FD_ISSET(m_joystick, &read_fds))
- read(m_joystick, &j_evt, sizeof(j_evt));
- else
- j_evt.type = 0;
- } else {
- read(m_joystick, &j_evt, sizeof(j_evt));
- }
-
- if ((j_evt.type & JS_EVENT_AXIS) == JS_EVENT_AXIS) {
- switch (j_evt.number) {
- case 1:
- m_lastposition.x = j_evt.value;
- jwx_event.SetEventType(wxEVT_JOY_MOVE);
- break;
- case 2:
- m_lastposition.y = j_evt.value;
- jwx_event.SetEventType(wxEVT_JOY_MOVE);
- break;
- case 3:
- m_axe[3] = j_evt.value;
- jwx_event.SetEventType(wxEVT_JOY_ZMOVE);
- break;
- default:
- m_axe[j_evt.number] = j_evt.value;
- jwx_event.SetEventType(wxEVT_JOY_MOVE);
- break;
- }
- jwx_event.SetPosition(m_lastposition);
- jwx_event.SetZPosition(m_axe[3]);
- }
- if ((j_evt.type & JS_EVENT_BUTTON) == JS_EVENT_BUTTON) {
- register int mask = 1 << j_evt.number;
- char button = m_buttons & mask;
-
- m_buttons &= ~mask;
- if (button) {
- jwx_event.SetEventType(wxEVT_JOY_BUTTON_UP);
- } else {
- jwx_event.SetEventType(wxEVT_JOY_BUTTON_DOWN);
- m_buttons |= mask;
- }
-
- jwx_event.SetButtonState(m_buttons);
- jwx_event.SetButtonChange(j_evt.number);
- }
- }
- if (m_catchwin)
- m_catchwin->ProcessEvent(jwx_event);
- if (m_polling)
- usleep(m_polling*1000);
-}