diff --git a/core/haptic/sink/haptic_sink_os.c b/core/haptic/sink/haptic_sink_os.c index 3dee808b..6eddf978 100644 --- a/core/haptic/sink/haptic_sink_os.c +++ b/core/haptic/sink/haptic_sink_os.c @@ -15,6 +15,10 @@ struct haptic_sink_state { static void dump_event(const GE_Event * event) { switch (event->type) { + case GE_JOYRUMBLE: + dprintf("< RUMBLE, weak=%hu, strong=%hu\n", event->jrumble.weak, event->jrumble.strong); + fflush(stdout); + break; case GE_JOYCONSTANTFORCE: dprintf("< CONSTANT, level: %d\n", event->jconstant.level); fflush(stdout); @@ -43,7 +47,7 @@ static struct haptic_sink_state * haptic_sink_os_init(int joystick) { if (joystick >= 0) { int haptic = ginput_joystick_get_haptic(joystick); - if (haptic & (GE_HAPTIC_CONSTANT | GE_HAPTIC_SPRING | GE_HAPTIC_DAMPER)) { + if (haptic & (GE_HAPTIC_RUMBLE | GE_HAPTIC_CONSTANT | GE_HAPTIC_SPRING | GE_HAPTIC_DAMPER)) { void * ptr = calloc(1, sizeof(struct haptic_sink_state)); if (ptr != NULL) { struct haptic_sink_state * state = (struct haptic_sink_state *) ptr; @@ -112,6 +116,19 @@ static void haptic_sink_os_process(struct haptic_sink_state * state, const s_hap if(gimx_params.debug.haptic) { dump_event(&event); } + } else if (data->type == E_DATA_TYPE_RUMBLE) { + GE_Event event = { + .jrumble = { + .type = GE_JOYRUMBLE, + .which = state->joystick, + .weak = data->rumble.weak, + .strong = data->rumble.strong + } + }; + ginput_queue_push(&event); + if(gimx_params.debug.haptic) { + dump_event(&event); + } } } diff --git a/core/haptic/sink/haptic_sink_rumble.c b/core/haptic/sink/haptic_sink_rumble.c deleted file mode 100644 index 4ea16ff8..00000000 --- a/core/haptic/sink/haptic_sink_rumble.c +++ /dev/null @@ -1,93 +0,0 @@ -/* - Copyright (c) 2017 Mathieu Laurendeau - License: GPLv3 - */ - -#include -#include -#include -#include - -struct haptic_sink_state -{ - int joystick; -}; - -static void dump_event(const GE_Event * event) { - - switch (event->type) { - case GE_JOYRUMBLE: - dprintf("< RUMBLE, weak=%hu, strong=%hu\n", event->jrumble.weak, event->jrumble.strong); - fflush(stdout); - break; - default: - dprintf("< UNKNOWN\n"); - fflush(stdout); - break; - } -} - -static struct haptic_sink_state * haptic_sink_rumble_init(int joystick) { - - if (joystick >= 0) { - int haptic = ginput_joystick_get_haptic(joystick); - if (haptic & GE_HAPTIC_RUMBLE) { - void * ptr = calloc(1, sizeof(struct haptic_sink_state)); - if (ptr != NULL) { - struct haptic_sink_state * state = (struct haptic_sink_state *) ptr; - state->joystick = joystick; - return state; - } else { - PRINT_ERROR_ALLOC_FAILED("calloc") - } - } - } - return NULL; -} - -static void haptic_sink_rumble_clean(struct haptic_sink_state * state) { - - free(state); -} - -static void haptic_sink_rumble_process(struct haptic_sink_state * state, const s_haptic_core_data * data) { - - GE_Event event = { - .jrumble = { - .type = GE_JOYRUMBLE, - .which = state->joystick, - .weak = data->rumble.weak, - .strong = data->rumble.strong - } - }; - ginput_queue_push(&event); - if(gimx_params.debug.haptic) { - dump_event(&event); - } -} - -static void haptic_sink_rumble_update(struct haptic_sink_state * state __attribute__((unused))) { - - // nothing to do here -} - -static s_haptic_core_ids haptic_sink_rumble_ids[] = { - /* This is a generic source, don't add anything here */ - { .vid = 0x0000, .pid = 0x0000 }, // end of table -}; - -static s_haptic_sink sink_rumble = { - .name = "haptic_sink_rumble", - .ids = haptic_sink_rumble_ids, - .caps = E_HAPTIC_SINK_CAP_RUMBLE, - .init = haptic_sink_rumble_init, - .clean = haptic_sink_rumble_clean, - .process = haptic_sink_rumble_process, - .update = haptic_sink_rumble_update -}; - -void haptic_sink_rumble_constructor(void) __attribute__((constructor)); -void haptic_sink_rumble_constructor(void) { - - haptic_sink_register(&sink_rumble); -}