android:text="One Second Gyro Sums"
android:textAppearance="?android:attr/textAppearanceMedium" />
</GridLayout>
+ <GridLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:columnCount="1" >
+ <TextView
+ android:id="@+id/ibLatText"
+ android:layout_column="0"
+ android:layout_gravity="left|top"
+ android:layout_row="1"
+ android:text="Latitude"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+ <TextView
+ android:id="@+id/ibLonText"
+ android:layout_column="0"
+ android:layout_gravity="center_horizontal|top"
+ android:layout_row="1"
+ android:text="Longitude"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+ <TextView
+ android:id="@+id/ibDistText"
+ android:layout_column="0"
+ android:layout_gravity="right|top"
+ android:layout_row="1"
+ android:text="Distance"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+ <TextView
+ android:id="@+id/beaconLabel"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_column="0"
+ android:layout_gravity="left|center_vertical"
+ android:layout_row="0"
+ android:text="IBeacon Distance"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+ </GridLayout>
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
import java.util.List;
import java.util.LinkedList;
+import java.util.HashMap;
import java.util.Collection;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
private Task task;
private IBeaconManager ibeacon;
+ private String uuid;
+ private HashMap<Integer,LatLon> locations;
/* Public methods */
public Beacon(Task task) {
- this.task = task;
IBeaconManager.LOG_DEBUG = true;
+
+ // Setup object
+ this.uuid = "iBeaconNav";
+ this.task = task;
+
+ // Initialize iBeacons
+ this.locations = new HashMap<Integer,LatLon>();
+ this.addIBeacon(1, 1, 34.0722, -118.4441);
+ this.addIBeacon(1, 2, 34.0722, -118.4441);
+ this.addIBeacon(1, 3, 34.0722, -118.4441);
+ this.addIBeacon(1, 5, 34.0722, -118.4441);
+ this.addIBeacon(1, 5, 34.0722, -118.4441);
}
public void connect() {
//this.ibeacon.setBackgroundMode(this, true);
}
+ /* Private methods */
+ private void addIBeacon(int major, int minor, double lat, double lon) {
+ IBeacon ib = new IBeacon(this.uuid, major, minor);
+ LatLon loc = new LatLon(lat, lon);
+ this.locations.put(ib.getMinor(), loc);
+ }
+
/* IBeaconConsumer Methods
* Pass most of these off to Task,
* I don't even know why they're here */
/* RangeNotifier Methods */
@Override
public void didRangeBeaconsInRegion(Collection<IBeacon> iBeacons, Region region) {
- Util.debug("Task: didRangeBeaconsInRegion");
+ Util.debug("Task: didRangeBeaconsInRegion - " + iBeacons.size() + " beacons");
+ for (IBeacon ib : iBeacons) {
+ if (this.locations.containsKey(ib.getMinor())) {
+ LatLon loc = this.locations.get(ib.getMinor());
+ float[] data = new float[4];
+ data[0] = CMD.Data.BEACON.ordinal();
+ data[1] = (float)loc.lat;
+ data[2] = (float)loc.lon;
+ data[3] = (float)ib.getAccuracy();
+ this.task.tellMain(CMD.Response.SHOWDATA, data);
+ } else {
+ Util.debug("Unknown beacon:" +
+ " " + ib.getProximityUuid() +
+ ":" + ib.getMajor() +
+ ":" + ib.getMinor() +
+ " @ " + ib.getAccuracy());
+ }
+ }
}
/* MonitorNotifier Methods */
public void didDetermineStateForRegion(int state, Region region) {
Util.debug("Task: didDetermineStateForRegion");
}
+
+ /* Location class */
+ class LatLon {
+ public double lat = 0;
+ public double lon = 0;
+
+ public LatLon(double lat, double lon) {
+ this.lat = lat;
+ this.lon = lon;
+ }
+ }
}
/* Show Data Commands */
static enum Data {
- ACC,
- MAG,
- GYR,
- GYR1HZ,
- ORIENT,
- WRDACC,
- WRDGYR,
- STPCNT,
- POSITION,
- ROTATION,
- HEADING,
- STABLE,
+ ACC, // x, y, z
+ MAG, // x, y, z
+ GYR, // roll, pitch, yaw (delta radians?)
+ GYR1HZ, // roll, pitch, yaw (delta radians?)
+ ORIENT, // roll, pitch, yaw (???
+ WRDACC, // x, y, z (world frame)
+ WRDGYR, // roll, pitch, yaw (worldf rame?)
+ STPCNT, // count, gravity
+ POSITION, // cur x, cur y
+ ROTATION, // roll, pitch, yaw (degrees)
+ HEADING, // heading
+ STABLE, // stable (true/false)
+ BEACON, // lat, lon, dist
}
}
import android.widget.Toast;
import android.os.Bundle;
-
+
import com.google.android.gms.maps.*;
import com.google.android.gms.maps.model.*;
Util.debug("Main: onRegister_task");
this.task = task;
}
-
+
private void onPosition()
{
Util.debug("Main: onPosition");
textView1 = (TextView)findViewById(R.id.stableText);
displayNum = 1;
break;
+ case BEACON:
+ textView1 = (TextView)findViewById(R.id.ibLatText);
+ textView2 = (TextView)findViewById(R.id.ibLonText);
+ textView3 = (TextView)findViewById(R.id.ibDistText);
+ displayNum = 3;
+ break;
default:
Util.debug("Main: Nothing Matches");
}
-
- textView1.setText(Float.toString(data[1]));
- if (displayNum >1){
- textView2.setText(Float.toString(data[2]));
- }
- if (displayNum >2){
- textView3.setText(Float.toString(data[3]));
+
+ switch (displayNum) {
+ case 3: textView3.setText(Float.toString(data[3]));
+ case 2: textView2.setText(Float.toString(data[2]));
+ case 1: textView1.setText(Float.toString(data[1]));
}
}
-
+
/* Private service methods */
private void register()
{
this.scroll = (ScrollView) findViewById(R.id.debug_scroll);
this.rstHdBttn = (Button) findViewById(R.id.rstHdBttn);
this.rstDstBttn= (Button) findViewById(R.id.rstDstBttn);
-
+
// TODO - remove these
rstHdBttn.setOnClickListener(new View.OnClickListener() {
@Override
.putExtra("Command", CMD.Command.RSTHEAD));
}
});
-
+
rstDstBttn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
this.sensorManager = (SensorManager)task.getSystemService(Context.SENSOR_SERVICE);
// Get sensors
- accSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
- grvSensor = sensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);
- magSensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
- gyrSensor = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
-
+ this.accSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
+ this.grvSensor = sensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);
+ this.magSensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
+ this.gyrSensor = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
+ }
+
+ public void connect() {
// Connect sensor listeners
sensorManager.registerListener(this, accSensor, SensorManager.SENSOR_DELAY_FASTEST);
sensorManager.registerListener(this, grvSensor, SensorManager.SENSOR_DELAY_FASTEST);
sensorManager.registerListener(this, gyrSensor, SensorManager.SENSOR_DELAY_FASTEST);
}
+ public void disconnect() {
+ // Remove sensor listeners
+ sensorManager.unregisterListener(this, accSensor);
+ sensorManager.unregisterListener(this, grvSensor);
+ sensorManager.unregisterListener(this, magSensor);
+ sensorManager.unregisterListener(this, gyrSensor);
+ }
+
public void reset_heading() {
Util.debug("Sensors: handle - reset heading");
this.rotation = new Quat();
case CONNECT:
Util.debug("Task: handle - connect");
this.running = true;
+ this.beacon.connect();
+ this.sensors.connect();
this.notify("Connected", android.R.drawable.presence_online);
- //this.ibeacon.setBackgroundMode(this, false);
break;
// Stop client thread
case DISCONNECT:
Util.debug("Task: handle - register");
- //this.ibeacon.setBackgroundMode(this, true);
this.running = false;
+ this.beacon.disconnect();
+ this.sensors.disconnect();
this.stopForeground(true);
break;