From 0f9cd318c7833bfb621dd2641feed5a4792e3d86 Mon Sep 17 00:00:00 2001 From: Denis Date: Sun, 19 Nov 2023 23:32:58 +0100 Subject: [PATCH] debugging... --- logic.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/logic.c b/logic.c index a4a32e2..264c049 100644 --- a/logic.c +++ b/logic.c @@ -69,18 +69,23 @@ int logic_copy_gamepad_status(logic_t *const logic, gamepad_status_t *const out) if (logic->gamepad.flags & GAMEPAD_STATUS_FLAGS_PRESS_AND_REALEASE_CENTER) { static struct timeval press_time; + struct timeval now; + gettimeofday(&now, NULL); + + // Calculate elapsed time in milliseconds + int64_t elapsed_time = (now.tv_sec - press_time.tv_sec) * 1000 + + (now.tv_usec - press_time.tv_usec) / 1000; + if (out->center) { - struct timeval now; - gettimeofday(&now, NULL); - - int64_t elapsed_time = (now.tv_sec - press_time.tv_sec) * 1000 + (now.tv_usec - press_time.tv_usec) / 1000; - + // If the center button is pressed and at least 500ms have passed if (elapsed_time >= 500) { + printf("Releasing center button\n"); out->center = 0; logic->gamepad.flags &= ~GAMEPAD_STATUS_FLAGS_PRESS_AND_REALEASE_CENTER; } } else { - printf("Pressing center button"); + // If the center button is pressed + printf("Pressing center button\n"); out->center = 1; gettimeofday(&press_time, NULL); }