You're using getDuration() instead of waitPulseGetDuration().
On Mar 5, 2015 8:44 AM, "Paul Johnson" <[email protected]> wrote:

> I commented everything else out, but for two pins.
>
> When I start the activity the Log prints my "Catch O" message below in
> clusters of two every second. (This is without any input on the pins). When
> I connect to one of the pins the Log prints "Catch O" one time each second.
> The text on screen continues to hang after disconnect. I don't understand
> why the catch would execute, but the text remain the same.
>
>
>
> class  PulseInputThread extends Thread {
>  private final PulseInput input_;
>   private final Timer timer_;
>   public float last_;
>  public PulseInputThread(PulseInput input,Timer timer) {
>  input_ = input;
>     timer_ = timer;
> }
>
>
>  private synchronized void read() throws ConnectionLostException {
>     TimerTask task = new TimerTask() {public void run() {
>      interrupt();
>   }};
>
>    * timer_.schedule(task, 1000);*
> *    try {*
> *      last_ = 1/input_.getDuration();*
> *      task.cancel();*
> *    } catch (InterruptedException e) {*
> *      last_ = 0;*
> *      Log.d("CATCH", "CATCHO");*
>
> *    }*
>   }
>
>   public void run() {
>     try {
>       while (true) {
>         read();
>
>         try {
> Thread.sleep(1000);
> } catch (InterruptedException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>       }
>     } catch (ConnectionLostException e) {
>      e.printStackTrace();
>     }
>   }
>
> public synchronized float getLastReading() {
>     return last_;
>   }
>  }
>   class Looper extends BaseIOIOLooper {
>  PulseInputThread thread1_;
> PulseInputThread thread2_;
>   @Override
> protected void setup() throws ConnectionLostException {
>  PulseInput  input1_ = ioio_.openPulseInput(new
> DigitalInput.Spec(1,Mode.PULL_DOWN), ClockRate.RATE_62KHz,  PulseMode.FREQ,
> false);
> PulseInput  input2_ = ioio_.openPulseInput( new
> DigitalInput.Spec(2,Mode.PULL_DOWN ), ClockRate.RATE_62KHz,
>  PulseMode.FREQ, false);
>
>  Timer t = new Timer();
>    thread1_ = new PulseInputThread(input1_, t);
>    thread2_ = new PulseInputThread(input2_, t);
>
>
>   thread1_.start();
>   thread2_.start();
>
> }
>
>  @Override
> public void loop() throws ConnectionLostException {
>  setText1(thread1_.getLastReading());
>   setText2(thread2_.getLastReading());
>
> try {
> Thread.sleep(1000);
> } catch (InterruptedException e) {
> }
> }
>  public void disconnected() {
>    try {
>
>      thread1_.join();
>      thread2_.join();
>
>    } catch (InterruptedException e) {
>    }
> }
>  }
>
>
>
> @Override
> protected IOIOLooper createIOIOLooper() {
> return new Looper();
> }
>
> private void setText1(final float freqHZ1) {
> runOnUiThread(new Runnable() {
> @Override
> public void run() {
>  row1.setText("Seeds per second: " + freqHZ1);
>  }
> });
> }
>  private void setText2( final float freqHZ2) {
> runOnUiThread(new Runnable() {
> @Override
> public void run() {
>  row2.setText("Seeds per second: " + freqHZ2);
>  }
> });
> }
>
> --
> 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.

Reply via email to