The sensor application subscription interface targets the events of a specific sensor, such as pedometer, to provide rich information on user's daily activities.
More...
The sensor application subscription interface targets the events of a specific sensor, such as pedometer, to provide rich information on user's daily activities.
An example implementation of the subscription to accelerometer data can be found in [sdk_root]/project/mt2523_sdk/apps/sensor_subsys_accelerometer. The steps are described below.
- 1. Call sensor_manager_init() to initialize the sensor manager.
- 2. Prepare the sensor data subscription structure. Refer to sensor_subscriber_t.
- 3. Call sensor_subscribe_sensor() to subscribe the specified sensor in application.
- Sample code:
int32_t acc_sensor_send_digest_callback(
sensor_data_t *
const output);
};
int32_t acc_sensor_send_digest_callback(
sensor_data_t *
const output)
{
printf("acc sensor type = %lu , value = ( %ld , %ld , %ld ) (%ld) , timestamp = %lu \r\n",
);
break;
default:
printf("type = %lu, timestamp = %lu \r\n",
break;
}
return 0;
}
int main(void)
{
int32_t subscription;
if (subscription < 0) {
printf("acc subscription fail\r\b");
}
| #define SENSOR_MAX_SUBSCRIBER_NAME_LEN ( 8 ) |
The maximum sensor subscriber name length.
| int32_t sensor_get_latest_sensor_data |
( |
uint32_t |
type, |
|
|
sensor_data_t *const |
output |
|
) |
| |
This function gets the latest data of the specified sensor type.
- Parameters
-
| [in] | type | is the sensor type for the sensor event data acquisition. |
| [out] | output | is the sensor event data. |
- Returns
- >=0, if the operation completed successfully.
| int32_t sensor_manager_init |
( |
void |
| ) |
|
This function initializes the data structures in sensor manager.
- Returns
- >=0, if the operation completed successfully.
| int sensor_manager_set_cust_from_app |
( |
uint32_t |
sensor_type, |
|
|
void * |
in_data_buf, |
|
|
int32_t |
in_size |
|
) |
| |
This function sends the sensor event for a specified sensor type from application layer.
- Parameters
-
| [in] | sensor_type | is the sensor type for the sensor event. |
| [in] | in_data_buf | is a pointer to the input data. |
| [in] | in_size | is the input buffer size. |
- Returns
- >=0, if the operation completed successfully.
This function subscribes the sensor event for a specified sensor type.
- Parameters
-
| [in,out] | subscriber | is the data structure for the subscription. |
- Returns
- >=0, if the operation completed successfully.
| int32_t sensor_unsubscribe_sensor |
( |
int32_t |
handle | ) |
|
This function unsubscribes the sensor event for a specified sensor type.
- Parameters
-
| [in] | handle | is the subscriber's handle to be unsubscribed. |
- Returns
- >=0, if the operation completed successfully.