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 GetTouchWheelData() const -> TouchWheelData;
auto PowerDown() -> void;
auto Recalibrate() -> void;
auto LowPowerMode(bool en) -> void;
private:
TouchWheelData data_;

@ -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

@ -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

@ -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_;
}

@ -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:

@ -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)

@ -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;

@ -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();

Loading…
Cancel
Save