Browse Source

AP_Notify: support playing tunes by string on ChibiOS

mission-4.1.18
Andrew Tridgell 7 years ago
parent
commit
d93964b319
  1. 23
      libraries/AP_Notify/ToneAlarm_ChibiOS.cpp
  2. 3
      libraries/AP_Notify/ToneAlarm_ChibiOS.h

23
libraries/AP_Notify/ToneAlarm_ChibiOS.cpp

@ -21,6 +21,7 @@ @@ -21,6 +21,7 @@
#if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
#include "ToneAlarm_ChibiOS.h"
#include <AP_HAL_ChibiOS/ToneAlarm.h>
#include <AP_Math/AP_Math.h>
#include "AP_Notify.h"
extern const AP_HAL::HAL& hal;
@ -102,4 +103,26 @@ void ToneAlarm_ChibiOS::update() @@ -102,4 +103,26 @@ void ToneAlarm_ChibiOS::update()
}
}
/*
handle a PLAY_TUNE message
*/
void ToneAlarm_ChibiOS::handle_play_tune(mavlink_message_t *msg)
{
// decode mavlink message
mavlink_play_tune_t packet;
mavlink_msg_play_tune_decode(msg, &packet);
char str[100];
strncpy(str, packet.tune, MIN(sizeof(packet.tune), sizeof(str)-1));
str[sizeof(str)-1] = 0;
uint8_t len = strlen(str);
uint8_t len2 = strnlen(packet.tune2, sizeof(packet.tune2));
len2 = MIN((sizeof(str)-1)-len, len2);
strncpy(str+len, packet.tune2, len2);
str[sizeof(str)-1] = 0;
hal.util->toneAlarm_set_tune_string(str);
}
#endif // CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS

3
libraries/AP_Notify/ToneAlarm_ChibiOS.h

@ -28,6 +28,9 @@ public: @@ -28,6 +28,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
bool play_tune(uint8_t tune_number);

Loading…
Cancel
Save