mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2025-10-03 18:05:50 +02:00
Input Settings: Add Vibro Trigger option
by 956MB & WillyJL
This commit is contained in:
@@ -162,13 +162,14 @@ int32_t input_srv(void* p) {
|
|||||||
event.type = pin_states[i].state ? InputTypePress : InputTypeRelease;
|
event.type = pin_states[i].state ? InputTypePress : InputTypeRelease;
|
||||||
furi_pubsub_publish(event_pubsub, &event);
|
furi_pubsub_publish(event_pubsub, &event);
|
||||||
// vibro signal if user setup vibro touch level in Settings-Input.
|
// vibro signal if user setup vibro touch level in Settings-Input.
|
||||||
if(settings->vibro_touch_level) {
|
if(settings->vibro_touch_level &&
|
||||||
|
((1 << event.type) & settings->vibro_touch_trigger_mask)) {
|
||||||
//delay 1 ticks for compatibility with rgb_backlight_mod
|
//delay 1 ticks for compatibility with rgb_backlight_mod
|
||||||
furi_delay_tick(1);
|
furi_delay_tick(1);
|
||||||
furi_hal_vibro_on(true);
|
furi_hal_vibro_on(true);
|
||||||
furi_delay_tick(settings->vibro_touch_level);
|
furi_delay_tick(settings->vibro_touch_level);
|
||||||
furi_hal_vibro_on(false);
|
furi_hal_vibro_on(false);
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,16 +1,20 @@
|
|||||||
#include "input_settings.h"
|
#include "input_settings.h"
|
||||||
#include "input_settings_filename.h"
|
#include "input_settings_filename.h"
|
||||||
|
#include "input.h"
|
||||||
|
|
||||||
#include <saved_struct.h>
|
#include <saved_struct.h>
|
||||||
#include <storage/storage.h>
|
#include <storage/storage.h>
|
||||||
|
|
||||||
#define TAG "InputSettings"
|
#define TAG "InputSettings"
|
||||||
|
|
||||||
#define INPUT_SETTINGS_VER (1) // version nnumber
|
#define INPUT_SETTINGS_VER (2) // version number
|
||||||
|
|
||||||
#define INPUT_SETTINGS_PATH INT_PATH(INPUT_SETTINGS_FILE_NAME)
|
#define INPUT_SETTINGS_PATH INT_PATH(INPUT_SETTINGS_FILE_NAME)
|
||||||
#define INPUT_SETTINGS_MAGIC (0x29)
|
#define INPUT_SETTINGS_MAGIC (0x29)
|
||||||
|
|
||||||
|
#define INPUT_SETTINGS_VIBRO_TOUCH_TRIGGER_MASK_DEFAULT \
|
||||||
|
((1 << InputTypePress) | (1 << InputTypeRelease))
|
||||||
|
|
||||||
void input_settings_load(InputSettings* settings) {
|
void input_settings_load(InputSettings* settings) {
|
||||||
furi_assert(settings);
|
furi_assert(settings);
|
||||||
|
|
||||||
@@ -22,6 +26,18 @@ void input_settings_load(InputSettings* settings) {
|
|||||||
uint8_t version;
|
uint8_t version;
|
||||||
if(!saved_struct_get_metadata(INPUT_SETTINGS_PATH, NULL, &version, NULL)) break;
|
if(!saved_struct_get_metadata(INPUT_SETTINGS_PATH, NULL, &version, NULL)) break;
|
||||||
|
|
||||||
|
if(version == 1) {
|
||||||
|
struct {
|
||||||
|
uint8_t vibro_touch_level;
|
||||||
|
} v1;
|
||||||
|
if(!saved_struct_load(INPUT_SETTINGS_PATH, &v1, sizeof(v1), INPUT_SETTINGS_MAGIC, 1))
|
||||||
|
break;
|
||||||
|
settings->vibro_touch_level = v1.vibro_touch_level;
|
||||||
|
settings->vibro_touch_trigger_mask = INPUT_SETTINGS_VIBRO_TOUCH_TRIGGER_MASK_DEFAULT;
|
||||||
|
success = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// if config actual version - load it directly
|
// if config actual version - load it directly
|
||||||
if(version == INPUT_SETTINGS_VER) {
|
if(version == INPUT_SETTINGS_VER) {
|
||||||
success = saved_struct_load(
|
success = saved_struct_load(
|
||||||
@@ -38,7 +54,8 @@ void input_settings_load(InputSettings* settings) {
|
|||||||
if(!success) {
|
if(!success) {
|
||||||
FURI_LOG_W(TAG, "Failed to load file, using defaults");
|
FURI_LOG_W(TAG, "Failed to load file, using defaults");
|
||||||
memset(settings, 0, sizeof(InputSettings));
|
memset(settings, 0, sizeof(InputSettings));
|
||||||
input_settings_save(settings);
|
settings->vibro_touch_trigger_mask = INPUT_SETTINGS_VIBRO_TOUCH_TRIGGER_MASK_DEFAULT;
|
||||||
|
// input_settings_save(settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t vibro_touch_level;
|
uint8_t vibro_touch_level;
|
||||||
|
uint8_t vibro_touch_trigger_mask;
|
||||||
} InputSettings;
|
} InputSettings;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@@ -4,6 +4,8 @@
|
|||||||
#define TAG "InputSettingsApp"
|
#define TAG "InputSettingsApp"
|
||||||
|
|
||||||
#define VIBRO_TOUCH_LEVEL_COUNT 10
|
#define VIBRO_TOUCH_LEVEL_COUNT 10
|
||||||
|
#define VIBRO_TOUCH_TRIGGER_MASK_COUNT 3
|
||||||
|
|
||||||
// vibro touch human readable levels
|
// vibro touch human readable levels
|
||||||
const char* const vibro_touch_level_text[VIBRO_TOUCH_LEVEL_COUNT] = {
|
const char* const vibro_touch_level_text[VIBRO_TOUCH_LEVEL_COUNT] = {
|
||||||
"OFF",
|
"OFF",
|
||||||
@@ -20,21 +22,45 @@ const char* const vibro_touch_level_text[VIBRO_TOUCH_LEVEL_COUNT] = {
|
|||||||
// vibro touch levels tick valies delay
|
// vibro touch levels tick valies delay
|
||||||
const uint32_t vibro_touch_level_value[VIBRO_TOUCH_LEVEL_COUNT] =
|
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};
|
||||||
|
// vibro touch trigger mask human readable values
|
||||||
|
const char* const vibro_touch_trigger_mask_text[VIBRO_TOUCH_TRIGGER_MASK_COUNT] = {
|
||||||
|
"Press",
|
||||||
|
"Release",
|
||||||
|
"Both",
|
||||||
|
};
|
||||||
|
// vibro touch trigger mask values
|
||||||
|
const uint32_t vibro_touch_trigger_mask_value[VIBRO_TOUCH_TRIGGER_MASK_COUNT] = {
|
||||||
|
(1 << InputTypePress),
|
||||||
|
(1 << InputTypeRelease),
|
||||||
|
(1 << InputTypePress) | (1 << InputTypeRelease),
|
||||||
|
};
|
||||||
|
|
||||||
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);
|
uint8_t index = variable_item_get_current_value_index(item);
|
||||||
variable_item_set_current_value_text(item, vibro_touch_level_text[index]);
|
variable_item_set_current_value_text(item, vibro_touch_level_text[index]);
|
||||||
|
|
||||||
//change settings to selected
|
|
||||||
InputSettingsApp* app = variable_item_get_context(item);
|
InputSettingsApp* app = variable_item_get_context(item);
|
||||||
app->settings->vibro_touch_level = vibro_touch_level_value[index];
|
app->settings->vibro_touch_level = vibro_touch_level_value[index];
|
||||||
|
|
||||||
// use RECORD for acces to input service instance and set settings
|
// use RECORD for access 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];
|
service_settings->vibro_touch_level = vibro_touch_level_value[index];
|
||||||
furi_record_close(RECORD_INPUT_SETTINGS);
|
furi_record_close(RECORD_INPUT_SETTINGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void input_settings_vibro_touch_trigger_mask_changed(VariableItem* item) {
|
||||||
|
uint8_t index = variable_item_get_current_value_index(item);
|
||||||
|
variable_item_set_current_value_text(item, vibro_touch_trigger_mask_text[index]);
|
||||||
|
|
||||||
|
InputSettingsApp* app = variable_item_get_context(item);
|
||||||
|
app->settings->vibro_touch_trigger_mask = vibro_touch_trigger_mask_value[index];
|
||||||
|
|
||||||
|
// use RECORD for access to input service instance and set settings
|
||||||
|
InputSettings* service_settings = furi_record_open(RECORD_INPUT_SETTINGS);
|
||||||
|
service_settings->vibro_touch_trigger_mask = vibro_touch_trigger_mask_value[index];
|
||||||
|
furi_record_close(RECORD_INPUT_SETTINGS);
|
||||||
|
}
|
||||||
|
|
||||||
static uint32_t input_settings_app_exit(void* context) {
|
static uint32_t input_settings_app_exit(void* context) {
|
||||||
UNUSED(context);
|
UNUSED(context);
|
||||||
return VIEW_NONE;
|
return VIEW_NONE;
|
||||||
@@ -66,6 +92,20 @@ InputSettingsApp* input_settings_app_alloc(void) {
|
|||||||
variable_item_set_current_value_index(item, value_index);
|
variable_item_set_current_value_index(item, value_index);
|
||||||
variable_item_set_current_value_text(item, vibro_touch_level_text[value_index]);
|
variable_item_set_current_value_text(item, vibro_touch_level_text[value_index]);
|
||||||
|
|
||||||
|
item = variable_item_list_add(
|
||||||
|
app->variable_item_list,
|
||||||
|
"Vibro Trigger",
|
||||||
|
VIBRO_TOUCH_TRIGGER_MASK_COUNT,
|
||||||
|
input_settings_vibro_touch_trigger_mask_changed,
|
||||||
|
app);
|
||||||
|
|
||||||
|
value_index = value_index_uint32(
|
||||||
|
app->settings->vibro_touch_trigger_mask,
|
||||||
|
vibro_touch_trigger_mask_value,
|
||||||
|
VIBRO_TOUCH_TRIGGER_MASK_COUNT);
|
||||||
|
variable_item_set_current_value_index(item, value_index);
|
||||||
|
variable_item_set_current_value_text(item, vibro_touch_trigger_mask_text[value_index]);
|
||||||
|
|
||||||
// create and setup view and view dispatcher
|
// 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_set_event_callback_context(app->view_dispatcher, app);
|
||||||
|
Reference in New Issue
Block a user