Here is the program and interface for my apps.
figure 1: The Eclipse software with my complete apps
Figure 2: Simulator Android run the apps
Figure 3: The icon shoes (pedometer) as my apps
----------------------------------------------------------------------------------------------------
Coding for pedometer apps (Fadzli)
----------------------------------------------------------------------------------------------------
/*
SensorGraph - Example to use with Amarino 2.0
*/
package edu.mit.media.hlt.sensorgraph;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Chronometer;
import android.widget.TextView;
import at.abraxas.amarino.Amarino;
import at.abraxas.amarino.AmarinoIntent;
/**
* <h3>Application that receives sensor readings from Arduino displaying it graphically.</h3>
*
* This example demonstrates how to catch data sent from Arduino forwarded by Amarino 2.0.
* SensorGraph registers a BroadcastReceiver to catch Intents with action string: <b>AmarinoIntent.ACTION_RECEIVED</b>
*
*
*
*/
public class SensorGraph extends Activity {
private static final String TAG = "SensorGraph";
// change this to your Bluetooth device address
private static final String DEVICE_ADDRESS = "00:12:04:20:51:76"; //"00:06:66:03:73:7B";
double myElapsedMillis;
double distance;
double calory;
private TextView mValueTV;
private TextView mValueDS;
private TextView mValueCL;
private ArduinoReceiver arduinoReceiver = new ArduinoReceiver();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// get handles to Views defined in our layout file
mValueTV = (TextView) findViewById(R.id.value);
mValueDS = (TextView) findViewById(R.id.distance);
mValueCL = (TextView) findViewById(R.id.calories);
final Chronometer myChronometer = (Chronometer)findViewById(R.id.chronometer1);
Button buttonStart = (Button)findViewById(R.id.button1);
buttonStart.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
myChronometer.start();
}});
}
@Override
protected void onStart() {
super.onStart();
// in order to receive broadcasted intents we need to register our receiver
registerReceiver(arduinoReceiver, new IntentFilter(AmarinoIntent.ACTION_RECEIVED));
// this is how you tell Amarino to connect to a specific BT device from within your own code
Amarino.connect(this, DEVICE_ADDRESS);
}
@Override
protected void onStop() {
super.onStop();
// if you connect in onStart() you must not forget to disconnect when your app is closed
Amarino.disconnect(this, DEVICE_ADDRESS);
// do never forget to unregister a registered receiver
unregisterReceiver(arduinoReceiver);
}
/**
* ArduinoReceiver is responsible for catching broadcasted Amarino
* events.
*
* It extracts data from the intent and updates the graph accordingly.
*/
public class ArduinoReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String data = null;
// the device address from which the data was sent, we don't need it here but to demonstrate how you retrieve it
final String address = intent.getStringExtra(AmarinoIntent.EXTRA_DEVICE_ADDRESS);
// the type of data which is added to the intent
final int dataType = intent.getIntExtra(AmarinoIntent.EXTRA_DATA_TYPE, -1);
// we only expect String data though, but it is better to check if really string was sent
// later Amarino will support differnt data types, so far data comes always as string and
// you have to parse the data to the type you have sent from Arduino, like it is shown below
if (dataType == AmarinoIntent.STRING_EXTRA){
data = intent.getStringExtra(AmarinoIntent.EXTRA_DATA);
if (data != null){
mValueTV.setText(data + " steps");
try {
// since we know that our string value is an int number we can parse it to an integer
final int sensorReading = Integer.parseInt(data);
distance = sensorReading * 0.762;
mValueDS.setText(distance + " m");
calory = sensorReading * 0.05;
mValueCL.setText(calory + " kcal");
}
catch (NumberFormatException e) { /* oh data was not an integer */ }
}
}
}
}
}

1 comments:
Well done Fadzli Fuzi. You have did a great job by learning by your own and you did a personal app also.
Im also in a learning curve and I hope some day I'll on my own. Thanks for the inspiration.
Easton
Personalized Erasers
Post a Comment