// miyoomini/keymon.c #include #include #include #include #include #include #include #include #include #include #include #include #include #include "defines.h" // for ev.value #define RELEASED 0 #define PRESSED 1 #define REPEAT 2 #define INPUT_COUNT 2 static int inputs[INPUT_COUNT]; static struct input_event ev; static int jack_fd; static pthread_t ports_pt; #define JACK_STATE_PATH "/sys/class/switch/h2w/state" #define BACKLIGHT_PATH "/sys/class/backlight/backlight.2/bl_power" int getInt(char* path) { int i = 0; FILE *file = fopen(path, "r"); if (file!=NULL) { fscanf(file, "%i", &i); fclose(file); } return i; } // TODO: still resetting between launches static void* watchPorts(void *arg) { int has_headphones,had_headphones; has_headphones = had_headphones = getInt(JACK_STATE_PATH); SetJack(has_headphones); while(1) { sleep(1); has_headphones = getInt(JACK_STATE_PATH); if (had_headphones!=has_headphones) { had_headphones = has_headphones; SetJack(has_headphones); } } return 0; } int main (int argc, char *argv[]) { InitSettings(); pthread_create(&ports_pt, NULL, &watchPorts, NULL); char path[32]; for (int i=0; i100) ignore = 1; // ignore input that arrived during sleep for (int i=0; i REPEAT )) continue; switch (ev.code) { case CODE_MENU: menu_pressed = val; break; case CODE_POWER: power_pressed = val; break; case CODE_PLUS: up_pressed = up_just_pressed = val; if (val) up_repeat_at = now + 300; break; case CODE_MINUS: down_pressed = down_just_pressed = val; if (val) down_repeat_at = now + 300; break; default: break; } } } if (up_just_pressed || (up_pressed && now>=up_repeat_at)) { if (menu_pressed) { val = GetBrightness(); if (val=down_repeat_at)) { if (menu_pressed) { val = GetBrightness(); if (val>BRIGHTNESS_MIN) SetBrightness(--val); } else { val = GetVolume(); if (val>VOLUME_MIN) SetVolume(--val); } if (down_just_pressed) down_just_pressed = 0; else down_repeat_at += 100; } then = now; ignore = 0; usleep(16666); // 60fps } }