From f9032d886e5a5481d8ea99cfd829f2fe485e6c52 Mon Sep 17 00:00:00 2001 From: Rick Astley Date: Tue, 7 Jan 2025 07:56:06 +0100 Subject: [PATCH 1/3] Preparing cross-plateform handling (generic keystoke and screen) --- .../main/BeamStalker-cardputer.cpp | 52 ++++++--------- .../main/firmware/apps/BLE/ble_main.cpp | 21 ++---- .../main/firmware/apps/BLE/ble_spam.cpp | 33 ++++------ .../firmware/apps/Wifi/app_wifi_sniffer.cpp | 30 ++------- .../main/firmware/apps/Wifi/beacon_spam.cpp | 31 ++++----- .../main/firmware/apps/Wifi/deauther.cpp | 45 +++++-------- .../main/firmware/apps/Wifi/wifi_main.cpp | 21 ++---- .../main/firmware/apps/options.cpp | 51 ++++++--------- Firmware/BeamStalker/main/firmware/helper.h | 2 +- .../main/firmware/includes/wifi.cpp | 25 +++---- .../main/firmware/includes/wifi_sniffer.cpp | 58 ++++++----------- Firmware/BeamStalker/main/firmware/menu.cpp | 65 +++++++++++++------ Firmware/BeamStalker/main/firmware/menu.h | 15 ++++- 13 files changed, 188 insertions(+), 261 deletions(-) diff --git a/Firmware/BeamStalker/main/BeamStalker-cardputer.cpp b/Firmware/BeamStalker/main/BeamStalker-cardputer.cpp index b878019..4372d31 100644 --- a/Firmware/BeamStalker/main/BeamStalker-cardputer.cpp +++ b/Firmware/BeamStalker/main/BeamStalker-cardputer.cpp @@ -20,7 +20,6 @@ extern "C" { #include "firmware/apps/Wifi/wifi_main.h" #include "firmware/apps/BLE/ble_main.h" -#include "M5GFX.h" #include "M5Cardputer.h" M5GFX display; @@ -60,60 +59,51 @@ int mainTask() { drawMenu(MainMenu, MainMenuSelector); - int UPp, DOWNp, LEFTp, RIGHTp, SELECTp, RETURNp; - while (1) { - M5Cardputer.update(); - if (M5Cardputer.Keyboard.isPressed()) { - UPp = M5Cardputer.Keyboard.isKeyPressed(';'); - DOWNp = M5Cardputer.Keyboard.isKeyPressed('.'); - LEFTp = M5Cardputer.Keyboard.isKeyPressed(','); - RIGHTp = M5Cardputer.Keyboard.isKeyPressed('/'); - SELECTp = M5Cardputer.Keyboard.isKeyPressed(KEY_ENTER); - RETURNp = M5Cardputer.Keyboard.isKeyPressed('`'); - - if (RETURNp) { + updateBoard(); + if (anyPressed()) { + + if (returnPressed()) { vTaskDelay(pdMS_TO_TICKS(300)); return 0; } - else if (UPp) { + else if (upPressed()) { MainMenuSelector = intChecker(MainMenuSelector - 1, MainMenu.length); vTaskDelay(pdMS_TO_TICKS(50)); } - else if (DOWNp) { + else if (downPressed()) { MainMenuSelector = intChecker(MainMenuSelector + 1, MainMenu.length); vTaskDelay(pdMS_TO_TICKS(50)); } - else if (LEFTp && (MainMenu.elements[MainMenuSelector].type == 0)) { + else if (leftPressed() && (MainMenu.elements[MainMenuSelector].type == 0)) { MainMenu.elements[MainMenuSelector].selector = intChecker(MainMenu.elements[MainMenuSelector].selector - 1, MainMenu.elements[MainMenuSelector].length); vTaskDelay(pdMS_TO_TICKS(50)); } - else if (RIGHTp && (MainMenu.elements[MainMenuSelector].type == 0)) { + else if (rightPressed() && (MainMenu.elements[MainMenuSelector].type == 0)) { MainMenu.elements[MainMenuSelector].selector = intChecker(MainMenu.elements[MainMenuSelector].selector + 1, MainMenu.elements[MainMenuSelector].length); vTaskDelay(pdMS_TO_TICKS(50)); } - - else if (SELECTp) { + else if (selectPressed()) { vTaskDelay(pdMS_TO_TICKS(300)); switch (MainMenuSelector) { int ret; case 0: // WiFcker - M5GFX_clear_screen(); + clearScreen(); ret = APP_WiFcker(); if (ret != 0) { printf("Error in app."); } break; case 1: // BLE - M5GFX_clear_screen(); + clearScreen(); ret = APP_BLE(); if (ret != 0) { printf("Error in app."); } break; case 2: // Options - M5GFX_clear_screen(); + clearScreen(); ret = APP_Options(); if (ret != 0) { printf("Error in app."); @@ -138,16 +128,14 @@ extern "C" void app_main(void) { } ESP_ERROR_CHECK(ret); - M5.Display.clear(); + clearScreen(); M5.Display.setTextSize(charsize_multiplier); M5.Display.setTextColor(TFT_WHITE, TFT_BLACK); M5.Display.setFont(&fonts::FreeMonoBold18pt7b); const char* name = "BeamStalker"; for (;;) { - M5.Display.clear(); - // int16_t x = (M5.Display.width() - 128) / 2; - // drawBitmap(x, 0, 128, 64, skullLogo, TFT_WHITE); + clearScreen(); int16_t x = ((M5.Display.width() - 120) / 4) * 3; drawBitmap(x, 0, 120, 120, skully, TFT_WHITE); @@ -157,27 +145,29 @@ extern "C" void app_main(void) { M5.Display.print(name); M5.Display.setCursor(0, 90); M5.Display.print(VERSION); + printf("%s %s\n", name, VERSION); vTaskDelay(pdMS_TO_TICKS(500)); + M5.Display.setCursor(0, 110); M5.Display.print("Press to boot..."); int loop = 1; while (loop) { - M5Cardputer.update(); - if (M5Cardputer.Keyboard.isPressed()) { + updateBoard(); + if (anyPressed()) { int wait = 1; while (wait) { - M5Cardputer.update(); - if (M5Cardputer.Keyboard.isPressed()) { + updateBoard(); + if (anyPressed()) { wait = 0; } vTaskDelay(pdMS_TO_TICKS(30)); } - M5.Display.clear(); + clearScreen(); int taskRet = mainTask(); if (taskRet != 0) { diff --git a/Firmware/BeamStalker/main/firmware/apps/BLE/ble_main.cpp b/Firmware/BeamStalker/main/firmware/apps/BLE/ble_main.cpp index 00f97a7..4d788f1 100644 --- a/Firmware/BeamStalker/main/firmware/apps/BLE/ble_main.cpp +++ b/Firmware/BeamStalker/main/firmware/apps/BLE/ble_main.cpp @@ -17,31 +17,22 @@ int bleMenuTask() { drawMenu(Menu, Selector); - int UPp, DOWNp, SELECTp, RETURNp; - while (1) { - M5Cardputer.update(); - if (M5Cardputer.Keyboard.isChange()) { - UPp = M5Cardputer.Keyboard.isKeyPressed(';'); - DOWNp = M5Cardputer.Keyboard.isKeyPressed('.'); -// LEFTp = M5Cardputer.Keyboard.isKeyPressed(','); -// RIGHTp = M5Cardputer.Keyboard.isKeyPressed('/'); - SELECTp = M5Cardputer.Keyboard.isKeyPressed(KEY_ENTER); - RETURNp = M5Cardputer.Keyboard.isKeyPressed('`'); - - if (RETURNp) { + updateBoard(); + if (anyPressed()) { + if (returnPressed()) { vTaskDelay(pdMS_TO_TICKS(300)); return 0; } - else if (UPp) { + else if (upPressed()) { Selector = intChecker(Selector - 1, Menu.length); vTaskDelay(pdMS_TO_TICKS(50)); } - else if (DOWNp) { + else if (downPressed()) { Selector = intChecker(Selector + 1, Menu.length); vTaskDelay(pdMS_TO_TICKS(50)); } - if (SELECTp) { + if (selectPressed()) { vTaskDelay(pdMS_TO_TICKS(300)); switch (Selector) { diff --git a/Firmware/BeamStalker/main/firmware/apps/BLE/ble_spam.cpp b/Firmware/BeamStalker/main/firmware/apps/BLE/ble_spam.cpp index f9c010c..1acf095 100644 --- a/Firmware/BeamStalker/main/firmware/apps/BLE/ble_spam.cpp +++ b/Firmware/BeamStalker/main/firmware/apps/BLE/ble_spam.cpp @@ -157,19 +157,10 @@ int BLESpam() { drawMenu(Menu, Selector); - int UPp, DOWNp, LEFTp, RIGHTp, SELECTp, RETURNp; - while (1) { - M5Cardputer.update(); - if (M5Cardputer.Keyboard.isChange()) { - UPp = M5Cardputer.Keyboard.isKeyPressed(';'); - DOWNp = M5Cardputer.Keyboard.isKeyPressed('.'); - LEFTp = M5Cardputer.Keyboard.isKeyPressed(','); - RIGHTp = M5Cardputer.Keyboard.isKeyPressed('/'); - SELECTp = M5Cardputer.Keyboard.isKeyPressed(KEY_ENTER); - RETURNp = M5Cardputer.Keyboard.isKeyPressed('`'); - - if (RETURNp) { + updateBoard(); + if (anyPressed()) { + if (returnPressed()) { /* STOP BLE */ ESP_ERROR_CHECK(esp_bluedroid_disable()); ESP_ERROR_CHECK(esp_bluedroid_deinit()); @@ -181,30 +172,30 @@ int BLESpam() { return 0; } - else if (UPp) { + else if (upPressed()) { Selector = intChecker(Selector - 1, Menu.length); vTaskDelay(pdMS_TO_TICKS(50)); } - else if (DOWNp) { + else if (downPressed()) { Selector = intChecker(Selector + 1, Menu.length); vTaskDelay(pdMS_TO_TICKS(50)); } - else if (LEFTp && (Menu.elements[Selector].type == 0)) { + else if (leftPressed() && (Menu.elements[Selector].type == 0)) { Menu.elements[Selector].selector = intChecker(Menu.elements[Selector].selector - 1, Menu.elements[Selector].length); vTaskDelay(pdMS_TO_TICKS(50)); } - else if (RIGHTp && (Menu.elements[Selector].type == 0)) { + else if (rightPressed() && (Menu.elements[Selector].type == 0)) { Menu.elements[Selector].selector = intChecker(Menu.elements[Selector].selector + 1, Menu.elements[Selector].length); vTaskDelay(pdMS_TO_TICKS(50)); } - if (SELECTp) { + if (selectPressed()) { vTaskDelay(pdMS_TO_TICKS(300)); - M5GFX_clear_screen(); + clearScreen(); switch (Selector) { case 1: // Start attack vTaskDelay(pdMS_TO_TICKS(100)); - M5GFX_display_text(0, 0, "Spamming!!!", TFT_WHITE); + displayText(0, 0, "Spamming!!!", TFT_WHITE); if (Menu.elements[Selector].selector == 4) { // all // choice = (EBLEPayloadType)esp_random() % 4; @@ -214,8 +205,8 @@ int BLESpam() { } int wait = 1; while (wait) { - M5Cardputer.update(); - if (M5Cardputer.Keyboard.isPressed()) { + updateBoard(); + if (anyPressed()) { wait = 0; } diff --git a/Firmware/BeamStalker/main/firmware/apps/Wifi/app_wifi_sniffer.cpp b/Firmware/BeamStalker/main/firmware/apps/Wifi/app_wifi_sniffer.cpp index 1720234..a114c52 100644 --- a/Firmware/BeamStalker/main/firmware/apps/Wifi/app_wifi_sniffer.cpp +++ b/Firmware/BeamStalker/main/firmware/apps/Wifi/app_wifi_sniffer.cpp @@ -26,45 +26,29 @@ int App_Wifi_Sniffer() { drawMenu(Menu, Selector); - int UPp, DOWNp, SELECTp, RETURNp; uint16_t *filters = NULL; int filter_count = 0; while (1) { - M5Cardputer.update(); - if (M5Cardputer.Keyboard.isPressed()) { - UPp = M5Cardputer.Keyboard.isKeyPressed(';'); - DOWNp = M5Cardputer.Keyboard.isKeyPressed('.'); - // LEFTp = M5Cardputer.Keyboard.isKeyPressed(','); - // RIGHTp = M5Cardputer.Keyboard.isKeyPressed('/'); - SELECTp = M5Cardputer.Keyboard.isKeyPressed(KEY_ENTER); - RETURNp = M5Cardputer.Keyboard.isKeyPressed('`'); - - if (RETURNp) { + updateBoard(); + if (anyPressed()) { + if (returnPressed()) { stop_wifi(); vTaskDelay(pdMS_TO_TICKS(300)); return 0; } - else if (UPp) { + else if (upPressed()) { Selector = intChecker(Selector - 1, Menu.length); vTaskDelay(pdMS_TO_TICKS(50)); } - else if (DOWNp) { + else if (downPressed()) { Selector = intChecker(Selector + 1, Menu.length); vTaskDelay(pdMS_TO_TICKS(50)); } - //else if (LEFTp && (Menu.elements[Selector].type == 0)) { - // Menu.elements[Selector].selector = intChecker(Menu.elements[Selector].selector - 1, Menu.elements[Selector].length); - // vTaskDelay(pdMS_TO_TICKS(50)); - // } - // else if (RIGHTp && (Menu.elements[Selector].type == 0)) { - // Menu.elements[Selector].selector = intChecker(Menu.elements[Selector].selector + 1, Menu.elements[Selector].length); - // vTaskDelay(pdMS_TO_TICKS(50)); - // } - if (SELECTp) { + if (selectPressed()) { vTaskDelay(pdMS_TO_TICKS(300)); - M5GFX_clear_screen(); + clearScreen(); switch (Selector) { case 0: //filter diff --git a/Firmware/BeamStalker/main/firmware/apps/Wifi/beacon_spam.cpp b/Firmware/BeamStalker/main/firmware/apps/Wifi/beacon_spam.cpp index 6946eff..6a24cbf 100644 --- a/Firmware/BeamStalker/main/firmware/apps/Wifi/beacon_spam.cpp +++ b/Firmware/BeamStalker/main/firmware/apps/Wifi/beacon_spam.cpp @@ -146,43 +146,34 @@ int BeaconSpam() { drawMenu(Menu, Selector); - int UPp, DOWNp, LEFTp, RIGHTp, SELECTp, RETURNp; - while (1) { - M5Cardputer.update(); - if (M5Cardputer.Keyboard.isPressed()) { - UPp = M5Cardputer.Keyboard.isKeyPressed(';'); - DOWNp = M5Cardputer.Keyboard.isKeyPressed('.'); - LEFTp = M5Cardputer.Keyboard.isKeyPressed(','); - RIGHTp = M5Cardputer.Keyboard.isKeyPressed('/'); - SELECTp = M5Cardputer.Keyboard.isKeyPressed(KEY_ENTER); - RETURNp = M5Cardputer.Keyboard.isKeyPressed('`'); - - if (RETURNp) { + updateBoard(); + if (anyPressed()) { + if (returnPressed()) { stop_wifi(); vTaskDelay(pdMS_TO_TICKS(300)); return 0; } - else if (UPp) { + else if (upPressed()) { Selector = intChecker(Selector - 1, Menu.length); vTaskDelay(pdMS_TO_TICKS(50)); } - else if (DOWNp) { + else if (downPressed()) { Selector = intChecker(Selector + 1, Menu.length); vTaskDelay(pdMS_TO_TICKS(50)); } - else if (LEFTp && (Menu.elements[Selector].type == 0)) { + else if (leftPressed() && (Menu.elements[Selector].type == 0)) { Menu.elements[Selector].selector = intChecker(Menu.elements[Selector].selector - 1, Menu.elements[Selector].length); vTaskDelay(pdMS_TO_TICKS(50)); } - else if (RIGHTp && (Menu.elements[Selector].type == 0)) { + else if (rightPressed() && (Menu.elements[Selector].type == 0)) { Menu.elements[Selector].selector = intChecker(Menu.elements[Selector].selector + 1, Menu.elements[Selector].length); vTaskDelay(pdMS_TO_TICKS(50)); } - if (SELECTp) { + if (selectPressed()) { vTaskDelay(pdMS_TO_TICKS(300)); - M5GFX_clear_screen(); + clearScreen(); switch (Selector) { case 1: // Start attack @@ -191,8 +182,8 @@ int BeaconSpam() { charset = Menu.elements[0].selector; int wait = 1; while (wait) { - M5Cardputer.update(); - if (M5Cardputer.Keyboard.isPressed()) { + updateBoard(); + if (anyPressed()) { wait = 0; } packet_count++; diff --git a/Firmware/BeamStalker/main/firmware/apps/Wifi/deauther.cpp b/Firmware/BeamStalker/main/firmware/apps/Wifi/deauther.cpp index 7002b26..ffb5359 100644 --- a/Firmware/BeamStalker/main/firmware/apps/Wifi/deauther.cpp +++ b/Firmware/BeamStalker/main/firmware/apps/Wifi/deauther.cpp @@ -52,55 +52,46 @@ int Deauther() { drawMenu(Menu, Selector); - int UPp, DOWNp, LEFTp, RIGHTp, SELECTp, RETURNp; int aps_count = 0; int clients_count = 0; AP* aps = NULL; mac_addr_t* clients = NULL; - while (1) { - M5Cardputer.update(); - if (M5Cardputer.Keyboard.isPressed()) { - UPp = M5Cardputer.Keyboard.isKeyPressed(';'); - DOWNp = M5Cardputer.Keyboard.isKeyPressed('.'); - LEFTp = M5Cardputer.Keyboard.isKeyPressed(','); - RIGHTp = M5Cardputer.Keyboard.isKeyPressed('/'); - SELECTp = M5Cardputer.Keyboard.isKeyPressed(KEY_ENTER); - RETURNp = M5Cardputer.Keyboard.isKeyPressed('`'); - - if (RETURNp) { + updateBoard(); + if (anyPressed()) { + if (returnPressed()) { stop_wifi(); vTaskDelay(pdMS_TO_TICKS(300)); return 0; } - else if (UPp) { + else if (upPressed()) { Selector = intChecker(Selector - 1, Menu.length); vTaskDelay(pdMS_TO_TICKS(50)); } - else if (DOWNp) { + else if (downPressed()) { Selector = intChecker(Selector + 1, Menu.length); vTaskDelay(pdMS_TO_TICKS(50)); } - else if (LEFTp && (Menu.elements[Selector].type == 0)) { + else if (leftPressed() && (Menu.elements[Selector].type == 0)) { Menu.elements[Selector].selector = intChecker(Menu.elements[Selector].selector - 1, Menu.elements[Selector].length); vTaskDelay(pdMS_TO_TICKS(50)); } - else if (RIGHTp && (Menu.elements[Selector].type == 0)) { + else if (rightPressed() && (Menu.elements[Selector].type == 0)) { Menu.elements[Selector].selector = intChecker(Menu.elements[Selector].selector + 1, Menu.elements[Selector].length); vTaskDelay(pdMS_TO_TICKS(50)); } - if (SELECTp) { - M5GFX_clear_screen(); + if (selectPressed()) { + clearScreen(); vTaskDelay(pdMS_TO_TICKS(300)); switch (Selector) { case 0: // Select AP - M5GFX_display_text(0, 0, "Scanning...\r", TFT_WHITE); + displayText(0, 0, "Scanning...\r", TFT_WHITE); aps = select_wifi_menu(&aps_count); - M5GFX_display_text(0, 0, "", TFT_WHITE); - M5GFX_clear_screen(); + displayText(0, 0, "", TFT_WHITE); + clearScreen(); for (int i = 0; i < aps_count; i ++) { printf ("%d: %s\n", i, aps[i].name); @@ -118,11 +109,11 @@ int Deauther() { sprintf(buffer, "Sniffing clients...\nFor %d selected APs\nDuring 10s", aps_count); printf("%s\n", buffer); // Print the string to verify - M5GFX_display_text(0, 0, buffer, TFT_WHITE); + displayText(0, 0, buffer, TFT_WHITE); clients = select_client_menu(&clients_count, aps, aps_count); - M5GFX_display_text(0, 0, "", TFT_WHITE); - M5GFX_clear_screen(); + displayText(0, 0, "", TFT_WHITE); + clearScreen(); // for (int i = 0; i < clients_count; i ++) { // printf ("%d: %02x:%02x:%02x:%02x:%02x:%02x\n", i, clients[i][0],clients[i][1],clients[i][2],clients[i][3],clients[i][4],clients[i][5]); @@ -142,7 +133,7 @@ int Deauther() { init_pps_timer(); vTaskDelay(pdMS_TO_TICKS(100)); - M5Cardputer.update(); + updateBoard(); stop_wifi(); vTaskDelay(pdMS_TO_TICKS(100)); @@ -150,8 +141,8 @@ int Deauther() { int wait = 1; while (wait) { - M5Cardputer.update(); - if (M5Cardputer.Keyboard.isPressed()) { + updateBoard(); + if (anyPressed()) { wait = 0; } diff --git a/Firmware/BeamStalker/main/firmware/apps/Wifi/wifi_main.cpp b/Firmware/BeamStalker/main/firmware/apps/Wifi/wifi_main.cpp index 1638fd9..1a68c1d 100644 --- a/Firmware/BeamStalker/main/firmware/apps/Wifi/wifi_main.cpp +++ b/Firmware/BeamStalker/main/firmware/apps/Wifi/wifi_main.cpp @@ -32,31 +32,22 @@ int wifiMenuTask() { drawMenu(Menu, Selector); - int UPp, DOWNp, SELECTp, RETURNp; - while (1) { - M5Cardputer.update(); - if (M5Cardputer.Keyboard.isPressed()) { - UPp = M5Cardputer.Keyboard.isKeyPressed(';'); - DOWNp = M5Cardputer.Keyboard.isKeyPressed('.'); -// LEFTp = M5Cardputer.Keyboard.isKeyPressed(','); -// RIGHTp = M5Cardputer.Keyboard.isKeyPressed('/'); - SELECTp = M5Cardputer.Keyboard.isKeyPressed(KEY_ENTER); - RETURNp = M5Cardputer.Keyboard.isKeyPressed('`'); - - if (RETURNp) { + updateBoard(); + if (anyPressed()) { + if (returnPressed()) { vTaskDelay(pdMS_TO_TICKS(300)); return 0; } - else if (UPp) { + else if (upPressed()) { Selector = intChecker(Selector - 1, Menu.length); vTaskDelay(pdMS_TO_TICKS(50)); } - else if (DOWNp) { + else if (downPressed()) { Selector = intChecker(Selector + 1, Menu.length); vTaskDelay(pdMS_TO_TICKS(50)); } - if (SELECTp) { + if (selectPressed()) { vTaskDelay(pdMS_TO_TICKS(300)); switch (Selector) { int ret; diff --git a/Firmware/BeamStalker/main/firmware/apps/options.cpp b/Firmware/BeamStalker/main/firmware/apps/options.cpp index f405a62..1a5148d 100644 --- a/Firmware/BeamStalker/main/firmware/apps/options.cpp +++ b/Firmware/BeamStalker/main/firmware/apps/options.cpp @@ -31,76 +31,67 @@ int APP_Options() { drawMenu(Menu, Selector); - int UPp, DOWNp, SELECTp, RETURNp; - while (1) { - M5Cardputer.update(); - if (M5Cardputer.Keyboard.isPressed()) { - UPp = M5Cardputer.Keyboard.isKeyPressed(';'); - DOWNp = M5Cardputer.Keyboard.isKeyPressed('.'); -// LEFTp = M5Cardputer.Keyboard.isKeyPressed(','); -// RIGHTp = M5Cardputer.Keyboard.isKeyPressed('/'); - SELECTp = M5Cardputer.Keyboard.isKeyPressed(KEY_ENTER); - RETURNp = M5Cardputer.Keyboard.isKeyPressed('`'); - - if (RETURNp) { + updateBoard(); + if (anyPressed()) { + if (returnPressed()) { vTaskDelay(pdMS_TO_TICKS(300)); return 0; } - else if (UPp) { + else if (upPressed()) { Selector = intChecker(Selector - 1, Menu.length); vTaskDelay(pdMS_TO_TICKS(50)); } - else if (DOWNp) { + else if (downPressed()) { Selector = intChecker(Selector + 1, Menu.length); vTaskDelay(pdMS_TO_TICKS(50)); } - if (SELECTp) { - M5GFX_clear_screen(); + if (selectPressed()) { + clearScreen(); vTaskDelay(pdMS_TO_TICKS(300)); int wait = 1; switch (Selector) { case 0: - M5GFX_display_text(0, 0, "Current Firmware:"); - M5GFX_display_text(0, 20, VERSION); + displayText(0, 0, "Current Firmware:"); + displayText(0, 20, VERSION); vTaskDelay(pdMS_TO_TICKS(200)); wait = 1; while (wait) { - M5Cardputer.update(); - if (M5Cardputer.Keyboard.isPressed()) { + updateBoard(); + if (anyPressed()) { wait = 0; } vTaskDelay(pdMS_TO_TICKS(50)); } - M5GFX_clear_screen(); + clearScreen(); break; case 1: - M5GFX_display_text(0, 0, "Nothing"); + displayText(0, 0, "Nothing"); vTaskDelay(pdMS_TO_TICKS(200)); wait = 1; while (wait) { - M5Cardputer.update(); - if (M5Cardputer.Keyboard.isPressed()) { + updateBoard(); + if (anyPressed()) { wait = 0; } vTaskDelay(pdMS_TO_TICKS(50)); } - M5GFX_clear_screen(); + clearScreen(); break; case 2: - M5GFX_display_text(0, 40, "Good job,"); - M5GFX_display_text(0, 60, "you develop"); + displayText(0, 40, "Good job,"); + displayText(0, 60, "you develop"); vTaskDelay(pdMS_TO_TICKS(200)); wait = 1; while (wait) { - M5Cardputer.update(); - if (M5Cardputer.Keyboard.isPressed()) { + updateBoard(); + if (anyPressed()) { wait = 0; } vTaskDelay(pdMS_TO_TICKS(50)); } - M5GFX_clear_screen(); + clearScreen(); break; } } diff --git a/Firmware/BeamStalker/main/firmware/helper.h b/Firmware/BeamStalker/main/firmware/helper.h index 7230ab9..dd97b43 100644 --- a/Firmware/BeamStalker/main/firmware/helper.h +++ b/Firmware/BeamStalker/main/firmware/helper.h @@ -1,7 +1,7 @@ #ifndef HELPER_H #define HELPER_H -#define VERSION "v0-2-7-13" +#define VERSION "v0-2-7-14" #define ROW_SIZE 7 #define COLUMN_SIZE 7 #define SCREEN_WIDTH 128 diff --git a/Firmware/BeamStalker/main/firmware/includes/wifi.cpp b/Firmware/BeamStalker/main/firmware/includes/wifi.cpp index 8f69531..5863987 100644 --- a/Firmware/BeamStalker/main/firmware/includes/wifi.cpp +++ b/Firmware/BeamStalker/main/firmware/includes/wifi.cpp @@ -161,39 +161,30 @@ AP* select_wifi_menu(int *selected_ap_count) { drawMenu(Menu, Selector); - int UPp, DOWNp, LEFTp, RIGHTp, SELECTp, RETURNp; - while (1) { - M5Cardputer.update(); - if (M5Cardputer.Keyboard.isPressed()) { - UPp = M5Cardputer.Keyboard.isKeyPressed(';'); - DOWNp = M5Cardputer.Keyboard.isKeyPressed('.'); - LEFTp = M5Cardputer.Keyboard.isKeyPressed(','); - RIGHTp = M5Cardputer.Keyboard.isKeyPressed('/'); - SELECTp = M5Cardputer.Keyboard.isKeyPressed(KEY_ENTER); - RETURNp = M5Cardputer.Keyboard.isKeyPressed('`'); - - if (RETURNp) { + updateBoard(); + if (anyPressed()) { + if (returnPressed()) { vTaskDelay(pdMS_TO_TICKS(300)); return 0; } - else if (UPp) { + else if (upPressed()) { Selector = intChecker(Selector - 1, Menu.length); vTaskDelay(pdMS_TO_TICKS(50)); } - else if (DOWNp) { + else if (downPressed()) { Selector = intChecker(Selector + 1, Menu.length); vTaskDelay(pdMS_TO_TICKS(50)); } - else if (LEFTp && (Menu.elements[Selector].type == 0)) { + else if (leftPressed() && (Menu.elements[Selector].type == 0)) { Menu.elements[Selector].selector = intChecker(Menu.elements[Selector].selector - 1, Menu.elements[Selector].length); vTaskDelay(pdMS_TO_TICKS(50)); } - else if (RIGHTp && (Menu.elements[Selector].type == 0)) { + else if (rightPressed() && (Menu.elements[Selector].type == 0)) { Menu.elements[Selector].selector = intChecker(Menu.elements[Selector].selector + 1, Menu.elements[Selector].length); vTaskDelay(pdMS_TO_TICKS(50)); } - if (SELECTp) { + if (selectPressed()) { vTaskDelay(pdMS_TO_TICKS(300)); if (Selector == (Menu.length - 1)) { // Select for (int i = 0; i < ap_count; i++) { diff --git a/Firmware/BeamStalker/main/firmware/includes/wifi_sniffer.cpp b/Firmware/BeamStalker/main/firmware/includes/wifi_sniffer.cpp index ac34f2f..59ac7fc 100644 --- a/Firmware/BeamStalker/main/firmware/includes/wifi_sniffer.cpp +++ b/Firmware/BeamStalker/main/firmware/includes/wifi_sniffer.cpp @@ -7,10 +7,10 @@ void sniff_pps_timer_callback(TimerHandle_t xTimer) { snprintf(ch_buffer, sizeof(ch_buffer), "Channel: %d", channel); M5.Display.clear(); - M5GFX_display_text(0, 0*charsize, "Sniffing for 1000s", TFT_WHITE); - M5GFX_display_text(0, 2*charsize, pc_buffer, TFT_WHITE); - M5GFX_display_text(0, 3*charsize, ch_buffer, TFT_WHITE); - M5GFX_display_text(0, 7*charsize, "Press any key to exit...", TFT_WHITE); + displayText(0, 0*charsize, "Sniffing for 1000s", TFT_WHITE); + displayText(0, 2*charsize, pc_buffer, TFT_WHITE); + displayText(0, 3*charsize, ch_buffer, TFT_WHITE); + displayText(0, 7*charsize, "Press any key to exit...", TFT_WHITE); } void init_sniff_pps_timer() { @@ -297,39 +297,30 @@ mac_addr_t* select_client_menu(int *selected_client_count, AP* aps, int aps_coun drawMenu(Menu, Selector); - int UPp, DOWNp, LEFTp, RIGHTp, SELECTp, RETURNp; - while (1) { - M5Cardputer.update(); - if (M5Cardputer.Keyboard.isPressed()) { - UPp = M5Cardputer.Keyboard.isKeyPressed(';'); - DOWNp = M5Cardputer.Keyboard.isKeyPressed('.'); - LEFTp = M5Cardputer.Keyboard.isKeyPressed(','); - RIGHTp = M5Cardputer.Keyboard.isKeyPressed('/'); - SELECTp = M5Cardputer.Keyboard.isKeyPressed(KEY_ENTER); - RETURNp = M5Cardputer.Keyboard.isKeyPressed('`'); - - if (RETURNp) { + updateBoard(); + if (anyPressed()) { + if (returnPressed()) { vTaskDelay(pdMS_TO_TICKS(300)); return 0; } - else if (UPp) { + else if (upPressed()) { Selector = intChecker(Selector - 1, Menu.length); vTaskDelay(pdMS_TO_TICKS(50)); } - else if (DOWNp) { + else if (downPressed()) { Selector = intChecker(Selector + 1, Menu.length); vTaskDelay(pdMS_TO_TICKS(50)); } - else if (LEFTp && (Menu.elements[Selector].type == 0)) { + else if (leftPressed() && (Menu.elements[Selector].type == 0)) { Menu.elements[Selector].selector = intChecker(Menu.elements[Selector].selector - 1, Menu.elements[Selector].length); vTaskDelay(pdMS_TO_TICKS(50)); } - else if (RIGHTp && (Menu.elements[Selector].type == 0)) { + else if (rightPressed() && (Menu.elements[Selector].type == 0)) { Menu.elements[Selector].selector = intChecker(Menu.elements[Selector].selector + 1, Menu.elements[Selector].length); vTaskDelay(pdMS_TO_TICKS(50)); } - if (SELECTp) { + if (selectPressed()) { vTaskDelay(pdMS_TO_TICKS(300)); if (Selector == (Menu.length - 1)) { // Select mac_addr_t* selected_clients = getSelectedClients(Menu, sniff_ap_list, selected_client_count); @@ -411,39 +402,30 @@ uint16_t* select_filter_menu(int *selected_filter_count, uint16_t *filters, int drawMenu(Menu, Selector); - int UPp, DOWNp, LEFTp, RIGHTp, SELECTp, RETURNp; - while (1) { - M5Cardputer.update(); - if (M5Cardputer.Keyboard.isPressed()) { - UPp = M5Cardputer.Keyboard.isKeyPressed(';'); - DOWNp = M5Cardputer.Keyboard.isKeyPressed('.'); - LEFTp = M5Cardputer.Keyboard.isKeyPressed(','); - RIGHTp = M5Cardputer.Keyboard.isKeyPressed('/'); - SELECTp = M5Cardputer.Keyboard.isKeyPressed(KEY_ENTER); - RETURNp = M5Cardputer.Keyboard.isKeyPressed('`'); - - if (RETURNp) { + updateBoard(); + if (anyPressed()) { + if (returnPressed()) { vTaskDelay(pdMS_TO_TICKS(300)); return 0; } - else if (UPp) { + else if (upPressed()) { Selector = intChecker(Selector - 1, Menu.length); vTaskDelay(pdMS_TO_TICKS(50)); } - else if (DOWNp) { + else if (downPressed()) { Selector = intChecker(Selector + 1, Menu.length); vTaskDelay(pdMS_TO_TICKS(50)); } - else if (LEFTp && (Menu.elements[Selector].type == 0)) { + else if (leftPressed() && (Menu.elements[Selector].type == 0)) { Menu.elements[Selector].selector = intChecker(Menu.elements[Selector].selector - 1, Menu.elements[Selector].length); vTaskDelay(pdMS_TO_TICKS(50)); } - else if (RIGHTp && (Menu.elements[Selector].type == 0)) { + else if (rightPressed() && (Menu.elements[Selector].type == 0)) { Menu.elements[Selector].selector = intChecker(Menu.elements[Selector].selector + 1, Menu.elements[Selector].length); vTaskDelay(pdMS_TO_TICKS(50)); } - if (SELECTp) { + if (selectPressed()) { vTaskDelay(pdMS_TO_TICKS(300)); if (Selector == (Menu.length - 1)) { // Select uint16_t* selected_filters = getSelectedFilter(Menu, filters, selected_filter_count); diff --git a/Firmware/BeamStalker/main/firmware/menu.cpp b/Firmware/BeamStalker/main/firmware/menu.cpp index 3158f71..349e109 100644 --- a/Firmware/BeamStalker/main/firmware/menu.cpp +++ b/Firmware/BeamStalker/main/firmware/menu.cpp @@ -62,10 +62,10 @@ void drawMenu(struct menu Menu, int selector) { char fullMenuName[50]; sprintf(fullMenuName, "%s",createHeaderLine(Menu.name)); - M5GFX_clear_screen(); + clearScreen(); M5.Display.fillRect(0, 0, M5.Display.width(), charsize, TFT_CYAN); - M5GFX_display_text(0, 0, fullMenuName, TFT_BLACK); + displayText(0, 0, fullMenuName, TFT_BLACK); int j = 1; char element_str[50]; @@ -96,31 +96,17 @@ void drawMenu(struct menu Menu, int selector) { } if (i == 0) { - M5GFX_display_text(0, j*charsize, element_str, TFT_GREEN); + displayText(0, j*charsize, element_str, TFT_GREEN); } else { - M5GFX_display_text(0, j*charsize, element_str, TFT_WHITE); + displayText(0, j*charsize, element_str, TFT_WHITE); } j++; } } -void M5GFX_display_text(int x, int y, const char* text, uint32_t color) { - M5.Display.setCursor(x, y); - M5.Display.setTextColor(color); - M5.Display.print(text); -} -/* -void M5GFX_clear_screen(uint32_t color) { - M5.Display.fillScreen(color); -} -*/ -void M5GFX_clear_screen(uint32_t color) { - M5.Display.fillScreen(color); -} - int LogError(const std::string& message) { - M5GFX_clear_screen(); - M5GFX_display_text(0, 1 * charsize, message.c_str(), TFT_RED); + clearScreen(); + displayText(0, 1 * charsize, message.c_str(), TFT_RED); vTaskDelay(pdMS_TO_TICKS(5000)); return 0; } @@ -132,4 +118,41 @@ void drawBitmap(int16_t x, int16_t y, int16_t width, int16_t height, const uint8 M5.Display.drawPixel(x + j, y + i, bit ? color : TFT_BLACK); } } -} \ No newline at end of file +} + +bool upPressed() { + return M5Cardputer.Keyboard.isKeyPressed(';'); +} +bool downPressed() { + return M5Cardputer.Keyboard.isKeyPressed('.'); +} +bool leftPressed() { + return M5Cardputer.Keyboard.isKeyPressed(','); +} +bool rightPressed() { + return M5Cardputer.Keyboard.isKeyPressed('/'); +} +bool selectPressed() { + return M5Cardputer.Keyboard.isKeyPressed(KEY_ENTER); +} +bool returnPressed() { + return M5Cardputer.Keyboard.isKeyPressed('`'); +} + +bool anyPressed() { + return M5Cardputer.Keyboard.isPressed(); +} + +void updateBoard() { + M5Cardputer.update(); +} + +void displayText(int x, int y, const char* text, uint32_t color) { + M5.Display.setCursor(x, y); + M5.Display.setTextColor(color); + M5.Display.print(text); +} + +void clearScreen(uint32_t color) { + M5.Display.fillScreen(color); +} diff --git a/Firmware/BeamStalker/main/firmware/menu.h b/Firmware/BeamStalker/main/firmware/menu.h index 0fb8eec..d0fa31b 100644 --- a/Firmware/BeamStalker/main/firmware/menu.h +++ b/Firmware/BeamStalker/main/firmware/menu.h @@ -28,9 +28,20 @@ int charsize = (int)(font_size*charsize_multiplier)+((40*font_size)/100); int intChecker(int value, int length); char *createHeaderLine(const char *menu_name); void drawMenu(struct menu Menu, int selector); -void M5GFX_display_text(int x, int y, const char* text, uint32_t color = TFT_WHITE); -void M5GFX_clear_screen(uint32_t color = TFT_BLACK); int LogError(const std::string& message); void drawBitmap(int16_t x, int16_t y, int16_t width, int16_t height, const uint8_t *bitmap, uint32_t color); +bool upPressed(); +bool downPressed(); +bool leftPressed(); +bool rightPressed(); +bool selectPressed(); +bool returnPressed(); + +bool anyPressed(); +void updateBoard(); + +void displayText(int x, int y, const char* text, uint32_t color = TFT_WHITE); +void clearScreen(uint32_t color = TFT_BLACK); + #endif \ No newline at end of file From 68e9d74d35ecc6d872b71b8f54d73beb8347542b Mon Sep 17 00:00:00 2001 From: Rick Astley Date: Tue, 7 Jan 2025 08:00:17 +0100 Subject: [PATCH 2/3] updating action (build on PR, release on merge) --- .github/workflows/build-and-release.yml | 47 +++++++++++++++++++++++++ .github/workflows/build-firmware.yml | 25 ------------- 2 files changed, 47 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/build-and-release.yml diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml new file mode 100644 index 0000000..f295db0 --- /dev/null +++ b/.github/workflows/build-and-release.yml @@ -0,0 +1,47 @@ +name: Build and release + +on: + push: + branches: + - main + +jobs: + build-and-release: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + submodules: 'recursive' + + - name: Build ESP-IDF Firmware + uses: espressif/esp-idf-ci-action@v1 + with: + command: /app/Retr0Kr0dy/BeamStalker/patch-esp-idf.sh && idf.py build + esp_idf_version: v4.4 + target: esp32s3 # Currently we only build for M5Cardputer (so esp32s3) + path: 'Firmware/BeamStalker' + + - name: Set name and tag_name + id: set_name + run: | + if [[ "${{ github.event_name }}" == "pull_request" && -n "${{ github.event.pull_request.title }}" ]]; then + echo "name=${{ github.event.pull_request.title }}" >> $GITHUB_ENV + echo "tag_name=${{ github.event.pull_request.title }}" >> $GITHUB_ENV + elif [[ -n "${{ github.event.head_commit.message }}" ]]; then + echo "name=${{ github.event.head_commit.message }}" >> $GITHUB_ENV + echo "tag_name=${{ github.event.head_commit.message }}" >> $GITHUB_ENV + else + echo "name=BeamStalker" >> $GITHUB_ENV + echo "tag_name=vX" >> $GITHUB_ENV + fi + + - name: Create Release + uses: softprops/action-gh-release@v1 + with: + name: ${{ env.name }} + tag_name: ${{ env.tag_name }} + fail_on_unmatched_files: true + files: | + Firmware/BeamStalker/build/BeamStalker-v*.bin diff --git a/.github/workflows/build-firmware.yml b/.github/workflows/build-firmware.yml index 08ff2de..479a899 100644 --- a/.github/workflows/build-firmware.yml +++ b/.github/workflows/build-firmware.yml @@ -4,9 +4,6 @@ on: pull_request: branches: - '**' - push: - branches: - - main jobs: build: @@ -25,25 +22,3 @@ jobs: esp_idf_version: v4.4 target: esp32s3 # Currently we only build for M5Cardputer (so esp32s3) path: 'Firmware/BeamStalker' - - - name: Set name and tag_name - id: set_name - run: | - if [[ "${{ github.event_name }}" == "pull_request" && -n "${{ github.event.pull_request.title }}" ]]; then - echo "name=${{ github.event.pull_request.title }}" >> $GITHUB_ENV - echo "tag_name=${{ github.event.pull_request.title }}" >> $GITHUB_ENV - elif [[ -n "${{ github.event.head_commit.message }}" ]]; then - echo "name=${{ github.event.head_commit.message }}" >> $GITHUB_ENV - echo "tag_name=${{ github.event.head_commit.message }}" >> $GITHUB_ENV - else - echo "name=BeamStalker" >> $GITHUB_ENV - echo "tag_name=vX" >> $GITHUB_ENV - fi - - name: Create Release - uses: softprops/action-gh-release@v1 - with: - name: ${{ env.name }} - tag_name: ${{ env.tag_name }} - fail_on_unmatched_files: true - files: | - Firmware/BeamStalker/build/BeamStalker-v*.bin From fe9167e365a97055fee1fe0e8248e32a18481bca Mon Sep 17 00:00:00 2001 From: Rick Astley Date: Tue, 7 Jan 2025 09:21:06 +0100 Subject: [PATCH 3/3] created Kconfig in preparation of cross-plateform --- .../BeamStalker/main/BeamStalker-cardputer.cpp | 9 ++++----- Firmware/BeamStalker/main/Kconfig.projbuild | 9 +++++++++ Firmware/BeamStalker/main/firmware/menu.cpp | 16 ++++++++++++++++ Firmware/BeamStalker/main/firmware/menu.h | 8 ++++++++ Firmware/BeamStalker/sdkconfig.defaults | 2 ++ 5 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 Firmware/BeamStalker/main/Kconfig.projbuild diff --git a/Firmware/BeamStalker/main/BeamStalker-cardputer.cpp b/Firmware/BeamStalker/main/BeamStalker-cardputer.cpp index 4372d31..43b4208 100644 --- a/Firmware/BeamStalker/main/BeamStalker-cardputer.cpp +++ b/Firmware/BeamStalker/main/BeamStalker-cardputer.cpp @@ -20,11 +20,6 @@ extern "C" { #include "firmware/apps/Wifi/wifi_main.h" #include "firmware/apps/BLE/ble_main.h" -#include "M5Cardputer.h" - -M5GFX display; -M5Canvas canvas(&display); - int mainTask() { vTaskDelay(pdMS_TO_TICKS(100)); @@ -118,8 +113,10 @@ int mainTask() { } extern "C" void app_main(void) { + #ifdef CONFIG_M5_BOARD M5Cardputer.begin(true); M5.Power.begin(); + #endif esp_err_t ret = nvs_flash_init(); if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { @@ -141,10 +138,12 @@ extern "C" void app_main(void) { vTaskDelay(pdMS_TO_TICKS(200)); + #ifdef CONFIG_M5_BOARD M5.Display.setCursor(0, 70); M5.Display.print(name); M5.Display.setCursor(0, 90); M5.Display.print(VERSION); + #endif printf("%s %s\n", name, VERSION); diff --git a/Firmware/BeamStalker/main/Kconfig.projbuild b/Firmware/BeamStalker/main/Kconfig.projbuild new file mode 100644 index 0000000..ae63527 --- /dev/null +++ b/Firmware/BeamStalker/main/Kconfig.projbuild @@ -0,0 +1,9 @@ +menu "BeamStalker Build Configuration" + +config M5_BOARD + bool "is M5Stack hardware" + default n + help + Specify if board is using M5Stack libs. + +endmenu \ No newline at end of file diff --git a/Firmware/BeamStalker/main/firmware/menu.cpp b/Firmware/BeamStalker/main/firmware/menu.cpp index 349e109..e63b8f7 100644 --- a/Firmware/BeamStalker/main/firmware/menu.cpp +++ b/Firmware/BeamStalker/main/firmware/menu.cpp @@ -121,30 +121,46 @@ void drawBitmap(int16_t x, int16_t y, int16_t width, int16_t height, const uint8 } bool upPressed() { + #ifdef CONFIG_M5_BOARD return M5Cardputer.Keyboard.isKeyPressed(';'); + #endif } bool downPressed() { + #ifdef CONFIG_M5_BOARD return M5Cardputer.Keyboard.isKeyPressed('.'); + #endif } bool leftPressed() { + #ifdef CONFIG_M5_BOARD return M5Cardputer.Keyboard.isKeyPressed(','); + #endif } bool rightPressed() { + #ifdef CONFIG_M5_BOARD return M5Cardputer.Keyboard.isKeyPressed('/'); + #endif } bool selectPressed() { + #ifdef CONFIG_M5_BOARD return M5Cardputer.Keyboard.isKeyPressed(KEY_ENTER); + #endif } bool returnPressed() { + #ifdef CONFIG_M5_BOARD return M5Cardputer.Keyboard.isKeyPressed('`'); + #endif } bool anyPressed() { + #ifdef CONFIG_M5_BOARD return M5Cardputer.Keyboard.isPressed(); + #endif } void updateBoard() { + #ifdef CONFIG_M5_BOARD M5Cardputer.update(); + #endif } void displayText(int x, int y, const char* text, uint32_t color) { diff --git a/Firmware/BeamStalker/main/firmware/menu.h b/Firmware/BeamStalker/main/firmware/menu.h index d0fa31b..18beb8f 100644 --- a/Firmware/BeamStalker/main/firmware/menu.h +++ b/Firmware/BeamStalker/main/firmware/menu.h @@ -31,6 +31,8 @@ void drawMenu(struct menu Menu, int selector); int LogError(const std::string& message); void drawBitmap(int16_t x, int16_t y, int16_t width, int16_t height, const uint8_t *bitmap, uint32_t color); +/* Future interface.cpp */ + bool upPressed(); bool downPressed(); bool leftPressed(); @@ -44,4 +46,10 @@ void updateBoard(); void displayText(int x, int y, const char* text, uint32_t color = TFT_WHITE); void clearScreen(uint32_t color = TFT_BLACK); +#ifdef CONFIG_M5_BOARD +M5GFX display; +M5Canvas canvas(&display); +#endif + + #endif \ No newline at end of file diff --git a/Firmware/BeamStalker/sdkconfig.defaults b/Firmware/BeamStalker/sdkconfig.defaults index 29a9a04..7acc68e 100644 --- a/Firmware/BeamStalker/sdkconfig.defaults +++ b/Firmware/BeamStalker/sdkconfig.defaults @@ -6,3 +6,5 @@ CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" CONFIG_BT_ENABLED=y CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y + +CONFIG_M5_BOARD=y