getDuration issues

23 views
Skip to first unread message

Kevin Miller

unread,
Mar 6, 2016, 11:54:24 PM3/6/16
to ioio-users
Hello,
I'm using an HC-SR04 in a IOIOService loop. I used a Timer to set a flag periodically so that the Looper will know when it should perform a ranging. 

If I use getDurationSync() the Looper will hang on getDurationSync after about 10 readings with the timer set to 500 (ms?) delay between triggers.

Second, if the sensor is unplugged, it hangs at getDuration() in every case no matter what form of getDuration I use or what the timer delay is. Is this by design to hang if there is no pulse, or is it possible to timeout?

Thanks,
Kevin

Ytai Ben-Tsvi

unread,
Mar 6, 2016, 11:58:55 PM3/6/16
to ioio-...@googlegroups.com
It is by design and the intention is that you can interrupt the thread if you want to cancel. Typically, you would use a TimerTask for that purpose.

--
You received this message because you are subscribed to the Google Groups "ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ioio-users+...@googlegroups.com.
To post to this group, send email to ioio-...@googlegroups.com.
Visit this group at https://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/d/optout.

Kevin Miller

unread,
Mar 12, 2016, 9:16:27 AM3/12/16
to ioio-users
Ytai,
Can you provide some detail on how to use a TimerTask and interrupt the thread? I read Javadoc for Pulseinput.getDurationBuffered() and it says:

Reads a single measurement from the queue. If the queue is empty, will block until more data arrives. The calling thread may be interrupted in order to abort the call. See interface documentation for further explanation regarding the read queue.

But I could not find the "interface documentation" that explains the read queue.

Thanks,
Kevin

Ytai Ben-Tsvi

unread,
Mar 12, 2016, 10:06:02 AM3/12/16
to ioio-...@googlegroups.com

Search the forum for TimerTask.

--
Reply all
Reply to author
Forward
0 new messages