Browse Source

Accelerometer class implemented in crown

mikymod 13 years ago
parent
commit
1e7b2877c8

+ 17 - 12
android/src/crown/android/CrownActivity.java

@@ -22,9 +22,9 @@ public class CrownActivity extends Activity
 	private static SensorManager sm;
 	private Sensor sensor;
 
-	
-    /** Called when the activity is first created. */
-    @Override
+	//TODO: add count of finger on screen at the same time
+
+//---------------------------------------------------------------------
     public void onCreate(Bundle savedInstanceState)
     {
         super.onCreate(savedInstanceState);
@@ -32,23 +32,26 @@ public class CrownActivity extends Activity
         mView = new CrownView(getApplication());
 	    sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
 	    sensor = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
-
     }
 
+//---------------------------------------------------------------------
 	public void onStart()
 	{
 		super.onStart();
 	}
-	
+
+//---------------------------------------------------------------------	
 	public void onRestart()
 	{
 		super.onRestart();
 	}
 
+//---------------------------------------------------------------------
 	public void onResume()
 	{
 		super.onResume();
         mView.onResume();
+
 		if (sensor != null) 
 		{
 		  sm.registerListener(sensorEventListener, sensor, SensorManager.SENSOR_DELAY_NORMAL);
@@ -63,24 +66,28 @@ public class CrownActivity extends Activity
 		}
 	}
 
+//---------------------------------------------------------------------
 	public void onPause()
 	{
 		super.onPause();
         mView.onPause();
+
 		sm.unregisterListener(sensorEventListener);
 	}
 
+//---------------------------------------------------------------------
 	public void onStop()
 	{
 		super.onStop();
 	}
 
+//---------------------------------------------------------------------
 	public void onDestroy()
 	{
 		super.onDestroy();
 	}
 
-	@Override
+//---------------------------------------------------------------------
 	public boolean onTouchEvent(MotionEvent event)
 	{
 	    float x = event.getX();
@@ -111,7 +118,8 @@ public class CrownActivity extends Activity
 		}
 		return true;
 	}
-	
+
+//---------------------------------------------------------------------
   	private SensorEventListener sensorEventListener = new SensorEventListener() 
 	{
     	@Override
@@ -122,14 +130,11 @@ public class CrownActivity extends Activity
     	@Override
     	public void onSensorChanged(SensorEvent event) 
 		{
-     	 	// angle between the magnetic north directio
-     	 	// 0=North, 90=East, 180=South, 270=West
      	 	float x = event.values[0];
 			float y = event.values[1];
 			float z = event.values[2];
 			Log.i(TAG, "X:" + x + "Y:" + y + "Z:" + z);
+			CrownLib.pushEvent(11,(int) x,(int) y, (int)z, 0);
     	}
-  };
-
-
+  	};
 }

+ 33 - 0
src/input/Accelerometer.h

@@ -0,0 +1,33 @@
+#pragma once
+
+namespace crown
+{
+
+class InputManager;
+
+struct AccelerometerEvent
+{
+	int32_t x;
+	int32_t y;
+	int32_t z;
+};
+
+class AccelerometerListener
+{
+	virtual public accelerometer_changed(const AccelerometerEvent& event) { (void)event; };
+};
+
+class Accelerometer
+{
+public:
+	
+	Accelerometer() : m_listener(NULL) {}
+
+	virtual ~Accelerometer() {}
+
+	inline void set_listener(AccelerometerListener* listener) { m_listener = listener; }
+
+private:
+
+	AccelerometerListener* m_listener;
+};

+ 1 - 0
src/input/InputManager.h

@@ -50,6 +50,7 @@ public:
 	bool IsMouseAvailable() {}
 	bool IsKeyboardAvailable() {}
 	bool IsTouchAvailable() {}
+	bool IsAccelerometerAvailable {}
 
 
 	inline void RegisterMouseListener(MouseListener* listener)

+ 1 - 1
src/input/Touch.h

@@ -32,7 +32,7 @@ class InputManager;
 
 struct TouchEvent
 {
-	int32_t point32_ter_id;
+	int32_t pointer_id;
 	int32_t x;
 	int32_t y;
 };

+ 5 - 5
src/os/android/AndroidInput.cpp

@@ -9,8 +9,8 @@ namespace os
 extern "C" 
 {
     JNIEXPORT void JNICALL Java_crown_android_CrownLib_pushEvent(JNIEnv * env, jobject obj, jint type, jint a, jint b, jint c, jint d);
-
 };
+
 JNIEXPORT void JNICALL Java_crown_android_CrownLib_pushEvent(JNIEnv * env, jobject obj, jint type, jint a, jint b, jint c, jint d)
 {
 	push_event((OSEventType)type, a, b, c, d);
@@ -24,22 +24,22 @@ void init_input()
 
 void get_cursor_xy(int32_t& x, int32_t& y)
 {
-	// FIXME
+	// not necessary
 }
 
 void set_cursor_xy(int32_t x, int32_t y)
 {
-	// FIXME
+	// not necessary
 }
 
 void hide_cursor()
 {
-	// FIXME
+	// not necessary
 }
 
 void show_cursor()
 {
-	// FIXME
+	// not necessary
 }
 } // namespace os
 } // namespace crown