MCPcopy Create free account
hub / github.com/BruceDevices/firmware / getScriptFromUser

Function getScriptFromUser

src/modules/ble/BLE_Suite.cpp:2961–3087  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2959}
2960
2961String getScriptFromUser() {
2962 const int MAX_SCRIPTS = 10;
2963 String scripts[MAX_SCRIPTS];
2964 int scriptCount = 0;
2965
2966 scripts[scriptCount++] = "Example: Open Calculator";
2967 scripts[scriptCount++] = "Example: Open CMD/Terminal";
2968 scripts[scriptCount++] = "Example: WiFi Credentials";
2969 scripts[scriptCount++] = "Example: Reverse Shell";
2970 scripts[scriptCount++] = "Example: Rickroll";
2971 scripts[scriptCount++] = "Load from SD";
2972 scripts[scriptCount++] = "Cancel";
2973
2974 int selected = 0, scrollOffset = 0;
2975 int lastSelected = -1, lastScrollOffset = -1;
2976 bool exitMenu = false;
2977 int menuStartY = 60, menuItemHeight = 25;
2978 int maxVisibleItems = (tftHeight - menuStartY - 50) / menuItemHeight;
2979 if (maxVisibleItems > scriptCount) maxVisibleItems = scriptCount;
2980
2981 while (!exitMenu) {
2982 if (selected != lastSelected || scrollOffset != lastScrollOffset) {
2983 tft.fillScreen(bruceConfig.bgColor);
2984 tft.drawRect(5, 5, tftWidth - 10, tftHeight - 10, TFT_WHITE);
2985
2986 tft.setTextColor(TFT_WHITE, bruceConfig.bgColor);
2987 tft.setTextSize(2);
2988 tft.setCursor((tftWidth - strlen("SELECT SCRIPT") * 12) / 2, 15);
2989 tft.print("SELECT SCRIPT");
2990 tft.setTextSize(1);
2991
2992 for (int i = 0; i < maxVisibleItems && (scrollOffset + i) < scriptCount; i++) {
2993 int scriptIdx = scrollOffset + i;
2994 int yPos = menuStartY + (i * menuItemHeight);
2995 if (yPos + menuItemHeight > tftHeight - 45) break;
2996
2997 if (scriptIdx == selected) {
2998 tft.fillRect(20, yPos, tftWidth - 40, menuItemHeight - 3, TFT_WHITE);
2999 tft.setTextColor(TFT_BLACK, TFT_WHITE);
3000 tft.setCursor(25, yPos + 8);
3001 tft.print("> ");
3002 } else {
3003 tft.fillRect(20, yPos, tftWidth - 40, menuItemHeight - 3, bruceConfig.bgColor);
3004 tft.setTextColor(TFT_WHITE, bruceConfig.bgColor);
3005 tft.setCursor(25, yPos + 8);
3006 tft.print(" ");
3007 }
3008
3009 String displayName = scripts[scriptIdx];
3010 if (displayName.length() > 28) displayName = displayName.substring(0, 25) + "...";
3011 tft.print(displayName);
3012 }
3013
3014 if (scriptCount > maxVisibleItems) {
3015 tft.setTextColor(TFT_CYAN, bruceConfig.bgColor);
3016 tft.setCursor(tftWidth - 25, menuStartY + 5);
3017 if (scrollOffset > 0) tft.print("^");
3018 tft.setCursor(tftWidth - 25, menuStartY + (maxVisibleItems * menuItemHeight) - 20);

Callers 2

showHIDSubMenuFunction · 0.85
showPayloadSubMenuFunction · 0.85

Calls 10

checkFunction · 0.85
selectFileFromSDFunction · 0.85
loadScriptFromSDFunction · 0.85
fillScreenMethod · 0.45
drawRectMethod · 0.45
setTextColorMethod · 0.45
setTextSizeMethod · 0.45
setCursorMethod · 0.45
printMethod · 0.45
fillRectMethod · 0.45

Tested by

no test coverage detected