LedInterface.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 {
  32. this->ledOff();
  33. }
  34. };
  35. void LedInterface::setMode(uint8_t new_mode) {
  36. this->current_mode = new_mode;
  37. }
  38. uint8_t LedInterface::getMode() {
  39. return this->current_mode;
  40. }
  41. void LedInterface::sniffLed() {
  42. strip.setPixelColor(0, strip.Color(0, 0, 255));
  43. strip.show();
  44. }
  45. void LedInterface::attackLed() {
  46. strip.setPixelColor(0, strip.Color(255, 0, 0));
  47. strip.show();
  48. }
  49. void LedInterface::ledOff() {
  50. strip.setPixelColor(0, strip.Color(0, 0, 0));
  51. strip.show();
  52. }
  53. void LedInterface::rainbow() {
  54. strip.setPixelColor(0, this->Wheel((0 * 256 / 100 + this->wheel_pos) % 256));
  55. strip.show();
  56. this->current_fade_itter++;
  57. this->wheel_pos = this->wheel_pos - this->wheel_speed;
  58. if (this->wheel_pos < 0)
  59. this->wheel_pos = 255;
  60. }
  61. uint32_t LedInterface::Wheel(byte WheelPos) {
  62. WheelPos = 255 - WheelPos;
  63. if(WheelPos < 85) {
  64. return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  65. }
  66. if(WheelPos < 170) {
  67. WheelPos -= 85;
  68. return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  69. }
  70. WheelPos -= 170;
  71. return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  72. }