LedInterface.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include "LedInterface.h"
  2. LedInterface::LedInterface() {
  3. }
  4. void LedInterface::RunSetup() {
  5. //Serial.println("Setting neopixel to black...");
  6. strip.setBrightness(0);
  7. strip.begin();
  8. strip.setPixelColor(0, strip.Color(0, 0, 0));
  9. strip.show();
  10. delay(100);
  11. strip.setBrightness(50);
  12. strip.setPixelColor(0, strip.Color(0, 0, 0));
  13. strip.show();
  14. this->initTime = millis();
  15. }
  16. void LedInterface::main(uint32_t currentTime) {
  17. if ((!settings_obj.loadSetting<bool>("EnableLED")) ||
  18. (this->current_mode == MODE_OFF)) {
  19. this->ledOff();
  20. return;
  21. }
  22. else if (this->current_mode == MODE_RAINBOW) {
  23. this->rainbow();
  24. }
  25. else if (this->current_mode == MODE_ATTACK) {
  26. this->attackLed();
  27. }
  28. else if (this->current_mode == MODE_SNIFF) {
  29. this->sniffLed();
  30. }
  31. else if (this->current_mode == MODE_CUSTOM) {
  32. return;
  33. }
  34. else {
  35. this->ledOff();
  36. }
  37. };
  38. void LedInterface::setMode(uint8_t new_mode) {
  39. this->current_mode = new_mode;
  40. }
  41. uint8_t LedInterface::getMode() {
  42. return this->current_mode;
  43. }
  44. void LedInterface::setColor(int r, int g, int b) {
  45. strip.setPixelColor(0, strip.Color(r, g, b));
  46. strip.show();
  47. }
  48. void LedInterface::sniffLed() {
  49. this->setColor(0, 0, 255);
  50. }
  51. void LedInterface::attackLed() {
  52. this->setColor(255, 0, 0);
  53. }
  54. void LedInterface::ledOff() {
  55. this->setColor(0, 0, 0);
  56. }
  57. void LedInterface::rainbow() {
  58. strip.setPixelColor(0, this->Wheel((0 * 256 / 100 + this->wheel_pos) % 256));
  59. strip.show();
  60. this->current_fade_itter++;
  61. this->wheel_pos = this->wheel_pos - this->wheel_speed;
  62. if (this->wheel_pos < 0)
  63. this->wheel_pos = 255;
  64. }
  65. uint32_t LedInterface::Wheel(byte WheelPos) {
  66. WheelPos = 255 - WheelPos;
  67. if(WheelPos < 85) {
  68. return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  69. }
  70. if(WheelPos < 170) {
  71. WheelPos -= 85;
  72. return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  73. }
  74. WheelPos -= 170;
  75. return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  76. }