linux gpio_keysの上位検出コード

1529 ワード

#include 
#include 
#include 
#include 
#include 


#define EVDEV "/dev/input/event0"


int main(int argc, char **argv) {
    unsigned char key_states[KEY_MAX/8 + 1];
    struct input_event evt;
    int fd;


    memset(key_states, 0, sizeof(key_states));
    fd = open(EVDEV, O_RDWR);
    ioctl(fd, EVIOCGKEY(sizeof(key_states)), key_states);


    // Create some inconsistency
    printf("Type (lots) now to make evdev drop events from the queue
"); sleep(5); printf("
"); while(read(fd, &evt, sizeof(struct input_event)) > 0) { if(evt.type == EV_SYN && evt.code == SYN_DROPPED) { printf("Received SYN_DROPPED. Restart.
"); fsync(fd); ioctl(fd, EVIOCGKEY(sizeof(key_states)), key_states); } else if(evt.type == EV_KEY) { // Ignore repetitions if(evt.value > 1) continue; key_states[evt.code / 8] ^= 1 << (evt.code % 8); if((key_states[evt.code / 8] >> (evt.code % 8)) & 1 != evt.value) { printf("Inconsistency detected: Keycode %d is reported as %d, but %d is stored
", evt.code, evt.value, (key_states[evt.code / 8] >> (evt.code % 8)) & 1); } } } }

ps:hexdump/dev/input/event 0データの変化を検出します.
cat/proc/interrupt検出割り込み発生回数