summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-08-07 12:09:23 +1000
committerjacqueline <me@jacqueline.id.au>2024-08-07 12:09:23 +1000
commit1ff28233bd6a64fab97c56861477e122e4c3eac6 (patch)
treeb5265a93a0e55043f16cefedbb8f9e43e9d18ff7
parent649cb74f036c392264264d35f98bef1fa4a5a8aa (diff)
downloadtangara-fw-1ff28233bd6a64fab97c56861477e122e4c3eac6.tar.gz
Recalibrate the touchwheel after unlocking
Also power it down whilst we're locked. This saves about half a milliamp.
-rw-r--r--src/drivers/include/drivers/touchwheel.hpp3
-rw-r--r--src/drivers/touchwheel.cpp8
-rw-r--r--src/tangara/input/input_device.hpp5
-rw-r--r--src/tangara/input/input_touch_wheel.cpp9
-rw-r--r--src/tangara/input/input_touch_wheel.hpp7
-rw-r--r--src/tangara/input/lvgl_input_driver.cpp11
-rw-r--r--src/tangara/input/lvgl_input_driver.hpp3
-rw-r--r--src/tangara/system_fsm/idle.cpp2
8 files changed, 40 insertions, 8 deletions
diff --git a/src/drivers/include/drivers/touchwheel.hpp b/src/drivers/include/drivers/touchwheel.hpp
index 60902087..9cd925a6 100644
--- a/src/drivers/include/drivers/touchwheel.hpp
+++ b/src/drivers/include/drivers/touchwheel.hpp
@@ -39,7 +39,8 @@ class TouchWheel {
auto Update() -> void;
auto GetTouchWheelData() const -> TouchWheelData;
- auto PowerDown() -> void;
+ auto Recalibrate() -> void;
+ auto LowPowerMode(bool en) -> void;
private:
TouchWheelData data_;
diff --git a/src/drivers/touchwheel.cpp b/src/drivers/touchwheel.cpp
index 5d55c6f2..402b839d 100644
--- a/src/drivers/touchwheel.cpp
+++ b/src/drivers/touchwheel.cpp
@@ -137,8 +137,12 @@ TouchWheelData TouchWheel::GetTouchWheelData() const {
return data_;
}
-auto TouchWheel::PowerDown() -> void {
- WriteRegister(LOW_POWER, 0);
+auto TouchWheel::Recalibrate() -> void {
+ WriteRegister(CALIBRATE, 1);
+}
+
+auto TouchWheel::LowPowerMode(bool en) -> void {
+ WriteRegister(LOW_POWER, en ? 0 : 1);
}
} // namespace drivers
diff --git a/src/tangara/input/input_device.hpp b/src/tangara/input/input_device.hpp
index da2b31cd..7edded3e 100644
--- a/src/tangara/input/input_device.hpp
+++ b/src/tangara/input/input_device.hpp
@@ -32,6 +32,11 @@ class IInputDevice {
virtual auto triggers() -> std::vector<std::reference_wrapper<TriggerHooks>> {
return {};
}
+
+ /* Called by the LVGL driver when controls are being locked. */
+ virtual auto onLock() -> void {}
+ /* Called by the LVGL driver when controls are being unlocked. */
+ virtual auto onUnlock() -> void {}
};
} // namespace input
diff --git a/src/tangara/input/input_touch_wheel.cpp b/src/tangara/input/input_touch_wheel.cpp
index b961bb02..a5069ae4 100644
--- a/src/tangara/input/input_touch_wheel.cpp
+++ b/src/tangara/input/input_touch_wheel.cpp
@@ -108,6 +108,15 @@ auto TouchWheel::triggers()
return {centre_, up_, right_, down_, left_};
}
+auto TouchWheel::onLock() -> void {
+ wheel_.LowPowerMode(true);
+}
+
+auto TouchWheel::onUnlock() -> void {
+ wheel_.LowPowerMode(false);
+ wheel_.Recalibrate();
+}
+
auto TouchWheel::sensitivity() -> lua::Property& {
return sensitivity_;
}
diff --git a/src/tangara/input/input_touch_wheel.hpp b/src/tangara/input/input_touch_wheel.hpp
index cf86eced..d5cdbbfc 100644
--- a/src/tangara/input/input_touch_wheel.hpp
+++ b/src/tangara/input/input_touch_wheel.hpp
@@ -12,12 +12,12 @@
#include "indev/lv_indev.h"
#include "drivers/haptics.hpp"
+#include "drivers/nvs.hpp"
+#include "drivers/touchwheel.hpp"
#include "input/input_device.hpp"
#include "input/input_hook.hpp"
#include "input/input_trigger.hpp"
#include "lua/property.hpp"
-#include "drivers/nvs.hpp"
-#include "drivers/touchwheel.hpp"
namespace input {
@@ -30,6 +30,9 @@ class TouchWheel : public IInputDevice {
auto name() -> std::string override;
auto triggers() -> std::vector<std::reference_wrapper<TriggerHooks>> override;
+ auto onLock() -> void override;
+ auto onUnlock() -> void override;
+
auto sensitivity() -> lua::Property&;
private:
diff --git a/src/tangara/input/lvgl_input_driver.cpp b/src/tangara/input/lvgl_input_driver.cpp
index 86f9b279..f6beabda 100644
--- a/src/tangara/input/lvgl_input_driver.cpp
+++ b/src/tangara/input/lvgl_input_driver.cpp
@@ -132,6 +132,17 @@ auto LvglInputDriver::feedback(uint8_t event) -> void {
}
}
+auto LvglInputDriver::lock(bool l) -> void {
+ is_locked_ = l;
+ for (auto&& device : inputs_) {
+ if (l) {
+ device->onLock();
+ } else {
+ device->onUnlock();
+ }
+ }
+}
+
LvglInputDriver::LuaTrigger::LuaTrigger(LvglInputDriver& driver,
IInputDevice& dev,
TriggerHooks& trigger)
diff --git a/src/tangara/input/lvgl_input_driver.hpp b/src/tangara/input/lvgl_input_driver.hpp
index ddbdee55..9b62c24d 100644
--- a/src/tangara/input/lvgl_input_driver.hpp
+++ b/src/tangara/input/lvgl_input_driver.hpp
@@ -40,8 +40,7 @@ class LvglInputDriver {
auto setGroup(lv_group_t*) -> void;
auto read(lv_indev_data_t* data) -> void;
auto feedback(uint8_t) -> void;
-
- auto lock(bool l) -> void { is_locked_ = l; }
+ auto lock(bool l) -> void;
auto pushHooks(lua_State* L) -> int;
diff --git a/src/tangara/system_fsm/idle.cpp b/src/tangara/system_fsm/idle.cpp
index e499693d..d233f603 100644
--- a/src/tangara/system_fsm/idle.cpp
+++ b/src/tangara/system_fsm/idle.cpp
@@ -76,7 +76,7 @@ void Idle::react(const internal::IdleTimeout& ev) {
// other state machines, etc.
auto touchwheel = sServices->touchwheel();
if (touchwheel) {
- touchwheel.value()->PowerDown();
+ touchwheel.value()->LowPowerMode(true);
}
auto& gpios = sServices->gpios();