Skip to content

Commit

Permalink
Add LVGL keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
justcallmekoko committed Aug 28, 2020
1 parent 9ee434a commit d32388e
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 65 deletions.
57 changes: 32 additions & 25 deletions esp32_marauder/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Big thanks to bodmer for having great TFT and JPEG libraries
https://github.com/bodmer
*/

//PROGMEM lv_obj_t * slider_label;
//PROGMEM lv_obj_t * ta1;
//PROGMEM lv_obj_t * ta2;
PROGMEM lv_obj_t * slider_label;
PROGMEM lv_obj_t * ta1;
PROGMEM lv_obj_t * ta2;

Display::Display()
{
Expand Down Expand Up @@ -56,6 +56,8 @@ void Display::RunSetup()
while (1) yield(); // Stay here twiddling thumbs waiting
}

this->initLVGL();


// Draw the title screen
//drawJpeg("/marauder3L.jpg", 0 , 0); // 240 x 320 image
Expand All @@ -69,14 +71,14 @@ void Display::RunSetup()
}

/* Interrupt driven periodic handler */
/*

void Display::lv_tick_handler()
{
lv_tick_inc(LVGL_TICK_PERIOD);
}*/
}

/* Display flushing */
/*void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
{
extern Display display_obj;
uint16_t c;
Expand All @@ -92,9 +94,9 @@ void Display::lv_tick_handler()
}
display_obj.tft.endWrite();
lv_disp_flush_ready(disp);
}*/
}


/*
bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data)
{
extern Display display_obj;
Expand Down Expand Up @@ -135,7 +137,7 @@ bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data)
}

return false;
}*/
}

void Display::tftDrawGraphObjects(byte x_scale)
{
Expand Down Expand Up @@ -816,7 +818,7 @@ void Display::buildBanner(String msg, int xpos)
img.print(msg);
}

/*

void Display::initLVGL() {
tick.attach_ms(LVGL_TICK_PERIOD, lv_tick_handler);

Expand All @@ -837,15 +839,16 @@ void Display::initLVGL() {
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = my_touchpad_read;
lv_indev_drv_register(&indev_drv);
}*/
}


/*
void Display::deinitLVGL() {
lv_deinit();
Serial.println(F("Deinit LVGL"));
//lv_deinit();
}
*/

/*


void Display::joinWiFiGFX(){

// Create one text area
Expand All @@ -864,8 +867,8 @@ void Display::joinWiFiGFX(){

// Create second text area
ta2 = lv_textarea_create(lv_scr_act(), ta1);
lv_textarea_set_pwd_mode(ta2, true);
lv_textarea_set_pwd_show_time(ta2, 1000);
//lv_textarea_set_pwd_mode(ta2, true); // This shit makes it so backspace does not work
//lv_textarea_set_pwd_show_time(ta2, 1000);
lv_textarea_set_cursor_hidden(ta2, true);
lv_obj_align(ta2, NULL, LV_ALIGN_IN_TOP_RIGHT, -5, 20);

Expand All @@ -883,10 +886,11 @@ void Display::joinWiFiGFX(){
lv_keyboard_set_textarea(kb, ta1);
lv_keyboard_set_cursor_manage(kb, true);

}*/
}


/*
void keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event){
extern Display display_obj;
lv_keyboard_def_event_cb(kb, event);
if(event == LV_EVENT_APPLY){
printf("LV_EVENT_APPLY\n");
Expand All @@ -898,11 +902,13 @@ void keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event){
//joinWiFi(ta1_text, ta2_text);
}else if(event == LV_EVENT_CANCEL){
printf("LV_EVENT_CANCEL\n");
lv_textarea_set_text(lv_keyboard_get_textarea(kb), "");
//lv_textarea_set_text(lv_keyboard_get_textarea(kb), "");
display_obj.deinitLVGL();
display_obj.exit_draw = true; // set everything back to normal
}
}*/
}


/*
void ta_event_cb(lv_obj_t * ta, lv_event_t event)
{
if(event == LV_EVENT_CLICKED) {
Expand All @@ -916,11 +922,12 @@ void ta_event_cb(lv_obj_t * ta, lv_event_t event)
// printf("Ready\n");
// }
//}
}*/
}

void Display::main()
void Display::main(uint8_t scan_mode)
{
//lv_task_handler();
if (scan_mode == LV_JOIN_WIFI)
lv_task_handler();
return;
}
// End SPIFFS_functions
46 changes: 32 additions & 14 deletions esp32_marauder/Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,32 @@
//#include <SimpleList.h>
#include <LinkedList.h>
#include <SPI.h>
//#include <lvgl.h>
#include <lvgl.h>
#include <Ticker.h>
//#include <M5Stack.h>
#include "SPIFFS.h"
#include "Assets.h"

#include <TFT_eSPI.h>

// 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 TFT_SHIELD
#define TFT_DIY

Expand All @@ -36,21 +54,21 @@
//#define MENU_FONT &FreeSansBold9pt7b
#define BUTTON_ARRAY_LEN 7
#define STATUS_BAR_WIDTH 16
//#define LVGL_TICK_PERIOD 6
#define LVGL_TICK_PERIOD 6

#define STATUSBAR_COLOR 0x4A49

//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 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 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);
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;
PROGMEM static lv_obj_t *kb;

class Display
{
Expand All @@ -68,7 +86,7 @@ class Display
//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();
static void lv_tick_handler();

public:
Display();
Expand Down Expand Up @@ -112,9 +130,9 @@ class Display
// 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 initLVGL();
void deinitLVGL();
void joinWiFiGFX();
void tftDrawGraphObjects(byte x_scale);
void tftDrawEapolColorKey();
void tftDrawColorKey();
Expand All @@ -134,7 +152,7 @@ class Display
void jpegRender(int xpos, int ypos);
void listDir(fs::FS &fs, const char * dirname, uint8_t levels);
void listFiles();
void main();
void main(uint8_t scan_mode);
void RunSetup();
void scrollAddress(uint16_t vsp);
int scroll_line(uint32_t color);
Expand Down
18 changes: 12 additions & 6 deletions esp32_marauder/MenuFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ MenuFunctions::MenuFunctions()
// Function to check menu input
void MenuFunctions::main(uint32_t currentTime)
{
// Some function exited and we need to go back to normal
if (display_obj.exit_draw) {
wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
display_obj.exit_draw = false;
changeMenu(current_menu);
this->orientDisplay();
//changeMenu(current_menu);
}
if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF) ||
(wifi_scan_obj.currentScanMode == OTA_UPDATE) ||
Expand All @@ -25,13 +28,15 @@ void MenuFunctions::main(uint32_t currentTime)
//{
// this->drawStatusBar();
//}
display_obj.updateBanner(current_menu->name);
if (wifi_scan_obj.currentScanMode != LV_JOIN_WIFI)
display_obj.updateBanner(current_menu->name);
}

if (currentTime != 0) {
if (currentTime - initTime >= 100) {
this->initTime = millis();
this->updateStatusBar();
if (wifi_scan_obj.currentScanMode != LV_JOIN_WIFI)
this->updateStatusBar();
}
}

Expand Down Expand Up @@ -380,6 +385,7 @@ void MenuFunctions::drawStatusBar()

void MenuFunctions::orientDisplay()
{
Serial.println(F("orientDisplay()"));
display_obj.tft.init();

display_obj.tft.setRotation(0); // Portrait
Expand Down Expand Up @@ -603,7 +609,7 @@ void MenuFunctions::RunSetup()
changeMenu(&infoMenu);
wifi_scan_obj.RunInfo();
});
//addNodes(&deviceMenu, "Join WiFi", TFT_YELLOW, NULL, SNIFFERS, [this](){display_obj.clearScreen(); wifi_scan_obj.currentScanMode = LV_JOIN_WIFI; wifi_scan_obj.StartScan(LV_JOIN_WIFI, TFT_YELLOW);});
addNodes(&deviceMenu, "Join WiFi", TFT_YELLOW, NULL, SNIFFERS, [this](){display_obj.clearScreen(); wifi_scan_obj.currentScanMode = LV_JOIN_WIFI; wifi_scan_obj.StartScan(LV_JOIN_WIFI, TFT_YELLOW);});

// Select update
whichUpdateMenu.parentMenu = &deviceMenu;
Expand Down Expand Up @@ -710,7 +716,7 @@ void MenuFunctions::buildButtons(Menu * menu)
{
//for (int i = 0; i < sizeof(key); i++)
// key[i] = NULL;
for (int i = 0; i < menu->list->size(); i++)
for (uint8_t i = 0; i < menu->list->size(); i++)
{
TFT_eSPI_Button new_button;
char buf[menu->list->get(i).name.length() + 1] = {};
Expand Down Expand Up @@ -750,7 +756,7 @@ void MenuFunctions::displayCurrentMenu()
if (current_menu->list != NULL)
{
display_obj.tft.setFreeFont(MENU_FONT);
for (int i = 0; i < current_menu->list->size(); i++)
for (uint8_t i = 0; i < current_menu->list->size(); i++)
{
//display_obj.key[i].drawButton2(current_menu->list->get(i).name);
//display_obj.key[i].drawButton(ML_DATUM, BUTTON_PADDING, current_menu->list->get(i).name);
Expand Down

0 comments on commit d32388e

Please sign in to comment.