2016-09-06 00:47:54 +02:00
|
|
|
/*************************************************************************/
|
2022-07-20 08:28:22 +02:00
|
|
|
/* joypad_macos.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
|
|
|
/*************************************************************************/
|
2022-01-03 21:27:34 +01:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 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
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
#ifndef JOYPAD_MACOS_H
|
|
|
|
#define JOYPAD_MACOS_H
|
2016-09-06 00:47:54 +02:00
|
|
|
|
2022-05-10 20:02:26 +02:00
|
|
|
#import <ForceFeedback/ForceFeedback.h>
|
|
|
|
#import <ForceFeedback/ForceFeedbackConstants.h>
|
|
|
|
#import <IOKit/hid/IOHIDLib.h>
|
2022-10-11 11:52:41 +02:00
|
|
|
#import <Kernel/IOKit/hidsystem/IOHIDUsageTables.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;
|
|
|
|
|
2020-11-24 10:12:55 +01:00
|
|
|
uint32_t usage = 0;
|
2016-09-06 00:47:54 +02:00
|
|
|
|
2020-11-24 10:12:55 +01:00
|
|
|
int min = 0;
|
|
|
|
int max = 0;
|
2016-09-06 00:47:54 +02:00
|
|
|
|
|
|
|
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 21:05:51 +01:00
|
|
|
struct joypad {
|
2020-11-24 10:12:55 +01:00
|
|
|
IOHIDDeviceRef device_ref = nullptr;
|
2016-09-06 00:47:54 +02:00
|
|
|
|
|
|
|
Vector<rec_element> axis_elements;
|
|
|
|
Vector<rec_element> button_elements;
|
|
|
|
Vector<rec_element> hat_elements;
|
|
|
|
|
2020-11-24 10:12:55 +01:00
|
|
|
int id = 0;
|
2021-07-31 21:49:52 +02:00
|
|
|
bool offset_hat = false;
|
2016-09-06 00:47:54 +02:00
|
|
|
|
2022-01-26 10:01:27 +01:00
|
|
|
io_service_t ffservice = 0; // Interface for force feedback, 0 = no ff.
|
2016-09-06 00:47:54 +02:00
|
|
|
FFCONSTANTFORCE ff_constant_force;
|
2021-11-16 21:10:19 +01:00
|
|
|
FFDeviceObjectReference ff_device = nullptr;
|
|
|
|
FFEffectObjectReference ff_object = nullptr;
|
2020-11-24 10:12:55 +01:00
|
|
|
uint64_t ff_timestamp = 0;
|
|
|
|
LONG *ff_directions = nullptr;
|
2016-09-06 00:47:54 +02:00
|
|
|
FFEFFECT ff_effect;
|
2020-11-24 10:12:55 +01:00
|
|
|
DWORD *ff_axes = nullptr;
|
2016-09-06 00:47:54 +02:00
|
|
|
|
|
|
|
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 21:05:51 +01:00
|
|
|
joypad();
|
2016-09-06 00:47:54 +02:00
|
|
|
};
|
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
class JoypadMacOS {
|
2016-09-06 00:47:54 +02:00
|
|
|
enum {
|
2017-01-08 21:05:51 +01:00
|
|
|
JOYPADS_MAX = 16,
|
2016-09-06 00:47:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2022-04-04 15:06:57 +02:00
|
|
|
Input *input = nullptr;
|
2016-09-06 00:47:54 +02:00
|
|
|
IOHIDManagerRef hid_manager;
|
|
|
|
|
2017-01-08 21:05:51 +01:00
|
|
|
Vector<joypad> device_list;
|
2016-09-06 00:47:54 +02:00
|
|
|
|
|
|
|
bool have_device(IOHIDDeviceRef p_device) const;
|
2017-01-08 21:05:51 +01: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 10:57:58 +01:00
|
|
|
int get_joy_ref(IOHIDDeviceRef p_device) const;
|
2016-09-06 00:47:54 +02:00
|
|
|
|
2017-01-08 21:05:51 +01:00
|
|
|
void poll_joypads() const;
|
2016-09-06 00:47:54 +02:00
|
|
|
void config_hid_manager(CFArrayRef p_matching_array) const;
|
|
|
|
|
2017-01-08 21:05:51 +01: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 10:57:58 +01:00
|
|
|
void _device_removed(IOReturn p_res, IOHIDDeviceRef p_device);
|
2016-09-06 00:47:54 +02:00
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
JoypadMacOS(Input *in);
|
|
|
|
~JoypadMacOS();
|
2016-09-06 00:47:54 +02:00
|
|
|
};
|
|
|
|
|
2022-07-20 08:28:22 +02:00
|
|
|
#endif // JOYPAD_MACOS_H
|