From ab76d63f46b531871daad4d86059d333ceb80276 Mon Sep 17 00:00:00 2001 From: Vincent Buso Date: Mon, 16 Jan 2023 20:55:28 +0100 Subject: [PATCH] New tests, Cleaned up tests, check screen dimensions before SDL_SetVideoMode --- Makefile | 4 +- funkey_prod_screens.c | 72 +- funkey_prod_screens.h | 5 +- prodScreen_brightnessTest.c | 24 +- prodScreen_buttonsTest.c | 4 +- prodScreen_displayTest.c | 22 +- prodScreen_failScreen.c | 20 +- prodScreen_gamma.c | 4 +- prodScreen_ledTest.c | 18 +- prodScreen_magnetTest.c | 22 +- prodScreen_speakerTest.c | 18 +- prodScreen_tearingTest.c | 10 +- prodScreen_tests.c | 1288 +++++++++++++++++++++++++++++++---- prodScreen_validation.c | 18 +- prodScreen_waitBattery.c | 42 +- 15 files changed, 1324 insertions(+), 247 deletions(-) diff --git a/Makefile b/Makefile index c1c383e..5211380 100644 --- a/Makefile +++ b/Makefile @@ -23,8 +23,10 @@ CC=$(CROSS_COMPILE)gcc # Other options ifeq ($(platform), funkey) CFLAGS += $(shell /opt/FunKey-sdk-2.3.0/arm-funkey-linux-musleabihf/sysroot/usr/bin/sdl-config --cflags) - CFLAGS += -O2 -mfloat-abi=hard -ffast-math -funsafe-math-optimizations -fno-PIC -march=armv7-a+neon-vfpv4 -mtune=cortex-a7 -mfpu=neon-vfpv4 #CFLAGS += -O2 + CFLAGS += -O3 + CFLAGS += -mfloat-abi=hard -ffast-math -funsafe-math-optimizations -fno-PIC -march=armv7-a+neon-vfpv4 -mtune=cortex-a7 -mfpu=neon-vfpv4 + #CFLAGS += -ffreestanding -mfpu=neon -mfloat-abi=hard LIBS += $(shell /opt/FunKey-sdk-2.3.0/arm-funkey-linux-musleabihf/sysroot/usr/bin/sdl-config --libs) else CFLAGS += `sdl-config --cflags` diff --git a/funkey_prod_screens.c b/funkey_prod_screens.c index 88ef9f7..34caed1 100644 --- a/funkey_prod_screens.c +++ b/funkey_prod_screens.c @@ -8,11 +8,6 @@ #include -void intHandler(int dummy) { - deinit_libraries(); - exit(EXIT_FAILURE); -} - /* Global variables */ SDL_Surface *hw_surface = NULL; @@ -21,6 +16,8 @@ TTF_Font *font_info = NULL; SDL_Color bg_color = {COLOR_BG_R, COLOR_BG_G, COLOR_BG_B}; SDL_Color text_color = {COLOR_TEXT_R, COLOR_TEXT_G, COLOR_TEXT_B}; char *prog_title = "FUNKEY S TESTS"; +int display_width = 0; +int display_height = 0; /* Static Variables */ static s_prod_test prod_tests[] = { @@ -42,8 +39,26 @@ static int idx_current_prod_test = 0; /// -------------- FUNCTIONS IMPLEMENTATION -------------- +void deinit_libraries(){ + /// ------ Close font ------- + TTF_CloseFont(font_title); + TTF_CloseFont(font_info); + + /// deinit libs + TTF_Quit(); + SDL_Quit(); +} + +void intHandler(int dummy) { + deinit_libraries(); + exit(EXIT_FAILURE); +} + void init_libraries(){ + /* Vars */ + SDL_Rect **modes; + /* Catch SIGINT and exit */ signal(SIGINT, intHandler); @@ -64,7 +79,7 @@ void init_libraries(){ exit(EXIT_FAILURE); } - /// ----- Loading the fonts ----- + /* Loading the fonts */ font_title = TTF_OpenFont(FONT_NAME_TITLE, FONT_SIZE_TITLE); if(!font_title){ printf("ERROR in init_menu_SDL: Could not open menu font %s, %s\n", FONT_NAME_TITLE, SDL_GetError()); @@ -76,32 +91,49 @@ void init_libraries(){ exit(EXIT_FAILURE); } + /* Get available fullscreen/hardware modes */ + modes=SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_DOUBLEBUF | SDL_HWSURFACE); + + /* Check is there are any modes available */ + if(modes == (SDL_Rect **)0){ + printf("No modes available!\n"); + exit(-1); + } + + /* Check if our resolution is restricted */ + if(modes == (SDL_Rect **)-1){ + printf("All resolutions available.\n"); + } + else{ + /* Print valid modes */ + printf("Available Modes:\n"); + for(int i=0;modes[i];++i){ + printf(" %d x %d\n", modes[i]->w, modes[i]->h); + } + } + + /* Get display dimensions (1st returned mode) */ + display_width = modes[0]->w; + display_height = modes[0]->h; + /// Open HW screen and set video mode 240x240 - hw_surface = SDL_SetVideoMode(SCREEN_HORIZONTAL_SIZE, SCREEN_VERTICAL_SIZE, - 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN); - /*hw_surface = SDL_SetVideoMode(SCREEN_HORIZONTAL_SIZE, SCREEN_VERTICAL_SIZE, - 32, SDL_HWSURFACE);*/ + hw_surface = SDL_SetVideoMode(display_width, display_height, + 16, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN); + /*hw_surface = SDL_SetVideoMode(display_width, display_height, + 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN);*/ if (hw_surface == NULL) { fprintf(stderr, "ERROR SDL_SetVideoMode: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } + + /* Extra */ SDL_ShowCursor(0); char prog_name[50]; sprintf(prog_name, "FunKey_Prod_%s", prod_tests[idx_current_prod_test].cmd_line_argument ); SDL_WM_SetCaption(prog_name, NULL); } -void deinit_libraries(){ - /// ------ Close font ------- - TTF_CloseFont(font_title); - TTF_CloseFont(font_info); - - /// deinit libs - TTF_Quit(); - SDL_Quit(); -} - void usage(char *progname){ int i; fprintf(stderr, "Usage: %s [prod_test] [optionnal: arg]\n\n", progname); diff --git a/funkey_prod_screens.h b/funkey_prod_screens.h index d917146..0e91081 100644 --- a/funkey_prod_screens.h +++ b/funkey_prod_screens.h @@ -26,9 +26,6 @@ /// Defines #define ERROR_MANUAL_FAIL 2 -#define SCREEN_HORIZONTAL_SIZE 240 -#define SCREEN_VERTICAL_SIZE 240 - #define SLEEP_PERIOD_MS 100 #define COLOR_BG_R 255 @@ -63,6 +60,8 @@ extern TTF_Font *font_info; extern SDL_Color bg_color; extern SDL_Color text_color; extern char *prog_title; +extern int display_width; +extern int display_height; #endif //__FUNKEY_PROD_SCREENS__ diff --git a/prodScreen_brightnessTest.c b/prodScreen_brightnessTest.c index c33b21a..235d1a6 100644 --- a/prodScreen_brightnessTest.c +++ b/prodScreen_brightnessTest.c @@ -38,8 +38,8 @@ static int wait_event_loop(){ } } - /* To inverstigate but with Buildroot, we need this: */ - SDL_Flip(hw_surface); + /* To investigate but with Buildroot, we need this: */ + //SDL_Flip(hw_surface); /* Sleep for some time */ SDL_Delay(SLEEP_PERIOD_MS); @@ -57,15 +57,15 @@ int launch_prod_screen_brightness(int argc, char *argv[]){ /* Write Title */ text_surface = TTF_RenderText_Shaded(font_title, prog_title, text_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE/2 - text_surface->w/2; + text_pos.x = display_width/2 - text_surface->w/2; text_pos.y = Y_PADDING; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); /* Write "SPEAKER ok ? */ text_surface = TTF_RenderText_Shaded(font_title, "BRIGHTNESS OK ?", text_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE/2 - text_surface->w/2; - text_pos.y = SCREEN_VERTICAL_SIZE/2 - text_surface->h/2; + text_pos.x = display_width/2 - text_surface->w/2; + text_pos.y = display_height/2 - text_surface->h/2; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); @@ -76,12 +76,12 @@ int launch_prod_screen_brightness(int argc, char *argv[]){ SDL_Color red_color={220,20,20}; text_surface = TTF_RenderText_Shaded(font_info, "Press", red_color, bg_color); text_pos.x = X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - 2*text_surface->h; + text_pos.y = display_height - Y_PADDING - 2*text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); text_surface = TTF_RenderText_Shaded(font_info, "L=FAIL", red_color, bg_color); text_pos.x = X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - text_surface->h; + text_pos.y = display_height - Y_PADDING - text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); @@ -91,18 +91,18 @@ int launch_prod_screen_brightness(int argc, char *argv[]){ */ SDL_Color green_color={20,220,20}; text_surface = TTF_RenderText_Shaded(font_info, "Press", green_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE - text_surface->w - X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - 2*text_surface->h; + text_pos.x = display_width - text_surface->w - X_PADDING; + text_pos.y = display_height - Y_PADDING - 2*text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); text_surface = TTF_RenderText_Shaded(font_info, "R=OK", green_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE - text_surface->w - X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - text_surface->h; + text_pos.x = display_width - text_surface->w - X_PADDING; + text_pos.y = display_height - Y_PADDING - text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); /* Render screen */ - //SDL_Flip(hw_surface); + SDL_Flip(hw_surface); /// int res = wait_event_loop(); diff --git a/prodScreen_buttonsTest.c b/prodScreen_buttonsTest.c index f39f12a..b7cd815 100644 --- a/prodScreen_buttonsTest.c +++ b/prodScreen_buttonsTest.c @@ -64,7 +64,7 @@ int launch_prod_screen_buttons(int argc, char *argv[]){ /* Write Title */ text_surface = TTF_RenderText_Shaded(font_title, prog_title, text_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE/2 - text_surface->w/2; + text_pos.x = display_width/2 - text_surface->w/2; text_pos.y = Y_PADDING; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); @@ -72,7 +72,7 @@ int launch_prod_screen_buttons(int argc, char *argv[]){ /* Write "Screen ok ? */ sprintf(str_title_buttons, "Press all buttons...%ds", time_left); text_surface = TTF_RenderText_Shaded(font_info, str_title_buttons, text_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE/2 - text_surface->w/2; + text_pos.x = display_width/2 - text_surface->w/2; text_pos.y = 2*Y_PADDING + text_surface->h/2; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); diff --git a/prodScreen_displayTest.c b/prodScreen_displayTest.c index 46937ad..e3e9c32 100644 --- a/prodScreen_displayTest.c +++ b/prodScreen_displayTest.c @@ -26,23 +26,23 @@ int launch_prod_screen_display(int argc, char *argv[]){ /* Write Title */ text_surface = TTF_RenderText_Shaded(font_title, prog_title, text_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE/2 - text_surface->w/2; + text_pos.x = display_width/2 - text_surface->w/2; text_pos.y = Y_PADDING; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); /* Write "Screen ok ? */ text_surface = TTF_RenderText_Shaded(font_title, "SCREEN OK ?", text_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE/2 - text_surface->w/2; - text_pos.y = SCREEN_VERTICAL_SIZE/2 - text_surface->h/2 - Y_PADDING; + text_pos.x = display_width/2 - text_surface->w/2; + text_pos.y = display_height/2 - text_surface->h/2 - Y_PADDING; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); /* Write timeout */ sprintf(str_title, "%d", timeout); text_surface = TTF_RenderText_Shaded(font_title, str_title, text_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE/2 - text_surface->w/2; - text_pos.y = SCREEN_VERTICAL_SIZE/2 - text_surface->h/2 + Y_PADDING; + text_pos.x = display_width/2 - text_surface->w/2; + text_pos.y = display_height/2 - text_surface->h/2 + Y_PADDING; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); @@ -53,12 +53,12 @@ int launch_prod_screen_display(int argc, char *argv[]){ SDL_Color red_color={220,20,20}; text_surface = TTF_RenderText_Shaded(font_info, "Press", red_color, bg_color); text_pos.x = X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - 2*text_surface->h; + text_pos.y = display_height - Y_PADDING - 2*text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); text_surface = TTF_RenderText_Shaded(font_info, "L=FAIL", red_color, bg_color); text_pos.x = X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - text_surface->h; + text_pos.y = display_height - Y_PADDING - text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); @@ -68,13 +68,13 @@ int launch_prod_screen_display(int argc, char *argv[]){ */ SDL_Color green_color={20,220,20}; text_surface = TTF_RenderText_Shaded(font_info, "Press", green_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE - text_surface->w - X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - 2*text_surface->h; + text_pos.x = display_width - text_surface->w - X_PADDING; + text_pos.y = display_height - Y_PADDING - 2*text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); text_surface = TTF_RenderText_Shaded(font_info, "R=OK", green_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE - text_surface->w - X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - text_surface->h; + text_pos.x = display_width - text_surface->w - X_PADDING; + text_pos.y = display_height - Y_PADDING - text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); diff --git a/prodScreen_failScreen.c b/prodScreen_failScreen.c index a60d163..00bcfa2 100644 --- a/prodScreen_failScreen.c +++ b/prodScreen_failScreen.c @@ -58,16 +58,16 @@ int launch_prod_screen_fail(int argc, char *argv[]){ /* Write Title */ SDL_Color red={255,0,0}; text_surface = TTF_RenderText_Shaded(font_title, prog_title, red, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE/2 - text_surface->w/2; + text_pos.x = display_width/2 - text_surface->w/2; text_pos.y = Y_PADDING; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); /* Write "Screen ok ? */ text_surface = TTF_RenderText_Shaded(font_title, "FAILED", red, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE/2 - text_surface->w/2; - text_pos.x = SCREEN_HORIZONTAL_SIZE/2 - text_surface->w/2; - text_pos.y = SCREEN_VERTICAL_SIZE/2 - text_surface->h/2; + text_pos.x = display_width/2 - text_surface->w/2; + text_pos.x = display_width/2 - text_surface->w/2; + text_pos.y = display_height/2 - text_surface->h/2; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); @@ -78,12 +78,12 @@ int launch_prod_screen_fail(int argc, char *argv[]){ SDL_Color red_color={220,20,20}; text_surface = TTF_RenderText_Shaded(font_info, "Press", red_color, bg_color); text_pos.x = X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - 2*text_surface->h; + text_pos.y = display_height - Y_PADDING - 2*text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); text_surface = TTF_RenderText_Shaded(font_info, "L=STOP", red_color, bg_color); text_pos.x = X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - text_surface->h; + text_pos.y = display_height - Y_PADDING - text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); @@ -93,13 +93,13 @@ int launch_prod_screen_fail(int argc, char *argv[]){ */ SDL_Color green_color={20,20,220}; text_surface = TTF_RenderText_Shaded(font_info, "Press", green_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE - text_surface->w - X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - 2*text_surface->h; + text_pos.x = display_width - text_surface->w - X_PADDING; + text_pos.y = display_height - Y_PADDING - 2*text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); text_surface = TTF_RenderText_Shaded(font_info, "R=RESTART", green_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE - text_surface->w - X_PADDING/2; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - text_surface->h; + text_pos.x = display_width - text_surface->w - X_PADDING/2; + text_pos.y = display_height - Y_PADDING - text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); diff --git a/prodScreen_gamma.c b/prodScreen_gamma.c index a7dbd79..d5ae390 100644 --- a/prodScreen_gamma.c +++ b/prodScreen_gamma.c @@ -9,8 +9,8 @@ /// -------------- FUNCTIONS IMPLEMENTATION -------------- int launch_prod_screen_gamma(int argc, char *argv[]){ SDL_Event event; - SDL_Surface *text_surface = NULL; - SDL_Rect text_pos; + //SDL_Surface *text_surface = NULL; + //SDL_Rect text_pos; int res = EXIT_FAILURE; int stop_menu_loop = 0; diff --git a/prodScreen_ledTest.c b/prodScreen_ledTest.c index 1192b3f..f61958e 100644 --- a/prodScreen_ledTest.c +++ b/prodScreen_ledTest.c @@ -56,14 +56,14 @@ int launch_prod_screen_LED(int argc, char *argv[]){ /* Write Title */ text_surface = TTF_RenderText_Shaded(font_title, prog_title, text_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE/2 - text_surface->w/2; + text_pos.x = display_width/2 - text_surface->w/2; text_pos.y = Y_PADDING; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); /* Write "LED ok ? */ text_surface = TTF_RenderText_Shaded(font_title, "LED OK ?", text_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE/2 - text_surface->w/2; - text_pos.y = SCREEN_VERTICAL_SIZE/2 - text_surface->h/2; + text_pos.x = display_width/2 - text_surface->w/2; + text_pos.y = display_height/2 - text_surface->h/2; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); @@ -74,12 +74,12 @@ int launch_prod_screen_LED(int argc, char *argv[]){ SDL_Color red_color={220,20,20}; text_surface = TTF_RenderText_Shaded(font_info, "Press", red_color, bg_color); text_pos.x = X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - 2*text_surface->h; + text_pos.y = display_height - Y_PADDING - 2*text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); text_surface = TTF_RenderText_Shaded(font_info, "L=FAIL", red_color, bg_color); text_pos.x = X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - text_surface->h; + text_pos.y = display_height - Y_PADDING - text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); @@ -89,13 +89,13 @@ int launch_prod_screen_LED(int argc, char *argv[]){ */ SDL_Color green_color={20,220,20}; text_surface = TTF_RenderText_Shaded(font_info, "Press", green_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE - text_surface->w - X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - 2*text_surface->h; + text_pos.x = display_width - text_surface->w - X_PADDING; + text_pos.y = display_height - Y_PADDING - 2*text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); text_surface = TTF_RenderText_Shaded(font_info, "R=OK", green_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE - text_surface->w - X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - text_surface->h; + text_pos.x = display_width - text_surface->w - X_PADDING; + text_pos.y = display_height - Y_PADDING - text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); diff --git a/prodScreen_magnetTest.c b/prodScreen_magnetTest.c index 5d3643f..6f4a0d3 100644 --- a/prodScreen_magnetTest.c +++ b/prodScreen_magnetTest.c @@ -89,7 +89,7 @@ int launch_prod_screen_magnet(int argc, char *argv[]){ /* Write Title */ text_surface = TTF_RenderText_Shaded(font_title, prog_title, text_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE/2 - text_surface->w/2; + text_pos.x = display_width/2 - text_surface->w/2; text_pos.y = Y_PADDING; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); @@ -99,14 +99,14 @@ int launch_prod_screen_magnet(int argc, char *argv[]){ (close the console)*/ int y_pad_tmp = 11; text_surface = TTF_RenderText_Shaded(font_title, "MAGNET TEST", text_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE/2 - text_surface->w/2; - text_pos.y = SCREEN_VERTICAL_SIZE/2 - text_surface->h/2 - y_pad_tmp; + text_pos.x = display_width/2 - text_surface->w/2; + text_pos.y = display_height/2 - text_surface->h/2 - y_pad_tmp; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); text_surface = TTF_RenderText_Shaded(font_title, "(close the console)", text_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE/2 - text_surface->w/2; - text_pos.y = SCREEN_VERTICAL_SIZE/2 - text_surface->h/2 + y_pad_tmp; + text_pos.x = display_width/2 - text_surface->w/2; + text_pos.y = display_height/2 - text_surface->h/2 + y_pad_tmp; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); @@ -117,12 +117,12 @@ int launch_prod_screen_magnet(int argc, char *argv[]){ SDL_Color red_color={220,20,20}; text_surface = TTF_RenderText_Shaded(font_info, "Press", red_color, bg_color); text_pos.x = X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - 2*text_surface->h; + text_pos.y = display_height - Y_PADDING - 2*text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); text_surface = TTF_RenderText_Shaded(font_info, "L=FAIL", red_color, bg_color); text_pos.x = X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - text_surface->h; + text_pos.y = display_height - Y_PADDING - text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); @@ -132,13 +132,13 @@ int launch_prod_screen_magnet(int argc, char *argv[]){ */ /*SDL_Color green_color={20,220,20}; text_surface = TTF_RenderText_Shaded(font_info, "Press", green_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE - text_surface->w - X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - 2*text_surface->h; + text_pos.x = display_width - text_surface->w - X_PADDING; + text_pos.y = display_height - Y_PADDING - 2*text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); text_surface = TTF_RenderText_Shaded(font_info, "R=OK", green_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE - text_surface->w - X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - text_surface->h; + text_pos.x = display_width - text_surface->w - X_PADDING; + text_pos.y = display_height - Y_PADDING - text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface);*/ diff --git a/prodScreen_speakerTest.c b/prodScreen_speakerTest.c index c8d4171..ee6829c 100644 --- a/prodScreen_speakerTest.c +++ b/prodScreen_speakerTest.c @@ -57,15 +57,15 @@ int launch_prod_screen_speaker(int argc, char *argv[]){ /* Write Title */ text_surface = TTF_RenderText_Shaded(font_title, prog_title, text_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE/2 - text_surface->w/2; + text_pos.x = display_width/2 - text_surface->w/2; text_pos.y = Y_PADDING; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); /* Write "SPEAKER ok ? */ text_surface = TTF_RenderText_Shaded(font_title, "SPEAKER OK ?", text_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE/2 - text_surface->w/2; - text_pos.y = SCREEN_VERTICAL_SIZE/2 - text_surface->h/2; + text_pos.x = display_width/2 - text_surface->w/2; + text_pos.y = display_height/2 - text_surface->h/2; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); @@ -76,12 +76,12 @@ int launch_prod_screen_speaker(int argc, char *argv[]){ SDL_Color red_color={220,20,20}; text_surface = TTF_RenderText_Shaded(font_info, "Press", red_color, bg_color); text_pos.x = X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - 2*text_surface->h; + text_pos.y = display_height - Y_PADDING - 2*text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); text_surface = TTF_RenderText_Shaded(font_info, "L=FAIL", red_color, bg_color); text_pos.x = X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - text_surface->h; + text_pos.y = display_height - Y_PADDING - text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); @@ -91,13 +91,13 @@ int launch_prod_screen_speaker(int argc, char *argv[]){ */ SDL_Color green_color={20,220,20}; text_surface = TTF_RenderText_Shaded(font_info, "Press", green_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE - text_surface->w - X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - 2*text_surface->h; + text_pos.x = display_width - text_surface->w - X_PADDING; + text_pos.y = display_height - Y_PADDING - 2*text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); text_surface = TTF_RenderText_Shaded(font_info, "R=OK", green_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE - text_surface->w - X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - text_surface->h; + text_pos.x = display_width - text_surface->w - X_PADDING; + text_pos.y = display_height - Y_PADDING - text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); diff --git a/prodScreen_tearingTest.c b/prodScreen_tearingTest.c index c09f1d4..4f35e2a 100644 --- a/prodScreen_tearingTest.c +++ b/prodScreen_tearingTest.c @@ -48,9 +48,9 @@ static int wait_event_loop(uint32_t fps){ } /* Fill screen random */ - SDL_Color current_color = {rand() % 256 + 128*bright, - rand() % 256 + 128*bright, - rand() % 256 + 128*bright}; + SDL_Color current_color = {rand() % 127 + 128*bright, + rand() % 127 + 128*bright, + rand() % 127 + 128*bright}; SDL_FillRect(hw_surface, NULL, SDL_MapRGBA(hw_surface->format, current_color.r, current_color.g, current_color.b, 0) ); bright = 1-bright; @@ -73,10 +73,8 @@ static int wait_event_loop(uint32_t fps){ } int launch_prod_screen_tearingtest(int argc, char *argv[]){ - SDL_Surface *text_surface = NULL; - SDL_Rect text_pos; - int fps = 0; // non stop + if(argc > 0 && argv[0] != NULL){ fps = atoi(argv[0]); if(!fps){ diff --git a/prodScreen_tests.c b/prodScreen_tests.c index ef59b9c..b7a2f3a 100644 --- a/prodScreen_tests.c +++ b/prodScreen_tests.c @@ -1,12 +1,25 @@ #include "funkey_prod_screens.h" #ifdef __ARM_FP - #warning ARM NEON enabled #include +#else + #warning ARM NEON not enabled #endif //__ARM_FP /// Defines #define AT(i, j) ((i) * N + (j)) +#define MAX(x, y) (((x) > (y)) ? (x) : (y)) +#define MIN(x, y) (((x) < (y)) ? (x) : (y)) + +#define CACHE_PAGE_SIZE 32 //Bytes +#define NB_CACHE_PAGES 8 +#define MAX_PRELOAD_DISTANCE (CACHE_PAGE_SIZE*NB_CACHE_PAGES) +//#define MAX_PRELOAD_DISTANCE (CACHE_PAGE_SIZE*10)/4 +//#define MAX_PRELOAD_DISTANCE 640 + +#define PREFETCH_ORDER_X 32 +#define PREFETCH_ORDER_Y 4 +#define PREFETCH_RANGE 1 /// Static variables @@ -75,7 +88,6 @@ Works only on 2D square matrices */ void fbtft_rotate_soft_square_export(uint16_t *src, uint16_t *dst, int size, int rotation) { int i, j; - uint16_t temp; int N = size; if (rotation == 90) { @@ -101,6 +113,74 @@ void fbtft_rotate_soft_square_export(uint16_t *src, uint16_t *dst, int size, int } } + + + + + + +/* Soft Matrix Rotation with only 2 pixel of extra RAM needed +Works only on 320x240 images (w=320, h=240) with 16bpp format */ +/* Very slow */ +#define NB_CHAINS_320x240 2 +void fbtft_rotate_soft_320240(uint16_t *src, int w, int h, int rotation) +{ +#if 1 + uint32_t start_indexes[NB_CHAINS_320x240] = {0, 10}; + uint32_t i, src_idx, dst_idx, x, y; + uint16_t saved_src, saved_dst; + + for (i = 0; iformat, bg_color.r, bg_color.g, bg_color.b, 0) ); @@ -964,6 +1867,8 @@ int launch_prod_screen_tests(int argc, char *argv[]){ //SDL_BlitSurface(image_rgb_16b_transposed_mano, NULL, hw_surface, NULL); /// -------- Main loop --------- + int stop_menu_loop = 0; + SDL_Event event; while (!stop_menu_loop) { /// -------- Handle Keyboard Events --------- @@ -1035,7 +1940,7 @@ int launch_prod_screen_tests(int argc, char *argv[]){ /* Vars */ int h = image_rgb_16b->h, w = image_rgb_16b->w; uint16_t * p = (uint16_t *)image_rgb_16b->pixels; - int y, x; + //int y, x; /* Rotate 90 CW */ SDL_Surface *image_rgb_16b_rotated_90_neon = SDL_CreateRGBSurface(SDL_SWSURFACE, h, w, 16, 0,0,0,0); @@ -1050,7 +1955,8 @@ int launch_prod_screen_tests(int argc, char *argv[]){ /* Rotate 270 CW */ SDL_Surface *image_rgb_16b_rotated_270_neon = SDL_CreateRGBSurface(SDL_SWSURFACE, h, w, 16, 0,0,0,0); uint16_t * p4 = (uint16_t *)image_rgb_16b_rotated_270_neon->pixels; - fbtft_rotate_270cw_neon(p, p4, w, h); + //fbtft_rotate_270cw_neon(p, p4, w, h); + fbtft_rotate_270cw_neon_prefetch6(p, p4, w, h); /* Blit image */ SDL_Surface * imgs_to_blit[] = { @@ -1066,6 +1972,8 @@ int launch_prod_screen_tests(int argc, char *argv[]){ SDL_BlitSurface(imgs_to_blit[cur_idx_blit], NULL, hw_surface, NULL); /// -------- Main loop --------- + int stop_menu_loop = 0; + SDL_Event event; while (!stop_menu_loop) { /// -------- Handle Keyboard Events --------- @@ -1141,7 +2049,7 @@ int launch_prod_screen_tests(int argc, char *argv[]){ //SDL_Rect dst_rect={ (image_rgb_16b->w-w)/2, 0, w, h }; SDL_BlitSurface(image_rgb_16b, NULL, image_rgb_16b_notsquare, NULL); uint16_t * p = (uint16_t *)image_rgb_16b_notsquare->pixels; - int y, x; + //int y, x; /* Rotate 90 CW */ SDL_Surface *image_rgb_16b_rotated_90_neon = SDL_CreateRGBSurface(SDL_SWSURFACE, h, w, 16, 0,0,0,0); @@ -1156,7 +2064,9 @@ int launch_prod_screen_tests(int argc, char *argv[]){ /* Rotate 270 CW */ SDL_Surface *image_rgb_16b_rotated_270_neon = SDL_CreateRGBSurface(SDL_SWSURFACE, h, w, 16, 0,0,0,0); uint16_t * p4 = (uint16_t *)image_rgb_16b_rotated_270_neon->pixels; - fbtft_rotate_270cw_neon(p, p4, w, h); + //fbtft_rotate_270cw_neon(p, p4, w, h); + fbtft_rotate_270cw_neon_prefetch2(p, p4, w, h); + //fbtft_rotate_270cw_neon_prefetch6(p, p4, w, h); -> careful, dimensions must be divisible by 16 /* Transpose */ SDL_Surface *image_rgb_16b_transp_neon = SDL_CreateRGBSurface(SDL_SWSURFACE, h, w, 16, 0,0,0,0); @@ -1164,20 +2074,26 @@ int launch_prod_screen_tests(int argc, char *argv[]){ fbtft_transpose_neon(p, p5, w, h); /* Blit image */ - SDL_Surface * imgs_to_blit[] = { + /*SDL_Surface * imgs_to_blit[] = { image_rgb_16b_notsquare, image_rgb_16b_rotated_270_neon, image_rgb_16b_rotated_90_neon, image_rgb_16b_transp_neon, image_rgb_16b_transp_inv_neon + };*/ + SDL_Surface * imgs_to_blit[] = { + image_rgb_16b_notsquare, + image_rgb_16b_rotated_270_neon, }; int nb_images_to_blit = sizeof(imgs_to_blit)/sizeof(imgs_to_blit[0]); - int cur_idx_blit = 0; + int cur_idx_blit = 1; SDL_BlitSurface(imgs_to_blit[cur_idx_blit], NULL, hw_surface, NULL); /// -------- Main loop --------- + int stop_menu_loop = 0; + SDL_Event event; while (!stop_menu_loop) { /// -------- Handle Keyboard Events --------- @@ -1253,15 +2169,32 @@ SDL_Surface *image_rgb_16b_transposed = SDL_CreateRGBSurface(SDL_SWSURFACE, h, w uint16_t * p2 = (uint16_t *)image_rgb_16b_transposed->pixels; int i; -uint32_t now = SDL_GetTicks(); +uint32_t now = 0, delta_ms = 0; -/* Saved perfs for 10000 iterations: */ -/* Rotate square optimized with memcpy: 2381ms -* Rotate square optimized exported: 9847ms -* Translate soft: 8645ms -* Translate soft a la mano 4x4: 11110ms -* Translate neon: 7800ms +/* Saved perfs on FunKey S for 10000 iterations: */ +/* + -02: + Rotate square optimized with memcpy: 9182ms + Rotate square optimized exported: 10632ms + Translate soft: 5837ms + rotate_soft_270cw_lra: 5817ms + rotate_soft_270cw_lwa: 6370ms + rotate_soft_270cw_hal: 6842ms + Translate soft a la mano 4x4: 8058ms + Transpose neon: 5422ms + rotate_270cw_neon_prefetch2: 5291ms + + -03, -mfloat-abi=hard -ffast-math -funsafe-math-optimizations -fno-PIC -march=armv7-a+neon-vfpv4 -mtune=cortex-a7 -mfpu=neon-vfpv4: + Rotate square optimized with memcpy: 9274ms + Rotate square optimized exported: 10627ms + Translate soft: 5834ms + rotate_soft_270cw_lra: 5842ms + rotate_soft_270cw_lwa: 6473ms + rotate_soft_270cw_hal: 7084ms + Translate soft a la mano 4x4: 6994ms + Transpose neon: 5451ms + rotate_270cw_neon_prefetch2: 5267ms */ @@ -1270,31 +2203,63 @@ uint32_t now = SDL_GetTicks(); printf("\n"); /* Rotate square optimized with memcpy*/ -memcpy((uint8_t*) p2, (uint8_t*) p, h*w*sizeof(uint16_t)); -for (i=0; ih, w = image_rgb_16b->w; uint16_t * p = (uint16_t *)image_rgb_16b->pixels; SDL_Surface *image_rgb_16b_transposed = SDL_CreateRGBSurface(SDL_SWSURFACE, h, w, 16, 0,0,0,0); uint16_t * p2 = (uint16_t *)image_rgb_16b_transposed->pixels; - +uint32_t now = 0, delta_ms = 0; int i; -uint32_t now = SDL_GetTicks(); /* Saved perfs for 10000 iterations: */ -/* Rotate square optimized with memcpy: 2381ms -* Rotate square optimized exported: 9847ms -* Translate soft: 8645ms -* Translate soft a la mano 4x4: 11110ms -* Translate neon: 7800ms +/* Rotate 270 cw neon with prefetch2: 5448ms +* Rotate 270 cw neon: 6347ms +* Rotate 270 cw neon with prefetch: 6347ms */ @@ -1339,20 +2301,23 @@ printf("\n"); #ifdef __ARM_FP -/* Rotate 270 with prefetch neon */ -for (i=0; ipixels; SDL_Surface *image_rgb_16b_transposed = SDL_CreateRGBSurface(SDL_SWSURFACE, h, w, 16, 0,0,0,0); uint16_t * p2 = (uint16_t *)image_rgb_16b_transposed->pixels; int i; -uint32_t now = SDL_GetTicks(); +uint32_t now = 0, delta_ms = 0; -/* Saved perfs for 10000 iterations: */ -/* Rotate square optimized: 10127ms for 320x320 though ! -/* Rotate square optimized with memcpy: 11734ms for 320x320 though ! -* Rotate square optimized exported: 21971ms for 320x320 though ! -* Translate soft: 8634ms -* Translate soft a la mano 4x4: 11097ms -* Translate neon: 7736ms +/* Saved perfs on FunKey S for 10000 iterations: */ +/* +-02: + Rotate square optimized (320x320): 16656ms + Rotate square optimized exported: 10220ms + Translate soft: 8582ms + rotate_soft_270cw_lra: 8589ms + rotate_soft_270cw_lwa: 12537ms + rotate_soft_270cw_hal: 9012ms + Translate soft a la mano 4x4: 11005ms + Rotate 270 neon: 8467ms + Rotate 270 cw neon with prefetch2: 7768ms + +-03, -mfloat-abi=hard -ffast-math -funsafe-math-optimizations -fno-PIC -march=armv7-a+neon-vfpv4 -mtune=cortex-a7 -mfpu=neon-vfpv4: + Rotate square optimized (320x320): 16580ms + Rotate square optimized exported: 9703ms + Translate soft: 8583ms + rotate_soft_270cw_lra: 8611ms + rotate_soft_270cw_lwa: 11461ms + rotate_soft_270cw_hal: 9001ms + Translate soft a la mano 4x4: 9330ms + Rotate 270 neon: 8332ms + Rotate 270 cw neon with prefetch2: 7604ms */ -#define ITERATIONS 10000 +#define ITERATIONS 3000 printf("\n"); /* Rotate square optimized */ -memcpy((uint8_t*) p2, (uint8_t*) p, h*w*sizeof(uint16_t)); -for (i=0; iw/2; + text_pos.x = display_width/2 - text_surface->w/2; text_pos.y = Y_PADDING; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); /* Write "Screen ok ? */ text_surface = TTF_RenderText_Shaded(font_title, "ALL TESTS DONE", text_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE/2 - text_surface->w/2; - text_pos.y = SCREEN_VERTICAL_SIZE/2 - text_surface->h/2; + text_pos.x = display_width/2 - text_surface->w/2; + text_pos.y = display_height/2 - text_surface->h/2; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); @@ -76,12 +76,12 @@ int launch_prod_screen_validation(int argc, char *argv[]){ SDL_Color red_color={220,20,20}; text_surface = TTF_RenderText_Shaded(font_info, "Press", red_color, bg_color); text_pos.x = X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - 2*text_surface->h; + text_pos.y = display_height - Y_PADDING - 2*text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); text_surface = TTF_RenderText_Shaded(font_info, "L=FAIL", red_color, bg_color); text_pos.x = X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - text_surface->h; + text_pos.y = display_height - Y_PADDING - text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); @@ -91,13 +91,13 @@ int launch_prod_screen_validation(int argc, char *argv[]){ */ SDL_Color green_color={20,220,20}; text_surface = TTF_RenderText_Shaded(font_info, "Press", green_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE - text_surface->w - X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - 2*text_surface->h; + text_pos.x = display_width - text_surface->w - X_PADDING; + text_pos.y = display_height - Y_PADDING - 2*text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); text_surface = TTF_RenderText_Shaded(font_info, "R=OK", green_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE - text_surface->w - X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING - text_surface->h; + text_pos.x = display_width - text_surface->w - X_PADDING; + text_pos.y = display_height - Y_PADDING - text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); diff --git a/prodScreen_waitBattery.c b/prodScreen_waitBattery.c index 181226c..da54712 100644 --- a/prodScreen_waitBattery.c +++ b/prodScreen_waitBattery.c @@ -27,9 +27,9 @@ typedef enum{BAT_TESTS} ENUM_BAT_TESTS; /// ----------- STATIC VARS -------------- -#undef X +/*#undef X #define X(a, b) b, -static const char *bat_tests_strings[] = {BAT_TESTS}; +static const char *bat_tests_strings[] = {BAT_TESTS};*/ static int bat_measurements[NB_BAT_MESUREMENTS] = {0}; static int idx_bat_measurements = 0; @@ -64,7 +64,7 @@ static int is_battery_present(){ static int get_battery_voltage(){ char buf[10]; FILE *fp; - int res = 0; + //int res = 0; /* Read battery voltage file */ char *file = BATTERY_VOLTAGE_NOW_FILE; @@ -113,7 +113,7 @@ static void render_static_text(){ /* Write Title */ text_surface = TTF_RenderText_Shaded(font_title, prog_title, text_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE/2 - text_surface->w/2; + text_pos.x = display_width/2 - text_surface->w/2; text_pos.y = Y_PADDING_BAT_RES; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); @@ -122,15 +122,15 @@ static void render_static_text(){ /*SDL_Color dark_gray={20,20,20}; text_surface = TTF_RenderText_Shaded(font_title, "BATTERY TESTS:", dark_gray, bg_color); text_pos.x = X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE/2 - (text_surface->h*(NB_BAT_TESTS+1) + Y_PADDING_BAT_RES*NB_BAT_TESTS)/2; + text_pos.y = display_height/2 - (text_surface->h*(NB_BAT_TESTS+1) + Y_PADDING_BAT_RES*NB_BAT_TESTS)/2; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface);*/ /* Write "Test title*/ /*SDL_Color red={255,0,0}; text_surface = TTF_RenderText_Shaded(font_title, "INSERT BATTERY", red, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE/2 - text_surface->w/2; - text_pos.y = SCREEN_VERTICAL_SIZE/2 - text_surface->h/2; + text_pos.x = display_width/2 - text_surface->w/2; + text_pos.y = display_height/2 - text_surface->h/2; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface);*/ @@ -141,12 +141,12 @@ static void render_static_text(){ SDL_Color red_color={220,20,20}; text_surface = TTF_RenderText_Shaded(font_info, "Press", red_color, bg_color); text_pos.x = X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING_BAT_RES - 2*text_surface->h; + text_pos.y = display_height - Y_PADDING_BAT_RES - 2*text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); text_surface = TTF_RenderText_Shaded(font_info, "L=FAIL", red_color, bg_color); text_pos.x = X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING_BAT_RES - text_surface->h; + text_pos.y = display_height - Y_PADDING_BAT_RES - text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); @@ -156,13 +156,13 @@ static void render_static_text(){ */ /*SDL_Color green_color={20,220,20}; text_surface = TTF_RenderText_Shaded(font_info, "Press", green_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE - text_surface->w - X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING_BAT_RES - 2*text_surface->h; + text_pos.x = display_width - text_surface->w - X_PADDING; + text_pos.y = display_height - Y_PADDING_BAT_RES - 2*text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); text_surface = TTF_RenderText_Shaded(font_info, "R=OK", green_color, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE - text_surface->w - X_PADDING; - text_pos.y = SCREEN_VERTICAL_SIZE - Y_PADDING_BAT_RES - text_surface->h; + text_pos.x = display_width - text_surface->w - X_PADDING; + text_pos.y = display_height - Y_PADDING_BAT_RES - text_surface->h; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface);*/ @@ -239,8 +239,8 @@ static int wait_event_loop(){ /* Show ERROR message */ SDL_Color red={255,0,0}; text_surface = TTF_RenderText_Shaded(font_title, "CONNECT BATTERY", red, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE/2 - text_surface->w/2; - text_pos.y = SCREEN_VERTICAL_SIZE/2 - Y_PADDING - (text_surface->h*(NB_BAT_TESTS) + Y_PADDING_BAT_RES*(NB_BAT_TESTS-1))/2 + text_pos.x = display_width/2 - text_surface->w/2; + text_pos.y = display_height/2 - Y_PADDING - (text_surface->h*(NB_BAT_TESTS) + Y_PADDING_BAT_RES*(NB_BAT_TESTS-1))/2 + (text_surface->h+Y_PADDING_BAT_RES)*cur_bat_test_idx; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); @@ -266,8 +266,8 @@ static int wait_event_loop(){ /* Show ERROR message */ SDL_Color red={255,0,0}; text_surface = TTF_RenderText_Shaded(font_title, "UNPLUG USB", red, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE/2 - text_surface->w/2; - text_pos.y = SCREEN_VERTICAL_SIZE/2 - Y_PADDING - (text_surface->h*(NB_BAT_TESTS) + Y_PADDING_BAT_RES*(NB_BAT_TESTS-1))/2 + text_pos.x = display_width/2 - text_surface->w/2; + text_pos.y = display_height/2 - Y_PADDING - (text_surface->h*(NB_BAT_TESTS) + Y_PADDING_BAT_RES*(NB_BAT_TESTS-1))/2 + (text_surface->h+Y_PADDING_BAT_RES)*cur_bat_test_idx; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); @@ -306,8 +306,8 @@ static int wait_event_loop(){ if(false_measurement_found){ SDL_Color red={255,0,0}; text_surface = TTF_RenderText_Shaded(font_title, "WRONG VOLTAGE", red, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE/2 - text_surface->w/2; - text_pos.y = SCREEN_VERTICAL_SIZE/2 - Y_PADDING - (text_surface->h*(NB_BAT_TESTS) + Y_PADDING_BAT_RES*(NB_BAT_TESTS-1))/2 + text_pos.x = display_width/2 - text_surface->w/2; + text_pos.y = display_height/2 - Y_PADDING - (text_surface->h*(NB_BAT_TESTS) + Y_PADDING_BAT_RES*(NB_BAT_TESTS-1))/2 + (text_surface->h+Y_PADDING_BAT_RES)*cur_bat_test_idx; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface); @@ -326,8 +326,8 @@ static int wait_event_loop(){ char text_tmp[40]; sprintf(text_tmp, "Check voltage (%d/%d)...", idx_bat_measurements, NB_BAT_MESUREMENTS); text_surface = TTF_RenderText_Shaded(font_info, text_tmp, dark_gray, bg_color); - text_pos.x = SCREEN_HORIZONTAL_SIZE/2 - text_surface->w/2; - text_pos.y = SCREEN_VERTICAL_SIZE/2 - Y_PADDING - (text_surface->h*(NB_BAT_TESTS) + Y_PADDING_BAT_RES*(NB_BAT_TESTS-1))/2 + text_pos.x = display_width/2 - text_surface->w/2; + text_pos.y = display_height/2 - Y_PADDING - (text_surface->h*(NB_BAT_TESTS) + Y_PADDING_BAT_RES*(NB_BAT_TESTS-1))/2 + (text_surface->h+Y_PADDING_BAT_RES)*cur_bat_test_idx; SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); SDL_FreeSurface(text_surface);