Listing 9. Sample Data Write Function /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include #include int main (int argc, char **argv) { int fd = -1; /* the file descriptor for the device */ int retval = 0; /* bytes written in write() */ struct input_event ev; /* the event */ /* read() requires a file descriptor, so we check for one, and then open it */ if (argc != 2) { fprintf(stderr, "usage: %s event-device - probably /dev/input/event0\n", argv[0]); exit(1); } if ((fd = open(argv[1], O_WRONLY)) < 0) { perror("evdev open"); exit(1); } /* we turn off all the LEDs to start */ ev.type = EV_LED; ev.code = LED_CAPSL; ev.value = 0; retval = write(fd, &ev, sizeof(struct input_event)); ev.code = LED_NUML; retval = write(fd, &ev, sizeof(struct input_event)); ev.code = LED_SCROLLL; retval = write(fd, &ev, sizeof(struct input_event)); while (1) { ev.code = LED_CAPSL; ev.value = 1; retval = write(fd, &ev, sizeof(struct input_event)); usleep(200000); ev.value = 0; retval = write(fd, &ev, sizeof(struct input_event)); ev.code = LED_NUML; ev.value = 1; write(fd, &ev, sizeof(struct input_event)); usleep(200000); ev.value = 0; retval = write(fd, &ev, sizeof(struct input_event)); } close(fd); exit(0); }