kurbatov / firmata4j

Firmata client written in Java.
MIT License
87 stars 45 forks source link

OnCapabilitiesRecieved Missing #33

Closed MarinaMatore closed 4 years ago

MarinaMatore commented 5 years ago

We need a callback when mFirmata.sendMessage(REQUEST_CAPABILITY); finishes. Or when the pin list gets filled.

Or did I miss it somewhere?

Kind Regards

kurbatov commented 5 years ago

Hi Marina,

You can achieve this using low-level message handlers:

    IODevice device = new FirmataDevice(port);
    device.addProtocolMessageHandler(FirmataEventType.PIN_CAPABILITIES_MESSAGE, new Consumer<Event>() {
        @Override
        public void accept(Event evt) {
            //do the stuff here
        }
    });
    device.start();

That will basically add another handler to already registered one which you amend in #34. Since additional delay is required only for Adafruit Feather 32u4 board, I beleive it would be better to handle delays in such an additional handler.

kurbatov commented 5 years ago

On the second thought the original design with delays is poorly implemented anyway. I think that all the pin state requests should be queued and sent only when response for the previous one is received. This approach yields robust and performant solution.

I beleive the primary handler should be redisigned because this exact place generates new issues with noticable frequency.

MarinaMatore commented 4 years ago

Hey @kurbatov !

When will your latest commit be available via Android gradle? Currently I still get the old commit.

Currently using: implementation 'com.github.kurbatov:firmata4j:2.3.7'

Thanks Best wishes.

kurbatov commented 4 years ago

Hi @MarinaMatore

I have released 2.3.8 which contains update of pin initialization. Besides of that it contains a new event type PIN_CAPABILITIES_FINISHED that can be used in a low-level message handler as described above.

The new release will be available soon via Maven Central.