Using button in pico mini ubuntu
Posted: 2024-11-17 19:51
hello, is it possible to use the luckfox pico mini BOOT button in ubuntu?
A short text to describe your forum
http://forums.luckfox.com/
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/input.h>
#include <signal.h>
#include <sys/wait.h>
#include <stdbool.h>
#include <string.h>
#define DEVICE_PATH "/dev/input/event0"
#define TRIGGER_KEY KEY_ENTER
int main() {
int fd = open(DEVICE_PATH, O_RDONLY);
if (fd < 0) {
perror("Failed to open device");
return 1;
}
//printf("Listening for key events on %s...\n", DEVICE_PATH);
struct input_event ev;
while (1) {
ssize_t bytes = read(fd, &ev, sizeof(struct input_event));
if (bytes < (ssize_t) sizeof(struct input_event)) {
perror("Failed to read input event");
close(fd);
return 1;
}
// Trigger button
if (ev.type == EV_KEY && ev.code == TRIGGER_KEY && ev.value == 1) {
/* Your Script */
}
}
close(fd);
return 0;
}