oh_sensor_type.h

Overview

The oh_sensor_type.h file declares the common sensor attributes.

Library: libohsensor.so

System capability: SystemCapability.Sensors.Sensor

Since: 11

Related module: Sensor

Summary

Types

Name Description
Sensor_Type Defines an enum that enumerates the sensor types.
Sensor_Result Defines an enum that enumerates the sensor result codes.
Sensor_Accuracy Defines an enum that enumerates the accuracy levels of data reported by a sensor.
Sensor_Info Defines the sensor information.
Sensor_Event Defines the sensor data information.
Sensor_SubscriptionId Defines the sensor subscription ID, which uniquely identifies a sensor.
Sensor_SubscriptionAttribute Defines the sensor subscription attribute.
void (Sensor_EventCallback) (Sensor_Event *event) Defines the callback function used to report sensor data.
Sensor_Subscriber Defines the sensor subscriber information.

Enums

Name Description
Sensor_Type {
SENSOR_TYPE_ACCELEROMETER = 1,
SENSOR_TYPE_GYROSCOPE = 2,
SENSOR_TYPE_AMBIENT_LIGHT = 5,
SENSOR_TYPE_MAGNETIC_FIELD = 6,
SENSOR_TYPE_BAROMETER = 8,
SENSOR_TYPE_HALL = 10,
SENSOR_TYPE_PROXIMITY = 12,
SENSOR_TYPE_ORIENTATION = 256,
SENSOR_TYPE_GRAVITY = 257,
SENSOR_TYPE_ROTATION_VECTOR = 259,
SENSOR_TYPE_PEDOMETER_DETECTION = 265,
SENSOR_TYPE_PEDOMETER = 266,
SENSOR_TYPE_HEART_RATE = 278
}
Enumerates the sensor types.
Sensor_Result {
SENSOR_SUCCESS = 0,
SENSOR_PERMISSION_DENIED = 201,
SENSOR_PARAMETER_ERROR = 401,
SENSOR_SERVICE_EXCEPTION = 14500101
}
Enumerates the sensor result codes.
Sensor_Accuracy {
SENSOR_ACCURACY_UNRELIABLE = 0,
SENSOR_ACCURACY_LOW = 1,
SENSOR_ACCURACY_MEDIUM = 2,
SENSOR_ACCURACY_HIGH = 3
}
Enumerates the accuracy levels of data reported by a sensor.

Functions

Name Description
OH_Sensor_CreateInfos(uint32_t count) Creates an array of Sensor_Info instances with the given number.
OH_Sensor_DestroyInfos(Sensor_Info **sensors, uint32_t count) Destroys an array of Sensor_Info instances and reclaims memory.
OH_SensorInfo_GetName(Sensor_Info *sensor, char *sensorName, uint32_t *length) Obtains the sensor name.
OH_SensorInfo_GetVendorName(Sensor_Info *sensor, char *vendorName, uint32_t *length) Obtains the sensor's vendor name.
OH_SensorInfo_GetType(Sensor_Info *sensor, Obtains the sensor type.
OH_SensorInfo_GetResolution (Sensor_Info *sensor, float *resolution) Obtains the sensor resolution.
OH_SensorInfo_GetMinSamplingInterval (Sensor_Info *sensor, int64_t *minSamplingInterval) Obtains the minimum data reporting interval of a sensor.
OH_SensorInfo_GetMaxSamplingInterval (Sensor_Info *sensor, int64_t *maxSamplingInterval) Obtains the maximum data reporting interval of a sensor.
OH_SensorEvent_GetType (Sensor_Event *sensorEvent, Sensor_Type *sensorType) Obtains the sensor type.
OH_SensorEvent_GetTimestamp (Sensor_Event *sensorEvent, int64_t *timestamp) Obtains the timestamp of sensor data.
OH_SensorEvent_GetAccuracy (Sensor_Event *sensorEvent, Sensor_Accuracy *accuracy) Obtains the accuracy of sensor data.
OH_SensorEvent_GetData (Sensor_Event *sensorEvent, float **data, uint32_t *length) Obtains sensor data. The data length and content depend on the sensor type. The format of the sensor data reported is as follows:
- SENSOR_TYPE_ACCELEROMETER: data[0], data[1], and data[2], indicating the acceleration around the x, y, and z axes of a device, respectively, in m/s².
- SENSOR_TYPE_GYROSCOPE: data[0], data[1], and data[2], indicating the angular velocity of rotation around the x, y, and z axes of a device, respectively, in rad/s.
- SENSOR_TYPE_AMBIENT_LIGHT: data[0], indicating the ambient light intensity, in lux.
- SENSOR_TYPE_MAGNETIC_FIELD: data[0], data[1], and data[2], indicating the magnetic field strength around the x, y, and z axes of a device, respectively, in μT.
- SENSOR_TYPE_BAROMETER: data[0], indicating the atmospheric pressure, in hPa.
- SENSOR_TYPE_HALL: data[0], indicating the opening/closing state of the flip cover. The value 0 means that the flip cover is opened, and a value greater than 0 means that the flip cover is closed.
- SENSOR_TYPE_PROXIMITY: data[0], indicates the approaching state. The value 0 means the two objects are close to each other, and a value greater than 0 means that they are far away from each other. - SENSOR_TYPE_ORIENTATION: data[0], data[1], and data[2], indicating the rotation angles of a device around the z, x, and y axes, respectively, in degree.
- SENSOR_TYPE_GRAVITY: data[0], data[1], and data[2], indicating the gravitational acceleration around the x, y, and z axes of a device, respectively, in m/s².
- SENSOR_TYPE_ROTATION_VECTOR: data[0], data[1] and data[2], indicating the rotation angles of a device around the x, y, and z axes, respectively, in degree. data[3] indicates the rotation vector.
- SENSOR_TYPE_PEDOMETER_DETECTION: data[0], indicating the pedometer detection status. The value 1 means that the number of detected steps changes.
- SENSOR_TYPE_PEDOMETER: data[0], indicating the number of steps a user has walked.
- SENSOR_TYPE_HEART_RATE: data[0], indicating the heart rate value.
OH_Sensor_CreateSubscriptionId (void) Creates a Sensor_SubscriptionId instance.
OH_Sensor_DestroySubscriptionId (Sensor_SubscriptionId *id) Destroys a Sensor_SubscriptionId instance and reclaims memory.
OH_SensorSubscriptionId_GetType (Sensor_SubscriptionId *id, Sensor_Type *sensorType) Obtains the sensor type.
OH_SensorSubscriptionId_SetType (Sensor_SubscriptionId *id, const Sensor_Type sensorType) Sets the sensor type.
OH_Sensor_CreateSubscriptionAttribute (void) Creates a Sensor_SubscriptionAttribute instance.
OH_Sensor_DestroySubscriptionAttribute (Sensor_SubscriptionAttribute *attribute) Destroys a Sensor_SubscriptionAttribute instance and reclaims memory.
OH_SensorSubscriptionAttribute_SetSamplingInterval (Sensor_SubscriptionAttribute *attribute, const int64_t samplingInterval) Sets the sensor data reporting interval.
OH_SensorSubscriptionAttribute_GetSamplingInterval (Sensor_SubscriptionAttribute *attribute, int64_t *samplingInterval) Obtains the sensor data reporting interval.
Creates a Sensor_Subscriber instance.
OH_Sensor_DestroySubscriber (Sensor_Subscriber *subscriber) Destroys a Sensor_Subscriber instance and reclaims memory.
OH_SensorSubscriber_SetCallback (Sensor_Subscriber *subscriber, const Sensor_EventCallback callback) Sets a callback function to report sensor data.
OH_SensorSubscriber_GetCallback (Sensor_Subscriber *subscriber, Sensor_EventCallback *callback) Obtains the callback function used to report sensor data.