2013-09-19 03:27:31 -03:00
|
|
|
/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
/*
|
|
|
|
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
|
|
|
|
|
|
|
// static flags, to allow for direct class update from device drivers
|
2014-12-14 23:20:59 -04:00
|
|
|
struct AP_Notify::notify_flags_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
|
|
|
|
AP_BoardLED boardled;
|
|
|
|
ToshibaLED_PX4 toshibaled;
|
|
|
|
ToneAlarm_PX4 tonealarm;
|
2015-02-27 02:35:53 -04:00
|
|
|
#if OREOLED_ENABLED
|
2015-02-06 23:24:37 -04:00
|
|
|
OreoLED_PX4 oreoled;
|
2015-07-17 12:15:10 -03:00
|
|
|
NotifyDevice *AP_Notify::_devices[] = {&boardled, &toshibaled, &tonealarm, &oreoled};
|
2015-02-27 02:35:53 -04:00
|
|
|
#else
|
2015-07-17 12:15:10 -03:00
|
|
|
NotifyDevice *AP_Notify::_devices[] = {&boardled, &toshibaled, &tonealarm};
|
2015-02-27 02:35:53 -04:00
|
|
|
#endif
|
2014-11-14 10:14:40 -04:00
|
|
|
#elif CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN
|
|
|
|
Buzzer buzzer;
|
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
|
2014-11-14 10:14:40 -04:00
|
|
|
ToshibaLED_I2C toshibaled;
|
|
|
|
ExternalLED externalled;
|
2015-07-17 12:15:10 -03:00
|
|
|
NotifyDevice *AP_Notify::_devices[] = {&boardled, &toshibaled, &externalled, &buzzer};
|
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
|
|
|
|
AP_BoardLED boardled;
|
|
|
|
NavioLED_I2C navioled;
|
2015-06-25 09:52:17 -03:00
|
|
|
ToshibaLED_I2C toshibaled;
|
2015-07-17 12:15:10 -03:00
|
|
|
NotifyDevice *AP_Notify::_devices[] = {&boardled, &navioled, &toshibaled};
|
2015-09-01 17:20:07 -03:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI
|
|
|
|
ToshibaLED_I2C toshibaled;
|
|
|
|
NotifyDevice *AP_Notify::_devices[] = {&toshibaled};
|
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
|
|
|
|
NotifyDevice *AP_Notify::_devices[0];
|
2015-11-01 07:28:17 -04:00
|
|
|
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBRAIN2
|
|
|
|
AP_BoardLED boardled;
|
|
|
|
NotifyDevice *AP_Notify::_devices[] = {&boardled};
|
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));
|
|
|
|
|
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++) {
|
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);
|
|
|
|
}
|
|
|
|
}
|