diff --git a/configs/DSTIKE_D-duino_with_LED_Ring_Shield/A_config.h b/configs/DSTIKE_D-duino_with_LED_Ring_Shield/A_config.h index a19fc72..b6880b2 100644 --- a/configs/DSTIKE_D-duino_with_LED_Ring_Shield/A_config.h +++ b/configs/DSTIKE_D-duino_with_LED_Ring_Shield/A_config.h @@ -32,11 +32,16 @@ // === Settings for RGB LED and Neopixel LED === // #define LED_MODE_BRIGHTNESS 10 // brightness of LED modes -#define LED_DYNAMIC_BRIGHTNESS true // brightness in scan mode depending on packet rate and deauths per second // === Settings for Neopixel LED === // #define LED_NEOPIXEL_NUM 12 #define LED_NEOPIXEL_PIN 15 +#define LED_NEOPIXEL_MODE NEO_GRB + NEO_KHZ800 +// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) +// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) +// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) +// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) +// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) // ===================== DISPLAY CONFIG ==================== // #define USE_DISPLAY true // default display setting diff --git a/configs/DSTIKE_Deauther_Boy/A_config.h b/configs/DSTIKE_Deauther_Boy/A_config.h index 61cb78c..cf06794 100644 --- a/configs/DSTIKE_Deauther_Boy/A_config.h +++ b/configs/DSTIKE_Deauther_Boy/A_config.h @@ -32,11 +32,16 @@ // === Settings for RGB LED and Neopixel LED === // #define LED_MODE_BRIGHTNESS 10 // brightness of LED modes -#define LED_DYNAMIC_BRIGHTNESS false // brightness in scan mode depending on packet rate and deauths per second // === Settings for Neopixel LED === // #define LED_NEOPIXEL_NUM 1 #define LED_NEOPIXEL_PIN 15 +#define LED_NEOPIXEL_MODE NEO_GRB + NEO_KHZ800 +// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) +// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) +// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) +// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) +// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) // ===================== DISPLAY CONFIG ==================== // #define USE_DISPLAY true // default display setting diff --git a/configs/DSTIKE_Deauther_OLED_v1-v1.5/A_config.h b/configs/DSTIKE_Deauther_OLED_v1-v1.5/A_config.h index f598c30..52c1782 100644 --- a/configs/DSTIKE_Deauther_OLED_v1-v1.5/A_config.h +++ b/configs/DSTIKE_Deauther_OLED_v1-v1.5/A_config.h @@ -32,11 +32,16 @@ // === Settings for RGB LED and Neopixel LED === // #define LED_MODE_BRIGHTNESS 10 // brightness of LED modes -#define LED_DYNAMIC_BRIGHTNESS false // brightness in scan mode depending on packet rate and deauths per second // === Settings for Neopixel LED === // #define LED_NEOPIXEL_NUM 1 #define LED_NEOPIXEL_PIN 9 +#define LED_NEOPIXEL_MODE NEO_GRB + NEO_KHZ800 +// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) +// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) +// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) +// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) +// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) // ===================== DISPLAY CONFIG ==================== // #define USE_DISPLAY true // default display setting diff --git a/configs/DSTIKE_Deauther_OLED_v2-v3/A_config.h b/configs/DSTIKE_Deauther_OLED_v2-v3/A_config.h index b633b63..4a11760 100644 --- a/configs/DSTIKE_Deauther_OLED_v2-v3/A_config.h +++ b/configs/DSTIKE_Deauther_OLED_v2-v3/A_config.h @@ -32,11 +32,16 @@ // === Settings for RGB LED and Neopixel LED === // #define LED_MODE_BRIGHTNESS 10 // brightness of LED modes -#define LED_DYNAMIC_BRIGHTNESS false // brightness in scan mode depending on packet rate and deauths per second // === Settings for Neopixel LED === // #define LED_NEOPIXEL_NUM 1 #define LED_NEOPIXEL_PIN 9 +#define LED_NEOPIXEL_MODE NEO_GRB + NEO_KHZ800 +// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) +// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) +// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) +// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) +// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) // ===================== DISPLAY CONFIG ==================== // #define USE_DISPLAY true // default display setting diff --git a/configs/DSTIKE_Deauther_OLED_v3.5_+_Monster/A_config.h b/configs/DSTIKE_Deauther_OLED_v3.5_+_Monster/A_config.h index 3fba1c6..42ac658 100644 --- a/configs/DSTIKE_Deauther_OLED_v3.5_+_Monster/A_config.h +++ b/configs/DSTIKE_Deauther_OLED_v3.5_+_Monster/A_config.h @@ -32,11 +32,16 @@ // === Settings for RGB LED and Neopixel LED === // #define LED_MODE_BRIGHTNESS 10 // brightness of LED modes -#define LED_DYNAMIC_BRIGHTNESS false // brightness in scan mode depending on packet rate and deauths per second // === Settings for Neopixel LED === // #define LED_NEOPIXEL_NUM 1 #define LED_NEOPIXEL_PIN 15 +#define LED_NEOPIXEL_MODE NEO_GRB + NEO_KHZ800 +// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) +// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) +// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) +// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) +// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) // ===================== DISPLAY CONFIG ==================== // #define USE_DISPLAY true // default display setting diff --git a/configs/DSTIKE_Deauther_v3_+_DSTIKE_NodeMCU-07_v2/A_config.h b/configs/DSTIKE_Deauther_v3_+_DSTIKE_NodeMCU-07_v2/A_config.h index 388dc3e..4f0a776 100644 --- a/configs/DSTIKE_Deauther_v3_+_DSTIKE_NodeMCU-07_v2/A_config.h +++ b/configs/DSTIKE_Deauther_v3_+_DSTIKE_NodeMCU-07_v2/A_config.h @@ -32,11 +32,16 @@ // === Settings for RGB LED and Neopixel LED === // #define LED_MODE_BRIGHTNESS 10 // brightness of LED modes -#define LED_DYNAMIC_BRIGHTNESS false // brightness in scan mode depending on packet rate and deauths per second // === Settings for Neopixel LED === // #define LED_NEOPIXEL_NUM 1 #define LED_NEOPIXEL_PIN 15 +#define LED_NEOPIXEL_MODE NEO_GRB + NEO_KHZ800 +// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) +// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) +// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) +// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) +// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) // ===================== DISPLAY CONFIG ==================== // #define USE_DISPLAY false // default display setting diff --git a/configs/DSTIKE_USB_Deauther/A_config.h b/configs/DSTIKE_USB_Deauther/A_config.h index 0249545..ca5575e 100644 --- a/configs/DSTIKE_USB_Deauther/A_config.h +++ b/configs/DSTIKE_USB_Deauther/A_config.h @@ -31,12 +31,17 @@ #define LED_PIN_B 2 // ESP-12 LED // === Settings for RGB LED and Neopixel LED === // -#define LED_MODE_BRIGHTNESS 10 // brightness of LED modes -#define LED_DYNAMIC_BRIGHTNESS false // brightness in scan mode depending on packet rate and deauths per second +#define LED_MODE_BRIGHTNESS 10 // brightness of LED modes // === Settings for Neopixel LED === // #define LED_NEOPIXEL_NUM 1 #define LED_NEOPIXEL_PIN 4 +#define LED_NEOPIXEL_MODE NEO_GRB + NEO_KHZ800 +// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) +// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) +// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) +// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) +// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) // ===================== DISPLAY CONFIG ==================== // #define USE_DISPLAY false // default display setting diff --git a/configs/Default/A_config.h b/configs/Default/A_config.h index eee73d9..d43cf0f 100644 --- a/configs/Default/A_config.h +++ b/configs/Default/A_config.h @@ -32,11 +32,16 @@ // === Settings for RGB LED and Neopixel LED === // #define LED_MODE_BRIGHTNESS 10 // brightness of LED modes -#define LED_DYNAMIC_BRIGHTNESS false // brightness in scan mode depending on packet rate and deauths per second // === Settings for Neopixel LED === // #define LED_NEOPIXEL_NUM 1 #define LED_NEOPIXEL_PIN 15 +#define LED_NEOPIXEL_MODE NEO_GRB + NEO_KHZ800 +// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) +// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) +// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) +// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) +// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) // ===================== DISPLAY CONFIG ==================== // #define USE_DISPLAY false // default display setting diff --git a/esp8266_deauther/A_config.h b/esp8266_deauther/A_config.h index 38daa30..8011ec4 100644 --- a/esp8266_deauther/A_config.h +++ b/esp8266_deauther/A_config.h @@ -16,9 +16,9 @@ Uncomment the type of LED you're using Only one of them can be defined at a time! = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ -#define DIGITAL_LED +//#define DIGITAL_LED // #define RGB_LED -// #define NEOPIXEL_LED + #define NEOPIXEL_LED /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = Adjust following settings for your type of LED @@ -33,11 +33,16 @@ // === Settings for RGB LED and Neopixel LED === // #define LED_MODE_BRIGHTNESS 10 // brightness of LED modes -#define LED_DYNAMIC_BRIGHTNESS false // brightness in scan mode depending on packet rate and deauths per second // === Settings for Neopixel LED === // #define LED_NEOPIXEL_NUM 1 #define LED_NEOPIXEL_PIN 15 +#define LED_NEOPIXEL_MODE NEO_GRB + NEO_KHZ800 +// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) +// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) +// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) +// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) +// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) // ===================== DISPLAY CONFIG ==================== // #define USE_DISPLAY false // default display setting @@ -73,4 +78,4 @@ // #define FLIP_DIPLAY // uncomment that to flip the display vertically // ========================================================= // -#endif // ifndef config_h \ No newline at end of file +#endif // ifndef config_h diff --git a/esp8266_deauther/LEDController.cpp b/esp8266_deauther/LEDController.cpp index d52ca09..b9e8537 100644 --- a/esp8266_deauther/LEDController.cpp +++ b/esp8266_deauther/LEDController.cpp @@ -15,14 +15,14 @@ void LEDController::setup() { #endif // ifdef DIGITAL_LED #ifdef RGB_LED - led = new AnalogRGBLED(LED_PIN_R, LED_PIN_G, LED_PIN_B, LED_MODE_BRIGHTNESS, LED_ANODE); + led = new LEDController::AnalogRGBLED(LED_PIN_R, LED_PIN_G, LED_PIN_B, LED_MODE_BRIGHTNESS, LED_ANODE); led->setup(); return; #endif // ifdef RGB_LED #ifdef NEOPIXEL_LED - led = new NeopixelLED(LED_NEOPIXEL_NUM, LED_NEOPIXEL_PIN, LED_MODE_BRIGHTNESS); + led = new LEDController::NeopixelLED(LED_NEOPIXEL_NUM, LED_NEOPIXEL_PIN, LED_MODE_BRIGHTNESS); led->setup(); return; @@ -100,4 +100,112 @@ void LEDController::tempDisable() { bool LEDController::getTempEnabled() { return tempEnabled; +} + +// ===== DigitalLED ===== // +LEDController::DigitalLED::DigitalLED(uint8_t rPin, uint8_t gPin, uint8_t bPin, bool anode) { + LEDController::DigitalLED::anode = anode; + LEDController::DigitalLED::rPin = rPin; + LEDController::DigitalLED::gPin = gPin; + LEDController::DigitalLED::bPin = bPin; +} + +LEDController::DigitalLED::~DigitalLED() {} + +void LEDController::DigitalLED::setup() { + if (rPin < 255) pinMode(rPin, OUTPUT); + + if (gPin < 255) pinMode(gPin, OUTPUT); + + if (bPin < 255) pinMode(bPin, OUTPUT); +} + +void LEDController::DigitalLED::setColor(uint8_t r, uint8_t g, uint8_t b) { + if (anode) { + if (rPin < 255) digitalWrite(rPin, r > 0); + + if (gPin < 255) digitalWrite(gPin, g > 0); + + if (bPin < 255) digitalWrite(bPin, b > 0); + } else { + if (rPin < 255) digitalWrite(rPin, r == 0); + + if (gPin < 255) digitalWrite(gPin, g == 0); + + if (bPin < 255) digitalWrite(bPin, b == 0); + } +} + +void LEDController::DigitalLED::setBrightness(uint8_t brightness) {} + + +// ===== AnalogRGBLED ===== // +LEDController::AnalogRGBLED::AnalogRGBLED(uint8_t rPin, uint8_t gPin, uint8_t bPin, uint8_t brightness, bool anode) { + LEDController::AnalogRGBLED::anode = anode; + LEDController::AnalogRGBLED::rPin = rPin; + LEDController::AnalogRGBLED::gPin = gPin; + LEDController::AnalogRGBLED::bPin = bPin; + setBrightness(brightness); +} + +LEDController::AnalogRGBLED::~AnalogRGBLED() {} + +void LEDController::AnalogRGBLED::setup() { + analogWriteRange(0xff); + + if (rPin < 255) pinMode(rPin, OUTPUT); + + if (gPin < 255) pinMode(gPin, OUTPUT); + + if (bPin < 255) pinMode(bPin, OUTPUT); +} + +void LEDController::AnalogRGBLED::setColor(uint8_t r, uint8_t g, uint8_t b) { + if ((r > 0) && (brightness < 100)) r = r * brightness / 100; + + if ((g > 0) && (brightness < 100)) g = g * brightness / 100; + + if ((b > 0) && (brightness < 100)) b = b * brightness / 100; + + if (anode) { + r = 255 - r; + g = 255 - g; + b = 255 - b; + } + + analogWrite(rPin, r); + analogWrite(gPin, g); + analogWrite(bPin, b); +} + +void LEDController::AnalogRGBLED::setBrightness(uint8_t brightness) { + if (brightness > 100) brightness = 100; + LEDController::AnalogRGBLED::brightness = brightness; +} + +// ===== NeopixelLED ===== // +LEDController::NeopixelLED::NeopixelLED(int num, uint8_t dataPin, uint8_t brightness) { + strip = new Adafruit_NeoPixel(num, dataPin, LED_NEOPIXEL_MODE); + setBrightness(brightness); +} + +LEDController::NeopixelLED::~NeopixelLED() { + delete strip; +} + +void LEDController::NeopixelLED::setup() { + strip->begin(); + strip->show(); +} + +void LEDController::NeopixelLED::setColor(uint8_t r, uint8_t g, uint8_t b) { + int num = strip->numPixels(); + + for (uint16_t i = 0; i < num; i++) strip->setPixelColor(i, strip->Color(r, g, b)); + strip->show(); +} + +void LEDController::NeopixelLED::setBrightness(uint8_t brightness) { + if (brightness > 100) brightness = 100; + strip->setBrightness(brightness); } \ No newline at end of file diff --git a/esp8266_deauther/LEDController.h b/esp8266_deauther/LEDController.h index 889a783..79d6add 100644 --- a/esp8266_deauther/LEDController.h +++ b/esp8266_deauther/LEDController.h @@ -11,10 +11,7 @@ extern "C" { #include "Attack.h" #include "Scan.h" -#include "StatusLED.h" -#include "DigitalLED.h" -#include "NeopixelLED.h" -#include "AnalogRGBLED.h" +#include extern Settings settings; extern Attack attack; @@ -41,6 +38,65 @@ class LEDController { bool getTempEnabled(); private: + class StatusLED { + public: + virtual ~StatusLED() = default; + + virtual void setup() = 0; + + virtual void setColor(uint8_t r, uint8_t g, uint8_t b) = 0; + virtual void setBrightness(uint8_t brightness) = 0; + }; + + class DigitalLED : public StatusLED { + public: + DigitalLED(uint8_t rPin, uint8_t gPin, uint8_t bPin, bool anode); + ~DigitalLED(); + + void setup(); + void setColor(uint8_t r, uint8_t g, uint8_t b); + void setBrightness(uint8_t brightness); + void setMode(uint8_t mode, bool force); + + private: + bool anode = true; + uint8_t rPin = 255; + uint8_t gPin = 255; + uint8_t bPin = 255; + }; + + class AnalogRGBLED : public StatusLED { + public: + AnalogRGBLED(uint8_t rPin, uint8_t gPin, uint8_t bPin, uint8_t brightness, bool anode); + ~AnalogRGBLED(); + + void setup(); + void setColor(uint8_t r, uint8_t g, uint8_t b); + void setBrightness(uint8_t brightness); + void setMode(uint8_t mode, bool force); + + private: + bool anode = true; + uint8_t rPin = 255; + uint8_t gPin = 255; + uint8_t bPin = 255; + uint8_t brightness = 0; + }; + + class NeopixelLED : public StatusLED { + public: + NeopixelLED(int num, uint8_t dataPin, uint8_t brightness); + ~NeopixelLED(); + + void setup(); + void setColor(uint8_t r, uint8_t g, uint8_t b); + void setBrightness(uint8_t brightness); + void setMode(uint8_t mode, bool force); + + private: + Adafruit_NeoPixel* strip; + }; + bool tempEnabled = true; uint8_t mode = LED_MODE::OFF; StatusLED* led = NULL;