#include #include #include #include #include #include #define HAVEFF 0 int main(int argc, char *argv[]) { struct input_event play; struct input_event stop; struct ff_effect *effect; int fd; int gain = 10; /* 0-100 */ char name[256] = "Unknown"; unsigned char display_time[] = { 0x10,0xbe,0x5e,0x40,0x7c,0xc6,0xbf,0xe5,0x70,0x60,0x00,0x10,0x10,0x10,0x10,0x10 }, display_offhook[] = { 0x11,0xbe,0x5e,0x40,0x7c,0xc6,0xfb,0xeb,0x70,0x60,0x00,0x10,0x10,0x10,0x10,0x10 } ; int retval; int i; effect = malloc(sizeof(struct ff_effect) + 16); memset(effect, 0, sizeof(struct ff_effect)); if(argc < 2) { printf("usage: fftest /dev/input/eventX\n"); return 0; } fd = open(argv[1], O_RDWR | O_SYNC); if(ioctl(fd, EVIOCGNAME(sizeof(name)), name) < 0) { perror("evdev ioctl"); } printf("%s: %s\n", argv[1], name); #if HAVEFF memset(effect, 0, sizeof(struct ff_effect)); /* fill the effect structure */ effect->type = FF_PERIODIC; effect->id = -1; /* generate new effect */ effect->u.periodic.waveform = FF_CUSTOM; /* dirty hack */ memcpy(&effect->u.periodic.period, display_offhook, sizeof(display_offhook)); /* upload the effect */ retval = ioctl(fd, EVIOCSFF, effect); if (retval < 0) { printf("cannot upload the effect\n"); } else { printf("effect %d uploaded.\n", effect->id); /* Remove the effect */ retval = ioctl(fd, EVIOCRMFF, effect->id); if (retval < 0) printf("cannot remove the effect %d\n", effect->id); } #endif #if 1 /* turn RINGER on */ play.type = EV_SND; play.code = SND_BELL; play.value = 1; write(fd, (const void*) &play, sizeof(play)); #endif for(i = 0; i < 2; i++) { /* turn LED on */ play.type = EV_LED; play.code = LED_NUML; play.value = 1; write(fd, (const void*) &play, sizeof(play)); fsync(fd); usleep(100000); /* turn LED off */ play.type = EV_LED; play.code = LED_NUML; play.value = 0; write(fd, (const void*) &play, sizeof(play)); fsync(fd); usleep(100000); } #if 1 /* turn RINGER off */ play.type = EV_SND; play.code = SND_BELL; play.value = 0; write(fd, (const void*) &play, sizeof(play)); #endif #if HAVEFF /* fill the effect structure */ effect->type = FF_PERIODIC; effect->id = -1; /* generate new effect */ effect->u.periodic.waveform = FF_CUSTOM; /* dirty hack */ memcpy(&effect->u.periodic.period, display_time, sizeof(display_time)); /* upload the effect */ retval = ioctl(fd, EVIOCSFF, effect); if (retval < 0) { printf("cannot upload the effect\n"); } else { printf("effect %d uploaded.\n", effect->id); /* Remove the effect */ retval = ioctl(fd, EVIOCRMFF, effect->id); if (retval < 0) printf("cannot remove the effect %d\n", effect->id); } #endif close(fd); return 0; }