VRBoard_LED.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. ToshibaLED driver
  3. */
  4. /*
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "VRBoard_LED.h"
  17. #include <AP_HAL/AP_HAL.h>
  18. #if (defined(HAL_GPIO_A_LED_PIN) && defined(HAL_GPIO_B_LED_PIN) && \
  19. defined(HAL_GPIO_C_LED_PIN))
  20. #define VRBRAIN_LED_BRIGHT 1 // full brightness
  21. #define VRBRAIN_LED_MEDIUM 1 // medium brightness
  22. #define VRBRAIN_LED_DIM 1 // dim
  23. #define VRBRAIN_LED_OFF 0 // off
  24. extern const AP_HAL::HAL& hal;
  25. VRBoard_LED::VRBoard_LED():
  26. RGBLed(VRBRAIN_LED_OFF, VRBRAIN_LED_BRIGHT, VRBRAIN_LED_MEDIUM, VRBRAIN_LED_DIM)
  27. {
  28. }
  29. bool VRBoard_LED::hw_init(void){
  30. // setup the main LEDs as outputs
  31. hal.gpio->pinMode(HAL_GPIO_A_LED_PIN, HAL_GPIO_OUTPUT);
  32. hal.gpio->pinMode(HAL_GPIO_B_LED_PIN, HAL_GPIO_OUTPUT);
  33. hal.gpio->pinMode(HAL_GPIO_C_LED_PIN, HAL_GPIO_OUTPUT);
  34. // turn all lights off
  35. hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_OFF);
  36. hal.gpio->write(HAL_GPIO_B_LED_PIN, HAL_GPIO_LED_OFF);
  37. hal.gpio->write(HAL_GPIO_C_LED_PIN, HAL_GPIO_LED_OFF);
  38. return true;
  39. }
  40. bool VRBoard_LED::hw_set_rgb(uint8_t r, uint8_t g, uint8_t b){
  41. if(r > 0){
  42. hal.gpio->write(HAL_GPIO_C_LED_PIN, HAL_GPIO_LED_ON);
  43. } else {
  44. hal.gpio->write(HAL_GPIO_C_LED_PIN, HAL_GPIO_LED_OFF);
  45. }
  46. if (g > 0) {
  47. hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_ON);
  48. } else {
  49. hal.gpio->write(HAL_GPIO_A_LED_PIN, HAL_GPIO_LED_OFF);
  50. }
  51. if (b > 0) {
  52. hal.gpio->write(HAL_GPIO_B_LED_PIN, HAL_GPIO_LED_ON);
  53. } else {
  54. hal.gpio->write(HAL_GPIO_B_LED_PIN, HAL_GPIO_LED_OFF);
  55. }
  56. return true;
  57. }
  58. #endif