summaryrefslogtreecommitdiff
path: root/libsensors_iio/src/SWLinearAccel.cpp
blob: 5e8163e0e4998fdf32490f551005ad4696696fd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * STMicroelectronics SW Linear Acceleration Sensor Class
 *
 * Copyright 2013-2015 STMicroelectronics Inc.
 * Author: Denis Ciocca - <denis.ciocca@st.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 */

#include <fcntl.h>
#include <assert.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>


#include "SWLinearAccel.h"

SWLinearAccel::SWLinearAccel(const char *name, int handle, int pipe_data_fd) :
		SWSensorBaseWithPollrate(name, handle, SENSOR_TYPE_LINEAR_ACCELERATION,
			pipe_data_fd, true, false, true, false)
{
	sensor_t_data.stringType = SENSOR_STRING_TYPE_LINEAR_ACCELERATION;
	sensor_t_data.flags = SENSOR_FLAG_CONTINUOUS_MODE;

	type_dependencies[SENSOR_BASE_DEPENDENCY_0] = SENSOR_TYPE_ST_ACCEL_GYRO_FUSION6X;
	type_sensor_need_trigger = SENSOR_TYPE_ST_ACCEL_GYRO_FUSION6X;

	num_data_axis = SENSOR_BASE_4AXIS;
}

SWLinearAccel::~SWLinearAccel()
{

}

void SWLinearAccel::TriggerEventReceived()
{
	int data_remaining;
	SensorBaseData linear_accel;

	do {
		data_remaining = GetLatestValidDataFromDependency(SENSOR_BASE_DEPENDENCY_0, &linear_accel);
		if (data_remaining < 0)
			return;

		memcpy(sensor_event.data, linear_accel.processed, num_data_axis * sizeof(float));
		sensor_event.timestamp = linear_accel.timestamp;

		SWSensorBaseWithPollrate::WriteDataToPipe();
		SWSensorBaseWithPollrate::ProcessData(&linear_accel);
	} while (data_remaining > 0);
}