Actually made settings work

This commit is contained in:
Just Call Me Koko
2022-01-18 03:29:45 -05:00
parent 373482822a
commit 8e874c493b
5 changed files with 2567 additions and 2464 deletions

View File

@@ -1,204 +1,204 @@
#ifndef Display_h #ifndef Display_h
#define Display_h #define Display_h
#include <FS.h> #include <FS.h>
#include <functional> #include <functional>
#include <JPEGDecoder.h> #include <JPEGDecoder.h>
//#include <SimpleList.h> //#include <SimpleList.h>
#include <LinkedList.h> #include <LinkedList.h>
#include <SPI.h> #include <SPI.h>
#include <lvgl.h> #include <lvgl.h>
#include <Ticker.h> #include <Ticker.h>
//#include <M5Stack.h> //#include <M5Stack.h>
#include "SPIFFS.h" #include "SPIFFS.h"
#include "Assets.h" #include "Assets.h"
#include <TFT_eSPI.h> #include <TFT_eSPI.h>
#define TFT_MISO 19 #define TFT_MISO 19
#define TFT_MOSI 23 #define TFT_MOSI 23
#define TFT_SCLK 18 #define TFT_SCLK 18
#define TFT_CS 27 #define TFT_CS 27
#define TFT_DC 26 #define TFT_DC 26
#define TFT_RST 5 #define TFT_RST 5
#define TFT_BL 32 #define TFT_BL 32
#define TOUCH_CS 21 #define TOUCH_CS 21
#define SD_CS 4 #define SD_CS 4
// WiFi stuff // WiFi stuff
#define OTA_UPDATE 100 #define OTA_UPDATE 100
#define SHOW_INFO 101 #define SHOW_INFO 101
#define WIFI_SCAN_OFF 0 #define WIFI_SCAN_OFF 0
#define WIFI_SCAN_PROBE 1 #define WIFI_SCAN_PROBE 1
#define WIFI_SCAN_AP 2 #define WIFI_SCAN_AP 2
#define WIFI_SCAN_PWN 3 #define WIFI_SCAN_PWN 3
#define WIFI_SCAN_EAPOL 4 #define WIFI_SCAN_EAPOL 4
#define WIFI_SCAN_DEAUTH 5 #define WIFI_SCAN_DEAUTH 5
#define WIFI_SCAN_ALL 6 #define WIFI_SCAN_ALL 6
#define WIFI_PACKET_MONITOR 7 #define WIFI_PACKET_MONITOR 7
#define WIFI_ATTACK_BEACON_SPAM 8 #define WIFI_ATTACK_BEACON_SPAM 8
#define WIFI_ATTACK_RICK_ROLL 9 #define WIFI_ATTACK_RICK_ROLL 9
#define BT_SCAN_ALL 10 #define BT_SCAN_ALL 10
#define BT_SCAN_SKIMMERS 11 #define BT_SCAN_SKIMMERS 11
#define WIFI_SCAN_ESPRESSIF 12 #define WIFI_SCAN_ESPRESSIF 12
#define LV_JOIN_WIFI 13 #define LV_JOIN_WIFI 13
#define LV_ADD_SSID 14 #define LV_ADD_SSID 14
#define WIFI_ATTACK_BEACON_LIST 15 #define WIFI_ATTACK_BEACON_LIST 15
//#define TFT_SHIELD //#define TFT_SHIELD
#define TFT_DIY #define TFT_DIY
//#define KIT #define KIT
#define SCREEN_WIDTH 240 #define SCREEN_WIDTH 240
#define SCREEN_HEIGHT 320 #define SCREEN_HEIGHT 320
#define HEIGHT_1 240 #define HEIGHT_1 240
#define WIDTH_1 320 #define WIDTH_1 320
#define STANDARD_FONT_CHAR_LIMIT 40 // number of characters on a single line with normal font #define STANDARD_FONT_CHAR_LIMIT 40 // number of characters on a single line with normal font
#define TEXT_HEIGHT 16 // Height of text to be printed and scrolled #define TEXT_HEIGHT 16 // Height of text to be printed and scrolled
#define BOT_FIXED_AREA 0 // Number of lines in bottom fixed area (lines counted from bottom of screen) #define BOT_FIXED_AREA 0 // Number of lines in bottom fixed area (lines counted from bottom of screen)
#define TOP_FIXED_AREA 48 // Number of lines in top fixed area (lines counted from top of screen) #define TOP_FIXED_AREA 48 // Number of lines in top fixed area (lines counted from top of screen)
#define YMAX 320 // Bottom of screen area #define YMAX 320 // Bottom of screen area
#define minimum(a,b) (((a) < (b)) ? (a) : (b)) #define minimum(a,b) (((a) < (b)) ? (a) : (b))
//#define MENU_FONT NULL //#define MENU_FONT NULL
#define MENU_FONT &FreeMono9pt7b // Winner #define MENU_FONT &FreeMono9pt7b // Winner
//#define MENU_FONT &FreeMonoBold9pt7b //#define MENU_FONT &FreeMonoBold9pt7b
//#define MENU_FONT &FreeSans9pt7b //#define MENU_FONT &FreeSans9pt7b
//#define MENU_FONT &FreeSansBold9pt7b //#define MENU_FONT &FreeSansBold9pt7b
#define BUTTON_ARRAY_LEN 9 #define BUTTON_ARRAY_LEN 9
#define STATUS_BAR_WIDTH 16 #define STATUS_BAR_WIDTH 16
#define LVGL_TICK_PERIOD 6 #define LVGL_TICK_PERIOD 6
#define FRAME_X 100 #define FRAME_X 100
#define FRAME_Y 64 #define FRAME_Y 64
#define FRAME_W 120 #define FRAME_W 120
#define FRAME_H 50 #define FRAME_H 50
// Red zone size // Red zone size
#define REDBUTTON_X FRAME_X #define REDBUTTON_X FRAME_X
#define REDBUTTON_Y FRAME_Y #define REDBUTTON_Y FRAME_Y
#define REDBUTTON_W (FRAME_W/2) #define REDBUTTON_W (FRAME_W/2)
#define REDBUTTON_H FRAME_H #define REDBUTTON_H FRAME_H
// Green zone size // Green zone size
#define GREENBUTTON_X (REDBUTTON_X + REDBUTTON_W) #define GREENBUTTON_X (REDBUTTON_X + REDBUTTON_W)
#define GREENBUTTON_Y FRAME_Y #define GREENBUTTON_Y FRAME_Y
#define GREENBUTTON_W (FRAME_W/2) #define GREENBUTTON_W (FRAME_W/2)
#define GREENBUTTON_H FRAME_H #define GREENBUTTON_H FRAME_H
#define STATUSBAR_COLOR 0x4A49 #define STATUSBAR_COLOR 0x4A49
#define KIT_LED_BUILTIN 13 #define KIT_LED_BUILTIN 13
/* /*
PROGMEM void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p); PROGMEM void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p);
PROGMEM bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data); PROGMEM bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data);
PROGMEM static lv_disp_buf_t disp_buf; PROGMEM static lv_disp_buf_t disp_buf;
PROGMEM static lv_color_t buf[LV_HOR_RES_MAX * 10]; PROGMEM static lv_color_t buf[LV_HOR_RES_MAX * 10];
PROGMEM static void ta_event_cb(lv_obj_t * ta, lv_event_t event); PROGMEM static void ta_event_cb(lv_obj_t * ta, lv_event_t event);
PROGMEM static void keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event); PROGMEM static void keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event);
// lvgl stuff // lvgl stuff
PROGMEM static lv_obj_t *kb; PROGMEM static lv_obj_t *kb;
*/ */
class Display class Display
{ {
private: private:
bool SwitchOn = false; bool SwitchOn = false;
bool run_setup = true; bool run_setup = true;
// For the byte we read from the serial port // For the byte we read from the serial port
byte data = 0; byte data = 0;
// A few test variables used during debugging // A few test variables used during debugging
boolean change_colour = 1; boolean change_colour = 1;
boolean selected = 1; boolean selected = 1;
void drawFrame(); void drawFrame();
//void addNodes(Menu* menu, String name, Menu* child, std::function<void()> callable); //void addNodes(Menu* menu, String name, Menu* child, std::function<void()> callable);
//void changeMenu(Menu* menu); //void changeMenu(Menu* menu);
//void showMenuList(Menu* menu, int layer); //void showMenuList(Menu* menu, int layer);
//static void lv_tick_handler(); //static void lv_tick_handler();
public: public:
Display(); Display();
//Ticker tick; //Ticker tick;
TFT_eSPI tft = TFT_eSPI(); TFT_eSPI tft = TFT_eSPI();
TFT_eSprite img = TFT_eSprite(&tft); TFT_eSprite img = TFT_eSprite(&tft);
TFT_eSPI_Button key[BUTTON_ARRAY_LEN]; TFT_eSPI_Button key[BUTTON_ARRAY_LEN];
const String PROGMEM version_number = "v0.9.3"; const String PROGMEM version_number = "v0.9.4";
bool printing = false; bool printing = false;
bool loading = false; bool loading = false;
bool tteBar = false; bool tteBar = false;
bool draw_tft = false; bool draw_tft = false;
bool exit_draw = false; bool exit_draw = false;
int TOP_FIXED_AREA_2 = 48; int TOP_FIXED_AREA_2 = 48;
int print_delay_1, print_delay_2 = 10; int print_delay_1, print_delay_2 = 10;
int current_banner_pos = SCREEN_WIDTH; int current_banner_pos = SCREEN_WIDTH;
//Menu* current_menu; //Menu* current_menu;
//Menu mainMenu; //Menu mainMenu;
//Menu wifiMenu; //Menu wifiMenu;
//Menu bluetoothMenu; //Menu bluetoothMenu;
LinkedList<String>* display_buffer; LinkedList<String>* display_buffer;
// The initial y coordinate of the top of the bottom text line // The initial y coordinate of the top of the bottom text line
uint16_t yDraw = YMAX - BOT_FIXED_AREA - TEXT_HEIGHT; uint16_t yDraw = YMAX - BOT_FIXED_AREA - TEXT_HEIGHT;
// Keep track of the drawing x coordinate // Keep track of the drawing x coordinate
uint16_t xPos = 0; uint16_t xPos = 0;
// The initial y coordinate of the top of the scrolling area // The initial y coordinate of the top of the scrolling area
uint16_t yStart = TOP_FIXED_AREA_2; uint16_t yStart = TOP_FIXED_AREA_2;
// yArea must be a integral multiple of TEXT_HEIGHT // yArea must be a integral multiple of TEXT_HEIGHT
uint16_t yArea = YMAX - TOP_FIXED_AREA_2 - BOT_FIXED_AREA; uint16_t yArea = YMAX - TOP_FIXED_AREA_2 - BOT_FIXED_AREA;
// We have to blank the top line each time the display is scrolled, but this takes up to 13 milliseconds // We have to blank the top line each time the display is scrolled, but this takes up to 13 milliseconds
// for a full width line, meanwhile the serial buffer may be filling... and overflowing // for a full width line, meanwhile the serial buffer may be filling... and overflowing
// We can speed up scrolling of short text lines by just blanking the character we drew // We can speed up scrolling of short text lines by just blanking the character we drew
int blank[19]; // We keep all the strings pixel lengths to optimise the speed of the top line blanking int blank[19]; // We keep all the strings pixel lengths to optimise the speed of the top line blanking
//void initLVGL(); //void initLVGL();
//void deinitLVGL(); //void deinitLVGL();
//void joinWiFiGFX(); //void joinWiFiGFX();
void tftDrawRedOnOffButton(); void tftDrawRedOnOffButton();
void tftDrawGreenOnOffButton(); void tftDrawGreenOnOffButton();
void tftDrawGraphObjects(byte x_scale); void tftDrawGraphObjects(byte x_scale);
void tftDrawEapolColorKey(); void tftDrawEapolColorKey();
void tftDrawColorKey(); void tftDrawColorKey();
void tftDrawXScaleButtons(byte x_scale); void tftDrawXScaleButtons(byte x_scale);
void tftDrawYScaleButtons(byte y_scale); void tftDrawYScaleButtons(byte y_scale);
void tftDrawChannelScaleButtons(int set_channel); void tftDrawChannelScaleButtons(int set_channel);
void tftDrawExitScaleButtons(); void tftDrawExitScaleButtons();
void buildBanner(String msg, int xpos); void buildBanner(String msg, int xpos);
void clearScreen(); void clearScreen();
void displayBuffer(bool do_clear = false); void displayBuffer(bool do_clear = false);
void drawJpeg(const char *filename, int xpos, int ypos); void drawJpeg(const char *filename, int xpos, int ypos);
void setupDraw(); void setupDraw();
void drawStylus(); void drawStylus();
void getTouchWhileFunction(bool pressed); void getTouchWhileFunction(bool pressed);
void initScrollValues(bool tte = false); void initScrollValues(bool tte = false);
void jpegInfo(); void jpegInfo();
void jpegRender(int xpos, int ypos); void jpegRender(int xpos, int ypos);
void listDir(fs::FS &fs, const char * dirname, uint8_t levels); void listDir(fs::FS &fs, const char * dirname, uint8_t levels);
void listFiles(); void listFiles();
void main(uint8_t scan_mode); void main(uint8_t scan_mode);
void RunSetup(); void RunSetup();
void scrollAddress(uint16_t vsp); void scrollAddress(uint16_t vsp);
int scroll_line(uint32_t color); int scroll_line(uint32_t color);
void setupScrollArea(uint16_t tfa, uint16_t bfa); void setupScrollArea(uint16_t tfa, uint16_t bfa);
void showCenterText(String text, int y); void showCenterText(String text, int y);
void touchToExit(); void touchToExit();
void twoPartDisplay(String center_text); void twoPartDisplay(String center_text);
void updateBanner(String msg); void updateBanner(String msg);
}; };
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,215 +1,217 @@
#ifndef MenuFunctions_h #ifndef MenuFunctions_h
#define MenuFunctions_h #define MenuFunctions_h
#define BATTERY_ANALOG_ON 0 #define BATTERY_ANALOG_ON 0
#include "WiFiScan.h" #include "WiFiScan.h"
#include "Display.h" #include "Display.h"
#include "BatteryInterface.h" #include "BatteryInterface.h"
#include "SDInterface.h" #include "SDInterface.h"
#include "Web.h" #include "Web.h"
#include "esp_interface.h" #include "esp_interface.h"
#include "a32u4_interface.h" #include "a32u4_interface.h"
#include "settings.h" #include "settings.h"
extern Display display_obj; extern Display display_obj;
extern WiFiScan wifi_scan_obj; extern WiFiScan wifi_scan_obj;
extern Web web_obj; extern Web web_obj;
extern SDInterface sd_obj; extern SDInterface sd_obj;
extern BatteryInterface battery_obj; extern BatteryInterface battery_obj;
extern EspInterface esp_obj; extern EspInterface esp_obj;
extern A32u4Interface a32u4_obj; extern A32u4Interface a32u4_obj;
extern Settings settings_obj; extern Settings settings_obj;
// Keypad start position, key sizes and spacing // Keypad start position, key sizes and spacing
#define KEY_X 120 // Centre of key #define KEY_X 120 // Centre of key
#define KEY_Y 50 #define KEY_Y 50
#define KEY_W 240 // Width and height #define KEY_W 240 // Width and height
#define KEY_H 22 #define KEY_H 22
#define KEY_SPACING_X 0 // X and Y gap #define KEY_SPACING_X 0 // X and Y gap
#define KEY_SPACING_Y 1 #define KEY_SPACING_Y 1
#define KEY_TEXTSIZE 1 // Font size multiplier #define KEY_TEXTSIZE 1 // Font size multiplier
#define ICON_W 22 #define ICON_W 22
#define ICON_H 22 #define ICON_H 22
#define BUTTON_PADDING 22 #define BUTTON_PADDING 22
//#define BUTTON_ARRAY_LEN 5 //#define BUTTON_ARRAY_LEN 5
#define FLASH_BUTTON 0 #define FLASH_BUTTON 0
#if BATTERY_ANALOG_ON == 1 #if BATTERY_ANALOG_ON == 1
#define BATTERY_PIN 13 #define BATTERY_PIN 13
#define ANALOG_PIN 34 #define ANALOG_PIN 34
#define CHARGING_PIN 27 #define CHARGING_PIN 27
#endif #endif
// Icon definitions // Icon definitions
#define ATTACKS 0 #define ATTACKS 0
#define BEACON_SNIFF 1 #define BEACON_SNIFF 1
#define BLUETOOTH 2 #define BLUETOOTH 2
#define BLUETOOTH_SNIFF 3 #define BLUETOOTH_SNIFF 3
#define DEAUTH_SNIFF 4 #define DEAUTH_SNIFF 4
#define DRAW 5 #define DRAW 5
#define PACKET_MONITOR 6 #define PACKET_MONITOR 6
#define PROBE_SNIFF 7 #define PROBE_SNIFF 7
#define SCANNERS 8 #define SCANNERS 8
#define CC_SKIMMERS 9 #define CC_SKIMMERS 9
#define SNIFFERS 10 #define SNIFFERS 10
#define WIFI 11 #define WIFI 11
#define BEACON_SPAM 12 #define BEACON_SPAM 12
#define RICK_ROLL 13 #define RICK_ROLL 13
#define REBOOT 14 #define REBOOT 14
#define GENERAL_APPS 15 #define GENERAL_APPS 15
#define UPDATE 16 #define UPDATE 16
#define DEVICE 17 #define DEVICE 17
#define DEVICE_INFO 18 #define DEVICE_INFO 18
#define SD_UPDATE 19 #define SD_UPDATE 19
#define WEB_UPDATE 20 #define WEB_UPDATE 20
#define EAPOL 21 #define EAPOL 21
#define STATUS_BAT 22 #define STATUS_BAT 22
#define STATUS_SD 23 #define STATUS_SD 23
#define PWNAGOTCHI 24 #define PWNAGOTCHI 24
#define ESPRESSIF 25 #define ESPRESSIF 25
#define SHUTDOWN 26 #define SHUTDOWN 26
#define BEACON_LIST 27 #define BEACON_LIST 27
#define GENERATE 28 #define GENERATE 28
#define CLEAR_ICO 29 #define CLEAR_ICO 29
#define KEYBOARD_ICO 30 #define KEYBOARD_ICO 30
#define JOIN_WIFI 31 #define JOIN_WIFI 31
#define ESP_UPDATE_ICO 32 #define ESP_UPDATE_ICO 32
#define BAD_USB_ICO 33 #define BAD_USB_ICO 33
#define TEST_BAD_USB_ICO 34 #define TEST_BAD_USB_ICO 34
PROGMEM void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p); PROGMEM void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p);
PROGMEM bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data); PROGMEM bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data);
PROGMEM static lv_disp_buf_t disp_buf; PROGMEM static lv_disp_buf_t disp_buf;
PROGMEM static lv_color_t buf[LV_HOR_RES_MAX * 10]; PROGMEM static lv_color_t buf[LV_HOR_RES_MAX * 10];
PROGMEM static void ta_event_cb(lv_obj_t * ta, lv_event_t event); PROGMEM static void ta_event_cb(lv_obj_t * ta, lv_event_t event);
PROGMEM static void join_wifi_keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event); PROGMEM static void join_wifi_keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event);
PROGMEM static void add_ssid_keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event); PROGMEM static void add_ssid_keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event);
PROGMEM static void write_bad_usb_keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event); PROGMEM static void write_bad_usb_keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event);
PROGMEM static void load_btn_cb(lv_obj_t * load_btn, lv_event_t event); PROGMEM static void load_btn_cb(lv_obj_t * load_btn, lv_event_t event);
PROGMEM static void test_btn_cb(lv_obj_t * load_btn, lv_event_t event); PROGMEM static void test_btn_cb(lv_obj_t * load_btn, lv_event_t event);
PROGMEM static void ap_list_cb(lv_obj_t * btn, lv_event_t event); PROGMEM static void ap_list_cb(lv_obj_t * btn, lv_event_t event);
PROGMEM static void setting_dropdown_cb(lv_obj_t * btn, lv_event_t event); PROGMEM static void setting_dropdown_cb(lv_obj_t * btn, lv_event_t event);
PROGMEM static void save_as_keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event); PROGMEM static void save_as_keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event);
// lvgl stuff // lvgl stuff
PROGMEM static lv_obj_t *kb; PROGMEM static lv_obj_t *kb;
PROGMEM static lv_obj_t * save_as_kb; PROGMEM static lv_obj_t * save_as_kb;
struct Menu; struct Menu;
// Individual Nodes of a menu // Individual Nodes of a menu
struct MenuNode { struct MenuNode {
String name; String name;
uint16_t color; uint16_t color;
int icon; int icon;
TFT_eSPI_Button* button; TFT_eSPI_Button* button;
std::function<void()> callable; bool selected;
}; std::function<void()> callable;
};
// Full Menus
struct Menu { // Full Menus
String name; struct Menu {
LinkedList<MenuNode>* list; String name;
Menu * parentMenu; LinkedList<MenuNode>* list;
//uint8_t selected; Menu * parentMenu;
}; //uint8_t selected;
};
class MenuFunctions
{ class MenuFunctions
private: {
private:
String u_result = "";
String u_result = "";
uint32_t initTime = 0;
uint32_t initTime = 0;
//Menu* current_menu;
//Menu* current_menu;
// Main menu stuff
Menu mainMenu; // Main menu stuff
Menu mainMenu;
Menu wifiMenu;
Menu bluetoothMenu; Menu wifiMenu;
Menu badusbMenu; Menu bluetoothMenu;
Menu generalMenu; Menu badusbMenu;
Menu deviceMenu; Menu generalMenu;
Menu deviceMenu;
// Device menu stuff
Menu whichUpdateMenu; // Device menu stuff
Menu failedUpdateMenu; Menu whichUpdateMenu;
Menu confirmMenu; Menu failedUpdateMenu;
Menu espUpdateMenu; Menu confirmMenu;
Menu updateMenu; Menu espUpdateMenu;
Menu settingsMenu; Menu updateMenu;
Menu specSettingMenu; Menu settingsMenu;
Menu infoMenu; Menu specSettingMenu;
Menu infoMenu;
// WiFi menu stuff
Menu wifiSnifferMenu; // WiFi menu stuff
Menu wifiAttackMenu; Menu wifiSnifferMenu;
Menu wifiGeneralMenu; Menu wifiAttackMenu;
Menu wifiGeneralMenu;
// Bluetooth menu stuff
Menu bluetoothSnifferMenu; // Bluetooth menu stuff
Menu bluetoothGeneralMenu; Menu bluetoothSnifferMenu;
Menu bluetoothGeneralMenu;
// Settings things menus
Menu shutdownWiFiMenu; // Settings things menus
Menu shutdownBLEMenu; Menu shutdownWiFiMenu;
Menu generateSSIDsMenu; Menu shutdownBLEMenu;
Menu clearSSIDsMenu; Menu generateSSIDsMenu;
Menu clearAPsMenu; Menu clearSSIDsMenu;
Menu clearAPsMenu;
static void lv_tick_handler();
static void lv_tick_handler();
// Menu icons
// Menu icons
//TFT_eSPI_Button key[BUTTON_ARRAY_LEN];
//TFT_eSPI_Button key[BUTTON_ARRAY_LEN];
void addNodes(Menu* menu, String name, uint16_t color, Menu* child, int place, std::function<void()> callable);
void drawStatusBar(); void addNodes(Menu* menu, String name, uint16_t color, Menu* child, int place, std::function<void()> callable, bool selected = false);
void updateStatusBar(); void drawStatusBar();
void battery(bool initial = false); void updateStatusBar();
void battery2(bool initial = false); void battery(bool initial = false);
void showMenuList(Menu* menu, int layer); void battery2(bool initial = false);
void callSetting(String key); void showMenuList(Menu* menu, int layer);
void runBoolSetting(String ley); String callSetting(String key);
void runBoolSetting(String ley);
public: void displaySetting(String key);
MenuFunctions();
public:
Menu* current_menu; MenuFunctions();
Ticker tick; Menu* current_menu;
uint16_t x = -1, y = -1; Ticker tick;
boolean pressed = false;
uint16_t x = -1, y = -1;
String loaded_file = ""; boolean pressed = false;
void initLVGL(); String loaded_file = "";
void deinitLVGL();
void joinWiFiGFX(); void initLVGL();
void addSSIDGFX(); void deinitLVGL();
void addAPGFX(); void joinWiFiGFX();
void displaySettingsGFX(); void addSSIDGFX();
void writeBadUSB(); void addAPGFX();
void displaySettingsGFX();
void buildButtons(Menu* menu); void writeBadUSB();
void changeMenu(Menu* menu);
void displayCurrentMenu(); void buildButtons(Menu* menu);
void main(uint32_t currentTime); void changeMenu(Menu* menu);
void RunSetup(); void displayCurrentMenu();
void orientDisplay(); void main(uint32_t currentTime);
}; void RunSetup();
void orientDisplay();
};
#endif
#endif

View File

@@ -1,234 +1,304 @@
#include "settings.h" #include "settings.h"
String Settings::getSettingsString() { String Settings::getSettingsString() {
return this->json_settings_string; return this->json_settings_string;
} }
bool Settings::begin() { bool Settings::begin() {
if(!SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED)){ if(!SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED)){
Serial.println("Settings SPIFFS Mount Failed"); Serial.println("Settings SPIFFS Mount Failed");
return false; return false;
} }
File settingsFile; File settingsFile;
//SPIFFS.remove("/settings.json"); // NEED TO REMOVE THIS LINE //SPIFFS.remove("/settings.json"); // NEED TO REMOVE THIS LINE
if (SPIFFS.exists("/settings.json")) { if (SPIFFS.exists("/settings.json")) {
settingsFile = SPIFFS.open("/settings.json", FILE_READ); settingsFile = SPIFFS.open("/settings.json", FILE_READ);
if (!settingsFile) { if (!settingsFile) {
settingsFile.close(); settingsFile.close();
Serial.println(F("Could not find settings file")); Serial.println(F("Could not find settings file"));
if (this->createDefaultSettings(SPIFFS)) if (this->createDefaultSettings(SPIFFS))
return true; return true;
else else
return false; return false;
} }
} }
else { else {
Serial.println("Settings file does not exist"); Serial.println("Settings file does not exist");
if (this->createDefaultSettings(SPIFFS)) if (this->createDefaultSettings(SPIFFS))
return true; return true;
else else
return false; return false;
} }
String json_string; String json_string;
DynamicJsonDocument jsonBuffer(1024); DynamicJsonDocument jsonBuffer(1024);
DeserializationError error = deserializeJson(jsonBuffer, settingsFile); DeserializationError error = deserializeJson(jsonBuffer, settingsFile);
serializeJson(jsonBuffer, json_string); serializeJson(jsonBuffer, json_string);
Serial.println("Settings: " + (String)json_string + "\n"); Serial.println("Settings: " + (String)json_string + "\n");
this->printJsonSettings(json_string); this->printJsonSettings(json_string);
this->json_settings_string = json_string; this->json_settings_string = json_string;
return true; return true;
} }
template <typename T> template <typename T>
T Settings::loadSetting(String key) {} T Settings::loadSetting(String key) {}
// Get type int settings // Get type int settings
template<> template<>
int Settings::loadSetting<int>(String key) { int Settings::loadSetting<int>(String key) {
DynamicJsonDocument json(1024); // ArduinoJson v6 DynamicJsonDocument json(1024); // ArduinoJson v6
if (deserializeJson(json, this->json_settings_string)) { if (deserializeJson(json, this->json_settings_string)) {
Serial.println("\nCould not parse json"); Serial.println("\nCould not parse json");
} }
for (int i = 0; i < json["Settings"].size(); i++) { for (int i = 0; i < json["Settings"].size(); i++) {
if (json["Settings"][i]["name"].as<String>() == key) if (json["Settings"][i]["name"].as<String>() == key)
return json["Settings"][i]["value"]; return json["Settings"][i]["value"];
} }
return 0; return 0;
} }
// Get type string settings // Get type string settings
template<> template<>
String Settings::loadSetting<String>(String key) { String Settings::loadSetting<String>(String key) {
//return this->json_settings_string; //return this->json_settings_string;
DynamicJsonDocument json(1024); // ArduinoJson v6 DynamicJsonDocument json(1024); // ArduinoJson v6
if (deserializeJson(json, this->json_settings_string)) { if (deserializeJson(json, this->json_settings_string)) {
Serial.println("\nCould not parse json"); Serial.println("\nCould not parse json");
} }
for (int i = 0; i < json["Settings"].size(); i++) { for (int i = 0; i < json["Settings"].size(); i++) {
if (json["Settings"][i]["name"].as<String>() == key) if (json["Settings"][i]["name"].as<String>() == key)
return json["Settings"][i]["value"]; return json["Settings"][i]["value"];
} }
return ""; return "";
} }
// Get type bool settings // Get type bool settings
template<> template<>
bool Settings::loadSetting<bool>(String key) { bool Settings::loadSetting<bool>(String key) {
DynamicJsonDocument json(1024); // ArduinoJson v6 DynamicJsonDocument json(1024); // ArduinoJson v6
if (deserializeJson(json, this->json_settings_string)) { if (deserializeJson(json, this->json_settings_string)) {
Serial.println("\nCould not parse json"); Serial.println("\nCould not parse json");
} }
for (int i = 0; i < json["Settings"].size(); i++) { for (int i = 0; i < json["Settings"].size(); i++) {
if (json["Settings"][i]["name"].as<String>() == key) if (json["Settings"][i]["name"].as<String>() == key)
return json["Settings"][i]["value"]; return json["Settings"][i]["value"];
} }
return false; return false;
} }
//Get type uint8_t settings //Get type uint8_t settings
template<> template<>
uint8_t Settings::loadSetting<uint8_t>(String key) { uint8_t Settings::loadSetting<uint8_t>(String key) {
DynamicJsonDocument json(1024); // ArduinoJson v6 DynamicJsonDocument json(1024); // ArduinoJson v6
if (deserializeJson(json, this->json_settings_string)) { if (deserializeJson(json, this->json_settings_string)) {
Serial.println("\nCould not parse json"); Serial.println("\nCould not parse json");
} }
for (int i = 0; i < json["Settings"].size(); i++) { for (int i = 0; i < json["Settings"].size(); i++) {
if (json["Settings"][i]["name"].as<String>() == key) if (json["Settings"][i]["name"].as<String>() == key)
return json["Settings"][i]["value"]; return json["Settings"][i]["value"];
} }
return 0; return 0;
} }
String Settings::setting_index_to_name(int i) { template <typename T>
DynamicJsonDocument json(1024); // ArduinoJson v6 T Settings::saveSetting(String key, bool value) {}
if (deserializeJson(json, this->json_settings_string)) { template<>
Serial.println("\nCould not parse json"); bool Settings::saveSetting<bool>(String key, bool value) {
} DynamicJsonDocument json(1024); // ArduinoJson v6
return json["Settings"][i]["name"]; if (deserializeJson(json, this->json_settings_string)) {
} Serial.println("\nCould not parse json");
}
int Settings::getNumberSettings() {
DynamicJsonDocument json(1024); // ArduinoJson v6 String settings_string;
if (deserializeJson(json, this->json_settings_string)) { for (int i = 0; i < json["Settings"].size(); i++) {
Serial.println("\nCould not parse json"); if (json["Settings"][i]["name"].as<String>() == key) {
} json["Settings"][i]["value"] = value;
return json["Settings"].size(); Serial.println("Saving setting...");
}
File settingsFile = SPIFFS.open("/settings.json", FILE_WRITE);
String Settings::getSettingType(String key) {
DynamicJsonDocument json(1024); // ArduinoJson v6 if (!settingsFile) {
Serial.println(F("Failed to create settings file"));
if (deserializeJson(json, this->json_settings_string)) { return false;
Serial.println("\nCould not parse json"); }
}
if (serializeJson(json, settingsFile) == 0) {
for (int i = 0; i < json["Settings"].size(); i++) { Serial.println(F("Failed to write to file"));
if (json["Settings"][i]["name"].as<String>() == key) }
return json["Settings"][i]["type"]; if (serializeJson(json, settings_string) == 0) {
} Serial.println(F("Failed to write to string"));
} }
void Settings::printJsonSettings(String json_string) { // Close the file
DynamicJsonDocument json(1024); // ArduinoJson v6 settingsFile.close();
if (deserializeJson(json, json_string)) { this->json_settings_string = settings_string;
Serial.println("\nCould not parse json");
} this->printJsonSettings(settings_string);
Serial.println("Settings\n----------------------------------------------"); return true;
for (int i = 0; i < json["Settings"].size(); i++) { }
Serial.println("Name: " + json["Settings"][i]["name"].as<String>()); }
Serial.println("Type: " + json["Settings"][i]["type"].as<String>()); }
Serial.println("Value: " + json["Settings"][i]["value"].as<String>());
Serial.println("----------------------------------------------"); bool Settings::toggleSetting(String key) {
} DynamicJsonDocument json(1024); // ArduinoJson v6
}
if (deserializeJson(json, this->json_settings_string)) {
bool Settings::createDefaultSettings(fs::FS &fs) { Serial.println("\nCould not parse json");
Serial.println(F("Creating default settings file: settings.json")); }
File settingsFile = fs.open("/settings.json", FILE_WRITE); for (int i = 0; i < json["Settings"].size(); i++) {
if (json["Settings"][i]["name"].as<String>() == key) {
if (!settingsFile) { if (json["Settings"][i]["value"]) {
Serial.println(F("Failed to create settings file")); saveSetting<bool>(key, false);
return false; Serial.println("Setting value to false");
} return false;
}
DynamicJsonDocument jsonBuffer(1024); else {
String settings_string; saveSetting<bool>(key, true);
Serial.println("Setting value to true");
jsonBuffer["Settings"][0]["name"] = "Channel"; return true;
jsonBuffer["Settings"][0]["type"] = "uint8_t"; }
jsonBuffer["Settings"][0]["value"] = 11;
jsonBuffer["Settings"][0]["range"]["min"] = 1; return false;
jsonBuffer["Settings"][0]["range"]["max"] = 14; }
}
jsonBuffer["Settings"][1]["name"] = "Channel Hop Delay"; }
jsonBuffer["Settings"][1]["type"] = "int";
jsonBuffer["Settings"][1]["value"] = 1; String Settings::setting_index_to_name(int i) {
jsonBuffer["Settings"][1]["range"]["min"] = 1; DynamicJsonDocument json(1024); // ArduinoJson v6
jsonBuffer["Settings"][1]["range"]["max"] = 10;
if (deserializeJson(json, this->json_settings_string)) {
jsonBuffer["Settings"][2]["name"] = "Force PMKID"; Serial.println("\nCould not parse json");
jsonBuffer["Settings"][2]["type"] = "bool"; }
jsonBuffer["Settings"][2]["value"] = true;
jsonBuffer["Settings"][2]["range"]["min"] = false; return json["Settings"][i]["name"];
jsonBuffer["Settings"][2]["range"]["max"] = true; }
jsonBuffer["Settings"][3]["name"] = "Force Probe"; int Settings::getNumberSettings() {
jsonBuffer["Settings"][3]["type"] = "bool"; DynamicJsonDocument json(1024); // ArduinoJson v6
jsonBuffer["Settings"][3]["value"] = true;
jsonBuffer["Settings"][3]["range"]["min"] = false; if (deserializeJson(json, this->json_settings_string)) {
jsonBuffer["Settings"][3]["range"]["max"] = true; Serial.println("\nCould not parse json");
}
jsonBuffer["Settings"][4]["name"] = "Save PCAP";
jsonBuffer["Settings"][4]["type"] = "bool"; return json["Settings"].size();
jsonBuffer["Settings"][4]["value"] = true; }
jsonBuffer["Settings"][4]["range"]["min"] = false;
jsonBuffer["Settings"][4]["range"]["max"] = true; String Settings::getSettingType(String key) {
DynamicJsonDocument json(1024); // ArduinoJson v6
//jsonBuffer.printTo(settingsFile);
if (serializeJson(jsonBuffer, settingsFile) == 0) { if (deserializeJson(json, this->json_settings_string)) {
Serial.println(F("Failed to write to file")); Serial.println("\nCould not parse json");
} }
if (serializeJson(jsonBuffer, settings_string) == 0) {
Serial.println(F("Failed to write to string")); for (int i = 0; i < json["Settings"].size(); i++) {
} if (json["Settings"][i]["name"].as<String>() == key)
return json["Settings"][i]["type"];
// Close the file }
settingsFile.close(); }
this->json_settings_string = settings_string; void Settings::printJsonSettings(String json_string) {
DynamicJsonDocument json(1024); // ArduinoJson v6
this->printJsonSettings(settings_string);
if (deserializeJson(json, json_string)) {
return true; Serial.println("\nCould not parse json");
} }
void Settings::main(uint32_t currentTime) { Serial.println("Settings\n----------------------------------------------");
for (int i = 0; i < json["Settings"].size(); i++) {
} Serial.println("Name: " + json["Settings"][i]["name"].as<String>());
Serial.println("Type: " + json["Settings"][i]["type"].as<String>());
Serial.println("Value: " + json["Settings"][i]["value"].as<String>());
Serial.println("----------------------------------------------");
}
}
bool Settings::createDefaultSettings(fs::FS &fs) {
Serial.println(F("Creating default settings file: settings.json"));
File settingsFile = fs.open("/settings.json", FILE_WRITE);
if (!settingsFile) {
Serial.println(F("Failed to create settings file"));
return false;
}
DynamicJsonDocument jsonBuffer(1024);
String settings_string;
//jsonBuffer["Settings"][0]["name"] = "Channel";
//jsonBuffer["Settings"][0]["type"] = "uint8_t";
//jsonBuffer["Settings"][0]["value"] = 11;
//jsonBuffer["Settings"][0]["range"]["min"] = 1;
//jsonBuffer["Settings"][0]["range"]["max"] = 14;
//jsonBuffer["Settings"][1]["name"] = "Channel Hop Delay";
//jsonBuffer["Settings"][1]["type"] = "int";
//jsonBuffer["Settings"][1]["value"] = 1;
//jsonBuffer["Settings"][1]["range"]["min"] = 1;
//jsonBuffer["Settings"][1]["range"]["max"] = 10;
jsonBuffer["Settings"][0]["name"] = "Force PMKID";
jsonBuffer["Settings"][0]["type"] = "bool";
jsonBuffer["Settings"][0]["value"] = true;
jsonBuffer["Settings"][0]["range"]["min"] = false;
jsonBuffer["Settings"][0]["range"]["max"] = true;
jsonBuffer["Settings"][1]["name"] = "Force Probe";
jsonBuffer["Settings"][1]["type"] = "bool";
jsonBuffer["Settings"][1]["value"] = true;
jsonBuffer["Settings"][1]["range"]["min"] = false;
jsonBuffer["Settings"][1]["range"]["max"] = true;
jsonBuffer["Settings"][2]["name"] = "Save PCAP";
jsonBuffer["Settings"][2]["type"] = "bool";
jsonBuffer["Settings"][2]["value"] = true;
jsonBuffer["Settings"][2]["range"]["min"] = false;
jsonBuffer["Settings"][2]["range"]["max"] = true;
//jsonBuffer.printTo(settingsFile);
if (serializeJson(jsonBuffer, settingsFile) == 0) {
Serial.println(F("Failed to write to file"));
}
if (serializeJson(jsonBuffer, settings_string) == 0) {
Serial.println(F("Failed to write to string"));
}
// Close the file
settingsFile.close();
this->json_settings_string = settings_string;
this->printJsonSettings(settings_string);
return true;
}
void Settings::main(uint32_t currentTime) {
}

View File

@@ -1,48 +1,52 @@
#ifndef Settings_h #ifndef Settings_h
#define Settings_h #define Settings_h
#include "SPIFFS.h" #include "SPIFFS.h"
#include <FS.h> #include <FS.h>
#include <ArduinoJson.h> #include <ArduinoJson.h>
#define FORMAT_SPIFFS_IF_FAILED true #define FORMAT_SPIFFS_IF_FAILED true
#include "Display.h" #include "Display.h"
extern Display display_obj; extern Display display_obj;
class Settings { class Settings {
private: private:
String json_settings_string; String json_settings_string;
void printJsonSettings(String json_string); void printJsonSettings(String json_string);
bool createDefaultSettings(fs::FS &fs); bool createDefaultSettings(fs::FS &fs);
public: public:
bool begin(); bool begin();
template <typename T> template <typename T>
T loadSetting(String name); T loadSetting(String name);
String getSettingType(String key); template <typename T>
String setting_index_to_name(int i); T saveSetting(String key, bool value);
int getNumberSettings();
bool toggleSetting(String key);
//template<> String getSettingType(String key);
//int loadSetting<int>(String key); String setting_index_to_name(int i);
int getNumberSettings();
//template<>
//String loadSetting<String>(String key); //template<>
//int loadSetting<int>(String key);
//template<>
//bool loadSetting<bool>(String key); //template<>
//String loadSetting<String>(String key);
//template<>
//uint8_t loadSetting<uint8_t>(String key); //template<>
//bool loadSetting<bool>(String key);
String getSettingsString();
void main(uint32_t currentTime); //template<>
}; //uint8_t loadSetting<uint8_t>(String key);
#endif String getSettingsString();
void main(uint32_t currentTime);
};
#endif