Cleaned up display class & fixed timeout

This commit is contained in:
Stefan Kremser
2018-10-12 21:07:59 +02:00
parent 7610db9534
commit 763bff53d4
5 changed files with 1418 additions and 1421 deletions

View File

@@ -1137,10 +1137,10 @@ void CLI::runCommand(String input) {
// ===== SCREEN ===== // // ===== SCREEN ===== //
// screen mode <menu/packetmonitor/buttontest/loading> // screen mode <menu/packetmonitor/buttontest/loading>
else if (eqlsCMD(0, CLI_SCREEN) && eqlsCMD(1, CLI_MODE)) { else if (eqlsCMD(0, CLI_SCREEN) && eqlsCMD(1, CLI_MODE)) {
if (eqlsCMD(2, CLI_MODE_BUTTONTEST)) displayUI.mode = SCREEN_MODE_BUTTON_TEST; if (eqlsCMD(2, CLI_MODE_BUTTONTEST)) displayUI.mode = displayUI.DISPLAY_MODE::BUTTON_TEST;
else if (eqlsCMD(2, CLI_MODE_PACKETMONITOR)) displayUI.mode = SCREEN_MODE_PACKETMONITOR; else if (eqlsCMD(2, CLI_MODE_PACKETMONITOR)) displayUI.mode = displayUI.DISPLAY_MODE::PACKETMONITOR;
else if (eqlsCMD(2, CLI_MODE_LOADINGSCREEN)) displayUI.mode = SCREEN_MODE_LOADSCAN; else if (eqlsCMD(2, CLI_MODE_LOADINGSCREEN)) displayUI.mode = displayUI.DISPLAY_MODE::LOADSCAN;
else if (eqlsCMD(2, CLI_MODE_MENU)) displayUI.mode = SCREEN_MODE_MENU; else if (eqlsCMD(2, CLI_MODE_MENU)) displayUI.mode = displayUI.DISPLAY_MODE::MENU;
else parameterError(list->get(2)); else parameterError(list->get(2));
prntln(CLI_CHANGED_SCREEN); prntln(CLI_CHANGED_SCREEN);
} }

File diff suppressed because it is too large Load Diff

View File

@@ -1,12 +1,6 @@
#ifndef DisplayUI_h #ifndef DisplayUI_h
#define DisplayUI_h #define DisplayUI_h
#include "Arduino.h"
#include <ESP8266WiFi.h>
#include <FS.h>
extern "C" {
#include "user_interface.h"
}
#include "language.h" #include "language.h"
#include "A_config.h" #include "A_config.h"
#include "Settings.h" #include "Settings.h"
@@ -35,42 +29,27 @@ 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);
// fallback for the buttons
#ifndef BUTTON_UP #ifndef BUTTON_UP
#define BUTTON_UP 255 #define BUTTON_UP 255
#endif #endif // ifndef BUTTON_UP
#ifndef BUTTON_DOWN #ifndef BUTTON_DOWN
#define BUTTON_DOWN 255 #define BUTTON_DOWN 255
#endif #endif // ifndef BUTTON_DOWN
#ifndef BUTTON_A #ifndef BUTTON_A
#define BUTTON_A 255 #define BUTTON_A 255
#endif #endif // ifndef BUTTON_A
#ifndef BUTTON_B #ifndef BUTTON_B
#define BUTTON_B 255 #define BUTTON_B 255
#endif #endif // ifndef BUTTON_B
// different display modes
#define SCREEN_MODE_OFF 0
#define SCREEN_MODE_BUTTON_TEST 1
#define SCREEN_MODE_MENU 2
#define SCREEN_MODE_LOADSCAN 3
#define SCREEN_MODE_PACKETMONITOR 4
#define SCREEN_MODE_INTRO 5
// ===== adjustable ===== //
#define BUTTON_DELAY 280 // in ms
#define DRAW_INTERVAL 100 // 100ms = 10 FPS
#define SCROLL_SPEED 5
#define SCREEN_INTRO_TIME 2500
// ====================== //
struct MenuNode { struct MenuNode {
std::function<String()>getStr; // function used to create the displayed string 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()> click; // function that is executed when node is clicked
std::function<void()> hold; // function that is executed when node is pressed for > 800ms std::function<void()> hold; // function that is executed when node is pressed for > 800ms
}; };
struct Menu { struct Menu {
@@ -82,20 +61,26 @@ struct Menu {
class DisplayUI { class DisplayUI {
public: public:
Button* up = NULL; enum DISPLAY_MODE { OFF = 0, BUTTON_TEST = 1, MENU = 2, LOADSCAN = 3, PACKETMONITOR = 4, INTRO = 5 };
Button* down = NULL;
Button* a = NULL;
Button* b = NULL;
DisplayUI(); uint8_t mode = DISPLAY_MODE::MENU;
void setup();
#ifdef HIGHLIGHT_LED
void setupLED();
bool highlightLED = false; bool highlightLED = false;
#endif
Button* up = NULL;
Button* down = NULL;
Button* a = NULL;
Button* b = NULL;
// ===== adjustable ===== // // ===== adjustable ===== //
DEAUTHER_DISPLAY // see config.h
const uint8_t maxLen = 18;
const uint8_t lineHeight = 12;
const uint8_t scrollSpeed = 5;
const uint8_t buttonDelay = 250;
const uint8_t drawInterval = 100; // 100ms = 10 FPS
const uint16_t screenIntroTime = 2500;
void configInit(); void configInit();
void configOn(); void configOn();
void configOff(); void configOff();
@@ -104,58 +89,35 @@ 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 lineHeight = 12;
uint8_t scrollSpeed = 5;
// ====================== // // ====================== //
DisplayUI();
~DisplayUI();
void setup();
#ifdef HIGHLIGHT_LED
void setupLED();
#endif // ifdef HIGHLIGHT_LED
void update(); void update();
void on(); void on();
void off(); void off();
uint8_t mode = SCREEN_MODE_MENU;
private: private:
void setupDisplay(); int16_t selectedID = 0; // i.e. access point ID to draw the apMenu
void setupButtons(); uint16_t scrollCounter = 0; // for horizontal scrolling
uint32_t drawTime = 0; // last time a frame was drawn
uint32_t startTime = 0; // when the screen was enabled
uint32_t buttonTime = 0; // last time a button was pressed
int16_t selectedID = 0; // i.e. access point ID to draw the apMenu bool enabled = false; // display enabled
uint16_t scrollCounter = 0; // for horizontal scrolling bool tempOff = false;
uint32_t drawTime = 0; // last time a frame was drawn
uint32_t startTime = 0; // when the screen was enabled
uint32_t buttonTime = 0; // last time a button was pressed
bool enabled = false; // display enabled
// selected attack modes // selected attack modes
bool beaconSelected = false; bool beaconSelected = false;
bool deauthSelected = false; bool deauthSelected = false;
bool probeSelected = false; bool probeSelected = false;
String getChannel();
// draw functions
void draw();
void drawButtonTest();
void drawMenu();
void drawLoadingScan();
void drawPacketMonitor();
void drawIntro();
void clearMenu(Menu* menu);
// menu functions
void changeMenu(Menu* menu);
void goBack();
void createMenu(Menu* menu, Menu* parent, std::function<void()>build);
void addMenuNode(Menu* menu, std::function<String()>getStr, std::function<void()>click,
std::function<void()>hold);
void addMenuNode(Menu* menu, std::function<String()>getStr, std::function<void()>click);
void addMenuNode(Menu* menu, std::function<String()>getStr, Menu* next);
void addMenuNode(Menu* menu, const char* ptr, std::function<void()>click);
void addMenuNode(Menu* menu, const char* ptr, Menu* next);
// menus // menus
Menu* currentMenu; Menu* currentMenu;
@@ -174,6 +136,30 @@ class DisplayUI {
Menu stationMenu; Menu stationMenu;
Menu nameMenu; Menu nameMenu;
Menu ssidMenu; Menu ssidMenu;
void setupButtons();
String getChannel();
// draw functions
void draw();
void drawButtonTest();
void drawMenu();
void drawLoadingScan();
void drawPacketMonitor();
void drawIntro();
void clearMenu(Menu* menu);
// menu functions
void changeMenu(Menu* menu);
void goBack();
void createMenu(Menu* menu, Menu* parent, std::function<void()>build);
void addMenuNode(Menu* menu, std::function<String()>getStr, std::function<void()>click, std::function<void()>hold);
void addMenuNode(Menu* menu, std::function<String()>getStr, std::function<void()>click);
void addMenuNode(Menu* menu, std::function<String()>getStr, Menu* next);
void addMenuNode(Menu* menu, const char* ptr, std::function<void()>click);
void addMenuNode(Menu* menu, const char* ptr, Menu* next);
}; };
// ===== FONT ===== // // ===== FONT ===== //

View File

@@ -91,7 +91,7 @@ void setup() {
// start display // start display
if (settings.getDisplayInterface()) { if (settings.getDisplayInterface()) {
displayUI.setup(); displayUI.setup();
displayUI.mode = SCREEN_MODE_INTRO; displayUI.mode = displayUI.DISPLAY_MODE::INTRO;
} }
// copy web files to SPIFFS // copy web files to SPIFFS

View File

@@ -1,6 +1,8 @@
#ifndef language_h #ifndef language_h
#define language_h #define language_h
#include "Arduino.h"
extern String str(const char* ptr); extern String str(const char* ptr);
extern String keyword(const char* keywordPtr); extern String keyword(const char* keywordPtr);
extern bool eqls(const char* str, const char* keywordPtr); extern bool eqls(const char* str, const char* keywordPtr);