Updated LED class, config for color modes

- No more led.tempDisable()
- Brightness is fixed and can't be changed
- led.setColor is now private
- setColor with brightness removed
- Removed unused strings from lang

Color modes can be adjusted in A_config now.
Color and Brightness are fixed and can not be changed over CLI anymore.
This commit is contained in:
Stefan Kremser
2019-05-10 13:11:37 +02:00
parent b498f03787
commit 46ffccb6bc
4 changed files with 711 additions and 714 deletions

View File

@@ -179,6 +179,10 @@
// ===== LED ===== // // ===== LED ===== //
#define LED_MY92 #define LED_MY92
#define LED_MODE_OFF 0, 0, 0
#define LED_MODE_SCAN 0, 0, 255
#define LED_MODE_ATTACK 255, 0, 0
#define LED_MODE_IDLE 0, 255, 0
#define LED_MODE_BRIGHTNESS 10 #define LED_MODE_BRIGHTNESS 10
#define LED_MY92_NUM 1 #define LED_MY92_NUM 1
@@ -195,6 +199,10 @@
// ===== LED ===== // // ===== LED ===== //
#define LED_MY92 #define LED_MY92
#define LED_MODE_OFF 0, 0, 0
#define LED_MODE_SCAN 0, 0, 255
#define LED_MODE_ATTACK 255, 0, 0
#define LED_MODE_IDLE 0, 255, 0
#define LED_MODE_BRIGHTNESS 10 #define LED_MODE_BRIGHTNESS 10
#define LED_MY92_NUM 1 #define LED_MY92_NUM 1
@@ -248,6 +256,22 @@
#define LED_ANODE false #define LED_ANODE false
#endif /* ifndef LED_ANODE */ #endif /* ifndef LED_ANODE */
#ifndef LED_MODE_OFF
#define LED_MODE_OFF 0, 0, 0
#endif /* ifndef LED_MODE_OFF */
#ifndef LED_MODE_SCAN
#define LED_MODE_SCAN 0, 0, 255
#endif /* ifndef LED_MODE_SCAN */
#ifndef LED_MODE_ATTACK
#define LED_MODE_ATTACK 255, 0, 0
#endif /* ifndef LED_MODE_ATTACK */
#ifndef LED_MODE_IDLE
#define LED_MODE_IDLE 0, 255, 0
#endif /* ifndef LED_MODE_IDLE */
#ifndef LED_MODE_BRIGHTNESS #ifndef LED_MODE_BRIGHTNESS
#define LED_MODE_BRIGHTNESS 10 #define LED_MODE_BRIGHTNESS 10
#endif /* ifndef LED_MODE_BRIGHTNESS */ #endif /* ifndef LED_MODE_BRIGHTNESS */
@@ -333,7 +357,11 @@
#define LED_NEOPIXEL_NUM 1 #define LED_NEOPIXEL_NUM 1
#define LED_NEOPIXEL_PIN 255 #define LED_NEOPIXEL_PIN 255
#define LED_MODE_BRIGHTNESS 100 #define LED_MODE_OFF 0,0,0
#define LED_MODE_SCAN 0,0,255
#define LED_MODE_ATTACK 255,0,0
#define LED_MODE_IDLE 0,255,0
#define LED_MODE_BRIGHTNESS 10
#define LED_MY92_NUM 1 #define LED_MY92_NUM 1
#define LED_MY92_DATA 4 #define LED_MY92_DATA 4
@@ -370,4 +398,9 @@
*/ */
// ========== ERROR CHECKS ========== //
#if LED_MODE_BRIGHTNESS == 0
#error LED_MODE_BRIGHTNESS must not be zero!
#endif /* if LED_MODE_BRIGHTNESS == 0 */
#endif /* ifndef config_h */ #endif /* ifndef config_h */

View File

@@ -1,25 +1,91 @@
#include "LED.h" #include "LED.h"
// Strings used in printColor and tempDisable // ===== [Includes] ===== //
#include "language.h" // used for update()
// For Update()
#include "Settings.h" #include "Settings.h"
#include "Attack.h" #include "Attack.h"
#include "Scan.h" #include "Scan.h"
// ===== [External] ===== //
// used for update()
extern Settings settings; extern Settings settings;
extern Attack attack; extern Attack attack;
extern Scan scan; extern Scan scan;
void LED::update() { void LED::setColor(uint8_t r, uint8_t g, uint8_t b, bool output) {
if (!tempEnabled) return; if (output) {
char s[30];
if (!settings.getLedEnabled() && tempEnabled) { sprintf_P(s, L_OUTPUT, r, g, b);
tempDisable(); prnt(String(s));
} }
if (scan.isScanning() && (scan.deauths < settings.getMinDeauths())) { #if defined(LED_DIGITAL)
if (LED_ANODE) {
if (LED_PIN_R < 255) digitalWrite(LED_PIN_R, r > 0);
if (LED_PIN_G < 255) digitalWrite(LED_PIN_G, g > 0);
if (LED_PIN_B < 255) digitalWrite(LED_PIN_B, b > 0);
} else {
if (LED_PIN_R < 255) digitalWrite(LED_PIN_R, r == 0);
if (LED_PIN_G < 255) digitalWrite(LED_PIN_G, g == 0);
if (LED_PIN_B < 255) digitalWrite(LED_PIN_B, b == 0);
}
#elif defined(LED_RGB)
if (r > 0) r = r * LED_MODE_BRIGHTNESS / 100;
if (g > 0) g = g * LED_MODE_BRIGHTNESS / 100;
if (b > 0) b = b * LED_MODE_BRIGHTNESS / 100;
if (LED_ANODE) {
r = 255 - r;
g = 255 - g;
b = 255 - b;
}
analogWrite(LED_PIN_R, r);
analogWrite(LED_PIN_G, g);
analogWrite(LED_PIN_B, b);
#elif defined(NEOPIXEL_LED)
for (size_t i = 0; i < LED_NEOPIXEL_NUM; i++) {
strip.setPixelColor(i, r, g, b);
}
strip.show();
#elif defined(LED_MY9291)
myled.setChannel(LED_MY92_CH_R, r);
myled.setChannel(LED_MY92_CH_G, g);
myled.setChannel(LED_MY92_CH_B, b);
myled.setChannel(LED_MY92_CH_BRIGHTNESS, LED_MODE_BRIGHTNESS);
myled.setState(true);
myled.update();
#endif // if defined(LED_DIGITAL)
}
void LED::setup() {
analogWriteRange(0xff);
#if defined(LED_DIGITAL) || defined(LED_RGB)
if (LED_PIN_R < 255) pinMode(LED_PIN_R, OUTPUT);
if (LED_PIN_G < 255) pinMode(LED_PIN_G, OUTPUT);
if (LED_PIN_B < 255) pinMode(LED_PIN_B, OUTPUT);
#elif defined(NEOPIXEL_LED)
strip.begin();
strip.setBrightness(LED_MODE_BRIGHTNESS);
strip.show();
#elif defined(LED_MY9291)
myled.setChannel(LED_MY92_CH_R, 0);
myled.setChannel(LED_MY92_CH_G, 0);
myled.setChannel(LED_MY92_CH_B, 0);
myled.setChannel(LED_MY92_CH_BRIGHTNESS, LED_MODE_BRIGHTNESS);
myled.setState(true);
myled.update();
#endif // if defined(LED_DIGITAL) || defined(LED_RGB)
}
void LED::update() {
if (!settings.getLedEnabled()) {
setMode(OFF);
} else if (scan.isScanning() && (scan.deauths < settings.getMinDeauths())) {
setMode(SCAN); setMode(SCAN);
} else if (attack.isRunning() || (scan.deauths >= settings.getMinDeauths())) { } else if (attack.isRunning() || (scan.deauths >= settings.getMinDeauths())) {
setMode(ATTACK); setMode(ATTACK);
@@ -28,51 +94,26 @@ void LED::update() {
} }
} }
void LED::printColor(uint8_t r, uint8_t g, uint8_t b) {
char s[30];
sprintf_P(s, L_OUTPUT, r, g, b);
prnt(String(s));
}
void LED::setMode(LED_MODE mode, bool force) { void LED::setMode(LED_MODE mode, bool force) {
if ((mode != this->mode) || force) { if ((mode != this->mode) || force) {
this->mode = mode; this->mode = mode;
switch (mode) { switch (mode) {
case OFF: case OFF:
setColor(0, 0, 0); setColor(LED_MODE_OFF);
break; break;
case SCAN: case SCAN:
setColor(0, 0, 255); setColor(LED_MODE_SCAN);
break; break;
case ATTACK: case ATTACK:
setColor(255, 0, 0); setColor(LED_MODE_ATTACK);
break; break;
case IDLE: case IDLE:
setColor(0, 255, 0); setColor(LED_MODE_IDLE);
break; break;
} }
} }
} }
void LED::setBrightness(uint8_t brightness) {
this->brightness = brightness % 100;
}
void LED::tempEnable() {
tempEnabled = true;
prntln(L_ENABLED);
}
void LED::tempDisable() {
tempEnabled = false;
prntln(L_DISABLED);
}
bool LED::getTempEnabled() {
return tempEnabled;
}

View File

@@ -1,8 +1,12 @@
#ifndef LED_h #ifndef LED_h
#define LED_h #define LED_h
// ===== [Includes] ===== //
#include "Arduino.h" // digitalWrite, analogWrite, pinMode #include "Arduino.h" // digitalWrite, analogWrite, pinMode
#include "A_config.h" // Config for LEDs #include "A_config.h" // Config for LEDs
#include "language.h" // Strings used in printColor and tempDisable
// ===== [Defines] ===== //
// Inlcude libraries for Neopixel or LED_MY92xx if used // Inlcude libraries for Neopixel or LED_MY92xx if used
#if defined(NEOPIXEL_LED) #if defined(NEOPIXEL_LED)
@@ -11,6 +15,10 @@
#include <my92xx.h> #include <my92xx.h>
#endif // if defined(NEOPIXEL_LED) #endif // if defined(NEOPIXEL_LED)
// ===== [Strings] ===== //
const char L_OUTPUT[] PROGMEM = "LED = (%u,%u,%u)";
// ===== [LED Mode Enum] ===== //
enum LED_MODE { enum LED_MODE {
OFF, OFF,
SCAN, SCAN,
@@ -18,13 +26,11 @@ enum LED_MODE {
IDLE IDLE
}; };
// ===== [LED Class] ===== //
class LED { class LED {
private: private:
bool tempEnabled = true;
LED_MODE mode = OFF; LED_MODE mode = OFF;
uint8_t brightness = 100;
#if defined(LED_NEOPIXEL_RGB) #if defined(LED_NEOPIXEL_RGB)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(LED_NEOPIXEL_NUM, LED_NEOPIXEL_PIN, NEO_RGB + NEO_KHZ400); Adafruit_NeoPixel strip = Adafruit_NeoPixel(LED_NEOPIXEL_NUM, LED_NEOPIXEL_PIN, NEO_RGB + NEO_KHZ400);
#elif defined(LED_NEOPIXEL_GRB) #elif defined(LED_NEOPIXEL_GRB)
@@ -33,89 +39,12 @@ class LED {
my92xx myled = my92xx(LED_MY92_MODEL, LED_MY92_NUM, LED_MY92_DATA, LED_MY92_CLK, MY92XX_COMMAND_DEFAULT); my92xx myled = my92xx(LED_MY92_MODEL, LED_MY92_NUM, LED_MY92_DATA, LED_MY92_CLK, MY92XX_COMMAND_DEFAULT);
#endif // if defined(NEOPIXEL_LED) #endif // if defined(NEOPIXEL_LED)
void setColor(uint8_t r, uint8_t g, uint8_t b, bool output = false);
public: public:
void setup() { void setup();
analogWriteRange(0xff);
brightness = LED_MODE_BRIGHTNESS;
#if defined(LED_DIGITAL) || defined(LED_RGB)
if (LED_PIN_R < 255) pinMode(LED_PIN_R, OUTPUT);
if (LED_PIN_G < 255) pinMode(LED_PIN_G, OUTPUT);
if (LED_PIN_B < 255) pinMode(LED_PIN_B, OUTPUT);
#elif defined(NEOPIXEL_LED)
strip.begin();
strip.setBrightness(brightness);
strip.show();
#elif defined(LED_MY9291)
myled.setChannel(LED_MY92_CH_R, 0);
myled.setChannel(LED_MY92_CH_G, 0);
myled.setChannel(LED_MY92_CH_B, 0);
myled.setChannel(LED_MY92_CH_BRIGHTNESS, brightness);
myled.setState(true);
myled.update();
#endif // if defined(LED_DIGITAL) || defined(LED_RGB)
}
void update(); void update();
void printColor(uint8_t r, uint8_t g, uint8_t b);
void setMode(LED_MODE mode, bool force = false); void setMode(LED_MODE mode, bool force = false);
void setBrightness(uint8_t brightness);
void setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t brightness, bool output = false) {
setBrightness(brightness);
setColor(r, g, b, output);
}
void setColor(uint8_t r, uint8_t g, uint8_t b, bool output = false) {
if (output) printColor(r, g, b);
#if defined(LED_DIGITAL)
if (LED_ANODE) {
if (LED_PIN_R < 255) digitalWrite(LED_PIN_R, r > 0);
if (LED_PIN_G < 255) digitalWrite(LED_PIN_G, g > 0);
if (LED_PIN_B < 255) digitalWrite(LED_PIN_B, b > 0);
} else {
if (LED_PIN_R < 255) digitalWrite(LED_PIN_R, r == 0);
if (LED_PIN_G < 255) digitalWrite(LED_PIN_G, g == 0);
if (LED_PIN_B < 255) digitalWrite(LED_PIN_B, b == 0);
}
#elif defined(LED_RGB)
if ((r > 0) && (brightness > 0)) r = r * brightness / 100;
if ((g > 0) && (brightness > 0)) g = g * brightness / 100;
if ((b > 0) && (brightness > 0)) b = b * brightness / 100;
if (LED_ANODE) {
r = 255 - r;
g = 255 - g;
b = 255 - b;
}
analogWrite(LED_PIN_R, r);
analogWrite(LED_PIN_G, g);
analogWrite(LED_PIN_B, b);
#elif defined(NEOPIXEL_LED)
for (size_t i = 0; i < LED_NEOPIXEL_NUM; i++) {
strip.setPixelColor(i, r, g, b);
}
strip.show();
#elif defined(LED_MY9291)
myled.setChannel(LED_MY92_CH_R, r);
myled.setChannel(LED_MY92_CH_G, g);
myled.setChannel(LED_MY92_CH_B, b);
myled.setChannel(LED_MY92_CH_BRIGHTNESS, brightness);
myled.setState(true);
myled.update();
#endif // if defined(LED_DIGITAL)
}
void tempEnable();
void tempDisable();
bool getTempEnabled();
}; };
#endif // ifndef LED_h #endif // ifndef LED_h

View File

@@ -221,64 +221,64 @@ const char CLI_RICE_OUTPUT[] PROGMEM = "[ % d % % ]\r\n";
const char CLI_RICE_ERROR[] PROGMEM = "ERROR : Memory check failure at block 0x"; const char CLI_RICE_ERROR[] PROGMEM = "ERROR : Memory check failure at block 0x";
const char CLI_RICE_MEM[] PROGMEM = "Checking memory block 0x"; const char CLI_RICE_MEM[] PROGMEM = "Checking memory block 0x";
const char CLI_CHICKEN_OUTPUT[] PROGMEM = " ` - : /////////:-. \r\n" const char CLI_CHICKEN_OUTPUT[] PROGMEM = " ` - : /////////:-. \r\n"
" ./++so:` `` `.:/++/. \r\n" " ./++so:` `` `.:/++/. \r\n"
" `/+o+.+o:.s:-++//s` `:++- \r\n" " `/+o+.+o:.s:-++//s` `:++- \r\n"
" `/+oo+//d- oh/ s- :o/` \r\n" " `/+oo+//d- oh/ s- :o/` \r\n"
" .++.o+` `h- .d. h`://+` .o+ \r\n" " .++.o+` `h- .d. h`://+` .o+ \r\n"
" .o+` +/ +o y- +d+. .y .s- \r\n" " .o+` +/ +o y- +d+. .y .s- \r\n"
" +o` h d` `/ .h- `h ++ \r\n" " +o` h d` `/ .h- `h ++ \r\n"
" .s- d - .` +/ /o \r\n" " .s- d - .` +/ /o \r\n"
" :o` y. -y /+ \r\n" " :o` y. -y /+ \r\n"
" /+ :o ` -h` s: \r\n" " /+ :o ` -h` s: \r\n"
" /o y..://///////:` /o/o. `h \r\n" " /o y..://///////:` /o/o. `h \r\n"
" -s +o:`` `-++::/+- `o/ o: \r\n" " -s +o:`` `-++::/+- `o/ o: \r\n"
" y. :o `:::.` `oo` -s \r\n" " y. :o `:::.` `oo` -s \r\n"
" -s h` .++:---/+/+/:::++. `h \r\n" " -s h` .++:---/+/+/:::++. `h \r\n"
" +/ h :o` ` `/s ` .s- d \r\n" " +/ h :o` ` `/s ` .s- d \r\n"
" o: .s h` /h- o:/h- -s `h \r\n" " o: .s h` /h- o:/h- -s `h \r\n"
" +/ +/ h` `` s- ` +/ -s \r\n" " +/ +/ h` `` s- ` +/ -s \r\n"
" .y `h` -s- `+y-.`.:+/ +: \r\n" " .y `h` -s- `+y-.`.:+/ +: \r\n"
" o: o: `/+/:/+ss:.-:y/.` `h` \r\n" " o: o: `/+/:/+ss:.-:y/.` `h` \r\n"
" .:-` `y- ++ `so::-://+y. +/ \r\n" " .:-` `y- ++ `so::-://+y. +/ \r\n"
" :o.-/+: :+//:` `s: `+/ -h//:::---:/o- -y \r\n" " :o.-/+: :+//:` `s: `+/ -h//:::---:/o- -y \r\n"
" :o `:o:h. `-+/` -d+.:o- .y.``...-/y/++` `y. \r\n" " :o `:o:h. `-+/` -d+.:o- .y.``...-/y/++` `y. \r\n"
" +/ `:hs -o- o/:/yo:-` +y++s//+/. `s. \r\n" " +/ `:hs -o- o/:/yo:-` +y++s//+/. `s. \r\n"
" /o` `oo` `/+` .-:y/-`+:+so+/:-` s- y: -s. \r\n" " /o` `oo` `/+` .-:y/-`+:+so+/:-` s- y: -s. \r\n"
" ++//+y: -+ .o: ``-:/+:-.`.:+/:hs+`++:/o/:.` `h .y` /o` \r\n" " ++//+y: -+ .o: ``-:/+:-.`.:+/:hs+`++:/o/:.` `h .y` /o` \r\n"
"`h` `./ys- :o- .--:////:-.` `-/o/::.`/sh-:os/:.` .y oo`+/ -o: \r\n" "`h` `./ys- :o- .--:////:-.` `-/o/::.`/sh-:os/:.` .y oo`+/ -o: \r\n"
" :o- `-o+. `/+o/:-..` `.:+++o/``/:-oo++/:.so+://` `:+/` \r\n" " :o- `-o+. `/+o/:-..` `.:+++o/``/:-oo++/:.so+://` `:+/` \r\n"
" `/+:` .. `++` `.-/+/:-/sy.`+o:+y/-. .-/+-` \r\n" " `/+:` .. `++` `.-/+/:-/sy.`+o:+y/-. .-/+-` \r\n"
" `-+/- .- `.:/o+:-:.```-:oy/:://:-` \r\n" " `-+/- .- `.:/o+:-:.```-:oy/:://:-` \r\n"
" .:+/. `.-:/+/::s/-..` \r\n" " .:+/. `.-:/+/::s/-..` \r\n"
" .++. `.-h. \r\n" " .++. `.-h. \r\n"
" .o/ +/ \r\n" " .o/ +/ \r\n"
" :o. :o \r\n" " :o. :o \r\n"
" .o: -s \r\n" " .o: -s \r\n"
" /o` :+ \r\n" " /o` :+ \r\n"
" -o- o: \r\n" " -o- o: \r\n"
" `o/ h` \r\n" " `o/ h` \r\n"
" :o. -s \r\n" " :o. -s \r\n"
" .o: y. \r\n" " .o: y. \r\n"
" /o. /+ \r\n" " /o. /+ \r\n"
" .+/` -s \r\n" " .+/` -s \r\n"
" -+/. .s` \r\n" " -+/. .s` \r\n"
" ./+/.` -s` \r\n" " ./+/.` -s` \r\n"
" .:/+:.` /o` \r\n" " .:/+:.` /o` \r\n"
" .:/o/.` .o: \r\n" " .:/o/.` .o: \r\n"
" o/:/+/.` .++` \r\n" " o/:/+/.` .++` \r\n"
" -s `:/+:` `:+/` \r\n" " -s `:/+:` `:+/` \r\n"
" ++` -+o-` `-++- \r\n" " ++` -+o-` `-++- \r\n"
" :s/::/+//::+/---/+/:` \r\n" " :s/::/+//::+/---/+/:` \r\n"
" +/s:` `-h-s- \r\n" " +/s:` `-h-s- \r\n"
" +/s- `y y. \r\n" " +/s- `y y. \r\n"
" +/y. `y h` \r\n" " +/y. `y h` \r\n"
" //s:` `y d \r\n" " //s:` `y d \r\n"
" +/-:/++/-` `y h-` \r\n" " +/-:/++/-` `y h-` \r\n"
" y:hs-ysosss..y --/+++/-` \r\n" " y:hs-ysosss..y --/+++/-` \r\n"
" ds:`s:o+`-:`o:oos./h++osoo` \r\n" " ds:`s:o+`-:`o:oos./h++osoo` \r\n"
" :: o+++ h:y `o+.s:`.:: \r\n" " :: o+++ h:y `o+.s:`.:: \r\n"
" -+- -/` :s.++ \r\n" " -+- -/` :s.++ \r\n"
" `/+- "; " `/+- ";
const char CLI_SYSTEM_INFO[] PROGMEM = "[======== SYSTEM INFO ========]"; const char CLI_SYSTEM_INFO[] PROGMEM = "[======== SYSTEM INFO ========]";
const char CLI_SYSTEM_OUTPUT[] PROGMEM = "RAM usage: %u bytes used [%d%%], %u bytes free [%d%%], %u bytes in total\r\n"; const char CLI_SYSTEM_OUTPUT[] PROGMEM = "RAM usage: %u bytes used [%d%%], %u bytes free [%d%%], %u bytes in total\r\n";
const char CLI_SYSTEM_AP_MAC[] PROGMEM = "AP MAC address: "; const char CLI_SYSTEM_AP_MAC[] PROGMEM = "AP MAC address: ";
@@ -483,12 +483,6 @@ const char A_STATUS[] PROGMEM = "[Pkt/s] All: %+4u | Deauths: %+3u/%-3u | Beacon
const char A_ENABLED_OUTPUT[] PROGMEM = "Enabled attack output"; const char A_ENABLED_OUTPUT[] PROGMEM = "Enabled attack output";
const char A_DISABLED_OUTPUT[] PROGMEM = "Disabled attack output"; const char A_DISABLED_OUTPUT[] PROGMEM = "Disabled attack output";
// ===== LED ===== //
const char L_ENABLED[] PROGMEM = "Enabled LED updates";
const char L_DISABLED[] PROGMEM = "Disabled LED updates";
const char L_OUTPUT[] PROGMEM = "LED = (%u,%u,%u)";
const char L_NOT_CONFIGURED[] PROGMEM = "ERROR: No LED is configured in A_config.h!";
// ===== NAMES ===== // // ===== NAMES ===== //
const char N_SAVED[] PROGMEM = "Device names saved in "; const char N_SAVED[] PROGMEM = "Device names saved in ";
const char N_LOADED[] PROGMEM = "Device names loaded from "; const char N_LOADED[] PROGMEM = "Device names loaded from ";