Mathias Agopian | 98c5309 | 2010-07-19 15:32:24 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 22 | typedef 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; |
Mathias Agopian | 6c84d7a | 2010-07-21 18:00:36 -0700 | [diff] [blame^] | 32 | float pressure; |
Mathias Agopian | 98c5309 | 2010-07-19 15:32:24 -0700 | [diff] [blame] | 33 | }; |
| 34 | int64_t time; |
| 35 | uint32_t reserved; |
| 36 | } sensors_data_t; |
| 37 | |
| 38 | struct sensors_control_device_t { |
| 39 | struct hw_device_t common; |
| 40 | native_handle_t* (*open_data_source)(struct sensors_control_device_t *dev); |
| 41 | int (*close_data_source)(struct sensors_control_device_t *dev); |
| 42 | int (*activate)(struct sensors_control_device_t *dev, |
| 43 | int handle, int enabled); |
| 44 | int (*set_delay)(struct sensors_control_device_t *dev, int32_t ms); |
| 45 | int (*wake)(struct sensors_control_device_t *dev); |
| 46 | }; |
| 47 | |
| 48 | struct sensors_data_device_t { |
| 49 | struct hw_device_t common; |
| 50 | int (*data_open)(struct sensors_data_device_t *dev, native_handle_t* nh); |
| 51 | int (*data_close)(struct sensors_data_device_t *dev); |
| 52 | int (*poll)(struct sensors_data_device_t *dev, |
| 53 | sensors_data_t* data); |
| 54 | }; |
| 55 | |
| 56 | static inline int sensors_control_open(const struct hw_module_t* module, |
| 57 | struct sensors_control_device_t** device) { |
| 58 | return module->methods->open(module, |
| 59 | SENSORS_HARDWARE_CONTROL, (struct hw_device_t**)device); |
| 60 | } |
| 61 | |
| 62 | static inline int sensors_control_close(struct sensors_control_device_t* device) { |
| 63 | return device->common.close(&device->common); |
| 64 | } |
| 65 | |
| 66 | static inline int sensors_data_open(const struct hw_module_t* module, |
| 67 | struct sensors_data_device_t** device) { |
| 68 | return module->methods->open(module, |
| 69 | SENSORS_HARDWARE_DATA, (struct hw_device_t**)device); |
| 70 | } |
| 71 | |
| 72 | static inline int sensors_data_close(struct sensors_data_device_t* device) { |
| 73 | return device->common.close(&device->common); |
| 74 | } |
| 75 | |
| 76 | __END_DECLS |