From fc6351b92941247d2b3be91582d3c8a94538b9be Mon Sep 17 00:00:00 2001 From: Alexey Bulatov Date: Thu, 12 Nov 2015 19:58:48 +0300 Subject: [PATCH] AP_Notify: added Navio2LED driver --- libraries/AP_Notify/AP_Notify.cpp | 1 + libraries/AP_Notify/Navio2LED.cpp | 73 +++++++++++++++++++++++++++++++ libraries/AP_Notify/Navio2LED.h | 32 ++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 libraries/AP_Notify/Navio2LED.cpp create mode 100644 libraries/AP_Notify/Navio2LED.h diff --git a/libraries/AP_Notify/AP_Notify.cpp b/libraries/AP_Notify/AP_Notify.cpp index 0bd8ffd4c8..3eebd7949c 100644 --- a/libraries/AP_Notify/AP_Notify.cpp +++ b/libraries/AP_Notify/AP_Notify.cpp @@ -29,6 +29,7 @@ #include "ToshibaLED_I2C.h" #include "ToshibaLED_PX4.h" #include "VRBoard_LED.h" +#include "Navio2LED.h" // table of user settable parameters const AP_Param::GroupInfo AP_Notify::var_info[] = { diff --git a/libraries/AP_Notify/Navio2LED.cpp b/libraries/AP_Notify/Navio2LED.cpp new file mode 100644 index 0000000000..45e9d6a970 --- /dev/null +++ b/libraries/AP_Notify/Navio2LED.cpp @@ -0,0 +1,73 @@ +/* + Navio2LED 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 + 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 . +*/ + +#include "Navio2LED.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 GPIO_A_LED_PIN 27 +# define GPIO_B_LED_PIN 6 +# define GPIO_C_LED_PIN 4 +# define GPIO_LED_ON 0 +# define GPIO_LED_OFF 1 + +extern const AP_HAL::HAL& hal; + +Navio2LED::Navio2LED(): + RGBLed(NAVIO_LED_OFF, NAVIO_LED_BRIGHT, NAVIO_LED_MEDIUM, NAVIO_LED_DIM) +{ + +} + +bool Navio2LED::hw_init(void) +{ + // setup the main LEDs as outputs + hal.gpio->pinMode(GPIO_A_LED_PIN, HAL_GPIO_OUTPUT); + hal.gpio->pinMode(GPIO_B_LED_PIN, HAL_GPIO_OUTPUT); + hal.gpio->pinMode(GPIO_C_LED_PIN, HAL_GPIO_OUTPUT); + + // turn all lights off + hal.gpio->write(GPIO_A_LED_PIN, GPIO_LED_OFF); + hal.gpio->write(GPIO_B_LED_PIN, GPIO_LED_OFF); + hal.gpio->write(GPIO_C_LED_PIN, GPIO_LED_OFF); + + return true; +} + +// set_rgb - set color as a combination of red, green and blue values +bool Navio2LED::hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue) +{ + if (red == NAVIO_LED_OFF) { + hal.gpio->write(GPIO_C_LED_PIN, GPIO_LED_OFF); + } else { + hal.gpio->write(GPIO_C_LED_PIN, GPIO_LED_ON); + } + if (green == NAVIO_LED_OFF) { + hal.gpio->write(GPIO_A_LED_PIN, GPIO_LED_OFF); + } else { + hal.gpio->write(GPIO_A_LED_PIN, GPIO_LED_ON); + } + if (blue == NAVIO_LED_OFF) { + hal.gpio->write(GPIO_B_LED_PIN, GPIO_LED_OFF); + } else { + hal.gpio->write(GPIO_B_LED_PIN, GPIO_LED_ON); + } + + return true; +} diff --git a/libraries/AP_Notify/Navio2LED.h b/libraries/AP_Notify/Navio2LED.h new file mode 100644 index 0000000000..05081549d4 --- /dev/null +++ b/libraries/AP_Notify/Navio2LED.h @@ -0,0 +1,32 @@ +/* + * AP_Notify Library. + * based upon a prototype library by David "Buzz" Bussenschutt. + */ + +/* + 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 . + */ + +#ifndef __NAVIO2_LED_H__ +#define __NAVIO2_LED_H__ + +#include "RGBLed.h" + +class Navio2LED: public RGBLed { +public: + Navio2LED(); + + bool hw_init(void) override; + bool hw_set_rgb(uint8_t r, uint8_t g, uint8_t b) override; +}; + +#endif