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"
2023-06-08 01:14:25 -03:00
# include "IS31FL3195.h"
2018-07-18 21:49:35 -03:00
# include "PCA9685LED_I2C.h"
2021-03-23 21:41:59 -03:00
# include "NavigatorLED.h"
2019-04-02 14:56:00 -03:00
# include "NeoPixel.h"
2018-07-25 09:07:49 -03:00
# include "NCP5623.h"
2018-11-21 21:18:30 -04:00
# include "OreoLED_I2C.h"
2016-01-29 00:38:21 -04:00
# include "RCOutputRGBLed.h"
2018-07-24 22:30:05 -03:00
# include "ToneAlarm.h"
2016-01-29 00:38:21 -04:00
# include "ToshibaLED_I2C.h"
2023-02-27 00:06:38 -04:00
# include "LP5562.h"
2016-01-29 00:38:21 -04:00
# 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-11-01 13:11:44 -03:00
# include "Led_Sysfs.h"
2023-04-08 01:09:10 -03:00
# include "DroneCAN_RGB_LED.h"
2019-05-16 00:24:07 -03:00
# include "SITL_SFML_LED.h"
2017-01-20 01:39:49 -04:00
# include <stdio.h>
2018-01-22 05:11:14 -04:00
# include "AP_BoardLED2.h"
2020-02-22 19:54:57 -04:00
# include "ProfiLED.h"
2020-09-03 10:30:24 -03:00
# include "ScriptingLED.h"
2021-04-03 19:01:55 -03:00
# include "DShotLED.h"
2016-09-30 04:21:28 -03:00
2018-01-29 17:33:57 -04:00
extern const AP_HAL : : HAL & hal ;
2019-02-10 14:04:10 -04:00
AP_Notify * AP_Notify : : _singleton ;
2017-07-08 20:40:45 -03:00
2023-05-18 02:24:24 -03:00
# if CONFIG_HAL_BOARD == HAL_BOARD_SITL
# define CONFIG_NOTIFY_DEVICES_MAX 12
# else
2017-09-06 07:12:36 -03:00
# define CONFIG_NOTIFY_DEVICES_MAX 6
2023-05-18 02:24:24 -03:00
# endif
2017-09-06 07:12:36 -03:00
2022-11-10 19:08:19 -04:00
# if AP_NOTIFY_TOSHIBALED_ENABLED
2017-09-06 07:12:36 -03:00
# define TOSHIBA_LED_I2C_BUS_INTERNAL 0
# define TOSHIBA_LED_I2C_BUS_EXTERNAL 1
2022-11-10 19:08:19 -04:00
# define ALL_TOSHIBALED_I2C (Notify_LED_ToshibaLED_I2C_Internal | Notify_LED_ToshibaLED_I2C_External)
# else
# define ALL_TOSHIBALED_I2C 0
# endif
# if AP_NOTIFY_NCP5623_ENABLED
# define ALL_NCP5623_I2C (Notify_LED_NCP5623_I2C_Internal | Notify_LED_NCP5623_I2C_External)
# else
# define ALL_NCP5623_I2C 0
# endif
2016-01-29 00:38:21 -04:00
2023-02-27 00:06:38 -04:00
# if AP_NOTIFY_LP5562_ENABLED
# define ALL_LP5562_I2C (Notify_LED_LP5562_I2C_Internal | Notify_LED_LP5562_I2C_External)
# else
# define ALL_LP5562_I2C 0
# endif
2023-11-14 01:44:20 -04:00
# if AP_NOTIFY_IS31FL3195_ENABLED
# define ALL_IS31FL3195_I2C (Notify_LED_IS31FL3195_I2C_Internal | Notify_LED_IS31FL3195_I2C_External)
# else
# define ALL_IS31FL3195_I2C 0
# endif
2018-07-25 09:07:49 -03:00
// all I2C_LEDS
2023-11-14 01:44:20 -04:00
# define I2C_LEDS (ALL_TOSHIBALED_I2C | ALL_NCP5623_I2C | ALL_LP5562_I2C | ALL_IS31FL3195_I2C)
2022-11-10 19:08:19 -04:00
2023-06-07 00:38:30 -03:00
# if AP_NOTIFY_DRONECAN_LED_ENABLED
# define DRONECAN_LEDS Notify_LED_DroneCAN
# else
# define DRONECAN_LEDS 0
# endif
2018-07-25 09:07:49 -03:00
2023-04-24 09:47:59 -03:00
# ifndef DEFAULT_NTF_LED_TYPES
2019-01-19 04:18:51 -04:00
# if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
2023-04-24 09:47:59 -03:00
# define DEFAULT_NTF_LED_TYPES (Notify_LED_Board | I2C_LEDS)
2018-07-18 21:49:35 -03:00
2020-01-19 13:15:15 -04:00
// Linux boards
2018-07-18 21:49:35 -03:00
# elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX
# if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO
2023-04-24 09:47:59 -03:00
# define DEFAULT_NTF_LED_TYPES (Notify_LED_Board | I2C_LEDS |\
2018-07-18 21:49:35 -03:00
Notify_LED_PCA9685LED_I2C_External )
# elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO2
2023-04-24 09:47:59 -03:00
# define DEFAULT_NTF_LED_TYPES (Notify_LED_Board | I2C_LEDS)
2018-07-18 21:49:35 -03:00
# elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_EDGE
2023-04-24 09:47:59 -03:00
# define DEFAULT_NTF_LED_TYPES (Notify_LED_Board | I2C_LEDS |\
2023-06-07 00:38:30 -03:00
DRONECAN_LEDS )
2018-07-18 21:49:35 -03:00
# elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI || \
CONFIG_HAL_BOARD_SUBTYPE = = HAL_BOARD_SUBTYPE_LINUX_BLUE | | \
CONFIG_HAL_BOARD_SUBTYPE = = HAL_BOARD_SUBTYPE_LINUX_POCKET | | \
CONFIG_HAL_BOARD_SUBTYPE = = HAL_BOARD_SUBTYPE_LINUX_ERLEBRAIN2 | | \
CONFIG_HAL_BOARD_SUBTYPE = = HAL_BOARD_SUBTYPE_LINUX_PXFMINI | | \
CONFIG_HAL_BOARD_SUBTYPE = = HAL_BOARD_SUBTYPE_LINUX_BH | | \
2021-09-07 02:17:39 -03:00
CONFIG_HAL_BOARD_SUBTYPE = = HAL_BOARD_SUBTYPE_LINUX_DISCO | | \
2023-10-22 14:50:57 -03:00
CONFIG_HAL_BOARD_SUBTYPE = = HAL_BOARD_SUBTYPE_LINUX_OBAL_V1 | | \
CONFIG_HAL_BOARD_SUBTYPE = = HAL_BOARD_SUBTYPE_LINUX_CANZERO
2023-04-24 09:47:59 -03:00
# define DEFAULT_NTF_LED_TYPES (Notify_LED_Board)
2018-07-18 21:49:35 -03:00
# elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_RST_ZYNQ
2023-04-24 09:47:59 -03:00
# define DEFAULT_NTF_LED_TYPES (Notify_LED_ToshibaLED_I2C_External)
2018-07-18 21:49:35 -03:00
# else // other linux
2023-04-24 09:47:59 -03:00
# define DEFAULT_NTF_LED_TYPES (Notify_LED_Board | I2C_LEDS)
2018-07-18 21:49:35 -03:00
# endif
// All other builds
# else
2023-04-24 09:47:59 -03:00
# define DEFAULT_NTF_LED_TYPES (Notify_LED_Board | I2C_LEDS)
2018-07-18 21:49:35 -03:00
# endif // board selection
2023-04-24 09:47:59 -03:00
# endif // DEFAULT_NTF_LED_TYPES
2018-07-18 21:49:35 -03:00
2019-01-04 22:26:46 -04:00
# ifndef BUZZER_ENABLE_DEFAULT
2021-06-20 07:31:09 -03:00
# if HAL_CANMANAGER_ENABLED
2021-05-26 12:48:48 -03:00
// Enable Buzzer messages over UAVCAN
# define BUZZER_ENABLE_DEFAULT (Notify_Buzz_Builtin | Notify_Buzz_UAVCAN)
# else
# define BUZZER_ENABLE_DEFAULT Notify_Buzz_Builtin
# endif
2019-01-04 22:26:46 -04:00
# endif
2021-04-03 19:01:55 -03:00
# ifndef BUILD_DEFAULT_BUZZER_TYPE
2021-07-04 05:23:44 -03:00
# define BUILD_DEFAULT_BUZZER_TYPE BUZZER_ENABLE_DEFAULT
2021-04-03 19:01:55 -03:00
# endif
2020-12-22 03:33:00 -04:00
# ifndef NOTIFY_LED_BRIGHT_DEFAULT
# define NOTIFY_LED_BRIGHT_DEFAULT RGB_LED_HIGH
# endif
# ifndef NOTIFY_LED_OVERRIDE_DEFAULT
2023-05-16 21:32:36 -03:00
# define NOTIFY_LED_OVERRIDE_DEFAULT 0 // rgb_source_t::standard
2020-12-22 03:33:00 -04:00
# endif
# ifndef NOTIFY_LED_LEN_DEFAULT
# define NOTIFY_LED_LEN_DEFAULT 1
# endif
2021-11-14 20:41:33 -04:00
# ifndef HAL_BUZZER_PIN
# define HAL_BUZZER_PIN -1
# endif
2023-04-22 18:11:08 -03:00
# ifndef DEFAULT_BUZZ_ON_LVL
# define DEFAULT_BUZZ_ON_LVL 1
2021-11-14 20:41:33 -04:00
# endif
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
2020-12-22 03:33:00 -04:00
AP_GROUPINFO ( " LED_BRIGHT " , 0 , AP_Notify , _rgb_led_brightness , NOTIFY_LED_BRIGHT_DEFAULT ) ,
2015-12-01 16:22:26 -04:00
2021-04-03 19:01:55 -03:00
// @Param: BUZZ_TYPES
// @DisplayName: Buzzer Driver Types
// @Description: Controls what types of Buzzer will be enabled
2021-12-13 21:32:24 -04:00
// @Bitmask: 0:Built-in buzzer, 1:DShot, 2:DroneCAN
2016-03-31 15:18:52 -03:00
// @User: Advanced
2021-04-03 19:01:55 -03:00
AP_GROUPINFO ( " BUZZ_TYPES " , 1 , AP_Notify , _buzzer_type , BUILD_DEFAULT_BUZZER_TYPE ) ,
2018-01-22 05:11:14 -04:00
2016-07-16 03:02:27 -03:00
// @Param: LED_OVERRIDE
2018-08-13 23:17:24 -03:00
// @DisplayName: Specifies colour source for the RGBLed
2019-08-29 18:04:17 -03:00
// @Description: Specifies the source for the colours and brightness for the LED. OutbackChallenge conforms to the MedicalExpress (https://uavchallenge.org/medical-express/) rules, essentially "Green" is disarmed (safe-to-approach), "Red" is armed (not safe-to-approach). Traffic light is a simplified color set, red when armed, yellow when the safety switch is not surpressing outputs (but disarmed), and green when outputs are surpressed and disarmed, the LED will blink faster if disarmed and failing arming checks.
2020-12-22 03:33:00 -04:00
// @Values: 0:Standard,1:MAVLink/Scripting/AP_Periph,2:OutbackChallenge,3:TrafficLight
2016-07-16 03:02:27 -03:00
// @User: Advanced
2020-12-22 03:33:00 -04:00
AP_GROUPINFO ( " LED_OVERRIDE " , 2 , AP_Notify , _rgb_led_override , NOTIFY_LED_OVERRIDE_DEFAULT ) ,
2016-09-30 04:21:28 -03:00
2021-06-09 14:30:59 -03:00
# if HAL_DISPLAY_ENABLED
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.
2019-07-05 04:26:55 -03:00
// @Values: 0:Disable,1:ssd1306,2:sh1106,10:SITL
2016-09-30 04:21:28 -03:00
// @User: Advanced
AP_GROUPINFO ( " DISPLAY_TYPE " , 3 , AP_Notify , _display_type , 0 ) ,
2021-06-09 14:30:59 -03:00
# endif
2016-09-30 04:21:28 -03:00
2022-11-16 03:56:01 -04:00
# if AP_NOTIFY_OREOLED_ENABLED
2017-06-01 19:08:07 -03:00
// @Param: OREO_THEME
// @DisplayName: OreoLED Theme
// @Description: Enable/Disable Solo Oreo LED driver, 0 to disable, 1 for Aircraft theme, 2 for Rover theme
// @Values: 0:Disabled,1:Aircraft,2:Rover
// @User: Advanced
AP_GROUPINFO ( " OREO_THEME " , 4 , AP_Notify , _oreo_theme , 0 ) ,
2018-11-21 21:18:30 -04:00
# endif
2017-06-01 19:08:07 -03:00
2018-01-22 05:11:14 -04:00
// @Param: BUZZ_PIN
// @DisplayName: Buzzer pin
2022-04-22 10:14:44 -03:00
// @Description: Enables to connect active buzzer to arbitrary pin. Requires 3-pin buzzer or additional MOSFET! Some the Wiki's "GPIOs" page for how to determine the pin number for a given autopilot.
2022-10-13 03:36:35 -03:00
// @Values: -1:Disabled
2018-01-22 05:11:14 -04:00
// @User: Advanced
2021-11-14 20:41:33 -04:00
AP_GROUPINFO ( " BUZZ_PIN " , 5 , AP_Notify , _buzzer_pin , HAL_BUZZER_PIN ) ,
2018-01-22 05:11:14 -04:00
2018-07-18 21:49:35 -03:00
// @Param: LED_TYPES
// @DisplayName: LED Driver Types
// @Description: Controls what types of LEDs will be enabled
2023-11-14 01:46:30 -04:00
// @Bitmask: 0:Built-in LED, 1:Internal ToshibaLED, 2:External ToshibaLED, 3:External PCA9685, 4:Oreo LED, 5:DroneCAN, 6:NCP5623 External, 7:NCP5623 Internal, 8:NeoPixel, 9:ProfiLED, 10:Scripting, 11:DShot, 12:ProfiLED_SPI, 13:LP5562 External, 14: LP5562 Internal, 15:IS31FL3195 External, 16: IS31FL3195 Internal, 17: DiscreteRGB, 18: NeoPixelRGB
2018-07-18 21:49:35 -03:00
// @User: Advanced
2023-04-24 09:47:59 -03:00
AP_GROUPINFO ( " LED_TYPES " , 6 , AP_Notify , _led_type , DEFAULT_NTF_LED_TYPES ) ,
2018-07-18 21:49:35 -03:00
2018-10-16 01:27:02 -03:00
// @Param: BUZZ_ON_LVL
// @DisplayName: Buzzer-on pin logic level
// @Description: Specifies pin level that indicates buzzer should play
// @Values: 0:LowIsOn,1:HighIsOn
// @User: Advanced
2023-04-22 18:11:08 -03:00
AP_GROUPINFO ( " BUZZ_ON_LVL " , 7 , AP_Notify , _buzzer_level , DEFAULT_BUZZ_ON_LVL ) ,
2018-10-16 01:27:02 -03:00
2019-09-02 22:25:18 -03:00
// @Param: BUZZ_VOLUME
// @DisplayName: Buzzer volume
2021-02-04 01:02:31 -04:00
// @Description: Control the volume of the buzzer
2019-09-02 22:25:18 -03:00
// @Range: 0 100
// @Units: %
AP_GROUPINFO ( " BUZZ_VOLUME " , 8 , AP_Notify , _buzzer_volume , 100 ) ,
2020-01-19 13:15:15 -04:00
2020-02-22 19:54:57 -04:00
// @Param: LED_LEN
// @DisplayName: Serial LED String Length
// @Description: The number of Serial LED's to use for notifications (NeoPixel's and ProfiLED)
2020-01-19 13:15:15 -04:00
// @Range: 1 32
// @User: Advanced
2021-02-16 12:58:56 -04:00
// @RebootRequired: True
2020-12-22 03:33:00 -04:00
AP_GROUPINFO ( " LED_LEN " , 9 , AP_Notify , _led_len , NOTIFY_LED_LEN_DEFAULT ) ,
2020-01-19 13:15:15 -04:00
2015-12-01 16:22:26 -04:00
AP_GROUPEND
} ;
// Default constructor
AP_Notify : : AP_Notify ( )
{
2018-07-18 21:49:35 -03:00
AP_Param : : setup_object_defaults ( this , var_info ) ;
2019-02-10 14:04:10 -04:00
if ( _singleton ! = nullptr ) {
2017-07-08 20:40:45 -03:00
AP_HAL : : panic ( " AP_Notify must be singleton " ) ;
}
2019-02-10 14:04:10 -04:00
_singleton = this ;
2015-12-01 16:22:26 -04:00
}
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
2017-09-06 07:12:36 -03:00
NotifyDevice * AP_Notify : : _devices [ CONFIG_NOTIFY_DEVICES_MAX ] ;
uint8_t AP_Notify : : _num_devices ;
2016-01-22 16:03:07 -04:00
2018-06-26 14:50:11 -03:00
void AP_Notify : : add_backend_helper ( NotifyDevice * backend )
{
_devices [ _num_devices ] = backend ;
_devices [ _num_devices ] - > pNotify = this ;
if ( ! _devices [ _num_devices ] - > init ( ) ) {
delete _devices [ _num_devices ] ;
_devices [ _num_devices ] = nullptr ;
} else {
_num_devices + + ;
}
}
# define ADD_BACKEND(backend) do { add_backend_helper(backend); if (_num_devices >= CONFIG_NOTIFY_DEVICES_MAX) return;} while(0)
2017-09-06 07:12:36 -03:00
// add notify backends to _devices array
void AP_Notify : : add_backends ( void )
2017-06-01 19:08:07 -03:00
{
2017-09-06 07:12:36 -03:00
if ( _num_devices ! = 0 ) {
return ;
}
2016-01-22 16:02:08 -04:00
2018-07-22 16:45:39 -03:00
for ( uint32_t i = 1 ; i < Notify_LED_MAX ; i = i < < 1 ) {
2018-07-18 21:49:35 -03:00
switch ( _led_type & i ) {
case Notify_LED_None :
break ;
case Notify_LED_Board :
// select the most appropriate built in LED driver type
# if CONFIG_HAL_BOARD == HAL_BOARD_LINUX
# if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO2
ADD_BACKEND ( new Led_Sysfs ( " rgb_led0 " , " rgb_led2 " , " rgb_led1 " ) ) ;
# elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_EDGE
ADD_BACKEND ( new RCOutputRGBLedInverted ( 12 , 13 , 14 ) ) ;
# elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BH
ADD_BACKEND ( new RCOutputRGBLed ( HAL_RCOUT_RGBLED_RED , HAL_RCOUT_RGBLED_GREEN , HAL_RCOUT_RGBLED_BLUE ) ) ;
# elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DISCO
ADD_BACKEND ( new DiscoLED ( ) ) ;
2020-01-10 15:25:30 -04:00
# elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIGATOR
2021-03-23 21:41:59 -03:00
ADD_BACKEND ( new NavigatorLED ( ) ) ;
2021-09-07 02:17:39 -03:00
# elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_OBAL_V1
ADD_BACKEND ( new AP_BoardLED2 ( ) ) ;
2018-07-18 21:49:35 -03:00
# endif
# endif // CONFIG_HAL_BOARD == HAL_BOARD_LINUX
2017-09-06 07:12:36 -03:00
2019-01-23 18:10:04 -04:00
# if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_VRBRAIN_V51 || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_VRBRAIN_V52 || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_VRUBRAIN_V51 || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_VRCORE_V10 || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_VRBRAIN_V54
2019-01-14 06:52:46 -04:00
ADD_BACKEND ( new ExternalLED ( ) ) ; // despite the name this is a built in set of onboard LED's
2019-01-19 04:18:51 -04:00
# endif // CONFIG_HAL_BOARD_SUBTYPE == various CHIBIOS-VRBRAINs
2018-07-25 22:09:34 -03:00
2018-07-18 21:49:35 -03:00
# if defined(HAL_HAVE_PIXRACER_LED)
ADD_BACKEND ( new PixRacerLED ( ) ) ;
# elif (defined(HAL_GPIO_A_LED_PIN) && defined(HAL_GPIO_B_LED_PIN) && defined(HAL_GPIO_C_LED_PIN))
2019-01-23 18:10:04 -04:00
# if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_VRBRAIN_V51 || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_VRBRAIN_V52 || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_VRUBRAIN_V51 || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_VRCORE_V10 || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_VRBRAIN_V54
2018-07-18 21:49:35 -03:00
ADD_BACKEND ( new VRBoard_LED ( ) ) ;
2019-01-14 06:52:46 -04:00
# else
ADD_BACKEND ( new AP_BoardLED ( ) ) ;
2019-01-19 04:18:51 -04:00
# endif
2018-07-18 21:49:35 -03:00
# elif (defined(HAL_GPIO_A_LED_PIN) && defined(HAL_GPIO_B_LED_PIN))
ADD_BACKEND ( new AP_BoardLED2 ( ) ) ;
# endif
break ;
2022-11-10 19:08:19 -04:00
# if AP_NOTIFY_TOSHIBALED_ENABLED
2018-07-18 21:49:35 -03:00
case Notify_LED_ToshibaLED_I2C_Internal :
ADD_BACKEND ( new ToshibaLED_I2C ( TOSHIBA_LED_I2C_BUS_INTERNAL ) ) ;
break ;
case Notify_LED_ToshibaLED_I2C_External :
ADD_BACKEND ( new ToshibaLED_I2C ( TOSHIBA_LED_I2C_BUS_EXTERNAL ) ) ;
break ;
2022-11-10 19:08:19 -04:00
# endif
2022-11-02 05:55:25 -03:00
# if AP_NOTIFY_NCP5623_ENABLED
2018-07-25 09:07:49 -03:00
case Notify_LED_NCP5623_I2C_External :
2018-08-07 05:28:13 -03:00
FOREACH_I2C_EXTERNAL ( b ) {
ADD_BACKEND ( new NCP5623 ( b ) ) ;
}
2018-07-25 09:07:49 -03:00
break ;
case Notify_LED_NCP5623_I2C_Internal :
2021-05-30 06:21:44 -03:00
FOREACH_I2C_INTERNAL ( b ) {
ADD_BACKEND ( new NCP5623 ( b ) ) ;
}
2018-07-25 09:07:49 -03:00
break ;
# endif
2022-11-07 21:22:04 -04:00
# if AP_NOTIFY_PCA9685_ENABLED
2018-07-18 21:49:35 -03:00
case Notify_LED_PCA9685LED_I2C_External :
ADD_BACKEND ( new PCA9685LED_I2C ( ) ) ;
break ;
2022-11-07 21:22:04 -04:00
# endif
2023-02-28 22:57:09 -04:00
# if AP_NOTIFY_NEOPIXEL_ENABLED
2019-04-02 14:56:00 -03:00
case Notify_LED_NeoPixel :
2023-09-28 17:49:43 -03:00
case Notify_LED_NeoPixelRGB :
2019-04-02 14:56:00 -03:00
ADD_BACKEND ( new NeoPixel ( ) ) ;
break ;
2023-02-28 22:57:09 -04:00
# endif
# if AP_NOTIFY_PROFILED_ENABLED
2020-02-22 19:54:57 -04:00
case Notify_LED_ProfiLED :
ADD_BACKEND ( new ProfiLED ( ) ) ;
break ;
2023-02-28 22:57:09 -04:00
# endif
# if AP_NOTIFY_PROFILED_SPI_ENABLED
2020-08-31 17:28:35 -03:00
case Notify_LED_ProfiLED_SPI :
ADD_BACKEND ( new ProfiLED_SPI ( ) ) ;
break ;
2023-02-28 22:57:09 -04:00
# endif
2022-11-16 03:56:01 -04:00
# if AP_NOTIFY_OREOLED_ENABLED
2023-06-07 00:38:30 -03:00
case Notify_LED_OreoLED :
2018-11-21 21:18:30 -04:00
if ( _oreo_theme ) {
ADD_BACKEND ( new OreoLED_I2C ( 0 , _oreo_theme ) ) ;
}
2018-07-18 21:49:35 -03:00
break ;
2023-06-07 00:38:30 -03:00
# endif
# if AP_NOTIFY_DRONECAN_LED_ENABLED
2023-04-08 01:09:10 -03:00
case Notify_LED_DroneCAN :
2023-05-02 03:04:21 -03:00
ADD_BACKEND ( new DroneCAN_RGB_LED ( ) ) ;
2018-07-18 21:49:35 -03:00
break ;
2023-06-07 00:38:30 -03:00
# endif // AP_NOTIFY_DRONECAN_LED_ENABLED
# if AP_NOTIFY_SCRIPTING_LED_ENABLED
2020-09-03 10:30:24 -03:00
case Notify_LED_Scripting :
ADD_BACKEND ( new ScriptingLED ( ) ) ;
break ;
2023-06-07 00:38:30 -03:00
# endif
# if AP_NOTIFY_DSHOT_LED_ENABLED
2021-04-03 19:01:55 -03:00
case Notify_LED_DShot :
ADD_BACKEND ( new DShotLED ( ) ) ;
break ;
2023-06-07 00:38:30 -03:00
# endif
2023-02-27 00:06:38 -04:00
# if AP_NOTIFY_LP5562_ENABLED
case Notify_LED_LP5562_I2C_External :
FOREACH_I2C_EXTERNAL ( b ) {
ADD_BACKEND ( new LP5562 ( b , 0x30 ) ) ;
}
break ;
case Notify_LED_LP5562_I2C_Internal :
FOREACH_I2C_INTERNAL ( b ) {
ADD_BACKEND ( new LP5562 ( b , 0x30 ) ) ;
}
break ;
2023-06-08 01:14:25 -03:00
# endif
# if AP_NOTIFY_IS31FL3195_ENABLED
case Notify_LED_IS31FL3195_I2C_External :
FOREACH_I2C_EXTERNAL ( b ) {
ADD_BACKEND ( new IS31FL3195 ( b , 0x54 ) ) ;
}
break ;
case Notify_LED_IS31FL3195_I2C_Internal :
FOREACH_I2C_INTERNAL ( b ) {
ADD_BACKEND ( new IS31FL3195 ( b , 0x54 ) ) ;
}
break ;
2023-09-11 16:04:13 -03:00
# endif
# if AP_NOTIFY_DISCRETE_RGB_ENABLED
case Notify_LED_DiscreteRGB :
ADD_BACKEND ( new DiscreteRGBLed ( DISCRETE_RGB_RED_PIN ,
DISCRETE_RGB_GREEN_PIN ,
DISCRETE_RGB_BLUE_PIN ,
DISCRETE_RGB_POLARITY ) ) ;
break ;
2023-02-27 00:06:38 -04:00
# endif
2018-07-18 21:49:35 -03:00
}
2017-09-06 07:12:36 -03:00
}
2017-06-01 19:08:07 -03:00
2021-06-09 14:30:59 -03:00
# if HAL_DISPLAY_ENABLED
2018-07-18 21:49:35 -03:00
// Always try and add a display backend
2017-09-06 07:12:36 -03:00
ADD_BACKEND ( new Display ( ) ) ;
2021-06-09 14:30:59 -03:00
# endif
2017-06-01 19:08:07 -03:00
2018-07-18 21:49:35 -03:00
// ChibiOS noise makers
2019-01-16 20:19:38 -04:00
# if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
2018-06-26 15:30:53 -03:00
ADD_BACKEND ( new Buzzer ( ) ) ;
2023-04-20 22:35:37 -03:00
# if AP_NOTIFY_TONEALARM_ENABLED
2018-07-25 13:53:33 -03:00
ADD_BACKEND ( new AP_ToneAlarm ( ) ) ;
2018-06-26 15:30:53 -03:00
# endif
2016-07-05 12:25:23 -03:00
2018-07-18 21:49:35 -03:00
// Linux noise makers
2014-11-14 10:14:40 -04:00
# elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX
2018-07-18 21:49:35 -03:00
# if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO || \
CONFIG_HAL_BOARD_SUBTYPE = = HAL_BOARD_SUBTYPE_LINUX_NAVIO2 | | \
CONFIG_HAL_BOARD_SUBTYPE = = HAL_BOARD_SUBTYPE_LINUX_EDGE | | \
CONFIG_HAL_BOARD_SUBTYPE = = HAL_BOARD_SUBTYPE_LINUX_ERLEBRAIN2 | | \
CONFIG_HAL_BOARD_SUBTYPE = = HAL_BOARD_SUBTYPE_LINUX_PXFMINI | | \
CONFIG_HAL_BOARD_SUBTYPE = = HAL_BOARD_SUBTYPE_LINUX_RST_ZYNQ | | \
2023-10-22 14:50:57 -03:00
CONFIG_HAL_BOARD_SUBTYPE = = HAL_BOARD_SUBTYPE_LINUX_BLUE | | \
CONFIG_HAL_BOARD_SUBTYPE = = HAL_BOARD_SUBTYPE_LINUX_CANZERO
2018-07-18 21:49:35 -03:00
// No noise makers, keep this though to ensure that the final else is safe
# elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI || \
2021-09-07 02:17:39 -03:00
CONFIG_HAL_BOARD_SUBTYPE = = HAL_BOARD_SUBTYPE_LINUX_POCKET | | \
CONFIG_HAL_BOARD_SUBTYPE = = HAL_BOARD_SUBTYPE_LINUX_OBAL_V1
2017-09-06 07:12:36 -03:00
ADD_BACKEND ( new Buzzer ( ) ) ;
2017-10-30 06:03:04 -03:00
2017-09-06 07:12:36 -03:00
# else // other linux
2018-07-25 13:53:33 -03:00
ADD_BACKEND ( new AP_ToneAlarm ( ) ) ;
2017-09-06 07:12:36 -03:00
# endif
2017-06-01 19:08:07 -03:00
2019-03-19 23:09:14 -03:00
# elif CONFIG_HAL_BOARD == HAL_BOARD_SITL
ADD_BACKEND ( new AP_ToneAlarm ( ) ) ;
2019-10-08 01:14:59 -03:00
ADD_BACKEND ( new Buzzer ( ) ) ;
2019-05-16 00:24:07 -03:00
# ifdef WITH_SITL_RGBLED
ADD_BACKEND ( new SITL_SFML_LED ( ) ) ;
# endif
2018-07-18 21:49:35 -03:00
# endif // Noise makers
2017-09-06 07:12:36 -03:00
}
// initialisation
2018-07-25 22:09:34 -03:00
void AP_Notify : : init ( void )
2017-09-06 07:12:36 -03:00
{
2018-06-26 14:47:00 -03:00
// add all the backends
add_backends ( ) ;
2013-09-19 03:27:31 -03:00
}
// main update function, called at 50Hz
void AP_Notify : : update ( void )
{
2017-09-06 07:12:36 -03:00
for ( uint8_t i = 0 ; i < _num_devices ; i + + ) {
2017-06-01 19:08:07 -03:00
if ( _devices [ i ] ! = nullptr ) {
_devices [ i ] - > update ( ) ;
}
2014-11-14 10:14:40 -04:00
}
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
2022-10-21 08:48:51 -03:00
# if AP_NOTIFY_MAVLINK_LED_CONTROL_SUPPORT_ENABLED
2015-02-26 03:07:33 -04:00
// handle a LED_CONTROL message
2019-04-30 07:22:48 -03:00
void AP_Notify : : handle_led_control ( const mavlink_message_t & msg )
2015-02-26 03:07:33 -04:00
{
2017-09-06 07:12:36 -03:00
for ( uint8_t i = 0 ; i < _num_devices ; i + + ) {
2017-06-01 19:08:07 -03:00
if ( _devices [ i ] ! = nullptr ) {
_devices [ i ] - > handle_led_control ( msg ) ;
}
2015-02-26 03:07:33 -04:00
}
}
2022-10-21 08:48:51 -03:00
# endif
2016-07-22 00:37:25 -03:00
2020-12-22 03:33:00 -04:00
// handle RGB from Scripting or AP_Periph
2019-12-09 17:06:35 -04:00
void AP_Notify : : handle_rgb ( uint8_t r , uint8_t g , uint8_t b , uint8_t rate_hz )
{
for ( uint8_t i = 0 ; i < _num_devices ; i + + ) {
if ( _devices [ i ] ! = nullptr ) {
_devices [ i ] - > rgb_control ( r , g , b , rate_hz ) ;
}
}
}
2020-08-31 17:28:35 -03:00
// handle RGB Per led from Scripting
void AP_Notify : : handle_rgb_id ( uint8_t r , uint8_t g , uint8_t b , uint8_t id )
{
for ( uint8_t i = 0 ; i < _num_devices ; i + + ) {
if ( _devices [ i ] ! = nullptr ) {
_devices [ i ] - > rgb_set_id ( r , g , b , id ) ;
}
}
}
2019-03-18 23:35:15 -03:00
void AP_Notify : : play_tune ( const char * tune )
{
for ( uint8_t i = 0 ; i < _num_devices ; i + + ) {
if ( _devices [ i ] ! = nullptr ) {
_devices [ i ] - > play_tune ( tune ) ;
}
}
}
2017-01-20 06:13:37 -04:00
// set flight mode string
void AP_Notify : : set_flight_mode_str ( const char * str )
{
2023-03-11 23:26:41 -04:00
strncpy ( _flight_mode_str , str , sizeof ( _flight_mode_str ) ) ;
2017-01-20 06:13:37 -04:00
_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
}
2019-03-18 23:35:15 -03:00
2020-12-22 03:33:00 -04:00
// convert 0-3 to 0-100
int8_t AP_Notify : : get_rgb_led_brightness_percent ( ) const
{
switch ( _rgb_led_brightness ) {
default :
case RGB_LED_OFF :
return 0 ;
case RGB_LED_LOW :
return 33 ;
case RGB_LED_MEDIUM :
return 66 ;
case RGB_LED_HIGH :
return 100 ;
}
}
2019-03-18 23:35:15 -03:00
namespace AP {
AP_Notify & notify ( )
{
return * AP_Notify : : get_singleton ( ) ;
}
} ;