diff --git a/funkey_prod_screens.c b/funkey_prod_screens.c index aafe6d8..d0893f8 100644 --- a/funkey_prod_screens.c +++ b/funkey_prod_screens.c @@ -17,18 +17,18 @@ char *prog_title = "FUNKEY S TESTS"; /* Static Variables */ static s_prod_test prod_tests[] = { - {"FAIL", launch_prod_screen_fail, 0}, - {"WAIT_BATTERY", launch_prod_screen_waitbattery, 0}, - {"DISPLAY", launch_prod_screen_display, 0}, - {"BRIGHTNESS", launch_prod_screen_brightness, 0}, - {"BUTTONS", launch_prod_screen_buttons, 0}, - {"SPEAKER", launch_prod_screen_speaker, 0}, - {"LED", launch_prod_screen_LED, 0}, - {"MAGNET", launch_prod_screen_magnet, 0}, - {"VALIDATE", launch_prod_screen_validation, 0}, - {"SHOW_IMAGE", launch_prod_screen_showImage, 1}, - {"GAMMA", launch_prod_screen_gamma, 0}, - {"TEARING", launch_prod_screen_tearingtest, 0} + {"FAIL", launch_prod_screen_fail, 0, NULL}, + {"WAIT_BATTERY", launch_prod_screen_waitbattery, 0, NULL}, + {"DISPLAY", launch_prod_screen_display, 0, NULL}, + {"BRIGHTNESS", launch_prod_screen_brightness, 0, NULL}, + {"BUTTONS", launch_prod_screen_buttons, 0, NULL}, + {"SPEAKER", launch_prod_screen_speaker, 0, NULL}, + {"LED", launch_prod_screen_LED, 0, NULL}, + {"MAGNET", launch_prod_screen_magnet, 0, NULL}, + {"VALIDATE", launch_prod_screen_validation, 0, NULL}, + {"SHOW_IMAGE", launch_prod_screen_showImage, 1, "img_path"}, + {"GAMMA", launch_prod_screen_gamma, 0, NULL}, + {"TEARING", launch_prod_screen_tearingtest, 0, "(FPS)"} }; static int idx_current_prod_test = 0; @@ -65,10 +65,11 @@ void init_libraries(){ exit(EXIT_FAILURE); } - /// Open HW screen and set video mode 240x240 hw_surface = SDL_SetVideoMode(SCREEN_HORIZONTAL_SIZE, SCREEN_VERTICAL_SIZE, 32, SDL_HWSURFACE | SDL_DOUBLEBUF); + /*hw_surface = SDL_SetVideoMode(SCREEN_HORIZONTAL_SIZE, SCREEN_VERTICAL_SIZE, + 32, SDL_HWSURFACE);*/ if (hw_surface == NULL) { fprintf(stderr, "ERROR SDL_SetVideoMode: %s\n", SDL_GetError()); @@ -95,12 +96,12 @@ void usage(char *progname){ fprintf(stderr, "Usage: %s [prod_test] [optionnal: arg]\n\n", progname); fprintf(stderr, "\"prod_tests\" in:\n"); for (i = 0; i < sizeof(prod_tests)/sizeof(prod_tests[0]); i++ ){ - if(!prod_tests[i].nb_args_needed){ + if(prod_tests[i].args_description == NULL){ fprintf(stderr, " %s\n", prod_tests[i].cmd_line_argument); } else{ - fprintf(stderr, " %s [needs %d additional args]\n", - prod_tests[i].cmd_line_argument, prod_tests[i].nb_args_needed); + fprintf(stderr, " %s %s\n", + prod_tests[i].cmd_line_argument, prod_tests[i].args_description); } } exit(EXIT_FAILURE); @@ -128,7 +129,7 @@ int main(int argc, char *argv[]) } } - if(test_found && (prod_tests[i].nb_args_needed+2 != argc) ){ + if(test_found && (argc < prod_tests[i].nb_args_needed+2) ){ fprintf(stderr, "ERROR: %s needs %d additional args\n", prod_tests[idx_current_prod_test].cmd_line_argument, prod_tests[idx_current_prod_test].nb_args_needed); diff --git a/funkey_prod_screens.h b/funkey_prod_screens.h index 6ef6772..2113e10 100644 --- a/funkey_prod_screens.h +++ b/funkey_prod_screens.h @@ -17,6 +17,7 @@ #include "prodScreen_validation.h" #include "prodScreen_showImage.h" #include "prodScreen_gamma.h" +#include "prodScreen_tearingTest.h" /// Defines @@ -37,7 +38,7 @@ #define Y_PADDING 10 #define X_PADDING 20 -#define FOLDER_RESSOURCES "/usr/local/sbin/ProdResources" +#define FOLDER_RESSOURCES "/usr/local/share/ProdResources" #define FONT_NAME_TITLE FOLDER_RESSOURCES"/FreeSansBold.ttf" #define FONT_SIZE_TITLE 20 #define FONT_NAME_INFO FONT_NAME_TITLE @@ -48,6 +49,7 @@ typedef struct char *cmd_line_argument; int (*ptr_function_launch_test)(int argc, char *argv[]); int nb_args_needed; + const char *args_description; } s_prod_test; diff --git a/prodScreen_tearingTest.c b/prodScreen_tearingTest.c index 0f1d0b5..6c025ba 100644 --- a/prodScreen_tearingTest.c +++ b/prodScreen_tearingTest.c @@ -8,12 +8,13 @@ static int bright = 0; /// -------------- FUNCTIONS IMPLEMENTATION -------------- -static int wait_event_loop(){ +static int wait_event_loop(uint32_t fps){ SDL_Event event; int stop_menu_loop = 0; - int prev_ms = 0; int res = EXIT_FAILURE; + uint32_t prev_ms = SDL_GetTicks(); + uint32_t cur_ms = SDL_GetTicks(); /// -------- Main loop --------- while (!stop_menu_loop) @@ -53,11 +54,17 @@ static int wait_event_loop(){ current_color.r, current_color.g, current_color.b, 0) ); bright = 1-bright; - /* To investigate but with Buildroot, we need this: */ + /* Flip screen */ SDL_Flip(hw_surface); - /* Sleep for some time */ - //SDL_Delay(SLEEP_PERIOD_MS); + /* Handle FPS */ + if(fps){ + cur_ms = SDL_GetTicks(); + if(cur_ms-prev_ms < 1000/fps){ + SDL_Delay(1000/fps - (cur_ms-prev_ms)); + } + prev_ms = SDL_GetTicks(); + } } return res; @@ -67,7 +74,19 @@ 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){ + printf("Cannot convert %s to int\n", argv[0]); + return EXIT_FAILURE; + } + } + + printf("fps = %d, argv[0] = %s\n", fps, argv[0]); + /// Main loop - int res = wait_event_loop(); + int res = wait_event_loop(fps); + return res; } \ No newline at end of file