| 
									
										
										
										
											2016-09-06 00:47:54 +02:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2017-09-01 21:07:55 +07:00
										 |  |  | /*  joypad_osx.h                                                         */ | 
					
						
							| 
									
										
										
										
											2016-09-06 00:47:54 +02:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							| 
									
										
										
										
											2017-08-27 14:16:55 +02:00
										 |  |  | /*                      https://godotengine.org                          */ | 
					
						
							| 
									
										
										
										
											2016-09-06 00:47:54 +02:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2020-01-01 11:16:22 +01:00
										 |  |  | /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							|  |  |  | /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ | 
					
						
							| 
									
										
										
										
											2016-09-06 00:47:54 +02:00
										 |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* Permission is hereby granted, free of charge, to any person obtaining */ | 
					
						
							|  |  |  | /* a copy of this software and associated documentation files (the       */ | 
					
						
							|  |  |  | /* "Software"), to deal in the Software without restriction, including   */ | 
					
						
							|  |  |  | /* without limitation the rights to use, copy, modify, merge, publish,   */ | 
					
						
							|  |  |  | /* distribute, sublicense, and/or sell copies of the Software, and to    */ | 
					
						
							|  |  |  | /* permit persons to whom the Software is furnished to do so, subject to */ | 
					
						
							|  |  |  | /* the following conditions:                                             */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* The above copyright notice and this permission notice shall be        */ | 
					
						
							|  |  |  | /* included in all copies or substantial portions of the Software.       */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ | 
					
						
							|  |  |  | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ | 
					
						
							|  |  |  | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ | 
					
						
							|  |  |  | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ | 
					
						
							|  |  |  | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ | 
					
						
							|  |  |  | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ | 
					
						
							|  |  |  | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2018-01-05 00:50:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-08 17:05:51 -03:00
										 |  |  | #ifndef JOYPADOSX_H
 | 
					
						
							|  |  |  | #define JOYPADOSX_H
 | 
					
						
							| 
									
										
										
										
											2016-09-06 00:47:54 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef MACOS_10_0_4
 | 
					
						
							|  |  |  | #include <IOKit/hidsystem/IOHIDUsageTables.h>
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | #include <Kernel/IOKit/hidsystem/IOHIDUsageTables.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #include <ForceFeedback/ForceFeedback.h>
 | 
					
						
							|  |  |  | #include <ForceFeedback/ForceFeedbackConstants.h>
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | #include <IOKit/hid/IOHIDLib.h>
 | 
					
						
							| 
									
										
										
										
											2016-09-06 00:47:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-28 15:19:37 +02:00
										 |  |  | #include "core/input/input.h"
 | 
					
						
							| 
									
										
										
										
											2016-09-06 00:47:54 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | struct rec_element { | 
					
						
							|  |  |  | 	IOHIDElementRef ref; | 
					
						
							|  |  |  | 	IOHIDElementCookie cookie; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	uint32_t usage; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int min; | 
					
						
							|  |  |  | 	int max; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct Comparator { | 
					
						
							|  |  |  | 		bool operator()(const rec_element p_a, const rec_element p_b) const { return p_a.usage < p_b.usage; } | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-08 17:05:51 -03:00
										 |  |  | struct joypad { | 
					
						
							| 
									
										
										
										
											2016-09-06 00:47:54 +02:00
										 |  |  | 	IOHIDDeviceRef device_ref; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Vector<rec_element> axis_elements; | 
					
						
							|  |  |  | 	Vector<rec_element> button_elements; | 
					
						
							|  |  |  | 	Vector<rec_element> hat_elements; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int id; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	io_service_t ffservice; /* Interface for force feedback, 0 = no ff */ | 
					
						
							| 
									
										
										
										
											2016-09-06 00:47:54 +02:00
										 |  |  | 	FFCONSTANTFORCE ff_constant_force; | 
					
						
							|  |  |  | 	FFDeviceObjectReference ff_device; | 
					
						
							|  |  |  | 	FFEffectObjectReference ff_object; | 
					
						
							|  |  |  | 	uint64_t ff_timestamp; | 
					
						
							|  |  |  | 	LONG *ff_directions; | 
					
						
							|  |  |  | 	FFEFFECT ff_effect; | 
					
						
							|  |  |  | 	DWORD *ff_axes; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void add_hid_elements(CFArrayRef p_array); | 
					
						
							|  |  |  | 	void add_hid_element(IOHIDElementRef p_element); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bool has_element(IOHIDElementCookie p_cookie, Vector<rec_element> *p_list) const; | 
					
						
							|  |  |  | 	bool config_force_feedback(io_service_t p_service); | 
					
						
							|  |  |  | 	bool check_ff_features(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int get_hid_element_state(rec_element *p_element) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void free(); | 
					
						
							| 
									
										
										
										
											2017-01-08 17:05:51 -03:00
										 |  |  | 	joypad(); | 
					
						
							| 
									
										
										
										
											2016-09-06 00:47:54 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-08 17:05:51 -03:00
										 |  |  | class JoypadOSX { | 
					
						
							| 
									
										
										
										
											2016-09-06 00:47:54 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	enum { | 
					
						
							| 
									
										
										
										
											2017-01-08 17:05:51 -03:00
										 |  |  | 		JOYPADS_MAX = 16, | 
					
						
							| 
									
										
										
										
											2016-09-06 00:47:54 +02:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2020-04-28 15:19:37 +02:00
										 |  |  | 	Input *input; | 
					
						
							| 
									
										
										
										
											2016-09-06 00:47:54 +02:00
										 |  |  | 	IOHIDManagerRef hid_manager; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-08 17:05:51 -03:00
										 |  |  | 	Vector<joypad> device_list; | 
					
						
							| 
									
										
										
										
											2016-09-06 00:47:54 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	bool have_device(IOHIDDeviceRef p_device) const; | 
					
						
							| 
									
										
										
										
											2017-01-08 17:05:51 -03:00
										 |  |  | 	bool configure_joypad(IOHIDDeviceRef p_device_ref, joypad *p_joy); | 
					
						
							| 
									
										
										
										
											2016-09-06 00:47:54 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	int get_joy_index(int p_id) const; | 
					
						
							| 
									
										
										
										
											2020-03-06 11:57:58 +02:00
										 |  |  | 	int get_joy_ref(IOHIDDeviceRef p_device) const; | 
					
						
							| 
									
										
										
										
											2016-09-06 00:47:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-08 17:05:51 -03:00
										 |  |  | 	void poll_joypads() const; | 
					
						
							|  |  |  | 	void setup_joypad_objects(); | 
					
						
							| 
									
										
										
										
											2016-09-06 00:47:54 +02:00
										 |  |  | 	void config_hid_manager(CFArrayRef p_matching_array) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-08 17:05:51 -03:00
										 |  |  | 	void joypad_vibration_start(int p_id, float p_magnitude, float p_duration, uint64_t p_timestamp); | 
					
						
							|  |  |  | 	void joypad_vibration_stop(int p_id, uint64_t p_timestamp); | 
					
						
							| 
									
										
										
										
											2016-09-06 00:47:54 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2017-03-26 15:59:13 +02:00
										 |  |  | 	void process_joypads(); | 
					
						
							| 
									
										
										
										
											2016-09-06 00:47:54 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void _device_added(IOReturn p_res, IOHIDDeviceRef p_device); | 
					
						
							| 
									
										
										
										
											2020-03-06 11:57:58 +02:00
										 |  |  | 	void _device_removed(IOReturn p_res, IOHIDDeviceRef p_device); | 
					
						
							| 
									
										
										
										
											2016-09-06 00:47:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-28 15:19:37 +02:00
										 |  |  | 	JoypadOSX(Input *in); | 
					
						
							| 
									
										
										
										
											2017-01-08 17:05:51 -03:00
										 |  |  | 	~JoypadOSX(); | 
					
						
							| 
									
										
										
										
											2016-09-06 00:47:54 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-08 17:05:51 -03:00
										 |  |  | #endif // JOYPADOSX_H
 |