FBInk icon indicating copy to clipboard operation
FBInk copied to clipboard

Add "Hello World" example

Open Limero opened this issue 3 months ago • 3 comments

Hello! FBInk looks super interesting and I've been trying to build a simple C program with it for my Kobo Clara 2E. However, I find all the examples to be too complicated to use as a template.

I tried starting with the doom.c util as a base and removing things, but it contains things like handling quirks and rotation things that I'm not sure is needed or not. Also, when running that (even unmodified) on my Kobo it mangles the screen and I have to force power off the device. Some other examples, like finger trace, I haven't even been able to build yet.

It would be super helpful if there was a simple "Hello World" example, like what is available for the other language wrappers.

Showing the bare minimum required to draw text, drawing a rectangle and potentially how to make said rectangle clickable to trigger an action, would allow anyone to easily get started building their own programs.

Limero avatar Sep 03 '25 16:09 Limero

I was finally able to achieve drawing a rectangle and text. How to make it clickable will be the next challenge.

#include "../cutef8/dfa.c"
#include "../cutef8/utf8.c"
#include "../fbink.c"
#include <stdio.h>

int fbFd = -1;

int
    main(int argc, char* argv[])
{
	FBInkConfig fbink_cfg = { 0U };
	fbink_cfg.is_centered = true;
	fbink_cfg.is_halfway  = true;

	if ((fbFd = fbink_open()) == ERRCODE(EXIT_FAILURE)) {
		fprintf(stderr, "Failed to open the framebuffer, aborting . . .\n");
		return ERRCODE(EXIT_FAILURE);
	}

	int rv = EXIT_SUCCESS;

	if (fbink_init(fbFd, &fbink_cfg) != EXIT_SUCCESS) {
		rv = ERRCODE(EXIT_FAILURE);
		goto cleanup;
	}
	if (!isFbMapped) {
		if (memmap_fb(fbFd) != EXIT_SUCCESS) {
			rv = ERRCODE(EXIT_FAILURE);
			goto cleanup;
		}
	}

	if (fbink_cls(fbFd, &fbink_cfg, NULL, false)) {
		rv = ERRCODE(EXIT_FAILURE);
		goto cleanup;
	}

	FBInkRect rect = {
		.left   = 100,
		.top    = 100,
		.width  = 500,
		.height = 500,
	};
	if (fbink_fill_rect_gray(fbFd, &fbink_cfg, &rect, false, 0)) {
		rv = ERRCODE(EXIT_FAILURE);
		goto cleanup;
	}

	if (fbink_print(fbFd, "Hello World", &fbink_cfg) < 0) {
		rv = ERRCODE(EXIT_FAILURE);
		goto cleanup;
	}

cleanup:
	if (fbink_close(fbFd) == ERRCODE(EXIT_FAILURE)) {
		fprintf(stderr, "Failed to close the framebuffer, aborting . . .\n");
		rv = ERRCODE(EXIT_FAILURE);
	}

	return rv;
}

Limero avatar Sep 04 '25 22:09 Limero

I was able to make a clickable rectangle, based on the finger_trace.c util. It can probably be cleaned up way further.

rectangle.c

I was able to build it by making sure to pass CROSS_TC

rm libevdev.built
CROSS_COMPILE=~/x-tools/arm-kobo-linux-gnueabihf/bin/arm-kobo-linux-gnueabihf- CROSS_TC=arm-linux-gnueabihf make libevdev.built

Hopefully this can save someone else all the trial and error. It would still be great to have official examples :)

Limero avatar Sep 05 '25 14:09 Limero

Ironically enough, there's a very very bare bones example in the Python bindings ;).

Otherwise, yeah, finger_trace is probably the sanest thing one could look at.

NiLuJe avatar Sep 16 '25 14:09 NiLuJe