智能手机中的压力传感器

发布于 2024-11-16 02:32:55 字数 121 浏览 4 评论 0原文

任何人都可以帮助我了解智能手机中的压力传感器。我猜测 TYPE_PRESSURE 用于查询大气压力。目前尚不清楚这些值存储在哪里。它是否存储在 SensorManager.values 字段中? 该传感器的其他可能用途是什么?

Could anyone help me understand the pressure sensors in smart phones.I am guessing the TYPE_PRESSURE is used to query the atmospheric pressure. It is not clear where the values are stored. Is it stored in the SensorManager.values field?
What could be the other possible uses of this sensor?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

上课铃就是安魂曲 2024-11-23 02:32:55

它的主要用途是告诉海拔变化,但我确信有一些智能方法可以使用该传感器来执行多项其他任务。

至于获取变量,我很确定它的工作原理与其他 Android 传感器一样。您注册一个传感器事件侦听器,然后在更改的传感器中从 event.values.clone() 获取值,例如。

switch (event.sensor.getType())
        {
        case Sensor.TYPE_PRESSURE:
            m_fPressureVal = event.values.clone();
            break;
                     }

Its main uses would be to tell elevation changes, however i am sure that there are some intelligent ways to use this sensor to do multiple other tasks.

As for getting the variables out I am pretty sure it works as the other android sensors do. You register a sensor event listener and then in your on sensor changed you get the values out of event.values.clone() eg.

switch (event.sensor.getType())
        {
        case Sensor.TYPE_PRESSURE:
            m_fPressureVal = event.values.clone();
            break;
                     }
静赏你的温柔 2024-11-23 02:32:55

压力传感器给出环境气压,单位为 hPa 或 mbar。它的值存储在 event.values[0] 中。在 Android 开发中心查看有关环境传感器的参考资料。

这里有一个如何使用它的示例:

 public class SensorActivity extends Activity implements SensorEventListener {
 private SensorManager mSensorManager;
 private Sensor mPressure;

 @Override
 public final void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Get an instance of the sensor service, and use that to get an instance of
    // a particular sensor.
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mPressure = mSensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);
  }

  @Override
  public final void onAccuracyChanged(Sensor sensor, int accuracy) {
    // Do something here if sensor accuracy changes.
  }

  @Override
  public final void onSensorChanged(SensorEvent event) {
    float millibars_of_pressure = event.values[0];
    // Do something with this sensor data.
  }

  @Override
  protected void onResume() {
    // Register a listener for the sensor.
    super.onResume();
    mSensorManager.registerListener(this, mPressure, SensorManager.SENSOR_DELAY_NORMAL);
  }

  @Override
  protected void onPause() {
    // Be sure to unregister the sensor when the activity pauses.
    super.onPause();
    mSensorManager.unregisterListener(this);
  }
}

The pressure sensor gives the ambient air pressure in hPa or mbar. Its values are stored in the event.values[0]. Check the reference about environment sensors in de Android Dev Centre.

Here you have an example of how to use it:

 public class SensorActivity extends Activity implements SensorEventListener {
 private SensorManager mSensorManager;
 private Sensor mPressure;

 @Override
 public final void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Get an instance of the sensor service, and use that to get an instance of
    // a particular sensor.
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mPressure = mSensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);
  }

  @Override
  public final void onAccuracyChanged(Sensor sensor, int accuracy) {
    // Do something here if sensor accuracy changes.
  }

  @Override
  public final void onSensorChanged(SensorEvent event) {
    float millibars_of_pressure = event.values[0];
    // Do something with this sensor data.
  }

  @Override
  protected void onResume() {
    // Register a listener for the sensor.
    super.onResume();
    mSensorManager.registerListener(this, mPressure, SensorManager.SENSOR_DELAY_NORMAL);
  }

  @Override
  protected void onPause() {
    // Be sure to unregister the sensor when the activity pauses.
    super.onPause();
    mSensorManager.unregisterListener(this);
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文