2 * Copyright (C) 2013 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <cutils/log.h>
23 #include <hardware/hardware.h>
24 #include <hardware/vibrator.h>
25 #include <qemu_pipe.h>
27 static int sendit(unsigned int timeout_ms)
29 static int pipe_fd = -2;
31 pipe_fd = qemu_pipe_open("pipe:qemud:hw-control");
37 snprintf(buff, sizeof(buff), "vibrator:%u", timeout_ms);
38 if (qemu_pipe_frame_send(pipe_fd, buff, strlen(buff)) < 0) {
44 static int qemu_vibra_on(vibrator_device_t* vibradev __unused,
45 unsigned int timeout_ms)
47 return sendit(timeout_ms);
50 static int qemu_vibra_off(vibrator_device_t* vibradev __unused)
55 static int qemu_vibra_close(hw_device_t *device)
61 static int qemu_vibra_open(const hw_module_t* module, const char* id __unused,
62 hw_device_t** device) {
63 vibrator_device_t *vibradev = calloc(1, sizeof(vibrator_device_t));
66 ALOGE("No memory available to create Goldfish vibrator device!");
70 vibradev->common.tag = HARDWARE_DEVICE_TAG;
71 vibradev->common.module = (hw_module_t *) module;
72 vibradev->common.version = HARDWARE_DEVICE_API_VERSION(1,0);
73 vibradev->common.close = qemu_vibra_close;
75 vibradev->vibrator_on = qemu_vibra_on;
76 vibradev->vibrator_off = qemu_vibra_off;
78 *device = (hw_device_t *) vibradev;
83 /*===========================*/
84 /* Emulator vibrator module */
85 /*===========================*/
87 static struct hw_module_methods_t qemu_vibrator_module_methods = {
88 .open = qemu_vibra_open,
91 struct hw_module_t HAL_MODULE_INFO_SYM = {
92 .tag = HARDWARE_MODULE_TAG,
93 .module_api_version = VIBRATOR_API_VERSION,
94 .hal_api_version = HARDWARE_HAL_API_VERSION,
95 .id = VIBRATOR_HARDWARE_MODULE_ID,
96 .name = "Goldfish vibrator module",
97 .author = "The Android Open Source Project",
98 .methods = &qemu_vibrator_module_methods,