Permalink
Browse files

Merge branch 'master' of github.com:HalfdanJ/UFO

Conflicts:
	client/client.pde
	client/osc.pde
  • Loading branch information...
HalfdanJ committed Jul 9, 2011
2 parents 923b576 + 2f0b073 commit 8f0672e48bce588c99361e8037d63c8afd014b52
Showing with 235 additions and 0 deletions.
  1. +6 −0 client/client.pde
  2. +155 −0 server/CompassManager.java
  3. +11 −0 server/com.pde
  4. +51 −0 server/gps.pde
  5. +12 −0 server/server.pde
View
@@ -9,6 +9,9 @@ boolean rightRev=false;
boolean fwdbkwOn = false;
void setup() {
+
+
+
size(screenWidth, screenHeight);
background(0);
fontList = PFont.list();
@@ -114,9 +117,12 @@ void draw() {
arc(screenWidth/2.0-70, screenHeight/2.0+100, 50, 50, 0-HALF_PI, TWO_PI*left/255.0-HALF_PI);
+
fill(80, 255, 80);
if (rightRev)
fill(255, 0, 0);
arc(screenWidth/2.0+70, screenHeight/2.0+100, 50, 50, 0-HALF_PI, TWO_PI*right/255.0-HALF_PI);
}
+
+
View
@@ -0,0 +1,155 @@
+import java.lang.reflect.*;
+import java.util.List;
+
+import android.content.Context;
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.SensorEventListener;
+import android.hardware.SensorManager;
+
+
+public class CompassManager {
+ private Sensor sensor;
+ private SensorManager sensorManager;
+
+ Method compassEventMethod;
+ Method directionEventMethod;
+
+ private Boolean supported;
+ private boolean running = false;
+
+ Context context;
+
+
+ public CompassManager(Context parent) {
+ this.context = parent;
+
+ try {
+ compassEventMethod =
+ parent.getClass().getMethod("compassEvent", new Class[] {
+ Float.TYPE, Float.TYPE, Float.TYPE
+ }
+ );
+ }
+ catch (Exception e) {
+ // no such method, or an error.. which is fine, just ignore
+ }
+ try {
+ directionEventMethod =
+ parent.getClass().getMethod("directionEvent", new Class[] {
+ Float.TYPE
+ }
+ );
+ }
+ catch (Exception e) {
+ // no such method, or an error.. which is fine, just ignore
+ }
+ // System.out.println("directionEventMethod is " + directionEventMethod);
+
+ resume();
+ }
+
+
+ public void resume() {
+ if (isSupported()) {
+ startListening();
+ }
+ }
+
+
+ public void pause() {
+ if (isListening()) {
+ stopListening();
+ }
+ }
+
+
+ /**
+ * Returns true if the manager is listening to orientation changes
+ */
+ public boolean isListening() {
+ return running;
+ }
+
+
+ /**
+ * Unregisters listeners
+ */
+ public void stopListening() {
+ running = false;
+ try {
+ if (sensorManager != null && sensorEventListener != null) {
+ sensorManager.unregisterListener(sensorEventListener);
+ }
+ }
+ catch (Exception e) {
+ }
+ }
+
+
+ /**
+ * Returns true if at least one Accelerometer sensor is available
+ */
+ public boolean isSupported() {
+ if (supported == null) {
+ sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
+ List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ORIENTATION);
+ supported = new Boolean(sensors.size() > 0);
+ }
+ return supported;
+ }
+
+
+ public void startListening() {
+ sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
+ List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ORIENTATION);
+ if (sensors.size() > 0) {
+ sensor = sensors.get(0);
+ running = sensorManager.registerListener(sensorEventListener, sensor, SensorManager.SENSOR_DELAY_GAME);
+ }
+ }
+
+
+ /**
+ * The listener that listen to events from the accelerometer listener
+ */
+ private SensorEventListener sensorEventListener = new SensorEventListener() {
+
+ public void onAccuracyChanged(Sensor sensor, int accuracy) {
+ // ignored for now
+ }
+
+ public void onSensorChanged(SensorEvent event) {
+ float x = event.values[0];
+ float y = event.values[1];
+ float z = event.values[2];
+
+ if (compassEventMethod != null) {
+ try {
+ compassEventMethod.invoke(context, new Object[] {
+ x, y, z
+ }
+ );
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ compassEventMethod = null;
+ }
+ }
+
+ if (directionEventMethod != null) {
+ try {
+ directionEventMethod.invoke(context, new Object[] {
+ (float) (-x * Math.PI / 180)
+ }
+ );
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ directionEventMethod = null;
+ }
+ }
+ }
+ };
+}
+
View
@@ -0,0 +1,11 @@
+CompassManager compass;
+float direction;
+
+void setupCom() {
+ compass = new CompassManager(this);
+}
+
+
+void directionEvent(float newDirection) {
+ direction = newDirection;
+}
View
@@ -0,0 +1,51 @@
+// Imports
+import android.content.Context;
+import android.location.Location;
+import android.location.LocationManager;
+import android.location.LocationListener;
+import android.location.GpsStatus.Listener;
+import android.location.GpsStatus.NmeaListener; // not needed yet, but going for nmea data next!
+import android.os.Bundle;
+
+LocationManager locationManager;
+MyLocationListener locationListener;
+
+// Variables to hold the current GPS data
+float currentLatitude = 0;
+float currentLongitude = 0;
+float currentAccuracy = 0;
+String currentProvider = "";
+
+//-----------------------------------------------------------------------------------------
+
+
+
+//-----------------------------------------------------------------------------------------
+
+
+
+//-----------------------------------------------------------------------------------------
+
+// Define a listener that responds to location updates
+class MyLocationListener implements LocationListener {
+ void onLocationChanged(Location location) {
+ // Called when a new location is found by the network location provider.
+ currentLatitude = (float)location.getLatitude();
+ currentLongitude = (float)location.getLongitude();
+ currentAccuracy = (float)location.getAccuracy();
+ currentProvider = location.getProvider();
+ }
+ void onProviderDisabled (String provider) {
+ currentProvider = "";
+ }
+
+ void onProviderEnabled (String provider) {
+ currentProvider = provider;
+ }
+
+ void onStatusChanged (String provider, int status, Bundle extras) {
+ // Nothing yet...
+ }
+
+}
+
View
@@ -13,6 +13,9 @@ PFont androidFont;
void setup()
{
+
+ setupCom();
+
orientation(PORTRAIT);
frameRate(30);
@@ -24,7 +27,16 @@ void setup()
textFont(androidFont);
}
+void onResume() {
+ super.onResume();
+ // Compass
+ if (compass != null) compass.resume();
+}
+void onPause() {
+ if (compass != null) compass.pause();
+ super.onPause();
+}
void draw()
{

0 comments on commit 8f0672e

Please sign in to comment.