blob: 797478824083d334c8483d3ee833899487cddeb0 [file] [log] [blame]
Mathias Agopian98c53092010-07-19 15:32:24 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define SENSORS_HARDWARE_CONTROL "control"
18#define SENSORS_HARDWARE_DATA "data"
19
20__BEGIN_DECLS
21
22typedef struct {
23 int sensor;
24 union {
25 sensors_vec_t vector;
26 sensors_vec_t orientation;
27 sensors_vec_t acceleration;
28 sensors_vec_t magnetic;
29 float temperature;
30 float distance;
31 float light;
32 };
33 int64_t time;
34 uint32_t reserved;
35} sensors_data_t;
36
37struct sensors_control_device_t {
38 struct hw_device_t common;
39 native_handle_t* (*open_data_source)(struct sensors_control_device_t *dev);
40 int (*close_data_source)(struct sensors_control_device_t *dev);
41 int (*activate)(struct sensors_control_device_t *dev,
42 int handle, int enabled);
43 int (*set_delay)(struct sensors_control_device_t *dev, int32_t ms);
44 int (*wake)(struct sensors_control_device_t *dev);
45};
46
47struct sensors_data_device_t {
48 struct hw_device_t common;
49 int (*data_open)(struct sensors_data_device_t *dev, native_handle_t* nh);
50 int (*data_close)(struct sensors_data_device_t *dev);
51 int (*poll)(struct sensors_data_device_t *dev,
52 sensors_data_t* data);
53};
54
55static inline int sensors_control_open(const struct hw_module_t* module,
56 struct sensors_control_device_t** device) {
57 return module->methods->open(module,
58 SENSORS_HARDWARE_CONTROL, (struct hw_device_t**)device);
59}
60
61static inline int sensors_control_close(struct sensors_control_device_t* device) {
62 return device->common.close(&device->common);
63}
64
65static inline int sensors_data_open(const struct hw_module_t* module,
66 struct sensors_data_device_t** device) {
67 return module->methods->open(module,
68 SENSORS_HARDWARE_DATA, (struct hw_device_t**)device);
69}
70
71static inline int sensors_data_close(struct sensors_data_device_t* device) {
72 return device->common.close(&device->common);
73}
74
75__END_DECLS