And tip: use arrays and loops to avoid code duplication. On Mar 4, 2015 8:26 PM, "Ytai Ben-Tsvi" <[email protected]> wrote:
> For sake of debugging of this particular issue, would you please remove 7 > out of the 8 channels and report the behavior? > On Mar 4, 2015 7:55 PM, "Paul Johnson" <[email protected]> wrote: > >> Thanks for the help. I changed the last_declaration to the thread from >> the top of the parent class and it is working good. >> >> I used the Log.d and put it inside the catch beside the last_ = 0 . The >> log is printing a cluster of 4 of the tag every second whether or not >> anything is plugged in and the numbers continue to remain on the screen >> after disconnect. I have attached my current code. Is there another place I >> need to place the last_=0 ? >> >> 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("BACON", "BACON"); >> >> } >> } >> >> 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_; >> PulseInputThread thread3_; >> PulseInputThread thread4_; >> PulseInputThread thread5_; >> PulseInputThread thread6_; >> PulseInputThread thread7_; >> PulseInputThread thread8_; >> @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); >> PulseInput input3_ = ioio_.openPulseInput(new >> DigitalInput.Spec(3,Mode.PULL_DOWN), ClockRate.RATE_62KHz, PulseMode.FREQ, >> false); >> PulseInput input4_ = ioio_.openPulseInput( new >> DigitalInput.Spec(4,Mode.PULL_DOWN ), ClockRate.RATE_62KHz, >> PulseMode.FREQ, false); >> PulseInput input5_ = ioio_.openPulseInput(new >> DigitalInput.Spec(6,Mode.PULL_DOWN), ClockRate.RATE_62KHz, PulseMode.FREQ, >> false); >> PulseInput input6_ = ioio_.openPulseInput( new >> DigitalInput.Spec(7,Mode.PULL_DOWN ), ClockRate.RATE_62KHz, >> PulseMode.FREQ, false); >> PulseInput input7_ = ioio_.openPulseInput(new >> DigitalInput.Spec(10,Mode.PULL_DOWN), ClockRate.RATE_62KHz, >> PulseMode.FREQ, false); >> PulseInput input8_ = ioio_.openPulseInput( new >> DigitalInput.Spec(12,Mode.PULL_DOWN ), ClockRate.RATE_62KHz, >> PulseMode.FREQ, false); >> >> Timer t = new Timer(); >> thread1_ = new PulseInputThread(input1_, t); >> thread2_ = new PulseInputThread(input2_, t); >> thread3_ = new PulseInputThread(input3_, t); >> thread4_ = new PulseInputThread(input4_, t); >> thread5_ = new PulseInputThread(input5_, t); >> thread6_ = new PulseInputThread(input6_, t); >> thread7_ = new PulseInputThread(input7_, t); >> thread8_ = new PulseInputThread(input8_, t); >> >> >> >> >> >> thread1_.start(); >> thread2_.start(); >> thread3_.start(); >> thread4_.start(); >> thread5_.start(); >> thread6_.start(); >> thread7_.start(); >> thread8_.start(); >> } >> >> @Override >> public void loop() throws ConnectionLostException { >> setText1(thread1_.getLastReading()); >> setText2(thread2_.getLastReading()); >> setText3(thread3_.getLastReading()); >> setText4(thread4_.getLastReading()); >> setText5(thread5_.getLastReading()); >> setText6(thread6_.getLastReading()); >> setText7(thread7_.getLastReading()); >> setText8(thread8_.getLastReading()); >> try { >> Thread.sleep(1000); >> } catch (InterruptedException e) { >> } >> } >> public void disconnected() { >> try { >> >> thread1_.join(); >> thread2_.join(); >> thread3_.join(); >> thread4_.join(); >> thread5_.join(); >> thread6_.join(); >> thread7_.join(); >> thread8_.join(); >> } catch (InterruptedException e) { >> } >> } >> } >> >> >> >> @Override >> protected IOIOLooper createIOIOLooper() { >> return new Looper(); >> } >> >> >> >>> -- >> 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.
