Skip to content

Commit

Permalink
Simulator: use SDL_GetTicks64()
Browse files Browse the repository at this point in the history
  • Loading branch information
KlausMu committed Dec 14, 2024
1 parent b61a00d commit 206e76f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 22 deletions.
7 changes: 3 additions & 4 deletions Platformio/hardware/windows_linux/keypad_gui/keypad_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "../util_hal_windows_linux.h"

#include "key_map.h"

Expand All @@ -19,7 +18,7 @@ uint32_t KEY_HOLD_TIME = 500; // Keys are considered held after 500 ms
// The state to track a single key since the GUI is mouse based
ActiveKey activeKey = {' ', 0, GUI_KEY_IDLE};
guiKeyStates lastGUIKeyState = GUI_KEY_IDLE;
long long holdTimer;
Uint64 holdTimer;

// https://wrfranklin.org/Research/Short_Notes/pnpoly.html
int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy)
Expand Down Expand Up @@ -81,7 +80,7 @@ int event_filter(void *userdata, SDL_Event * event) {
activeKey.key = key.key;
activeKey.state = event->type == SDL_MOUSEBUTTONDOWN ? GUI_KEY_PRESSED : GUI_KEY_RELEASED;
activeKey.keyCode = key.id;
holdTimer = SDL_MOUSEBUTTONDOWN ? current_timestamp_hal_windowsLinux() : 0;
holdTimer = SDL_MOUSEBUTTONDOWN ? SDL_GetTicks64() : 0;
break;
}
}
Expand Down Expand Up @@ -168,7 +167,7 @@ KeyState pumpKeys() {
lastGUIKeyState = activeKey.state;

// If the key has been pressed long enough to be considered held, change the state
if (activeKey.state == GUI_KEY_PRESSED && (current_timestamp_hal_windowsLinux() - holdTimer) > KEY_HOLD_TIME) {
if (activeKey.state == GUI_KEY_PRESSED && (SDL_GetTicks64() - holdTimer) > KEY_HOLD_TIME) {
activeKey.state = GUI_KEY_HOLD;
}

Expand Down
12 changes: 5 additions & 7 deletions Platformio/hardware/windows_linux/lvgl_hal_windows_linux.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include <stdlib.h>
#include <sys/time.h>
#include <lvgl.h>
#include <SDL2/SDL_thread.h>
#include "sdl/sdl.h"
#include "SDL2/SDL_events.h"

#include "util_hal_windows_linux.h"
#include "keypad_gui/keypad_gui.h"

/**
Expand All @@ -14,16 +14,14 @@
*/
static int tick_thread(void * data)
{
(void)data;

long long lastTimestamp = current_timestamp_hal_windowsLinux();
long long newTimestamp = 0;
Uint64 lastTimestamp = SDL_GetTicks64();
Uint64 newTimestamp = 0;
while(1) {
// we don't use this blackbox
// SDL_Delay(5); /*Sleep for 5 millisecond*/
// lv_tick_inc(5); /*Tell lvgl that 5 milliseconds were elapsed*/
newTimestamp = current_timestamp_hal_windowsLinux();

newTimestamp = SDL_GetTicks64();
if ((newTimestamp - lastTimestamp) > 5) {
lv_tick_inc(newTimestamp - lastTimestamp);
lastTimestamp = newTimestamp;
Expand Down
10 changes: 0 additions & 10 deletions Platformio/hardware/windows_linux/util_hal_windows_linux.cpp

This file was deleted.

1 change: 0 additions & 1 deletion Platformio/hardware/windows_linux/util_hal_windows_linux.h

This file was deleted.

0 comments on commit 206e76f

Please sign in to comment.