+ static void HIDCallback(void* target, IOReturn res, void* context, void* sender)
+ {
+ IOHIDEventStruct hidevent;
+ AbsoluteTime bogustime = {0,0};
+ IOReturn ret;
+ wxJoystickThread* pThis = (wxJoystickThread*) context;
+ wxHIDJoystick* m_hid = pThis->m_hid;
+
+// wxMutexGuiEnter();
+ ret = (*m_hid->GetQueue())->getNextEvent(m_hid->GetQueue(),
+ &hidevent, bogustime, 0);
+ // wxMutexGuiLeave();
+ while ( ret != kIOReturnUnderrun )
+ {
+ if (pThis->TestDestroy())
+ break;
+
+// wxPrintf(wxT("ENTER\n"));
+ if(ret != kIOReturnSuccess)
+ {
+ wxLogSysError(wxString::Format(wxT("wxJoystick Error:[%i]"), ret));
+ return;
+ }
+
+ wxJoystickEvent wxevent;
+
+ int nIndex = 0;
+ IOHIDElementCookie* pCookies = m_hid->GetCookies();
+ while(nIndex < 50)
+ {
+ if(hidevent.elementCookie == pCookies[nIndex])
+ break;
+
+ ++nIndex;
+ }
+ if(nIndex == 50)
+ {
+ wxLogSysError(wxString::Format(wxT("wxJoystick Out Of Bounds Error")));
+ break;
+ }
+
+ if (nIndex < 40)
+ {
+ if (hidevent.value)
+ {
+ pThis->m_buttons |= (1 << nIndex);
+ wxevent.SetEventType(wxEVT_JOY_BUTTON_DOWN);
+ }
+ else
+ {
+ pThis->m_buttons &= ~(1 << nIndex);
+ wxevent.SetEventType(wxEVT_JOY_BUTTON_UP);
+ }
+
+ wxevent.SetButtonChange(nIndex+1);
+ }
+ else if (nIndex == wxJS_AXIS_X)
+ {
+ pThis->m_lastposition.x = hidevent.value;
+ wxevent.SetEventType(wxEVT_JOY_MOVE);
+ pThis->m_axe[0] = hidevent.value;
+ }
+ else if (nIndex == wxJS_AXIS_Y)
+ {
+ pThis->m_lastposition.y = hidevent.value;
+ wxevent.SetEventType(wxEVT_JOY_MOVE);
+ pThis->m_axe[1] = hidevent.value;
+ }
+ else if (nIndex == wxJS_AXIS_Z)
+ {
+ wxevent.SetEventType(wxEVT_JOY_ZMOVE);
+ pThis->m_axe[2] = hidevent.value;
+ }
+ else
+ wxevent.SetEventType(wxEVT_JOY_MOVE);
+
+ Nanoseconds timestamp = AbsoluteToNanoseconds(hidevent.timestamp);
+
+ wxULongLong llTime(timestamp.hi, timestamp.lo);
+
+ llTime /= 1000000;
+
+ wxevent.SetTimestamp(llTime.GetValue());
+ wxevent.SetJoystick(pThis->m_joystick);
+ wxevent.SetButtonState(pThis->m_buttons);
+ wxevent.SetPosition(pThis->m_lastposition);
+ wxevent.SetZPosition(pThis->m_axe[2]);
+ wxevent.SetEventObject(pThis->m_catchwin);
+
+// wxPrintf(wxT("SEND\n"));
+
+ if (pThis->m_catchwin)
+ pThis->m_catchwin->AddPendingEvent(wxevent);
+
+ // wxMutexGuiEnter();
+ ret = (*m_hid->GetQueue())->getNextEvent(m_hid->GetQueue(),
+ &hidevent, bogustime, 0);
+ // wxMutexGuiLeave();
+ }
+ }
+