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);
77 struct input_event ev;
81 int fd_button = open(
"/dev/input/pm_mcu_event", O_RDONLY);
82 if (fd_button == -1) {
83 printf(
"Unable to open mcu_event to read power button state\n");
89 n = read(fd_button, &ev,
sizeof(ev));
90 if (n ==
sizeof(ev) && ev.type == EV_KEY && ev.code == KEY_POWER && ev.value > 0) {
91 printf(
"Stopping Paparazzi from power button and rebooting\n");
93 int ret __attribute__((unused)) = system(
"reboot.sh");
108 int ret __attribute__((unused));
109 ret = system(
"pstop delosd");
110 ret = system(
"pstop dragon-prog");
114 pthread_t bat_thread;
115 if (pthread_create(&bat_thread, NULL,
bat_read, NULL) != 0) {
116 printf(
"[swing_board] Could not create battery reading thread!\n");
118 pthread_setname_np(bat_thread,
"pprz_bat_thread");
121 pthread_t button_thread;
122 if (pthread_create(&button_thread, NULL,
button_read, NULL) != 0) {
123 printf(
"[swing_board] Could not create button reading thread!\n");
125 pthread_setname_np(button_thread,
"pprz_button_thread");
static void * bat_read(void *data)
Battery reading thread.
void board_init2(void)
Optional board init function called at the end of mcu_init().
Interface for electrical status: supply voltage, current, battery status, etc.
static void * button_read(void *data)
Check button thread.
void board_init(void)
Optional board init function called at the start of mcu_init().
Arch independent mcu ( Micro Controller Unit ) utilities.
uint16_t vsupply
supply voltage in decivolts
struct Electrical electrical