From 47a883854f42fdd4a39f33e513a82c697ea45d90 Mon Sep 17 00:00:00 2001 From: mk Date: Sat, 6 Nov 2021 01:52:35 +1100 Subject: [PATCH 1/2] implement memory for 10 effects --- controller/controller.cpp | 1 + controller/input.cpp | 37 ++++++++++++++++++++++++++++--------- controller/input.h | 4 +++- 3 files changed, 32 insertions(+), 10 deletions(-) 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..734321b 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 && 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..52c3374 100644 --- a/controller/input.h +++ b/controller/input.h @@ -27,6 +27,8 @@ #include #include +#define INPUT_MAX_FF_EFFECTS 10 + /* * 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; }; From 2fc66dc9c7c260f65fd284d8564398a751828aa2 Mon Sep 17 00:00:00 2001 From: mk Date: Sat, 6 Nov 2021 12:22:02 +1100 Subject: [PATCH 2/2] Increase limit to 16. Add bounds checking on upload/erase. --- controller/input.cpp | 24 ++++++++++++++++++++---- controller/input.h | 2 +- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/controller/input.cpp b/controller/input.cpp index 734321b..550a727 100644 --- a/controller/input.cpp +++ b/controller/input.cpp @@ -169,8 +169,16 @@ void InputDevice::handleFeedbackUpload(uint32_t id) return; } - effects[upload.effect.id] = upload.effect; //should really check the id first but the driver always seems to assign the first available from 0. - upload.retval = 0; + if (upload.effect.id >= 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) { @@ -201,8 +209,16 @@ void InputDevice::handleFeedbackErase(uint32_t id) return; } - effects[erase.effect_id] = {}; - 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) { diff --git a/controller/input.h b/controller/input.h index 52c3374..60a5969 100644 --- a/controller/input.h +++ b/controller/input.h @@ -27,7 +27,7 @@ #include #include -#define INPUT_MAX_FF_EFFECTS 10 +#define INPUT_MAX_FF_EFFECTS 16 /* * User mode input device for gamepads