Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow mavlink PLAY_TUNE support to be compiled out #22022

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion libraries/AP_BattMonitor/AP_BattMonitor_SMBus_SUI.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <AP_HAL/AP_HAL.h>
#include <AP_Common/AP_Common.h>
#include <AP_Math/AP_Math.h>
#include <AP_Notify/AP_Notify.h>
#include "AP_BattMonitor.h"
#include "AP_BattMonitor_SMBus_SUI.h"

Expand Down
12 changes: 2 additions & 10 deletions libraries/AP_Notify/AP_Notify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ void AP_Notify::update(void)
memset(&AP_Notify::events, 0, sizeof(AP_Notify::events));
}

#if AP_NOTIFY_MAVLINK_LED_CONTROL_SUPPORT_ENABLED
// handle a LED_CONTROL message
void AP_Notify::handle_led_control(const mavlink_message_t &msg)
{
Expand All @@ -421,6 +422,7 @@ void AP_Notify::handle_led_control(const mavlink_message_t &msg)
}
}
}
#endif

// handle RGB from Scripting or AP_Periph
void AP_Notify::handle_rgb(uint8_t r, uint8_t g, uint8_t b, uint8_t rate_hz)
Expand All @@ -442,16 +444,6 @@ void AP_Notify::handle_rgb_id(uint8_t r, uint8_t g, uint8_t b, uint8_t id)
}
}

// handle a PLAY_TUNE message
void AP_Notify::handle_play_tune(const mavlink_message_t &msg)
{
for (uint8_t i = 0; i < _num_devices; i++) {
if (_devices[i] != nullptr) {
_devices[i]->handle_play_tune(msg);
}
}
}

void AP_Notify::play_tune(const char *tune)
{
for (uint8_t i = 0; i < _num_devices; i++) {
Expand Down
6 changes: 5 additions & 1 deletion libraries/AP_Notify/AP_Notify.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include <AP_Common/AP_Common.h>
#include <AP_Param/AP_Param.h>
#include <GCS_MAVLink/GCS_MAVLink.h>
#include "AP_Notify_config.h"

#include "NotifyDevice.h"

Expand Down Expand Up @@ -151,17 +151,21 @@ class AP_Notify
/// update - allow updates of leds that cannot be updated during a timed interrupt
void update(void);

#if AP_NOTIFY_MAVLINK_LED_CONTROL_SUPPORT_ENABLED
// handle a LED_CONTROL message
static void handle_led_control(const mavlink_message_t &msg);
#endif

// handle RGB from Scripting or AP_Periph
static void handle_rgb(uint8_t r, uint8_t g, uint8_t b, uint8_t rate_hz = 0);

// handle RGB from Scripting
static void handle_rgb_id(uint8_t r, uint8_t g, uint8_t b, uint8_t id);

#if AP_NOTIFY_MAVLINK_PLAY_TUNE_SUPPORT_ENABLED
// handle a PLAY_TUNE message
static void handle_play_tune(const mavlink_message_t &msg);
#endif

// play a tune string
static void play_tune(const char *tune);
Expand Down
14 changes: 14 additions & 0 deletions libraries/AP_Notify/AP_Notify_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include <GCS_MAVLink/GCS_config.h>
#if HAL_GCS_ENABLED
#include <GCS_MAVLink/GCS_MAVLink.h>
#endif

#ifndef AP_NOTIFY_MAVLINK_PLAY_TUNE_SUPPORT_ENABLED
#define AP_NOTIFY_MAVLINK_PLAY_TUNE_SUPPORT_ENABLED HAL_GCS_ENABLED
#endif

#ifndef AP_NOTIFY_MAVLINK_LED_CONTROL_SUPPORT_ENABLED
#define AP_NOTIFY_MAVLINK_LED_CONTROL_SUPPORT_ENABLED HAL_GCS_ENABLED
#endif
7 changes: 3 additions & 4 deletions libraries/AP_Notify/NotifyDevice.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <AP_Common/AP_Common.h>
#include <GCS_MAVLink/GCS_MAVLink.h>
#include "AP_Notify_config.h"

class AP_Notify;

Expand All @@ -14,11 +14,10 @@ class NotifyDevice {
// called at 50Hz
virtual void update() = 0;

#if AP_NOTIFY_MAVLINK_LED_CONTROL_SUPPORT_ENABLED
// handle a LED_CONTROL message, by default device ignore message
virtual void handle_led_control(const mavlink_message_t &msg) {}

// handle a PLAY_TUNE message, by default device ignore message
virtual void handle_play_tune(const mavlink_message_t &msg) {}
#endif

// play a MML tune
virtual void play_tune(const char *tune) {}
Expand Down
2 changes: 2 additions & 0 deletions libraries/AP_Notify/OreoLED_I2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ void OreoLED_I2C::send_sync(void)



#if AP_NOTIFY_MAVLINK_LED_CONTROL_SUPPORT_ENABLED
// Handle an LED_CONTROL mavlink message
void OreoLED_I2C::handle_led_control(const mavlink_message_t &msg)
{
Expand Down Expand Up @@ -645,6 +646,7 @@ void OreoLED_I2C::handle_led_control(const mavlink_message_t &msg)
}
_pattern_override = packet.pattern;
}
#endif

OreoLED_I2C::oreo_state::oreo_state()
{
Expand Down
2 changes: 2 additions & 0 deletions libraries/AP_Notify/OreoLED_I2C.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ class OreoLED_I2C : public NotifyDevice {
// called at 50Hz
void update() override;

#if AP_NOTIFY_MAVLINK_LED_CONTROL_SUPPORT_ENABLED
// handle a LED_CONTROL message, by default device ignore message
void handle_led_control(const mavlink_message_t &msg) override;
#endif

private:
enum oreoled_pattern {
Expand Down
2 changes: 2 additions & 0 deletions libraries/AP_Notify/RGBLed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ void RGBLed::update()
set_rgb(red_des, green_des, blue_des);
}

#if AP_NOTIFY_MAVLINK_LED_CONTROL_SUPPORT_ENABLED
/*
handle LED control, only used when LED_OVERRIDE=1
*/
Expand All @@ -251,6 +252,7 @@ void RGBLed::handle_led_control(const mavlink_message_t &msg)
break;
}
}
#endif

/*
update LED when in override mode
Expand Down
2 changes: 2 additions & 0 deletions libraries/AP_Notify/RGBLed.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ class RGBLed: public NotifyDevice {
// called at 50Hz
virtual void update() override;

#if AP_NOTIFY_MAVLINK_LED_CONTROL_SUPPORT_ENABLED
// handle LED control, only used when LED_OVERRIDE=1
virtual void handle_led_control(const mavlink_message_t &msg) override;
#endif

// RGB control
// give RGB and flash rate, used with scripting
Expand Down
15 changes: 7 additions & 8 deletions libraries/AP_Notify/ToneAlarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,26 +449,25 @@ void AP_ToneAlarm::update()
}


#if AP_NOTIFY_MAVLINK_PLAY_TUNE_SUPPORT_ENABLED
/*
* handle a PLAY_TUNE message
*/
void AP_ToneAlarm::handle_play_tune(const mavlink_message_t &msg)
void AP_Notify::handle_play_tune(const mavlink_message_t &msg)
{
// decode mavlink message
mavlink_play_tune_t packet;

mavlink_msg_play_tune_decode(&msg, &packet);

WITH_SEMAPHORE(_sem);

_mml_player.stop();

char _tone_buf[AP_NOTIFY_TONEALARM_TONE_BUF_SIZE] {}; // ~100 bytes
strncpy(_tone_buf, packet.tune, MIN(sizeof(packet.tune), sizeof(_tone_buf)-1));
_tone_buf[sizeof(_tone_buf)-1] = 0;
uint8_t len = strlen(_tone_buf);
uint8_t len2 = strnlen(packet.tune2, sizeof(packet.tune2));
len2 = MIN((sizeof(_tone_buf)-1)-len, len2);
strncpy(_tone_buf+len, packet.tune2, len2);
memcpy(_tone_buf+len, packet.tune2, len2); // not strncpy to avoid truncation warning
_tone_buf[sizeof(_tone_buf)-1] = 0;
_mml_player.play(_tone_buf);

play_tune(_tone_buf);
}
#endif
3 changes: 0 additions & 3 deletions libraries/AP_Notify/ToneAlarm.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ class AP_ToneAlarm: public NotifyDevice {
/// update - updates led according to timed_updated. Should be called at 50Hz
void update() override;

// handle a PLAY_TUNE message
void handle_play_tune(const mavlink_message_t &msg) override;

// play_tune - play tone specified by the provided string of notes
void play_tune(const char *tune) override;

Expand Down
4 changes: 4 additions & 0 deletions libraries/GCS_MAVLink/GCS_Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3786,15 +3786,19 @@ void GCS_MAVLINK::handle_common_message(const mavlink_message_t &msg)
handle_statustext(msg);
break;

#if AP_NOTIFY_MAVLINK_LED_CONTROL_SUPPORT_ENABLED
case MAVLINK_MSG_ID_LED_CONTROL:
// send message to Notify
AP_Notify::handle_led_control(msg);
break;
#endif

#if AP_NOTIFY_MAVLINK_PLAY_TUNE_SUPPORT_ENABLED
case MAVLINK_MSG_ID_PLAY_TUNE:
// send message to Notify
AP_Notify::handle_play_tune(msg);
break;
#endif

#if HAL_RALLY_ENABLED
case MAVLINK_MSG_ID_RALLY_POINT:
Expand Down