Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/flipperzero-firmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgornekich <n.gorbadey@gmail.com>2021-07-25 14:34:54 +0300
committerGitHub <noreply@github.com>2021-07-25 14:34:54 +0300
commitebd158a823c68d4e908b190f8a55d1be7e9be87e (patch)
treef2a85b774350d9284a5f1d4bc3233bbc2cf7e9a0 /applications/ibutton
parent0c7a8edf518c77788ada147134c64513fbcde873 (diff)
[FL-1542], [FL-1603] Generate random name (#602)
* Lib: add random name library * Text_input: add default text clearing * All: rework all applications with new text_input API * Nfc: fix removing dev file on save_name scene enter * Lib: move all free radicals to toolbox and update API usage. Co-authored-by: あく <alleteam@gmail.com>
Diffstat (limited to 'applications/ibutton')
-rw-r--r--applications/ibutton/ibutton-app.cpp37
-rw-r--r--applications/ibutton/ibutton-app.h2
-rw-r--r--applications/ibutton/ibutton-cli.cpp2
-rw-r--r--applications/ibutton/scene/ibutton-scene-save-name.cpp10
4 files changed, 8 insertions, 43 deletions
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 <callback-connector.h>
#include <m-string.h>
#include <file-worker-cpp.h>
-#include <path.h>
+#include <lib/toolbox/path.h>
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 <api-hal.h>
#include <stdarg.h>
#include <cli/cli.h>
-#include <args.h>
+#include <lib/toolbox/args.h>
#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 <callback-connector.h>
+#include <lib/toolbox/random_name.h>
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) {