Begin work with Input_service settings (edit,save) for vibro_touch option

This commit is contained in:
Dmitry422
2025-01-31 19:25:52 +07:00
parent 1acc814b2a
commit a5f62f756a
10 changed files with 232 additions and 1 deletions

View File

@@ -6,6 +6,7 @@
#include <furi.h>
#include <cli/cli.h>
#include <furi_hal_gpio.h>
#include <furi_hal_vibro.h>
#define INPUT_DEBOUNCE_TICKS_HALF (INPUT_DEBOUNCE_TICKS / 2)
#define INPUT_PRESS_TICKS 150
@@ -79,9 +80,23 @@ const char* input_get_type_name(InputType type) {
}
}
// allocate memory for input_settings structure
static InputSettings* input_settings_alloc (void) {
InputSettings* input_settings = malloc(sizeof(InputSettings));
return input_settings;
}
//free memory from input_settings structure
void input_settings_free (InputSettings* input_settings) {
free (input_settings);
}
int32_t input_srv(void* p) {
UNUSED(p);
//define object input_settings and take memory for him
InputSettings* input_settings = input_settings_alloc();
const FuriThreadId thread_id = furi_thread_get_current_id();
FuriPubSub* event_pubsub = furi_pubsub_alloc();
uint32_t counter = 1;
@@ -149,6 +164,11 @@ int32_t input_srv(void* p) {
// Send Press/Release event
event.type = pin_states[i].state ? InputTypePress : InputTypeRelease;
furi_pubsub_publish(event_pubsub, &event);
if (input_settings->vibro_touch_level) {
furi_hal_vibro_on(true);
furi_delay_tick (30);
furi_hal_vibro_on(false);
};
}
}
@@ -165,5 +185,7 @@ int32_t input_srv(void* p) {
}
}
// if we come here and ready exit from service (whats going on ??!!) then best practice is free memory
input_settings_free(input_settings);
return 0;
}

View File

@@ -6,6 +6,7 @@
#pragma once
#include <furi_hal_resources.h>
#include "input_settings.h"
#ifdef __cplusplus
extern "C" {
@@ -40,6 +41,13 @@ typedef struct {
InputType type;
} InputEvent;
//for next step input structure globalization;
//typedef struct Input {
//InputSettings* settings;
//InputType* type;
//InputEvent* event;
//} Input;
/** Get human readable input key name
* @param key - InputKey
* @return string

View File

@@ -0,0 +1,77 @@
#include "input_settings.h"
#include "input_settings_filename.h"
#include <saved_struct.h>
#include <storage/storage.h>
#define TAG "InputSettings"
#define INPUT_SETTINGS_VER_0 (0) // OLD version number
#define INPUT_SETTINGS_VER (1) // NEW actual version nnumber
#define INPUT_SETTINGS_PATH INT_PATH(INPUT_SETTINGS_FILE_NAME)
#define INPUT_SETTINGS_MAGIC (0x19)
typedef struct {
//inital set - empty
} InputSettingsV0;
void input_settings_load(InputSettings* settings) {
furi_assert(settings);
bool success = false;
do {
uint8_t version;
if(!saved_struct_get_metadata(INPUT_SETTINGS_PATH, NULL, &version, NULL)) break;
if(version == INPUT_SETTINGS_VER) { // if config actual version - load it directly
success = saved_struct_load(
INPUT_SETTINGS_PATH,
settings,
sizeof(InputSettings),
INPUT_SETTINGS_MAGIC,
INPUT_SETTINGS_VER);
} else if(
version ==
INPUT_SETTINGS_VER_0) { // if config previous version - load it and manual set new settings to inital value
InputSettingsV0* settings_v0 = malloc(sizeof(InputSettingsV0));
success = saved_struct_load(
INPUT_SETTINGS_PATH,
settings_v0,
sizeof(InputSettingsV0),
INPUT_SETTINGS_MAGIC,
INPUT_SETTINGS_VER_0);
if(success) {
settings->vibro_touch_level = 0;
}
free(settings_v0);
}
} while(false);
if(!success) {
FURI_LOG_W(TAG, "Failed to load file, using defaults");
memset(settings, 0, sizeof(InputSettings));
input_settings_save(settings);
}
}
void input_settings_save(const InputSettings* settings) {
furi_assert(settings);
const bool success = saved_struct_save(
INPUT_SETTINGS_PATH,
settings,
sizeof(InputSettings),
INPUT_SETTINGS_MAGIC,
INPUT_SETTINGS_VER);
if(!success) {
FURI_LOG_E(TAG, "Failed to save file");
}
}

View File

@@ -0,0 +1,18 @@
#pragma once
#include <stdint.h>
typedef struct {
uint8_t vibro_touch_level;
} InputSettings;
#ifdef __cplusplus
extern "C" {
#endif
void input_settings_load(InputSettings* settings);
void input_settings_save(const InputSettings* settings);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,3 @@
#pragma once
#define INPUT_SETTINGS_FILE_NAME ".input.settings"

View File

@@ -9,8 +9,10 @@ typedef struct {
#ifdef __cplusplus
extern "C" {
#endif
void power_settings_load(PowerSettings* settings);
void power_settings_save(const PowerSettings* settings);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,9 @@
App(
appid="input_settings",
name="Input",
apptype=FlipperAppType,SETTINGS,
entry_point="input_settings_app",
requires=["gui"],
stack_size= 1 * 1024,
order=100,
)

View File

@@ -0,0 +1,67 @@
#include <stdint.h>
#include "input_settings_app.h"
#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",
};
// 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};
input_settings_start_vibro_touch_level_changed (){
}
InputSettingsApp* input_settings_alloc (void) {
InputSettingsApp* app = malloc(sizeof(InputSettingsApp));
app->gui = furi_record_open (RECORD_GUI);
app->view_dispatcher = view_dispatcher_alloc ();
VariableItem* item;
app->var_item_list = variable_item_list_alloc();
item = variable_item_list_add(
variable_item_list,
"Vibro touch level",
VIBRO_TOUCH_LEVEL_COUNT,
input_settings_start_vibro_touch_level_changed,
app);
value_index = value_index_uint32(
app->settings.vibro_touch_level, vibro_touch_level_value, VIBRO_TOUCH_LEVEL_COUNT);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, vibro_touch_level_text[value_index]);
return app;
}
// Enter point
int32_t input_settings_app (void* p) {
UNUSED (p);
//take memory
InputSettingsApp* app = input_settings_alloc ();
//start view_dispatcher
view_dispatcher_run(app->view_dispatcher);
//free memory
Input_settings_free (app);
//exit with 0 code
return 0;
};

View File

@@ -0,0 +1,23 @@
#pragma once
#include <furi.h>
#include <furi_hal.h>
#include <gui/gui.h>
#include <gui/view.h>
#include <gui/view_dispatcher.h>
#include <gui/modules/variable_item_list.h>
#include "input/input_settings.h"
// app stucture
typedef struct {
InputSettings* settings;
Input* input;
Gui* gui;
ViewDispatcher* view_dispatcher;
VariableItemList* variable_item_list;
} InputSettingsApp;
// list of menu views for view dispatcher
typedef enum {
InputSettingsViewVariableItemList,
} InputSettingsView;

View File

@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,79.3,,
Version,+,79.4,,
Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/bt/bt_service/bt_keys_storage.h,,
@@ -2112,6 +2112,8 @@ Function,+,infrared_worker_tx_stop,void,InfraredWorker*
Function,-,initstate,char*,"unsigned, char*, size_t"
Function,+,input_get_key_name,const char*,InputKey
Function,+,input_get_type_name,const char*,InputType
Function,+,input_settings_load,void,InputSettings*
Function,+,input_settings_save,void,const InputSettings*
Function,-,iprintf,int,"const char*, ..."
Function,-,isalnum,int,int
Function,-,isalnum_l,int,"int, locale_t"
1 entry status name type params
2 Version + 79.3 79.4
3 Header + applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h
4 Header + applications/services/bt/bt_service/bt.h
5 Header + applications/services/bt/bt_service/bt_keys_storage.h
2112 Function - initstate char* unsigned, char*, size_t
2113 Function + input_get_key_name const char* InputKey
2114 Function + input_get_type_name const char* InputType
2115 Function + input_settings_load void InputSettings*
2116 Function + input_settings_save void const InputSettings*
2117 Function - iprintf int const char*, ...
2118 Function - isalnum int int
2119 Function - isalnum_l int int, locale_t