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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
/*!
* @section LICENSE
*
* (C) Copyright 2011~2015 Bosch Sensortec GmbH All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
* @file BstSensorAccel.h
* @date "Mon Jan 19 13:43:34 2015 +0800"
* @commit "e253b7d"
*
* @brief
*
* @detail
*
*/
#ifndef __BST_SENSOR_ACCEL_H
#define __BST_SENSOR_ACCEL_H
#include <stdint.h>
#include <errno.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include "sensors.h"
#include "SensorBase.h"
#include "InputEventReader.h"
#include "BstSensorPriv.h"
struct input_event;
struct sensor_accel_bw {
int odr;
int reg_val;
};
class BstSensorAccel: public SensorBase {
public:
BstSensorAccel(const char* name, SensorBase *delegate = NULL);
virtual ~BstSensorAccel();
virtual int readEvents(sensors_event_t* data, int count);
virtual int setDelay(int32_t handle, int64_t ns);
virtual int enable(int32_t handle, int enabled);
//virtual void getSensorSpec(struct bst_sensor_spec *spec) = 0;
#if __HAL_VER__ >= __SENSORS_DEVICE_API_VERSION_1_1__
virtual int batch(int handle,int flags,int64_t period_ns,int64_t timeout);
virtual int flush(int handle);
#endif
enum {
HW_A_BW_INVALID = -1,
/* 0 */
HW_A_BW_8 = 0,
/* 1 */
HW_A_BW_16,
/* 2 */
HW_A_BW_31,
/* 3 */
HW_A_BW_63,
/* 4 */
HW_A_BW_125,
/* 5 */
HW_A_BW_250,
/* 6 */
HW_A_BW_500,
/* 7 */
HW_A_BW_1000,
/* 8 */
HW_A_BW_2000,
/* 9 */
HW_A_BW_MAX
};
enum {
HW_A_RANGE_INVALID = -1,
/* 0 */
HW_A_RANGE_2G,
/* 1 */
HW_A_RANGE_4G,
/* 2 */
HW_A_RANGE_8G,
/* 3 */
HW_A_RANGE_16G,
/* 4 */
HW_A_RANGE_32G,
/* 5 */
HW_A_RANGE_MAX
};
enum {
BMA_CHIPID_BMA222E = 0XF8,
BMA_CHIPID_BMA250E = 0XF9,
BMA_CHIPID_BMA255 = 0XFA,
BMA_CHIPID_BMA280 = 0XFB,
BMA_CHIPID_BMA355 = 0XEA,
};
protected:
int mEnabled;
InputEventCircularReader mInputReader;
sensors_event_t mPendingEvent;
char mInputSysfsPath[PATH_MAX];
int mInputSysfsPathLen;
protected:
SensorBase *mDelegate;
int mPlace;
int mBW;
int mRange;
int mRef;
int mScale;
pthread_mutex_t mLock;
/* set the bandwidth */
int setBW(int bw);
/* set the range */
int setRange(int range);
int processEvent(const input_event *event);
/* TODO: those should be moved out to some generic base class */
static void remapSensorData(sensors_event_t *event,
const struct bst_axis_remap *remap);
static void remapSensorData(sensors_event_t *event, int place);
static int getBWFromDelay(uint64_t delay_us);
int getInputSysfsNodeInt(const char *name, int *val);
int setInputSysfsNodeInt(const char *name, int val);
void lock();
void unlock();
static const int64_t MIN_DELAY;
static const int32_t BASE_DELAY_WAKEUP;
static const struct sensor_accel_bw sTabHWBW[HW_A_BW_MAX];
static const struct bst_axis_remap
sTabAxisRemapDft[BST_DFT_AXIS_REMAP_TAB_SZ];
static const float SCALE_GRAVITY = GRAVITY_EARTH / 4096;
};
#endif
|