Using button in pico mini ubuntu
-
hello, is it possible to use the luckfox pico mini BOOT button in ubuntu?
Hello, then ubuntu can use apt download evtest software, boot button as an adc-key input device can be controlled, you can write programs to trigger the simple script to run
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;
}