Added all files

This commit is contained in:
busebusemac 2020-09-07 20:35:46 +02:00
parent 17ffd79780
commit f5bac63ec4
40 changed files with 1282 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
funkey_prod_screens

29
Makefile Normal file
View File

@ -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)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
ProdResources/arial.ttf Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 348 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 721 B

BIN
ProdResources/courbd.ttf Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

BIN
ProdResources/manaspc.ttf Normal file

Binary file not shown.

BIN
ProdResources/prstart.ttf Normal file

Binary file not shown.

137
funkey_prod_screens.c Normal file
View File

@ -0,0 +1,137 @@
#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"
/* 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;
}

57
funkey_prod_screens.h Normal file
View File

@ -0,0 +1,57 @@
#ifndef __FUNKEY_PROD_SCREENS__
#define __FUNKEY_PROD_SCREENS__
#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include <SDL/SDL_ttf.h>
//#include <SDL/SDL_image.h>
#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__

204
prodScreen_buttonsTest.c Normal file
View File

@ -0,0 +1,204 @@
#include <SDL/SDL_image.h>
#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;
}

10
prodScreen_buttonsTest.h Normal file
View File

@ -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__

117
prodScreen_displayTest.c Normal file
View File

@ -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;
}

6
prodScreen_displayTest.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef __PROD_SCREEN_DISPLAY__
#define __PROD_SCREEN_DISPLAY__
int launch_prod_screen_display();
#endif //__PROD_SCREEN_DISPLAY__

109
prodScreen_failScreen.c Normal file
View File

@ -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;
}

6
prodScreen_failScreen.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef __PROD_SCREEN_FAIL__
#define __PROD_SCREEN_FAIL__
int launch_prod_screen_fail();
#endif //__PROD_SCREEN_FAIL__

105
prodScreen_ledTest.c Normal file
View File

@ -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;
}

6
prodScreen_ledTest.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef __PROD_SCREEN_LED__
#define __PROD_SCREEN_LED__
int launch_prod_screen_LED();
#endif //__PROD_SCREEN_LED__

107
prodScreen_magnetTest.c Normal file
View File

@ -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;
}

6
prodScreen_magnetTest.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef __PROD_SCREEN_MAGNET__
#define __PROD_SCREEN_MAGNET__
int launch_prod_screen_magnet();
#endif //__PROD_SCREEN_MAGNET__

106
prodScreen_speakerTest.c Normal file
View File

@ -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;
}

6
prodScreen_speakerTest.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef __PROD_SCREEN_SPEAKER__
#define __PROD_SCREEN_SPEAKER__
int launch_prod_screen_speaker();
#endif //__PROD_SCREEN_SPEAKER__

107
prodScreen_validation.c Normal file
View File

@ -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;
}

6
prodScreen_validation.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef __PROD_SCREEN_VALIDATION__
#define __PROD_SCREEN_VALIDATION__
int launch_prod_screen_validation();
#endif //__PROD_SCREEN_VALIDATION__

148
prodScreen_waitBattery.c Normal file
View File

@ -0,0 +1,148 @@
#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"
/// -------------- 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;
}

9
prodScreen_waitBattery.h Normal file
View File

@ -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__