Steward
分享是一種喜悅、更是一種幸福
掌機 - GKDmini Plus - C/C++ - Set Volume
main.c
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <fcntl.h>
#include <linux/input.h>
uint64_t get_tickcount_ms(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
return (uint64_t)(tv.tv_sec) * 1000 + (tv.tv_usec / 1000);
}
int main(int argc, char **argv)
{
uint64_t s0 = 0;
int fd = -1;
struct input_event ev = { 0 };
fd = open("/dev/input/event1", O_RDONLY);
if (fd > 0) {
s0 = get_tickcount_ms();
while (read(fd, &ev, sizeof(struct input_event))) {
if ((ev.type == EV_KEY) && (ev.value == 1)) {
if ((get_tickcount_ms() - s0) > 100) {
s0 = get_tickcount_ms();
if (ev.code == 115) {
system("amixer sset Master 3%+");
}
if (ev.code == 114) {
system("amixer sset Master 3%-");
}
}
}
}
close(fd);
}
return 0;
}