BlinkenArea - GitList
Repositories
Blog
Wiki
libetherpix
Code
Commits
Branches
Tags
Search
Tree:
e2a21a2
Branches
Tags
master
libetherpix
examples
src
blink.c
v1.0.6
Stefan Schuermans
commited
e2a21a2
at 2011-09-11 17:17:58
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(p_display, white, 0, 0, 0, 0, width, height); 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; }