[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,35 +0,0 @@
#include "rfid-name-generator.h"
#include <stdio.h>
#include <stdlib.h>
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');
}

View File

@@ -1,4 +0,0 @@
#pragma once
#include "stdint.h"
void rfid_generate_random_name(char* name, uint8_t max_name_size);

View File

@@ -17,7 +17,7 @@
#include "scene/lfrfid-app-scene-delete-success.h"
#include <file-worker-cpp.h>
#include <path.h>
#include <lib/toolbox/path.h>
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() {

View File

@@ -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/rfid-reader.h"
#include "helpers/rfid-timer-emulator.h"

View File

@@ -1,11 +1,12 @@
#include "lfrfid-app-scene-save-name.h"
#include "../helpers/rfid-name-generator.h"
#include <lib/toolbox/random_name.h>
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<TextInputVM>();
}