diff --git a/applications/archive/archive.c b/applications/archive/archive.c index 9ed91e76..f6c0dc1f 100644 --- a/applications/archive/archive.c +++ b/applications/archive/archive.c @@ -297,7 +297,8 @@ static void archive_enter_text_input(ArchiveApp* archive) { archive_text_input_callback, archive, archive->browser.text_input_buffer, - MAX_NAME_LEN); + MAX_NAME_LEN, + false); view_dispatcher_switch_to_view(archive->view_dispatcher, ArchiveViewTextInput); } diff --git a/applications/cli/cli.c b/applications/cli/cli.c index 97b35d39..213bef90 100644 --- a/applications/cli/cli.c +++ b/applications/cli/cli.c @@ -1,7 +1,6 @@ #include "cli_i.h" #include "cli_commands.h" -#include #include #include diff --git a/applications/dolphin/dolphin_views.c b/applications/dolphin/dolphin_views.c index 387a9f8e..ff468ef8 100644 --- a/applications/dolphin/dolphin_views.c +++ b/applications/dolphin/dolphin_views.c @@ -3,7 +3,6 @@ #include #include #include -#include #include static char* Lockmenu_Items[3] = {"Lock", "Set PIN", "DUMB mode"}; diff --git a/applications/gui-test/gui-test.c b/applications/gui-test/gui-test.c index 0ff42d85..19addf2f 100644 --- a/applications/gui-test/gui-test.c +++ b/applications/gui-test/gui-test.c @@ -192,7 +192,8 @@ int32_t gui_test(void* param) { text_input_callback, gui_tester, text_input_text, - text_input_text_len); + text_input_text_len, + false); text_input_set_header_text(gui_tester->text_input, "Name the key"); const uint8_t byte_input_bytes_len = 16; diff --git a/applications/gui/modules/text_input.c b/applications/gui/modules/text_input.c old mode 100644 new mode 100755 index 7c9f6bad..965f95ec --- a/applications/gui/modules/text_input.c +++ b/applications/gui/modules/text_input.c @@ -16,6 +16,7 @@ typedef struct { const char* header; char* text_buffer; size_t text_buffer_size; + bool clear_default_text; TextInputCallback callback; void* callback_context; @@ -128,7 +129,7 @@ static const char char_to_uppercase(const char letter) { } static void text_input_backspace_cb(TextInputModel* model) { - uint8_t text_length = strlen(model->text_buffer); + uint8_t text_length = model->clear_default_text ? 1 : strlen(model->text_buffer); if(text_length > 0) { model->text_buffer[text_length - 1] = 0; } @@ -158,11 +159,16 @@ static void text_input_view_draw_callback(Canvas* canvas, void* _model) { text++; } + if(model->clear_default_text) { + elements_slightly_rounded_box( + canvas, start_pos - 1, 14, canvas_string_width(canvas, text) + 2, 10); + canvas_set_color(canvas, ColorWhite); + } else { + canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 1, 22, "|"); + canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 2, 22, "|"); + } canvas_draw_str(canvas, start_pos, 22, text); - canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 1, 22, "|"); - canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 2, 22, "|"); - canvas_set_font(canvas, FontKeyboard); for(uint8_t row = 0; row <= keyboard_row_count; row++) { @@ -295,12 +301,16 @@ static void text_input_handle_ok(TextInput* text_input) { } else if(selected == BACKSPACE_KEY) { text_input_backspace_cb(model); } else if(text_length < (model->text_buffer_size - 1)) { + if(model->clear_default_text) { + text_length = 0; + } if(text_length == 0 && char_is_lowercase(selected)) { selected = char_to_uppercase(selected); } model->text_buffer[text_length] = selected; model->text_buffer[text_length + 1] = 0; } + model->clear_default_text = false; return true; }); } @@ -365,6 +375,7 @@ TextInput* text_input_alloc() { model->header = ""; model->selected_row = 0; model->selected_column = 0; + model->clear_default_text = false; return true; }); @@ -387,13 +398,15 @@ void text_input_set_result_callback( TextInputCallback callback, void* callback_context, char* text_buffer, - size_t text_buffer_size) { + size_t text_buffer_size, + bool clear_default_text) { with_view_model( text_input->view, (TextInputModel * model) { model->callback = callback; model->callback_context = callback_context; model->text_buffer = text_buffer; model->text_buffer_size = text_buffer_size; + model->clear_default_text = clear_default_text; return true; }); } diff --git a/applications/gui/modules/text_input.h b/applications/gui/modules/text_input.h index 51f5e3e2..d8e341cb 100644 --- a/applications/gui/modules/text_input.h +++ b/applications/gui/modules/text_input.h @@ -39,13 +39,15 @@ View* text_input_get_view(TextInput* text_input); * @param callback_context - callback context * @param text_buffer - pointer to YOUR text buffer, that we going to modify * @param text_buffer_size - YOUR text buffer size in bytes. Max string length will be text_buffer_size - 1. + * @param clear_default_text - clear text from text_buffer on first OK event */ void text_input_set_result_callback( TextInput* text_input, TextInputCallback callback, void* callback_context, char* text_buffer, - size_t text_buffer_size); + size_t text_buffer_size, + bool clear_default_text); /** * @brief Set text input header text diff --git a/applications/ibutton/ibutton-app.cpp b/applications/ibutton/ibutton-app.cpp index 46b0516b..082c2673 100644 --- a/applications/ibutton/ibutton-app.cpp +++ b/applications/ibutton/ibutton-app.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include const char* iButtonApp::app_folder = "/any/ibutton"; const char* iButtonApp::app_extension = ".ibtn"; @@ -40,9 +40,6 @@ iButtonApp::iButtonApp() : notification{"notification"} { api_hal_power_insomnia_enter(); key_worker = new KeyWorker(&ibutton_gpio); - - // we need random - srand(DWT->CYCCNT); } iButtonApp::~iButtonApp() { @@ -186,38 +183,6 @@ uint8_t iButtonApp::get_text_store_size() { return text_store_size; } -void iButtonApp::generate_random_name(char* name, uint8_t max_name_size) { - const uint8_t prefix_size = 9; - const char* prefix[prefix_size] = { - "ancient", - "hollow", - "strange", - "disappeared", - "unknown", - "unthinkable", - "unnamable", - "nameless", - "my", - }; - - const uint8_t suffix_size = 8; - const char* suffix[suffix_size] = { - "door", - "entrance", - "doorway", - "entry", - "portal", - "entree", - "opening", - "crack", - }; - - sniprintf( - name, max_name_size, "%s_%s", prefix[rand() % prefix_size], suffix[rand() % suffix_size]); - // to upper - name[0] = name[0] - 0x20; -} - // file managment bool iButtonApp::save_key(const char* key_name) { // Create ibutton directory if necessary diff --git a/applications/ibutton/ibutton-app.h b/applications/ibutton/ibutton-app.h index 27ed3a68..7e6017d5 100644 --- a/applications/ibutton/ibutton-app.h +++ b/applications/ibutton/ibutton-app.h @@ -90,8 +90,6 @@ public: char* get_file_name(); uint8_t get_file_name_size(); - void generate_random_name(char* name, uint8_t max_name_size); - bool save_key(const char* key_name); bool load_key(); bool load_key(const char* key_name); diff --git a/applications/ibutton/ibutton-cli.cpp b/applications/ibutton/ibutton-cli.cpp index b28e263d..7602d46d 100644 --- a/applications/ibutton/ibutton-cli.cpp +++ b/applications/ibutton/ibutton-cli.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include "helpers/key-info.h" #include "helpers/key-worker.h" diff --git a/applications/ibutton/scene/ibutton-scene-save-name.cpp b/applications/ibutton/scene/ibutton-scene-save-name.cpp index 2d41cc41..2fcd0804 100644 --- a/applications/ibutton/scene/ibutton-scene-save-name.cpp +++ b/applications/ibutton/scene/ibutton-scene-save-name.cpp @@ -4,6 +4,7 @@ #include "../ibutton-event.h" #include "../ibutton-key.h" #include +#include void iButtonSceneSaveName::on_enter(iButtonApp* app) { iButtonAppViewManager* view_manager = app->get_view_manager(); @@ -12,16 +13,17 @@ void iButtonSceneSaveName::on_enter(iButtonApp* app) { iButtonKey* key = app->get_key(); const char* key_name = key->get_name(); + bool key_name_empty = !strcmp(key_name, ""); - if(strcmp(key_name, "") == 0) { - app->generate_random_name(app->get_text_store(), app->get_text_store_size()); + if(key_name_empty) { + set_random_name(app->get_text_store(), app->get_text_store_size()); } else { app->set_text_store("%s", key_name); } text_input_set_header_text(text_input, "Name the key"); text_input_set_result_callback( - text_input, callback, app, app->get_text_store(), IBUTTON_KEY_NAME_SIZE); + text_input, callback, app, app->get_text_store(), IBUTTON_KEY_NAME_SIZE, key_name_empty); view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewTextInput); } @@ -47,7 +49,7 @@ bool iButtonSceneSaveName::on_event(iButtonApp* app, iButtonEvent* event) { void iButtonSceneSaveName::on_exit(iButtonApp* app) { TextInput* text_input = app->get_view_manager()->get_text_input(); text_input_set_header_text(text_input, ""); - text_input_set_result_callback(text_input, NULL, NULL, NULL, 0); + text_input_set_result_callback(text_input, NULL, NULL, NULL, 0, false); } void iButtonSceneSaveName::text_input_callback(void* context) { diff --git a/applications/irda/scene/irda-app-scene-edit-rename.cpp b/applications/irda/scene/irda-app-scene-edit-rename.cpp index 998e4c3e..24b4d0f9 100644 --- a/applications/irda/scene/irda-app-scene-edit-rename.cpp +++ b/applications/irda/scene/irda-app-scene-edit-rename.cpp @@ -20,7 +20,8 @@ void IrdaAppSceneEditRename::on_enter(IrdaApp* app) { IrdaApp::text_input_callback, app, app->get_text_store(0), - app->get_text_store_size()); + app->get_text_store_size(), + false); view_manager->switch_to(IrdaAppViewManager::ViewType::TextInput); } diff --git a/applications/irda/scene/irda-app-scene-learn-enter-name.cpp b/applications/irda/scene/irda-app-scene-learn-enter-name.cpp index be0b8d63..a3b403e0 100644 --- a/applications/irda/scene/irda-app-scene-learn-enter-name.cpp +++ b/applications/irda/scene/irda-app-scene-learn-enter-name.cpp @@ -26,7 +26,8 @@ void IrdaAppSceneLearnEnterName::on_enter(IrdaApp* app) { IrdaApp::text_input_callback, app, app->get_text_store(0), - app->get_text_store_size()); + app->get_text_store_size(), + false); view_manager->switch_to(IrdaAppViewManager::ViewType::TextInput); } diff --git a/applications/lfrfid/helpers/rfid-name-generator.cpp b/applications/lfrfid/helpers/rfid-name-generator.cpp deleted file mode 100644 index 5d324e6f..00000000 --- a/applications/lfrfid/helpers/rfid-name-generator.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "rfid-name-generator.h" -#include -#include - -void rfid_generate_random_name(char* name, uint8_t max_name_size) { - const uint8_t prefix_size = 9; - const char* prefix[prefix_size] = { - "good", - "nice", - "best", - "some", - "strange", - "working", - "that", - "forgettable", - "easy", - }; - - const uint8_t suffix_size = 7; - const char* suffix[suffix_size] = { - "pass", - "card", - "key", - "fob", - "permit", - "pass", - "one", - }; - - sniprintf( - name, max_name_size, "%s_%s", prefix[rand() % prefix_size], suffix[rand() % suffix_size]); - - // to upper - name[0] = name[0] - ('a' - 'A'); -} diff --git a/applications/lfrfid/helpers/rfid-name-generator.h b/applications/lfrfid/helpers/rfid-name-generator.h deleted file mode 100644 index 3f97172d..00000000 --- a/applications/lfrfid/helpers/rfid-name-generator.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once -#include "stdint.h" - -void rfid_generate_random_name(char* name, uint8_t max_name_size); \ No newline at end of file diff --git a/applications/lfrfid/lfrfid-app.cpp b/applications/lfrfid/lfrfid-app.cpp index 351aec49..1cd59b61 100644 --- a/applications/lfrfid/lfrfid-app.cpp +++ b/applications/lfrfid/lfrfid-app.cpp @@ -17,7 +17,7 @@ #include "scene/lfrfid-app-scene-delete-success.h" #include -#include +#include const char* LfRfidApp::app_folder = "/any/lfrfid"; const char* LfRfidApp::app_extension = ".rfid"; @@ -27,9 +27,6 @@ LfRfidApp::LfRfidApp() , notification{"notification"} , text_store(40) { api_hal_power_insomnia_enter(); - - // we need random - srand(DWT->CYCCNT); } LfRfidApp::~LfRfidApp() { diff --git a/applications/lfrfid/lfrfid-cli.cpp b/applications/lfrfid/lfrfid-cli.cpp index 2e7e2f99..1a047fcb 100644 --- a/applications/lfrfid/lfrfid-cli.cpp +++ b/applications/lfrfid/lfrfid-cli.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include "helpers/rfid-reader.h" #include "helpers/rfid-timer-emulator.h" diff --git a/applications/lfrfid/scene/lfrfid-app-scene-save-name.cpp b/applications/lfrfid/scene/lfrfid-app-scene-save-name.cpp old mode 100644 new mode 100755 index f751f061..fba15817 --- a/applications/lfrfid/scene/lfrfid-app-scene-save-name.cpp +++ b/applications/lfrfid/scene/lfrfid-app-scene-save-name.cpp @@ -1,11 +1,12 @@ #include "lfrfid-app-scene-save-name.h" -#include "../helpers/rfid-name-generator.h" +#include void LfRfidAppSceneSaveName::on_enter(LfRfidApp* app, bool need_restore) { const char* key_name = app->worker.key.get_name(); - if(strcmp(key_name, "") == 0) { - rfid_generate_random_name(app->text_store.text, app->text_store.text_size); + bool key_name_empty = !strcmp(key_name, ""); + if(key_name_empty) { + set_random_name(app->text_store.text, app->text_store.text_size); } else { app->text_store.set("%s", key_name); } @@ -14,7 +15,11 @@ void LfRfidAppSceneSaveName::on_enter(LfRfidApp* app, bool need_restore) { text_input->set_header_text("Name the card"); text_input->set_result_callback( - save_callback, app, app->text_store.text, app->worker.key.get_name_length()); + save_callback, + app, + app->text_store.text, + app->worker.key.get_name_length(), + key_name_empty); app->view_controller.switch_to(); } diff --git a/applications/nfc/nfc_device.c b/applications/nfc/nfc_device.c index d22e63e7..d0575e1b 100755 --- a/applications/nfc/nfc_device.c +++ b/applications/nfc/nfc_device.c @@ -1,8 +1,8 @@ #include "nfc_device_i.h" #include -#include -#include +#include +#include #define NFC_DEVICE_MAX_DATA_LEN 14 diff --git a/applications/nfc/scenes/nfc_scene_save_name.c b/applications/nfc/scenes/nfc_scene_save_name.c index af448ef1..9de2ac47 100755 --- a/applications/nfc/scenes/nfc_scene_save_name.c +++ b/applications/nfc/scenes/nfc_scene_save_name.c @@ -1,4 +1,5 @@ #include "../nfc_i.h" +#include #define SCENE_SAVE_NAME_CUSTOM_EVENT (0UL) @@ -13,17 +14,21 @@ const void nfc_scene_save_name_on_enter(void* context) { // Setup view TextInput* text_input = nfc->text_input; - if(nfc->dev.dev_name) { - nfc_device_delete(&nfc->dev); + bool dev_name_empty = false; + if(!strcmp(nfc->dev.dev_name, "")) { + set_random_name(nfc->text_store, sizeof(nfc->text_store)); + dev_name_empty = true; + } else { + nfc_text_store_set(nfc, nfc->dev.dev_name); } - nfc_text_store_set(nfc, nfc->dev.dev_name); text_input_set_header_text(text_input, "Name the card"); text_input_set_result_callback( text_input, nfc_scene_save_name_text_input_callback, nfc, nfc->text_store, - sizeof(nfc->text_store)); + NFC_DEV_NAME_MAX_LEN, + dev_name_empty); view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewTextInput); } @@ -32,6 +37,9 @@ const bool nfc_scene_save_name_on_event(void* context, SceneManagerEvent event) if(event.type == SceneManagerEventTypeCustom) { if(event.event == SCENE_SAVE_NAME_CUSTOM_EVENT) { + if(nfc->dev.dev_name) { + nfc_device_delete(&nfc->dev); + } memcpy(&nfc->dev.dev_name, nfc->text_store, strlen(nfc->text_store)); if(nfc_device_save(&nfc->dev, nfc->text_store)) { scene_manager_next_scene(nfc->scene_manager, NfcSceneSaveSuccess); @@ -49,4 +57,5 @@ const void nfc_scene_save_name_on_exit(void* context) { // Clear view text_input_set_header_text(nfc->text_input, NULL); + text_input_set_result_callback(nfc->text_input, NULL, NULL, NULL, 0, false); } diff --git a/applications/storage/storage-cli.c b/applications/storage/storage-cli.c index bf49faa2..203daa8a 100644 --- a/applications/storage/storage-cli.c +++ b/applications/storage/storage-cli.c @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include #include diff --git a/bootloader/targets/f6/target.c b/bootloader/targets/f6/target.c index edf3cbde..6d061337 100644 --- a/bootloader/targets/f6/target.c +++ b/bootloader/targets/f6/target.c @@ -9,7 +9,7 @@ #include #include -#include +#include #include // Boot request enum diff --git a/bootloader/targets/f6/target.mk b/bootloader/targets/f6/target.mk index 13170b8e..ab0c24b4 100644 --- a/bootloader/targets/f6/target.mk +++ b/bootloader/targets/f6/target.mk @@ -12,7 +12,7 @@ MCU_FLAGS = -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard CFLAGS += $(MCU_FLAGS) $(BOOT_CFLAGS) -DSTM32WB55xx -Wall -fdata-sections -ffunction-sections LDFLAGS += $(MCU_FLAGS) -specs=nosys.specs -specs=nano.specs -CUBE_DIR = ../lib/STM32CubeWB +CUBE_DIR = $(PROJECT_ROOT)/lib/STM32CubeWB # ST HAL CFLAGS += -DUSE_FULL_LL_DRIVER @@ -29,7 +29,7 @@ CFLAGS += -I$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Inc LDFLAGS += -T$(TARGET_DIR)/stm32wb55xx_flash_cm4.ld # Drivers -DRIVERS_DIR = ../lib/drivers +DRIVERS_DIR = $(PROJECT_ROOT)//lib/drivers CFLAGS += -I$(DRIVERS_DIR) C_SOURCES += $(DRIVERS_DIR)/lp5562.c @@ -38,11 +38,10 @@ CFLAGS += -I$(TARGET_DIR)/api-hal C_SOURCES += $(wildcard $(TARGET_DIR)/api-hal/*.c) # Version generation -CFLAGS += -I../lib/version -C_SOURCES += ../lib/version/version.c +C_SOURCES += $(PROJECT_ROOT)/lib/toolbox/version.c ASM_SOURCES += $(wildcard $(TARGET_DIR)/*.s) C_SOURCES += $(wildcard $(TARGET_DIR)/*.c) CPP_SOURCES += $(wildcard $(TARGET_DIR)/*.cpp) -SVD_FILE = ../debug/STM32WB55_CM4.svd +SVD_FILE = $(PROJECT_ROOT)/debug/STM32WB55_CM4.svd diff --git a/core/flipper.c b/core/flipper.c index faef2bb7..ffd44742 100755 --- a/core/flipper.c +++ b/core/flipper.c @@ -1,7 +1,6 @@ #include "flipper.h" #include #include -#include #include static void flipper_print_version(const char* target, const Version* version) { diff --git a/firmware/targets/api-hal-include/api-hal-version.h b/firmware/targets/api-hal-include/api-hal-version.h index 037b1af7..edf4d9f0 100644 --- a/firmware/targets/api-hal-include/api-hal-version.h +++ b/firmware/targets/api-hal-include/api-hal-version.h @@ -3,7 +3,7 @@ #include #include #include -#include +#include #ifdef __cplusplus extern "C" { diff --git a/lib/app-scened-template/file-worker-cpp.cpp b/lib/app-scened-template/file-worker-cpp.cpp index 616cb30c..7f7c5d6a 100644 --- a/lib/app-scened-template/file-worker-cpp.cpp +++ b/lib/app-scened-template/file-worker-cpp.cpp @@ -1,5 +1,5 @@ #include "file-worker-cpp.h" -#include +#include FileWorkerCpp::FileWorkerCpp(bool _silent) { file_worker = file_worker_alloc(_silent); diff --git a/lib/app-scened-template/file-worker.c b/lib/app-scened-template/file-worker.c index cc02d994..3f1bb175 100644 --- a/lib/app-scened-template/file-worker.c +++ b/lib/app-scened-template/file-worker.c @@ -1,6 +1,6 @@ #include "file-worker.h" #include "m-string.h" -#include +#include #include #include diff --git a/lib/app-scened-template/view-modules/text-input-vm.cpp b/lib/app-scened-template/view-modules/text-input-vm.cpp index 027b510b..7a6f7d39 100644 --- a/lib/app-scened-template/view-modules/text-input-vm.cpp +++ b/lib/app-scened-template/view-modules/text-input-vm.cpp @@ -13,7 +13,7 @@ View* TextInputVM::get_view() { } void TextInputVM::clean() { - set_result_callback(NULL, NULL, NULL, 0); + set_result_callback(NULL, NULL, NULL, 0, false); set_header_text(""); } @@ -21,8 +21,9 @@ void TextInputVM::set_result_callback( TextInputCallback callback, void* callback_context, char* text, - uint8_t max_text_length) { - text_input_set_result_callback(text_input, callback, callback_context, text, max_text_length); + uint8_t max_text_length, + bool clear_default_text) { + text_input_set_result_callback(text_input, callback, callback_context, text, max_text_length, clear_default_text); } void TextInputVM::set_header_text(const char* text) { diff --git a/lib/app-scened-template/view-modules/text-input-vm.h b/lib/app-scened-template/view-modules/text-input-vm.h index cf256747..7baa207f 100644 --- a/lib/app-scened-template/view-modules/text-input-vm.h +++ b/lib/app-scened-template/view-modules/text-input-vm.h @@ -16,12 +16,14 @@ public: * @param callback_context - callback context * @param text - text buffer to use * @param max_text_length - text buffer length + * @param clear_default_text - clears given buffer on OK event */ void set_result_callback( TextInputCallback callback, void* callback_context, char* text, - uint8_t max_text_length); + uint8_t max_text_length, + bool clear_default_text); /** * @brief Set text input header text diff --git a/lib/lib.mk b/lib/lib.mk index 5ee3f965..52061e42 100644 --- a/lib/lib.mk +++ b/lib/lib.mk @@ -85,10 +85,6 @@ CFLAGS += -I$(LIB_DIR)/common-api CFLAGS += -I$(LIB_DIR)/drivers C_SOURCES += $(wildcard $(LIB_DIR)/drivers/*.c) -#version -CFLAGS += -I$(LIB_DIR)/version -C_SOURCES += $(LIB_DIR)/version/version.c - #file reader CFLAGS += -I$(LIB_DIR)/file_reader CPP_SOURCES += $(wildcard $(LIB_DIR)/file_reader/*.cpp) @@ -100,10 +96,6 @@ C_SOURCES += $(wildcard $(LIB_DIR)/irda/encoder_decoder/*.c) C_SOURCES += $(wildcard $(LIB_DIR)/irda/encoder_decoder/*/*.c) C_SOURCES += $(wildcard $(LIB_DIR)/irda/worker/*.c) -#args lib -CFLAGS += -I$(LIB_DIR)/args -C_SOURCES += $(wildcard $(LIB_DIR)/args/*.c) - # SubGhz C_SOURCES += $(wildcard $(LIB_DIR)/subghz/*.c) C_SOURCES += $(wildcard $(LIB_DIR)/subghz/*/*.c) @@ -113,3 +105,6 @@ CFLAGS += -I$(LIB_DIR)/app-scened-template C_SOURCES += $(wildcard $(LIB_DIR)/app-scened-template/*.c) CPP_SOURCES += $(wildcard $(LIB_DIR)/app-scened-template/*.cpp) CPP_SOURCES += $(wildcard $(LIB_DIR)/app-scened-template/*/*.cpp) + +# Toolbox +C_SOURCES += $(wildcard $(LIB_DIR)/toolbox/*.c) diff --git a/lib/args/args.c b/lib/toolbox/args.c similarity index 100% rename from lib/args/args.c rename to lib/toolbox/args.c diff --git a/lib/args/args.h b/lib/toolbox/args.h similarity index 100% rename from lib/args/args.h rename to lib/toolbox/args.h diff --git a/lib/args/hex.c b/lib/toolbox/hex.c similarity index 100% rename from lib/args/hex.c rename to lib/toolbox/hex.c diff --git a/lib/args/hex.h b/lib/toolbox/hex.h similarity index 100% rename from lib/args/hex.h rename to lib/toolbox/hex.h diff --git a/lib/args/path.c b/lib/toolbox/path.c similarity index 100% rename from lib/args/path.c rename to lib/toolbox/path.c diff --git a/lib/args/path.h b/lib/toolbox/path.h similarity index 100% rename from lib/args/path.h rename to lib/toolbox/path.h diff --git a/lib/toolbox/random_name.c b/lib/toolbox/random_name.c new file mode 100644 index 00000000..ac7af0ae --- /dev/null +++ b/lib/toolbox/random_name.c @@ -0,0 +1,43 @@ +#include "random_name.h" +#include +#include +#include +#include + +void set_random_name(char* name, uint8_t max_name_size) { + static bool rand_generator_inited = false; + + if(!rand_generator_inited) { + srand(DWT->CYCCNT); + rand_generator_inited = true; + } + const char* prefix[] = { + "ancient", + "hollow", + "strange", + "disappeared", + "unknown", + "unthinkable", + "unnamable", + "nameless", + "my", + }; + + const char* suffix[] = { + "door", + "entrance", + "doorway", + "entry", + "portal", + "entree", + "opening", + "crack", + }; + uint8_t prefix_i = rand() % SIZEOF_ARRAY(prefix); + uint8_t suffix_i = rand() % SIZEOF_ARRAY(suffix); + + sniprintf( + name, max_name_size, "%s_%s", prefix[prefix_i], suffix[suffix_i]); + // Set first symbol to upper case + name[0] = name[0] - 0x20; +} diff --git a/lib/toolbox/random_name.h b/lib/toolbox/random_name.h new file mode 100644 index 00000000..358ea685 --- /dev/null +++ b/lib/toolbox/random_name.h @@ -0,0 +1,17 @@ +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** Generates random name + * @param name buffer to write random name + * @param max_name_size length of given buffer + */ +void set_random_name(char* name, uint8_t max_name_size); + +#ifdef __cplusplus +} +#endif diff --git a/lib/version/version.c b/lib/toolbox/version.c similarity index 100% rename from lib/version/version.c rename to lib/toolbox/version.c diff --git a/lib/version/version.h b/lib/toolbox/version.h similarity index 100% rename from lib/version/version.h rename to lib/toolbox/version.h