From ade9c47f715f095dfc19465a45a71abe6218865c Mon Sep 17 00:00:00 2001 From: Alessio Caiazza Date: Tue, 7 Dec 2021 21:50:23 +0100 Subject: [PATCH] Implement platform_setBacklightLevel for linux --- openrtx/src/ui/ui.c | 1 + platform/targets/linux/emulator/sdl_engine.c | 13 ++++++++++--- platform/targets/linux/platform.c | 12 +++++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/openrtx/src/ui/ui.c b/openrtx/src/ui/ui.c index 925b9599..9906be61 100644 --- a/openrtx/src/ui/ui.c +++ b/openrtx/src/ui/ui.c @@ -385,6 +385,7 @@ layout_t _ui_calculateLayout() void ui_init() { + last_event_tick = getTick(); redraw_needed = true; layout = _ui_calculateLayout(); layout_ready = true; diff --git a/platform/targets/linux/emulator/sdl_engine.c b/platform/targets/linux/emulator/sdl_engine.c index bee5cf4d..c2ba9b5e 100644 --- a/platform/targets/linux/emulator/sdl_engine.c +++ b/platform/targets/linux/emulator/sdl_engine.c @@ -32,6 +32,8 @@ SDL_Texture *displayTexture; /* Custom SDL Event to request a screenshot */ Uint32 SDL_Screenshot_Event; +/* Custom SDL Event to change backlight */ +Uint32 SDL_Backlight_Event; /* * Mutex protected variables @@ -338,6 +340,11 @@ void sdl_task() screenshot_display(filename); free(ev.user.data1); } + else if (ev.type == SDL_Backlight_Event) + { + set_brightness(*((uint8_t*)ev.user.data1)); + free(ev.user.data1); + } } // we update the window only if there is a something ready to render @@ -353,7 +360,6 @@ void sdl_task() } chan_send(&fb_sync, pixels); - set_brightness(state.settings.brightness); chan_recv(&fb_sync, NULL); SDL_UnlockTexture(displayTexture); @@ -376,8 +382,9 @@ void init_sdl() exit(1); } - // Register an SDL custom event type to handle screenshot requests - SDL_Screenshot_Event = SDL_RegisterEvents(1); + // Register SDL custom events to handle screenshot requests and backlight + SDL_Screenshot_Event = SDL_RegisterEvents(2); + SDL_Backlight_Event = SDL_Screenshot_Event+1; chan_init(&fb_sync); diff --git a/platform/targets/linux/platform.c b/platform/targets/linux/platform.c index a9a9a759..0f3d67dd 100644 --- a/platform/targets/linux/platform.c +++ b/platform/targets/linux/platform.c @@ -22,6 +22,9 @@ #include "emulator.h" #include +/* Custom SDL Event to adjust backlight */ +extern Uint32 SDL_Backlight_Event; + hwInfo_t hwInfo; void platform_init() @@ -51,7 +54,14 @@ void platform_terminate() void platform_setBacklightLevel(uint8_t level) { - (void) level; + SDL_Event e; + SDL_zero(e); + e.type = SDL_Backlight_Event; + e.user.data1 = malloc(sizeof(uint8_t)); + uint8_t *data = (uint8_t *)e.user.data1; + *data = level; + + SDL_PushEvent(&e); } // Simulate a fully charged lithium battery