Add LVGL keyboard

This commit is contained in:
Just Call Me Koko
2020-08-27 22:41:39 -04:00
parent 9ee434ae7f
commit d32388eb2f
6 changed files with 130 additions and 67 deletions

View File

@@ -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()
{
@@ -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
@@ -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;
@@ -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;
@@ -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)
{
@@ -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);
@@ -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();
}
*/
/*
void Display::deinitLVGL() {
Serial.println(F("Deinit LVGL"));
//lv_deinit();
}
void Display::joinWiFiGFX(){
// Create one text area
@@ -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);
@@ -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");
@@ -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) {
@@ -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

View File

@@ -8,7 +8,7 @@
//#include <SimpleList.h>
#include <LinkedList.h>
#include <SPI.h>
//#include <lvgl.h>
#include <lvgl.h>
#include <Ticker.h>
//#include <M5Stack.h>
#include "SPIFFS.h"
@@ -16,6 +16,24 @@
#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
@@ -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
{
@@ -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();
@@ -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();
@@ -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);

View File

@@ -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) ||
@@ -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();
}
}
@@ -380,6 +385,7 @@ void MenuFunctions::drawStatusBar()
void MenuFunctions::orientDisplay()
{
Serial.println(F("orientDisplay()"));
display_obj.tft.init();
display_obj.tft.setRotation(0); // Portrait
@@ -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;
@@ -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] = {};
@@ -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);

View File

@@ -42,8 +42,8 @@ class bluetoothScanAllCallback: public BLEAdvertisedDeviceCallbacks {
Serial.print(advertisedDevice->getAddress().toString().c_str());
}
int temp_len = display_string.length();
for (int i = 0; i < 40 - temp_len; i++)
uint8_t temp_len = display_string.length();
for (uint8_t i = 0; i < 40 - temp_len; i++)
{
display_string.concat(" ");
}
@@ -77,15 +77,15 @@ class bluetoothScanSkimmersCallback: public BLEAdvertisedDeviceCallbacks {
{
//display_string.concat(advertisedDevice.getName().c_str());
Serial.print(advertisedDevice->getName().c_str());
for(int i = 0; i < bad_list_length; i++)
for(uint8_t i = 0; i < bad_list_length; i++)
{
if(strcmp(advertisedDevice->getName().c_str(), bad_list[i].c_str()) == 0)
{
display_string.concat("Potential Skimmer: ");
display_string.concat(" ");
display_string.concat(advertisedDevice->getName().c_str());
int temp_len = display_string.length();
for (int i = 0; i < 40 - temp_len; i++)
uint8_t temp_len = display_string.length();
for (uint8_t i = 0; i < 40 - temp_len; i++)
{
display_string.concat(" ");
}
@@ -128,6 +128,13 @@ WiFiScan::WiFiScan()
{
}
void WiFiScan::RunSetup() {
BLEDevice::init("");
pBLEScan = BLEDevice::getScan(); //create new scan
this->shutdownBLE();
}
// Function to prepare to run a specific scan
void WiFiScan::StartScan(uint8_t scan_mode, uint16_t color)
{
@@ -156,8 +163,8 @@ void WiFiScan::StartScan(uint8_t scan_mode, uint16_t color)
RunBluetoothScan(scan_mode, color);
else if (scan_mode == WIFI_SCAN_ESPRESSIF)
RunEspressifScan(scan_mode, color);
//else if (scan_mode == LV_JOIN_WIFI)
// RunLvJoinWiFi(scan_mode, color);
else if (scan_mode == LV_JOIN_WIFI)
RunLvJoinWiFi(scan_mode, color);
WiFiScan::currentScanMode = scan_mode;
}
@@ -174,6 +181,24 @@ void WiFiScan::shutdownWiFi() {
esp_wifi_deinit();
}
void WiFiScan::shutdownBLE() {
Serial.println("Stopping BLE scan...");
pBLEScan->stop();
Serial.println("BLE Scan Stopped");
Serial.println("Clearing BLE Results...");
pBLEScan->clearResults();
Serial.println("Deinitializing BT Controller...");
BLEDevice::deinit();
//Serial.println("Disable and Deinit BLE...");
//esp_bt_controller_disable();
//esp_bt_controller_deinit();
//Serial.println("Releasing BLE Memory...");
//esp_bt_controller_mem_release(ESP_BT_MODE_BLE);
//Serial.println("BT Controller Status: " + (String)esp_bt_controller_get_status());
}
// Function to stop all wifi scans
void WiFiScan::StopScan(uint8_t scan_mode)
{
@@ -195,14 +220,14 @@ void WiFiScan::StopScan(uint8_t scan_mode)
else if ((currentScanMode == BT_SCAN_ALL) ||
(currentScanMode == BT_SCAN_SKIMMERS))
{
Serial.println("Stopping BLE scan...");
pBLEScan->stop();
Serial.println("BLE Scan Stopped");
//Serial.println("Stopping BLE scan...");
//pBLEScan->stop();
//Serial.println("BLE Scan Stopped");
Serial.println("Clearing BLE Results...");
pBLEScan->clearResults();
Serial.println("Deinitializing BT Controller...");
//Serial.println("Clearing BLE Results...");
//pBLEScan->clearResults();
/*Serial.println("Deinitializing BT Controller...");
BLEDevice::deinit();
//Serial.println("Disable and Deinit BLE...");
//esp_bt_controller_disable();
@@ -210,7 +235,8 @@ void WiFiScan::StopScan(uint8_t scan_mode)
//Serial.println("Releasing BLE Memory...");
//esp_bt_controller_mem_release(ESP_BT_MODE_BLE);
//Serial.println("BT Controller Status: " + (String)esp_bt_controller_get_status());
*/
this->shutdownBLE();
}
@@ -276,7 +302,7 @@ String WiFiScan::freeRAM()
return String(s);
}
/*
void WiFiScan::RunLvJoinWiFi(uint8_t scan_mode, uint16_t color) {
display_obj.tft.init();
@@ -291,13 +317,13 @@ void WiFiScan::RunLvJoinWiFi(uint8_t scan_mode, uint16_t color) {
#endif
display_obj.tft.setTouch(calData);
display_obj.initLVGL();
//display_obj.initLVGL();
lv_obj_t * scr = lv_cont_create(NULL, NULL);
lv_disp_load_scr(scr);
display_obj.joinWiFiGFX();
}*/
}
void WiFiScan::RunInfo()
{

View File

@@ -41,7 +41,7 @@
#define BT_SCAN_ALL 10
#define BT_SCAN_SKIMMERS 11
#define WIFI_SCAN_ESPRESSIF 12
//#define LV_JOIN_WIFI 12
#define LV_JOIN_WIFI 13
#define GRAPH_REFRESH 100
@@ -148,7 +148,7 @@ class WiFiScan
void RunProbeScan(uint8_t scan_mode, uint16_t color);
void RunPacketMonitor(uint8_t scan_mode, uint16_t color);
void RunBluetoothScan(uint8_t scan_mode, uint16_t color);
//void RunLvJoinWiFi(uint8_t scan_mode, uint16_t color);
void RunLvJoinWiFi(uint8_t scan_mode, uint16_t color);
static void scanCompleteCB(BLEScanResults scanResults);
public:
@@ -163,9 +163,13 @@ class WiFiScan
String free_ram = "";
String old_free_ram = "";
//lv_obj_t * scr = lv_cont_create(NULL, NULL);
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
void RunSetup();
void shutdownWiFi();
void shutdownBLE();
String getStaMAC();
String getApMAC();
String freeRAM();

View File

@@ -87,6 +87,8 @@ void setup()
//Serial.println("Internal Temp: " + (String)((temprature_sens_read() - 32) / 1.8));
wifi_scan_obj.RunSetup();
Serial.println(wifi_scan_obj.freeRAM());
display_obj.tft.println("Checked RAM");
@@ -173,7 +175,7 @@ void loop()
// (wifi_scan_obj.currentScanMode != OTA_UPDATE))
if (!display_obj.draw_tft)
{
display_obj.main();
display_obj.main(wifi_scan_obj.currentScanMode);
wifi_scan_obj.main(currentTime);
sd_obj.main();
battery_obj.main(currentTime);