mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-11 14:37:40 +00:00
Touch: Use calibration matrix.
This commit is contained in:
@@ -111,10 +111,8 @@ void Manager::feed(const Frame& frame) {
|
|||||||
// TODO: Add touch pressure hysteresis?
|
// TODO: Add touch pressure hysteresis?
|
||||||
touch_pressure = (metrics.r < r_touch_threshold);
|
touch_pressure = (metrics.r < r_touch_threshold);
|
||||||
if( touch_pressure ) {
|
if( touch_pressure ) {
|
||||||
const float x = width_pixels * (metrics.x - calib_x_low) / calib_x_range;
|
filter_x.feed(metrics.x * 1024);
|
||||||
filter_x.feed(x);
|
filter_y.feed(metrics.y * 1024);
|
||||||
const float y = height_pixels * (calib_y_high - metrics.y) / calib_y_range;
|
|
||||||
filter_y.feed(y);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
filter_x.reset();
|
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 */
|
} /* namespace touch */
|
||||||
|
@@ -220,21 +220,10 @@ private:
|
|||||||
TouchDetected,
|
TouchDetected,
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr uint32_t width_pixels = 240;
|
|
||||||
static constexpr uint32_t height_pixels = 320;
|
|
||||||
|
|
||||||
static constexpr float r_touch_threshold = 0x1000;
|
static constexpr float r_touch_threshold = 0x1000;
|
||||||
static constexpr size_t touch_count_threshold { 4 };
|
static constexpr size_t touch_count_threshold { 4 };
|
||||||
static constexpr uint32_t touch_stable_bound { 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,
|
// Ensure filter length is equal or less than touch_count_threshold,
|
||||||
// or coordinates from the last touch will be in the initial averages.
|
// or coordinates from the last touch will be in the initial averages.
|
||||||
Filter<touch_count_threshold> filter_x;
|
Filter<touch_count_threshold> filter_x;
|
||||||
@@ -249,12 +238,7 @@ private:
|
|||||||
&& filter_y.stable(touch_stable_bound);
|
&& filter_y.stable(touch_stable_bound);
|
||||||
}
|
}
|
||||||
|
|
||||||
ui::Point filtered_point() const {
|
ui::Point filtered_point() const;
|
||||||
return {
|
|
||||||
static_cast<ui::Coord>(filter_x.value()),
|
|
||||||
static_cast<ui::Coord>(filter_y.value())
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
void touch_started() {
|
void touch_started() {
|
||||||
fire_event(ui::TouchEvent::Type::Start);
|
fire_event(ui::TouchEvent::Type::Start);
|
||||||
|
Reference in New Issue
Block a user