devEnju / n_gamepad

https://pub.dev/packages/n_gamepad
BSD 3-Clause "New" or "Revised" License
2 stars 1 forks source link

How to read unsupportted gamepad events? #3

Open cool2apps opened 1 year ago

cool2apps commented 1 year ago

Hello,

This is not a bug report. I just need help, and I think you may have knowledge for solving this problem.

I am developing an Android TV (game like) app with flutter. This app will use gamepad interactions to control the app. I tested with your flutter plugin, but failed to see the gamepad in 2.4 GHz wireless USB dongle connection.

For testing purposes, I just bought a gamepad (Pusat Clutch) which has 2 connection method:

  1. bluetooth (android is fully supported by the vendor)
  2. 2.4 GHz wireless with USB dongle (android is not supported by the vendor)

When I connect it to an android phone with bluetooth connection, everything works like a charm. I can detect it as Pusat gamepad on Android with java or flutter code. I can read keyEvents, motionEvents. When I test it with Game Controller Test app, it detects it as Pusat gamepad, and works excellent. No problem at all.

Game Controller Test app: https://play.google.com/store/apps/details?id=uk.co.powgames.gamecondiag

But when I connect it to an Android TV with 2.4 GHz wireless with USB dongle, and open Game Controller Test app, it detects this gamepad as Nintendo Switch gamepad. Test is ok, all buttons are working fine. But when I try to read keyEvents and motionEvents with java code or flutter code or with your plugin, I don't get any events.

How can I read keyEvents and motionEvents from 2.4 GHz wireless USB dongle connected gamepad like Game Controller Test app did with java (or with kotlin) or with your plugin in Android?

I use following java code to test that if I get any event from the gamepad. This code works for bluetooth connection, but does not work for 2.4 GHz with USB dongle connection.

Thanks for help

 @Override
        public boolean onGenericMotionEvent(MotionEvent event) {
            TextView textView = (TextView) findViewById(R.id.text);
            textView.setText("onGenericMotionEvent");
            return super.onGenericMotionEvent(event);
        }

        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            TextView textView = (TextView) findViewById(R.id.text);
            textView.setText("onKeyDown");
            return super.onKeyDown(keyCode, event);
        }
devEnju commented 1 year ago

Hi, Thanks for your comment. It's a little difficult to judge from a distance but to me it looks like the app you were using to test the controller is either using a game engine, or has a custom implementation with the Android NDK.

Everything which goes over the Java event handlers is limited to the controllers supported by the implementation of Android and the manufacturer. Some manufacturers support it right out of the box, others unfortunately don't.

Game Engines usually also make use of the Android NDK which in general is closer to the hardware. This way you can detect more connected devices which are not picked up by Android. There are many open source libraries like SDL which might even have an abstraction for Java.

I wish to could help you further, but right now I don't see myself implementing a solution for this anytime soon.

If you have another question, please do not hesitate to reach out again.

cool2apps commented 1 year ago

Hi, Thanks for your comment. It's a little difficult to judge from a distance but to me it looks like the app you were using to test the controller is either using a game engine, or has a custom implementation with the Android NDK.

Everything which goes over the Java event handlers is limited to the controllers supported by the implementation of Android and the manufacturer. Some manufacturers support it right out of the box, others unfortunately don't.

Game Engines usually also make use of the Android NDK which in general is closer to the hardware. This way you can detect more connected devices which are not picked up by Android. There are many open source libraries like SDL which might even have an abstraction for Java.

I wish to could help you further, but right now I don't see myself implementing a solution for this anytime soon.

If you have another question, please do not hesitate to reach out again.

Thanks for reply. Are you planning to include SDL like libraries in your plugin to support more gamepads in future?

devEnju commented 1 year ago

I'll definitely keep the issue open as I've also noticed that Playstation controllers don't seem to work too nice with the current implementation. Things like multi controller support is also something I'd really like to implement and I might even want to overthink the method interface for it.

To give you some background information: This Flutter plugin was mainly derived from one of my projects, sending controller inputs over a network. The API for callback bindings to certain buttons was a result of clean separation. Since at the moment I'm only using it for the network functionality, that's also how I decided on the direction of further feature developments.

A Linux platform integration with Steamworks is on its way which unfortunately doesn't leave me with any additional time. However, I'd like to encourage you to go down this rabbit hole yourself and maybe you'd even like to create a PR to this repository. There is a lot to learn and the result can be really rewarding!

Edit: I moved the Linux platform integration with Steamworks onto the tx_gamepad repository after realizing an action based implementation for controller inputs, as the API suggests, only makes sense as a direct implementation in an applications. Wrapping it in the n_gamepad plugin would complicate abstracting and then later customizing actions which is why I've decided against it.