You can do something like the code below, where one looper doesn't do much
but store the TwiMaster in a shared variable and the other one does the
work on both IOIOs. There's nothing forcing you to use a IOIO instance from
any specific thread. The thread running the looper is only an option.

TwiMaster readerTwi_;

class ReaderLooper extends BaseIOIOLooper {
  setup() {
    readerTwi_ = ioio_.openTwi(...);
  }

  disconnected() {
    readerTwi_ = null;
  }
}

class WriterLooper extends BaseIOIOLooper {
  TwiMaster writerTwi_;

  setup() {
    writerTwi_ = ioio_.openTwi(...);
  }

  loop() {
    TwiMaster readerTwi = readerTwi_;
    if (readerTwi != null) {
      readerTwi.writeRead(...);  // read sensor
      writerTwi_.writeRead(...);  // control actuator.
    }
  }
}

On Thu, Jul 30, 2015 at 5:32 PM, Eric Rule <[email protected]> wrote:

> Hey all,
>
> Let me know if you've encountered something similar to this:
>
> In my application, I am controlling two IOIO concurrently, but
> independently (one through USB, the other through Bluetooth).  I am using
> these two boards to perform I2C reads/writes to two separate devices.  All
> of my I2C stuff is working fine, so assume that code is correct.
>
> My goal is to read a register value from the BT devices, and update a
> value on the USB device.  I have two IOIOLoopers (one for USB, one for
> Bluetooth), and I want to* first* read the value from the BT board, *then
> *update the value on the USB board (using a simple proportional control
> algorithm).  How can I do this correctly? I believe the two Loopers are
> treated as two separate threads and they are running simultaneously? I know
> about the Thread.join() function, but I'm not sure how I can differentiate
> between the two threads in code to make one wait for the other.
>
> Here is a skeleton of my setup (I only have one activity):
>
> public class Main Activity extends IOIOActivity{
>
> onCreate(){
>
> ...
>
> }
>
> class MyBluetoothLooper extends BaseIOIOLooper {
>
>
> void setup(){
>
>
>
> ...
>
>
>  }
>
>
>
> void loop(){
>
>
> i2c.read(...);
>
>
>
> Thread.sleep(100);
>
>
>  }
>
>
> ...
>
>
> }
>
>
>
>
> class MyUSBLooper extends BaseIOIOLooper {
>
>
> void setup(){
>
>
>
> ...
>
>
>  }
>
>
>
> void loop(){
>
>
> i2c.write(...);
>
>
>
> Thread.sleep(100);
>
>
>  }
>
>
> ...
>
>
> }
>
>
> ...
>
> }
>
> If anyone has any experience with this type of IOIO use case, or more
> experience with Thread handling in Java/Android (I am relatively new), I
> could really use some help.
>
> Thanks,
>
> Eric
>
>
>
>
>
>
> --
> 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