diff --git a/CHANGELOG.md b/CHANGELOG.md index f04a65ac3..7d66074f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - RFID: Support writing Securakey, Jablotron and FDX-B to EM4305 cards (#434 by @jamisonderek) - BT Remote: Add Rename Option, simplify Bad KB BLE profile (#439 by @aaronjamt & @WillyJL) - MNTM Settings: Add Skip Sliding Animations option for Lockscreen (#436 by @aaronjamt) +- Input Settings: Add Vibro Trigger option (#429 by @956MB) ### Updated: - Apps: diff --git a/applications/services/input/input.c b/applications/services/input/input.c index fb6eb7a25..8d1267a90 100644 --- a/applications/services/input/input.c +++ b/applications/services/input/input.c @@ -156,13 +156,14 @@ int32_t input_srv(void* p) { event.type = pin_states[i].state ? InputTypePress : InputTypeRelease; furi_pubsub_publish(event_pubsub, &event); // 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 furi_delay_tick(1); furi_hal_vibro_on(true); furi_delay_tick(settings->vibro_touch_level); furi_hal_vibro_on(false); - }; + } } } diff --git a/applications/services/input/input_settings.c b/applications/services/input/input_settings.c index d48990847..df2928fad 100644 --- a/applications/services/input/input_settings.c +++ b/applications/services/input/input_settings.c @@ -1,15 +1,19 @@ #include "input_settings.h" #include "input_settings_filename.h" +#include "input.h" #include #include #define TAG "InputSettings" -#define INPUT_SETTINGS_VER (1) // version nnumber +#define INPUT_SETTINGS_VER (2) // version number #define INPUT_SETTINGS_MAGIC (0x29) +#define INPUT_SETTINGS_VIBRO_TOUCH_TRIGGER_MASK_DEFAULT \ + ((1 << InputTypePress) | (1 << InputTypeRelease)) + void input_settings_load(InputSettings* settings) { furi_assert(settings); @@ -21,6 +25,18 @@ void input_settings_load(InputSettings* settings) { uint8_t version; 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(version == INPUT_SETTINGS_VER) { success = saved_struct_load( @@ -37,6 +53,7 @@ void input_settings_load(InputSettings* settings) { if(!success) { FURI_LOG_W(TAG, "Failed to load file, using defaults"); memset(settings, 0, sizeof(InputSettings)); + settings->vibro_touch_trigger_mask = INPUT_SETTINGS_VIBRO_TOUCH_TRIGGER_MASK_DEFAULT; // input_settings_save(settings); } } diff --git a/applications/services/input/input_settings.h b/applications/services/input/input_settings.h index 861c15ac4..2dce6586a 100644 --- a/applications/services/input/input_settings.h +++ b/applications/services/input/input_settings.h @@ -6,6 +6,7 @@ typedef struct { uint8_t vibro_touch_level; + uint8_t vibro_touch_trigger_mask; } InputSettings; void input_settings_load(InputSettings* settings); diff --git a/applications/settings/input_settings_app/input_settings_app.c b/applications/settings/input_settings_app/input_settings_app.c index 4f3e101da..035a84e79 100644 --- a/applications/settings/input_settings_app/input_settings_app.c +++ b/applications/settings/input_settings_app/input_settings_app.c @@ -3,7 +3,9 @@ #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 const char* const vibro_touch_level_text[VIBRO_TOUCH_LEVEL_COUNT] = { "OFF", @@ -20,21 +22,45 @@ const char* const vibro_touch_level_text[VIBRO_TOUCH_LEVEL_COUNT] = { // 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}; +// 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) { 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 + // use RECORD for access to input service instance and set 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); } +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) { UNUSED(context); 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_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 app->view_dispatcher = view_dispatcher_alloc(); view_dispatcher_set_event_callback_context(app->view_dispatcher, app);