[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>
This commit is contained in:
gornekich
2021-07-25 14:34:54 +03:00
committed by GitHub
parent 0c7a8edf51
commit ebd158a823
39 changed files with 142 additions and 132 deletions

View File

@@ -1,5 +1,5 @@
#include "file-worker-cpp.h"
#include <hex.h>
#include <lib/toolbox/hex.h>
FileWorkerCpp::FileWorkerCpp(bool _silent) {
file_worker = file_worker_alloc(_silent);

View File

@@ -1,6 +1,6 @@
#include "file-worker.h"
#include "m-string.h"
#include <hex.h>
#include <lib/toolbox/hex.h>
#include <dialogs/dialogs.h>
#include <furi.h>

View File

@@ -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) {

View File

@@ -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

View File

@@ -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)

43
lib/toolbox/random_name.c Normal file
View File

@@ -0,0 +1,43 @@
#include "random_name.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <furi.h>
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;
}

17
lib/toolbox/random_name.h Normal file
View File

@@ -0,0 +1,17 @@
#pragma once
#include <stdint.h>
#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