DiscreteRGBLed.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. #include "DiscreteRGBLed.h"
  14. extern const AP_HAL::HAL& hal;
  15. DiscreteRGBLed::DiscreteRGBLed(uint16_t red, uint16_t green, uint16_t blue, bool normal_polarity)
  16. : RGBLed(normal_polarity ? 0 : 1,
  17. normal_polarity ? 1 : 0,
  18. normal_polarity ? 1 : 0,
  19. normal_polarity ? 1 : 0),
  20. red_pin_number(red),
  21. green_pin_number(green),
  22. blue_pin_number(blue)
  23. {
  24. }
  25. bool DiscreteRGBLed::hw_init(void)
  26. {
  27. red_pin = hal.gpio->channel(red_pin_number);
  28. green_pin = hal.gpio->channel(green_pin_number);
  29. blue_pin = hal.gpio->channel(blue_pin_number);
  30. red_pin->mode(HAL_GPIO_OUTPUT);
  31. green_pin->mode(HAL_GPIO_OUTPUT);
  32. blue_pin->mode(HAL_GPIO_OUTPUT);
  33. red_pin->write(0);
  34. green_pin->write(0);
  35. blue_pin->write(0);
  36. return true;
  37. }
  38. // set_rgb - set color as a combination of red, green and blue values
  39. bool DiscreteRGBLed::hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue)
  40. {
  41. red_pin->write(!!red);
  42. green_pin->write(!!green);
  43. blue_pin->write(!!blue);
  44. return true;
  45. }