mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-12 04:34:43 +04:00
InputSettings complete. Added VibroTouchLevel
This commit is contained in:
@@ -7,4 +7,5 @@ App(
|
||||
stack_size=1 * 1024,
|
||||
order=80,
|
||||
sdk_headers=["input.h"],
|
||||
provides=["input_settings"],
|
||||
)
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#define INPUT_LONG_PRESS_COUNTS 2
|
||||
#define INPUT_THREAD_FLAG_ISR 0x00000001
|
||||
|
||||
#define TAG "Input"
|
||||
|
||||
/** Input pin state */
|
||||
typedef struct {
|
||||
const InputPin* pin;
|
||||
@@ -80,27 +82,76 @@ const char* input_get_type_name(InputType type) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// static void input_storage_callback(const void* message, void* context) {
|
||||
// furi_assert(context);
|
||||
// InputSettings* settings = context;
|
||||
// const StorageEvent* event = message;
|
||||
// UNUSED (settings);
|
||||
// if(event->type == StorageEventTypeCardMount) {
|
||||
// // 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_delay_tick (100);
|
||||
// // furi_hal_vibro_on(true);
|
||||
// // furi_delay_tick (100);
|
||||
// // furi_hal_vibro_on(false);
|
||||
// //input_settings_load(settings);
|
||||
// }
|
||||
// }
|
||||
|
||||
// // load inital settings from file for power service
|
||||
// static void input_init_settings(InputSettings* settings) {
|
||||
// Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
// furi_pubsub_subscribe(storage_get_pubsub(storage), input_storage_callback, settings);
|
||||
|
||||
// if(storage_sd_status(storage) != FSE_OK) {
|
||||
// FURI_LOG_D(TAG, "SD Card not ready, skipping settings");
|
||||
// //set default value
|
||||
// settings->vibro_touch_level=0;
|
||||
// //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);
|
||||
|
||||
// input_settings_load(settings);
|
||||
// furi_record_close(RECORD_STORAGE);
|
||||
// }
|
||||
|
||||
// allocate memory for input_settings structure
|
||||
static InputSettings* input_settings_alloc (void) {
|
||||
InputSettings* input_settings = malloc(sizeof(InputSettings));
|
||||
return input_settings;
|
||||
InputSettings* settings = malloc(sizeof(InputSettings));
|
||||
return settings;
|
||||
}
|
||||
|
||||
//free memory from input_settings structure
|
||||
void input_settings_free (InputSettings* input_settings) {
|
||||
free (input_settings);
|
||||
void input_settings_free (InputSettings* settings) {
|
||||
free (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;
|
||||
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);
|
||||
input_settings_load(settings);
|
||||
|
||||
#ifdef INPUT_DEBUG
|
||||
furi_hal_gpio_init_simple(&gpio_ext_pa4, GpioModeOutputPushPull);
|
||||
@@ -164,9 +215,10 @@ 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) {
|
||||
// do vibro if user setup vibro touch level in Settings-Input.
|
||||
if (settings->vibro_touch_level) {
|
||||
furi_hal_vibro_on(true);
|
||||
furi_delay_tick (30);
|
||||
furi_delay_tick (settings->vibro_touch_level);
|
||||
furi_hal_vibro_on(false);
|
||||
};
|
||||
}
|
||||
@@ -185,7 +237,6 @@ 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;
|
||||
}
|
||||
|
||||
@@ -7,12 +7,15 @@
|
||||
|
||||
#include <furi_hal_resources.h>
|
||||
#include "input_settings.h"
|
||||
#include <storage/storage.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define RECORD_INPUT_EVENTS "input_events"
|
||||
#define RECORD_INPUT_SETTINGS "input_settings"
|
||||
#define INPUT_SEQUENCE_SOURCE_HARDWARE (0u)
|
||||
#define INPUT_SEQUENCE_SOURCE_SOFTWARE (1u)
|
||||
|
||||
@@ -41,13 +44,6 @@ 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
|
||||
|
||||
@@ -21,18 +21,21 @@ void input_settings_load(InputSettings* settings) {
|
||||
|
||||
bool success = false;
|
||||
|
||||
//a useless cycle do-while, may will be used in future with anoter condition
|
||||
do {
|
||||
// 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(version == INPUT_SETTINGS_VER) { // if config actual version - load it directly
|
||||
|
||||
// if config actual version - load it directly
|
||||
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
|
||||
} else if(
|
||||
version ==
|
||||
INPUT_SETTINGS_VER_0) { // if config previous version - load it and manual set new settings to inital value
|
||||
@@ -51,9 +54,10 @@ void input_settings_load(InputSettings* settings) {
|
||||
|
||||
free(settings_v0);
|
||||
}
|
||||
|
||||
// in case of another config version we exit from useless cycle to next step
|
||||
} while(false);
|
||||
|
||||
// fill settings with 0 and save to settings file;
|
||||
if(!success) {
|
||||
FURI_LOG_W(TAG, "Failed to load file, using defaults");
|
||||
memset(settings, 0, sizeof(InputSettings));
|
||||
@@ -71,6 +75,12 @@ 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);
|
||||
|
||||
if(!success) {
|
||||
FURI_LOG_E(TAG, "Failed to save file");
|
||||
}
|
||||
|
||||
@@ -615,7 +615,7 @@ static Power* power_alloc(void) {
|
||||
free(settings);
|
||||
|
||||
// auto_poweroff
|
||||
//---define subscription to loader events message (info about started apps) and defina callback for this
|
||||
//---define subscription to loader events message (info about started apps) and define callback for this
|
||||
Loader* loader = furi_record_open(RECORD_LOADER);
|
||||
furi_pubsub_subscribe(loader_get_pubsub(loader), power_loader_callback, power);
|
||||
power->input_events_pubsub = furi_record_open(RECORD_INPUT_EVENTS);
|
||||
|
||||
Reference in New Issue
Block a user