BlinkenArea - GitList
Repositories
Blog
Wiki
libflexipix
Code
Commits
Branches
Tags
Search
Tree:
b17c6a4
Branches
Tags
master
v1.0.0
v1.0.1
v1.0.2
v1.0.3
v1.0.4
v1.0.5
v1.0.6
v1.0.7
v1.0.8
libflexipix
examples
src
blink.c
support BGR input in addition to RGB
Stefan Schuermans
commited
b17c6a4
at 2016-12-21 10:31:43
blink.c
Blame
History
Raw
#include <stdarg.h> #include <stdio.h> #include <unistd.h> #include <flexipix/flexipix.h> #ifdef WINDOWS #include <winsock.h> #endif /* just an example for some data */ typedef struct userdata_s { int i; float f; char c; } userdata_t; /* callback function called during display creation, the p_ctx parameter is the userdata supplied in the call to flp_display_create() */ void msg(void *p_ctx, flp_msg_type_t type, const char *fmt, ...) { userdata_t *p_userdata = (userdata_t *)p_ctx; va_list va; printf("msg (%d %f %c): ", p_userdata->i, p_userdata->f, p_userdata->c); /* make use of the userdata */ /* type tells if the message is an error, a warning or an information */ switch (type) { case flp_msg_type_err: printf("ERROR: "); break; case flp_msg_type_warn: printf("WARNING: "); break; case flp_msg_type_info: printf("INFORMATION: "); break; } /* fmt is a printf-style format string, the arguments are passed exactly as for printf */ va_start(va, fmt); vprintf(fmt, va); va_end(va); } int main(int argc, char *argv[]) { const char *config; userdata_t userdata = { 42, 42.0, '!' }; /* just an example */ flp_display_t *p_display; unsigned int width, height, i; flp_u8_t white[3] = { 255, 255, 255 }; if (argc < 2) { printf("usage: %s <config.flp>\n", argv[0]); return -1; } config = argv[1]; #ifdef WINDOWS { WSADATA data; WSAStartup(MAKEWORD(1,1), &data); } #endif /* create a display, take the configuration from a file, deliver messages to the callback function msg(), the last parameter is passed as first parameter to msg() and can be used to supply some user defined data */ p_display = flp_display_create(config, msg, (void *)&userdata); if (!p_display) { printf("could not create display\n"); return -1; } flp_display_get_size(p_display, &width, &height); printf("width: %5u\nheight: %5u\n", width, height); printf("blink\n"); for (i = 0; i < 5; ++i) { printf("on\n"); flp_display_data_fmt(p_display, white, 0, 0, 0, 0, width, height, flp_pixfmt_rgb24); flp_display_send(p_display); usleep(100000); printf("off\n"); flp_display_data_clear(p_display); flp_display_send(p_display); usleep(500000); } /* for (i ...) */ printf("done\n"); flp_display_free(p_display); #ifdef WINDOWS WSACleanup(); #endif return 0; }