From 4dadd62ea4acf857964374395f607785c907a32b Mon Sep 17 00:00:00 2001 From: cnlohr Date: Wed, 29 Jul 2015 01:28:38 -0400 Subject: [PATCH] Add tool to simulate LEDs --- embeddedlinux/Makefile | 22 +++++--- embeddedlinux/ccconfig.h | 11 ++++ embeddedlinux/dummy_leds.c | 108 +++++++++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+), 7 deletions(-) create mode 100644 embeddedlinux/ccconfig.h create mode 100644 embeddedlinux/dummy_leds.c diff --git a/embeddedlinux/Makefile b/embeddedlinux/Makefile index 6b32729..8ccdf93 100644 --- a/embeddedlinux/Makefile +++ b/embeddedlinux/Makefile @@ -1,16 +1,24 @@ -all : embeddedcc +all : embeddedcc dummy_leds + +CFLAGS:=-Os -I. -I.. -flto -I../embeddedcommon + +LDFLAGS:= -s -Wl,--relax -Wl,-Map=test.map -Wl,--gc-sections -ffunction-sections -fdata-sections -Wl,--strip-all -fno-asynchronous-unwind-tables +#LDFLAGS:=-O0 -g -CFLAGS:=-Ofast -DCCEMBEDDED -I.. -flto -m32 -DDFREQ=11025 -I../embeddedcommon -DNUM_LIN_LEDS=20 -LDFLAGS:=-ffunction-sections -Wl,--gc-sections -fno-asynchronous-unwind-tables -Wl,--strip-all embeddedcc : ../embeddedcommon/embeddednf.c ../embeddedcommon/DFT32.c embeddedcc.c ../embeddedcommon/embeddedout.c - gcc -o $@ $^ $(CFLAGS) $(LDFLAGS) + gcc -o $@ $^ $(CFLAGS) $(LDFLAGS) -m32 +dummy_leds : dummy_leds.c + gcc -o $@ $^ -lX11 -lpthread $(CFLAGS) $(LDFLAGS) -#SOUNDDEVICE:= --device=alsa_output.pci-0000_00_1b.0.analog-stereo.monitor +SOUNDDEVICE:= --device=alsa_output.pci-0000_00_1b.0.analog-stereo.monitor +#OUTIP:=192.168.4.1 +OUTIP:=127.0.0.1 runembedded : embeddedcc - parec --format=u8 --rate=11025 --channels=1 $(SOUNDDEVICE) --latency=128 | ./embeddedcc 192.168.4.1 0 + parec --format=u8 --rate=16000 --channels=1 $(SOUNDDEVICE) --latency=128 | ./embeddedcc $(OUTIP) 1 + clean : - rm -rf embeddedcc *~ + rm -rf embeddedcc *~ dummy_leds diff --git a/embeddedlinux/ccconfig.h b/embeddedlinux/ccconfig.h new file mode 100644 index 0000000..e4a5a30 --- /dev/null +++ b/embeddedlinux/ccconfig.h @@ -0,0 +1,11 @@ +#ifndef _CCCONFIG_H +#define _CCCONFIG_H + +#define CCEMBEDDED +#define NUM_LIN_LEDS 300 +#define USE_NUM_LIN_LEDS 300 +#define DFREQ 16000 + + +#endif + diff --git a/embeddedlinux/dummy_leds.c b/embeddedlinux/dummy_leds.c new file mode 100644 index 0000000..d49fc87 --- /dev/null +++ b/embeddedlinux/dummy_leds.c @@ -0,0 +1,108 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +pthread_t pt; +Display *d; +Window w; +XEvent e; +int sockfd; +struct sockaddr_in servaddr; +int wid, hei; + +uint8_t mesg[NUM_LIN_LEDS*3+3]; + +#define LEDS_PER_ROW 15 +#define LED_SIZE 15 + + +void thread_function( void * tf ) +{ + int n; + struct sockaddr_in cliaddr; + socklen_t len; + XEvent exppp; + + while(1) + { + len = sizeof(cliaddr); + n = recvfrom(sockfd,mesg,sizeof(mesg),0,(struct sockaddr *)&cliaddr,&len); + //XSendEventXClearArea( d, w, 0, 0, 1, 1, 1 ); + XLockDisplay( d ); + memset(&exppp, 0, sizeof(exppp)); + exppp.type = Expose; + exppp.xexpose.window = w; + XSendEvent(d,w,False,ExposureMask,&exppp); + XFlush( d ); + XUnlockDisplay( d ); + } +} + + +int main(void) +{ + int n; + + sockfd=socket(AF_INET,SOCK_DGRAM,0); + + bzero(&servaddr,sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr=htonl(INADDR_ANY); + servaddr.sin_port=htons(7777); + + if( bind(sockfd,(struct sockaddr *)&servaddr,sizeof(servaddr)) ) + { + fprintf( stderr, "Error binding.\n" ); + } + + + memset( mesg, 0, sizeof( mesg ) ); + + pthread_create (&pt, NULL, (void *) &thread_function, (void *)0); + + int s; + wid = LEDS_PER_ROW; + hei = NUM_LIN_LEDS/LEDS_PER_ROW + ( (NUM_LIN_LEDS%LEDS_PER_ROW)?1:0 ); + + XInitThreads(); + + d = XOpenDisplay(NULL); + + if (d == NULL) { + fprintf(stderr, "Cannot open display\n"); + exit(1); + } + + s = DefaultScreen(d); + w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, wid*LED_SIZE, hei*LED_SIZE, 1, BlackPixel(d, s), WhitePixel(d, s)); + XSetStandardProperties( d, w, "LED Simulaor", "LED Simulator", None, NULL, 0, NULL ); + XSelectInput(d, w, ExposureMask | KeyPressMask); + XMapWindow(d, w); + + GC dgc = XCreateGC(d, w, 0, 0); + + while (1) { + XNextEvent(d, &e); + if (e.type == Expose) { + for( n = 0; n < NUM_LIN_LEDS; n++ ) + { + unsigned long color = ( mesg[n*3+3] << 8 ) | ( mesg[n*3+4] << 16 ) | (mesg[n*3+5] << 0); + XSetForeground(d, dgc, color); + int x = n % wid; + int y = n / wid; + + XFillRectangle(d, w, dgc, x*LED_SIZE, y*LED_SIZE, LED_SIZE, LED_SIZE); + } + } +// if (e.type == ClientMessage ) +// break; + } + + XCloseDisplay(d); + return 0; +}