vibrator.c

来自「Android平台上Midware层源代码合集」· C语言 代码 · 共 37 行

C
37
字号
#include <hardware/vibrator.h>#include <stdio.h>#include <unistd.h>#include <fcntl.h>#include <errno.h>#define THE_DEVICE "/sys/class/timed_output/vibrator/enable"static int sendit(int timeout_ms){    int nwr, ret, fd;    char value[20];    fd = open(THE_DEVICE, O_RDWR);    if(fd < 0)        return errno;    nwr = sprintf(value, "%d\n", timeout_ms);    ret = write(fd, value, nwr);    close(fd);    return (ret == nwr) ? 0 : -1;}int vibrator_on(){    /* constant on, up to maximum allowed time */    return sendit(-1);}int vibrator_off(){    return sendit(0);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?