BlueSCSI_blink.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * ZuluSCSI™ - Copyright (c) 2025 Rabbit Hole Computing™
  3. *
  4. * ZuluSCSI™ firmware is licensed under the GPL version 3 or any later version.
  5. *
  6. * https://www.gnu.org/licenses/gpl-3.0.html
  7. * ----
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  20. **/
  21. /************************************/
  22. /* Status reporting by blinking led */
  23. /************************************/
  24. #include <BlueSCSI_platform.h>
  25. #include "BlueSCSI_blink.h"
  26. static uint32_t blink_count = 0;
  27. static uint32_t blink_start = 0;
  28. static uint32_t blink_delay = 0;
  29. static uint32_t blink_end_delay= 0;
  30. extern "C" void s2s_ledOn()
  31. {
  32. LED_ON();
  33. }
  34. extern "C" void s2s_ledOff()
  35. {
  36. LED_OFF();
  37. }
  38. bool blink_poll()
  39. {
  40. bool is_blinking = true;
  41. if (blink_count == 0)
  42. {
  43. is_blinking = false;
  44. }
  45. else if (blink_count == 1 && ((uint32_t)(millis() - blink_start)) > blink_end_delay )
  46. {
  47. LED_OFF_OVERRIDE();
  48. blink_count = 0;
  49. is_blinking = false;
  50. }
  51. else if (blink_count > 1 && ((uint32_t)(millis() - blink_start)) > blink_delay)
  52. {
  53. if (1 & blink_count)
  54. LED_ON_OVERRIDE();
  55. else
  56. LED_OFF_OVERRIDE();
  57. blink_count--;
  58. blink_start = millis();
  59. }
  60. if (!is_blinking)
  61. platform_set_blink_status(false);
  62. return is_blinking;
  63. }
  64. void blink_cancel()
  65. {
  66. blink_count = 0;
  67. platform_set_blink_status(false);
  68. }
  69. void blinkStatus(uint32_t times, uint32_t delay, uint32_t end_delay)
  70. {
  71. if (!blink_poll() && blink_count == 0)
  72. {
  73. blink_start = millis();
  74. blink_count = 2 * times + 1;
  75. blink_delay = delay / 2;
  76. blink_end_delay = end_delay;
  77. platform_set_blink_status(true);
  78. LED_OFF_OVERRIDE();
  79. }
  80. }