-
Notifications
You must be signed in to change notification settings - Fork 123
Add optional polling interval to reduce CPU usage #113
base: develop
Are you sure you want to change the base?
Conversation
Hi, I am closing and re-opening this PR to bump the CLA bot. Sorry for the inconvenience! |
Hi @Qowy, |
I wonder if that read should block.... |
I updated the commit and changed the tabs into spaces. As to whether it should block: inputThread() calls processInput() which eventually calls IStream->read() I only looked at the UsbSerial implementation of it: read() calls available() which in essence calls LoadAsync() on the Windows::Storage::Streams::DataReader when there is no data available. In order to make it truly async the create_task(LoadAsync()).then(//callback) pattern would have to be used. However I cannot see how this would work with the current structure of the code. Currently it just polls the IAsyncTask returned by LoadAsync() on whether it is running and if the underlying DataReader has pending input.
Considering this, this pull request seems like the only possible solution without rewriting the entire ISerial and UWPFirmata classes. However maybe I am misunderstanding the whole async pattern in C++ and there is a simple solution in there somewhere. |
In short I think as long as IStream->Read() in Microsoft.Maker.Serial is not implemented as a IAsyncOperation<uint16_t> (maybe I will take a look at this if it is feasible but I can't say if I have the time) this pr is the only solutions since Microsoft.Maker.Firmata is essentially consuming a synchronous API |
See #114 for centralized discussion about possible solutions. |
As soon as Firmata.begin is called one of the cores of my Raspberry Pi 3 is fully utilized.
While this might be necessary for highly latency dependent applications, it seems like total overkill for basic usage of the firmata protocol.
This Pull Request introduces a second UwpFirmata(ulong pollingInterval) constructor that sleeps the inputThread() for the given amount of micro seconds.
A value of for example 10ms reduces the CPU usage to non noticable levels and is still entirely sufficent for simple non realtime data polling vie SYSEX