| 1 | /* |
| 2 | Simple DirectMedia Layer |
| 3 | Copyright (C) 2025 Katharine Chui <katharine.chui@gmail.com> |
| 4 | |
| 5 | This software is provided 'as-is', without any express or implied |
| 6 | warranty. In no event will the authors be held liable for any damages |
| 7 | arising from the use of this software. |
| 8 | |
| 9 | Permission is granted to anyone to use this software for any purpose, |
| 10 | including commercial applications, and to alter it and redistribute it |
| 11 | freely, subject to the following restrictions: |
| 12 | |
| 13 | 1. The origin of this software must not be misrepresented; you must not |
| 14 | claim that you wrote the original software. If you use this software |
| 15 | in a product, an acknowledgment in the product documentation would be |
| 16 | appreciated but is not required. |
| 17 | 2. Altered source versions must be plainly marked as such, and must not be |
| 18 | misrepresented as being the original software. |
| 19 | 3. This notice may not be removed or altered from any source distribution. |
| 20 | */ |
| 21 | |
| 22 | #ifndef SDL_hidapihaptic_c_h_ |
| 23 | #define SDL_hidapihaptic_c_h_ |
| 24 | |
| 25 | #include "SDL3/SDL_haptic.h" |
| 26 | #include "SDL3/SDL_joystick.h" |
| 27 | #include "../SDL_syshaptic.h" |
| 28 | #include "../../joystick/SDL_joystick_c.h" // accessing _SDL_JoystickDriver |
| 29 | #include "../../joystick/SDL_sysjoystick.h" // accessing _SDL_Joystick |
| 30 | |
| 31 | #define SDL_HAPTIC_HIDAPI_LG4FF |
| 32 | |
| 33 | typedef struct SDL_HIDAPI_HapticDriver SDL_HIDAPI_HapticDriver; |
| 34 | typedef struct SDL_HIDAPI_HapticDevice |
| 35 | { |
| 36 | SDL_Haptic *haptic; /* related haptic ref */ |
| 37 | SDL_Joystick *joystick; /* related hidapi joystick */ |
| 38 | SDL_HIDAPI_HapticDriver *driver; /* driver to use */ |
| 39 | void *ctx; /* driver specific context */ |
| 40 | } SDL_HIDAPI_HapticDevice; |
| 41 | |
| 42 | struct SDL_HIDAPI_HapticDriver |
| 43 | { |
| 44 | bool (*JoystickSupported)(SDL_Joystick *joystick); /* return SDL_TRUE if haptic can be opened from the joystick */ |
| 45 | void *(*Open)(SDL_Joystick *joystick); /* returns a driver context allocated with SDL_malloc, or null if it cannot be allocated */ |
| 46 | |
| 47 | /* functions below need to handle the possibility of a null joystick instance, indicating the absence of the joystick */ |
| 48 | void (*Close)(SDL_HIDAPI_HapticDevice *device); /* cleanup resources allocated during Open, do NOT free driver context created in Open */ |
| 49 | |
| 50 | /* below mirror SDL_haptic.h effect interfaces */ |
| 51 | int (*NumEffects)(SDL_HIDAPI_HapticDevice *device); /* returns supported number of effects the device can store */ |
| 52 | int (*NumEffectsPlaying)(SDL_HIDAPI_HapticDevice *device); /* returns supported number of effects the device can play concurrently */ |
| 53 | Uint32 (*GetFeatures)(SDL_HIDAPI_HapticDevice *device); /* returns supported effects in a bitmask */ |
| 54 | int (*NumAxes)(SDL_HIDAPI_HapticDevice *device); /* returns the number of haptic axes */ |
| 55 | int (*CreateEffect)(SDL_HIDAPI_HapticDevice *device, const SDL_HapticEffect *data); /* returns effect id if created correctly, negative number on error */ |
| 56 | bool (*UpdateEffect)(SDL_HIDAPI_HapticDevice *device, int id, const SDL_HapticEffect *data); /* returns 0 on success, negative number on error */ |
| 57 | bool (*RunEffect)(SDL_HIDAPI_HapticDevice *device, int id, Uint32 iterations); /* returns 0 on success, negative number on error */ |
| 58 | bool (*StopEffect)(SDL_HIDAPI_HapticDevice *device, int id); /* returns 0 on success, negative number on error */ |
| 59 | void (*DestroyEffect)(SDL_HIDAPI_HapticDevice *device, int id); /* returns 0 on success, negative number on error */ |
| 60 | bool (*GetEffectStatus)(SDL_HIDAPI_HapticDevice *device, int id); /* returns 0 if not playing, 1 if playing, negative number on error */ |
| 61 | bool (*SetGain)(SDL_HIDAPI_HapticDevice *device, int gain); /* gain 0 - 100, returns 0 on success, negative number on error */ |
| 62 | bool (*SetAutocenter)(SDL_HIDAPI_HapticDevice *device, int autocenter); /* gain 0 - 100, returns 0 on success, negative number on error */ |
| 63 | bool (*Pause)(SDL_HIDAPI_HapticDevice *device); /* returns 0 on success, negative number on error */ |
| 64 | bool (*Resume)(SDL_HIDAPI_HapticDevice *device); /* returns 0 on success, negative number on error */ |
| 65 | bool (*StopEffects)(SDL_HIDAPI_HapticDevice *device); /* returns 0 on success, negative number on error */ |
| 66 | }; |
| 67 | |
| 68 | extern SDL_HIDAPI_HapticDriver SDL_HIDAPI_HapticDriverLg4ff; |
| 69 | |
| 70 | #endif //SDL_joystick_c_h_ |