Skip to content
Snippets Groups Projects
Select Git revision
1 result Searching

utils.js

Blame
  • blink1raw.c 4.69 KiB
    /* 
     * blinkraw.c
     *
     * fgmr 2012-09-22
     *
     * playing with the hidraw interface to blink(1)
     * 
     * Thank you Alan Ott for
     * http://lxr.free-electrons.com/source/samples/hidraw/hid-example.c
     */
    
    #include <linux/types.h>
    #include <linux/input.h>
    #include <linux/hidraw.h>
    
    #ifndef HIDIOCSFEATURE
    #define HIDIOCSFEATURE(len) _IOC(_IOC_WRITE|_IOC_READ, 'H', 0x06, len)
    #define HIDIOCGFEATURE(len) _IOC(_IOC_WRITE|_IOC_READ, 'H', 0x07, len)
    #endif /* HIDIOCSFEATURE */
    
    #include <sys/ioctl.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <unistd.h>
    
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <errno.h>
    #include <stdarg.h>
    #include <ctype.h>
    
    static void
    usage(const char* hunh) {
      if (NULL != hunh) {
        fprintf(stderr, "Can't understand %s\n", hunh);
      }
    
      fprintf(stderr,
              "Usage: blinkraw {arg, ...}\n"
              "  /dev/whatever  -- open device\n"
              "  ./whatever     -- open device\n"
              "  =R,G,B,t       -- fade to color\n"
              "  :R,G,B         -- set color (now)\n"
              "  @step:R,G,B,t  -- set step\n"
              "  +step          -- start playing at step\n"
              "  -[step]        -- stop playing at step (default zero)\n"
              "  %%              -- clear all steps\n"
              "  _              -- turn off\n"
              "  _t             -- fade off\n"
              "\n"
              "       step is on [0,15]\n",
              "       R, G, B are on [0, 255]\n"
              "       t is time in centiseconds\n"
              "\n"
              "    Arguments are applied in order.  A new device, which is\n"
              "    a valid blink(1) device, will become the new target.\n"
              "\n"
              "    Example:\n"
              "    # blinkraw /dev/hidraw* % =255,0,0,100\n"
              );
      exit(1);
    }
    
    static void
    color(int fd, char action, int R, int G, int B, int T, int step) {
      char buf[16];
      int rc;