Turns out the problem was I didn't add permission on the menifest.. I guess that means the emulator is not exactly like a real android device.
On Friday, December 6, 2013 3:30:41 AM UTC+2, Ytai wrote: > > Logcat? > > On Thursday, December 5, 2013, רועי פרטוש wrote: > >> I managed to piece together an app that transmits a number serially >> (digit by digit), using BCD (binary coded decimal). An additional digital >> output (represented by a public boolean variable called nd_flag [nd = new >> digit] ) lets the receiver know when a new digit is ready to be read. >> >> Basically the code goes like this: >> Upon clicking the SEND button, a thread starts running a loop which first >> puts a false in nd_flag, waits 100 ms, then updates the boolean public >> variables representing each bit (bit0, bit1, bit2 and bit3), then turns >> nd_flag true, and waits 900 ms. The loop iterrates one time for each digit >> in the number inserted by the user on the EditText field. >> Meanwhile (while the described thread runs), a code similar to HelloIOIO >> writes the values in bit0-3 and nd_flag to the corresponding digital >> outputs. I set the update rate in BaseIOIOLooper.loop() to 50 ms which is >> fast enough relative to the first loop. >> >> This is the UI: >> >> >> <https://lh5.googleusercontent.com/-63QbYfeqmaE/UqENBw70G0I/AAAAAAAAItE/w7D3uGZWp8Y/s1600/Screenshot_2013-12-06-01-23-04.png> >> The five check boxes on the lower half of the screen indicate the current >> state of the digital outputs on the IOIO. >> >> The code runs perfectly on the emulator (using IOIO bridge), but when I >> run it on my motorla razr with android 4.0.4 the IOIO is not responding, >> and non of the indicatory check boxes (bit0-3 and new_digit_flag) ever >> turns on (which actually does indicate the actual state of the respective >> digital outputs). >> It seems that the app doesn't establish a communication with the IOIO >> when it's executes on the android device (altough HelloIOIO does run on >> that same device). >> >> Any ideas? Is it likely that there's just somehing wrong with my phone, >> or is it the code? >> >> >> package com.example.ioiocom; >> >> import android.app.AlertDialog; >> import android.content.DialogInterface; >> import android.os.Bundle; >> import android.view.Menu; >> import android.view.View; >> import android.view.View.OnClickListener; >> >> import ioio.lib.api.exception.ConnectionLostException; >> import ioio.lib.api.DigitalOutput; >> >> import ioio.lib.util.BaseIOIOLooper; >> import ioio.lib.util.IOIOLooper; >> import ioio.lib.util.android.IOIOActivity; >> import android.widget.Button; >> import android.widget.CheckBox; >> import android.widget.EditText; >> >> >> public class MainActivity extends IOIOActivity { >> EditText dataET; >> Button SEND; >> CheckBox sent,bit0_CB_,bit1_CB_,bit2_CB_,bit3_CB_,nd_flag_CB_; >> boolean bit0,bit1,bit2,bit3,nd_flag=false; >> >> @Override >> protected void onCreate(Bundle savedInstanceState) { >> super.onCreate(savedInstanceState); >> setContentView(R.layout.activity_main); >> dataET = (EditText)findViewById(R.id.data); >> SEND = (Button)findViewById(R.id.send_button); >> sent = (CheckBox)findViewById(R.id.sent_check); >> bit0_CB_ = (CheckBox)findViewById(R.id.bit0_CB); >> bit1_CB_ = (CheckBox)findViewById(R.id.bit1_CB); >> bit2_CB_ = (CheckBox)findViewById(R.id.bit2_CB); >> bit3_CB_ = (CheckBox)findViewById(R.id.bit3_CB); >> nd_flag_CB_ = (CheckBox)findViewById(R.id.nd_flag_CB); >> SEND.setOnClickListener(new OnClickListener() { >> @Override >> public void onClick(View v) { >> send_looper transmit_data = new send_looper(); >> try { >> sent.setChecked(false); >> transmit_data.start(); >> } catch (NumberFormatException e) { >> // TODO Auto-generated catch block >> e.printStackTrace(); >> } >> } >> }); >> } >> class Looper extends BaseIOIOLooper { >> private DigitalOutput data_out0; >> private DigitalOutput data_out1; >> private DigitalOutput data_out2; >> private DigitalOutput data_out3; >> private DigitalOutput new_dig_flag; >> >> /** >> * 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.AbstractIOIOActivity.IOIOThread#setup() >> */ >> @Override >> protected void setup() throws ConnectionLostException { >> data_out0 = ioio_.openDigitalOutput(1, true); >> data_out1 = ioio_.openDigitalOutput(2, true); >> data_out2 = ioio_.openDigitalOutput(3, true); >> data_out3 = ioio_.openDigitalOutput(4, true); >> new_dig_flag = ioio_.openDigitalOutput(0, true); >> } >> >> /** >> * Called repetitively while the IOIO is connected. >> * >> * @throws ConnectionLostException >> * When IOIO connection is lost. >> * @throws InterruptedException >> * >> * @see ioio.lib.util.AbstractIOIOActivity.IOIOThread#loop() >> */ >> @Override >> public void loop() throws ConnectionLostException, InterruptedException { >> data_out0.write(bit0); >> data_out1.write(bit1); >> data_out2.write(bit2); >> data_out3.write(bit3); >> new_dig_flag.write(!nd_flag); >> runOnUiThread(new Runnable() { >> @Override >> public void run() { >> bit0_CB_.setChecked(bit0); >> bit1_CB_.setChecked(bit1); >> bit2_CB_.setChecked(bit2); >> bit3_CB_.setChecked(bit3); >> nd_flag_CB_.setChecked(nd_flag); >> } >> }); >> try { >> Thread.sleep(50); >> } catch (InterruptedException e) { >> } >> } >> } >> >> /** >> * A method to create our IOIO thread. >> * >> * @see ioio.lib.util.AbstractIOIOActivity#createIOIOThread() >> */ >> @Override >> protected IOIOLooper createIOIOLooper() { >> return new Looper(); >> } >> @Override >> public boolean onCreateOptionsMenu(Menu menu) { >> // Inflate the menu; this adds items to the action bar if it is present. >> getMenuInflater().inflate(R.menu.main, menu); >> return true; >> } >> // android part: >> public class send_looper extends Thread { >> public void run() { >> String data = dataET.getText().toString(); >> for (int i = 0; i < data.length(); ++i) { >> nd_flag = false; >> try { >> Thread.sleep(100); // down time for nd_flag >> } catch (InterruptedException e) { >> // TODO Auto-generated catch block >> e.printStackTrace(); >> } >> try { >> digit_out(Integer.parseInt(data.substring(i, i+1))); >> >> } catch (NumberFormatException e1) { >> // TODO Auto-generated catch block >> e1.printStackTrace(); >> } catch (ConnectionLostException e1) { >> // TODO Auto-generated catch block >> e1.printStackTrace(); >> } >> finally { >> nd_flag = true; >> try { >> Thread.sleep(900); //up time for nd_flag >> >> } catch (InterruptedException e) { >> // TODO Auto-generated catch block >> e.printStackTrace(); >> } >> } >> } >> runOnUiThread(new Runnable() { >> @Override >> public void run() { >> sent.setChecked(true); >> } >> }); >> } >> } >> public void digit_out(int digit) throws ConnectionLostException { >> if(digit==0) >> data_bin_out(false,false,false,false); >> else if(digit==1) >> data_bin_out(true,false,false,false); >> else if(digit==2) >> data_bin_out(false,true,false,false); >> else if(digit==3) >> data_bin_out(true,true,false,false); >> else if(digit==4) >> data_bin_out(false,false,true,false); >> else if(digit==5) >> data_bin_out(true,false,true,false); >> else if(digit==6) >> data_bin_out(false,true,true,false); >> else if(digit==7) >> data_bin_out(true,true,true,false); >> else if(digit==8) >> data_bin_out(false,false,false,true); >> else if(digit==9) >> data_bin_out(true,false,false,true); >> else >> data_bin_out(true,true,true,true); >> } >> public void data_bin_out(boolean b0, boolean b1, boolean b2, boolean >> b3) throws ConnectionLostException { >> bit0 = b0; >> bit1 = b1; >> bit2 = b2; >> bit3 = b3; >> } >> } >> >> -- >> 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/groups/opt_out. >> > -- 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/groups/opt_out.
