ToshibaLED_test.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include <AP_HAL/AP_HAL.h>
  2. #include <AP_Notify/AP_Notify.h>
  3. #include <AP_Notify/ToshibaLED_I2C.h>
  4. void setup();
  5. void loop();
  6. void full_spectrum();
  7. void blink();
  8. const AP_HAL::HAL& hal = AP_HAL::get_HAL();
  9. AP_Notify notify;
  10. static ToshibaLED_I2C toshiba_led(1);
  11. void setup(void)
  12. {
  13. // display welcome message
  14. hal.console->printf("Toshiba LED test ver 0.1\n");
  15. // initialise LED
  16. if (toshiba_led.init()) {
  17. hal.console->printf("Failed to initialise Toshiba LED\n");
  18. }
  19. toshiba_led.pNotify = &notify;
  20. // turn on initialising notification
  21. AP_Notify::flags.initialising = false;
  22. AP_Notify::flags.save_trim = true;
  23. AP_Notify::flags.gps_status = 1;
  24. AP_Notify::flags.armed = 1;
  25. AP_Notify::flags.pre_arm_check = 1;
  26. }
  27. void loop(void)
  28. {
  29. // blink test
  30. //hal.console->printf("Blink test\n");
  31. //blink();
  32. /*
  33. // full spectrum test
  34. hal.console->printf("Spectrum test\n");
  35. full_spectrum();
  36. */
  37. // update the toshiba led
  38. toshiba_led.update();
  39. // wait 1/50th of a second
  40. hal.scheduler->delay(20);
  41. }
  42. // full_spectrum - runs through the full spectrum of colours the led can display
  43. void full_spectrum()
  44. {
  45. // go through the full range of colours but only up to the dim light level
  46. for (uint8_t red = 0; red <= 0x05; red++) {
  47. for (uint8_t green = 0; green <= 0x05; green++) {
  48. for (uint8_t blue = 0; blue <= 0x05; blue++) {
  49. toshiba_led.set_rgb(red, green, blue);
  50. hal.scheduler->delay(5);
  51. }
  52. }
  53. }
  54. }
  55. #define LED_DIM 0x11
  56. // blink - blink the led at 10hz for 10 seconds
  57. void blink()
  58. {
  59. // set colour to red
  60. toshiba_led.set_rgb(LED_DIM, 0, 0);
  61. // full spectrum test
  62. for (uint8_t c=0; c<=2; c++ ) {
  63. if (c == 0) {
  64. toshiba_led.set_rgb(LED_DIM, 0, 0); // red
  65. }else if (c==1) {
  66. toshiba_led.set_rgb(0, LED_DIM, 0); // green
  67. }else{
  68. toshiba_led.set_rgb(0, 0, LED_DIM); // blue
  69. }
  70. }
  71. }
  72. AP_HAL_MAIN();