Recalibrate the touchwheel after unlocking

Also power it down whilst we're locked. This saves about half a
milliamp.
custom
jacqueline 9 months ago
parent 649cb74f03
commit 1ff28233bd
  1. 3
      src/drivers/include/drivers/touchwheel.hpp
  2. 8
      src/drivers/touchwheel.cpp
  3. 5
      src/tangara/input/input_device.hpp
  4. 9
      src/tangara/input/input_touch_wheel.cpp
  5. 7
      src/tangara/input/input_touch_wheel.hpp
  6. 11
      src/tangara/input/lvgl_input_driver.cpp
  7. 3
      src/tangara/input/lvgl_input_driver.hpp
  8. 2
      src/tangara/system_fsm/idle.cpp

@ -39,7 +39,8 @@ class TouchWheel {
auto Update() -> void; auto Update() -> void;
auto GetTouchWheelData() const -> TouchWheelData; auto GetTouchWheelData() const -> TouchWheelData;
auto PowerDown() -> void; auto Recalibrate() -> void;
auto LowPowerMode(bool en) -> void;
private: private:
TouchWheelData data_; TouchWheelData data_;

@ -137,8 +137,12 @@ TouchWheelData TouchWheel::GetTouchWheelData() const {
return data_; return data_;
} }
auto TouchWheel::PowerDown() -> void { auto TouchWheel::Recalibrate() -> void {
WriteRegister(LOW_POWER, 0); WriteRegister(CALIBRATE, 1);
}
auto TouchWheel::LowPowerMode(bool en) -> void {
WriteRegister(LOW_POWER, en ? 0 : 1);
} }
} // namespace drivers } // namespace drivers

@ -32,6 +32,11 @@ class IInputDevice {
virtual auto triggers() -> std::vector<std::reference_wrapper<TriggerHooks>> { virtual auto triggers() -> std::vector<std::reference_wrapper<TriggerHooks>> {
return {}; 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 } // namespace input

@ -108,6 +108,15 @@ auto TouchWheel::triggers()
return {centre_, up_, right_, down_, left_}; 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& { auto TouchWheel::sensitivity() -> lua::Property& {
return sensitivity_; return sensitivity_;
} }

@ -12,12 +12,12 @@
#include "indev/lv_indev.h" #include "indev/lv_indev.h"
#include "drivers/haptics.hpp" #include "drivers/haptics.hpp"
#include "drivers/nvs.hpp"
#include "drivers/touchwheel.hpp"
#include "input/input_device.hpp" #include "input/input_device.hpp"
#include "input/input_hook.hpp" #include "input/input_hook.hpp"
#include "input/input_trigger.hpp" #include "input/input_trigger.hpp"
#include "lua/property.hpp" #include "lua/property.hpp"
#include "drivers/nvs.hpp"
#include "drivers/touchwheel.hpp"
namespace input { namespace input {
@ -30,6 +30,9 @@ class TouchWheel : public IInputDevice {
auto name() -> std::string override; auto name() -> std::string override;
auto triggers() -> std::vector<std::reference_wrapper<TriggerHooks>> override; auto triggers() -> std::vector<std::reference_wrapper<TriggerHooks>> override;
auto onLock() -> void override;
auto onUnlock() -> void override;
auto sensitivity() -> lua::Property&; auto sensitivity() -> lua::Property&;
private: private:

@ -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, LvglInputDriver::LuaTrigger::LuaTrigger(LvglInputDriver& driver,
IInputDevice& dev, IInputDevice& dev,
TriggerHooks& trigger) TriggerHooks& trigger)

@ -40,8 +40,7 @@ class LvglInputDriver {
auto setGroup(lv_group_t*) -> void; auto setGroup(lv_group_t*) -> void;
auto read(lv_indev_data_t* data) -> void; auto read(lv_indev_data_t* data) -> void;
auto feedback(uint8_t) -> void; auto feedback(uint8_t) -> void;
auto lock(bool l) -> void;
auto lock(bool l) -> void { is_locked_ = l; }
auto pushHooks(lua_State* L) -> int; auto pushHooks(lua_State* L) -> int;

@ -76,7 +76,7 @@ void Idle::react(const internal::IdleTimeout& ev) {
// other state machines, etc. // other state machines, etc.
auto touchwheel = sServices->touchwheel(); auto touchwheel = sServices->touchwheel();
if (touchwheel) { if (touchwheel) {
touchwheel.value()->PowerDown(); touchwheel.value()->LowPowerMode(true);
} }
auto& gpios = sServices->gpios(); auto& gpios = sServices->gpios();

Loading…
Cancel
Save