[FL-2297, FL-2289] Power info command, Validator fixes (#1097)
* Power info command, validator fixes * strdup in validator, fix memory leak * furi_hal_crypto fixed again * FuriHal: limit ARR and CC in speaker hal * FuriHal: LL_TIM_DisableAllOutputs in speaker stop * Rpc: fix memory leak in screen streaming * Get rid of crypto_enable/crypto_disable Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -31,8 +31,8 @@ void archive_scene_rename_on_enter(void* context) {
|
||||
MAX_TEXT_INPUT_LEN,
|
||||
false);
|
||||
|
||||
ValidatorIsFile* validator_is_file =
|
||||
validator_is_file_alloc_init(archive_get_path(archive->browser), archive->file_extension);
|
||||
ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
|
||||
archive_get_path(archive->browser), archive->file_extension, NULL);
|
||||
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
|
||||
|
||||
view_dispatcher_switch_to_view(archive->view_dispatcher, ArchiveViewTextInput);
|
||||
|
@@ -5,11 +5,19 @@
|
||||
struct ValidatorIsFile {
|
||||
const char* app_path_folder;
|
||||
const char* app_extension;
|
||||
char* current_name;
|
||||
};
|
||||
|
||||
bool validator_is_file_callback(const char* text, string_t error, void* context) {
|
||||
furi_assert(context);
|
||||
ValidatorIsFile* instance = context;
|
||||
|
||||
if(instance->current_name != NULL) {
|
||||
if(strcmp(instance->current_name, text) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool ret = true;
|
||||
string_t path;
|
||||
string_init_printf(path, "%s/%s%s", instance->app_path_folder, text, instance->app_extension);
|
||||
@@ -26,17 +34,21 @@ bool validator_is_file_callback(const char* text, string_t error, void* context)
|
||||
return ret;
|
||||
}
|
||||
|
||||
ValidatorIsFile*
|
||||
validator_is_file_alloc_init(const char* app_path_folder, const char* app_extension) {
|
||||
ValidatorIsFile* validator_is_file_alloc_init(
|
||||
const char* app_path_folder,
|
||||
const char* app_extension,
|
||||
const char* current_name) {
|
||||
ValidatorIsFile* instance = malloc(sizeof(ValidatorIsFile));
|
||||
|
||||
instance->app_path_folder = app_path_folder;
|
||||
instance->app_extension = app_extension;
|
||||
instance->current_name = strdup(current_name);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void validator_is_file_free(ValidatorIsFile* instance) {
|
||||
furi_assert(instance);
|
||||
free(instance->current_name);
|
||||
free(instance);
|
||||
}
|
||||
|
@@ -8,8 +8,10 @@ extern "C" {
|
||||
#endif
|
||||
typedef struct ValidatorIsFile ValidatorIsFile;
|
||||
|
||||
ValidatorIsFile*
|
||||
validator_is_file_alloc_init(const char* app_path_folder, const char* app_extension);
|
||||
ValidatorIsFile* validator_is_file_alloc_init(
|
||||
const char* app_path_folder,
|
||||
const char* app_extension,
|
||||
const char* current_name);
|
||||
|
||||
void validator_is_file_free(ValidatorIsFile* instance);
|
||||
|
||||
|
@@ -35,7 +35,7 @@ void iButtonSceneSaveName::on_enter(iButtonApp* app) {
|
||||
key_name_empty);
|
||||
|
||||
ValidatorIsFile* validator_is_file =
|
||||
validator_is_file_alloc_init(app->app_folder, app->app_extension);
|
||||
validator_is_file_alloc_init(app->app_folder, app->app_extension, key_name);
|
||||
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewTextInput);
|
||||
|
@@ -21,8 +21,8 @@ void InfraredAppSceneEditRename::on_enter(InfraredApp* app) {
|
||||
enter_name_length = InfraredAppRemoteManager::max_remote_name_length;
|
||||
text_input_set_header_text(text_input, "Name the remote");
|
||||
|
||||
ValidatorIsFile* validator_is_file =
|
||||
validator_is_file_alloc_init(app->infrared_directory, app->infrared_extension);
|
||||
ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
|
||||
app->infrared_directory, app->infrared_extension, remote_name.c_str());
|
||||
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,7 @@ void LfRfidAppSceneSaveName::on_enter(LfRfidApp* app, bool need_restore) {
|
||||
key_name_empty);
|
||||
|
||||
ValidatorIsFile* validator_is_file =
|
||||
validator_is_file_alloc_init(app->app_folder, app->app_extension);
|
||||
validator_is_file_alloc_init(app->app_folder, app->app_extension, key_name);
|
||||
text_input->set_validator(validator_is_file_callback, validator_is_file);
|
||||
|
||||
app->view_controller.switch_to<TextInputVM>();
|
||||
|
@@ -30,7 +30,7 @@ void nfc_scene_save_name_on_enter(void* context) {
|
||||
dev_name_empty);
|
||||
|
||||
ValidatorIsFile* validator_is_file =
|
||||
validator_is_file_alloc_init(NFC_APP_FOLDER, NFC_APP_EXTENSION);
|
||||
validator_is_file_alloc_init(NFC_APP_FOLDER, NFC_APP_EXTENSION, nfc->dev->dev_name);
|
||||
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewTextInput);
|
||||
|
@@ -20,6 +20,14 @@ void power_cli_reboot2dfu(Cli* cli, string_t args) {
|
||||
power_reboot(PowerBootModeDfu);
|
||||
}
|
||||
|
||||
static void power_cli_info_callback(const char* key, const char* value, bool last, void* context) {
|
||||
printf("%-24s: %s\r\n", key, value);
|
||||
}
|
||||
|
||||
void power_cli_info(Cli* cli, string_t args) {
|
||||
furi_hal_power_info_get(power_cli_info_callback, NULL);
|
||||
}
|
||||
|
||||
void power_cli_debug(Cli* cli, string_t args) {
|
||||
furi_hal_power_dump_state();
|
||||
}
|
||||
@@ -52,6 +60,7 @@ static void power_cli_command_print_usage() {
|
||||
printf("\toff\t - shutdown power\r\n");
|
||||
printf("\treboot\t - reboot\r\n");
|
||||
printf("\treboot2dfu\t - reboot to dfu bootloader\r\n");
|
||||
printf("\tinfo\t - show power info\r\n");
|
||||
printf("\tdebug\t - show debug information\r\n");
|
||||
printf("\t5v <0 or 1>\t - enable or disable 5v ext\r\n");
|
||||
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
||||
@@ -84,6 +93,11 @@ void power_cli(Cli* cli, string_t args, void* context) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "info") == 0) {
|
||||
power_cli_info(cli, args);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "debug") == 0) {
|
||||
power_cli_debug(cli, args);
|
||||
break;
|
||||
|
@@ -4,6 +4,8 @@
|
||||
#include <furi_hal.h>
|
||||
#include <semphr.h>
|
||||
|
||||
#define TAG "RpcCli"
|
||||
|
||||
typedef struct {
|
||||
Cli* cli;
|
||||
bool session_close_request;
|
||||
@@ -38,6 +40,9 @@ static void rpc_session_terminated_callback(void* context) {
|
||||
void rpc_cli_command_start_session(Cli* cli, string_t args, void* context) {
|
||||
Rpc* rpc = context;
|
||||
|
||||
uint32_t mem_before = memmgr_get_free_heap();
|
||||
FURI_LOG_D(TAG, "Free memory %d", mem_before);
|
||||
|
||||
furi_hal_usb_lock();
|
||||
RpcSession* rpc_session = rpc_session_open(rpc);
|
||||
if(rpc_session == NULL) {
|
||||
|
@@ -346,8 +346,19 @@ void rpc_system_gui_free(void* context) {
|
||||
}
|
||||
|
||||
if(rpc_gui->is_streaming) {
|
||||
rpc_gui->is_streaming = false;
|
||||
// Remove GUI framebuffer callback
|
||||
gui_remove_framebuffer_callback(
|
||||
rpc_gui->gui, rpc_system_gui_screen_stream_frame_callback, context);
|
||||
// Stop and release worker thread
|
||||
osThreadFlagsSet(
|
||||
furi_thread_get_thread_id(rpc_gui->transmit_thread), RpcGuiWorkerFlagExit);
|
||||
furi_thread_join(rpc_gui->transmit_thread);
|
||||
furi_thread_free(rpc_gui->transmit_thread);
|
||||
// Release frame
|
||||
pb_release(&PB_Main_msg, rpc_gui->transmit_frame);
|
||||
free(rpc_gui->transmit_frame);
|
||||
rpc_gui->transmit_frame = NULL;
|
||||
}
|
||||
furi_record_close("gui");
|
||||
free(rpc_gui);
|
||||
|
@@ -6,6 +6,11 @@
|
||||
|
||||
#include "rpc_i.h"
|
||||
|
||||
typedef struct {
|
||||
RpcSession* session;
|
||||
PB_Main* response;
|
||||
} RpcSystemContext;
|
||||
|
||||
static void rpc_system_system_ping_process(const PB_Main* request, void* context) {
|
||||
furi_assert(request);
|
||||
furi_assert(request->which_content == PB_Main_system_ping_request_tag);
|
||||
@@ -55,11 +60,6 @@ static void rpc_system_system_reboot_process(const PB_Main* request, void* conte
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
RpcSession* session;
|
||||
PB_Main* response;
|
||||
} RpcSystemSystemDeviceInfoContext;
|
||||
|
||||
static void rpc_system_system_device_info_callback(
|
||||
const char* key,
|
||||
const char* value,
|
||||
@@ -67,7 +67,7 @@ static void rpc_system_system_device_info_callback(
|
||||
void* context) {
|
||||
furi_assert(key);
|
||||
furi_assert(value);
|
||||
RpcSystemSystemDeviceInfoContext* ctx = context;
|
||||
RpcSystemContext* ctx = context;
|
||||
|
||||
char* str_key = strdup(key);
|
||||
char* str_value = strdup(value);
|
||||
@@ -91,7 +91,7 @@ static void rpc_system_system_device_info_process(const PB_Main* request, void*
|
||||
response->which_content = PB_Main_system_device_info_response_tag;
|
||||
response->command_status = PB_CommandStatus_OK;
|
||||
|
||||
RpcSystemSystemDeviceInfoContext device_info_context = {
|
||||
RpcSystemContext device_info_context = {
|
||||
.session = session,
|
||||
.response = response,
|
||||
};
|
||||
@@ -202,6 +202,46 @@ static void rpc_system_system_protobuf_version_process(const PB_Main* request, v
|
||||
free(response);
|
||||
}
|
||||
|
||||
static void rpc_system_system_power_info_callback(
|
||||
const char* key,
|
||||
const char* value,
|
||||
bool last,
|
||||
void* context) {
|
||||
furi_assert(key);
|
||||
furi_assert(value);
|
||||
RpcSystemContext* ctx = context;
|
||||
|
||||
char* str_key = strdup(key);
|
||||
char* str_value = strdup(value);
|
||||
|
||||
ctx->response->has_next = !last;
|
||||
ctx->response->content.system_device_info_response.key = str_key;
|
||||
ctx->response->content.system_device_info_response.value = str_value;
|
||||
|
||||
rpc_send_and_release(ctx->session, ctx->response);
|
||||
}
|
||||
|
||||
static void rpc_system_system_get_power_info_process(const PB_Main* request, void* context) {
|
||||
furi_assert(request);
|
||||
furi_assert(request->which_content == PB_Main_system_power_info_request_tag);
|
||||
|
||||
RpcSession* session = (RpcSession*)context;
|
||||
furi_assert(session);
|
||||
|
||||
PB_Main* response = malloc(sizeof(PB_Main));
|
||||
response->command_id = request->command_id;
|
||||
response->which_content = PB_Main_system_power_info_response_tag;
|
||||
response->command_status = PB_CommandStatus_OK;
|
||||
|
||||
RpcSystemContext power_info_context = {
|
||||
.session = session,
|
||||
.response = response,
|
||||
};
|
||||
furi_hal_power_info_get(rpc_system_system_power_info_callback, &power_info_context);
|
||||
|
||||
free(response);
|
||||
}
|
||||
|
||||
void* rpc_system_system_alloc(RpcSession* session) {
|
||||
RpcHandler rpc_handler = {
|
||||
.message_handler = NULL,
|
||||
@@ -233,5 +273,8 @@ void* rpc_system_system_alloc(RpcSession* session) {
|
||||
rpc_handler.message_handler = rpc_system_system_protobuf_version_process;
|
||||
rpc_add_handler(session, PB_Main_system_protobuf_version_request_tag, &rpc_handler);
|
||||
|
||||
rpc_handler.message_handler = rpc_system_system_get_power_info_process;
|
||||
rpc_add_handler(session, PB_Main_system_power_info_request_tag, &rpc_handler);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@@ -42,8 +42,10 @@ void subghz_scene_save_name_on_enter(void* context) {
|
||||
SUBGHZ_MAX_LEN_NAME + 1, // buffer size
|
||||
dev_name_empty);
|
||||
|
||||
ValidatorIsFile* validator_is_file =
|
||||
validator_is_file_alloc_init(SUBGHZ_APP_FOLDER, SUBGHZ_APP_EXTENSION);
|
||||
ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
|
||||
SUBGHZ_APP_FOLDER,
|
||||
SUBGHZ_APP_EXTENSION,
|
||||
(dev_name_empty) ? (NULL) : (subghz->file_name_tmp));
|
||||
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
|
||||
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdTextInput);
|
||||
|
@@ -400,12 +400,14 @@ bool subghz_rename_file(SubGhz* subghz) {
|
||||
string_init_printf(
|
||||
new_path, "%s/%s%s", SUBGHZ_APP_FOLDER, subghz->file_name, SUBGHZ_APP_EXTENSION);
|
||||
|
||||
FS_Error fs_result =
|
||||
storage_common_rename(storage, string_get_cstr(old_path), string_get_cstr(new_path));
|
||||
if(string_cmp(old_path, new_path) != 0) {
|
||||
FS_Error fs_result =
|
||||
storage_common_rename(storage, string_get_cstr(old_path), string_get_cstr(new_path));
|
||||
|
||||
if(fs_result != FSE_OK) {
|
||||
dialog_message_show_storage_error(subghz->dialogs, "Cannot rename\n file/directory");
|
||||
ret = false;
|
||||
if(fs_result != FSE_OK) {
|
||||
dialog_message_show_storage_error(subghz->dialogs, "Cannot rename\n file/directory");
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
|
||||
string_clear(old_path);
|
||||
|
Reference in New Issue
Block a user