Source code C\C++ formating

This commit is contained in:
Dmitry422
2025-02-02 15:13:55 +07:00
parent eef2441af9
commit a5c241139d
5 changed files with 67 additions and 58 deletions

View File

@@ -82,7 +82,6 @@ const char* input_get_type_name(InputType type) {
}
}
// static void input_storage_callback(const void* message, void* context) {
// furi_assert(context);
// InputSettings* settings = context;
@@ -116,28 +115,28 @@ const char* input_get_type_name(InputType type) {
// //furi_record_close(RECORD_STORAGE);
// return;
// }
// furi_hal_vibro_on(true);
// furi_delay_tick (100);
// furi_hal_vibro_on(false);
// furi_delay_tick (100);
// furi_hal_vibro_on(true);
// furi_delay_tick (100);
// furi_hal_vibro_on(false);
// furi_hal_vibro_on(true);
// furi_delay_tick (100);
// furi_hal_vibro_on(false);
// furi_delay_tick (100);
// furi_hal_vibro_on(true);
// furi_delay_tick (100);
// furi_hal_vibro_on(false);
// input_settings_load(settings);
// furi_record_close(RECORD_STORAGE);
// }
// allocate memory for input_settings structure
static InputSettings* input_settings_alloc (void) {
static InputSettings* input_settings_alloc(void) {
InputSettings* settings = malloc(sizeof(InputSettings));
return settings;
}
//free memory from input_settings structure
void input_settings_free (InputSettings* settings) {
free (settings);
void input_settings_free(InputSettings* settings) {
free(settings);
}
int32_t input_srv(void* p) {
@@ -145,9 +144,9 @@ int32_t input_srv(void* p) {
const FuriThreadId thread_id = furi_thread_get_current_id();
FuriPubSub* event_pubsub = furi_pubsub_alloc();
uint32_t counter = 1;
uint32_t counter = 1;
furi_record_create(RECORD_INPUT_EVENTS, event_pubsub);
//define object input_settings, take memory load (or init) settings and create record for access to settings structure outside
InputSettings* settings = input_settings_alloc();
furi_record_create(RECORD_INPUT_SETTINGS, settings);
@@ -216,9 +215,9 @@ int32_t input_srv(void* p) {
event.type = pin_states[i].state ? InputTypePress : InputTypeRelease;
furi_pubsub_publish(event_pubsub, &event);
// do vibro if user setup vibro touch level in Settings-Input.
if (settings->vibro_touch_level) {
if(settings->vibro_touch_level) {
furi_hal_vibro_on(true);
furi_delay_tick (settings->vibro_touch_level);
furi_delay_tick(settings->vibro_touch_level);
furi_hal_vibro_on(false);
};
}
@@ -237,6 +236,5 @@ int32_t input_srv(void* p) {
}
}
return 0;
}

View File

@@ -9,7 +9,6 @@
#include "input_settings.h"
#include <storage/storage.h>
#ifdef __cplusplus
extern "C" {
#endif

View File

@@ -26,16 +26,16 @@ void input_settings_load(InputSettings* settings) {
// take version from settings file metadata, if cant then break and fill settings with 0 and save to settings file;
uint8_t version;
if(!saved_struct_get_metadata(INPUT_SETTINGS_PATH, NULL, &version, NULL)) break;
// if config actual version - load it directly
if(version == INPUT_SETTINGS_VER) {
if(version == INPUT_SETTINGS_VER) {
success = saved_struct_load(
INPUT_SETTINGS_PATH,
settings,
sizeof(InputSettings),
INPUT_SETTINGS_MAGIC,
INPUT_SETTINGS_VER);
// if config previous version - load it and inicialize new settings
// if config previous version - load it and inicialize new settings
} else if(
version ==
INPUT_SETTINGS_VER_0) { // if config previous version - load it and manual set new settings to inital value
@@ -75,11 +75,11 @@ void input_settings_save(const InputSettings* settings) {
INPUT_SETTINGS_MAGIC,
INPUT_SETTINGS_VER);
// debug log
// FURI_LOG_D(TAG,"SAVE");
// char buffer[12] = {};
// snprintf(buffer, sizeof(buffer), "%d",settings->vibro_touch_level);
// FURI_LOG_D(TAG,buffer);
// debug log
// FURI_LOG_D(TAG,"SAVE");
// char buffer[12] = {};
// snprintf(buffer, sizeof(buffer), "%d",settings->vibro_touch_level);
// FURI_LOG_D(TAG,buffer);
if(!success) {
FURI_LOG_E(TAG, "Failed to save file");

View File

@@ -6,24 +6,33 @@
#define VIBRO_TOUCH_LEVEL_COUNT 10
// vibro touch human readable levels
const char* const vibro_touch_level_text[VIBRO_TOUCH_LEVEL_COUNT] = {
"OFF","1","2","3","4","5","6","7","8","9",};
"OFF",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
};
// vibro touch levels tick valies delay
const uint32_t vibro_touch_level_value[VIBRO_TOUCH_LEVEL_COUNT] =
{0,13,16,19,21,24,27,30,33,36};
{0, 13, 16, 19, 21, 24, 27, 30, 33, 36};
static void input_settings_vibro_touch_level_changed (VariableItem* item) {
static void input_settings_vibro_touch_level_changed(VariableItem* item) {
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, vibro_touch_level_text[index]);
//change settings to selected
InputSettingsApp* app = variable_item_get_context(item);
app->settings->vibro_touch_level = vibro_touch_level_value[index];
// use RECORD for acces to input service instance and set settings
InputSettings* service_settings = furi_record_open (RECORD_INPUT_SETTINGS);
InputSettings* service_settings = furi_record_open(RECORD_INPUT_SETTINGS);
service_settings->vibro_touch_level = vibro_touch_level_value[index];
furi_record_close (RECORD_INPUT_SETTINGS);
furi_record_close(RECORD_INPUT_SETTINGS);
}
static uint32_t input_settings_app_exit(void* context) {
@@ -31,15 +40,15 @@ static uint32_t input_settings_app_exit(void* context) {
return VIEW_NONE;
}
InputSettingsApp* input_settings_app_alloc (void) {
InputSettingsApp* input_settings_app_alloc(void) {
InputSettingsApp* app = malloc(sizeof(InputSettingsApp));
//app->inputservice = furi_record_open(RECORD_INPUT_EVENTS);
app->gui = furi_record_open (RECORD_GUI);
app->gui = furi_record_open(RECORD_GUI);
app->settings = malloc(sizeof(InputSettings));
input_settings_load (app->settings);
input_settings_load(app->settings);
app->variable_item_list = variable_item_list_alloc();
View* view = variable_item_list_get_view(app->variable_item_list);
view_set_previous_callback(view, input_settings_app_exit);
@@ -48,7 +57,11 @@ InputSettingsApp* input_settings_app_alloc (void) {
uint8_t value_index;
item = variable_item_list_add(
app->variable_item_list,"VibroTouchLevel",VIBRO_TOUCH_LEVEL_COUNT,input_settings_vibro_touch_level_changed,app);
app->variable_item_list,
"VibroTouchLevel",
VIBRO_TOUCH_LEVEL_COUNT,
input_settings_vibro_touch_level_changed,
app);
value_index = value_index_uint32(
app->settings->vibro_touch_level, vibro_touch_level_value, VIBRO_TOUCH_LEVEL_COUNT);
@@ -56,16 +69,16 @@ InputSettingsApp* input_settings_app_alloc (void) {
variable_item_set_current_value_text(item, vibro_touch_level_text[value_index]);
// create and setup view and view dispatcher
app->view_dispatcher = view_dispatcher_alloc ();
app->view_dispatcher = view_dispatcher_alloc();
view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
view_dispatcher_add_view(app->view_dispatcher,InputSettingsViewVariableItemList,view);
view_dispatcher_add_view(app->view_dispatcher, InputSettingsViewVariableItemList, view);
view_dispatcher_switch_to_view(app->view_dispatcher, InputSettingsViewVariableItemList);
return app;
return app;
}
void input_settings_app_free (InputSettingsApp* app){
void input_settings_app_free(InputSettingsApp* app) {
furi_assert(app);
// Variable item list
@@ -74,18 +87,18 @@ void input_settings_app_free (InputSettingsApp* app){
// View dispatcher
view_dispatcher_free(app->view_dispatcher);
// Records
furi_record_close(RECORD_GUI);
//furi_record_close(RECORD_INPUT_EVENTS);
free (app->settings);
free(app->settings);
free(app);
}
// Enter point
int32_t input_settings_app (void* p) {
UNUSED (p);
InputSettingsApp* app = input_settings_app_alloc ();
// Enter point
int32_t input_settings_app(void* p) {
UNUSED(p);
InputSettingsApp* app = input_settings_app_alloc();
view_dispatcher_run(app->view_dispatcher);
@@ -98,6 +111,6 @@ int32_t input_settings_app (void* p) {
//save current settings;
input_settings_save(app->settings);
input_settings_app_free (app);
input_settings_app_free(app);
return 0;
};
}

View File

@@ -11,17 +11,16 @@
#include <furi_hal_vibro.h>
#include <storage/storage.h>
// input_settings_app stucture
typedef struct {
//InputService* inputservice; //link to input_sevice with they setings and events
Gui* gui;
ViewDispatcher* view_dispatcher;
VariableItemList* variable_item_list;
InputSettings* settings;
//InputService* inputservice; //link to input_sevice with they setings and events
Gui* gui;
ViewDispatcher* view_dispatcher;
VariableItemList* variable_item_list;
InputSettings* settings;
} InputSettingsApp;
// list of menu views for view dispatcher
typedef enum {
InputSettingsViewVariableItemList,
} InputSettingsView;
} InputSettingsView;