diff options
author | ConfuSomu | 2024-02-14 12:20:01 -0500 |
---|---|---|
committer | ConfuSomu | 2024-02-14 12:20:01 -0500 |
commit | e953d44fb79e77ee300f67d1f18107cd95bbc6dc (patch) | |
tree | d2e5381dfc056c5846b62867e1b98bc2da7bbeb5 | |
parent | 9a74ae13182061a239f308011a3fd3ba8121c015 (diff) | |
download | pico-watch-e953d44fb79e77ee300f67d1f18107cd95bbc6dc.tar pico-watch-e953d44fb79e77ee300f67d1f18107cd95bbc6dc.tar.gz pico-watch-e953d44fb79e77ee300f67d1f18107cd95bbc6dc.zip |
Separate SDL input processing into separate method
-rw-r--r-- | hal/api.cpp | 1 | ||||
-rw-r--r-- | hal/sdl2/display.cpp | 13 | ||||
-rw-r--r-- | hal/sdl2/display.hpp | 1 |
3 files changed, 9 insertions, 6 deletions
diff --git a/hal/api.cpp b/hal/api.cpp index f15c4ec..a983c9b 100644 --- a/hal/api.cpp +++ b/hal/api.cpp @@ -73,6 +73,7 @@ bool Api::display_write_backbuffer() { m_writebb_needed = false; return false; #else + m_sdl_display.process_input(); return m_sdl_display.update_display(m_ucBuffer); #endif } diff --git a/hal/sdl2/display.cpp b/hal/sdl2/display.cpp index ecb6870..64b92cd 100644 --- a/hal/sdl2/display.cpp +++ b/hal/sdl2/display.cpp @@ -1,5 +1,4 @@ #ifdef SDL2_BUILD -#include <SDL.h> #include "display.hpp" #include "../../buttons.hpp" #include <iostream> @@ -11,7 +10,7 @@ SDLDisplay::SDLDisplay() { SDL_Init(SDL_INIT_VIDEO); SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "0"); /* scale here to make the window larger than the surface itself. - Int*eger scalings only as set by function below. */ + Integer scalings only as set by function below. */ m_window = SDL_CreateWindow("SDL2 pico-watch build", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, 0); if (m_window == nullptr) { @@ -31,7 +30,7 @@ SDLDisplay::SDLDisplay() { const int height = SCREEN_HEIGHT; /* Since we are going to display a low resolution buffer, - i t i*s best to limit the window size so that it cannot be + it's best to limit the window size so that it cannot be smaller than our internal buffer size. */ SDL_SetWindowMinimumSize(m_window, width, height); SDL_RenderSetLogicalSize(m_renderer, width, height); @@ -44,9 +43,7 @@ SDLDisplay::SDLDisplay() { SDL_SetPaletteColors(m_surface->format->palette, colors, 0, 2); } -bool SDLDisplay::update_display(const uint8_t* oled_screen) { - if (m_should_quit) return true; - +bool SDLDisplay::process_input() { SDL_Event e; while (SDL_PollEvent(&e) != 0) { switch (e.type) { @@ -61,7 +58,10 @@ bool SDLDisplay::update_display(const uint8_t* oled_screen) { break; } } + return m_should_quit; +} +bool SDLDisplay::update_display(const uint8_t* oled_screen) { // NOTE: hardcoded display size (might be fine, see todo.md and oledWriteDataBlock in ss_oled.c) // memcpy(m_surface->pixels, oled_screen, (size_t)(128*8)); convert_display(oled_screen); @@ -110,6 +110,7 @@ void SDLDisplay::convert_display(const uint8_t* in) { } } +// Get the GPIO pin number corresponding to the button that has been pressed uint SDLDisplay::get_button(SDL_Keycode key) { switch (key) { case SDLK_w: diff --git a/hal/sdl2/display.hpp b/hal/sdl2/display.hpp index 55d82b7..a267cae 100644 --- a/hal/sdl2/display.hpp +++ b/hal/sdl2/display.hpp @@ -9,6 +9,7 @@ public: // bool init_display(); // When returning false, please quit the program (return from main) bool update_display(const uint8_t* oled_screen); + bool process_input(); private: SDL_Window* m_window = nullptr; SDL_Renderer* m_renderer = nullptr; |