webusb / arduino

WebUSB demos running on Arduino (and compatible) hardware.
580 stars 154 forks source link

remove delay in WebUSB #53

Closed DeqingSun closed 6 years ago

DeqingSun commented 6 years ago

This makes state polling non-blocking to fix https://github.com/webusb/arduino/issues/50

The original Arduino CDC code used a delay to avoid some issue at cost of blocking all other code. As a result, this caused a big issue if you want to know if computer connects Arduino while you do fast/complex tasks. 10 milliseconds delay will cause a lot of issues.

original

You can see the code in loop can run 100 times per second.

There was commit to fix the issue (although not merged)

"Fixed slowdown with repeated CDC bool operator test" https://github.com/arduino/ArduinoCore-avr/commit/53944cf44418c8c19906794ef904ae8353a4cc2d

majenkotech _fix

There is only one delay when computer connects.

I tried to improve that commit and remove all delay. Now the code is no longer blocking.

screen shot 2018-08-09 at 12 18 15 pm

And it will not interfere with other code.

DeqingSun commented 6 years ago

Done