From 66a04c69529ee9303dbf7472baa049a7a6168ae0 Mon Sep 17 00:00:00 2001 From: Pirata Date: Mon, 30 Dec 2024 20:00:20 -0300 Subject: [PATCH] Custom WifiBeacon, Portrait orientation Added Custom WIFI Beacon Spam, need to save a file with a name in each line to use https://github.com/pr3y/Bruce/issues/610 Added possibility to boards higher than 240x240 to be used in portrait mode (CYD and Core x) Enhanced overall keyboards to not keep the bar selected when not in it. Enhanced T-Embed CC1101 keyboard to run over all keyboard without press btn, but btn still works Preparing to say goodbye to M5Unified and M5GFX library files --- .gitignore | 1 + boards/CYD-2432S028/interface.cpp | 63 ++++++++++++++-------- boards/lilygo-t-embed-cc1101/interface.cpp | 17 +++--- boards/m5stack-core/interface.cpp | 2 +- boards/m5stack-core2/interface.cpp | 63 ++++++++++++++++++++-- boards/m5stack-cores3/interface.cpp | 45 +++++++++++++--- boards/m5stack-cplus1_1/interface.cpp | 6 +-- boards/m5stack-cplus2/interface.cpp | 6 +-- boards/smoochiee-board/interface.cpp | 13 +++-- include/MenuItemInterface.h | 33 ++++++++++++ lib/Unified/M5Unified.cpp | 2 +- src/core/config.cpp | 2 +- src/core/settings.cpp | 29 +++++++++- src/core/wifi_common.cpp | 1 + src/main.cpp | 9 ++-- src/modules/others/webInterface.cpp | 3 ++ src/modules/wifi/wifi_atks.cpp | 43 +++++++++++++-- 17 files changed, 274 insertions(+), 64 deletions(-) diff --git a/.gitignore b/.gitignore index 0c67c5312..a4a51e4bb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .vscode/.browse.c_cpp.db* .vscode/c_cpp_properties.json .vscode/launch.json +.vscode/extensions.json .vscode/ipch Bruce3_*.bin bruce.conf diff --git a/boards/CYD-2432S028/interface.cpp b/boards/CYD-2432S028/interface.cpp index 62ecd7af0..8c590b975 100644 --- a/boards/CYD-2432S028/interface.cpp +++ b/boards/CYD-2432S028/interface.cpp @@ -120,12 +120,21 @@ bool menuPress(int bot) { if (touch.touched()) { //touch.tirqTouched() && auto t = touch.getPointScaled(); t = touch.getPointScaled(); - //log_i("Touchscreen Pressed at x=%d, y=%d, z=%d", t.x,t.y,t.z); - if(bruceConfig.rotation==3) { - t.y = (tftHeight+20)-t.y; - t.x = tftWidth-t.x; - } - + if(bruceConfig.rotation==3) { + t.y = (tftHeight+20)-t.y; + t.x = tftWidth-t.x; + } + if(bruceConfig.rotation==0) { + int tmp=t.x; + t.x = tftWidth-t.y; + t.y = tmp; + } + if(bruceConfig.rotation==2) { + int tmp=t.x; + t.x = t.y; + t.y = (tftHeight+20)-tmp; + } + //log_i("Touchscreen Pressed at x=%d, y=%d, z=%d, rotation=%d", t.x,t.y,t.z,bruceConfig.rotation); if(t.y>(tftHeight) && ((t.x>terco*bot && t.x3) { y=-1; } @@ -485,12 +485,11 @@ String keyboard(String mytext, int maxSize, String msg) { // To handle Encoder devices such as T-EMBED #ifdef T_EMBED_1101 if(digitalRead(BK_BTN) == BTN_ACT) { y--; } - #else - if(x==0) { y--; x--; } #endif + if(x==0) { y--; x--; } else x--; - if(y<0 && x<0) x=3; + if(y<0 && x<0) x=11; if(x>11) x=0; else if (x<0) x=11; @@ -529,11 +528,11 @@ void checkReboot() { // Display poweroff bar only if holding button if (millis() - time_count > 500) { tft.setTextSize(1); - tft.setTextColor(TFT_RED, TFT_BLACK); + tft.setTextColor(bruceConfig.priColor, bruceConfig.bgColor); countDown = (millis() - time_count) / 1000 + 1; if(countDown<4) tft.drawCentreString("PWR OFF IN "+String(countDown)+"/3",tftWidth/2,12,1); else { - tft.fillScreen(TFT_BLACK); + tft.fillScreen(bruceConfig.bgColor); while(digitalRead(BK_BTN)==BTN_ACT); delay(200); powerOff(); @@ -544,7 +543,7 @@ void checkReboot() { // Clear text after releasing the button delay(30); - tft.fillRect(60, 12, tftWidth - 60, tft.fontHeight(1), TFT_BLACK); + tft.fillRect(60, 12, tftWidth - 60, tft.fontHeight(1), bruceConfig.bgColor); } #endif } diff --git a/boards/m5stack-core/interface.cpp b/boards/m5stack-core/interface.cpp index 0f7f6c302..ce8446d0f 100644 --- a/boards/m5stack-core/interface.cpp +++ b/boards/m5stack-core/interface.cpp @@ -222,7 +222,7 @@ String keyboard(String mytext, int maxSize, String msg) { tft.setTextSize(FM); //Draw the rectangles - if(y<0) { + if(y<0 || y2<0) { tft.fillRect(0,1,tftWidth,22,bruceConfig.bgColor); tft.drawRect(7,2,46,20,TFT_WHITE); // Ok Rectangle tft.drawRect(55,2,50,20,TFT_WHITE); // CAP Rectangle diff --git a/boards/m5stack-core2/interface.cpp b/boards/m5stack-core2/interface.cpp index 1465d95aa..991a3389e 100644 --- a/boards/m5stack-core2/interface.cpp +++ b/boards/m5stack-core2/interface.cpp @@ -36,6 +36,45 @@ void _setBrightness(uint8_t brightval) { M5.Display.setBrightness(brightval); } +#define PREV 0 +#define SEL 1 +#define NEXT 2 +#define ALL 3 + +bool menuPress(int bot) { + //0 - prev + //1 - Sel + //2 - next + //3 - all + M5.update(); + auto t = M5.Touch.getDetail(); + int terco=tftWidth/3; + if (t.isPressed() || t.isHolding()) { + + if(bruceConfig.rotation==3) { + t.y = (tftHeight+20)-t.y; + t.x = tftWidth-t.x; + } + if(bruceConfig.rotation==0) { + int tmp=t.x; + t.x = tftWidth-t.y; + t.y = tmp; + } + if(bruceConfig.rotation==2) { + int tmp=t.x; + t.x = t.y; + t.y = (tftHeight+20)-tmp; + } + //log_i("Touchscreen Pressed at x=%d, y=%d, z=%d, rotation=%d", t.x,t.y,t.z,bruceConfig.rotation); + if(t.y>(tftHeight) && ((t.x>terco*bot && t.x(tftHeight) && (t.x>terco*bot && t.x(tftHeight) && ((t.x>terco*bot && t.x 500) { tft.setCursor(60, 12); tft.setTextSize(1); - tft.setTextColor(TFT_RED, TFT_BLACK); + tft.setTextColor(bruceConfig.priColor, bruceConfig.bgColor); countDown = (millis() - time_count) / 1000 + 1; tft.printf(" PWR OFF IN %d/3\n", countDown); delay(10); @@ -371,6 +371,6 @@ void checkReboot() { } // Clear text after releasing the button delay(30); - tft.fillRect(60, 12, tftWidth - 60, tft.fontHeight(1), TFT_BLACK); + tft.fillRect(60, 12, tftWidth - 60, tft.fontHeight(1), bruceConfig.bgColor); } } diff --git a/boards/m5stack-cplus2/interface.cpp b/boards/m5stack-cplus2/interface.cpp index 6752e0ec2..8d62b3c49 100644 --- a/boards/m5stack-cplus2/interface.cpp +++ b/boards/m5stack-cplus2/interface.cpp @@ -236,7 +236,7 @@ String keyboard(String mytext, int maxSize, String msg) { tft.setTextSize(FM); //Draw the rectangles - if(y<0) { + if(y<0 || y2<0) { tft.fillRect(0,1,tftWidth,22,bruceConfig.bgColor); tft.drawRect(7,2,46,20,TFT_WHITE); // Ok Rectangle tft.drawRect(55,2,50,20,TFT_WHITE); // CAP Rectangle @@ -430,7 +430,7 @@ void checkReboot() { if (millis() - time_count > 500) { tft.setCursor(60, 12); tft.setTextSize(1); - tft.setTextColor(TFT_RED, TFT_BLACK); + tft.setTextColor(bruceConfig.priColor, bruceConfig.bgColor); countDown = (millis() - time_count) / 1000 + 1; tft.printf(" PWR OFF IN %d/3\n", countDown); delay(10); @@ -439,6 +439,6 @@ void checkReboot() { // Clear text after releasing the button delay(30); - tft.fillRect(60, 12, tftWidth - 60, tft.fontHeight(1), TFT_BLACK); + tft.fillRect(60, 12, tftWidth - 60, tft.fontHeight(1), bruceConfig.bgColor); } } \ No newline at end of file diff --git a/boards/smoochiee-board/interface.cpp b/boards/smoochiee-board/interface.cpp index 01d411e61..dd77ef438 100644 --- a/boards/smoochiee-board/interface.cpp +++ b/boards/smoochiee-board/interface.cpp @@ -457,17 +457,22 @@ void checkReboot() { { // Display poweroff bar only if holding button if (millis() - time_count > 500) { - tft.setCursor(60, 12); tft.setTextSize(1); - tft.setTextColor(TFT_RED, TFT_BLACK); + tft.setTextColor(bruceConfig.priColor, bruceConfig.bgColor); countDown = (millis() - time_count) / 1000 + 1; - tft.printf(" PWR OFF IN %d/3\n", countDown); + if(countDown<4) tft.drawCentreString("PWR OFF IN "+String(countDown)+"/3",tftWidth/2,12,1); + else { + tft.fillScreen(bruceConfig.bgColor); + while(digitalRead(L_BTN)==BTN_ACT || digitalRead(R_BTN)==BTN_ACT); + delay(200); + powerOff(); + } delay(10); } } // Clear text after releasing the button delay(30); - tft.fillRect(60, 12, tftWidth - 60, tft.fontHeight(1), TFT_BLACK); + tft.fillRect(60, 12, tftWidth - 60, tft.fontHeight(1), bruceConfig.bgColor); } } \ No newline at end of file diff --git a/include/MenuItemInterface.h b/include/MenuItemInterface.h index bfdc3ce3b..5316d45ec 100644 --- a/include/MenuItemInterface.h +++ b/include/MenuItemInterface.h @@ -14,6 +14,8 @@ class MenuItemInterface { String getName() const {return _name;} void draw(float scale = 1) { + if(rotation!=bruceConfig.rotation) resetCoordinates(); + drawIcon(scale); drawArrows(scale); drawTitle(scale); @@ -84,6 +86,7 @@ class MenuItemInterface { protected: String _name = ""; + uint8_t rotation=ROTATION; int iconAreaH = ( (tftHeight - 2*BORDER_PAD_Y) % 2 == 0 @@ -106,6 +109,36 @@ class MenuItemInterface { void clearIconArea(void) { tft.fillRect(iconAreaX, iconAreaY, iconAreaW, iconAreaH, bruceConfig.bgColor); } + + void resetCoordinates(void) { + // Recalculate Center and ared due to portrait/landscape changings + if(tftWidth>tftHeight) { + iconAreaH = ( + (tftHeight - 2*BORDER_PAD_Y) % 2 == 0 + ? tftHeight - 2*BORDER_PAD_Y + : tftHeight - 2*BORDER_PAD_Y + 1 + ); + } else { + iconAreaH = ( + (tftWidth - 2*BORDER_PAD_Y) % 2 == 0 + ? tftWidth - 2*BORDER_PAD_Y + : tftWidth - 2*BORDER_PAD_Y + 1 + ); + } + + iconAreaW = iconAreaH; + + iconCenterX = tftWidth/2; + iconCenterY = tftHeight/2; + + iconAreaX = iconCenterX - iconAreaW/2; + iconAreaY = iconCenterY - iconAreaH/2; + + arrowAreaX = BORDER_PAD_X; + arrowAreaW = iconAreaX - arrowAreaX; + + rotation = bruceConfig.rotation; + } }; #endif diff --git a/lib/Unified/M5Unified.cpp b/lib/Unified/M5Unified.cpp index 96e7c413b..93b7325a5 100644 --- a/lib/Unified/M5Unified.cpp +++ b/lib/Unified/M5Unified.cpp @@ -1193,7 +1193,7 @@ for (int i = 0; i < 0x50; ++i) while (--i >= 0) { auto raw = Touch.getTouchPointRaw(i); - if (raw.y > 220) //240 - 20 to bottom margin where buttons are placed + if (raw.y > 240) //240 - 20 to bottom margin where buttons are placed // Back to origins { auto det = Touch.getDetail(i); if (det.state & touch_state_t::touch) diff --git a/src/core/config.cpp b/src/core/config.cpp index 44821f869..374ad3a4c 100644 --- a/src/core/config.cpp +++ b/src/core/config.cpp @@ -226,7 +226,7 @@ void BruceConfig::setRotation(int value) { void BruceConfig::validateRotationValue() { - if (rotation!=1 && rotation!=3) rotation = 1; + if (rotation<0 && rotation>3) rotation = 1; } diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 1831e063a..9113622b5 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -53,6 +53,16 @@ int gsetRotation(bool set){ int getRot = bruceConfig.rotation; int result = ROTATION; + #if TFT_WIDTH>=240 && TFT_HEIGHT>=240 + getRot++; + if(getRot>3 && set) result = 0; + else if(set) result = getRot; + else if(getRot<=3) result = getRot; + else { + set=true; + result = ROTATION; + } + #else if(getRot==1 && set) result = 3; else if(getRot==3 && set) result = 1; else if(getRot<=3) result = getRot; @@ -60,13 +70,30 @@ int gsetRotation(bool set){ set=true; result = ROTATION; } + #endif if(set) { bruceConfig.setRotation(result); tft.setRotation(result); - tft.setRotation(result); + tft.setRotation(result); // must repeat, sometimes ESP32S3 miss one SPI command and it just jumps this step and don't rotate } returnToMenu=true; + + if(result & 0b01) { // if 1 or 3 + tftWidth=TFT_HEIGHT; + #if defined(HAS_TOUCH) + tftHeight=TFT_WIDTH - 20; + #else + tftHeight=TFT_WIDTH; + #endif + } else { // if 2 or 0 + tftWidth=TFT_WIDTH; + #if defined(HAS_TOUCH) + tftHeight=TFT_HEIGHT-20; + #else + tftHeight=TFT_HEIGHT; + #endif + } return result; } diff --git a/src/core/wifi_common.cpp b/src/core/wifi_common.cpp index 1a4f60bad..a063d8db4 100644 --- a/src/core/wifi_common.cpp +++ b/src/core/wifi_common.cpp @@ -115,6 +115,7 @@ bool wifiConnectMenu(wifi_mode_t mode) WiFi.SSID(i).c_str(), [=]() { _wifiConnect(WiFi.SSID(i), int(WiFi.encryptionType(i))); } ); } + options.emplace_back("Hidden SSID",[=](){ String __ssid=keyboard("", 32, "Your SSID"); _wifiConnect(__ssid.c_str(),8); }); options.emplace_back( "Main Menu", [=](){ backToMenu(); }); delay(200); loopOptions(options); diff --git a/src/main.cpp b/src/main.cpp index 75af8ceef..d5f1d1e27 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -175,7 +175,6 @@ void boot_screen_anim() { //else if(LittleFS.exists("/boot.gif")) boot_img = 4; // Start image loop while(millis()2000) && !drawn) { tft.fillRect(0,45,tftWidth,tftHeight-45,bruceConfig.bgColor); if(boot_img > 0 && !drawn) { @@ -188,11 +187,12 @@ void boot_screen_anim() { } drawn=true; } + #if !defined(LITE_VERSION) if(!boot_img && (millis()-i>2200) && (millis()-i)<2700) tft.drawRect(2*tftWidth/3,tftHeight/2,2,2,bruceConfig.priColor); if(!boot_img && (millis()-i>2700) && (millis()-i)<2900) tft.fillRect(0,45,tftWidth,tftHeight-45,bruceConfig.bgColor); - if(!boot_img && (millis()-i>2900) && (millis()-i)<3400) tft.drawXBitmap(2*tftWidth/3 - 30 ,5+tftHeight/2,bruce_small_bits, bruce_small_width, bruce_small_height,TFT_BLACK,bruceConfig.priColor); + if(!boot_img && (millis()-i>2900) && (millis()-i)<3400) tft.drawXBitmap(2*tftWidth/3 - 30 ,5+tftHeight/2,bruce_small_bits, bruce_small_width, bruce_small_height,bruceConfig.bgColor,bruceConfig.priColor); if(!boot_img && (millis()-i>3400) && (millis()-i)<3600) tft.fillRect(0,0,tftWidth,tftHeight,bruceConfig.bgColor); - if(!boot_img && (millis()-i>3600)) tft.drawXBitmap((tftWidth-238)/2,(tftHeight-133)/2,bits, bits_width, bits_height,TFT_BLACK,bruceConfig.priColor); + if(!boot_img && (millis()-i>3600)) tft.drawXBitmap((tftWidth-238)/2,(tftHeight-133)/2,bits, bits_width, bits_height,bruceConfig.bgColor,bruceConfig.priColor); #endif if(checkAnyKeyPress()) // If any key or M5 key is pressed, it'll jump the boot screen { @@ -347,7 +347,8 @@ void loop() { } if (redraw) { - mainMenu.draw(float((float)tftHeight/(float)135)); + if(bruceConfig.rotation & 0b01) mainMenu.draw(float((float)tftHeight/(float)135)); + else mainMenu.draw(float((float)tftWidth/(float)240)); clock_update=0; // forces clock drawing redraw = false; delay(REDRAW_DELAY); diff --git a/src/modules/others/webInterface.cpp b/src/modules/others/webInterface.cpp index df7f80bb9..3198a668a 100644 --- a/src/modules/others/webInterface.cpp +++ b/src/modules/others/webInterface.cpp @@ -261,6 +261,9 @@ void drawWebUiScreen(bool mode_ap) { tft.setTextColor(TFT_RED); tft.setTextSize(FP); + #if defined(HAS_TOUCH) + TouchFooter(); + #endif tft.drawCentreString("press Esc to stop", tftWidth/2,tftHeight-15,1); diff --git a/src/modules/wifi/wifi_atks.cpp b/src/modules/wifi/wifi_atks.cpp index 7ae35e78f..94b94f95e 100644 --- a/src/modules/wifi/wifi_atks.cpp +++ b/src/modules/wifi/wifi_atks.cpp @@ -121,6 +121,8 @@ void wifi_atk_menu() { beaconAttack(); }}, {"Deauth Flood", [=]() { deauthFloodAttack(); }}, + {"Main Menu", [&]() + { returnToMenu=true; }} }; delay(200); loopOptions(options); @@ -574,17 +576,21 @@ void beaconAttack() { BeaconMode = 1; txt = "Spamming Ricky"; }}, {"Random SSID", [&]() { BeaconMode = 2; txt = "Spamming Random"; }}, + {"Custom SSIDs", [&]() + { BeaconMode = 3; txt = "Spamming Custom"; }}, + {"Main Menu", [&]() + { returnToMenu=true; }} }; delay(200); loopOptions(options); delay(200); wifiConnected = true; // display wifi icon - // drawMainMenu(0); - displaySomething(txt); + String beaconFile = ""; + File file; + FS *fs; while (1) { - displaySomething(String(txt)); delay(200); if (BeaconMode == 0) { @@ -599,8 +605,37 @@ void beaconAttack() char *randoms = randomSSID(); beaconSpamList(randoms); } - if (checkEscPress()) + else if (BeaconMode == 3) + { + if(!file) { + options = { }; + + if(setupSdCard()) { + options.push_back({"SD Card", [&]() { fs=&SD; }}); + } + options.push_back({"LittleFS", [&]() { fs=&LittleFS; }}); + options.push_back({"Main Menu", [&]() { fs=nullptr; returnToMenu=true; }}); + + delay(250); + loopOptions(options); + delay(250); + if(fs!=nullptr) beaconFile = loopSD(*fs,true,"TXT"); + else goto END; + file=fs->open(beaconFile,FILE_READ); + beaconFile = file.readString(); + beaconFile.replace('\r\n','\n'); + } + + const char* randoms = beaconFile.c_str(); + beaconSpamList(randoms); + + } + if (checkEscPress() || returnToMenu){ + if(BeaconMode==3) file.close(); break; + } + displaySomething(String(txt)); } + END: wifiDisconnect(); }