From 461937443cb25a32603151c42d5ecedcd4a91b1a Mon Sep 17 00:00:00 2001 From: Caleb Connolly Date: Mon, 4 Oct 2021 01:52:24 +0100 Subject: [PATCH] first commit! very messy implementation of a simple FB splash for postmarketOS. --- .gitignore | 1 + .gitmodules | 3 +++ CMakeLists.txt | 13 +++++++++++++ logo.h | 26 +++++++++++++++++++++++++ pbsplash.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ tfblib | 1 + 6 files changed, 95 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 CMakeLists.txt create mode 100644 logo.h create mode 100644 pbsplash.c create mode 160000 tfblib diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..96d8ae0 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "tfblib"] + path = tfblib + url = https://github.com/calebccff/tfblib diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2603af1 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.10) + +# set the project name +project(pbsplash) + +# add the executable +add_executable(pbsplash pbsplash.c) + +include_directories(tfblib/include) + +add_subdirectory(tfblib) + +target_link_libraries(pbsplash tfb) diff --git a/logo.h b/logo.h new file mode 100644 index 0000000..0334dfa --- /dev/null +++ b/logo.h @@ -0,0 +1,26 @@ +const float logo[] = { + // Top + 50, 00, 35, 30, // top to left + 35, 30, 38, 42, // top left point left + 38, 42, 50, 40, // top left point right + 50, 40, 67, 75, // top to right inside + 67, 75, 70, 63, + 70, 63, 83, 65, + 83, 65, 50, 00, // top to right + // Bottom left + 32, 35, 0, 100, + 0, 100, 30, 100, + 30, 100, 35, 90, + 35, 90, 30, 80, + 30, 80, 45, 45, + 45, 45, 35, 47, + 35, 47, 32, 35, + // Bottom right + 35, 80, 40, 90, + 40, 90, 35, 100, + 35, 100, 100, 100, + 100, 100, 85, 70, + 85, 70, 73, 68, + 73, 68, 70, 80, + 70, 80, 35, 80, +}; \ No newline at end of file diff --git a/pbsplash.c b/pbsplash.c new file mode 100644 index 0000000..ba06202 --- /dev/null +++ b/pbsplash.c @@ -0,0 +1,51 @@ +#include +#include +#include +#include + +#include "logo.h" + +int main(int argc, char **argv) +{ + int rc; + if ((rc = tfb_acquire_fb(TFB_FL_USE_DOUBLE_BUFFER, "/dev/fb0", "/dev/tty1")) != TFB_SUCCESS) { + fprintf(stderr, "tfb_acquire_fb() failed with error code: %d\n", rc); + return 1; + } + + int w = (int) tfb_screen_width(); + int h = (int) tfb_screen_height(); + int sz = (float)(w < h ? w : h) * 0.5; + fprintf(stdout, "w=%du, h=%du\n", w, h); + float x = (float)w / 2 - sz / 2; + float y = (float)h / 2 - sz / 2 - 300; + 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"); + + 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); + } + + getchar(); + tfb_release_fb(); + return 0; +} diff --git a/tfblib b/tfblib new file mode 160000 index 0000000..6938919 --- /dev/null +++ b/tfblib @@ -0,0 +1 @@ +Subproject commit 69389193fcf1c4d632febcfa0d3bdd99eb1ae2b7