mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-25 07:13:35 +08:00
commander: add power button notification callback
This commit is contained in:
@@ -303,6 +303,16 @@ static void answer_command(struct vehicle_command_s &cmd, unsigned result,
|
|||||||
/* publish vehicle status flags from the global variable status_flags*/
|
/* publish vehicle status flags from the global variable status_flags*/
|
||||||
static void publish_status_flags(orb_advert_t &vehicle_status_flags_pub);
|
static void publish_status_flags(orb_advert_t &vehicle_status_flags_pub);
|
||||||
|
|
||||||
|
|
||||||
|
static int power_button_state_notification_cb(board_power_button_state_notification_e request)
|
||||||
|
{
|
||||||
|
// Note: this can be called from IRQ handlers
|
||||||
|
if (request == PWR_BUTTON_REQUEST_SHUT_DOWN) {
|
||||||
|
px4_shutdown_request(false, false);
|
||||||
|
}
|
||||||
|
return PWR_BUTTON_RESPONSE_SHUT_DOWN_PENDING;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check whether autostart ID is in the reserved range for HIL setups
|
* check whether autostart ID is in the reserved range for HIL setups
|
||||||
*/
|
*/
|
||||||
@@ -1378,6 +1388,10 @@ int commander_thread_main(int argc, char *argv[])
|
|||||||
PX4_WARN("Buzzer init failed");
|
PX4_WARN("Buzzer init failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (board_register_power_state_notification_cb(power_button_state_notification_cb) != 0) {
|
||||||
|
PX4_ERR("Failed to register power notification callback");
|
||||||
|
}
|
||||||
|
|
||||||
/* vehicle status topic */
|
/* vehicle status topic */
|
||||||
memset(&status, 0, sizeof(status));
|
memset(&status, 0, sizeof(status));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user