Use SimpleButton Library

This commit is contained in:
Stefan Kremser
2018-10-12 14:34:18 +02:00
parent 7242543017
commit 7610db9534
2 changed files with 153 additions and 332 deletions

View File

@@ -71,7 +71,7 @@ void DisplayUI::on() {
if (enabled) { if (enabled) {
configOn(); configOn();
mode = SCREEN_MODE_MENU; mode = SCREEN_MODE_MENU;
buttonUp.time = currentTime; // update a button time to keep display on buttonTime = currentTime; // update a button time to keep display on
prntln(D_MSG_DISPLAY_ON); prntln(D_MSG_DISPLAY_ON);
} else { } else {
prntln(D_ERROR_NOT_ENABLED); prntln(D_ERROR_NOT_ENABLED);
@@ -89,113 +89,15 @@ void DisplayUI::off() {
} }
void DisplayUI::setupButtons() { void DisplayUI::setupButtons() {
#ifdef BUTTON_UP up = new ButtonPullup(BUTTON_UP);
buttonUp.enabled = true; down = new ButtonPullup(BUTTON_DOWN);
buttonUp.gpio = BUTTON_UP; a = new ButtonPullup(BUTTON_A);
#else // ifdef BUTTON_UP b = new ButtonPullup(BUTTON_B);
buttonUp.enabled = false;
#endif // ifdef BUTTON_UP
#ifdef BUTTON_DOWN
buttonDown.enabled = true;
buttonDown.gpio = BUTTON_DOWN;
#else // ifdef BUTTON_DOWN
buttonDown.enabled = false;
#endif // ifdef BUTTON_DOWN
#ifdef BUTTON_LEFT
buttonLeft.enabled = true;
buttonLeft.gpio = BUTTON_LEFT;
#else // ifdef BUTTON_LEFT
buttonLeft.enabled = false;
#endif // ifdef BUTTON_LEFT
#ifdef BUTTON_RIGHT
buttonRight.enabled = true;
buttonRight.gpio = BUTTON_RIGHT;
#else // ifdef BUTTON_RIGHT
buttonRight.enabled = false;
#endif // ifdef BUTTON_RIGHT
#ifdef BUTTON_A
buttonA.enabled = true;
buttonA.gpio = BUTTON_A;
#else // ifdef BUTTON_A
buttonA.enabled = false;
#endif // ifdef BUTTON_A
#ifdef BUTTON_B
buttonB.enabled = true;
buttonB.gpio = BUTTON_B;
#else // ifdef BUTTON_B
buttonB.enabled = false;
#endif // ifdef BUTTON_B
// ====================== //
// setup and read functions
// ====================== //
buttonUp.setup = [this]() {
if (buttonUp.gpio != 2) pinMode(buttonUp.gpio, INPUT_PULLUP);
buttonUp.time = currentTime;
};
buttonUp.read = [this]() {
return !digitalRead(buttonUp.gpio);
};
buttonDown.setup = [this]() {
if (buttonDown.gpio != 2) pinMode(buttonDown.gpio, INPUT_PULLUP);
buttonDown.time = currentTime;
};
buttonDown.read = [this]() {
return !digitalRead(buttonDown.gpio);
};
buttonLeft.setup = [this]() {
if (buttonLeft.gpio != 2) pinMode(buttonLeft.gpio, INPUT_PULLUP);
buttonLeft.time = currentTime;
};
buttonLeft.read = [this]() {
return !digitalRead(buttonLeft.gpio);
};
buttonRight.setup = [this]() {
if (buttonRight.gpio != 2) pinMode(buttonRight.gpio, INPUT_PULLUP);
buttonRight.time = currentTime;
};
buttonRight.read = [this]() {
return !digitalRead(buttonRight.gpio);
};
buttonA.setup = [this]() {
if (buttonA.gpio != 2) pinMode(buttonA.gpio, INPUT_PULLUP);
buttonA.time = currentTime;
};
buttonA.read = [this]() {
return !digitalRead(buttonA.gpio);
};
buttonB.setup = [this]() {
if (buttonB.gpio != 2) pinMode(buttonB.gpio, INPUT_PULLUP);
buttonB.time = currentTime;
};
buttonB.read = [this]() {
return !digitalRead(buttonB.gpio);
};
}
void DisplayUI::setup() {
setupDisplay();
setupButtons();
// ===== PUSH AND RELEASE FUNCTIONS ===== //
// === BUTTON UP === // // === BUTTON UP === //
buttonUp.push = [this]() { up->setOnClicked([this]() {
if (buttonUp.time > currentTime - BUTTON_DELAY) return;
buttonUp.pushed = true;
buttonUp.time = currentTime;
scrollCounter = 0; scrollCounter = 0;
buttonTime = millis();
if (mode == SCREEN_MODE_MENU) { // when in menu, go up or down with cursor if (mode == SCREEN_MODE_MENU) { // when in menu, go up or down with cursor
if (currentMenu->selected > 0) currentMenu->selected--; if (currentMenu->selected > 0) currentMenu->selected--;
@@ -203,21 +105,24 @@ void DisplayUI::setup() {
} else if (mode == SCREEN_MODE_PACKETMONITOR) { // when in packet monitor, change channel } else if (mode == SCREEN_MODE_PACKETMONITOR) { // when in packet monitor, change channel
scan.setChannel(wifi_channel + 1); scan.setChannel(wifi_channel + 1);
} }
}; });
buttonUp.release = [this]() { up->setOnHolding([this]() {
if (!buttonUp.pushed) return; scrollCounter = 0;
buttonTime = millis();
buttonUp.pushed = false; if (mode == SCREEN_MODE_MENU) { // when in menu, go up or down with cursor
}; if (currentMenu->selected > 0) currentMenu->selected--;
else currentMenu->selected = currentMenu->list->size() - 1;
} else if (mode == SCREEN_MODE_PACKETMONITOR) { // when in packet monitor, change channel
scan.setChannel(wifi_channel + 1);
}
}, 250);
// === BUTTON DOWN === // // === BUTTON DOWN === //
buttonDown.push = [this]() { down->setOnClicked([this]() {
if (buttonDown.time > currentTime - BUTTON_DELAY) return;
buttonDown.pushed = true;
buttonDown.time = currentTime;
scrollCounter = 0; scrollCounter = 0;
buttonTime = millis();
if (mode == SCREEN_MODE_MENU) { // when in menu, go up or down with cursor if (mode == SCREEN_MODE_MENU) { // when in menu, go up or down with cursor
if (currentMenu->selected < currentMenu->list->size() - 1) currentMenu->selected++; if (currentMenu->selected < currentMenu->list->size() - 1) currentMenu->selected++;
@@ -225,94 +130,54 @@ void DisplayUI::setup() {
} else if (mode == SCREEN_MODE_PACKETMONITOR) { // when in packet monitor, change channel } else if (mode == SCREEN_MODE_PACKETMONITOR) { // when in packet monitor, change channel
scan.setChannel(wifi_channel - 1); scan.setChannel(wifi_channel - 1);
} }
}; });
buttonDown.release = [this]() { down->setOnHolding([this]() {
if (!buttonDown.pushed) return;
buttonDown.pushed = false;
};
// === BUTTON LEFT === //
buttonLeft.push = [this]() {
if (buttonLeft.time > currentTime - BUTTON_DELAY) return;
buttonLeft.pushed = true;
buttonLeft.time = currentTime;
scrollCounter = 0; scrollCounter = 0;
}; buttonTime = millis();
buttonLeft.release = [this]() { if (mode == SCREEN_MODE_MENU) { // when in menu, go up or down with cursor
if (!buttonLeft.pushed) return; if (currentMenu->selected < currentMenu->list->size() - 1) currentMenu->selected++;
else currentMenu->selected = 0;
buttonLeft.pushed = false; } else if (mode == SCREEN_MODE_PACKETMONITOR) { // when in packet monitor, change channel
}; scan.setChannel(wifi_channel - 1);
}
// === BUTTON RIGHT === // }, 250);
buttonRight.push = [this]() {
if (buttonRight.time > currentTime - BUTTON_DELAY) return;
buttonRight.pushed = true;
buttonRight.time = currentTime;
scrollCounter = 0;
};
buttonRight.release = [this]() {
if (!buttonRight.pushed) return;
buttonRight.pushed = false;
};
// === BUTTON A === // // === BUTTON A === //
buttonA.push = [this]() { a->setOnClicked([this]() {
if (!buttonA.pushed) { // first push scrollCounter = 0;
buttonA.pushed = true; buttonTime = millis();
buttonA.time = currentTime;
scrollCounter = 0; switch (mode) {
} else { // holding button case SCREEN_MODE_MENU:
if ((currentTime - buttonA.time > 800) && !buttonA.hold) {
if (currentMenu->list->get(currentMenu->selected).hold) currentMenu->list->get( if (currentMenu->list->get(currentMenu->selected).click) {
currentMenu->selected).hold(); currentMenu->list->get(currentMenu->selected).click();
buttonA.hold = true; }
} break;
case SCREEN_MODE_PACKETMONITOR:
case SCREEN_MODE_LOADSCAN:
scan.stop();
mode = SCREEN_MODE_MENU;
break;
} }
}; });
buttonA.release = [this]() { a->setOnHolding([this]() {
if (!buttonA.pushed) return; // exit when button wasn't pushed before scrollCounter = 0;
buttonTime = millis();
if (!buttonA.hold && (currentTime - buttonA.time > 80)) { if (currentMenu->list->get(currentMenu->selected).hold) {
switch (mode) { currentMenu->list->get(currentMenu->selected).hold();
case SCREEN_MODE_MENU:
if (currentMenu->list->get(currentMenu->selected).click) {
currentMenu->list->get(currentMenu->selected).click();
}
break;
case SCREEN_MODE_PACKETMONITOR:
case SCREEN_MODE_LOADSCAN:
scan.stop();
mode = SCREEN_MODE_MENU;
break;
}
} }
}, 800);
buttonA.pushed = false;
buttonA.hold = false;
};
// === BUTTON B === // // === BUTTON B === //
buttonB.push = [this]() { a->setOnClicked([this]() {
if (!buttonB.pushed && (buttonB.time > currentTime - BUTTON_DELAY)) return;
buttonB.pushed = true;
buttonB.time = currentTime;
scrollCounter = 0; scrollCounter = 0;
}; buttonTime = millis();
buttonB.release = [this]() {
if (!buttonB.pushed) return;
switch (mode) { switch (mode) {
case SCREEN_MODE_MENU: case SCREEN_MODE_MENU:
@@ -325,23 +190,12 @@ void DisplayUI::setup() {
mode = SCREEN_MODE_MENU; mode = SCREEN_MODE_MENU;
break; break;
} }
});
}
buttonB.pushed = false; void DisplayUI::setup() {
}; setupDisplay();
setupButtons();
// === RUN SETUPS === //
// setting pin modes for buttons
if (buttonUp.enabled && buttonUp.setup) buttonUp.setup();
if (buttonDown.enabled && buttonDown.setup) buttonDown.setup();
if (buttonLeft.enabled && buttonLeft.setup) buttonLeft.setup();
if (buttonRight.enabled && buttonRight.setup) buttonRight.setup();
if (buttonA.enabled && buttonA.setup) buttonA.setup();
if (buttonB.enabled && buttonB.setup) buttonB.setup();
// ===== MENUS ===== // // ===== MENUS ===== //
@@ -380,17 +234,17 @@ void DisplayUI::setup() {
// SHOW MENU // SHOW MENU
createMenu(&showMenu, &mainMenu, [this]() { createMenu(&showMenu, &mainMenu, [this]() {
addMenuNode(&showMenu, []() { // Accesspoints 0 [0] addMenuNode(&showMenu, [this]() { // Accesspoints 0 [0]
return leftRight(str(D_ACCESSPOINTS), (String)accesspoints.count(), CHARS_PER_LINE); return leftRight(str(D_ACCESSPOINTS), (String)accesspoints.count(), maxLen - 1);
}, &apListMenu); }, &apListMenu);
addMenuNode(&showMenu, []() { // Stations 0 [0] addMenuNode(&showMenu, [this]() { // Stations 0 [0]
return leftRight(str(D_STATIONS), (String)stations.count(), CHARS_PER_LINE); return leftRight(str(D_STATIONS), (String)stations.count(), maxLen - 1);
}, &stationListMenu); }, &stationListMenu);
addMenuNode(&showMenu, []() { // Names 0 [0] addMenuNode(&showMenu, [this]() { // Names 0 [0]
return leftRight(str(D_NAMES), (String)names.count(), CHARS_PER_LINE); return leftRight(str(D_NAMES), (String)names.count(), maxLen - 1);
}, &nameListMenu); }, &nameListMenu);
addMenuNode(&showMenu, []() { // SSIDs 0 addMenuNode(&showMenu, [this]() { // SSIDs 0
return leftRight(str(D_SSIDS), (String)ssids.count(), CHARS_PER_LINE); return leftRight(str(D_SSIDS), (String)ssids.count(), maxLen - 1);
}, &ssidListMenu); }, &ssidListMenu);
}); });
@@ -660,8 +514,8 @@ void DisplayUI::setup() {
addMenuNode(&attackMenu, [this]() { // *DEAUTH 0/0 addMenuNode(&attackMenu, [this]() { // *DEAUTH 0/0
if (attack.isRunning()) return leftRight(b2a(deauthSelected) + str(D_DEAUTH), if (attack.isRunning()) return leftRight(b2a(deauthSelected) + str(D_DEAUTH),
(String)attack.getDeauthPkts() + SLASH + (String)attack.getDeauthPkts() + SLASH +
(String)attack.getDeauthMaxPkts(), CHARS_PER_LINE); (String)attack.getDeauthMaxPkts(), maxLen - 1);
else return leftRight(b2a(deauthSelected) + str(D_DEAUTH), (String)scan.countSelected(), CHARS_PER_LINE); else return leftRight(b2a(deauthSelected) + str(D_DEAUTH), (String)scan.countSelected(), maxLen - 1);
}, [this]() { // deauth }, [this]() { // deauth
deauthSelected = !deauthSelected; deauthSelected = !deauthSelected;
@@ -673,8 +527,8 @@ void DisplayUI::setup() {
addMenuNode(&attackMenu, [this]() { // *BEACON 0/0 addMenuNode(&attackMenu, [this]() { // *BEACON 0/0
if (attack.isRunning()) return leftRight(b2a(beaconSelected) + str(D_BEACON), if (attack.isRunning()) return leftRight(b2a(beaconSelected) + str(D_BEACON),
(String)attack.getBeaconPkts() + SLASH + (String)attack.getBeaconPkts() + SLASH +
(String)attack.getBeaconMaxPkts(), CHARS_PER_LINE); (String)attack.getBeaconMaxPkts(), maxLen - 1);
else return leftRight(b2a(beaconSelected) + str(D_BEACON), (String)ssids.count(), CHARS_PER_LINE); else return leftRight(b2a(beaconSelected) + str(D_BEACON), (String)ssids.count(), maxLen - 1);
}, [this]() { // beacon }, [this]() { // beacon
beaconSelected = !beaconSelected; beaconSelected = !beaconSelected;
@@ -686,8 +540,8 @@ void DisplayUI::setup() {
addMenuNode(&attackMenu, [this]() { // *PROBE 0/0 addMenuNode(&attackMenu, [this]() { // *PROBE 0/0
if (attack.isRunning()) return leftRight(b2a(probeSelected) + str(D_PROBE), if (attack.isRunning()) return leftRight(b2a(probeSelected) + str(D_PROBE),
(String)attack.getProbePkts() + SLASH + (String)attack.getProbePkts() + SLASH +
(String)attack.getProbeMaxPkts(), CHARS_PER_LINE); (String)attack.getProbeMaxPkts(), maxLen - 1);
else return leftRight(b2a(probeSelected) + str(D_PROBE), (String)ssids.count(), CHARS_PER_LINE); else return leftRight(b2a(probeSelected) + str(D_PROBE), (String)ssids.count(), maxLen - 1);
}, [this]() { // probe }, [this]() { // probe
probeSelected = !probeSelected; probeSelected = !probeSelected;
@@ -696,9 +550,9 @@ void DisplayUI::setup() {
settings.getAttackTimeout() * 1000); settings.getAttackTimeout() * 1000);
} }
}); });
addMenuNode(&attackMenu, []() { // START addMenuNode(&attackMenu, [this]() { // START
return leftRight(str(attack.isRunning() ? D_STOP_ATTACK : D_START_ATTACK), return leftRight(str(attack.isRunning() ? D_STOP_ATTACK : D_START_ATTACK),
attack.getPacketRate() > 0 ? (String)attack.getPacketRate() : String(), CHARS_PER_LINE); attack.getPacketRate() > 0 ? (String)attack.getPacketRate() : String(), maxLen - 1);
}, [this]() { }, [this]() {
if (attack.isRunning()) attack.stop(); if (attack.isRunning()) attack.stop();
else attack.start(beaconSelected, deauthSelected, false, probeSelected, true, else attack.start(beaconSelected, deauthSelected, false, probeSelected, true,
@@ -717,39 +571,18 @@ void DisplayUI::setup() {
void DisplayUI::update() { void DisplayUI::update() {
if (!enabled) return; if (!enabled) return;
// when display is off up->update();
if (mode == SCREEN_MODE_OFF) { down->update();
if (updateButton(&buttonA)) { a->update();
on(); b->update();
buttonA.hold = true; // to make sure you don't double click
}
}
else { draw();
// timeout to save display life /*
if ((mode == SCREEN_MODE_MENU) && (settings.getDisplayTimeout() > 0) && uint32_t timeout = millis() - (settings.getDisplayTimeout() * 1000);
(currentTime > settings.getDisplayTimeout() * 1000)) { Serial.println(timeout);
uint32_t buttonTimeout = currentTime - settings.getDisplayTimeout() * 1000;
if ((buttonUp.time < buttonTimeout) if (mode != SCREEN_MODE_OFF && buttonTime < timeout) off();
&& (buttonDown.time < buttonTimeout) else if (mode == SCREEN_MODE_OFF && buttonTime > timeout) on();*/
&& (buttonLeft.time < buttonTimeout)
&& (buttonRight.time < buttonTimeout)
&& (buttonA.time < buttonTimeout)
&& (buttonB.time < buttonTimeout)) {
off();
}
}
// only one button can be pressed at a time
if (updateButton(&buttonB)) draw();
else if (updateButton(&buttonA)) draw();
else if (updateButton(&buttonUp)) draw();
else if (updateButton(&buttonDown)) draw();
else if (updateButton(&buttonLeft)) draw();
else if (updateButton(&buttonRight)) draw();
else draw();
}
} }
void DisplayUI::draw() { void DisplayUI::draw() {
@@ -789,17 +622,18 @@ void DisplayUI::draw() {
} }
void DisplayUI::drawButtonTest() { void DisplayUI::drawButtonTest() {
if (buttonUp.enabled) drawString(0, 0, str(D_UP) + b2s(buttonUp.pushed)); /*
if (buttonUp.enabled) drawString(0, 0, str(D_UP) + b2s(buttonUp.pushed));
if (buttonDown.enabled) drawString(0, 9, str(D_DOWN) + b2s(buttonDown.pushed)); if (buttonDown.enabled) drawString(0, 9, str(D_DOWN) + b2s(buttonDown.pushed));
if (buttonLeft.enabled) drawString(0, 18, str(D_LEFT) + b2s(buttonLeft.pushed)); if (buttonLeft.enabled) drawString(0, 18, str(D_LEFT) + b2s(buttonLeft.pushed));
if (buttonRight.enabled) drawString(0, 27, str(D_RIGHT) + b2s(buttonRight.pushed)); if (buttonRight.enabled) drawString(0, 27, str(D_RIGHT) + b2s(buttonRight.pushed));
if (buttonA.enabled) drawString(0, 36, str(D_A) + b2s(buttonA.pushed)); if (buttonA.enabled) drawString(0, 36, str(D_A) + b2s(buttonA.pushed));
if (buttonB.enabled) drawString(0, 45, str(D_B) + b2s(buttonB.pushed)); if (buttonB.enabled) drawString(0, 45, str(D_B) + b2s(buttonB.pushed));*/
} }
void DisplayUI::drawMenu() { void DisplayUI::drawMenu() {
@@ -817,11 +651,11 @@ void DisplayUI::drawMenu() {
tmpLen = tmp.length(); tmpLen = tmp.length();
// horizontal scrolling // horizontal scrolling
if ((currentMenu->selected == i) && (tmpLen > CHARS_PER_LINE)) { if ((currentMenu->selected == i) && (tmpLen > maxLen - 1)) {
tmp = tmp.substring(scrollCounter / SCROLL_SPEED); tmp = tmp.substring(scrollCounter / SCROLL_SPEED);
scrollCounter++; scrollCounter++;
if (scrollCounter / SCROLL_SPEED > tmpLen - CHARS_PER_LINE) scrollCounter = 0; if (scrollCounter / SCROLL_SPEED > tmpLen - maxLen - 1) scrollCounter = 0;
} }
tmp = (currentMenu->selected == i ? CURSOR : SPACE) + tmp; tmp = (currentMenu->selected == i ? CURSOR : SPACE) + tmp;
@@ -830,24 +664,24 @@ void DisplayUI::drawMenu() {
} }
void DisplayUI::drawLoadingScan() { void DisplayUI::drawLoadingScan() {
String percentage; String percentage;
if (scan.isScanning()) { if (scan.isScanning()) {
percentage = String(scan.getPercentage()) + '%'; percentage = String(scan.getPercentage()) + '%';
} else { } else {
percentage = String(DSP_SCAN_DONE); percentage = String(DSP_SCAN_DONE);
} }
drawString(0, leftRight(String(DSP_SCAN_FOR), scan.getMode(), maxLen)); drawString(0, leftRight(String(DSP_SCAN_FOR), scan.getMode(), maxLen));
drawString(1, leftRight(String(DSP_APS), String(accesspoints.count()), maxLen)); drawString(1, leftRight(String(DSP_APS), String(accesspoints.count()), maxLen));
drawString(2, leftRight(String(DSP_STS), String(stations.count()), maxLen)); drawString(2, leftRight(String(DSP_STS), String(stations.count()), maxLen));
drawString(3, leftRight(String(DSP_PKTS), String(scan.getPacketRate()) + String(DSP_S), maxLen)); drawString(3, leftRight(String(DSP_PKTS), String(scan.getPacketRate()) + String(DSP_S), maxLen));
drawString(4, center(percentage, maxLen)); drawString(4, center(percentage, maxLen));
} }
String DisplayUI::getChannel() { String DisplayUI::getChannel() {
String ch = String(wifi_channel); String ch = String(wifi_channel);
if(ch.length() < 2) ch = ' ' + ch; if (ch.length() < 2) ch = ' ' + ch;
return ch; return ch;
} }
@@ -866,25 +700,11 @@ void DisplayUI::drawPacketMonitor() {
} }
void DisplayUI::drawIntro() { void DisplayUI::drawIntro() {
drawString(0, lineHeight*0, center(String(F("")), maxLen)); drawString(0, lineHeight * 0, center(String(F("")), maxLen));
drawString(0, lineHeight*1, center(String(F("ESP8266 Deauther")), maxLen)); drawString(0, lineHeight * 1, center(String(F("ESP8266 Deauther")), maxLen));
drawString(0, lineHeight*2, center(String(F("by @Spacehuhn")), maxLen)); drawString(0, lineHeight * 2, center(String(F("by @Spacehuhn")), maxLen));
drawString(0, lineHeight*3, center(String(F("")), maxLen)); drawString(0, lineHeight * 3, center(String(F("")), maxLen));
drawString(0, lineHeight*4, center(settings.getVersion(), maxLen)); drawString(0, lineHeight * 4, center(settings.getVersion(), maxLen));
}
bool DisplayUI::updateButton(Button* button) {
// direct exit when button is disabled or has no read function
if (!button->enabled || !button->read) return false;
// read pin
if (button->read()) {
if (button->push) button->push();
} else {
if (button->release) button->release();
}
return button->pushed;
} }
void DisplayUI::clearMenu(Menu* menu) { void DisplayUI::clearMenu(Menu* menu) {
@@ -905,7 +725,7 @@ void DisplayUI::changeMenu(Menu* menu) {
if (currentMenu) clearMenu(currentMenu); if (currentMenu) clearMenu(currentMenu);
currentMenu = menu; currentMenu = menu;
currentMenu->selected = 0; currentMenu->selected = 0;
buttonA.time = currentTime; buttonTime = currentTime;
if (selectedID < 0) selectedID = 0; if (selectedID < 0) selectedID = 0;

View File

@@ -15,6 +15,10 @@ extern "C" {
#include "Scan.h" #include "Scan.h"
#include "Attack.h" #include "Attack.h"
#include <SimpleButton.h>
using namespace simplebutton;
extern Settings settings; extern Settings settings;
extern Names names; extern Names names;
extern SSIDs ssids; extern SSIDs ssids;
@@ -31,6 +35,23 @@ extern String right(String a, int len);
extern String leftRight(String a, String b, int len); extern String leftRight(String a, String b, int len);
extern String replaceUtf8(String str, String r); extern String replaceUtf8(String str, String r);
#ifndef BUTTON_UP
#define BUTTON_UP 255
#endif
#ifndef BUTTON_DOWN
#define BUTTON_DOWN 255
#endif
#ifndef BUTTON_A
#define BUTTON_A 255
#endif
#ifndef BUTTON_B
#define BUTTON_B 255
#endif
// different display modes // different display modes
#define SCREEN_MODE_OFF 0 #define SCREEN_MODE_OFF 0
#define SCREEN_MODE_BUTTON_TEST 1 #define SCREEN_MODE_BUTTON_TEST 1
@@ -42,25 +63,14 @@ extern String replaceUtf8(String str, String r);
// ===== adjustable ===== // // ===== adjustable ===== //
#define BUTTON_DELAY 280 // in ms #define BUTTON_DELAY 280 // in ms
#define DRAW_INTERVAL 100 // 100ms = 10 FPS #define DRAW_INTERVAL 100 // 100ms = 10 FPS
#define CHARS_PER_LINE 17
#define SCROLL_SPEED 5 #define SCROLL_SPEED 5
#define SCREEN_INTRO_TIME 2500 #define SCREEN_INTRO_TIME 2500
// ====================== // // ====================== //
struct Menu; struct MenuNode {
struct MenuNode; std::function<String()>getStr; // function used to create the displayed string
struct Button; std::function<void()> click; // function that is executed when node is clicked
std::function<void()> hold; // function that is executed when node is pressed for > 800ms
struct Button {
bool enabled; // use button
uint8_t gpio; // pin that is used
bool pushed; // currently pushed
bool hold; // if button was hold (only used for buttonA at the moment)
uint32_t time; // last time it was pushed
std::function<bool()>read; // function to return if button is pushed
std::function<void()>setup; // function to enable/setup the button, if needed
std::function<void()>push; // function that is executed when button is pushed
std::function<void()>release; // function that is executed when button is released
}; };
struct Menu { struct Menu {
@@ -70,14 +80,13 @@ struct Menu {
std::function<void()> build; // function that is executed when button is clicked std::function<void()> build; // function that is executed when button is clicked
}; };
struct MenuNode {
std::function<String()>getStr; // function used to create the displayed string
std::function<void()> click; // function that is executed when node is clicked
std::function<void()> hold; // function that is executed when node is pressed for > 800ms
};
class DisplayUI { class DisplayUI {
public: public:
Button* up = NULL;
Button* down = NULL;
Button* a = NULL;
Button* b = NULL;
DisplayUI(); DisplayUI();
void setup(); void setup();
@@ -95,8 +104,11 @@ class DisplayUI {
void drawString(int x, int y, String str); void drawString(int x, int y, String str);
void drawString(int row, String str); void drawString(int row, String str);
void drawLine(int x1, int y1, int x2, int y2); void drawLine(int x1, int y1, int x2, int y2);
DEAUTHER_DISPLAY // see config.h
uint8_t maxLen = 18; uint8_t maxLen = 18;
uint8_t lineHeight = 12; uint8_t lineHeight = 12;
uint8_t scrollSpeed = 5;
// ====================== // // ====================== //
void update(); void update();
@@ -106,8 +118,6 @@ class DisplayUI {
uint8_t mode = SCREEN_MODE_MENU; uint8_t mode = SCREEN_MODE_MENU;
private: private:
DEAUTHER_DISPLAY // see config.h
void setupDisplay(); void setupDisplay();
void setupButtons(); void setupButtons();
@@ -115,15 +125,9 @@ class DisplayUI {
uint16_t scrollCounter = 0; // for horizontal scrolling uint16_t scrollCounter = 0; // for horizontal scrolling
uint32_t drawTime = 0; // last time a frame was drawn uint32_t drawTime = 0; // last time a frame was drawn
uint32_t startTime = 0; // when the screen was enabled uint32_t startTime = 0; // when the screen was enabled
uint32_t buttonTime = 0; // last time a button was pressed
bool enabled = false; // display enabled bool enabled = false; // display enabled
Button buttonUp;
Button buttonDown;
Button buttonLeft;
Button buttonRight;
Button buttonA;
Button buttonB;
// selected attack modes // selected attack modes
bool beaconSelected = false; bool beaconSelected = false;
bool deauthSelected = false; bool deauthSelected = false;
@@ -131,9 +135,6 @@ class DisplayUI {
String getChannel(); String getChannel();
// functions for buttons
bool updateButton(Button* button); // read and update
// draw functions // draw functions
void draw(); void draw();
void drawButtonTest(); void drawButtonTest();