diff options
Diffstat (limited to 'src/input/include')
| -rw-r--r-- | src/input/include/device_factory.hpp | 39 | ||||
| -rw-r--r-- | src/input/include/feedback_device.hpp | 32 | ||||
| -rw-r--r-- | src/input/include/feedback_haptics.hpp | 26 | ||||
| -rw-r--r-- | src/input/include/input_device.hpp | 39 | ||||
| -rw-r--r-- | src/input/include/input_nav_buttons.hpp | 34 | ||||
| -rw-r--r-- | src/input/include/input_touch_dpad.hpp | 36 | ||||
| -rw-r--r-- | src/input/include/input_touch_wheel.hpp | 51 | ||||
| -rw-r--r-- | src/input/include/input_trigger.hpp | 37 | ||||
| -rw-r--r-- | src/input/include/input_volume_buttons.hpp | 34 | ||||
| -rw-r--r-- | src/input/include/lvgl_input_driver.hpp | 58 |
10 files changed, 386 insertions, 0 deletions
diff --git a/src/input/include/device_factory.hpp b/src/input/include/device_factory.hpp new file mode 100644 index 00000000..dd9c7133 --- /dev/null +++ b/src/input/include/device_factory.hpp @@ -0,0 +1,39 @@ +/* + * Copyright 2023 jacqueline <me@jacqueline.id.au> + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include <cstdint> +#include <memory> + +#include "feedback_device.hpp" +#include "input_device.hpp" +#include "input_touch_wheel.hpp" +#include "nvs.hpp" +#include "service_locator.hpp" + +namespace input { + +class DeviceFactory { + public: + DeviceFactory(std::shared_ptr<system_fsm::ServiceLocator>); + + auto createInputs(drivers::NvsStorage::InputModes mode) + -> std::vector<std::shared_ptr<IInputDevice>>; + + auto createFeedbacks() -> std::vector<std::shared_ptr<IFeedbackDevice>>; + + auto touch_wheel() -> std::shared_ptr<TouchWheel> { return wheel_; } + + private: + std::shared_ptr<system_fsm::ServiceLocator> services_; + + // HACK: the touchwheel is current a special case, since it's the only input + // device that has some kind of setting/configuration; scroll sensitivity. + std::shared_ptr<TouchWheel> wheel_; +}; + +} // namespace input diff --git a/src/input/include/feedback_device.hpp b/src/input/include/feedback_device.hpp new file mode 100644 index 00000000..4faeeafd --- /dev/null +++ b/src/input/include/feedback_device.hpp @@ -0,0 +1,32 @@ +/* + * Copyright 2024 jacqueline <me@jacqueline.id.au> + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include <cstdint> + +namespace input { + +/* + * Interface for providing non-visual feedback to the user as a result of LVGL + * events. 'Feedback Devices' are able to observe all events that are generated + * by LVGL as a result of Input Devices. + * + * Implementations of this interface are a mix of hardware features (e.g. a + * haptic motor buzzing when your selection changes) and firmware features + * (e.g. playing audio feedback that describes the selected element). + */ +class IFeedbackDevice { + public: + virtual ~IFeedbackDevice() {} + + virtual auto feedback(uint8_t event_type) -> void = 0; + + // TODO: Add configuration; likely the same shape of interface that + // IInputDevice uses. +}; + +} // namespace input diff --git a/src/input/include/feedback_haptics.hpp b/src/input/include/feedback_haptics.hpp new file mode 100644 index 00000000..a307a429 --- /dev/null +++ b/src/input/include/feedback_haptics.hpp @@ -0,0 +1,26 @@ +/* + * Copyright 2024 jacqueline <me@jacqueline.id.au> + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include <cstdint> + +#include "feedback_device.hpp" +#include "haptics.hpp" + +namespace input { + +class Haptics : public IFeedbackDevice { + public: + Haptics(drivers::Haptics& haptics_); + + auto feedback(uint8_t event_type) -> void override; + + private: + drivers::Haptics& haptics_; +}; + +} // namespace input diff --git a/src/input/include/input_device.hpp b/src/input/include/input_device.hpp new file mode 100644 index 00000000..5fc3e066 --- /dev/null +++ b/src/input/include/input_device.hpp @@ -0,0 +1,39 @@ +/* + * Copyright 2024 jacqueline <me@jacqueline.id.au> + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include <functional> +#include <string> +#include <vector> + +#include "hal/lv_hal_indev.h" +#include "property.hpp" + +namespace input { + +/* + * Interface for all device input methods. Each 'Input Device' is polled by + * LVGL at regular intervals, and can effect the device either via LVGL's input + * device driver API, or by emitting events for other parts of the system to + * react to (e.g. issuing a play/pause event, or altering the volume). + */ +class IInputDevice { + public: + virtual ~IInputDevice() {} + + virtual auto read(lv_indev_data_t* data) -> void = 0; + + // TODO: Add hooks and configuration (or are hooks just one kind of + // configuration?) + + virtual auto settings() + -> std::vector<std::pair<std::string, lua::Property>> { + return {}; + } +}; + +} // namespace input diff --git a/src/input/include/input_nav_buttons.hpp b/src/input/include/input_nav_buttons.hpp new file mode 100644 index 00000000..29a19a16 --- /dev/null +++ b/src/input/include/input_nav_buttons.hpp @@ -0,0 +1,34 @@ +/* + * Copyright 2024 jacqueline <me@jacqueline.id.au> + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include <cstdint> + +#include "gpios.hpp" +#include "hal/lv_hal_indev.h" + +#include "haptics.hpp" +#include "input_device.hpp" +#include "input_trigger.hpp" +#include "touchwheel.hpp" + +namespace input { + +class NavButtons : public IInputDevice { + public: + NavButtons(drivers::IGpios&); + + auto read(lv_indev_data_t* data) -> void override; + + private: + drivers::IGpios& gpios_; + + Trigger up_; + Trigger down_; +}; + +} // namespace input diff --git a/src/input/include/input_touch_dpad.hpp b/src/input/include/input_touch_dpad.hpp new file mode 100644 index 00000000..03936acb --- /dev/null +++ b/src/input/include/input_touch_dpad.hpp @@ -0,0 +1,36 @@ +/* + * Copyright 2024 jacqueline <me@jacqueline.id.au> + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include <stdint.h> +#include <cstdint> + +#include "hal/lv_hal_indev.h" + +#include "haptics.hpp" +#include "input_device.hpp" +#include "input_trigger.hpp" +#include "touchwheel.hpp" + +namespace input { + +class TouchDPad : public IInputDevice { + public: + TouchDPad(drivers::TouchWheel&); + + auto read(lv_indev_data_t* data) -> void override; + + private: + drivers::TouchWheel& wheel_; + + Trigger up_; + Trigger right_; + Trigger down_; + Trigger left_; +}; + +} // namespace input diff --git a/src/input/include/input_touch_wheel.hpp b/src/input/include/input_touch_wheel.hpp new file mode 100644 index 00000000..c81cbb1a --- /dev/null +++ b/src/input/include/input_touch_wheel.hpp @@ -0,0 +1,51 @@ +/* + * Copyright 2024 jacqueline <me@jacqueline.id.au> + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include <sys/_stdint.h> +#include <cstdint> + +#include "hal/lv_hal_indev.h" + +#include "haptics.hpp" +#include "input_device.hpp" +#include "input_trigger.hpp" +#include "nvs.hpp" +#include "property.hpp" +#include "touchwheel.hpp" + +namespace input { + +class TouchWheel : public IInputDevice { + public: + TouchWheel(drivers::NvsStorage&, drivers::TouchWheel&); + + auto read(lv_indev_data_t* data) -> void override; + + auto sensitivity() -> lua::Property&; + + private: + auto calculateTicks(const drivers::TouchWheelData& data) -> int8_t; + auto calculateThreshold(uint8_t sensitivity) -> uint8_t; + + drivers::NvsStorage& nvs_; + drivers::TouchWheel& wheel_; + + lua::Property sensitivity_; + + Trigger up_; + Trigger right_; + Trigger down_; + Trigger left_; + + bool is_scrolling_; + uint8_t threshold_; + bool is_first_read_; + uint8_t last_angle_; +}; + +} // namespace input diff --git a/src/input/include/input_trigger.hpp b/src/input/include/input_trigger.hpp new file mode 100644 index 00000000..599b796b --- /dev/null +++ b/src/input/include/input_trigger.hpp @@ -0,0 +1,37 @@ +/* + * Copyright 2024 jacqueline <me@jacqueline.id.au> + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include <cstdint> +#include <optional> + +#include "hal/lv_hal_indev.h" + +namespace input { + +const uint16_t kLongPressDelayMs = LV_INDEV_DEF_LONG_PRESS_TIME; +const uint16_t kRepeatDelayMs = LV_INDEV_DEF_LONG_PRESS_REP_TIME; + +class Trigger { + public: + enum class State { + kNone, + kClick, + kLongPress, + kRepeatPress, + }; + + Trigger(); + + auto update(bool is_pressed) -> State; + + private: + std::optional<uint64_t> touch_time_ms_; + uint16_t times_fired_; +}; + +} // namespace input diff --git a/src/input/include/input_volume_buttons.hpp b/src/input/include/input_volume_buttons.hpp new file mode 100644 index 00000000..162ca8d9 --- /dev/null +++ b/src/input/include/input_volume_buttons.hpp @@ -0,0 +1,34 @@ +/* + * Copyright 2024 jacqueline <me@jacqueline.id.au> + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include <cstdint> + +#include "gpios.hpp" +#include "hal/lv_hal_indev.h" + +#include "haptics.hpp" +#include "input_device.hpp" +#include "input_trigger.hpp" +#include "touchwheel.hpp" + +namespace input { + +class VolumeButtons : public IInputDevice { + public: + VolumeButtons(drivers::IGpios&); + + auto read(lv_indev_data_t* data) -> void override; + + private: + drivers::IGpios& gpios_; + + Trigger up_; + Trigger down_; +}; + +} // namespace input diff --git a/src/input/include/lvgl_input_driver.hpp b/src/input/include/lvgl_input_driver.hpp new file mode 100644 index 00000000..257ccb28 --- /dev/null +++ b/src/input/include/lvgl_input_driver.hpp @@ -0,0 +1,58 @@ +/* + * Copyright 2023 jacqueline <me@jacqueline.id.au> + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include <cstdint> +#include <deque> +#include <memory> +#include <set> + +#include "core/lv_group.h" +#include "device_factory.hpp" +#include "feedback_device.hpp" +#include "gpios.hpp" +#include "hal/lv_hal_indev.h" + +#include "input_device.hpp" +#include "nvs.hpp" +#include "property.hpp" +#include "touchwheel.hpp" + +namespace input { + +/* + * Implementation of an LVGL input device. This class composes multiple + * IInputDevice and IFeedbackDevice instances together into a single LVGL + * device. + */ +class LvglInputDriver { + public: + LvglInputDriver(drivers::NvsStorage& nvs, DeviceFactory&); + + auto mode() -> lua::Property& { return mode_; } + + auto read(lv_indev_data_t* data) -> void; + auto feedback(uint8_t) -> void; + + auto registration() -> lv_indev_t* { return registration_; } + auto lock(bool l) -> void { is_locked_ = l; } + + private: + drivers::NvsStorage& nvs_; + DeviceFactory& factory_; + + lua::Property mode_; + lv_indev_drv_t driver_; + lv_indev_t* registration_; + + std::vector<std::shared_ptr<IInputDevice>> inputs_; + std::vector<std::shared_ptr<IFeedbackDevice>> feedbacks_; + + bool is_locked_; +}; + +} // namespace input |
