java - trying to find when CH34xAndroidDriver.isConnected() is becomes true -
i trying find when , ch34xandroiddriver.isconnected()
value becomes true. have tried find out , display value in toast. can explain clearly.
public class uartloopbackactivity extends activity { public static final string tag = "com.wch.wchusbdriver"; private static final string action_usb_permission = "com.wch.wchusbdriver.usb_permission"; /* thread read data */ public readthread handlerthread; protected final object threadlock = new object(); /* declare uart interface variable */ public ch34xandroiddriver uartinterface; // byte timeout; // time out public context global_context; public boolean isconfiged = false; public boolean read_enable = false; public sharedpreferences shareprefsettings; drawable originaldrawable; public string act_string; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); /* create editable text objects */ readtext = (edittext) findviewbyid(r.id.readvalues); // writetext = (edittext) findviewbyid(r.id.writevalues); global_context = this; configbutton = (button) findviewbyid(r.id.configbutton); originaldrawable = configbutton.getbackground(); readbuffer = new char[512]; baudrate = 9600; stopbit = 1; databit = 8; parity = 0; flowcontrol = 0; configbutton.setonclicklistener(new opendevicelistener()); // writebutton.setonclicklistener(new onclickedwritebutton()); // writebutton.setenabled(false); // uartinterface = new ch34xandroiddriver( (usbmanager) getsystemservice(context.usb_service), this, action_usb_permission); act_string = getintent().getaction(); if (-1 != act_string.indexof("android.intent.action.main")) { log.d(tag, "android.intent.action.main"); } else if (-1 != act_string .indexof("android.hardware.usb.action.usb_device_attached")) { log.d(tag, "android.hardware.usb.action.usb_device_attached"); } if (!uartinterface.usbfeaturesupported()) { toast.maketext(this, "no support usb host api", toast.length_short) .show(); readtext.settext("no support usb host api"); uartinterface = null; toast.maketext(global_context, "148k" + ((boolean) uartinterface.isconnected()), toast.length_short).show(); } getwindow().setsoftinputmode( windowmanager.layoutparams.soft_input_state_always_hidden); if (read_enable == false) { read_enable = true; handlerthread = new readthread(handler); handlerthread.start(); toast.maketext(global_context,"155k" + ((boolean) uartinterface.isconnected()),toast.length_short).show(); } } public class opendevicelistener implements view.onclicklistener { @override public void onclick(view v) { // todo auto-generated method stub boolean flags; toast.maketext(global_context,"170" + ((boolean) uartinterface.isconnected()),toast.length_short).show(); log.d("onclick", "12"); if (false == isconfiged) { log.d("onclick", "58"); isconfiged = true; log.d("onclick", "98"); // writebutton.setenabled(true); if (uartinterface.isconnected()) { log.d("onclick", "100"); flags = uartinterface.uartinit(); if (!flags) { log.d(tag, "init uart error"); toast.maketext(global_context, "init uart error", toast.length_short).show(); } else { if (uartinterface.setconfig(baudrate, databit, stopbit, parity, flowcontrol)) { log.d(tag, "configed"); } } } if (isconfiged == true) { toast.maketext(global_context,"193" + ((boolean) uartinterface.isconnected()),toast.length_short).show(); log.d("onclick", "200"); configbutton.setenabled(false); } } } } public void onhomepressed() { onbackpressed(); } public void onbackpressed() { super.onbackpressed(); } protected void onresume() { super.onresume(); if (2 == uartinterface.resumeusblist()) { uartinterface.closedevice(); log.d(tag, "enter onresume error"); } } protected void onpause() { super.onpause(); } protected void onstop() { if (read_enable == true) { read_enable = false; } super.onstop(); } protected void ondestroy() { if (uartinterface != null) { if (uartinterface.isconnected()) { uartinterface.closedevice(); } uartinterface = null; } super.ondestroy(); } final handler handler = new handler() { @override public void handlemessage(message msg) { if (actualnumbytes != 0x00) { readtext.append(string.copyvalueof(readbuffer, 0, actualnumbytes)); toast.maketext(global_context,"269k" + ((boolean) uartinterface.isconnected()),toast.length_short).show(); actualnumbytes = 0; } } }; /* usb input data handler */ private class readthread extends thread { handler mhandler; /* constructor */ handler mhandler; readthread(handler h) { mhandler = h; this.setpriority(thread.min_priority); } public void run() { while (read_enable) { message msg = mhandler.obtainmessage(); try { thread.sleep(50); } catch (interruptedexception e) { } // log.d(tag, "thread"); synchronized (threadlock) { if (uartinterface != null) { actualnumbytes = uartinterface.readdata(readbuffer, 64); if (actualnumbytes > 0) { mhandler.sendmessage(msg); } } } } } } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.uart_loop_back, menu); return true; } }
upto line 74 (toast.maketext(global_context,"155k" + ((boolean) uartinterface.isconnected()),toast.length_short).show();) found returns false when onclick() called return true. why if body has answer pls check it. thanks
the method resumeusblist() enables usb connection , changes isconnected() true. if resumeusblist() fails returns 2
check activity's onresume()
Comments
Post a Comment