Add sensor class for magnetic field uncalibrated
@@ -12,6 +12,34 @@ Sensor = autoclass('android.hardware.Sensor')
SensorManager = autoclass('android.hardware.SensorManager')
+class MFUSensorListener(PythonJavaClass):
+ __javainterfaces__ = ['android/hardware/SensorEventListener']
+
+ def __init__(self):
+ super(MFUSensorListener, self).__init__()
+ service = activity.getSystemService(Context.SENSOR_SERVICE)
+ self.SensorManager = cast('android.hardware.SensorManager', service)
+
+ self.sensor = self.SensorManager.getDefaultSensor(
+ Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED)
+ self.values = [None, None, None, None, None, None]
+
+ def enable(self):
+ self.SensorManager.registerListener(self, self.sensor,
+ SensorManager.SENSOR_DELAY_NORMAL)
+
+ def disable(self):
+ self.SensorManager.unregisterListener(self, self.sensor)
+
+ @java_method('(Landroid/hardware/SensorEvent;)V')
+ def onSensorChanged(self, event):
+ self.values = event.values[:6]
+
+ @java_method('(Landroid/hardware/Sensor;I)V')
+ def onAccuracyChanged(self, sensor, accuracy):
+ pass
+
+
class MagneticFieldSensorListener(PythonJavaClass):
__javainterfaces__ = ['android/hardware/SensorEventListener']
@@ -48,22 +76,32 @@ class AndroidCompass(Compass):
def _enable(self):
if (not self.bState):
- self.listener = MagneticFieldSensorListener()
- self.listener.enable()
+ self.listenerm = MagneticFieldSensorListener()
+ self.listenermu = MFUSensorListener()
+ self.listenerm.enable()
+ self.listenermu.enable()
self.bState = True
def _disable(self):
if (self.bState):
self.bState = False
- self.listener.disable()
- del self.listener
+ self.listenerm.disable()
+ self.listenermu.disable()
+ del self.listenerm
+ del self.listenerm
def _get_orientation(self):
if (self.bState):
- return tuple(self.listener.values)
+ return tuple(self.listenerm.values)
else:
return (None, None, None)
+ def _get_field_uncalib(self):
+ if (self.bState):
+ return tuple(self.listenermu.values)
+ else:
+ return (None, None, None, None, None, None)
+
def __del__(self):
if(self.bState):
self._disable()
