diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..803c950 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +funkey_prod_screens \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..63bdcce --- /dev/null +++ b/Makefile @@ -0,0 +1,29 @@ +# Files +S_FILES=funkey_prod_screens.c \ +prodScreen_failScreen.c \ +prodScreen_waitBattery.c \ +prodScreen_displayTest.c \ +prodScreen_buttonsTest.c \ +prodScreen_speakerTest.c \ +prodScreen_ledTest.c \ +prodScreen_magnetTest.c \ +prodScreen_validation.c + +# Output +EXEC=funkey_prod_screens + +# Build settings +CC=gcc +# SDL options +CC_SDL=-lSDL -lSDL_image -lSDL_ttf `sdl-config --cflags --libs` +# Other options +CFLAGS=-O3 -std=c99 -Wall + + +all:Build + +Build: + $(CC) $(S_FILES) -o $(EXEC) $(CC_SDL) $(CFLAGS) + +clean: + rm $(EXEC) \ No newline at end of file diff --git a/ProdResources/FreeSansBold.ttf b/ProdResources/FreeSansBold.ttf new file mode 100644 index 0000000..63644e7 Binary files /dev/null and b/ProdResources/FreeSansBold.ttf differ diff --git a/ProdResources/Jaapokki-Regular.otf b/ProdResources/Jaapokki-Regular.otf new file mode 100644 index 0000000..9ea7554 Binary files /dev/null and b/ProdResources/Jaapokki-Regular.otf differ diff --git a/ProdResources/OpenSans-Bold.ttf b/ProdResources/OpenSans-Bold.ttf new file mode 100644 index 0000000..fd79d43 Binary files /dev/null and b/ProdResources/OpenSans-Bold.ttf differ diff --git a/ProdResources/OpenSans-BoldItalic.ttf b/ProdResources/OpenSans-BoldItalic.ttf new file mode 100644 index 0000000..9bc8009 Binary files /dev/null and b/ProdResources/OpenSans-BoldItalic.ttf differ diff --git a/ProdResources/OpenSans-ExtraBold.ttf b/ProdResources/OpenSans-ExtraBold.ttf new file mode 100644 index 0000000..21f6f84 Binary files /dev/null and b/ProdResources/OpenSans-ExtraBold.ttf differ diff --git a/ProdResources/OpenSans-ExtraBoldItalic.ttf b/ProdResources/OpenSans-ExtraBoldItalic.ttf new file mode 100644 index 0000000..31cb688 Binary files /dev/null and b/ProdResources/OpenSans-ExtraBoldItalic.ttf differ diff --git a/ProdResources/OpenSans-Italic.ttf b/ProdResources/OpenSans-Italic.ttf new file mode 100644 index 0000000..c90da48 Binary files /dev/null and b/ProdResources/OpenSans-Italic.ttf differ diff --git a/ProdResources/OpenSans-Light.ttf b/ProdResources/OpenSans-Light.ttf new file mode 100644 index 0000000..0d38189 Binary files /dev/null and b/ProdResources/OpenSans-Light.ttf differ diff --git a/ProdResources/OpenSans-LightItalic.ttf b/ProdResources/OpenSans-LightItalic.ttf new file mode 100644 index 0000000..68299c4 Binary files /dev/null and b/ProdResources/OpenSans-LightItalic.ttf differ diff --git a/ProdResources/OpenSans-Regular.ttf b/ProdResources/OpenSans-Regular.ttf new file mode 100644 index 0000000..db43334 Binary files /dev/null and b/ProdResources/OpenSans-Regular.ttf differ diff --git a/ProdResources/OpenSans-Semibold.ttf b/ProdResources/OpenSans-Semibold.ttf new file mode 100644 index 0000000..1a7679e Binary files /dev/null and b/ProdResources/OpenSans-Semibold.ttf differ diff --git a/ProdResources/OpenSans-SemiboldItalic.ttf b/ProdResources/OpenSans-SemiboldItalic.ttf new file mode 100644 index 0000000..59b6d16 Binary files /dev/null and b/ProdResources/OpenSans-SemiboldItalic.ttf differ diff --git a/ProdResources/arial.ttf b/ProdResources/arial.ttf new file mode 100644 index 0000000..886789b Binary files /dev/null and b/ProdResources/arial.ttf differ diff --git a/ProdResources/button_LR_green.png b/ProdResources/button_LR_green.png new file mode 100644 index 0000000..f80b2fe Binary files /dev/null and b/ProdResources/button_LR_green.png differ diff --git a/ProdResources/button_round_green.png b/ProdResources/button_round_green.png new file mode 100644 index 0000000..ddc55de Binary files /dev/null and b/ProdResources/button_round_green.png differ diff --git a/ProdResources/courbd.ttf b/ProdResources/courbd.ttf new file mode 100644 index 0000000..a4f26b4 Binary files /dev/null and b/ProdResources/courbd.ttf differ diff --git a/ProdResources/funkey_with_buttons.png b/ProdResources/funkey_with_buttons.png new file mode 100644 index 0000000..b0c5e6a Binary files /dev/null and b/ProdResources/funkey_with_buttons.png differ diff --git a/ProdResources/joystixmonospace.ttf b/ProdResources/joystixmonospace.ttf new file mode 100644 index 0000000..5fd36a5 Binary files /dev/null and b/ProdResources/joystixmonospace.ttf differ diff --git a/ProdResources/manaspc.ttf b/ProdResources/manaspc.ttf new file mode 100644 index 0000000..0c56733 Binary files /dev/null and b/ProdResources/manaspc.ttf differ diff --git a/ProdResources/prstart.ttf b/ProdResources/prstart.ttf new file mode 100644 index 0000000..40ca6b6 Binary files /dev/null and b/ProdResources/prstart.ttf differ diff --git a/funkey_prod_screens.c b/funkey_prod_screens.c new file mode 100644 index 0000000..0cdd6a8 --- /dev/null +++ b/funkey_prod_screens.c @@ -0,0 +1,137 @@ + +#include +#include +#include +#include +//#include +#include "funkey_prod_screens.h" + + +/* Global variables */ +SDL_Surface *hw_surface = NULL; +TTF_Font *font_title = NULL; +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}; + +/* Static Variables */ +static s_prod_test prod_tests[] = { + {"FAIL", launch_prod_screen_fail}, + {"WAIT_BATTERY", launch_prod_screen_waitbattery}, + {"DISPLAY", launch_prod_screen_display}, + {"BUTTONS", launch_prod_screen_buttons}, + {"SPEAKER", launch_prod_screen_speaker}, + {"LED", launch_prod_screen_LED}, + {"MAGNET", launch_prod_screen_magnet}, + {"VALIDATE", launch_prod_screen_validation} +}; +static int idx_current_prod_test = 0; + + +/// -------------- FUNCTIONS IMPLEMENTATION -------------- +void init_libraries(){ + + /* export SDL_NOMOUSE=1 */ + putenv(strdup("SDL_NOMOUSE=1")); + + /// Init SDL Video + if (SDL_Init(SDL_INIT_VIDEO)) + { + fprintf(stderr, "ERROR init SDL: %s\n", SDL_GetError()); + exit(EXIT_FAILURE); + } + + /// Init fonts library + if(TTF_Init()) + { + fprintf(stderr, "Error TTF_Init: %s\n", TTF_GetError()); + exit(EXIT_FAILURE); + } + + /// ----- 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()); + exit(EXIT_FAILURE); + } + font_info = TTF_OpenFont(FONT_NAME_INFO, FONT_SIZE_INFO); + if(!font_info){ + printf("ERROR in init_menu_SDL: Could not open menu font %s, %s\n", FONT_NAME_INFO, SDL_GetError()); + exit(EXIT_FAILURE); + } + + + /// Open HW screen and set video mode 240x240 + hw_surface = SDL_SetVideoMode(SCREEN_HORIZONTAL_SIZE, SCREEN_VERTICAL_SIZE, + 16, SDL_HWSURFACE | SDL_DOUBLEBUF); + if (hw_surface == NULL) + { + fprintf(stderr, "ERROR SDL_SetVideoMode: %s\n", SDL_GetError()); + exit(EXIT_FAILURE); + } + 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]\n\n", progname); + fprintf(stderr, "\"prod_tests\" in:\n"); + for (i = 0; i < sizeof(prod_tests)/sizeof(prod_tests[0]); i++ ){ + fprintf(stderr, " %s\n", prod_tests[i].cmd_line_argument); + } + exit(EXIT_FAILURE); +} + + +int main(int argc, char *argv[]) +{ + int optind, i; + int res = ERROR_MANUAL_FAIL; + + if(argc != 2){ + usage(argv[0]); + } + + for (optind = 1; optind < argc; optind++) { + + int test_found = 0; + + /* Check argument */ + for (i = 0; i < sizeof(prod_tests)/sizeof(prod_tests[0]); i++ ){ + if(!strcmp(prod_tests[i].cmd_line_argument, argv[optind])){ + test_found = 1; + idx_current_prod_test = i; + break; + } + } + + if(!test_found){ + usage(argv[0]); + } + + } + + /// Init SDL + init_libraries(); + + /// Launch Program + res = prod_tests[idx_current_prod_test].ptr_function_launch_test(); + + /// Deinit SDL + deinit_libraries(); + + return res; +} diff --git a/funkey_prod_screens.h b/funkey_prod_screens.h new file mode 100644 index 0000000..7767a6d --- /dev/null +++ b/funkey_prod_screens.h @@ -0,0 +1,57 @@ +#ifndef __FUNKEY_PROD_SCREENS__ +#define __FUNKEY_PROD_SCREENS__ + +#include +#include +#include +#include +//#include +#include "prodScreen_failScreen.h" +#include "prodScreen_waitBattery.h" +#include "prodScreen_displayTest.h" +#include "prodScreen_buttonsTest.h" +#include "prodScreen_speakerTest.h" +#include "prodScreen_ledTest.h" +#include "prodScreen_magnetTest.h" +#include "prodScreen_validation.h" + + +/// 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 +#define COLOR_BG_G 255 +#define COLOR_BG_B 255 +#define COLOR_TEXT_R 130 +#define COLOR_TEXT_G 30 +#define COLOR_TEXT_B 160 + +#define Y_PADDING 10 +#define X_PADDING 20 + +#define FONT_NAME_TITLE "ProdResources/FreeSansBold.ttf" +#define FONT_SIZE_TITLE 20 +#define FONT_NAME_INFO FONT_NAME_TITLE +#define FONT_SIZE_INFO 18 + +typedef struct +{ + char *cmd_line_argument; + int (*ptr_function_launch_test)(); +} s_prod_test; + + +/// Global variables +extern SDL_Surface *hw_surface; +extern TTF_Font *font_title; +extern TTF_Font *font_info; +extern SDL_Color bg_color; +extern SDL_Color text_color; + + +#endif //__FUNKEY_PROD_SCREENS__ \ No newline at end of file diff --git a/prodScreen_buttonsTest.c b/prodScreen_buttonsTest.c new file mode 100644 index 0000000..c9b44b7 --- /dev/null +++ b/prodScreen_buttonsTest.c @@ -0,0 +1,204 @@ +#include +#include "funkey_prod_screens.h" + + +/// Defines +#define TIMEOUT_FAIL 121 // in seconds +#define NB_KEYS 13 + +/// Static variables +static SDL_Surface *img_console_layout; +static SDL_Surface *img_button_LR_green; +static SDL_Surface *img_button_normal_green; +static int keys[NB_KEYS] = {SDLK_m, SDLK_n, SDLK_l, SDLK_u, SDLK_r, SDLK_d, SDLK_b, SDLK_y, SDLK_x, SDLK_a, SDLK_s, SDLK_f, SDLK_q}; +static int keys_pushed[NB_KEYS] = {0}; + + +/// -------------- FUNCTIONS IMPLEMENTATION -------------- +int launch_prod_screen_buttons(){ + + /* Declare Vars */ + SDL_Surface *text_surface = NULL; + SDL_Rect text_pos; + SDL_Event event; + int stop_menu_loop = 0; + int res = 2; // 2=FAIL + int render = 0; + int timeout = TIMEOUT_FAIL; + int prev_ms = 0; + int i; + char str_title_buttons[50]; + int nb_keys_pushed = 0; + + /* Load images */ + img_console_layout = IMG_Load(IMG_CONSOLE_LAYOUT); + if(!img_console_layout) { + printf("Error IMG_Load: %s\n", IMG_GetError()); + exit(EXIT_FAILURE); + } + img_button_LR_green = IMG_Load(IMG_BUTTON_LR_GREEN); + if(!img_button_LR_green) { + printf("Error IMG_Load: %s\n", IMG_GetError()); + exit(EXIT_FAILURE); + } + img_button_normal_green = IMG_Load(IMG_BUTTON_NORMAL_GREEN); + if(!img_button_normal_green) { + printf("Error IMG_Load: %s\n", IMG_GetError()); + exit(EXIT_FAILURE); + } + + /* Main loop */ + while (!stop_menu_loop && timeout) + { + if(SDL_GetTicks() - prev_ms > 1000){ + + /* Update time*/ + prev_ms = SDL_GetTicks(); + timeout--; + + /* Fill screen white */ + SDL_FillRect(hw_surface, NULL, SDL_MapRGB(hw_surface->format, bg_color.r, bg_color.g, bg_color.b)); + + /* Background image */ + SDL_BlitSurface(img_console_layout, NULL, hw_surface, NULL); + + /* Write Title */ + text_surface = TTF_RenderText_Shaded(font_title, "FunKey PCBA Tests", text_color, bg_color); + text_pos.x = SCREEN_HORIZONTAL_SIZE/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 ? */ + sprintf(str_title_buttons, "Press all buttons...%ds", timeout); + 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.y = 2*Y_PADDING + text_surface->h/2; + SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); + SDL_FreeSurface(text_surface); + + + /* Write key SDLK_m*/ + if(keys_pushed[0]){ + SDL_Rect rect_tmp = {13, 68, img_button_LR_green->w, img_button_LR_green->h}; + SDL_BlitSurface(img_button_LR_green, NULL, hw_surface, &rect_tmp); + } + /* Write key SDLK_n*/ + if(keys_pushed[1]){ + SDL_Rect rect_tmp = {207, 68, img_button_LR_green->w, img_button_LR_green->h}; + SDL_BlitSurface(img_button_LR_green, NULL, hw_surface, &rect_tmp); + } + + /* Write key SDLK_l*/ + if(keys_pushed[2]){ + SDL_Rect rect_tmp = {21, 145, img_button_normal_green->w, img_button_normal_green->h}; + SDL_BlitSurface(img_button_normal_green, NULL, hw_surface, &rect_tmp); + } + /* Write key SDLK_u*/ + if(keys_pushed[3]){ + SDL_Rect rect_tmp = {47, 118, img_button_normal_green->w, img_button_normal_green->h}; + SDL_BlitSurface(img_button_normal_green, NULL, hw_surface, &rect_tmp); + } + /* Write key SDLK_r*/ + if(keys_pushed[4]){ + SDL_Rect rect_tmp = {74, 143, img_button_normal_green->w, img_button_normal_green->h}; + SDL_BlitSurface(img_button_normal_green, NULL, hw_surface, &rect_tmp); + } + /* Write key SDLK_d*/ + if(keys_pushed[5]){ + SDL_Rect rect_tmp = {48, 169, img_button_normal_green->w, img_button_normal_green->h}; + SDL_BlitSurface(img_button_normal_green, NULL, hw_surface, &rect_tmp); + } + + /* Write key SDLK_b*/ + if(keys_pushed[6]){ + SDL_Rect rect_tmp = {169, 169, img_button_normal_green->w, img_button_normal_green->h}; + SDL_BlitSurface(img_button_normal_green, NULL, hw_surface, &rect_tmp); + } + /* Write key SDLK_y*/ + if(keys_pushed[7]){ + SDL_Rect rect_tmp = {143, 144, img_button_normal_green->w, img_button_normal_green->h}; + SDL_BlitSurface(img_button_normal_green, NULL, hw_surface, &rect_tmp); + } + /* Write key SDLK_x*/ + if(keys_pushed[8]){ + SDL_Rect rect_tmp = {169, 117, img_button_normal_green->w, img_button_normal_green->h}; + SDL_BlitSurface(img_button_normal_green, NULL, hw_surface, &rect_tmp); + } + /* Write key SDLK_a*/ + if(keys_pushed[9]){ + SDL_Rect rect_tmp = {195, 143, img_button_normal_green->w, img_button_normal_green->h}; + SDL_BlitSurface(img_button_normal_green, NULL, hw_surface, &rect_tmp); + } + + /* Write key SDLK_s*/ + if(keys_pushed[10]){ + SDL_Rect rect_tmp = {125, 203, img_button_normal_green->w, img_button_normal_green->h}; + SDL_BlitSurface(img_button_normal_green, NULL, hw_surface, &rect_tmp); + } + /* Write key SDLK_f*/ + if(keys_pushed[11]){ + SDL_Rect rect_tmp = {92, 204, img_button_normal_green->w, img_button_normal_green->h}; + SDL_BlitSurface(img_button_normal_green, NULL, hw_surface, &rect_tmp); + } + + /* Write key SDLK_q*/ + if(keys_pushed[12]){ + SDL_Rect rect_tmp = {106, 73, img_button_normal_green->w, img_button_normal_green->h}; + SDL_BlitSurface(img_button_normal_green, NULL, hw_surface, &rect_tmp); + } + + /* Render screen */ + render = 1; + } + + /* Handle Keyboard Events */ + while (SDL_PollEvent(&event)) + switch(event.type) + { + case SDL_QUIT: + stop_menu_loop = 1; + break; + case SDL_KEYDOWN: + for (i = 0; i < NB_KEYS; i++){ + if(event.key.keysym.sym != keys[i]) continue; + + /* Key pushed for the 1st time */ + if(!keys_pushed[i]){ + nb_keys_pushed++; + keys_pushed[i] = 1; + } + + /* All keys pushe = exit with success */ + if(nb_keys_pushed == NB_KEYS){ + stop_menu_loop = 1; + res = 0; + } + + /* Render screen */ + render = 1; + + break; + } + } + + + if(render){ + /// Render screen + SDL_Flip(hw_surface); + render = 0; + } + + /* Sleep for some time */ + SDL_Delay(SLEEP_PERIOD_MS); + } + + + /*Free surfaces */ + SDL_FreeSurface(img_console_layout); + SDL_FreeSurface(img_button_LR_green); + SDL_FreeSurface(img_button_normal_green); + + return res; +} + diff --git a/prodScreen_buttonsTest.h b/prodScreen_buttonsTest.h new file mode 100644 index 0000000..a1e7339 --- /dev/null +++ b/prodScreen_buttonsTest.h @@ -0,0 +1,10 @@ +#ifndef __PROD_SCREEN_BUTTONS__ +#define __PROD_SCREEN_BUTTONS__ + +#define IMG_CONSOLE_LAYOUT "ProdResources/funkey_with_buttons.png" +#define IMG_BUTTON_LR_GREEN "ProdResources/button_LR_green.png" +#define IMG_BUTTON_NORMAL_GREEN "ProdResources/button_round_green.png" + +int launch_prod_screen_buttons(); + +#endif //__PROD_SCREEN_BUTTONS__ \ No newline at end of file diff --git a/prodScreen_displayTest.c b/prodScreen_displayTest.c new file mode 100644 index 0000000..f9f3cac --- /dev/null +++ b/prodScreen_displayTest.c @@ -0,0 +1,117 @@ +#include "funkey_prod_screens.h" + + +/// -------------- FUNCTIONS IMPLEMENTATION -------------- +int launch_prod_screen_display(){ + SDL_Event event; + SDL_Surface *text_surface = NULL; + SDL_Rect text_pos; + int stop_menu_loop = 0; + int timeout = 31; + int prev_ms = 0; + int res = ERROR_MANUAL_FAIL; + + /* Main loop */ + while (!stop_menu_loop && timeout) + { + if(SDL_GetTicks() - prev_ms > 1000){ + + /* Update time*/ + prev_ms = SDL_GetTicks(); + char str_title[50]; + timeout--; + + /* Fill screen white */ + SDL_FillRect(hw_surface, NULL, SDL_MapRGB(hw_surface->format, bg_color.r, bg_color.g, bg_color.b)); + + /* Write Title */ + text_surface = TTF_RenderText_Shaded(font_title, "FUNKEY PCBA TESTS", text_color, bg_color); + text_pos.x = SCREEN_HORIZONTAL_SIZE/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; + 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; + SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); + SDL_FreeSurface(text_surface); + + /* Write: + "Press + L=FAIL + */ + 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; + 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; + SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); + SDL_FreeSurface(text_surface); + + /* Write: + Press + R=OK" + */ + 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; + 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; + SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); + SDL_FreeSurface(text_surface); + + /// Render screen + SDL_Flip(hw_surface); + } + + /* Handle 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; + } + } + + /* Sleep for some time */ + SDL_Delay(SLEEP_PERIOD_MS); + } + + return res; +} \ No newline at end of file diff --git a/prodScreen_displayTest.h b/prodScreen_displayTest.h new file mode 100644 index 0000000..54b9c4d --- /dev/null +++ b/prodScreen_displayTest.h @@ -0,0 +1,6 @@ +#ifndef __PROD_SCREEN_DISPLAY__ +#define __PROD_SCREEN_DISPLAY__ + +int launch_prod_screen_display(); + +#endif //__PROD_SCREEN_DISPLAY__ \ No newline at end of file diff --git a/prodScreen_failScreen.c b/prodScreen_failScreen.c new file mode 100644 index 0000000..bc54112 --- /dev/null +++ b/prodScreen_failScreen.c @@ -0,0 +1,109 @@ +#include "funkey_prod_screens.h" + + +/// -------------- FUNCTIONS IMPLEMENTATION -------------- +static int wait_event_loop(){ + + SDL_Event event; + int stop_menu_loop = 0; + int res = 0; + + /// -------- 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; + } + } + + /* Sleep for some time */ + SDL_Delay(SLEEP_PERIOD_MS); + } + + return res; +} + +int launch_prod_screen_fail(){ + SDL_Surface *text_surface = NULL; + SDL_Rect text_pos; + + /* Fill screen white */ + SDL_FillRect(hw_surface, NULL, SDL_MapRGB(hw_surface->format, bg_color.r, bg_color.g, bg_color.b)); + + /* Write Title */ + SDL_Color red={255,0,0}; + text_surface = TTF_RenderText_Shaded(font_title, "FUNKEY PCBA TESTS", red, bg_color); + text_pos.x = SCREEN_HORIZONTAL_SIZE/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; + SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); + SDL_FreeSurface(text_surface); + + /* Write: + "Press + L=FAIL + */ + 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; + 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; + SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); + SDL_FreeSurface(text_surface); + + /* Write: + Press + R=OK" + */ + 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; + 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; + SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); + SDL_FreeSurface(text_surface); + + /// Render screen + SDL_Flip(hw_surface); + + /// + int res = wait_event_loop(); + return res; +} diff --git a/prodScreen_failScreen.h b/prodScreen_failScreen.h new file mode 100644 index 0000000..9458569 --- /dev/null +++ b/prodScreen_failScreen.h @@ -0,0 +1,6 @@ +#ifndef __PROD_SCREEN_FAIL__ +#define __PROD_SCREEN_FAIL__ + +int launch_prod_screen_fail(); + +#endif //__PROD_SCREEN_FAIL__ \ No newline at end of file diff --git a/prodScreen_ledTest.c b/prodScreen_ledTest.c new file mode 100644 index 0000000..a9688c9 --- /dev/null +++ b/prodScreen_ledTest.c @@ -0,0 +1,105 @@ +#include "funkey_prod_screens.h" + +/// -------------- FUNCTIONS IMPLEMENTATION -------------- +static int wait_event_loop(){ + + SDL_Event event; + int stop_menu_loop = 0; + int res = 0; + + /// -------- 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; + } + } + + /* Sleep for some time */ + SDL_Delay(SLEEP_PERIOD_MS); + } + + return res; +} + +int launch_prod_screen_LED(){ + SDL_Surface *text_surface = NULL; + SDL_Rect text_pos; + + /* Fill screen white */ + SDL_FillRect(hw_surface, NULL, SDL_MapRGB(hw_surface->format, bg_color.r, bg_color.g, bg_color.b)); + + /* Write Title */ + text_surface = TTF_RenderText_Shaded(font_title, "FunKey PCBA Tests", text_color, bg_color); + text_pos.x = SCREEN_HORIZONTAL_SIZE/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; + SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); + SDL_FreeSurface(text_surface); + + /* Write: + "Press + L=FAIL + */ + 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; + 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; + SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); + SDL_FreeSurface(text_surface); + + /* Write: + Press + R=OK" + */ + 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; + 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; + SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); + SDL_FreeSurface(text_surface); + + /* Render screen */ + SDL_Flip(hw_surface); + + /// + int res = wait_event_loop(); + return res; +} diff --git a/prodScreen_ledTest.h b/prodScreen_ledTest.h new file mode 100644 index 0000000..c85dbc0 --- /dev/null +++ b/prodScreen_ledTest.h @@ -0,0 +1,6 @@ +#ifndef __PROD_SCREEN_LED__ +#define __PROD_SCREEN_LED__ + +int launch_prod_screen_LED(); + +#endif //__PROD_SCREEN_LED__ \ No newline at end of file diff --git a/prodScreen_magnetTest.c b/prodScreen_magnetTest.c new file mode 100644 index 0000000..34cb902 --- /dev/null +++ b/prodScreen_magnetTest.c @@ -0,0 +1,107 @@ +#include "funkey_prod_screens.h" + + +/// -------------- FUNCTIONS IMPLEMENTATION -------------- +static int wait_event_loop(){ + + SDL_Event event; + int stop_menu_loop = 0; + int res = 0; + + /// -------- 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; + } + } + + /* Sleep for some time */ + SDL_Delay(SLEEP_PERIOD_MS); + } + + return res; +} + +int launch_prod_screen_magnet(){ + SDL_Surface *text_surface = NULL; + SDL_Rect text_pos; + + /* Fill screen white */ + SDL_FillRect(hw_surface, NULL, SDL_MapRGB(hw_surface->format, bg_color.r, bg_color.g, bg_color.b)); + + /* Write Title */ + text_surface = TTF_RenderText_Shaded(font_title, "FunKey PCBA Tests", text_color, bg_color); + text_pos.x = SCREEN_HORIZONTAL_SIZE/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, "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; + SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); + SDL_FreeSurface(text_surface); + + /* Write: + "Press + L=FAIL + */ + 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; + 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; + SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); + SDL_FreeSurface(text_surface); + + /* Write: + Press + R=OK" + */ + /*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; + 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; + SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); + SDL_FreeSurface(text_surface);*/ + + /// Render screen + SDL_Flip(hw_surface); + + /// + int res = wait_event_loop(); + return res; +} \ No newline at end of file diff --git a/prodScreen_magnetTest.h b/prodScreen_magnetTest.h new file mode 100644 index 0000000..0e0d11c --- /dev/null +++ b/prodScreen_magnetTest.h @@ -0,0 +1,6 @@ +#ifndef __PROD_SCREEN_MAGNET__ +#define __PROD_SCREEN_MAGNET__ + +int launch_prod_screen_magnet(); + +#endif //__PROD_SCREEN_MAGNET__ \ No newline at end of file diff --git a/prodScreen_speakerTest.c b/prodScreen_speakerTest.c new file mode 100644 index 0000000..fac4726 --- /dev/null +++ b/prodScreen_speakerTest.c @@ -0,0 +1,106 @@ +#include "funkey_prod_screens.h" + + +/// -------------- FUNCTIONS IMPLEMENTATION -------------- +static int wait_event_loop(){ + + SDL_Event event; + int stop_menu_loop = 0; + int res = 0; + + /// -------- 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; + } + } + + /* Sleep for some time */ + SDL_Delay(SLEEP_PERIOD_MS); + } + + return res; +} + +int launch_prod_screen_speaker(){ + SDL_Surface *text_surface = NULL; + SDL_Rect text_pos; + + /* Fill screen white */ + SDL_FillRect(hw_surface, NULL, SDL_MapRGB(hw_surface->format, bg_color.r, bg_color.g, bg_color.b)); + + /* Write Title */ + text_surface = TTF_RenderText_Shaded(font_title, "FunKey PCBA Tests", text_color, bg_color); + text_pos.x = SCREEN_HORIZONTAL_SIZE/2 - text_surface->w/2; + text_pos.y = Y_PADDING; + SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); + + /* 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; + SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); + SDL_FreeSurface(text_surface); + + /* Write: + "Press + L=FAIL + */ + 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; + 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; + SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); + SDL_FreeSurface(text_surface); + + /* Write: + Press + R=OK" + */ + 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; + 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; + SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); + SDL_FreeSurface(text_surface); + + /* Render screen */ + SDL_Flip(hw_surface); + + /// + int res = wait_event_loop(); + return res; +} diff --git a/prodScreen_speakerTest.h b/prodScreen_speakerTest.h new file mode 100644 index 0000000..1ff30bc --- /dev/null +++ b/prodScreen_speakerTest.h @@ -0,0 +1,6 @@ +#ifndef __PROD_SCREEN_SPEAKER__ +#define __PROD_SCREEN_SPEAKER__ + +int launch_prod_screen_speaker(); + +#endif //__PROD_SCREEN_SPEAKER__ \ No newline at end of file diff --git a/prodScreen_validation.c b/prodScreen_validation.c new file mode 100644 index 0000000..28562d1 --- /dev/null +++ b/prodScreen_validation.c @@ -0,0 +1,107 @@ +#include "funkey_prod_screens.h" + + +/// -------------- FUNCTIONS IMPLEMENTATION -------------- +static int wait_event_loop(){ + + SDL_Event event; + int stop_menu_loop = 0; + int res = 0; + + /// -------- 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; + } + } + + /* Sleep for some time */ + SDL_Delay(SLEEP_PERIOD_MS); + } + + return res; +} + +int launch_prod_screen_validation(){ + SDL_Surface *text_surface = NULL; + SDL_Rect text_pos; + + /* Fill screen white */ + SDL_FillRect(hw_surface, NULL, SDL_MapRGB(hw_surface->format, bg_color.r, bg_color.g, bg_color.b)); + + /* Write Title */ + text_surface = TTF_RenderText_Shaded(font_title, "FUNKEY PCBA TESTS", text_color, bg_color); + text_pos.x = SCREEN_HORIZONTAL_SIZE/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; + SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); + SDL_FreeSurface(text_surface); + + /* Write: + "Press + L=FAIL + */ + 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; + 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; + SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); + SDL_FreeSurface(text_surface); + + /* Write: + Press + R=OK" + */ + 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; + 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; + SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); + SDL_FreeSurface(text_surface); + + /// Render screen + SDL_Flip(hw_surface); + + /// + int res = wait_event_loop(); + return res; +} \ No newline at end of file diff --git a/prodScreen_validation.h b/prodScreen_validation.h new file mode 100644 index 0000000..8e8fb18 --- /dev/null +++ b/prodScreen_validation.h @@ -0,0 +1,6 @@ +#ifndef __PROD_SCREEN_VALIDATION__ +#define __PROD_SCREEN_VALIDATION__ + +int launch_prod_screen_validation(); + +#endif //__PROD_SCREEN_VALIDATION__ \ No newline at end of file diff --git a/prodScreen_waitBattery.c b/prodScreen_waitBattery.c new file mode 100644 index 0000000..ba75f16 --- /dev/null +++ b/prodScreen_waitBattery.c @@ -0,0 +1,148 @@ +#include +#include +#include +#include +//#include +#include "funkey_prod_screens.h" + + +/// -------------- FUNCTIONS IMPLEMENTATION -------------- +static int is_battery_present(){ + char buf[10]; + FILE *fp; + int res = 0; + + /* Read battery file */ + if ((fp = fopen(BATTERY_PRESENT_FILE, "r")) == NULL) { + printf("Error! opening file: %s\n", BATTERY_PRESENT_FILE); + exit(EXIT_FAILURE); + } + if(!fscanf(fp, "%s", buf)) exit(EXIT_FAILURE); + fclose(fp); + + /* Check batery present */ + //printf("%s\n", buf); + if(atoi(buf) == 1){ + res = 1; + } + + return res; +} + +static int wait_event_loop(){ + + SDL_Event event; + int stop_menu_loop = 0; + int prev_ms = 0; + int res = ERROR_MANUAL_FAIL; + + /// -------- 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; + } + } + + if(SDL_GetTicks() - prev_ms > CHECK_BATTERY_DELAY_MS){ + + /* Update time*/ + prev_ms = SDL_GetTicks(); + + /* Check batery present */ + if(is_battery_present() == 1){ + stop_menu_loop = 1; + res = 0; + } + } + + /* Sleep for some time */ + SDL_Delay(SLEEP_PERIOD_MS); + } + + return res; +} + +int launch_prod_screen_waitbattery(){ + SDL_Surface *text_surface = NULL; + SDL_Rect text_pos; + + /* Fill screen white */ + SDL_FillRect(hw_surface, NULL, SDL_MapRGB(hw_surface->format, bg_color.r, bg_color.g, bg_color.b)); + + /* Write Title */ + text_surface = TTF_RenderText_Shaded(font_title, "FUNKEY PCBA TESTS", text_color, bg_color); + text_pos.x = SCREEN_HORIZONTAL_SIZE/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 ? */ + 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; + SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); + SDL_FreeSurface(text_surface); + + /* Write: + "Press + L=FAIL + */ + 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; + 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; + SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); + SDL_FreeSurface(text_surface); + + /* Write: + Press + R=OK" + */ + /*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; + 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; + SDL_BlitSurface(text_surface, NULL, hw_surface, &text_pos); + SDL_FreeSurface(text_surface);*/ + + /// Render screen + SDL_Flip(hw_surface); + + /// + int res = wait_event_loop(); + return res; +} \ No newline at end of file diff --git a/prodScreen_waitBattery.h b/prodScreen_waitBattery.h new file mode 100644 index 0000000..efd28cf --- /dev/null +++ b/prodScreen_waitBattery.h @@ -0,0 +1,9 @@ +#ifndef __PROD_SCREEN_WAITBATTERY__ +#define __PROD_SCREEN_WAITBATTERY__ + +#define BATTERY_PRESENT_FILE "/sys/class/power_supply/axp20x-battery/present" +#define CHECK_BATTERY_DELAY_MS 500 + +int launch_prod_screen_waitbattery(); + +#endif //__PROD_SCREEN_WAITBATTERY__ \ No newline at end of file