// Set the brightness of the Griffin Powermate's LED. // By Phil Endecott, 2008. // I hereby place this code in the public domain. // You can get the latest version of this code from // http://svn.chezphil.org/utils/trunk/gpsetled.c // See also // http://sowerbutts.com/powermate/ // which I discovered after writing this. #include #include #include #include #include #include #include #include void usage() { fprintf(stderr,"Usage: gpsetled off|on|\n"); } int main(int argc, char* argv[]) { if (argc!=3) { usage(); exit(1); } const char* dev_fn = argv[1]; const char* brightness_s = argv[2]; int fd = open(dev_fn,O_WRONLY); if (fd==-1) { perror("open()"); exit(1); } int brightness; if (strcmp(brightness_s,"on")==0) { brightness=255; } else if (strcmp(brightness_s,"off")==0) { brightness=0; } else { brightness = strtoul(brightness_s,NULL,0); } struct input_event ev; ev.type = EV_MSC; ev.code = MSC_PULSELED; ev.value = brightness; ssize_t b = write(fd,&ev,sizeof(ev)); if (b != sizeof(ev)) { perror("write()"); exit(1); } exit(0); }