diff --git a/firmware/application/touch.cpp b/firmware/application/touch.cpp index b9a8b8cb..07c558bf 100644 --- a/firmware/application/touch.cpp +++ b/firmware/application/touch.cpp @@ -111,10 +111,8 @@ void Manager::feed(const Frame& frame) { // TODO: Add touch pressure hysteresis? touch_pressure = (metrics.r < r_touch_threshold); if( touch_pressure ) { - const float x = width_pixels * (metrics.x - calib_x_low) / calib_x_range; - filter_x.feed(x); - const float y = height_pixels * (calib_y_high - metrics.y) / calib_y_range; - filter_y.feed(y); + filter_x.feed(metrics.x * 1024); + filter_y.feed(metrics.y * 1024); } } else { filter_x.reset(); @@ -146,4 +144,8 @@ void Manager::feed(const Frame& frame) { } } +ui::Point Manager::filtered_point() const { + return calibration().translate({ filter_x.value(), filter_y.value() }); +} + } /* namespace touch */ diff --git a/firmware/application/touch.hpp b/firmware/application/touch.hpp index cf7ea62b..d1e6eaee 100644 --- a/firmware/application/touch.hpp +++ b/firmware/application/touch.hpp @@ -220,21 +220,10 @@ private: TouchDetected, }; - static constexpr uint32_t width_pixels = 240; - static constexpr uint32_t height_pixels = 320; - static constexpr float r_touch_threshold = 0x1000; static constexpr size_t touch_count_threshold { 4 }; static constexpr uint32_t touch_stable_bound { 4 }; - static constexpr float calib_x_low = 0.07f; - static constexpr float calib_x_high = 0.94f; - static constexpr float calib_x_range = calib_x_high - calib_x_low; - - static constexpr float calib_y_low = 0.04f; - static constexpr float calib_y_high = 0.91f; - static constexpr float calib_y_range = calib_y_high - calib_y_low; - // Ensure filter length is equal or less than touch_count_threshold, // or coordinates from the last touch will be in the initial averages. Filter filter_x; @@ -249,12 +238,7 @@ private: && filter_y.stable(touch_stable_bound); } - ui::Point filtered_point() const { - return { - static_cast(filter_x.value()), - static_cast(filter_y.value()) - }; - } + ui::Point filtered_point() const; void touch_started() { fire_event(ui::TouchEvent::Type::Start);