diff --git a/controller/controller.cpp b/controller/controller.cpp index b0e95cd..bc957e2 100644 --- a/controller/controller.cpp +++ b/controller/controller.cpp @@ -281,6 +281,7 @@ void Controller::inputFeedbackReceived( // Ignore other types of force feedback if (effect.type != FF_RUMBLE) { + Log::debug("Unknown effect %d", (int)effect.type); return; } diff --git a/controller/input.cpp b/controller/input.cpp index ab6f8b8..550a727 100644 --- a/controller/input.cpp +++ b/controller/input.cpp @@ -23,12 +23,16 @@ #include #include -#define INPUT_MAX_FF_EFFECTS 1 - InputDevice::InputDevice( FeedbackReceived feedbackReceived ) : feedbackReceived(feedbackReceived) { + for(int i=0;i= 0 && upload.effect.id < INPUT_MAX_FF_EFFECTS) + { + effects[upload.effect.id] = upload.effect; + upload.retval = 0; + } + else + { + upload.retval = -EINVAL; + Log::error("Invalid effect ID (upload)"); + } if (ioctl(file, UI_END_FF_UPLOAD, &upload) < 0) { @@ -173,6 +187,8 @@ void InputDevice::handleFeedbackUpload(uint32_t id) strerror(errno) ); } + + Log::debug("Uploaded effect id %d", upload.effect.id); } void InputDevice::handleFeedbackErase(uint32_t id) @@ -181,6 +197,8 @@ void InputDevice::handleFeedbackErase(uint32_t id) erase.request_id = id; + Log::debug("Got feedback erase %d", id); + if (ioctl(file, UI_BEGIN_FF_ERASE, &erase) < 0) { Log::error( @@ -191,8 +209,16 @@ void InputDevice::handleFeedbackErase(uint32_t id) return; } - effect = {}; - erase.retval = 0; + if (erase.effect_id >= 0 && erase.effect_id < INPUT_MAX_FF_EFFECTS) + { + effects[erase.effect_id] = {}; + erase.retval = 0; + } + else + { + erase.retval = -EINVAL; + Log::error("Invalid effect ID (erase)"); + } if (ioctl(file, UI_END_FF_ERASE, &erase) < 0) { @@ -201,15 +227,18 @@ void InputDevice::handleFeedbackErase(uint32_t id) strerror(errno) ); } + + Log::debug("Erased effect id %d", erase.effect_id); } void InputDevice::handleEvent(input_event event) { + Log::debug("input_event type %d code %d value %d", (int)event.type, (int)event.code, (int)event.value); if (event.type == EV_UINPUT) - { + {//special event type, see uinput.h if (event.code == UI_FF_UPLOAD) { - handleFeedbackUpload(event.value); + handleFeedbackUpload(event.value); //value is the uinput event id, not to be confused with the request id } else if (event.code == UI_FF_ERASE) @@ -223,12 +252,18 @@ void InputDevice::handleEvent(input_event event) if (event.code == FF_GAIN) { // Gain varies between 0 and 0xffff - effectGain = event.value; + effectGain = event.value; //seems to be device-wide, not tied to any effect + Log::debug("Gain adjusted to %d", (int)effectGain); } - else if (event.code == effect.id) + else if (event.code >= 0 && event.code < INPUT_MAX_FF_EFFECTS) //should really check if the effect has been erased or not + { + Log::debug("Triggering effect %d", (int)event.code); + feedbackReceived(effectGain, effects[event.code], event.value); + } + else { - feedbackReceived(effectGain, effect, event.value); + Log::debug("Event code %d not handled", (int)event.code); } } } diff --git a/controller/input.h b/controller/input.h index c3c2cfd..60a5969 100644 --- a/controller/input.h +++ b/controller/input.h @@ -27,6 +27,8 @@ #include #include +#define INPUT_MAX_FF_EFFECTS 16 + /* * User mode input device for gamepads * Passes force feedback events to callback @@ -91,7 +93,7 @@ class InputDevice InterruptibleReader eventReader; std::thread eventThread; - ff_effect effect = {}; + ff_effect effects[INPUT_MAX_FF_EFFECTS] = {}; uint16_t effectGain = 0xffff; FeedbackReceived feedbackReceived; };