Vincent Becker | 022224f | 2012-08-10 14:40:49 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 | #ifndef _HARDWARE_VIBRATOR_H |
| 18 | #define _HARDWARE_VIBRATOR_H |
| 19 | |
| 20 | #include <hardware/hardware.h> |
| 21 | |
| 22 | __BEGIN_DECLS |
| 23 | |
| 24 | #define VIBRATOR_API_VERSION HARDWARE_MODULE_API_VERSION(1,0) |
| 25 | |
| 26 | /** |
| 27 | * The id of this module |
| 28 | */ |
| 29 | #define VIBRATOR_HARDWARE_MODULE_ID "vibrator" |
| 30 | |
| 31 | /** |
| 32 | * The id of the main vibrator device |
| 33 | */ |
| 34 | #define VIBRATOR_DEVICE_ID_MAIN "main_vibrator" |
| 35 | |
| 36 | struct vibrator_device; |
| 37 | typedef struct vibrator_device { |
Stewart Miles | 84d3549 | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 38 | /** |
| 39 | * Common methods of the vibrator device. This *must* be the first member of |
| 40 | * vibrator_device as users of this structure will cast a hw_device_t to |
| 41 | * vibrator_device pointer in contexts where it's known the hw_device_t references a |
| 42 | * vibrator_device. |
| 43 | */ |
| 44 | struct hw_device_t common; |
Vincent Becker | 022224f | 2012-08-10 14:40:49 +0200 | [diff] [blame] | 45 | |
| 46 | /** Turn on vibrator |
| 47 | * |
David Wagner | 8e09d12 | 2014-05-07 15:04:05 +0200 | [diff] [blame] | 48 | * This function must only be called after the previous timeout has expired or |
| 49 | * was canceled (through vibrator_off()). |
Vincent Becker | 022224f | 2012-08-10 14:40:49 +0200 | [diff] [blame] | 50 | * |
| 51 | * @param timeout_ms number of milliseconds to vibrate |
| 52 | * |
| 53 | * @return 0 in case of success, negative errno code else |
| 54 | */ |
| 55 | int (*vibrator_on)(struct vibrator_device* vibradev, unsigned int timeout_ms); |
| 56 | |
| 57 | /** Turn off vibrator |
| 58 | * |
David Wagner | 8e09d12 | 2014-05-07 15:04:05 +0200 | [diff] [blame] | 59 | * Cancel a previously-started vibration, if any. |
Vincent Becker | 022224f | 2012-08-10 14:40:49 +0200 | [diff] [blame] | 60 | * |
| 61 | * @return 0 in case of success, negative errno code else |
| 62 | */ |
| 63 | int (*vibrator_off)(struct vibrator_device* vibradev); |
| 64 | } vibrator_device_t; |
| 65 | |
| 66 | static inline int vibrator_open(const struct hw_module_t* module, vibrator_device_t** device) |
| 67 | { |
Colin Cross | cc8d9f9 | 2016-10-06 16:44:23 -0700 | [diff] [blame] | 68 | return module->methods->open(module, VIBRATOR_DEVICE_ID_MAIN, TO_HW_DEVICE_T_OPEN(device)); |
Vincent Becker | 022224f | 2012-08-10 14:40:49 +0200 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | __END_DECLS |
| 72 | |
| 73 | #endif // _HARDWARE_VIBRATOR_H |