mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-11 06:09:08 -07:00
Begin work with Input_service settings (edit,save) for vibro_touch option
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
77
applications/services/input/input_settings.c
Normal file
77
applications/services/input/input_settings.c
Normal 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");
|
||||
}
|
||||
}
|
||||
18
applications/services/input/input_settings.h
Normal file
18
applications/services/input/input_settings.h
Normal 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
|
||||
3
applications/services/input/input_settings_filename.h
Normal file
3
applications/services/input/input_settings_filename.h
Normal file
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#define INPUT_SETTINGS_FILE_NAME ".input.settings"
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user