From 6960600c285f9c2ffd8bd0d5b0c0b758cf8e297b Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Tue, 28 Sep 2021 11:32:48 +0200 Subject: [PATCH] Mantis: play power off tune To play a power off tune, I needed to convert the file to C++, so that I could use the uORB::Publication. The current implementation starts playing the power off sound but then stops it as soon as the button is released. The problem is mostly that we only get an interrupt when the button is pressed or released but we don't seem to be able to poll it, at least not in the current state. --- boards/atl/mantis-edu/src/CMakeLists.txt | 2 +- boards/atl/mantis-edu/src/{pwr.c => pwr.cpp} | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) rename boards/atl/mantis-edu/src/{pwr.c => pwr.cpp} (90%) diff --git a/boards/atl/mantis-edu/src/CMakeLists.txt b/boards/atl/mantis-edu/src/CMakeLists.txt index c7522a98b1..398389f97d 100644 --- a/boards/atl/mantis-edu/src/CMakeLists.txt +++ b/boards/atl/mantis-edu/src/CMakeLists.txt @@ -39,7 +39,7 @@ add_library(drivers_board spi.cpp timer_config.cpp usb.c - pwr.c + pwr.cpp ) add_dependencies(drivers_board arch_board_hw_info) diff --git a/boards/atl/mantis-edu/src/pwr.c b/boards/atl/mantis-edu/src/pwr.cpp similarity index 90% rename from boards/atl/mantis-edu/src/pwr.c rename to boards/atl/mantis-edu/src/pwr.cpp index 2db785891f..36e1792f92 100644 --- a/boards/atl/mantis-edu/src/pwr.c +++ b/boards/atl/mantis-edu/src/pwr.cpp @@ -53,6 +53,7 @@ #include #include +#include #include #include @@ -116,13 +117,26 @@ int board_power_off(int status) static int board_button_irq(int irq, FAR void *context, FAR void *args) { + uORB::Publication tune_control_pub{ORB_ID(tune_control)}; + if (board_pwr_button_down()) { led_on(BOARD_LED_RED); clock_gettime(CLOCK_REALTIME, &time_down); power_state_notification(PWR_BUTTON_DOWN); + tune_control_s tune_control{}; + tune_control.volume = tune_control_s::VOLUME_LEVEL_DEFAULT - 20; + tune_control.tune_id = tune_control_s::TUNE_ID_POWER_OFF; + tune_control.timestamp = hrt_absolute_time(); + tune_control_pub.publish(tune_control); + } else { + tune_control_s tune_control{}; + tune_control.tune_override = true; + tune_control.timestamp = hrt_absolute_time(); + tune_control_pub.publish(tune_control); + power_state_notification(PWR_BUTTON_UP); led_off(BOARD_LED_RED);