From 48495ddafe2ed59611c9491470f192b790e6146d Mon Sep 17 00:00:00 2001 From: ailurux Date: Fri, 7 Feb 2025 02:44:24 +0000 Subject: Add centre button haptic feedback on touch, and setting to disable/lessen haptics (#246) This adds a way for feedback devices to respond to events from outside of LVGL's event system, being passed from input device to feedback device through a vector. This was done so that touch events and long-press triggers can now give feedback through haptics. This PR also adds haptic modes, saved in nvs similarly to input and locked input modes, to disable or change the haptic effect behaviour based on which mode is selected. Finally, this also fixes a bug in which some click events would not trigger haptics, at the expense of re-introducing the (undesired?) behaviour of clicking a button that transitions to a new screen causing a double click. Relevant issues this should close: #195, #233, and (partially?) #120 Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/246 Co-authored-by: ailurux Co-committed-by: ailurux --- src/drivers/nvs.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/drivers/nvs.cpp') diff --git a/src/drivers/nvs.cpp b/src/drivers/nvs.cpp index 02a0058b..04a93fd9 100644 --- a/src/drivers/nvs.cpp +++ b/src/drivers/nvs.cpp @@ -35,6 +35,7 @@ static constexpr char kKeyAmpCurrentVolume[] = "hp_vol"; static constexpr char kKeyAmpLeftBias[] = "hp_bias"; static constexpr char kKeyPrimaryInput[] = "in_pri"; static constexpr char kKeyLockedInput[] = "in_locked"; +static constexpr char kKeyHaptics[] = "haptic_mode"; static constexpr char kKeyScrollSensitivity[] = "scroll"; static constexpr char kKeyLockPolarity[] = "lockpol"; static constexpr char kKeyDisplayCols[] = "dispcols"; @@ -275,6 +276,7 @@ NvsStorage::NvsStorage(nvs_handle_t handle) input_mode_(kKeyPrimaryInput), locked_input_mode_(kKeyLockedInput), output_mode_(kKeyOutput), + haptics_mode_(kKeyHaptics), theme_{kKeyInterfaceTheme}, bt_preferred_(kKeyBluetoothPreferred), bt_names_(kKeyBluetoothNames), @@ -304,6 +306,7 @@ auto NvsStorage::Read() -> void { input_mode_.read(handle_); locked_input_mode_.read(handle_); output_mode_.read(handle_); + haptics_mode_.read(handle_); theme_.read(handle_); bt_preferred_.read(handle_); bt_names_.read(handle_); @@ -328,6 +331,7 @@ auto NvsStorage::Write() -> bool { input_mode_.write(handle_); locked_input_mode_.write(handle_); output_mode_.write(handle_); + haptics_mode_.write(handle_); theme_.write(handle_); bt_preferred_.write(handle_); bt_names_.write(handle_); @@ -483,6 +487,31 @@ auto NvsStorage::OutputMode(Output out) -> void { nvs_commit(handle_); } +auto NvsStorage::HapticsMode() -> HapticsModes { + std::lock_guard lock{mutex_}; + int val = haptics_mode_.get().value_or(static_cast(HapticsModes::kMinimal)); + return intToHapticsMode(val); +} + +auto NvsStorage::intToHapticsMode(int raw) -> HapticsModes { + switch (raw) { + case static_cast(HapticsModes::kDisabled): + return HapticsModes::kDisabled; + case static_cast(HapticsModes::kMinimal): + return HapticsModes::kMinimal; + case static_cast(HapticsModes::kStrong): + return HapticsModes::kStrong; + default: + return HapticsModes::kStrong; + } +} + +auto NvsStorage::HapticsMode(HapticsModes mode) -> void { + std::lock_guard lock{mutex_}; + haptics_mode_.set(static_cast(mode)); +} + + auto NvsStorage::FastCharge() -> bool { std::lock_guard lock{mutex_}; return fast_charge_.get().value_or(true); -- cgit v1.2.3