AP_Notify: Use a bitfield to load LED drivers

This commit is contained in:
Michael du Breuil 2018-07-18 17:49:35 -07:00 committed by Andrew Tridgell
parent 73cfd40e7f
commit 961e16dca9
4 changed files with 159 additions and 117 deletions

View File

@ -20,7 +20,7 @@
#include "Buzzer.h" #include "Buzzer.h"
#include "Display.h" #include "Display.h"
#include "ExternalLED.h" #include "ExternalLED.h"
#include "NavioLED_I2C.h" #include "PCA9685LED_I2C.h"
#include "OreoLED_PX4.h" #include "OreoLED_PX4.h"
#include "RCOutputRGBLed.h" #include "RCOutputRGBLed.h"
#include "ToneAlarm_Linux.h" #include "ToneAlarm_Linux.h"
@ -44,6 +44,60 @@ AP_Notify *AP_Notify::_instance;
#define TOSHIBA_LED_I2C_BUS_INTERNAL 0 #define TOSHIBA_LED_I2C_BUS_INTERNAL 0
#define TOSHIBA_LED_I2C_BUS_EXTERNAL 1 #define TOSHIBA_LED_I2C_BUS_EXTERNAL 1
#ifndef BUILD_DEFAULT_LED_TYPE
// PX4 boards
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_PX4_V3 // Has enough memory for Oreo LEDs
#define BUILD_DEFAULT_LED_TYPE (Notify_LED_Board | Notify_LED_ToshibaLED_I2C_Internal | Notify_LED_ToshibaLED_I2C_External | Notify_LED_OreoLED)
#else // All other px4 boards use standard devices
#define BUILD_DEFAULT_LED_TYPE (Notify_LED_Board | Notify_LED_ToshibaLED_I2C_Internal | Notify_LED_ToshibaLED_I2C_External)
#endif
// ChibiOS and VRBrain boards
#elif CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS || \
CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN
#define BUILD_DEFAULT_LED_TYPE (Notify_LED_Board | Notify_LED_ToshibaLED_I2C_Internal | Notify_LED_ToshibaLED_I2C_External)
// Linux boards
#elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO
#define BUILD_DEFAULT_LED_TYPE (Notify_LED_Board | Notify_LED_ToshibaLED_I2C_Internal | Notify_LED_ToshibaLED_I2C_External |\
Notify_LED_PCA9685LED_I2C_External)
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO2
#define BUILD_DEFAULT_LED_TYPE (Notify_LED_Board | Notify_LED_ToshibaLED_I2C_Internal | Notify_LED_ToshibaLED_I2C_External)
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_EDGE
#define BUILD_DEFAULT_LED_TYPE (Notify_LED_Board | Notify_LED_ToshibaLED_I2C_Internal | Notify_LED_ToshibaLED_I2C_External |\
Notify_LED_UAVCAN)
#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 || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DISCO
#define BUILD_DEFAULT_LED_TYPE (Notify_LED_Board)
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_RST_ZYNQ
#define BUILD_DEFAULT_LED_TYPE (Notify_LED_ToshibaLED_I2C_External)
#else // other linux
#define BUILD_DEFAULT_LED_TYPE (Notify_LED_Board | Notify_LED_ToshibaLED_I2C_Internal | Notify_LED_ToshibaLED_I2C_External)
#endif
// F4Light
#elif CONFIG_HAL_BOARD == HAL_BOARD_F4LIGHT
#define BUILD_DEFAULT_LED_TYPE (Notify_LED_Board | Notify_LED_ToshibaLED_I2C_External)
// All other builds
#else
#define BUILD_DEFAULT_LED_TYPE (Notify_LED_Board | Notify_LED_ToshibaLED_I2C_Internal | Notify_LED_ToshibaLED_I2C_External)
#endif // board selection
#endif // BUILD_DEFAULT_LED_TYPE
// table of user settable parameters // table of user settable parameters
const AP_Param::GroupInfo AP_Notify::var_info[] = { const AP_Param::GroupInfo AP_Notify::var_info[] = {
@ -94,13 +148,20 @@ const AP_Param::GroupInfo AP_Notify::var_info[] = {
AP_GROUPINFO("BUZZ_PIN", 5, AP_Notify, _buzzer_pin, 0), AP_GROUPINFO("BUZZ_PIN", 5, AP_Notify, _buzzer_pin, 0),
#endif #endif
// @Param: LED_TYPES
// @DisplayName: LED Driver Types
// @Description: Controls what types of LEDs will be enabled
// @Bitmask: 0:Build in LED, 1:Internal ToshibaLED, 2:External ToshibaLED, 3:External PCA9685, 4:Oreo LED, 5:UAVCAN
// @User: Advanced
AP_GROUPINFO("LED_TYPES", 6, AP_Notify, _led_type, BUILD_DEFAULT_LED_TYPE),
AP_GROUPEND AP_GROUPEND
}; };
// Default constructor // Default constructor
AP_Notify::AP_Notify() AP_Notify::AP_Notify()
{ {
AP_Param::setup_object_defaults(this, var_info); AP_Param::setup_object_defaults(this, var_info);
if (_instance != nullptr) { if (_instance != nullptr) {
AP_HAL::panic("AP_Notify must be singleton"); AP_HAL::panic("AP_Notify must be singleton");
} }
@ -135,136 +196,105 @@ void AP_Notify::add_backends(void)
return; return;
} }
// Notify devices for PX4 boards for (uint32_t i = 1; i < 32; i = i << 1) {
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4 switch(_led_type & i) {
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_PX4_V3 // Has enough memory for Oreo LEDs case Notify_LED_None:
ADD_BACKEND(new AP_BoardLED()); case Notify_LED_MAX:
ADD_BACKEND(new ToshibaLED_I2C(TOSHIBA_LED_I2C_BUS_EXTERNAL)); break;
ADD_BACKEND(new ToshibaLED_I2C(TOSHIBA_LED_I2C_BUS_INTERNAL)); case Notify_LED_Board:
ADD_BACKEND(new ToneAlarm_PX4()); // select the most appropriate built in LED driver type
ADD_BACKEND(new Display()); #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());
#endif
#endif // CONFIG_HAL_BOARD == HAL_BOARD_LINUX
// Oreo LED enable/disable by NTF_OREO_THEME parameter #if defined(HAL_HAVE_PIXRACER_LED)
if (_oreo_theme) { ADD_BACKEND(new PixRacerLED());
ADD_BACKEND(new OreoLED_PX4(_oreo_theme)); #elif (defined(HAL_GPIO_A_LED_PIN) && defined(HAL_GPIO_B_LED_PIN) && defined(HAL_GPIO_C_LED_PIN))
#if CONFIG_HAL_BOARD != HAL_BOARD_VRBRAIN || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_VRBRAIN_V45
ADD_BACKEND(new AP_BoardLED());
#else
ADD_BACKEND(new VRBoard_LED());
#endif // CONFIG_HAL_BOARD != HAL_BOARD_VRBRAIN || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_VRBRAIN_V45
#elif (defined(HAL_GPIO_A_LED_PIN) && defined(HAL_GPIO_B_LED_PIN))
ADD_BACKEND(new AP_BoardLED2());
#endif
break;
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;
case Notify_LED_PCA9685LED_I2C_External:
ADD_BACKEND(new PCA9685LED_I2C());
break;
case Notify_LED_OreoLED:
// OreoLED's are PX4-v3 build only
#if (CONFIG_HAL_BOARD == HAL_BOARD_PX4) && (CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_PX4_V3)
if (_oreo_theme) {
ADD_BACKEND(new OreoLED_PX4(_oreo_theme));
}
#endif // (CONFIG_HAL_BOARD == HAL_BOARD_PX4) && (CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_PX4_V3)
break;
case Notify_LED_UAVCAN:
#if HAL_WITH_UAVCAN
ADD_BACKEND(new UAVCAN_RGB_LED(0));
#endif // HAL_WITH_UAVCAN
break;
}
} }
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_PX4_V4 // Has its own LED board
ADD_BACKEND(new PixRacerLED()); // Always try and add a display backend
ADD_BACKEND(new ToshibaLED_I2C(TOSHIBA_LED_I2C_BUS_EXTERNAL));
ADD_BACKEND(new ToshibaLED_I2C(TOSHIBA_LED_I2C_BUS_INTERNAL));
ADD_BACKEND(new ToneAlarm_PX4());
ADD_BACKEND(new Display()); ADD_BACKEND(new Display());
#else // All other px4 boards use standard devices. // Add noise making devices
ADD_BACKEND(new AP_BoardLED()); #if CONFIG_HAL_BOARD == HAL_BOARD_PX4 || \
ADD_BACKEND(new ToshibaLED_I2C(TOSHIBA_LED_I2C_BUS_EXTERNAL)); CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN
ADD_BACKEND(new ToshibaLED_I2C(TOSHIBA_LED_I2C_BUS_INTERNAL));
ADD_BACKEND(new ToneAlarm_PX4()); ADD_BACKEND(new ToneAlarm_PX4());
ADD_BACKEND(new Display());
#endif
// Notify devices for ChibiOS boards // ChibiOS noise makers
#elif CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS #elif CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
# ifdef 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))
ADD_BACKEND(new AP_BoardLED());
#else
ADD_BACKEND(new AP_BoardLED2());
# endif
#ifdef HAL_BUZZER_PIN #ifdef HAL_BUZZER_PIN
ADD_BACKEND(new Buzzer()); ADD_BACKEND(new Buzzer());
#endif #endif
#ifdef HAL_PWM_ALARM #ifdef HAL_PWM_ALARM
ADD_BACKEND(new ToneAlarm_ChibiOS()); ADD_BACKEND(new ToneAlarm_ChibiOS());
#endif #endif
ADD_BACKEND(new ToshibaLED_I2C(TOSHIBA_LED_I2C_BUS_EXTERNAL));
ADD_BACKEND(new ToshibaLED_I2C(TOSHIBA_LED_I2C_BUS_INTERNAL));
ADD_BACKEND(new Display());
// Notify devices for VRBRAIN boards // Linux noise makers
#elif CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_VRBRAIN_V45 // Uses px4 LED board
ADD_BACKEND(new AP_BoardLED());
ADD_BACKEND(new ToshibaLED_I2C(TOSHIBA_LED_I2C_BUS_EXTERNAL));
ADD_BACKEND(new ToshibaLED_I2C(TOSHIBA_LED_I2C_BUS_INTERNAL));
ADD_BACKEND(new ToneAlarm_PX4());
ADD_BACKEND(new ExternalLED());
#else
ADD_BACKEND(new VRBoard_LED());
ADD_BACKEND(new ToshibaLED_I2C(TOSHIBA_LED_I2C_BUS_EXTERNAL));
ADD_BACKEND(new ToshibaLED_I2C(TOSHIBA_LED_I2C_BUS_INTERNAL));
ADD_BACKEND(new ToneAlarm_PX4());
ADD_BACKEND(new ExternalLED());
#endif
// Notify devices for linux boards
#elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX #elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO #if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO || \
ADD_BACKEND(new AP_BoardLED()); CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO2 || \
ADD_BACKEND(new NavioLED_I2C()); CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_EDGE || \
ADD_BACKEND(new ToshibaLED_I2C(TOSHIBA_LED_I2C_BUS_EXTERNAL)); CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBRAIN2 || \
ADD_BACKEND(new ToshibaLED_I2C(TOSHIBA_LED_I2C_BUS_INTERNAL)); CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXFMINI || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_RST_ZYNQ || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BLUE
// No noise makers, keep this though to ensure that the final else is safe
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO2 #elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI || \
ADD_BACKEND(new Led_Sysfs("rgb_led0", "rgb_led2", "rgb_led1")); CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_POCKET
ADD_BACKEND(new ToshibaLED_I2C(TOSHIBA_LED_I2C_BUS_EXTERNAL));
ADD_BACKEND(new ToshibaLED_I2C(TOSHIBA_LED_I2C_BUS_INTERNAL));
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_EDGE
ADD_BACKEND(new RCOutputRGBLedInverted(12, 13, 14));
ADD_BACKEND(new ToshibaLED_I2C(TOSHIBA_LED_I2C_BUS_EXTERNAL));
ADD_BACKEND(new ToshibaLED_I2C(TOSHIBA_LED_I2C_BUS_INTERNAL));
ADD_BACKEND(new UAVCAN_RGB_LED(0));
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI
ADD_BACKEND(new AP_BoardLED());
ADD_BACKEND(new Buzzer()); ADD_BACKEND(new Buzzer());
ADD_BACKEND(new Display());
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BLUE
ADD_BACKEND(new AP_BoardLED());
ADD_BACKEND(new Display());
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_POCKET
ADD_BACKEND(new AP_BoardLED());
ADD_BACKEND(new Buzzer());
ADD_BACKEND(new Display());
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBRAIN2 || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXFMINI
ADD_BACKEND(new AP_BoardLED());
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BH
ADD_BACKEND(new AP_BoardLED());
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());
ADD_BACKEND(new ToneAlarm_Linux());
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_RST_ZYNQ
ADD_BACKEND(new ToshibaLED_I2C(TOSHIBA_LED_I2C_BUS_EXTERNAL));
#else // other linux #else // other linux
ADD_BACKEND(new AP_BoardLED());
ADD_BACKEND(new ToshibaLED_I2C(TOSHIBA_LED_I2C_BUS_EXTERNAL));
ADD_BACKEND(new ToshibaLED_I2C(TOSHIBA_LED_I2C_BUS_INTERNAL));
ADD_BACKEND(new ToneAlarm_Linux()); ADD_BACKEND(new ToneAlarm_Linux());
#endif #endif
// F4Light noise makers
#elif CONFIG_HAL_BOARD == HAL_BOARD_F4LIGHT #elif CONFIG_HAL_BOARD == HAL_BOARD_F4LIGHT
ADD_BACKEND(new ToshibaLED_I2C(TOSHIBA_LED_I2C_BUS_EXTERNAL));
ADD_BACKEND(new Display());
ADD_BACKEND(new Buzzer()); ADD_BACKEND(new Buzzer());
ADD_BACKEND(new AP_BoardLED2()); // needs AP_BoardLED2 in master #endif // Noise makers
#else
ADD_BACKEND(new AP_BoardLED());
ADD_BACKEND(new ToshibaLED_I2C(TOSHIBA_LED_I2C_BUS_EXTERNAL));
ADD_BACKEND(new ToshibaLED_I2C(TOSHIBA_LED_I2C_BUS_INTERNAL));
ADD_BACKEND(new Display());
#endif
} }
// initialisation // initialisation

View File

@ -58,6 +58,17 @@ public:
OreoLED_Automobile = 2, // Automobile themed lighting (white front, red back) OreoLED_Automobile = 2, // Automobile themed lighting (white front, red back)
}; };
enum Notify_LED_Type {
Notify_LED_None = 0, // not enabled
Notify_LED_Board = (1 << 0), // Built in board LED's
Notify_LED_ToshibaLED_I2C_Internal = (1 << 1), // Internal ToshibaLED_I2C
Notify_LED_ToshibaLED_I2C_External = (1 << 2), // External ToshibaLED_I2C
Notify_LED_PCA9685LED_I2C_External = (1 << 3), // External PCA9685_I2C
Notify_LED_OreoLED = (1 << 4), // Oreo
Notify_LED_UAVCAN = (1 << 5), // UAVCAN RGB LED
Notify_LED_MAX
};
/// notify_flags_type - bitmask of notification flags /// notify_flags_type - bitmask of notification flags
struct notify_flags_and_values_type { struct notify_flags_and_values_type {
uint32_t initialising : 1; // 1 if initialising and copter should not be moved uint32_t initialising : 1; // 1 if initialising and copter should not be moved
@ -159,6 +170,7 @@ private:
AP_Int8 _display_type; AP_Int8 _display_type;
AP_Int8 _oreo_theme; AP_Int8 _oreo_theme;
AP_Int8 _buzzer_pin; AP_Int8 _buzzer_pin;
AP_Int32 _led_type;
char _send_text[NOTIFY_TEXT_BUFFER_SIZE]; char _send_text[NOTIFY_TEXT_BUFFER_SIZE];
uint32_t _send_text_updated_millis; // last time text changed uint32_t _send_text_updated_millis; // last time text changed

View File

@ -1,5 +1,5 @@
/* /*
NavioLED I2C driver PCA9685LED I2C driver
*/ */
/* /*
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
@ -15,7 +15,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "NavioLED_I2C.h" #include "PCA9685LED_I2C.h"
#include <AP_HAL/AP_HAL.h> #include <AP_HAL/AP_HAL.h>
@ -29,12 +29,12 @@
extern const AP_HAL::HAL& hal; extern const AP_HAL::HAL& hal;
NavioLED_I2C::NavioLED_I2C() : PCA9685LED_I2C::PCA9685LED_I2C() :
RGBLed(NAVIO_LED_OFF, NAVIO_LED_BRIGHT, NAVIO_LED_MEDIUM, NAVIO_LED_DIM) RGBLed(NAVIO_LED_OFF, NAVIO_LED_BRIGHT, NAVIO_LED_MEDIUM, NAVIO_LED_DIM)
{ {
} }
bool NavioLED_I2C::hw_init() bool PCA9685LED_I2C::hw_init()
{ {
_dev = hal.i2c_mgr->get_device(1, PCA9685_ADDRESS); _dev = hal.i2c_mgr->get_device(1, PCA9685_ADDRESS);
@ -42,13 +42,13 @@ bool NavioLED_I2C::hw_init()
return false; return false;
} }
_dev->register_periodic_callback(20000, FUNCTOR_BIND_MEMBER(&NavioLED_I2C::_timer, void)); _dev->register_periodic_callback(20000, FUNCTOR_BIND_MEMBER(&PCA9685LED_I2C::_timer, void));
return true; return true;
} }
// set_rgb - set color as a combination of red, green and blue values // set_rgb - set color as a combination of red, green and blue values
bool NavioLED_I2C::hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue) bool PCA9685LED_I2C::hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue)
{ {
rgb.r = red; rgb.r = red;
rgb.g = green; rgb.g = green;
@ -57,7 +57,7 @@ bool NavioLED_I2C::hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue)
return true; return true;
} }
void NavioLED_I2C::_timer(void) void PCA9685LED_I2C::_timer(void)
{ {
if (!_need_update) { if (!_need_update) {
return; return;

View File

@ -1,5 +1,5 @@
/* /*
NavioLED I2C driver PCA9685LED I2C driver
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -19,10 +19,10 @@
#include <AP_HAL/I2CDevice.h> #include <AP_HAL/I2CDevice.h>
#include "RGBLed.h" #include "RGBLed.h"
class NavioLED_I2C : public RGBLed class PCA9685LED_I2C : public RGBLed
{ {
public: public:
NavioLED_I2C(void); PCA9685LED_I2C(void);
protected: protected:
bool hw_init(void) override; bool hw_init(void) override;
bool hw_set_rgb(uint8_t r, uint8_t g, uint8_t b) override; bool hw_set_rgb(uint8_t r, uint8_t g, uint8_t b) override;