From d6f20ec1fa15ebdf31586c980046ae5c678be251 Mon Sep 17 00:00:00 2001 From: Just Call Me Koko Date: Thu, 15 Apr 2021 21:20:47 -0400 Subject: [PATCH] add Save As to ducky scripts --- esp32_marauder/MenuFunctions.cpp | 49 ++++++++++++++++++++++++++++++-- esp32_marauder/MenuFunctions.h | 1 + 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/esp32_marauder/MenuFunctions.cpp b/esp32_marauder/MenuFunctions.cpp index f3dc7abfc..646254704 100644 --- a/esp32_marauder/MenuFunctions.cpp +++ b/esp32_marauder/MenuFunctions.cpp @@ -235,9 +235,54 @@ void MenuFunctions::joinWiFiGFX(){ // Function to create keyboard for saving file name void save_as_keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event) { - if(event == LV_EVENT_APPLY){ + extern MenuFunctions menu_function_obj; + + lv_keyboard_def_event_cb(save_as_kb, event); + + // User canceled so we will get rid of the keyboard and text box + if (event == LV_EVENT_CANCEL) { + lv_obj_del_async(save_as_kb); + lv_obj_del_async(save_name); + } + + // Save content from ta1 to file name in save_name + else if(event == LV_EVENT_APPLY){ String display_string = ""; printf("LV_EVENT_APPLY\n"); + + // Get ducky script + String content = lv_textarea_get_text(ta1); + + String target_file_name = "/SCRIPTS/" + (String)lv_textarea_get_text(save_name); + + Serial.println("Writing to target file: " + (String)target_file_name); + + // Open file with the given name + File script = SD.open(target_file_name, FILE_WRITE); + + if (script) { + menu_function_obj.loaded_file = target_file_name; + + Serial.println("Writing content: "); + Serial.println(content); + + script.print(content); + + script.close(); + } + + lv_obj_del_async(save_as_kb); + lv_obj_del_async(save_name); + + // Create Save button + lv_obj_t * save_label; + lv_obj_t * save_btn = lv_btn_create(lv_scr_act(), NULL); + lv_obj_set_event_cb(save_btn, load_btn_cb); + lv_obj_set_height(save_btn, 35); + lv_obj_set_width(save_btn, LV_HOR_RES / 3); + lv_obj_align(save_btn, ta1, LV_ALIGN_IN_TOP_LEFT, NULL, (LV_VER_RES / 2) - 35); // align to text area + save_label = lv_label_create(save_btn, NULL); + lv_label_set_text(save_label, "Save"); } } @@ -353,7 +398,7 @@ void load_btn_cb(lv_obj_t * load_btn, lv_event_t event) { lv_textarea_set_placeholder_text(save_name, "File Name"); // Create a keyboard and apply the styles - lv_obj_t * save_as_kb = lv_keyboard_create(lv_scr_act(), NULL); + save_as_kb = lv_keyboard_create(lv_scr_act(), NULL); lv_obj_set_size(save_as_kb, LV_HOR_RES, LV_VER_RES / 2); lv_obj_set_event_cb(save_as_kb, save_as_keyboard_event_cb); diff --git a/esp32_marauder/MenuFunctions.h b/esp32_marauder/MenuFunctions.h index 6f3adffca..ce8bddb97 100644 --- a/esp32_marauder/MenuFunctions.h +++ b/esp32_marauder/MenuFunctions.h @@ -94,6 +94,7 @@ PROGMEM static void save_as_keyboard_event_cb(lv_obj_t * keyboard, lv_event_t ev // lvgl stuff PROGMEM static lv_obj_t *kb; +PROGMEM static lv_obj_t * save_as_kb; struct Menu;