Advertisement
metalx1000

C code for Griffin Technology PowerMate USB Knob

Oct 20th, 2017
645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.72 KB | None | 0 0
  1. /*
  2.  * Copyright (c) 2017 Kris Occhipint.
  3.  * http://filmsbykris.com
  4.  *
  5.  * This program is free software: you can redistribute it and/or modify  
  6.  * it under the terms of the GNU General Public License as published by  
  7.  * the Free Software Foundation, version 3.
  8.  *
  9.  * This program is distributed in the hope that it will be useful, but
  10.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12.  * General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16.  */
  17.  
  18. #include <stdlib.h>
  19. #include <unistd.h>
  20. #include <fcntl.h>
  21. #include <errno.h>
  22. #include <linux/input.h>
  23. #include <string.h>
  24. #include <stdio.h>
  25.  
  26. static const char *const evval[2] = {
  27.   "RELEASED",
  28.   "PRESSED "
  29. };
  30.  
  31. int main(void){
  32.   //get input device
  33.   const char *dev = "/dev/input/by-id/usb-Griffin_Technology__Inc._Griffin_PowerMate-event-if00";
  34.   struct input_event ev;
  35.   ssize_t n;
  36.   int fd;
  37.  
  38.   //open device for reading
  39.   fd = open(dev, O_RDONLY);
  40.   //exit on error opening device
  41.   if (fd == -1) {
  42.     fprintf(stderr, "Cannot open %s: %s.\n", dev, strerror(errno));
  43.     return -1;
  44.   }
  45.   while (1) {
  46.     n = read(fd, &ev, sizeof ev);
  47.     //printf("%d\n",ev.type);
  48.     //printf("%d\n",(int)ev.value);
  49.     if(ev.type == 2 && (int)ev.value == 1){
  50.       printf("Clock Wise\n");
  51.     }else if(ev.type == 2 && (int)ev.value == -1){
  52.       printf("Counter Clock Wise\n");
  53.     }
  54.     if (ev.type == EV_KEY && ev.value >= 0 && ev.value <= 2){
  55.       printf("%s 0x%04x (%d)\n", evval[ev.value], (int)ev.code, (int)ev.code);
  56.     }
  57.   }
  58.  
  59.   return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement