comparison src/joystick/darwin/SDL_sysjoystick.c @ 858:5db50aa5bf08

Date: Wed, 25 Feb 2004 06:41:17 -0500 From: "Ryan C. Gordon" Subject: Re: MacOS X bugs... This isn't an ideal patch (trying to open a joystick that has previously been unplugged will report success, but it'll just never give any input, etc), but it handles the worst case of deadlock in the event subsystem.
author Sam Lantinga <slouken@libsdl.org>
date Thu, 26 Feb 2004 13:45:22 +0000
parents b8d311d90021
children f122afdfa025
comparison
equal deleted inserted replaced
857:ce05e92d909b 858:5db50aa5bf08
90 90
91 recElement* firstAxis; 91 recElement* firstAxis;
92 recElement* firstButton; 92 recElement* firstButton;
93 recElement* firstHat; 93 recElement* firstHat;
94 94
95 int removed;
96 int uncentered;
97
95 struct joystick_hwdata* pNext; // next device 98 struct joystick_hwdata* pNext; // next device
96 }; 99 };
97 typedef struct joystick_hwdata recDevice; 100 typedef struct joystick_hwdata recDevice;
98 101
99 102
159 return value; // no scaling at all 162 return value; // no scaling at all
160 else 163 else
161 return ((value - pElement->minReport) * deviceScale / readScale) + min; 164 return ((value - pElement->minReport) * deviceScale / readScale) + min;
162 } 165 }
163 166
167
168 static void HIDRemovalCallback(void * target,
169 IOReturn result,
170 void * refcon,
171 void * sender)
172 {
173 recDevice *device = (recDevice *) refcon;
174 device->removed = 1;
175 device->uncentered = 1;
176 }
177
178
179
164 /* Create and open an interface to device, required prior to extracting values or building queues. 180 /* Create and open an interface to device, required prior to extracting values or building queues.
165 * Note: appliction now owns the device and must close and release it prior to exiting 181 * Note: appliction now owns the device and must close and release it prior to exiting
166 */ 182 */
167 183
168 IOReturn HIDCreateOpenDeviceInterface (io_object_t hidDevice, recDevice *pDevice) 184 IOReturn HIDCreateOpenDeviceInterface (io_object_t hidDevice, recDevice *pDevice)
191 if (NULL != pDevice->interface) 207 if (NULL != pDevice->interface)
192 { 208 {
193 result = (*(pDevice->interface))->open (pDevice->interface, 0); 209 result = (*(pDevice->interface))->open (pDevice->interface, 0);
194 if (kIOReturnSuccess != result) 210 if (kIOReturnSuccess != result)
195 HIDReportErrorNum ("Failed to open pDevice->interface via open.", result); 211 HIDReportErrorNum ("Failed to open pDevice->interface via open.", result);
212 else
213 (*(pDevice->interface))->setRemovalCallback (pDevice->interface, HIDRemovalCallback, pDevice, pDevice);
214
196 } 215 }
197 return result; 216 return result;
198 } 217 }
199 218
200 /* Closes and releases interface to device, should be done prior to exting application 219 /* Closes and releases interface to device, should be done prior to exting application
720 { 739 {
721 recDevice *device = joystick->hwdata; 740 recDevice *device = joystick->hwdata;
722 recElement *element; 741 recElement *element;
723 SInt32 value; 742 SInt32 value;
724 int i; 743 int i;
725 744
745 if (device->removed) /* device was unplugged; ignore it. */
746 {
747 if (device->uncentered)
748 {
749 device->uncentered = 0;
750
751 /* Tell the app that everything is centered/unpressed... */
752 for (i = 0; i < device->axes; i++)
753 SDL_PrivateJoystickAxis(joystick, i, 0);
754
755 for (i = 0; i < device->buttons; i++)
756 SDL_PrivateJoystickButton(joystick, i, 0);
757
758 for (i = 0; i < device->hats; i++)
759 SDL_PrivateJoystickHat(joystick, i, SDL_HAT_CENTERED);
760 }
761
762 return;
763 }
764
726 element = device->firstAxis; 765 element = device->firstAxis;
727 i = 0; 766 i = 0;
728 while (element) 767 while (element)
729 { 768 {
730 value = HIDScaledCalibratedValue(device, element, -32768, 32767); 769 value = HIDScaledCalibratedValue(device, element, -32768, 32767);