mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-04-03 06:26:04 +00:00
Initial attempt to implement rumble for evdev
This commit is contained in:
@@ -63,6 +63,7 @@ struct input_device {
|
||||
char modifiers;
|
||||
__s32 mouseDeltaX, mouseDeltaY, mouseScroll;
|
||||
short controllerId;
|
||||
int haptic_effect_id;
|
||||
int buttonFlags;
|
||||
char leftTrigger, rightTrigger;
|
||||
short leftStickX, leftStickY;
|
||||
@@ -547,6 +548,7 @@ void evdev_create(const char* device, struct mapping* mappings, bool verbose) {
|
||||
}
|
||||
|
||||
devices[dev].controllerId = -1;
|
||||
devices[dev].haptic_effect_id = -1;
|
||||
|
||||
if (devices[dev].map != NULL) {
|
||||
bool valid = evdev_init_parms(&devices[dev], &(devices[dev].xParms), devices[dev].map->abs_leftx);
|
||||
@@ -704,3 +706,40 @@ void evdev_stop() {
|
||||
void evdev_init() {
|
||||
handler = evdev_handle_event;
|
||||
}
|
||||
|
||||
static struct input_device* evdev_get_input_device(unsigned short controller_id) {
|
||||
for (int i=0; i<numDevices; i++)
|
||||
if (devices[i].controllerId == controller_id)
|
||||
return &devices[i];
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void evdev_rumble(unsigned short controller_id, unsigned short low_freq_motor, unsigned short high_freq_motor) {
|
||||
struct input_device* device = evdev_get_input_device(controller_id);
|
||||
if (!device)
|
||||
return;
|
||||
|
||||
if (device->haptic_effect_id >= 0) {
|
||||
ioctl(device->fd, EVIOCRMFF, device->haptic_effect_id);
|
||||
device->haptic_effect_id = -1;
|
||||
}
|
||||
|
||||
if (low_freq_motor == 0 && high_freq_motor == 0)
|
||||
return;
|
||||
|
||||
struct ff_effect effect = {0};
|
||||
effect.type = FF_RUMBLE;
|
||||
effect.id = -1;
|
||||
effect.replay.length = USHRT_MAX;
|
||||
effect.u.rumble.strong_magnitude = low_freq_motor;
|
||||
effect.u.rumble.weak_magnitude = high_freq_motor;
|
||||
if (ioctl(device->fd, EVIOCSFF, &effect) == -1)
|
||||
return;
|
||||
|
||||
struct input_event event = {0};
|
||||
event.type = EV_FF;
|
||||
event.code = effect.id;
|
||||
write(device->fd, (const void*) &event, sizeof(event));
|
||||
device->haptic_effect_id = effect.id;
|
||||
}
|
||||
|
||||
@@ -28,3 +28,4 @@ void evdev_init();
|
||||
void evdev_start();
|
||||
void evdev_stop();
|
||||
void evdev_map(char* device);
|
||||
void evdev_rumble(unsigned short controller_id, unsigned short low_freq_motor, unsigned short high_freq_motor);
|
||||
|
||||
@@ -311,6 +311,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
udev_init(!inputAdded, mappings, config.debug_level > 0);
|
||||
evdev_init();
|
||||
rumble_handler = evdev_rumble;
|
||||
#ifdef HAVE_LIBCEC
|
||||
cec_init();
|
||||
#endif /* HAVE_LIBCEC */
|
||||
|
||||
Reference in New Issue
Block a user