36 #include <linux/input.h>
42 static void *
bat_read(
void *data __attribute__((unused)))
49 fp = popen(
"cat /sys/devices/platform/p6-spi.2/spi2.0/vbat",
"r");
51 printf(
"Failed to read battery\n");
54 while (fgets(path,
sizeof(path) - 1, fp) != NULL) {
55 int raw_bat = atoi(path);
76 struct input_event
ev;
80 int fd_button = open(
"/dev/input/pm_mcu_event", O_RDONLY);
81 if (fd_button == -1) {
82 printf(
"Unable to open mcu_event to read power button state\n");
88 n = read(fd_button, &
ev,
sizeof(
ev));
89 if (n ==
sizeof(
ev) &&
ev.type == EV_KEY &&
ev.code == KEY_POWER &&
ev.value > 0) {
90 printf(
"Stopping Paparazzi from power button and rebooting\n");
92 int ret __attribute__((unused)) = system(
"reboot.sh");
107 int ret __attribute__((unused));
108 ret = system(
"pstop delosd");
109 ret = system(
"pstop dragon-prog");
113 pthread_t bat_thread;
114 if (pthread_create(&bat_thread, NULL,
bat_read, NULL) != 0) {
115 printf(
"[swing_board] Could not create battery reading thread!\n");
117 pthread_setname_np(bat_thread,
"pprz_bat_thread");
120 pthread_t button_thread;
121 if (pthread_create(&button_thread, NULL,
button_read, NULL) != 0) {
122 printf(
"[swing_board] Could not create button reading thread!\n");
124 pthread_setname_np(button_thread,
"pprz_button_thread");