rustui / hid

A cross platform plugin for communicating with HID devices for Flutter applications.
11 stars 7 forks source link

Support a way to access low level hidapi methods #7

Open minhnn-mvn opened 2 years ago

minhnn-mvn commented 2 years ago

Could you please provide an API with methods that match the methods in the hidapi. I think it will be very helpful to provide both high level API and also low level API. And even the current high level can be implemented with the new low level API.

For example, please add new class LowLevelHidapi with methods such as: List < HidDeviceInfo > enumerate(int vendorId, int productId); int write(Pointer dev, Uint8List data); Uint8List? readTimeout(Pointer dev, int length, int milliseconds); // return null if error, empty Uint8List if no data

Thanks and I hope this will be supported soon.

rustui commented 2 years ago

If you want to work with pointer, you can use generated_bindings.dart directly. It contains all the low-level APIs that come from hidapi. Current high-level APIs is experimental and immature. Hidapi does not support android and web platforms. I should refactor the api to be close to the WebHID API and try to include more features.

minhnn-mvn commented 2 years ago

Thanks, below is my explanation for the suggestions:

1) If use generated_bindings.dart directly then it is not cross platform, developers need to implement for each platform which will take a lot of time.

2) To support the above point number 1, we just need to change hid.dart and add just one method LowLevelHidapi getLowLevelHidapi(), the developer will access this feature cross platform on what hidapi natively support (without Android, Web)

3) This new LowLevelHidapi will be stable API because it based on the API of hidapi which is very stable.

4) This new LowLevelHidapi will provide synchronous programming, which is easier in a lot of cases.

5) The high level API does not need to be implemented for each platform, we can rewrite the high level API (implemented only one time for macOS, Windows, Linux) with the new LowLevelHidapi.

6) This will provide developers 2 API: the async and the synch so they can choose to best suit their specific need. (For macOS, Linux, Windows)

7) For Android and Web, developer will need to use the high level API, the LowLevelHidapi just need to throw Exception for Android and Web.

I am looking forward to this new feature, and I hope you could support it soon (if you need help I could develop this feature, please just let me know)

rustui commented 2 years ago

The stable version of dart will soon support wchar_t, then we should not need to generate different bindings for different desktop platforms. This means we can make generated_bindings.dart cross desktop platforms.

minhnn-mvn commented 2 years ago

It looks like Dart 2.16 will support this, but we not sure when Dart 2.16 will be released to the stable channel.

And do you plan to organize your federated plugin model? When Dart 2.16 is released then this plugin would have the same implementation for many platforms, which will be better to move to "hid" or "hid_platform_interface".

rustui commented 2 years ago

Yes, I have a plan similar to what you think. I intend to remove most of the duplicated code and make the implementation more streamlined.

minhnn-mvn commented 2 years ago

I am working on an synch API which higher level than the LowLevelHidapi that I explain above, this will be a class which 2 characteristics: 1) it is a synch API with class (object oriented) 2) it is designed to be as similar/compatible/same functionalities as possible with the native C hidapi

I hope in a few days I could share it to you to review and please commit to this project.

phomes commented 2 years ago

is this still being worked on?