mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-03 06:28:27 -04:00
AP_Notify: made DiscreteRGBLed more generic
- made pins and polarity configurable - got rid of all Navio specific code
This commit is contained in:
parent
ef4e3aa333
commit
5b3627f83e
@ -80,7 +80,7 @@ struct AP_Notify::notify_events_type AP_Notify::events;
|
||||
ToshibaLED_I2C toshibaled;
|
||||
NotifyDevice *AP_Notify::_devices[] = {&navioled, &toshibaled};
|
||||
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO2
|
||||
DiscreteRGBLed navioled;
|
||||
DiscreteRGBLed navioled(4, 27, 6, false);
|
||||
ToshibaLED_I2C toshibaled;
|
||||
NotifyDevice *AP_Notify::_devices[] = {&navioled, &toshibaled};
|
||||
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI
|
||||
|
@ -1,6 +1,3 @@
|
||||
/*
|
||||
DiscreteRGBLed driver
|
||||
*/
|
||||
/*
|
||||
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
|
||||
@ -16,49 +13,43 @@
|
||||
|
||||
#include "DiscreteRGBLed.h"
|
||||
|
||||
#define NAVIO_LED_BRIGHT 1 // full brightness
|
||||
#define NAVIO_LED_MEDIUM 1 // medium brightness
|
||||
#define NAVIO_LED_DIM 1 // dim brightness
|
||||
#define NAVIO_LED_OFF 0 // off
|
||||
|
||||
# define GREEN_PIN 27
|
||||
# define BLUE_PIN 6
|
||||
# define RED_PIN 4
|
||||
|
||||
extern const AP_HAL::HAL& hal;
|
||||
|
||||
DiscreteRGBLed::DiscreteRGBLed()
|
||||
: RGBLed(NAVIO_LED_OFF, NAVIO_LED_BRIGHT, NAVIO_LED_MEDIUM, NAVIO_LED_DIM)
|
||||
DiscreteRGBLed::DiscreteRGBLed(uint16_t red, uint16_t green, uint16_t blue, bool normal_polarity)
|
||||
: RGBLed(normal_polarity ? 0 : 1,
|
||||
normal_polarity ? 1 : 0,
|
||||
normal_polarity ? 1 : 0,
|
||||
normal_polarity ? 1 : 0),
|
||||
red_pin_number(red),
|
||||
green_pin_number(green),
|
||||
blue_pin_number(blue)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#include <unistd.h>
|
||||
bool DiscreteRGBLed::hw_init(void)
|
||||
{
|
||||
red_pin = hal.gpio->channel(RED_PIN);
|
||||
green_pin = hal.gpio->channel(GREEN_PIN);
|
||||
blue_pin = hal.gpio->channel(BLUE_PIN);
|
||||
red_pin = hal.gpio->channel(red_pin_number);
|
||||
green_pin = hal.gpio->channel(green_pin_number);
|
||||
blue_pin = hal.gpio->channel(blue_pin_number);
|
||||
|
||||
red_pin->mode(HAL_GPIO_OUTPUT);
|
||||
green_pin->mode(HAL_GPIO_OUTPUT);
|
||||
blue_pin->mode(HAL_GPIO_OUTPUT);
|
||||
|
||||
|
||||
red_pin->write(0);
|
||||
green_pin->write(0);
|
||||
blue_pin->write(0);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// set_rgb - set color as a combination of red, green and blue values
|
||||
bool DiscreteRGBLed::hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue)
|
||||
{
|
||||
/* We fix the GPIO polarity right here */
|
||||
|
||||
red_pin->write(!red);
|
||||
green_pin->write(!green);
|
||||
blue_pin->write(!blue);
|
||||
red_pin->write(!!red);
|
||||
green_pin->write(!!green);
|
||||
blue_pin->write(!!blue);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -22,12 +22,14 @@
|
||||
|
||||
class DiscreteRGBLed: public RGBLed {
|
||||
public:
|
||||
DiscreteRGBLed();
|
||||
DiscreteRGBLed(uint16_t red, uint16_t green, uint16_t blue, bool polarity);
|
||||
|
||||
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 red, uint8_t green, uint8_t blue) override;
|
||||
private:
|
||||
AP_HAL::DigitalSource *red_pin;
|
||||
AP_HAL::DigitalSource *green_pin;
|
||||
AP_HAL::DigitalSource *blue_pin;
|
||||
|
||||
uint16_t red_pin_number, green_pin_number, blue_pin_number;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user