-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprodScreen_tearingTest.c
93 lines (78 loc) · 2.46 KB
/
prodScreen_tearingTest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include <SDL/SDL_ttf.h>
//#include <SDL/SDL_image.h>
#include "funkey_prod_screens.h"
static int bright = 0;
FILE *fptr;
/// -------------- FUNCTIONS IMPLEMENTATION --------------
static int wait_event_loop(uint32_t fps){
SDL_Event event;
int stop_menu_loop = 0;
int res = EXIT_FAILURE;
uint32_t prev_ms = SDL_GetTicks();
uint32_t cur_ms = SDL_GetTicks();
/// -------- Main loop ---------
while (!stop_menu_loop)
{
/// -------- Handle Keyboard Events ---------
while (SDL_PollEvent(&event))
switch(event.type)
{
case SDL_QUIT:
stop_menu_loop = 1;
break;
case SDL_KEYDOWN:
switch (event.key.keysym.sym)
{
case SDLK_m:
stop_menu_loop = 1;
res = ERROR_MANUAL_FAIL;
break;
case SDLK_n:
case SDLK_ESCAPE:
stop_menu_loop = 1;
res = 0;
break;
default:
break;
}
}
/* Fill screen random */
SDL_Color current_color = {rand() % 128 + 128*bright,
rand() % 256 + 128*bright,
rand() % 256 + 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;
/* Flip screen */
//system("echo 1 > /sys/class/graphics/fb0/switch_backbuf");
SDL_Flip(hw_surface);
/* 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;
}
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(fps);
return res;
}