yup you were right. I was changing UI from the wrong thread. Thanks On Monday, March 7, 2016 at 10:02:22 PM UTC+5:30, Ytai wrote: > > Look at the logs to figure out what's wrong. My suspicion is that the > problem is that you're calling an Android UI function > (button_input.setChecked()) from the IOIO thread. You'd need to use the > same trick with the runOnUiThread() like in toast() and enableUi(). > > On Mon, Mar 7, 2016 at 3:29 AM, Pranay Sharma <[email protected] > <javascript:>> wrote: > >> Hi all, >> I tried modifying the HelloIOIO program to test Input and output on >> custom pins. >> The program starts and shows the Toast for a successful connection. >> But then it disconnects. >> Kindly advice what could wrong. >> >> public class MainActivity extends IOIOActivity { >> private ToggleButton button_; >> private ToggleButton button_input; >> >> >> /** >> * Called when the activity is first created. Here we normally initialize >> * our GUI. >> */ >> @Override >> public void onCreate(Bundle savedInstanceState) { >> super.onCreate(savedInstanceState); >> setContentView(R.layout.main); >> button_ = (ToggleButton) findViewById(R.id.button); >> button_input = (ToggleButton) findViewById(R.id.button_input); >> } >> >> /** >> * This is the thread on which all the IOIO activity happens. It will be >> run >> * every time the application is resumed and aborted when it is paused. The >> * method setup() will be called right after a connection with the IOIO has >> * been established (which might happen several times!). Then, loop() will >> * be called repetitively until the IOIO gets disconnected. >> */ >> class Looper extends BaseIOIOLooper { >> /** The on-board LED. */ >> private DigitalOutput led_; >> private DigitalOutput mOutput; >> private DigitalInput mInput_; >> >> /** >> * Called every time a connection with IOIO has been established. >> * Typically used to open pins. >> * >> * @throws ConnectionLostException >> * When IOIO connection is lost. >> * >> * @see ioio.lib.util.IOIOLooper#setup() >> */ >> @Override >> protected void setup() throws ConnectionLostException { >> showVersions(ioio_, "IOIO connected!"); >> led_ = ioio_.openDigitalOutput(0, true); >> /** Output is being tested on PIN 41 and input on >> pin 42 . With PULL_DOWN option on pin42, my assumption is that the pin 42 >> should be >> setup at 0V **/ >> mOutput = ioio_.openDigitalOutput(41, true); >> mInput_ = ioio_.openDigitalInput(42, DigitalInput.Spec.Mode.PULL_DOWN); >> enableUi(true); >> } >> >> /** >> * Called repetitively while the IOIO is connected. >> * >> * @throws ConnectionLostException >> * When IOIO connection is lost. >> * @throws InterruptedException >> * When the IOIO thread has been interrupted. >> * >> * @see ioio.lib.util.IOIOLooper#loop() >> */ >> @Override >> public void loop() throws ConnectionLostException, InterruptedException { >> toast("working 1"); >> led_.write(!button_.isChecked()); >> toast("working 2"); >> Thread.sleep(100); >> toast("working 3"); >> if(button_input!= null) { >> button_input.setChecked(mInput_.read()); >> }else{ >> toast("Bhai null pointer"); >> } >> } >> >> /** >> * Called when the IOIO is disconnected. >> * >> * @see ioio.lib.util.IOIOLooper#disconnected() >> */ >> @Override >> public void disconnected() { >> enableUi(false); >> toast("IOIO disconnected"); >> } >> >> /** >> * Called when the IOIO is connected, but has an incompatible firmware >> version. >> * >> * @see ioio.lib.util.IOIOLooper#incompatible(IOIO) >> */ >> @Override >> public void incompatible() { >> showVersions(ioio_, "Incompatible firmware version!"); >> } >> } >> >> /** >> * A method to create our IOIO thread. >> * >> * @see ioio.lib.util.AbstractIOIOActivity#createIOIOThread() >> */ >> @Override >> protected IOIOLooper createIOIOLooper() { >> return new Looper(); >> } >> >> private void showVersions(IOIO ioio, String title) { >> toast(String.format("%s\n" + >> "IOIOLib: %s\n" + >> "Application firmware: %s\n" + >> "Bootloader firmware: %s\n" + >> "Hardware: %s", >> title, >> ioio.getImplVersion(VersionType.IOIOLIB_VER), >> ioio.getImplVersion(VersionType.APP_FIRMWARE_VER), >> ioio.getImplVersion(VersionType.BOOTLOADER_VER), >> ioio.getImplVersion(VersionType.HARDWARE_VER))); >> } >> >> private void toast(final String message) { >> final Context context = this; >> runOnUiThread(new Runnable() { >> @Override >> public void run() { >> Toast.makeText(context, message, Toast.LENGTH_LONG).show(); >> } >> }); >> } >> >> private int numConnected_ = 0; >> >> private void enableUi(final boolean enable) { >> // This is slightly trickier than expected to support a multi-IOIO >> use-case. >> runOnUiThread(new Runnable() { >> @Override >> public void run() { >> if (enable) { >> if (numConnected_++ == 0) { >> button_.setEnabled(true); >> } >> } else { >> if (--numConnected_ == 0) { >> button_.setEnabled(false); >> } >> } >> } >> }); >> } >> } >> >> >> -- >> 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] <javascript:>. >> To post to this group, send email to [email protected] >> <javascript:>. >> Visit this group at https://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 https://groups.google.com/group/ioio-users. For more options, visit https://groups.google.com/d/optout.
