Skip to content

Commit 0f1c90f

Browse files
committed
added Tearing test
1 parent 77b25c1 commit 0f1c90f

File tree

3 files changed

+46
-24
lines changed

3 files changed

+46
-24
lines changed

funkey_prod_screens.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ char *prog_title = "FUNKEY S TESTS";
1717

1818
/* Static Variables */
1919
static s_prod_test prod_tests[] = {
20-
{"FAIL", launch_prod_screen_fail, 0},
21-
{"WAIT_BATTERY", launch_prod_screen_waitbattery, 0},
22-
{"DISPLAY", launch_prod_screen_display, 0},
23-
{"BRIGHTNESS", launch_prod_screen_brightness, 0},
24-
{"BUTTONS", launch_prod_screen_buttons, 0},
25-
{"SPEAKER", launch_prod_screen_speaker, 0},
26-
{"LED", launch_prod_screen_LED, 0},
27-
{"MAGNET", launch_prod_screen_magnet, 0},
28-
{"VALIDATE", launch_prod_screen_validation, 0},
29-
{"SHOW_IMAGE", launch_prod_screen_showImage, 1},
30-
{"GAMMA", launch_prod_screen_gamma, 0},
31-
{"TEARING", launch_prod_screen_tearingtest, 0}
20+
{"FAIL", launch_prod_screen_fail, 0, NULL},
21+
{"WAIT_BATTERY", launch_prod_screen_waitbattery, 0, NULL},
22+
{"DISPLAY", launch_prod_screen_display, 0, NULL},
23+
{"BRIGHTNESS", launch_prod_screen_brightness, 0, NULL},
24+
{"BUTTONS", launch_prod_screen_buttons, 0, NULL},
25+
{"SPEAKER", launch_prod_screen_speaker, 0, NULL},
26+
{"LED", launch_prod_screen_LED, 0, NULL},
27+
{"MAGNET", launch_prod_screen_magnet, 0, NULL},
28+
{"VALIDATE", launch_prod_screen_validation, 0, NULL},
29+
{"SHOW_IMAGE", launch_prod_screen_showImage, 1, "img_path"},
30+
{"GAMMA", launch_prod_screen_gamma, 0, NULL},
31+
{"TEARING", launch_prod_screen_tearingtest, 0, "(FPS)"}
3232
};
3333
static int idx_current_prod_test = 0;
3434

@@ -65,10 +65,11 @@ void init_libraries(){
6565
exit(EXIT_FAILURE);
6666
}
6767

68-
6968
/// Open HW screen and set video mode 240x240
7069
hw_surface = SDL_SetVideoMode(SCREEN_HORIZONTAL_SIZE, SCREEN_VERTICAL_SIZE,
7170
32, SDL_HWSURFACE | SDL_DOUBLEBUF);
71+
/*hw_surface = SDL_SetVideoMode(SCREEN_HORIZONTAL_SIZE, SCREEN_VERTICAL_SIZE,
72+
32, SDL_HWSURFACE);*/
7273
if (hw_surface == NULL)
7374
{
7475
fprintf(stderr, "ERROR SDL_SetVideoMode: %s\n", SDL_GetError());
@@ -95,12 +96,12 @@ void usage(char *progname){
9596
fprintf(stderr, "Usage: %s [prod_test] [optionnal: arg]\n\n", progname);
9697
fprintf(stderr, "\"prod_tests\" in:\n");
9798
for (i = 0; i < sizeof(prod_tests)/sizeof(prod_tests[0]); i++ ){
98-
if(!prod_tests[i].nb_args_needed){
99+
if(prod_tests[i].args_description == NULL){
99100
fprintf(stderr, " %s\n", prod_tests[i].cmd_line_argument);
100101
}
101102
else{
102-
fprintf(stderr, " %s [needs %d additional args]\n",
103-
prod_tests[i].cmd_line_argument, prod_tests[i].nb_args_needed);
103+
fprintf(stderr, " %s %s\n",
104+
prod_tests[i].cmd_line_argument, prod_tests[i].args_description);
104105
}
105106
}
106107
exit(EXIT_FAILURE);
@@ -128,7 +129,7 @@ int main(int argc, char *argv[])
128129
}
129130
}
130131

131-
if(test_found && (prod_tests[i].nb_args_needed+2 != argc) ){
132+
if(test_found && (argc < prod_tests[i].nb_args_needed+2) ){
132133
fprintf(stderr, "ERROR: %s needs %d additional args\n",
133134
prod_tests[idx_current_prod_test].cmd_line_argument,
134135
prod_tests[idx_current_prod_test].nb_args_needed);

funkey_prod_screens.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "prodScreen_validation.h"
1818
#include "prodScreen_showImage.h"
1919
#include "prodScreen_gamma.h"
20+
#include "prodScreen_tearingTest.h"
2021

2122

2223
/// Defines
@@ -37,7 +38,7 @@
3738
#define Y_PADDING 10
3839
#define X_PADDING 20
3940

40-
#define FOLDER_RESSOURCES "/usr/local/sbin/ProdResources"
41+
#define FOLDER_RESSOURCES "/usr/local/share/ProdResources"
4142
#define FONT_NAME_TITLE FOLDER_RESSOURCES"/FreeSansBold.ttf"
4243
#define FONT_SIZE_TITLE 20
4344
#define FONT_NAME_INFO FONT_NAME_TITLE
@@ -48,6 +49,7 @@ typedef struct
4849
char *cmd_line_argument;
4950
int (*ptr_function_launch_test)(int argc, char *argv[]);
5051
int nb_args_needed;
52+
const char *args_description;
5153
} s_prod_test;
5254

5355

prodScreen_tearingTest.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
static int bright = 0;
99

1010
/// -------------- FUNCTIONS IMPLEMENTATION --------------
11-
static int wait_event_loop(){
11+
static int wait_event_loop(uint32_t fps){
1212

1313
SDL_Event event;
1414
int stop_menu_loop = 0;
15-
int prev_ms = 0;
1615
int res = EXIT_FAILURE;
16+
uint32_t prev_ms = SDL_GetTicks();
17+
uint32_t cur_ms = SDL_GetTicks();
1718

1819
/// -------- Main loop ---------
1920
while (!stop_menu_loop)
@@ -53,11 +54,17 @@ static int wait_event_loop(){
5354
current_color.r, current_color.g, current_color.b, 0) );
5455
bright = 1-bright;
5556

56-
/* To investigate but with Buildroot, we need this: */
57+
/* Flip screen */
5758
SDL_Flip(hw_surface);
5859

59-
/* Sleep for some time */
60-
//SDL_Delay(SLEEP_PERIOD_MS);
60+
/* Handle FPS */
61+
if(fps){
62+
cur_ms = SDL_GetTicks();
63+
if(cur_ms-prev_ms < 1000/fps){
64+
SDL_Delay(1000/fps - (cur_ms-prev_ms));
65+
}
66+
prev_ms = SDL_GetTicks();
67+
}
6168
}
6269

6370
return res;
@@ -67,7 +74,19 @@ int launch_prod_screen_tearingtest(int argc, char *argv[]){
6774
SDL_Surface *text_surface = NULL;
6875
SDL_Rect text_pos;
6976

77+
int fps = 0; // non stop
78+
if(argc > 0 && argv[0] != NULL){
79+
fps = atoi(argv[0]);
80+
if(!fps){
81+
printf("Cannot convert %s to int\n", argv[0]);
82+
return EXIT_FAILURE;
83+
}
84+
}
85+
86+
printf("fps = %d, argv[0] = %s\n", fps, argv[0]);
87+
7088
/// Main loop
71-
int res = wait_event_loop();
89+
int res = wait_event_loop(fps);
90+
7291
return res;
7392
}

0 commit comments

Comments
 (0)