Conceptually (i.e. do not expect this to actually compile), what you want
is along the lines of:
class PulseInputThread : public Thread {
private final PulseInput input_;
private final Timer timer_;
private float last_;
public PulseInputThread(PulseInput input, Timer timer) {
input_ = input;
timer_ = timer;
}
public synchronized float getLastReading() {
return last_;
}
private synchronized void read() throws ConnectionLostException {
TimerTask task = new TimerTask() { ... }
timer_.schedule(task, ...);
try {
last_ = input_.waitPulseGetFrequency();
task.cancel();
} catch (InterruptedException e) {
last_ = 0;
}
}
public void run() {
try {
while (true) {
read();
Thread.sleep(...);
}
} catch (ConnectionLostException) {
}
}
}
...
public void setup() throws ... {
input1_ = ioio_.openPulseInput(..., *PulseMode.FREQ*, ...);
input2_ = ...;
Timer t = new Timer();
thread1_ = new PulseInputThread(input1_, t);
thread2_ = new PulseInputThread(input2_, t);
thread1_.start();
thread2_.start();
}
public void loop() throws ... {
// ... call getLastReading() on each thread and do something with
// the result...
}
public void disconnected() {
try {
thread1_.join();
thread2_.join();
} catch (InterruptedException e) {
}
}
I hope this makes some sense to you.
On Thu, Feb 26, 2015 at 9:51 AM, Paul Johnson <[email protected]>
wrote:
>
>
> Update:
>
> I noticed I placed both results in the same setText method. I fixed that
> and now both pins are displaying, however both are displaying at the
> frequency rate and not as timed and neither are going back to zero when
> unhooked.
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/ioio-users.
> For more options, visit https://groups.google.com/d/optout.
>
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/d/optout.