Skip to content

Commit

Permalink
added command line option to omit a bad pixel
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulski committed Jun 6, 2013
1 parent 62ff098 commit 4b4e002
Show file tree
Hide file tree
Showing 17 changed files with 376 additions and 138 deletions.
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,21 @@ clean:
$(RM) *.o
$(RM) $(ARCHIVE)-$(VERSION).tar.gz

udplights: main.o UDPSender.o tclled.o
udplights: main.o UDPSender.o tclled.o
$(CC) $(CFLAGS) $(LIBS) -o $@ $^

udpfast: udpfast.o UDPSender.o tclled.o
$(CC) $(CFLAGS) $(LIBS) -lpthread -o $@ $^

tallwide: tallwide.o UDPSender.o tclled.o
tallwide: tallwide.o UDPSender.o tclled.o
$(CC) $(CFLAGS) $(LIBS) -o $@ $^

tallwide.o: tallwide.cpp UDPSender.h TCLZoned.hxx
dithered: dithered.o UDPSender.o tclled.o
$(CC) $(CFLAGS) $(LIBS) -o $@ $^

dithered.o: dithered.cpp UDPSender.h TCLZoned.hxx Options.hxx

tallwide.o: tallwide.cpp UDPSender.h TCLZoned.hxx Options.hxx

tclled.o: tclled.c tclled.h

Expand Down
160 changes: 160 additions & 0 deletions Options.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
#include "tclled.h"
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include "UDPSender.h"
#include <stdlib.h>
#include <signal.h>
#include "TCLZoned.hxx"
#include <vector>
#include <list>
#include <string>
#include <algorithm>
#include <iostream>

void prepPixels(unsigned int *raw, const tcl_buffer &tcl);
void initTclBuf(const tcl_buffer &tcl);
void interruptHandler(int param);
using namespace std;


class Options {
public:

Options(int argc, const char * argv[]):
leds(200),
port(54321)
{
buffersize ={20,10};
slurp(argc,argv);



findStart = args.begin();
findEnd = args.end();
buffersize = eatXY("size",buffersize);
leds = eatInt("leds",leds);
port = eatInt("port",port);
eatOmissions();

eatZones();





}

~Options() {
std::list<Zone*>::iterator first = zones.begin(), last = zones.end();
for ( ; first!=last; ++first )
delete (*first);
}

void dump() {

cout << "port:" << port << endl
<<"leds:" << leds << endl
<<"wd:" << buffersize.x << ", ht:" << buffersize.y << endl;
}
public:
XY buffersize;
int leds;
int port;

vector<string> args;
list<Zone *> zones;
list<XY> omissions;
vector<string>::iterator findStart, findEnd;

private:

int getInt(string &strVal) { return atoi(strVal.c_str());}

XY eatXY(const char *key, XY defaultVal) {
vector<string>::iterator where, keyloc,xloc,yloc;

where = find(findStart, findEnd,key);
if(where == findEnd) return defaultVal;



keyloc = where;
xloc = where + 1;
yloc = where + 2;


XY rval{getInt(*xloc),getInt(*yloc)};

args.erase(keyloc,yloc);
return rval;
}

int eatInt(const char *key, int defaultVal) {
vector<string>::iterator where;
where = find(findStart,findEnd,key);
if(where == findEnd) return defaultVal;

int rval = getInt(where[1]);
args.erase(where, where+1);
return rval;
}

int eatFlag(const char *key) {
vector<string>::iterator where;
where = find(findStart,findEnd,key);

if(where == findEnd) return 0;
// cerr << where[0] << endl;
// args.erase(where);
return 1;
}

void slurp(int argc, const char **argv) {
for(int i=0 ; i < argc; i++)
args.push_back(argv[i]);
}


void eatZones() {
while(findZone())
zones.push_back(eatZone());
}

bool findZone() {
findStart = find(args.begin(), args.end(), "zone");
if(findStart == args.end()) return false;
findStart++;

findEnd = find(findStart,args.end(),"zone");
}

Zone *eatZone() {

XY orig = eatXY("origin",XY{0,0});
XY size = eatXY("size",XY{10,10});

int offset = eatInt("offset",0);
bool vertical = eatFlag("vertical");
int flipX = eatFlag("flipX");
int flipY = eatFlag("flipY");


args.erase(findStart,findEnd);

Zone *rval = vertical ? new VZone(orig, size,offset, flipX, flipY) :
new Zone(orig,size,offset, flipX, flipY);

return rval;
}


void eatOmissions() {

while(true) {
XY omit = eatXY("omit",XY{-1,-1});
if(omit.x == -1) return;
omissions.push_back(omit);
}
}
};
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scp * <ssh-identity>:udplights
46 changes: 44 additions & 2 deletions TCLZoned.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public:
buf[offset(x,y)] = (r << 8) | (g << 16) | (b << 24);
}


private:
int size;
int wd, ht;
Expand Down Expand Up @@ -176,8 +177,34 @@ public:
}
}


void mapOutBadPixel(uint32_t *px) {
int idx = findIndex(px);
if(idx < 0) return;
if(idx >= count) return;
mapOut(idx);
}



private:
int count;
void mapOut(int idx) {
for(int i = idx; i < count-1; i++) {
pixelMap[i] = pixelMap[i+1];
}
}

int findIndex(uint32_t *px) {

for(int i = 0; i < count; i++) {
uint32_t *from = pixelMap[i];
if(from == px) return i;
}
return -1;
}


int count;
uint32_t **pixelMap;
Buffer *rawBuffer;
tcl_color *pixels;
Expand All @@ -203,6 +230,10 @@ public:
~TCLZoned() {
delete rawBuffer;
}

void mapOutBadPixel(XY px) {
pixelMap->mapOutBadPixel(rawBuffer->pixelAt(px.x,px.y));
}

Buffer *getBuffer() { return rawBuffer;}

Expand All @@ -213,6 +244,14 @@ public:
for ( ; first!=last; ++first )
add(*first);
}

void addOmissions(std::list<XY> omissions) {
std::list<XY>::iterator first = omissions.begin(), last = omissions.end();
for ( ; first!=last; ++first ) {
cout << "omitting " << first->x << first->y << endl;
mapOutBadPixel(*first);
}
}

void add(Zone *zone) {

Expand Down Expand Up @@ -250,7 +289,10 @@ private:
int leds;







void openSPI() {
/* Open SPI device */
spi = open("/dev/spidev2.0",O_WRONLY);
Expand Down
8 changes: 8 additions & 0 deletions UDPSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,11 @@ size_t UDPListener::listen(void *data, size_t maxcount) {
return recvfrom(sock,data,maxcount,0,(struct sockaddr *)&from,&fromlen);
}


void UDPListener::setNonblocking() {
int flags;
flags = fcntl(sock,F_GETFL,0);
assert(flags != -1);
fcntl(sock, F_SETFL, flags | O_NONBLOCK);
}

4 changes: 3 additions & 1 deletion UDPSender.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ class UDPSender {
class UDPListener {
public:
UDPListener(int port);
// virtual ~UDPListener();
void setNonblocking();
// virtual ~UDPListener();
size_t listen(void *data, size_t maxcount);
private:

int sock;
struct sockaddr_in server;
struct sockaddr_in from;
Expand Down
12 changes: 12 additions & 0 deletions bb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Run the UDP -> TCL lighting daemon
After=syslog.target network.target
#BindsTo=dev-spidev2.0.device
RequiresMountsFor=/dev/spidev2.0
# Requires=dev-spidev2.0.device
[Service]
Type=simple
ExecStart=/usr/bin/udplights/startUdplights.bash
#ExecStart=/home/root/udplights/tallwide size 32 11 leds 200 port 54321 zone size 22 5 offset 100 flipX zone size 10 10 offset 0 origin 22 1 flipY flipX vertical > /dev/null
[Install]
WantedBy=multi-user.target
12 changes: 12 additions & 0 deletions beagebone
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Run the UDP -> TCL lighting daemon
After=syslog.target network.target
#BindsTo=dev-spidev2.0.device
RequiresMountsFor=/dev/spidev2.0
# Requires=dev-spidev2.0.device
[Service]
Type=simple
ExecStart=/usr/bin/udplights/startUdplights.bash
#ExecStart=/home/root/udplights/tallwide size 32 11 leds 200 port 54321 zone size 22 5 offset 100 flipX zone size 10 10 offset 0 origin 22 1 flipY flipX vertical > /dev/null
[Install]
WantedBy=multi-user.target
12 changes: 12 additions & 0 deletions beaglebone.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Run the UDP -> TCL lighting daemon
After=syslog.target network.target
#BindsTo=dev-spidev2.0.device
RequiresMountsFor=/dev/spidev2.0
# Requires=dev-spidev2.0.device
[Service]
Type=simple
ExecStart=/usr/bin/udplights/startUdplights.bash
#ExecStart=/home/root/udplights/tallwide size 32 11 leds 200 port 54321 zone size 22 5 offset 100 flipX zone size 10 10 offset 0 origin 22 1 flipY flipX vertical > /dev/null
[Install]
WantedBy=multi-user.target
62 changes: 62 additions & 0 deletions dithered.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// main.c
// udpListen
//
// Created by Timothy Kukulski on 10/30/12.
// Copyright (c) 2012 Adobe. All rights reserved.
//


#include "tclled.h"
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include "UDPSender.h"
#include <stdlib.h>
#include <signal.h>
#include "TCLZoned.hxx"
#include <vector>
#include <list>
#include <string>
#include <algorithm>
#include <iostream>
#include "Options.hxx"

void prepPixels(unsigned int *raw, const tcl_buffer &tcl);
void initTclBuf(const tcl_buffer &tcl);
void interruptHandler(int param);
using namespace std;

int main(int argc, const char * argv[])
{

Options opts(argc, argv);

TCLZoned tcl(opts.buffersize.x, opts.buffersize.y, opts.leds);
tcl.addZones(opts.zones);
UDPListener udp(opts.port);

udp.setNonblocking();

opts.dump();

uint32_t *udpBuf = tcl.getBuffer()->getBuffer();
size_t bufSize = tcl.getBuffer()->getBufferSize();



tcl.testPattern();
tcl.send();


while(1) {
size_t amount = udp.listen(udpBuf,bufSize);
if(amount == bufSize) {
tcl.send();
} else {
cout << "bad buffer size:" << amount << " expected: " << bufSize << endl;
}
}

return 0;
}
Loading

0 comments on commit 4b4e002

Please sign in to comment.