IPC Module - Accelerometer Service
This page contains documentation of the accelerometer part of IMU API.
According to the interface description, the values in the
a_ipc_msg_accelerometer_publish_ind comes as an array of bytes. To be able to read
out the actual values, these bytes need to be re-composed to an
accelerometer_sample
struct:
struct accelerometer_sample {
int16_t x;
int16_t y;
int16_t z;
int16_t pad;
int64_t ts;
} __attribute__ ((__packed__));
Here is an example of how to do this:
static void handle_publish_ind(a_ipc_msg* message)
{
struct accelerometer_sample {
int16_t x;
int16_t y;
int16_t z;
int16_t pad;
int64_t ts;
} __attribute__ ((__packed__));
struct accelerometer_sample* samples = (struct accelerometer_sample*)
message->accelerometer_publish_ind.sample_buffer.value;
int number_of_samples =
message->accelerometer_publish_ind.sample_buffer.length /
sizeof(struct accelerometer_sample);
for (int i = 0; i < number_of_samples; i++)
{
printf("Received values (sample %d of %d):\n", i + 1, number_of_samples);
printf("x: %i\n", samples[i].x);
printf("y: %i\n", samples[i].y);
printf("z: %i\n", samples[i].z);
printf("time stamp: %lu\n", samples[i].ts);
}
exit_main_loop_with_return_code(0);
}
Messages
Enums
- enum accelerometer_result
Result codes
Constant
Value
Description
OK
0
OK
ERROR
1
Error