コード例 #1
0
static int powermate_input_event(struct input_dev *dev, unsigned int type, unsigned int code, int _value)
{
	unsigned int command = (unsigned int)_value;
	struct powermate_device *pm = input_get_drvdata(dev);

	if (type == EV_MSC && code == MSC_PULSELED){
		
		int static_brightness = command & 0xFF;   
		int pulse_speed = (command >> 8) & 0x1FF; 
		int pulse_table = (command >> 17) & 0x3;  
		int pulse_asleep = (command >> 19) & 0x1; 
		int pulse_awake  = (command >> 20) & 0x1; 

		powermate_pulse_led(pm, static_brightness, pulse_speed, pulse_table, pulse_asleep, pulse_awake);
	}
コード例 #2
0
/* Callback from the Input layer when an event arrives from userspace to configure the LED */
static int powermate_input_event(struct input_dev *dev, unsigned int type, unsigned int code, int _value)
{
	unsigned int command = (unsigned int)_value;
	struct powermate_device *pm = dev->private;

	if (type == EV_MSC && code == MSC_PULSELED){
		/*  
		    bits  0- 7: 8 bits: LED brightness
		    bits  8-16: 9 bits: pulsing speed modifier (0 ... 510); 0-254 = slower, 255 = standard, 256-510 = faster.
		    bits 17-18: 2 bits: pulse table (0, 1, 2 valid)
		    bit     19: 1 bit : pulse whilst asleep?
		    bit     20: 1 bit : pulse constantly?
		*/  
		int static_brightness = command & 0xFF;   // bits 0-7
		int pulse_speed = (command >> 8) & 0x1FF; // bits 8-16
		int pulse_table = (command >> 17) & 0x3;  // bits 17-18
		int pulse_asleep = (command >> 19) & 0x1; // bit 19
		int pulse_awake  = (command >> 20) & 0x1; // bit 20
  
		powermate_pulse_led(pm, static_brightness, pulse_speed, pulse_table, pulse_asleep, pulse_awake);
	}
コード例 #3
0
ファイル: evdev.c プロジェクト: pgrandin/evdev-jukebox
void *
 process_evdev_events(void )
{
     int evdev_fd;
     struct input_event ev[64];
     int clic_duration;
     int i;

  int static_brightness = 0x80;
  int pulse_speed = 255;
  int pulse_table = 0;
  int pulse_asleep = 1;
  int pulse_awake = 0;

    evdev_fd = find_powermate(O_WRONLY);

  if(evdev_fd < 0){
    fprintf(stderr, "Unable to locate powermate\n");
    return 1;
  }
  pulse_awake=1;
  powermate_pulse_led(static_brightness, pulse_speed, pulse_table, pulse_asleep, pulse_awake);

        if ((evdev_fd = open("/dev/input/by-id/usb-Griffin_Technology__Inc._Griffin_PowerMate-event-if00", O_RDONLY)) < 0) {
                perror("jukebox");
                return 1;
        }
     printf("Starting thread loop\n");
     for (;;) {
         int rd = read(evdev_fd, ev, sizeof(struct input_event) * 64);
         if (rd < (int) sizeof(struct input_event)) {
                 perror("\njukebox: error reading");
                 pthread_exit(NULL);
         }
        for (i = 0; i < rd / sizeof(struct input_event); i++){
                     if ( ev[i].type == 1 ) {
                             if ( ev[i].value == 1 ) {
                                     clic_start_time=ev[i].time.tv_sec * 1000000 + ev[i].time.tv_usec;
                             } else {
                                     clic_duration=( ev[i].time.tv_sec * 1000000 + ev[i].time.tv_usec - clic_start_time ) /1000;
                                     printf("That's a release, duration %ld ms\n", clic_duration );
                                     if ( clic_duration > 3000 ) {
                                             sync();
                                             // reboot(RB_POWER_OFF);
                                     } else if ( clic_duration > 500 ) {
                                             printf ("That was a long clic!\n");
                                     } else {
                                             printf ("That was a short clic!\n");
                                             media_toggle_playback();
                                     }
                             }
                     } else if ( ev[i].type == 2 ) {
                                SetAlsaMasterVolume(ev[i].value);
                                last_scroll_event=ev[i].time.tv_sec * 1000000 + ev[i].time.tv_usec;
                     }
                     if(0) {
                     printf("EventC: time %ld.%06ld, type %d (%s), code %d, value %d\n",
                             ev[i].time.tv_sec, ev[i].time.tv_usec, ev[i].type,
                             events[ev[i].type] ? events[ev[i].type] : "?",
                             ev[i].code,
                             ev[i].value);
                     }
        }
     }
     printf("Thread loop finished\n");
     close(evdev_fd);
     pthread_exit(NULL);
}