i trying plot data received bluetooth real-time mpandroidchart library. believe there problem thread deadlocks cannot figure out exactly.
here how code goes: after connection established, when "read" button pressed.
public boolean onoptionsitemselected(menuitem item) { intent serverintent; if (dttoggle.onoptionsitemselected(item)) { return true; } switch (item.getitemid()) { ...... case r.id.menu_read: string message; if (oper_state) { oper_state = false; put_thread = new puttask(); put_thread.start(); timer = new timer(); timer.schedule(new mytask(),10, 100); //feedmultiple(); //put_thread.start(); message = cmd_read + ""; sendmessage(message); } else { if(timer != null) { message = cmd_stop + ""; sendmessage(message); put_thread.interrupt(); timer.cancel(); timer.purge(); timer = null; oper_state = true; //put_thread.interrupt(); try{ if(fos != null) fos.close(); } catch(exception e) { } } } return true; putthread add received data bluetooth data queue:
class puttask extends thread { public void run(){ int channel_idx; customparsepackets mbluetoothservice; while(true) { mbluetoothservice = mchestpatchservice; for(int i=0;i<num_siganl_list;i++) { if(!mbluetoothservice.isempty(i)) { int read_data = mbluetoothservice.poll_data(i); put_data(i, read_data); sample_incr(i); } } } } } put_data function:
public synchronized void put_data(int i, int int_data) { int tmp_sample = 0; int tmp_data, filtered_data; double tmp_diff_val=0; tmp_sample = sample_get_value(i); tmp_data = int_data; if(mecgsigncheck.ischecked()) tmp_data = -tmp_data; if(mfiltercheck.ischecked() == true) ecg_data[i] = ecg_bpf[i].getoutputsample(tmp_data); else ecg_data[i] = tmp_data; if(i==1) { tmp_diff_val = mrpeak.put_ecg(tmp_sample, tmp_data); peak_point = mrpeak.apply_ecg(); log.d("peak", "data pushed" ); } synchronized (chartqueue_lock){ if(tmp_sample % 4 == 0) **chartqueue[i].offer(new point(tmp_sample, (int)ecg_data[i]));** } } and update ui:
class mytask extends timertask {
public void run(){ runonuithread(new runnable(){ @override public void run(){ //updateui(); dataseries_add_new((int)(math.random() * 7),0, math.random() * 500); } }); } } the above code works fine graphview library. want implement mpandroidchart. mpandroidchart when start dataseries_add_new((int)(math.random() * 7),0, math.random() * 500); in above class works well. goal add data data queue graphs. in order so, in above code sample instead of dataseries_add_new((int)(math.random() * 7),0, math.random() * 500); call updateui() poll data queue , call dataseries_add_new((int)(math.random() * 7),0, math.random() * 500);:
public void updateui() { long starttime, endtime; int tmp_sample = sample_get_value(apw_signal); point qpoint = new point(); for(int i=0; i<num_siganl_list; i++) { int poll_num = 0; while(!chartqueue[i].isempty()) { if(poll_num != 0) { if(qpoint.x % 4 == 0) { dataseries_add_new(i, qpoint.x, qpoint.y); } } synchronized (chartqueue_lock) { qpoint = chartqueue[i].poll(); } poll_num = 1; } where graph update code taken mpandroidchart sample app realtime chart.
when "read" button presed app screen goes black time , gives error. please provide insight how solve problem?
Comments
Post a Comment