本文整理匯總了Java中android.hardware.Sensor.TYPE_MAGNETIC_FIELD屬性的典型用法代碼示例。如果您正苦於以下問題:Java Sensor.TYPE_MAGNETIC_FIELD屬性的具體用法?Java Sensor.TYPE_MAGNETIC_FIELD怎麽用?Java Sensor.TYPE_MAGNETIC_FIELD使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.hardware.Sensor
的用法示例。
在下文中一共展示了Sensor.TYPE_MAGNETIC_FIELD屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onSensorChanged
public void onSensorChanged(SensorEvent event) {
if (event.accuracy == SensorManager.SENSOR_STATUS_ACCURACY_LOW) return;
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
arrayCopy(event.values, geomagnetic);
}
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
arrayCopy(event.values, gravity);
}
if (SensorManager.getRotationMatrix(R, I, gravity, geomagnetic)) {
SensorManager.getOrientation(R, orientation);
azimuth += easing * (orientation[0] - azimuth);
pitch += easing * (orientation[1] - pitch);
roll += easing * (orientation[2] - roll);
}
}
示例2: onSensorChanged
@Override
public void onSensorChanged(SensorEvent event) {
switch (event.sensor.getType()) {
case Sensor.TYPE_ROTATION_VECTOR:
System.arraycopy(event.values, 0, mRotation, 0, 3);
calculateOrientation();
break;
case Sensor.TYPE_ACCELEROMETER:
mAccel = LowPassFilter.lowPass(event.values.clone(), mAccel);
calculateOrientation();
break;
case Sensor.TYPE_MAGNETIC_FIELD:
mMagnet = LowPassFilter.lowPass(event.values.clone(), mMagnet);
break;
case Sensor.TYPE_STEP_DETECTOR:
mStep = event.values[0] == 1.0;
announceChange(STEP_UPDATE);
break;
}
}
示例3: onSensorChanged
/**
* SensorEventListener method called when sensor values are updated. Reads gravitational and
* magnetic field information, and when both are available computes the orientation values
* and calls the delegate with them.
*/
@Override public void onSensorChanged(SensorEvent event) {
switch(event.sensor.getType()) {
case Sensor.TYPE_MAGNETIC_FIELD:
mags = event.values.clone();
break;
case Sensor.TYPE_ACCELEROMETER:
accels = event.values.clone();
break;
}
if (mags!=null && accels!=null) {
SensorManager.getRotationMatrix(R, I, accels, mags);
SensorManager.getOrientation(R, orientationValues);
delegate.receivedOrientationValues(
orientationValues[0], orientationValues[1], orientationValues[2]);
}
}
示例4: onSensorChanged
@Override
public void onSensorChanged(SensorEvent event) {
synchronized (this) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
lowPass(event.values, mGravity);
}
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
lowPass(event.values, mGeomagnetic);
}
float R[] = new float[9];
float I[] = new float[9];
if (SensorManager.getRotationMatrix(R, I, mGravity, mGeomagnetic)) {
float orientation[] = new float[3];
SensorManager.getOrientation(R, orientation);
mOrientation[0] = (float)Math.toDegrees(orientation[0]);
adjustArrow();
}
}
}
示例5: onSensorChanged
@Override
public void onSensorChanged(SensorEvent event) {
// we received a sensor event. it is a good practice to check
// that we received the proper event
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
System.arraycopy(event.values, 0, magnitudeValues, 0, magnitudeValues.length);
} else if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
System.arraycopy(event.values, 0, accelerometerValues, 0, accelerometerValues.length);
}
if (magnitudeValues != null && accelerometerValues != null) {
// Fuse accelerometer with compass
SensorManager.getRotationMatrix(currentOrientationRotationMatrix.matrix, inclinationValues, accelerometerValues,
magnitudeValues);
// Transform rotation matrix to quaternion
currentOrientationQuaternion.setRowMajor(currentOrientationRotationMatrix.matrix);
}
}
示例6: onSensorChanged
public void onSensorChanged(SensorEvent event) {
int type = event.sensor.getType();
float[] data;
if (type == Sensor.TYPE_ACCELEROMETER) {
data = mGData;
} else if (type == Sensor.TYPE_MAGNETIC_FIELD) {
data = mMData;
} else {
// we should not be here.
return;
}
for (int i=0 ; i<3 ; i++)
data[i] = event.values[i];
SensorManager.getRotationMatrix(mR, mI, mGData, mMData);
// some test code which will be used/cleaned up before we ship this.
// SensorManager.remapCoordinateSystem(mR,
// SensorManager.AXIS_X, SensorManager.AXIS_Z, mR);
// SensorManager.remapCoordinateSystem(mR,
// SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, mR);
SensorManager.getOrientation(mR, mOrientation);
float incl = SensorManager.getInclination(mI);
if (mCount++ > 50) {
final float rad2deg = (float)(180.0f/Math.PI);
mCount = 0;
Log.d("Compass", "yaw: " + (int)(mOrientation[0]*rad2deg) +
" pitch: " + (int)(mOrientation[1]*rad2deg) +
" roll: " + (int)(mOrientation[2]*rad2deg) +
" incl: " + (int)(incl*rad2deg)
);
}
}
示例7: onSensorChanged
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
if(sensorEvent.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
synchronized (this.mutex) {
this.magneticField.getMagneticField().setX(sensorEvent.values[0]);
this.magneticField.getMagneticField().setY(sensorEvent.values[1]);
this.magneticField.getMagneticField().setZ(sensorEvent.values[2]);
Collection<Double> tmpCov = Arrays.asList(); //TODO
this.magneticField.setMagneticFieldCovariance(tmpCov);
this.magneTime = sensorEvent.timestamp;
// logger.debug("Sensor compass value : " + this.magneticField);
// System.out.println("Sensor compass value : " + this.magneticField);
}
}
}
示例8: parse
@Override
public double[] parse(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
accValues = new float[3];
fixOrientation(event.values, accValues);
accFilt.add(accValues);
}
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
magValues = new float[3];
fixOrientation(event.values, magValues);
magFilt.add(magValues);
}
if (magValues != null && accValues != null) {
float[] rotationMatrix = new float[9];
if (SensorManager.getRotationMatrix(rotationMatrix, null, accFilt.getAverage(), magFilt.getAverage())) {
degHolder = parseRoatationMatrix(rotationMatrix);
}
}
return degHolder;
}
示例9: onSensorChanged
@Override
public void onSensorChanged(SensorEvent event) {
// we received a sensor event. it is a good practice to check
// that we received the proper event
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
System.arraycopy(event.values, 0, magnitudeValues, 0, magnitudeValues.length);
} else if (event.sensor.getType() == Sensor.TYPE_GRAVITY) {
System.arraycopy(event.values, 0, gravityValues, 0, gravityValues.length);
}
if (magnitudeValues != null && gravityValues != null) {
// Fuse gravity-sensor (virtual sensor) with compass
SensorManager.getRotationMatrix(currentOrientationRotationMatrix.matrix, inclinationValues, gravityValues, magnitudeValues);
// Transform rotation matrix to quaternion
currentOrientationQuaternion.setRowMajor(currentOrientationRotationMatrix.matrix);
}
}
示例10: onSensorChanged
@Override
public void onSensorChanged(SensorEvent event) {
int type = event.sensor.getType();
String luminosity_value;
String magnetic_value;
switch (type) {
case Sensor.TYPE_MAGNETIC_FIELD:
if ((System.currentTimeMillis() - lastUpdateSensorMagnetic) < Utils.SAMPLE_MILLIS) {
break;
}
magnetic_value = Math.round(event.values[0]) + ", " + Math.round(event.values[1]) + ", " + Math.round(event.values[2]);
real_magnetic_value = event.values[0] + ", " + event.values[1] + ", " + event.values[2];
bt_magnetic_sample.setText(magnetic_value + " (uT)");
bt_magnetic_sample.setEnabled(true);
lastUpdateSensorMagnetic = System.currentTimeMillis();
break;
case Sensor.TYPE_LIGHT:
if ((System.currentTimeMillis() - lastUpdateSensorLuminosity) < Utils.SAMPLE_MILLIS) {
break;
}
luminosity_value = event.values[0] + "lx";
bt_luminosity_sample.setText(luminosity_value);
bt_luminosity_sample.setEnabled(true);
lastUpdateSensorLuminosity = System.currentTimeMillis();
break;
default:
break;
}
}
示例11: onSensorChanged
/**
* Event that fires when sensor data is updated
*
* @param event Event data
*/
public void onSensorChanged(SensorEvent event) {
switch (event.sensor.getType()) {
case Sensor.TYPE_ACCELEROMETER:
// alpha is calculated as t / (t + dT)
// with t, the low-pass filter's time-constant
// and dT, the event delivery rate
final float alpha = 0.8f;
acceleration[0] = event.values[0];
acceleration[1] = event.values[1];
acceleration[2] = event.values[2];
gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0];
gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1];
gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2];
linear_acceleration[0] = event.values[0] - gravity[0];
linear_acceleration[1] = event.values[1] - gravity[1];
linear_acceleration[2] = event.values[2] - gravity[2];
updateScreenOrientation();
break;
case Sensor.TYPE_MAGNETIC_FIELD:
geomagnetic[0] = event.values[0];
geomagnetic[1] = event.values[1];
geomagnetic[2] = event.values[2];
updateScreenOrientation();
break;
}
}
示例12: isRestricted
@SuppressWarnings("deprecation")
private boolean isRestricted(XParam param, int type) throws Throwable {
if (type == Sensor.TYPE_ALL)
return false;
else if (type == Sensor.TYPE_ACCELEROMETER || type == Sensor.TYPE_LINEAR_ACCELERATION) {
if (isRestricted(param, "acceleration"))
return true;
} else if (type == Sensor.TYPE_GRAVITY) {
if (isRestricted(param, "gravity"))
return true;
} else if (type == Sensor.TYPE_RELATIVE_HUMIDITY) {
if (isRestricted(param, "humidity"))
return true;
} else if (type == Sensor.TYPE_LIGHT) {
if (isRestricted(param, "light"))
return true;
} else if (type == Sensor.TYPE_MAGNETIC_FIELD || type == Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED) {
if (isRestricted(param, "magnetic"))
return true;
} else if (type == Sensor.TYPE_SIGNIFICANT_MOTION) {
if (isRestricted(param, "motion"))
return true;
} else if (type == Sensor.TYPE_ORIENTATION || type == Sensor.TYPE_GYROSCOPE
|| type == Sensor.TYPE_GYROSCOPE_UNCALIBRATED) {
if (isRestricted(param, "orientation"))
return true;
} else if (type == Sensor.TYPE_PRESSURE) {
if (isRestricted(param, "pressure"))
return true;
} else if (type == Sensor.TYPE_PROXIMITY) {
if (isRestricted(param, "proximity"))
return true;
} else if (type == Sensor.TYPE_GAME_ROTATION_VECTOR || type == Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR
|| type == Sensor.TYPE_ROTATION_VECTOR) {
if (isRestricted(param, "rotation"))
return true;
} else if (type == Sensor.TYPE_TEMPERATURE || type == Sensor.TYPE_AMBIENT_TEMPERATURE) {
if (isRestricted(param, "temperature"))
return true;
} else if (type == Sensor.TYPE_STEP_COUNTER || type == Sensor.TYPE_STEP_DETECTOR) {
if (isRestricted(param, "step"))
return true;
} else if (type == Sensor.TYPE_HEART_RATE) {
if (isRestricted(param, "heartrate"))
return true;
} else if (type == 22) {
// 22 = TYPE_TILT_DETECTOR
// Do nothing
} else if (type == 23 || type == 24 || type == 25) {
// 23 = TYPE_WAKE_GESTURE
// 24 = TYPE_GLANCE_GESTURE
// 25 = TYPE_PICK_UP_GESTURE
// 23/24 This sensor is expected to only be used by the system ui
// 25 Expected to be used internally for always on display
} else
Util.log(this, Log.WARN, "Unknown sensor type=" + type);
return false;
}
示例13: onSensorChanged
@Override
public void onSensorChanged(SensorEvent event) {
//如果傳感器類型為磁場傳感器
if (System.currentTimeMillis() - mCurrentTime <= 500 && event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
mFloatsX.add(event.values[0]);
mFloatsY.add(event.values[1]);
mFloatsZ.add(event.values[2]);
} else {
if (mOnece == 0) {
mOnece++;
isEmulator = mFloatsX.size() <= 1 || mFloatsY.size() <= 1 || mFloatsZ.size() <= 1 || isXLinearCorrelation() || isYLinearCorrelation() || isZLinearCorrelation();
mSensorManager.unregisterListener(this);
}
}
}
示例14: onSensorChanged
@Override
public void onSensorChanged(SensorEvent event) {
if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
{
mGravity = event.values;
}
if(event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
{
mGeomagnetic = event.values;
}
if(mGravity != null && mGeomagnetic != null)
{
float R[] = new float[9];
float I[] = new float[9];
boolean success = SensorManager.getRotationMatrix(R,I,mGravity,mGeomagnetic);
if(success)
{
float orientation[] = new float[3];
SensorManager.getOrientation(R, orientation);
Log.e("NEW ORIENTATION---","---------------");
Log.e("orientation azimut", String.valueOf(orientation[0]*60));
Log.e("orientation pitch", String.valueOf(orientation[1]*60));
Log.e("orientation roll", String.valueOf(orientation[2]*60));
txt.setText("orientation azimut " + String.valueOf(orientation[0]*60) + "\n" + "orientation pitch" + String.valueOf(orientation[1]*60) + "\n" + "orientation roll"+ String.valueOf(orientation[2]*60));
}
}
}
示例15: onSensorChanged
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
System.arraycopy(event.values, 0, mAccelerometerReading,
0, mAccelerometerReading.length);
} else if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
System.arraycopy(event.values, 0, mMagnetometerReading,
0, mMagnetometerReading.length);
}
updateOrientationAngles();
directionView.updateAngle(mOrientationAngles[0]);
}