Public Types | Static Public Member Functions | List of all members
cpp3ds::Sensor Class Reference

Give access to the real-time state of the sensors. More...

#include <Sensor.hpp>

Public Types

enum  Type {
  Accelerometer,
  Gyroscope,
  Magnetometer,
  Gravity,
  UserAcceleration,
  Orientation,
  Count
}
 Sensor type. More...
 

Static Public Member Functions

static bool isAvailable (Type sensor)
 Check if a sensor is available on the underlying platform. More...
 
static void setEnabled (Type sensor, bool enabled)
 Enable or disable a sensor. More...
 
static bool isEnabled (Type sensor)
 Check if a sensor is enabled. More...
 
static void update ()
 Update the state of all the sensors. More...
 
static Vector3f getValue (Type sensor)
 Get the current sensor value. More...
 

Detailed Description

Give access to the real-time state of the sensors.

cpp3ds::Sensor provides an interface to the state of the various sensors that a device provides.

It only contains static functions, so it's not meant to be instanciated.

This class allows users to query the sensors values at any time and directly, without having to deal with a window and its events. Compared to the SensorChanged event, cpp3ds::Sensor can retrieve the state of a sensor at any time (you don't need to store and update its current value on your side).

Depending on the OS and hardware of the device (phone, tablet, ...), some sensor types may not be available. You should always check the availability of a sensor before trying to read it, with the cpp3ds::Sensor::isAvailable function.

You may wonder why some sensor types look so similar, for example Accelerometer and Gravity / UserAcceleration. The first one is the raw measurement of the acceleration, and takes in account both the earth gravity and the user movement. The others are more precise: they provide these components separately, which is usually more useful. In fact they are not direct sensors, they are computed internally based on the raw acceleration and other sensors. This is exactly the same for Gyroscope vs Orientation.

Because sensors consume a non-negligible amount of current, they are all disabled by default. You must call cpp3ds::Sensor::setEnabled for each sensor in which you are interested.

Usage example:

{
// gravity sensor is available
}
// enable the gravity sensor
// get the current value of gravity

Definition at line 12 of file Sensor.hpp.

Member Enumeration Documentation

Sensor type.

Enumerator
Accelerometer 

Measures the raw acceleration (m/s²)

Gyroscope 

Measures the raw rotation rates (degrees/s)

Magnetometer 

Measures the ambient magnetic field (micro-teslas)

Gravity 

Measures the direction and intensity of gravity, independent of device acceleration (m/s²)

UserAcceleration 

Measures the direction and intensity of device acceleration, independent of the gravity (m/s²)

Orientation 

Measures the absolute 3D orientation (degrees)

Count 

Keep last – the total number of sensor types.

Definition at line 19 of file Sensor.hpp.

Member Function Documentation

static Vector3f cpp3ds::Sensor::getValue ( Type  sensor)
static

Get the current sensor value.

Parameters
sensorSensor to read
Returns
The current sensor value
static bool cpp3ds::Sensor::isAvailable ( Type  sensor)
static

Check if a sensor is available on the underlying platform.

Parameters
sensorSensor to check
Returns
True if the sensor is available, false otherwise
static bool cpp3ds::Sensor::isEnabled ( Type  sensor)
static

Check if a sensor is enabled.

Parameters
sensorSensor to check
Returns
True if the sensor is enabled, false otherwise
static void cpp3ds::Sensor::setEnabled ( Type  sensor,
bool  enabled 
)
static

Enable or disable a sensor.

All sensors are disabled by default, to avoid consuming too much battery power. Once a sensor is enabled, it starts sending events of the corresponding type.

This function does nothing if the sensor is unavailable.

Parameters
sensorSensor to enable
enabledTrue to enable, false to disable
static void cpp3ds::Sensor::update ( )
static

Update the state of all the sensors.


The documentation for this class was generated from the following file: