On Thu, Jun 18, 2015 at 7:27 AM, Matthijs Kooijman <
matt...@stdin.nl> wrote:
>> I guess the question is, who put that there and how can we fix it?
>> It's there to fix a problem but I just don't feel that phantom delays
>> hidden in the core library are the proper solution. Perhaps the code
>> could store the current timestamp when lineState goes non-zero and the
>> bool operator could return false until at least 10ms has gone by since
>> that point? That's a bit more complicated and requires 4 more bytes of
>> RAM used by the core to track the timestamp but it's a hell of a lot
>> faster than always waiting 10ms in this function.
> It does sound like the proper solution to me, yes.
>
> More obvious would be to wait 10ms before changing lineState, but that
> would mean 10ms delay in an ISR, which probably breaks more than it
> fixes.
>
I've gone ahead and submitted a pull request for this.
https://github.com/arduino/Arduino/pull/3437
It's basically exactly what I had suggested - a 32 bit variable that
stores the time stamp when lineState changed and then a check in
operator bool() to make sure that true is not returned until at least
10ms after the lineState changed. I've tested this with a sketch and
it seems to work fine.
It's probably not something tons of people are dying to see but I
found another use case - I wrote a battery managment system sketch
that initializes and runs without needing the USB port to be plugged
into anything. It specifically checks within loop() to see if it has
gotten a connection on the USB port and if this is the first time that
has happened since the sketch started up. If so it outputs a simple
menu of what the user can do and what the current state of the BMS is.
This requires that I'm able to check the current state of the USB port
from within loop. If I were to do that within setup it would either
happen once or I wouldn't be able to run the sketch while I'm waiting
for a USB connection. So, in my case the 10ms delay really was
annoying even though it's a pretty specific use case. So, simple fix
and it seems like it should satisfy everyone so long as nobody misses
the 4 bytes of RAM now taken up. But, the Due has lots of RAM.
-Collin