diff --git a/pbsplash.c b/pbsplash.c index ba06202..b323b0f 100644 --- a/pbsplash.c +++ b/pbsplash.c @@ -1,16 +1,64 @@ #include +#include +#include #include #include -#include #include "logo.h" +#define MSG_MAX_LEN 4096 + +int usage() { + fprintf(stderr, "pbsplash: a simple fbsplash tool\n"); + fprintf(stderr, "--------------------------------\n"); + fprintf(stderr, "pbsplash [-h] [-s splash image] [-m message]\n\n"); + fprintf(stderr, " -h show this help\n"); + fprintf(stderr, " -s path to splash image to display\n"); + fprintf(stderr, " -m message to show under the splash image\n"); + + return 1; +} + int main(int argc, char **argv) { - int rc; - if ((rc = tfb_acquire_fb(TFB_FL_USE_DOUBLE_BUFFER, "/dev/fb0", "/dev/tty1")) != TFB_SUCCESS) { + int rc = 0; + int opt; + char *message = calloc(MSG_MAX_LEN, 1); + char *splash_image; + + for (int i = 1; i < argc; i++) + { + printf("%d: %s\n", i, argv[i]); + if (strcmp(argv[i], "-h") == 0) { + rc = usage(); + goto out; + } + + if (strcmp(argv[i], "-s") == 0) { + splash_image = argv[1]; + printf("splash_image path: %s\n", splash_image); + continue; + } + + if (strcmp(argv[i], "-m") == 0) { + if (*argv[i+1] == '-') { + rc = read(STDIN_FILENO, message, MSG_MAX_LEN); + if (rc < 0) + goto out; + printf("%s\n", message); + } else { + free(message); + message = argv[i+1]; + } + printf("message: %s\n", message); + continue; + } + } + + if ((rc = tfb_acquire_fb(0, "/dev/fb0", "/dev/tty1")) != TFB_SUCCESS) { fprintf(stderr, "tfb_acquire_fb() failed with error code: %d\n", rc); - return 1; + rc = 1; + goto out; } int w = (int) tfb_screen_width(); @@ -22,30 +70,32 @@ int main(int argc, char **argv) float textX = x; float textY = y; - while(true) { - /* Paint the whole screen in black */ - tfb_clear_screen(tfb_black); - /* Draw a red rectangle at the center of the screen */ - /* Draw some text on-screen */ - tfb_draw_string_scaled(x + 75, y + sz + 40, tfb_white, tfb_black, 4, 4, "postmarketOS"); + /* Paint the whole screen in black */ + tfb_clear_screen(tfb_black); + /* Draw a red rectangle at the center of the screen */ + /* Draw some text on-screen */ + tfb_draw_string_scaled(x + 75, y + sz + 40, tfb_white, tfb_black, 4, 4, "postmarketOS"); - for (size_t i = 0; i < sizeof(logo) / sizeof(logo[0]); i+=4) - { - int x1 = (int) (logo[i] / 100 * sz) + (int)x; - int y1 = (int) (logo[i+1] / 100 * sz) + (int)y; - int x2 = (int) (logo[i+2] / 100 * sz) + (int)x; - int y2 = (int) (logo[i+3] / 100 * sz) + (int)y; - //printf("%f == ", logo[i] / 100 * w); - printf("x1: %d, y1: %d, x2: %d, y2: %d\n", x1, y1, x1, y2); - tfb_draw_line(x1, y1, x2, y2, tfb_green); - } - - tfb_flush_window(); - tfb_flush_fb(); - usleep(50000); + if (message) { + tfb_draw_string_scaled_wrapped(50, (int) ((float)h * 0.6), tfb_white, tfb_black, 2, 2, 80, message); } - getchar(); + for (size_t i = 0; i < sizeof(logo) / sizeof(logo[0]); i+=4) + { + int x1 = (int) (logo[i] / 100 * sz) + (int)x; + int y1 = (int) (logo[i+1] / 100 * sz) + (int)y; + int x2 = (int) (logo[i+2] / 100 * sz) + (int)x; + int y2 = (int) (logo[i+3] / 100 * sz) + (int)y; + //printf("x1: %d, y1: %d, x2: %d, y2: %d\n", x1, y1, x1, y2); + tfb_draw_line(x1, y1, x2, y2, tfb_green); + } + + tfb_flush_window(); + tfb_flush_fb(); + + sleep(20); +out: tfb_release_fb(); - return 0; + free(message); + return rc; } diff --git a/tfblib b/tfblib index 6938919..3e5de10 160000 --- a/tfblib +++ b/tfblib @@ -1 +1 @@ -Subproject commit 69389193fcf1c4d632febcfa0d3bdd99eb1ae2b7 +Subproject commit 3e5de1026f2965591fb9feb1256c0ea10f4dc928