2013-09-19 03:27:31 -03:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-08-11 03:28:44 -03:00
|
|
|
#include "AP_Notify.h"
|
2013-09-19 03:27:31 -03:00
|
|
|
|
2016-01-29 00:38:21 -04:00
|
|
|
#include "AP_BoardLED.h"
|
2017-01-26 08:12:36 -04:00
|
|
|
#include "PixRacerLED.h"
|
2016-01-29 00:38:21 -04:00
|
|
|
#include "Buzzer.h"
|
2017-01-19 03:15:24 -04:00
|
|
|
#include "Display.h"
|
2016-01-29 00:38:21 -04:00
|
|
|
#include "ExternalLED.h"
|
|
|
|
#include "NavioLED_I2C.h"
|
|
|
|
#include "OreoLED_PX4.h"
|
|
|
|
#include "RCOutputRGBLed.h"
|
|
|
|
#include "ToneAlarm_Linux.h"
|
|
|
|
#include "ToneAlarm_PX4.h"
|
2016-01-22 16:03:07 -04:00
|
|
|
#include "ToneAlarm_PX4_Solo.h"
|
2016-01-29 00:38:21 -04:00
|
|
|
#include "ToshibaLED.h"
|
|
|
|
#include "ToshibaLED_I2C.h"
|
|
|
|
#include "VRBoard_LED.h"
|
2016-02-25 09:30:36 -04:00
|
|
|
#include "DiscreteRGBLed.h"
|
2016-10-26 05:26:59 -03:00
|
|
|
#include "DiscoLED.h"
|
2017-01-20 01:39:49 -04:00
|
|
|
#include <stdio.h>
|
2016-09-30 04:21:28 -03:00
|
|
|
|
2016-01-29 00:38:21 -04:00
|
|
|
|
2015-12-01 16:22:26 -04:00
|
|
|
// table of user settable parameters
|
|
|
|
const AP_Param::GroupInfo AP_Notify::var_info[] = {
|
|
|
|
|
2015-12-30 22:11:00 -04:00
|
|
|
// @Param: LED_BRIGHT
|
|
|
|
// @DisplayName: LED Brightness
|
|
|
|
// @Description: Select the RGB LED brightness level. When USB is connected brightness will never be higher than low regardless of the setting.
|
2015-12-01 16:22:26 -04:00
|
|
|
// @Values: 0:Off,1:Low,2:Medium,3:High
|
|
|
|
// @User: Advanced
|
|
|
|
AP_GROUPINFO("LED_BRIGHT", 0, AP_Notify, _rgb_led_brightness, RGB_LED_HIGH),
|
|
|
|
|
2016-03-31 15:18:52 -03:00
|
|
|
// @Param: BUZZ_ENABLE
|
|
|
|
// @DisplayName: Buzzer enable
|
|
|
|
// @Description: Enable or disable the buzzer. Only for Linux and PX4 based boards.
|
|
|
|
// @Values: 0:Disable,1:Enable
|
|
|
|
// @User: Advanced
|
|
|
|
AP_GROUPINFO("BUZZ_ENABLE", 1, AP_Notify, _buzzer_enable, BUZZER_ON),
|
|
|
|
|
2016-07-16 03:02:27 -03:00
|
|
|
// @Param: LED_OVERRIDE
|
|
|
|
// @DisplayName: Setup for MAVLink LED override
|
|
|
|
// @Description: This sets up the board RGB LED for override by MAVLink. Normal notify LED control is disabled
|
|
|
|
// @Values: 0:Disable,1:Enable
|
|
|
|
// @User: Advanced
|
|
|
|
AP_GROUPINFO("LED_OVERRIDE", 2, AP_Notify, _rgb_led_override, 0),
|
2016-09-30 04:21:28 -03:00
|
|
|
|
|
|
|
// @Param: DISPLAY_TYPE
|
|
|
|
// @DisplayName: Type of on-board I2C display
|
|
|
|
// @Description: This sets up the type of on-board I2C display. Disabled by default.
|
|
|
|
// @Values: 0:Disable,1:ssd1306,2:sh1106
|
|
|
|
// @User: Advanced
|
|
|
|
AP_GROUPINFO("DISPLAY_TYPE", 3, AP_Notify, _display_type, 0),
|
|
|
|
|
2015-12-01 16:22:26 -04:00
|
|
|
AP_GROUPEND
|
|
|
|
};
|
|
|
|
|
|
|
|
// Default constructor
|
|
|
|
AP_Notify::AP_Notify()
|
|
|
|
{
|
|
|
|
AP_Param::setup_object_defaults(this, var_info);
|
|
|
|
}
|
|
|
|
|
2013-09-19 03:27:31 -03:00
|
|
|
// static flags, to allow for direct class update from device drivers
|
2016-09-30 04:21:28 -03:00
|
|
|
struct AP_Notify::notify_flags_and_values_type AP_Notify::flags;
|
2014-10-23 09:04:34 -03:00
|
|
|
struct AP_Notify::notify_events_type AP_Notify::events;
|
2013-09-19 03:27:31 -03:00
|
|
|
|
2014-11-14 10:14:40 -04:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4
|
2017-01-26 08:12:36 -04:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_PX4_V4
|
|
|
|
PixRacerLED boardled;
|
|
|
|
#else
|
2014-11-14 10:14:40 -04:00
|
|
|
AP_BoardLED boardled;
|
2017-01-26 08:12:36 -04:00
|
|
|
#endif
|
2017-01-26 05:19:10 -04:00
|
|
|
ToshibaLED_I2C toshibaled;
|
2017-01-19 03:15:24 -04:00
|
|
|
Display display;
|
2016-01-22 16:03:07 -04:00
|
|
|
|
|
|
|
#if AP_NOTIFY_SOLO_TONES == 1
|
|
|
|
ToneAlarm_PX4_Solo tonealarm;
|
|
|
|
#else
|
2014-11-14 10:14:40 -04:00
|
|
|
ToneAlarm_PX4 tonealarm;
|
2016-01-22 16:03:07 -04:00
|
|
|
#endif
|
2016-01-22 16:02:08 -04:00
|
|
|
|
2016-01-22 16:03:07 -04:00
|
|
|
#if AP_NOTIFY_OREOLED == 1
|
2015-02-06 23:24:37 -04:00
|
|
|
OreoLED_PX4 oreoled;
|
2016-09-30 04:21:28 -03:00
|
|
|
NotifyDevice *AP_Notify::_devices[] = {&boardled, &toshibaled, &tonealarm, &oreoled, &display};
|
2015-02-27 02:35:53 -04:00
|
|
|
#else
|
2016-09-30 04:21:28 -03:00
|
|
|
NotifyDevice *AP_Notify::_devices[] = {&boardled, &toshibaled, &tonealarm, &display};
|
2015-02-27 02:35:53 -04:00
|
|
|
#endif
|
2016-01-22 16:02:08 -04:00
|
|
|
|
2014-11-14 10:14:40 -04:00
|
|
|
#elif CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN
|
2016-07-05 12:25:23 -03:00
|
|
|
ToneAlarm_PX4 tonealarm;
|
2014-12-30 07:45:27 -04:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_VRBRAIN_V45
|
2014-11-14 10:14:40 -04:00
|
|
|
AP_BoardLED boardled;
|
2014-12-30 07:45:27 -04:00
|
|
|
#else
|
|
|
|
VRBoard_LED boardled;
|
|
|
|
#endif
|
2017-01-26 05:19:10 -04:00
|
|
|
ToshibaLED_I2C toshibaled;
|
2014-11-14 10:14:40 -04:00
|
|
|
ExternalLED externalled;
|
2016-07-05 12:25:23 -03:00
|
|
|
NotifyDevice *AP_Notify::_devices[] = {&boardled, &toshibaled, &externalled, &tonealarm};
|
|
|
|
|
2014-11-14 10:14:40 -04:00
|
|
|
#elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX
|
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO
|
|
|
|
NavioLED_I2C navioled;
|
2015-06-25 09:52:17 -03:00
|
|
|
ToshibaLED_I2C toshibaled;
|
2016-02-24 06:25:29 -04:00
|
|
|
NotifyDevice *AP_Notify::_devices[] = {&navioled, &toshibaled};
|
2016-02-24 06:24:38 -04:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO2
|
2016-02-25 09:59:08 -04:00
|
|
|
DiscreteRGBLed navioled(4, 27, 6, false);
|
2016-02-24 06:24:38 -04:00
|
|
|
ToshibaLED_I2C toshibaled;
|
|
|
|
NotifyDevice *AP_Notify::_devices[] = {&navioled, &toshibaled};
|
2015-09-01 17:20:07 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI
|
2016-05-04 23:48:44 -03:00
|
|
|
Buzzer buzzer;
|
2017-01-19 03:15:24 -04:00
|
|
|
Display display;
|
2016-05-04 23:48:44 -03:00
|
|
|
NotifyDevice *AP_Notify::_devices[] = {&display, &buzzer};
|
2016-12-29 11:29:15 -04:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BLUE
|
|
|
|
AP_BoardLED boardled;
|
|
|
|
NotifyDevice *AP_Notify::_devices[] = {&boardled};
|
2015-08-19 05:38:09 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_RASPILOT
|
|
|
|
ToshibaLED_I2C toshibaled;
|
|
|
|
ToneAlarm_Linux tonealarm;
|
|
|
|
NotifyDevice *AP_Notify::_devices[] = {&toshibaled, &tonealarm};
|
2015-08-11 18:48:48 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_MINLURE
|
2016-01-05 16:36:38 -04:00
|
|
|
RCOutputRGBLedOff led(15, 13, 14, 255);
|
|
|
|
NotifyDevice *AP_Notify::_devices[] = { &led };
|
2016-01-05 06:37:13 -04:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBRAIN2 || \
|
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXFMINI
|
2015-11-01 07:28:17 -04:00
|
|
|
AP_BoardLED boardled;
|
|
|
|
NotifyDevice *AP_Notify::_devices[] = {&boardled};
|
2015-11-28 05:29:35 -04:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BH
|
|
|
|
AP_BoardLED boardled;
|
|
|
|
RCOutputRGBLed bhled(HAL_RCOUT_RGBLED_RED, HAL_RCOUT_RGBLED_GREEN, HAL_RCOUT_RGBLED_BLUE);
|
|
|
|
NotifyDevice *AP_Notify::_devices[] = {&boardled, &bhled};
|
2016-10-26 05:26:59 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DISCO
|
|
|
|
DiscoLED discoled;
|
2016-10-29 05:23:31 -03:00
|
|
|
ToneAlarm_Linux tonealarm;
|
|
|
|
NotifyDevice *AP_Notify::_devices[] = {&discoled, &tonealarm};
|
2014-11-14 10:14:40 -04:00
|
|
|
#else
|
|
|
|
AP_BoardLED boardled;
|
|
|
|
ToshibaLED_I2C toshibaled;
|
|
|
|
ToneAlarm_Linux tonealarm;
|
2015-07-17 12:15:10 -03:00
|
|
|
NotifyDevice *AP_Notify::_devices[] = {&boardled, &toshibaled, &tonealarm};
|
2014-11-14 10:14:40 -04:00
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
AP_BoardLED boardled;
|
|
|
|
ToshibaLED_I2C toshibaled;
|
2015-07-17 12:15:10 -03:00
|
|
|
NotifyDevice *AP_Notify::_devices[] = {&boardled, &toshibaled};
|
2014-11-14 10:14:40 -04:00
|
|
|
#endif
|
|
|
|
|
2015-07-17 12:15:10 -03:00
|
|
|
#define CONFIG_NOTIFY_DEVICES_COUNT (ARRAY_SIZE(AP_Notify::_devices))
|
|
|
|
|
2013-09-19 03:27:31 -03:00
|
|
|
// initialisation
|
2013-11-30 09:53:40 -04:00
|
|
|
void AP_Notify::init(bool enable_external_leds)
|
2013-09-19 03:27:31 -03:00
|
|
|
{
|
2015-02-02 17:14:44 -04:00
|
|
|
// clear all flags and events
|
|
|
|
memset(&AP_Notify::flags, 0, sizeof(AP_Notify::flags));
|
|
|
|
memset(&AP_Notify::events, 0, sizeof(AP_Notify::events));
|
|
|
|
|
2017-01-20 06:13:37 -04:00
|
|
|
// clear flight mode string and text buffer
|
|
|
|
memset(_flight_mode_str, 0, sizeof(_flight_mode_str));
|
2016-09-30 04:21:28 -03:00
|
|
|
memset(_send_text, 0, sizeof(_send_text));
|
2017-02-17 03:19:16 -04:00
|
|
|
_send_text_updated_millis = 0;
|
2016-09-30 04:21:28 -03:00
|
|
|
|
2013-11-30 09:53:40 -04:00
|
|
|
AP_Notify::flags.external_leds = enable_external_leds;
|
|
|
|
|
2015-07-21 01:39:04 -03:00
|
|
|
for (uint8_t i = 0; i < CONFIG_NOTIFY_DEVICES_COUNT; i++) {
|
2015-12-01 16:22:26 -04:00
|
|
|
_devices[i]->pNotify = this;
|
2014-11-14 10:14:40 -04:00
|
|
|
_devices[i]->init();
|
|
|
|
}
|
2013-09-19 03:27:31 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// main update function, called at 50Hz
|
|
|
|
void AP_Notify::update(void)
|
|
|
|
{
|
2015-07-21 01:39:04 -03:00
|
|
|
for (uint8_t i = 0; i < CONFIG_NOTIFY_DEVICES_COUNT; i++) {
|
2014-11-14 10:14:40 -04:00
|
|
|
_devices[i]->update();
|
|
|
|
}
|
2014-10-23 09:04:34 -03:00
|
|
|
|
|
|
|
//reset the events
|
|
|
|
memset(&AP_Notify::events, 0, sizeof(AP_Notify::events));
|
2013-09-19 03:27:31 -03:00
|
|
|
}
|
2015-02-26 03:07:33 -04:00
|
|
|
|
|
|
|
// handle a LED_CONTROL message
|
|
|
|
void AP_Notify::handle_led_control(mavlink_message_t *msg)
|
|
|
|
{
|
2015-07-21 01:39:04 -03:00
|
|
|
for (uint8_t i = 0; i < CONFIG_NOTIFY_DEVICES_COUNT; i++) {
|
2015-02-26 03:07:33 -04:00
|
|
|
_devices[i]->handle_led_control(msg);
|
|
|
|
}
|
|
|
|
}
|
2016-07-22 00:37:25 -03:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
2016-09-30 04:21:28 -03:00
|
|
|
|
2017-01-20 06:13:37 -04:00
|
|
|
// set flight mode string
|
|
|
|
void AP_Notify::set_flight_mode_str(const char *str)
|
|
|
|
{
|
|
|
|
strncpy(_flight_mode_str, str, 4);
|
|
|
|
_flight_mode_str[sizeof(_flight_mode_str)-1] = 0;
|
|
|
|
}
|
|
|
|
|
2016-09-30 04:21:28 -03:00
|
|
|
void AP_Notify::send_text(const char *str)
|
|
|
|
{
|
|
|
|
strncpy(_send_text, str, sizeof(_send_text));
|
|
|
|
_send_text[sizeof(_send_text)-1] = 0;
|
2017-02-17 03:19:16 -04:00
|
|
|
_send_text_updated_millis = AP_HAL::millis();
|
2016-09-30 04:21:28 -03:00
|
|
|
}
|