当前位置: 首页>>代码示例>>Java>>正文


Java Sensor.TYPE_MAGNETIC_FIELD属性代码示例

本文整理汇总了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);
    }
}
 
开发者ID:InnoFang,项目名称:Android-Code-Demos,代码行数:16,代码来源:CompassSketch.java

示例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;
    }
}
 
开发者ID:tringuyen1121,项目名称:Khonsu,代码行数:20,代码来源:SensorService.java

示例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]);
    }
}
 
开发者ID:StringMon,项目名称:homescreenarcade,代码行数:22,代码来源:OrientationListener.java

示例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();
        }
    }
}
 
开发者ID:wade-fs,项目名称:Military-North-Compass,代码行数:19,代码来源:Compass.java

示例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);
    }
}
 
开发者ID:peter10110,项目名称:Android-SteamVR-controller,代码行数:19,代码来源:AccelerometerCompassProvider.java

示例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)
                    );
        }
    }
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:33,代码来源:CompassActivity.java

示例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);
            }
        }
    }
 
开发者ID:ros2java-alfred,项目名称:ros2_android,代码行数:17,代码来源:CompassSensorAdapter.java

示例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;
}
 
开发者ID:lucasax,项目名称:Zero,代码行数:24,代码来源:AccelerationParser.java

示例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);
    }
}
 
开发者ID:peter10110,项目名称:Android-SteamVR-controller,代码行数:18,代码来源:GravityCompassProvider.java

示例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;
    }
}
 
开发者ID:feup-infolab,项目名称:labtablet,代码行数:31,代码来源:FieldModeActivity.java

示例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;
    }
}
 
开发者ID:ykarim,项目名称:FTC2016,代码行数:35,代码来源:Sensors.java

示例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;
}
 
开发者ID:ukanth,项目名称:XPrivacy,代码行数:58,代码来源:XSensorManager.java

示例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);
        }
    }
}
 
开发者ID:CodyyAndroid,项目名称:EmulatorDetect,代码行数:15,代码来源:EmulatorDetectorService.java

示例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));
        }
    }
}
 
开发者ID:ANFR-France,项目名称:proto-collecte,代码行数:28,代码来源:CameraActivity.java

示例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]);
}
 
开发者ID:Twelvelines,项目名称:AndroidMuseumBleManager,代码行数:12,代码来源:ScanFragment.java


注:本文中的android.hardware.Sensor.TYPE_MAGNETIC_FIELD属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。