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

File diff suppressed because it is too large Load Diff

View File

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

View File

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