BlinkenArea - GitList
Repositories
Blog
Wiki
libetherpix
Code
Commits
Branches
Tags
Search
Tree:
a3a92ab
Branches
Tags
master
libetherpix
examples
src
blink.c
rename "FlexiPix" to "EtherPix"
Stefan Schuermans
commited
a3a92ab
at 2017-05-20 16:55:59
blink.c
Blame
History
Raw
#include <stdarg.h> #include <stdio.h> #include <unistd.h> #include <etherpix/etherpix.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 etp_display_create() */ void msg(void *p_ctx, etp_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 etp_msg_type_err: printf("ERROR: "); break; case etp_msg_type_warn: printf("WARNING: "); break; case etp_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 */ etp_display_t *p_display; unsigned int width, height, i; etp_u8_t white[3] = { 255, 255, 255 }; if (argc < 2) { printf("usage: %s <config.etp>\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 = etp_display_create(config, msg, (void *)&userdata); if (!p_display) { printf("could not create display\n"); return -1; } etp_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"); etp_display_data_fmt(p_display, white, 0, 0, 0, 0, width, height, etp_pixfmt_rgb24); etp_display_send(p_display); usleep(100000); printf("off\n"); etp_display_data_clear(p_display); etp_display_send(p_display); usleep(500000); } /* for (i ...) */ printf("done\n"); etp_display_free(p_display); #ifdef WINDOWS WSACleanup(); #endif return 0; }