Hardware Reference
In-Depth Information
SensorChartView = ChartFactory.getLineChartView(this, SensorData,
SensorRenderer);
layout.addView(SensorChartView);
}// end registerUIobjects
The SetupGraph function defined in Listing 8-9 sets the options for how the graph will be rendered to the screen,
and also links the individual data series to the graph. The overall options that are set include the color of the axes,
the text size, the axes' minimums and maximums, and the pan limitations. The color of the data series is controlled
by individual renderers that are added to the multi-series renderer variable. There are a lot of options that can be set
for the graph; be sure to check out the Java reference documentation at www.achartengine.org/content/javadoc/
index.html for more in-depth information. The SetupGraph function needs to be called from the onResume function
of the framework. Add the code line SetupGraph(); after the super.onResume(); line in the function. The SetupGraph
function is called from this function to ensure that the graph will be set up correctly every time the program resumes.
Listing 8-9. Function That Defines How the Graph Is Drawn
public void SetupGraph(){
// set chart-drawing options
SensorRenderer.setAxisTitleTextSize(10);
SensorRenderer.setChartTitleTextSize(10);
SensorRenderer.setLabelsTextSize(10);
SensorRenderer.setLegendTextSize(10);
SensorRenderer.setMargins(new int[] {10, 10, 10, 0});
SensorRenderer.setAxesColor(Color.WHITE);
SensorRenderer.setShowGrid(true);
SensorRenderer.setYAxisMin(−127);
SensorRenderer.setYAxisMax(127);
SensorRenderer.setXAxisMin(0);
SensorRenderer.setXAxisMax(100);
SensorRenderer.setPanLimits(limits);
// add the three series to the multi-series data set
SensorData.addSeries(Sensor1CurrentSeries);
SensorData.addSeries(Sensor2CurrentSeries);
SensorData.addSeries(Sensor3CurrentSeries);
// set color options for the data lines to match graph openFrameworks
XYSeriesRenderer Sensor1renderer = new XYSeriesRenderer();
Sensor1renderer.setColor(Color.GREEN);
XYSeriesRenderer Sensor2renderer = new XYSeriesRenderer();
Sensor2renderer.setColor(Color.YELLOW);
XYSeriesRenderer Sensor3renderer = new XYSeriesRenderer();
Sensor3renderer.setColor(Color.BLUE);
// add the sensor graph with set options to the graph
SensorRenderer.addSeriesRenderer(Sensor1renderer);
SensorRenderer.addSeriesRenderer(Sensor2renderer);
SensorRenderer.addSeriesRenderer(Sensor3renderer);
} // end SetupGraph
The message handler function that is linked to the thread that is created to check for incoming data from the
Arduino is where the program dynamically updates the graph. Because the data is well formatted at the point it is sent
from the Arduino, and the data is consistently sized, the parsing is pretty straightforward—we have only to look at
specific places in the data buffer. This is only possible if the data transition is reliable; in a more refined setup,
a verification step should be used to check that the transition is what is expected. The connection between the Android
device and the Arduino is decently reliable, so this example does not add the verification complexity.
 
Search WWH ::




Custom Search