mirror of
https://github.com/FunKey-Project/FunKey-ProdScreens.git
synced 2025-12-12 08:48:51 +01:00
added simple img reader since fbv seems not to work when launched from bash script
This commit is contained in:
parent
00a2864ba2
commit
cde9d77e23
3
Makefile
3
Makefile
@ -7,7 +7,8 @@ prodScreen_buttonsTest.c \
|
||||
prodScreen_speakerTest.c \
|
||||
prodScreen_ledTest.c \
|
||||
prodScreen_magnetTest.c \
|
||||
prodScreen_validation.c
|
||||
prodScreen_validation.c \
|
||||
prodScreen_showImage.c
|
||||
|
||||
# Output
|
||||
EXEC=funkey_prod_screens
|
||||
|
||||
@ -16,14 +16,15 @@ 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}
|
||||
{"FAIL", launch_prod_screen_fail, 0},
|
||||
{"WAIT_BATTERY", launch_prod_screen_waitbattery, 0},
|
||||
{"DISPLAY", launch_prod_screen_display, 0},
|
||||
{"BUTTONS", launch_prod_screen_buttons, 0},
|
||||
{"SPEAKER", launch_prod_screen_speaker, 0},
|
||||
{"LED", launch_prod_screen_LED, 0},
|
||||
{"MAGNET", launch_prod_screen_magnet, 0},
|
||||
{"VALIDATE", launch_prod_screen_validation, 0},
|
||||
{"SHOW_IMAGE", launch_prod_screen_showImage, 1}
|
||||
};
|
||||
static int idx_current_prod_test = 0;
|
||||
|
||||
@ -87,48 +88,58 @@ void deinit_libraries(){
|
||||
|
||||
void usage(char *progname){
|
||||
int i;
|
||||
fprintf(stderr, "Usage: %s [prod_test]\n\n", progname);
|
||||
fprintf(stderr, "Usage: %s [prod_test] [optionnal: arg]\n\n", progname);
|
||||
fprintf(stderr, "\"prod_tests\" in:\n");
|
||||
for (i = 0; i < sizeof(prod_tests)/sizeof(prod_tests[0]); i++ ){
|
||||
if(!prod_tests[i].nb_args_needed){
|
||||
fprintf(stderr, " %s\n", prod_tests[i].cmd_line_argument);
|
||||
}
|
||||
else{
|
||||
fprintf(stderr, " %s [needs %d additional args]\n",
|
||||
prod_tests[i].cmd_line_argument, prod_tests[i].nb_args_needed);
|
||||
}
|
||||
}
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int optind, i;
|
||||
int i;
|
||||
int res = ERROR_MANUAL_FAIL;
|
||||
|
||||
if(argc != 2){
|
||||
if(argc < 2){
|
||||
usage(argv[0]);
|
||||
}
|
||||
|
||||
for (optind = 1; optind < argc; optind++) {
|
||||
|
||||
char * prod_test_str = argv[1];
|
||||
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])){
|
||||
if(!strcmp(prod_tests[i].cmd_line_argument, prod_test_str)){
|
||||
test_found = 1;
|
||||
idx_current_prod_test = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!test_found){
|
||||
usage(argv[0]);
|
||||
if(test_found && (prod_tests[i].nb_args_needed+2 != argc) ){
|
||||
fprintf(stderr, "ERROR: %s needs %d additional args\n",
|
||||
prod_tests[idx_current_prod_test].cmd_line_argument,
|
||||
prod_tests[idx_current_prod_test].nb_args_needed);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if(!test_found){
|
||||
usage(argv[0]);
|
||||
}
|
||||
|
||||
/// Init SDL
|
||||
init_libraries();
|
||||
|
||||
/// Launch Program
|
||||
res = prod_tests[idx_current_prod_test].ptr_function_launch_test();
|
||||
res = prod_tests[idx_current_prod_test].ptr_function_launch_test(argc-2, &argv[2]);
|
||||
|
||||
/// Deinit SDL
|
||||
deinit_libraries();
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
#include <stdio.h>
|
||||
#include <SDL/SDL.h>
|
||||
#include <SDL/SDL_ttf.h>
|
||||
//#include <SDL/SDL_image.h>
|
||||
#include <SDL/SDL_image.h>
|
||||
#include "prodScreen_failScreen.h"
|
||||
#include "prodScreen_waitBattery.h"
|
||||
#include "prodScreen_displayTest.h"
|
||||
@ -14,6 +14,7 @@
|
||||
#include "prodScreen_ledTest.h"
|
||||
#include "prodScreen_magnetTest.h"
|
||||
#include "prodScreen_validation.h"
|
||||
#include "prodScreen_showImage.h"
|
||||
|
||||
|
||||
/// Defines
|
||||
@ -40,10 +41,15 @@
|
||||
#define FONT_NAME_INFO FONT_NAME_TITLE
|
||||
#define FONT_SIZE_INFO 18
|
||||
|
||||
#define IMG_CONSOLE_LAYOUT FOLDER_RESSOURCES"/funkey_with_buttons.png"
|
||||
#define IMG_BUTTON_LR_GREEN FOLDER_RESSOURCES"/button_LR_green.png"
|
||||
#define IMG_BUTTON_NORMAL_GREEN FOLDER_RESSOURCES"/button_round_green.png"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char *cmd_line_argument;
|
||||
int (*ptr_function_launch_test)();
|
||||
int (*ptr_function_launch_test)(int argc, char *argv[]);
|
||||
int nb_args_needed;
|
||||
} s_prod_test;
|
||||
|
||||
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
#include <SDL/SDL_image.h>
|
||||
#include "funkey_prod_screens.h"
|
||||
|
||||
|
||||
@ -15,7 +14,7 @@ static int keys_pushed[NB_KEYS] = {0};
|
||||
|
||||
|
||||
/// -------------- FUNCTIONS IMPLEMENTATION --------------
|
||||
int launch_prod_screen_buttons(){
|
||||
int launch_prod_screen_buttons(int argc, char *argv[]){
|
||||
|
||||
/* Declare Vars */
|
||||
SDL_Surface *text_surface = NULL;
|
||||
|
||||
@ -1,10 +1,6 @@
|
||||
#ifndef __PROD_SCREEN_BUTTONS__
|
||||
#define __PROD_SCREEN_BUTTONS__
|
||||
|
||||
#define IMG_CONSOLE_LAYOUT FOLDER_RESSOURCES"/funkey_with_buttons.png"
|
||||
#define IMG_BUTTON_LR_GREEN FOLDER_RESSOURCES"/button_LR_green.png"
|
||||
#define IMG_BUTTON_NORMAL_GREEN FOLDER_RESSOURCES"/button_round_green.png"
|
||||
|
||||
int launch_prod_screen_buttons();
|
||||
int launch_prod_screen_buttons(int argc, char *argv[]);
|
||||
|
||||
#endif //__PROD_SCREEN_BUTTONS__
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
|
||||
/// -------------- FUNCTIONS IMPLEMENTATION --------------
|
||||
int launch_prod_screen_display(){
|
||||
int launch_prod_screen_display(int argc, char *argv[]){
|
||||
SDL_Event event;
|
||||
SDL_Surface *text_surface = NULL;
|
||||
SDL_Rect text_pos;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#ifndef __PROD_SCREEN_DISPLAY__
|
||||
#define __PROD_SCREEN_DISPLAY__
|
||||
|
||||
int launch_prod_screen_display();
|
||||
int launch_prod_screen_display(int argc, char *argv[]);
|
||||
|
||||
#endif //__PROD_SCREEN_DISPLAY__
|
||||
@ -48,7 +48,7 @@ static int wait_event_loop(){
|
||||
return res;
|
||||
}
|
||||
|
||||
int launch_prod_screen_fail(){
|
||||
int launch_prod_screen_fail(int argc, char *argv[]){
|
||||
SDL_Surface *text_surface = NULL;
|
||||
SDL_Rect text_pos;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#ifndef __PROD_SCREEN_FAIL__
|
||||
#define __PROD_SCREEN_FAIL__
|
||||
|
||||
int launch_prod_screen_fail();
|
||||
int launch_prod_screen_fail(int argc, char *argv[]);
|
||||
|
||||
#endif //__PROD_SCREEN_FAIL__
|
||||
@ -47,7 +47,7 @@ static int wait_event_loop(){
|
||||
return res;
|
||||
}
|
||||
|
||||
int launch_prod_screen_LED(){
|
||||
int launch_prod_screen_LED(int argc, char *argv[]){
|
||||
SDL_Surface *text_surface = NULL;
|
||||
SDL_Rect text_pos;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#ifndef __PROD_SCREEN_LED__
|
||||
#define __PROD_SCREEN_LED__
|
||||
|
||||
int launch_prod_screen_LED();
|
||||
int launch_prod_screen_LED(int argc, char *argv[]);
|
||||
|
||||
#endif //__PROD_SCREEN_LED__
|
||||
@ -1,11 +1,20 @@
|
||||
#include "funkey_prod_screens.h"
|
||||
#include <signal.h>
|
||||
|
||||
/* Static variable */
|
||||
static int stop_menu_loop = 0;
|
||||
|
||||
/* Handler for SIGUSR1, caused by closing the console */
|
||||
void handle_sigusr1(int sig)
|
||||
{
|
||||
//printf("Caught signal USR1 %d\n", sig);
|
||||
stop_menu_loop = 1;
|
||||
}
|
||||
|
||||
/// -------------- FUNCTIONS IMPLEMENTATION --------------
|
||||
static int wait_event_loop(){
|
||||
|
||||
SDL_Event event;
|
||||
int stop_menu_loop = 0;
|
||||
int res = 0;
|
||||
|
||||
/// -------- Main loop ---------
|
||||
@ -48,10 +57,13 @@ static int wait_event_loop(){
|
||||
return res;
|
||||
}
|
||||
|
||||
int launch_prod_screen_magnet(){
|
||||
int launch_prod_screen_magnet(int argc, char *argv[]){
|
||||
SDL_Surface *text_surface = NULL;
|
||||
SDL_Rect text_pos;
|
||||
|
||||
/* Init Signals */
|
||||
signal(SIGUSR1, handle_sigusr1);
|
||||
|
||||
/* Fill screen white */
|
||||
SDL_FillRect(hw_surface, NULL, SDL_MapRGB(hw_surface->format, bg_color.r, bg_color.g, bg_color.b));
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#ifndef __PROD_SCREEN_MAGNET__
|
||||
#define __PROD_SCREEN_MAGNET__
|
||||
|
||||
int launch_prod_screen_magnet();
|
||||
int launch_prod_screen_magnet(int argc, char *argv[]);
|
||||
|
||||
#endif //__PROD_SCREEN_MAGNET__
|
||||
107
prodScreen_showImage.c
Normal file
107
prodScreen_showImage.c
Normal file
@ -0,0 +1,107 @@
|
||||
#include "funkey_prod_screens.h"
|
||||
|
||||
|
||||
/// Defines
|
||||
|
||||
/// Static variables
|
||||
|
||||
|
||||
/// -------------- FUNCTIONS IMPLEMENTATION --------------
|
||||
|
||||
/* Nearest neighboor optimized with possible out of screen coordinates (for cropping) */
|
||||
void flip_NNOptimized_AllowOutOfScreen(SDL_Surface *src_surface, SDL_Surface *dst_surface, int new_w, int new_h){
|
||||
int w1=src_surface->w;
|
||||
//int h1=src_surface->h;
|
||||
int w2=new_w;
|
||||
int h2=new_h;
|
||||
int x_ratio = (int)((src_surface->w<<16)/w2);
|
||||
int y_ratio = (int)((src_surface->h<<16)/h2);
|
||||
int x2, y2;
|
||||
int i, j;
|
||||
|
||||
/* Compute padding for centering when out of bounds */
|
||||
int y_padding = (SCREEN_VERTICAL_SIZE-new_h)/2;
|
||||
int x_padding = 0;
|
||||
if(w2>SCREEN_HORIZONTAL_SIZE){
|
||||
x_padding = (w2-SCREEN_HORIZONTAL_SIZE)/2 + 1;
|
||||
}
|
||||
int x_padding_ratio = x_padding*w1/w2;
|
||||
|
||||
for (i=0;i<h2;i++)
|
||||
{
|
||||
if(i>=SCREEN_VERTICAL_SIZE){
|
||||
continue;
|
||||
}
|
||||
|
||||
uint16_t* t = (uint16_t*)(dst_surface->pixels+((i+y_padding)* ((w2>SCREEN_HORIZONTAL_SIZE)?SCREEN_HORIZONTAL_SIZE:w2) )*sizeof(uint16_t));
|
||||
y2 = ((i*y_ratio)>>16);
|
||||
uint16_t* p = (uint16_t*)(src_surface->pixels + (y2*w1 + x_padding_ratio) *sizeof(uint16_t));
|
||||
int rat = 0;
|
||||
for (j=0;j<w2;j++)
|
||||
{
|
||||
if(j>=SCREEN_HORIZONTAL_SIZE){
|
||||
continue;
|
||||
}
|
||||
x2 = (rat>>16);
|
||||
*t++ = p[x2];
|
||||
rat += x_ratio;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int launch_prod_screen_showImage(int argc, char *argv[]){
|
||||
SDL_Event event;
|
||||
int res = 0;
|
||||
int stop_menu_loop = 0;
|
||||
|
||||
/* Load Img */
|
||||
char *img_path = argv[0];
|
||||
SDL_Surface *image=IMG_Load(img_path);
|
||||
if(!image) {
|
||||
printf("ERROR IMG_Load: %s\n", IMG_GetError());
|
||||
printf("IMG path is: %s\n", img_path);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
/* Convert img to RGB565 */
|
||||
SDL_Surface *image_rgb565 = SDL_CreateRGBSurface(SDL_SWSURFACE, image->w, image->h, 16, 0, 0, 0, 0);
|
||||
SDL_BlitSurface(image, NULL, image_rgb565, NULL);
|
||||
SDL_FreeSurface(image);
|
||||
|
||||
/* Scale to fullscreen */
|
||||
flip_NNOptimized_AllowOutOfScreen(image_rgb565, hw_surface, hw_surface->w, hw_surface->h);
|
||||
|
||||
/// -------- 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_ESCAPE:
|
||||
stop_menu_loop = 1;
|
||||
res = 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* To investigate but with Buildroot, we need this: */
|
||||
SDL_Flip(hw_surface);
|
||||
|
||||
/* Sleep for some time */
|
||||
SDL_Delay(SLEEP_PERIOD_MS);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
6
prodScreen_showImage.h
Normal file
6
prodScreen_showImage.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef __PROD_SCREEN_SHOW_IMAGE__
|
||||
#define __PROD_SCREEN_SHOW_IMAGE__
|
||||
|
||||
int launch_prod_screen_showImage(int argc, char *argv[]);
|
||||
|
||||
#endif //__PROD_SCREEN_SHOW_IMAGE__
|
||||
@ -48,7 +48,7 @@ static int wait_event_loop(){
|
||||
return res;
|
||||
}
|
||||
|
||||
int launch_prod_screen_speaker(){
|
||||
int launch_prod_screen_speaker(int argc, char *argv[]){
|
||||
SDL_Surface *text_surface = NULL;
|
||||
SDL_Rect text_pos;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#ifndef __PROD_SCREEN_SPEAKER__
|
||||
#define __PROD_SCREEN_SPEAKER__
|
||||
|
||||
int launch_prod_screen_speaker();
|
||||
int launch_prod_screen_speaker(int argc, char *argv[]);
|
||||
|
||||
#endif //__PROD_SCREEN_SPEAKER__
|
||||
@ -48,7 +48,7 @@ static int wait_event_loop(){
|
||||
return res;
|
||||
}
|
||||
|
||||
int launch_prod_screen_validation(){
|
||||
int launch_prod_screen_validation(int argc, char *argv[]){
|
||||
SDL_Surface *text_surface = NULL;
|
||||
SDL_Rect text_pos;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#ifndef __PROD_SCREEN_VALIDATION__
|
||||
#define __PROD_SCREEN_VALIDATION__
|
||||
|
||||
int launch_prod_screen_validation();
|
||||
int launch_prod_screen_validation(int argc, char *argv[]);
|
||||
|
||||
#endif //__PROD_SCREEN_VALIDATION__
|
||||
@ -88,7 +88,7 @@ static int wait_event_loop(){
|
||||
return res;
|
||||
}
|
||||
|
||||
int launch_prod_screen_waitbattery(){
|
||||
int launch_prod_screen_waitbattery(int argc, char *argv[]){
|
||||
SDL_Surface *text_surface = NULL;
|
||||
SDL_Rect text_pos;
|
||||
|
||||
|
||||
@ -4,6 +4,6 @@
|
||||
#define BATTERY_PRESENT_FILE "/sys/class/power_supply/axp20x-battery/present"
|
||||
#define CHECK_BATTERY_DELAY_MS 500
|
||||
|
||||
int launch_prod_screen_waitbattery();
|
||||
int launch_prod_screen_waitbattery(int argc, char *argv[]);
|
||||
|
||||
#endif //__PROD_SCREEN_WAITBATTERY__
|
||||
Loading…
x
Reference in New Issue
Block a user