diff --git a/libraries/AP_Notify/AP_Notify.cpp b/libraries/AP_Notify/AP_Notify.cpp index a872f03f7d..ade9b83e4f 100644 --- a/libraries/AP_Notify/AP_Notify.cpp +++ b/libraries/AP_Notify/AP_Notify.cpp @@ -171,3 +171,11 @@ void AP_Notify::handle_led_control(mavlink_message_t *msg) _devices[i]->handle_led_control(msg); } } + +// handle a PLAY_TUNE message +void AP_Notify::handle_play_tune(mavlink_message_t *msg) +{ + for (uint8_t i = 0; i < CONFIG_NOTIFY_DEVICES_COUNT; i++) { + _devices[i]->handle_play_tune(msg); + } +} diff --git a/libraries/AP_Notify/AP_Notify.h b/libraries/AP_Notify/AP_Notify.h index 5055c4e400..470d42703c 100644 --- a/libraries/AP_Notify/AP_Notify.h +++ b/libraries/AP_Notify/AP_Notify.h @@ -107,6 +107,9 @@ public: // handle a LED_CONTROL message static void handle_led_control(mavlink_message_t* msg); + // handle a PLAY_TUNE message + static void handle_play_tune(mavlink_message_t* msg); + static const struct AP_Param::GroupInfo var_info[]; bool buzzer_enabled() const { return _buzzer_enable; } diff --git a/libraries/AP_Notify/NotifyDevice.h b/libraries/AP_Notify/NotifyDevice.h index 534ed8a7f3..9d350f6a57 100644 --- a/libraries/AP_Notify/NotifyDevice.h +++ b/libraries/AP_Notify/NotifyDevice.h @@ -13,9 +13,13 @@ public: // update - updates device according to timed_updated. Should be // called at 50Hz virtual void update() = 0; + // handle a LED_CONTROL message, by default device ignore message virtual void handle_led_control(mavlink_message_t *msg) {} + // handle a PLAY_TUNE message, by default device ignore message + virtual void handle_play_tune(mavlink_message_t *msg) {} + // this pointer is used to read the parameters relative to devices const AP_Notify *pNotify; }; diff --git a/libraries/AP_Notify/ToneAlarm_PX4.cpp b/libraries/AP_Notify/ToneAlarm_PX4.cpp index f5eadd00be..b64526360e 100644 --- a/libraries/AP_Notify/ToneAlarm_PX4.cpp +++ b/libraries/AP_Notify/ToneAlarm_PX4.cpp @@ -336,4 +336,19 @@ void ToneAlarm_PX4::update() } } + +/* + handle a PLAY_TUNE message +*/ +void ToneAlarm_PX4::handle_play_tune(mavlink_message_t *msg) +{ + // decode mavlink message + mavlink_play_tune_t packet; + + mavlink_msg_play_tune_decode(msg, &packet); + + play_string(packet.tune); +} + + #endif // CONFIG_HAL_BOARD == HAL_BOARD_PX4 diff --git a/libraries/AP_Notify/ToneAlarm_PX4.h b/libraries/AP_Notify/ToneAlarm_PX4.h index 712f56c3d7..ba566fb592 100644 --- a/libraries/AP_Notify/ToneAlarm_PX4.h +++ b/libraries/AP_Notify/ToneAlarm_PX4.h @@ -31,6 +31,9 @@ public: /// update - updates led according to timed_updated. Should be called at 50Hz void update(); + // handle a PLAY_TUNE message + void handle_play_tune(mavlink_message_t *msg); + private: /// play_tune - play one of the pre-defined tunes void play_tone(const uint8_t tone_index);