fix touch

This commit is contained in:
Adolfo Reyna
2026-01-30 22:52:25 -05:00
parent 30c3c2a066
commit 45cbcc8384
3 changed files with 48 additions and 24 deletions

View File

@@ -308,6 +308,27 @@ int main()
renderer.set_font(&font_5x5_obj);
LowLevelGUI gui = LowLevelGUI(&renderer, font_BMplain_obj);
// Initialize touch screen using abstraction FIRST (before InputManager needs it)
touch = LowLevelTouch::create((TouchType)TOUCH_TYPE_SELECTED, V_WIDTH, V_HEIGHT,
TOUCH_SWAP_XY, TOUCH_INVERT_X, TOUCH_INVERT_Y);
if (touch) {
printf("Touch initialized successfully\n");
// Set up interrupt-driven touch detection
printf("Setting up touch interrupt callback...\n");
touch->set_interrupt_callback(touch_interrupt_handler);
printf("Touch interrupt enabled on INT pin (falling and rising edges)\n");
// Run communication test if available
// Note: Commented out as it may hang on some hardware configurations
printf("\nRunning touch reliability test...\n");
touch->test_communication();
printf("...\n");
} else {
printf("Touch initialization failed or not configured\n");
}
// Initialize game configuration
GameConfig config = {
.touch_debounce_ms = 10,
@@ -317,7 +338,7 @@ int main()
.debug_verbose = false
};
// Create InputManager for processing inputs
// Create InputManager for processing inputs (touch must be initialized first!)
InputManager input_manager(touch, &config);
// Create GameLauncher
@@ -340,27 +361,6 @@ int main()
// Refresh the screen with the launcher menu (async on Core 1)
refresh_screen_async(bit_buffer, display);
printf("Initial screen refresh queued on Core 1\n");
// Initialize touch screen using abstraction
touch = LowLevelTouch::create((TouchType)TOUCH_TYPE_SELECTED, V_WIDTH, V_HEIGHT,
TOUCH_SWAP_XY, TOUCH_INVERT_X, TOUCH_INVERT_Y);
if (touch) {
printf("Touch initialized successfully\n");
// Set up interrupt-driven touch detection
printf("Setting up touch interrupt callback...\n");
touch->set_interrupt_callback(touch_interrupt_handler);
printf("Touch interrupt enabled on INT pin (falling and rising edges)\n");
// Run communication test if available
// Note: Commented out as it may hang on some hardware configurations
printf("\nRunning touch reliability test...\n");
touch->test_communication();
printf("...\n");
} else {
printf("Touch initialization failed or not configured\n");
}
#ifdef BUTTON_KEY0_PIN
// Initialize hardware buttons (e-ink board only)
@@ -434,10 +434,22 @@ int main()
// 2. Process touch input (if no button was pressed)
if (!input.valid) {
input = input_manager.process_touch_input(&last_touch_time);
// if debugging enabled, print touch event
if (input.valid && config.debug_verbose) {
printf("Touch Event: type=%d, x=%d, y=%d, pressure=%d, gesture=0x%02X\n",
input.type, input.x, input.y, input.pressure, input.gesture_code);
}
}
// 3. Process input based on current state
if (input.valid) {
// if debugging enabled, print input event
if (config.debug_verbose) {
printf("Input Event: type=%d, x=%d, y=%d, gesture=0x%02X, button=%d, pressure=%d\n",
input.type, input.x, input.y, input.gesture_code,
input.button_id, input.pressure);
}
if (launcher.is_game_selected()) {
// In game mode - process game input
current_game = launcher.get_selected_game();