I think your problem is related to the graphic output when you are not in the UI thread. To understand this please refer to https://developer.android.com/training/multiple-threads/communicate-ui.html
2014-07-28 19:48 GMT+02:00 Jamal Thorne <[email protected]>: > Hello, > > I am trying produce a graph on my android phone of the 5 analog input. It > works with the Abstract IOIO Activity but once I make the switch to > IOIOActivity, the code does nothing can anon tell me if my setup is correct > or where i went wrong. > > > > package com.jamal.sideswipegraph; > > import ioio.lib.api.AnalogInput; > import ioio.lib.api.exception.ConnectionLostException; > import ioio.lib.util.BaseIOIOLooper; > import ioio.lib.util.IOIOLooper; > import ioio.lib.util.android.IOIOActivity; > import android.content.pm.ActivityInfo; > import android.graphics.Color; > import android.os.Bundle; > import android.view.Window; > import android.view.WindowManager; > import android.widget.Button; > import android.widget.LinearLayout; > import android.widget.ToggleButton; > > import com.jjoe64.graphview.GraphView; > import com.jjoe64.graphview.GraphView.GraphViewData; > import com.jjoe64.graphview.GraphView.LegendAlign; > import com.jjoe64.graphview.GraphViewSeries; > import com.jjoe64.graphview.GraphViewSeries.GraphViewStyle; > import com.jjoe64.graphview.LineGraphView; > > public class MainActivity extends IOIOActivity { > Button IOIOConnect, IOIODisconnect, IOIOxMinus,IOIOxPlus; > ToggleButton tbLock,tbScroll, tbStream; > static boolean Lock, AutoScrollX,Stream; > static LinearLayout GraphView; > static GraphView graphView; > static GraphViewSeries Series_Pin1; > static GraphViewSeries Series_Pin2; > static GraphViewSeries Series_Pin3; > static GraphViewSeries Series_Pin4; > static GraphViewSeries Series_Pin5; > private static double graph2LastXValue=0; > private static int Xview=10; > @Override > protected void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); > requestWindowFeature(Window.FEATURE_NO_TITLE); > > this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); > setContentView(R.layout.activity_main); > LinearLayout background = (LinearLayout)findViewById(R.id.bg); > background.setBackgroundColor(Color.BLACK); > init(); > Buttoninit(); > } > void init(){ > GraphView = (LinearLayout)findViewById(R.id.Graph); > Series_Pin1 = new GraphViewSeries("Signal", > new GraphViewStyle(Color.YELLOW,2), > new GraphViewData[]{new GraphViewData(0,0)}); > Series_Pin2 = new GraphViewSeries("Signal", > new GraphViewStyle(Color.BLUE,2), > new GraphViewData[]{new GraphViewData(0,0)}); > Series_Pin3 = new GraphViewSeries("Signal", > new GraphViewStyle(Color.RED,2), > new GraphViewData[]{new GraphViewData(0,0)}); > Series_Pin4 = new GraphViewSeries("Signal", > new GraphViewStyle(Color.GREEN,2), > new GraphViewData[]{new GraphViewData(0,0)}); > Series_Pin5 = new GraphViewSeries("Signal", > new GraphViewStyle(Color.WHITE,2), > new GraphViewData[]{new GraphViewData(0,0)}); > graphView = new LineGraphView(this,"Graph"); > graphView.setScrollable(true); > graphView.setShowLegend(true); > graphView.setLegendAlign(LegendAlign.BOTTOM); > graphView.setManualYAxis(true); > graphView.setManualYAxisBounds(5, -5); > graphView.addSeries(Series_Pin1); > graphView.addSeries(Series_Pin2); > graphView.addSeries(Series_Pin3); > graphView.addSeries(Series_Pin4); > graphView.addSeries(Series_Pin5); > graphView.addView(graphView); > } > void Buttoninit(){ > IOIOConnect = (Button)findViewById(R.id.IOIOConnect); > //IOIOConnect.setOnClickListener(this); > IOIODisconnect = (Button)findViewById(R.id.IOIODisconnect); > //IOIODisconnect.setOnClickListener(this); > //X-axis control button > IOIOxMinus = (Button)findViewById(R.id.IOIOxMinus); > //IOIOxMinus.setOnClickListener(this); > IOIOxPlus = (Button)findViewById(R.id.IOIOxPlus); > //IOIOxPlus.setOnClickListener(this); > tbLock = (ToggleButton)findViewById(R.id.tbLock); > //tbLock.setOnClickListener(this); > tbScroll = (ToggleButton)findViewById(R.id.tbScroll); > //tbScroll.setOnClickListener(this); > tbStream = (ToggleButton)findViewById(R.id.tbStream); > //tbStream.setOnClickListener(this); > //init toggleButton > Lock=true; > AutoScrollX=true; > Stream=false; > } > class IOIOThread extends BaseIOIOLooper { > private AnalogInput mPin1,mPin2,mPin3,mPin4,mPin5; > int capacity=1000; > > @Override > public void setup() throws ConnectionLostException { > try { > mPin1=ioio_.openAnalogInput(39); > mPin2=ioio_.openAnalogInput(40); > mPin3=ioio_.openAnalogInput(41); > mPin4=ioio_.openAnalogInput(42); > mPin5=ioio_.openAnalogInput(43); > > mPin1.setBuffer(capacity); > mPin2.setBuffer(capacity); > mPin3.setBuffer(capacity); > mPin4.setBuffer(capacity); > mPin5.setBuffer(capacity); > } catch (ConnectionLostException e) { > throw e; > } > } > @Override > public void loop() throws ConnectionLostException { > try { > final float reading_pin1 = mPin1.readBuffered(); > final float reading_pin2 = mPin2.readBuffered(); > final float reading_pin3 = mPin3.readBuffered(); > final float reading_pin4 = mPin4.readBuffered(); > final float reading_pin5 = mPin5.readBuffered(); > //addPoint(reading * 100); > //setText(Float.toString((reading * 100))); > Series_Pin1.appendData(new > GraphViewData(graph2LastXValue,reading_pin1),AutoScrollX); > Series_Pin2.appendData(new > GraphViewData(graph2LastXValue,reading_pin2),AutoScrollX); > Series_Pin3.appendData(new > GraphViewData(graph2LastXValue,reading_pin3),AutoScrollX); > Series_Pin4.appendData(new > GraphViewData(graph2LastXValue,reading_pin4),AutoScrollX); > Series_Pin5.appendData(new > GraphViewData(graph2LastXValue,reading_pin5),AutoScrollX); > > //X-axis control > if (graph2LastXValue >= Xview && Lock == true){ > Series_Pin1.resetData(new GraphViewData[] {}); > Series_Pin2.resetData(new GraphViewData[] {}); > Series_Pin3.resetData(new GraphViewData[] {}); > Series_Pin4.resetData(new GraphViewData[] {}); > Series_Pin5.resetData(new GraphViewData[] {}); > graph2LastXValue = 0; > }else graph2LastXValue += 0.1; > > if(Lock == true) > graphView.setViewPort(0, Xview); > else > graphView.setViewPort(graph2LastXValue-Xview, Xview); > > //refresh > GraphView.removeView(graphView); > GraphView.addView(graphView); > Thread.sleep(10); > } catch (InterruptedException e) { > ioio_.disconnect(); > } catch (ConnectionLostException e) { > throw e; > } > } > } > @Override > protected IOIOLooper createIOIOLooper() { > return new IOIOThread(); > } > > } > > -- > 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.
