Skip to content

Commit cde9d77

Browse files
committed
added simple img reader since fbv seems not to work when launched from bash script
1 parent 00a2864 commit cde9d77

21 files changed

+191
-53
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ prodScreen_buttonsTest.c \
77
prodScreen_speakerTest.c \
88
prodScreen_ledTest.c \
99
prodScreen_magnetTest.c \
10-
prodScreen_validation.c
10+
prodScreen_validation.c \
11+
prodScreen_showImage.c
1112

1213
# Output
1314
EXEC=funkey_prod_screens

funkey_prod_screens.c

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ SDL_Color text_color = {COLOR_TEXT_R, COLOR_TEXT_G, COLOR_TEXT_B};
1616

1717
/* Static Variables */
1818
static s_prod_test prod_tests[] = {
19-
{"FAIL", launch_prod_screen_fail},
20-
{"WAIT_BATTERY", launch_prod_screen_waitbattery},
21-
{"DISPLAY", launch_prod_screen_display},
22-
{"BUTTONS", launch_prod_screen_buttons},
23-
{"SPEAKER", launch_prod_screen_speaker},
24-
{"LED", launch_prod_screen_LED},
25-
{"MAGNET", launch_prod_screen_magnet},
26-
{"VALIDATE", launch_prod_screen_validation}
19+
{"FAIL", launch_prod_screen_fail, 0},
20+
{"WAIT_BATTERY", launch_prod_screen_waitbattery, 0},
21+
{"DISPLAY", launch_prod_screen_display, 0},
22+
{"BUTTONS", launch_prod_screen_buttons, 0},
23+
{"SPEAKER", launch_prod_screen_speaker, 0},
24+
{"LED", launch_prod_screen_LED, 0},
25+
{"MAGNET", launch_prod_screen_magnet, 0},
26+
{"VALIDATE", launch_prod_screen_validation, 0},
27+
{"SHOW_IMAGE", launch_prod_screen_showImage, 1}
2728
};
2829
static int idx_current_prod_test = 0;
2930

@@ -87,48 +88,58 @@ void deinit_libraries(){
8788

8889
void usage(char *progname){
8990
int i;
90-
fprintf(stderr, "Usage: %s [prod_test]\n\n", progname);
91+
fprintf(stderr, "Usage: %s [prod_test] [optionnal: arg]\n\n", progname);
9192
fprintf(stderr, "\"prod_tests\" in:\n");
9293
for (i = 0; i < sizeof(prod_tests)/sizeof(prod_tests[0]); i++ ){
93-
fprintf(stderr, " %s\n", prod_tests[i].cmd_line_argument);
94+
if(!prod_tests[i].nb_args_needed){
95+
fprintf(stderr, " %s\n", prod_tests[i].cmd_line_argument);
96+
}
97+
else{
98+
fprintf(stderr, " %s [needs %d additional args]\n",
99+
prod_tests[i].cmd_line_argument, prod_tests[i].nb_args_needed);
100+
}
94101
}
95102
exit(EXIT_FAILURE);
96103
}
97104

98105

99106
int main(int argc, char *argv[])
100107
{
101-
int optind, i;
108+
int i;
102109
int res = ERROR_MANUAL_FAIL;
103110

104-
if(argc != 2){
111+
if(argc < 2){
105112
usage(argv[0]);
106113
}
107114

108-
for (optind = 1; optind < argc; optind++) {
115+
char * prod_test_str = argv[1];
116+
int test_found = 0;
109117

110-
int test_found = 0;
111-
112-
/* Check argument */
113-
for (i = 0; i < sizeof(prod_tests)/sizeof(prod_tests[0]); i++ ){
114-
if(!strcmp(prod_tests[i].cmd_line_argument, argv[optind])){
115-
test_found = 1;
116-
idx_current_prod_test = i;
117-
break;
118-
}
118+
/* Check argument */
119+
for (i = 0; i < sizeof(prod_tests)/sizeof(prod_tests[0]); i++ ){
120+
if(!strcmp(prod_tests[i].cmd_line_argument, prod_test_str)){
121+
test_found = 1;
122+
idx_current_prod_test = i;
123+
break;
119124
}
125+
}
120126

121-
if(!test_found){
122-
usage(argv[0]);
123-
}
124-
125-
}
127+
if(test_found && (prod_tests[i].nb_args_needed+2 != argc) ){
128+
fprintf(stderr, "ERROR: %s needs %d additional args\n",
129+
prod_tests[idx_current_prod_test].cmd_line_argument,
130+
prod_tests[idx_current_prod_test].nb_args_needed);
131+
exit(EXIT_FAILURE);
132+
}
133+
134+
if(!test_found){
135+
usage(argv[0]);
136+
}
126137

127138
/// Init SDL
128139
init_libraries();
129140

130141
/// Launch Program
131-
res = prod_tests[idx_current_prod_test].ptr_function_launch_test();
142+
res = prod_tests[idx_current_prod_test].ptr_function_launch_test(argc-2, &argv[2]);
132143

133144
/// Deinit SDL
134145
deinit_libraries();

funkey_prod_screens.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <stdio.h>
66
#include <SDL/SDL.h>
77
#include <SDL/SDL_ttf.h>
8-
//#include <SDL/SDL_image.h>
8+
#include <SDL/SDL_image.h>
99
#include "prodScreen_failScreen.h"
1010
#include "prodScreen_waitBattery.h"
1111
#include "prodScreen_displayTest.h"
@@ -14,6 +14,7 @@
1414
#include "prodScreen_ledTest.h"
1515
#include "prodScreen_magnetTest.h"
1616
#include "prodScreen_validation.h"
17+
#include "prodScreen_showImage.h"
1718

1819

1920
/// Defines
@@ -40,10 +41,15 @@
4041
#define FONT_NAME_INFO FONT_NAME_TITLE
4142
#define FONT_SIZE_INFO 18
4243

44+
#define IMG_CONSOLE_LAYOUT FOLDER_RESSOURCES"/funkey_with_buttons.png"
45+
#define IMG_BUTTON_LR_GREEN FOLDER_RESSOURCES"/button_LR_green.png"
46+
#define IMG_BUTTON_NORMAL_GREEN FOLDER_RESSOURCES"/button_round_green.png"
47+
4348
typedef struct
4449
{
4550
char *cmd_line_argument;
46-
int (*ptr_function_launch_test)();
51+
int (*ptr_function_launch_test)(int argc, char *argv[]);
52+
int nb_args_needed;
4753
} s_prod_test;
4854

4955

prodScreen_buttonsTest.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <SDL/SDL_image.h>
21
#include "funkey_prod_screens.h"
32

43

@@ -15,7 +14,7 @@ static int keys_pushed[NB_KEYS] = {0};
1514

1615

1716
/// -------------- FUNCTIONS IMPLEMENTATION --------------
18-
int launch_prod_screen_buttons(){
17+
int launch_prod_screen_buttons(int argc, char *argv[]){
1918

2019
/* Declare Vars */
2120
SDL_Surface *text_surface = NULL;

prodScreen_buttonsTest.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#ifndef __PROD_SCREEN_BUTTONS__
22
#define __PROD_SCREEN_BUTTONS__
33

4-
#define IMG_CONSOLE_LAYOUT FOLDER_RESSOURCES"/funkey_with_buttons.png"
5-
#define IMG_BUTTON_LR_GREEN FOLDER_RESSOURCES"/button_LR_green.png"
6-
#define IMG_BUTTON_NORMAL_GREEN FOLDER_RESSOURCES"/button_round_green.png"
7-
8-
int launch_prod_screen_buttons();
4+
int launch_prod_screen_buttons(int argc, char *argv[]);
95

106
#endif //__PROD_SCREEN_BUTTONS__

prodScreen_displayTest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
/// -------------- FUNCTIONS IMPLEMENTATION --------------
5-
int launch_prod_screen_display(){
5+
int launch_prod_screen_display(int argc, char *argv[]){
66
SDL_Event event;
77
SDL_Surface *text_surface = NULL;
88
SDL_Rect text_pos;

prodScreen_displayTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#ifndef __PROD_SCREEN_DISPLAY__
22
#define __PROD_SCREEN_DISPLAY__
33

4-
int launch_prod_screen_display();
4+
int launch_prod_screen_display(int argc, char *argv[]);
55

66
#endif //__PROD_SCREEN_DISPLAY__

prodScreen_failScreen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static int wait_event_loop(){
4848
return res;
4949
}
5050

51-
int launch_prod_screen_fail(){
51+
int launch_prod_screen_fail(int argc, char *argv[]){
5252
SDL_Surface *text_surface = NULL;
5353
SDL_Rect text_pos;
5454

prodScreen_failScreen.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#ifndef __PROD_SCREEN_FAIL__
22
#define __PROD_SCREEN_FAIL__
33

4-
int launch_prod_screen_fail();
4+
int launch_prod_screen_fail(int argc, char *argv[]);
55

66
#endif //__PROD_SCREEN_FAIL__

prodScreen_ledTest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static int wait_event_loop(){
4747
return res;
4848
}
4949

50-
int launch_prod_screen_LED(){
50+
int launch_prod_screen_LED(int argc, char *argv[]){
5151
SDL_Surface *text_surface = NULL;
5252
SDL_Rect text_pos;
5353

0 commit comments

Comments
 (0)