Skip to content

Commit

Permalink
comments and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brainmachine committed Feb 2, 2018
1 parent 158979e commit dec90a2
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 128 deletions.
15 changes: 7 additions & 8 deletions LightWork_Mapper/Animator.pde
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public class Animator {
ledIndex = 0; // TODO: resetInternalVariables() method?
testIndex = 0;
frameCounter = 0;
//resetPixels();
}

AnimationMode getMode() {
Expand Down Expand Up @@ -78,8 +77,8 @@ public class Animator {
for (int i = 0; i<leds.size(); i++) {
l[i]=leds.get(i).c;
}
return l; //<>// //<>//
}
return l;
} //<>// //<>//


//////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -113,7 +112,7 @@ public class Animator {
// Advance the internal counter
frameCounter++;

//send pixel data over network
// Send pixel data over network
if (mode!=AnimationMode.OFF && network.isConnected) {
network.update(this.getPixels());
}
Expand All @@ -133,13 +132,13 @@ public class Animator {
}

if (frameCounter == 0) return; // Avoid the first LED going off too quickly //<>// //<>//
if (frameCounter%this.frameSkip==0)ledIndex++; // use frameskip to delay animation updates
if (frameCounter%this.frameSkip==0)ledIndex++; // use frameskip to delay animation updates //<>// //<>//

// Stop at end of LEDs
if (ledIndex >= leds.size()) {
this.setMode(AnimationMode.OFF);
} //<>// //<>//
}
}
} //<>// //<>//

// Set all LEDs to the same colour (useful to turn them all on or off).
void setAllLEDColours(color col) {
Expand All @@ -148,7 +147,7 @@ public class Animator {
}
}

//LED pre-flight test. Cycle: White, Red, Green, Blue.
// LED pre-flight test. Cycle: White, Red, Green, Blue.
void test() {
testIndex++;

Expand Down
7 changes: 4 additions & 3 deletions LightWork_Mapper/BinaryPattern.pde
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ public class BinaryPattern {
BinaryPattern() {
numBits = 10;
animationPatternLength = 10;
frameNum = 0; // Used for animation
readIndex = 0; // Used by the detector to write bits
writeIndex = 0;
frameNum = 0; // Used for animation
readIndex = 0; // Used by the detector to read bits
writeIndex = 0; // Used by the detector to write bits
previousState = 0;
detectedState = 0;

// TODO: Review initial capacity
decodedString = new StringBuffer(10); // Init with capacity
decodedString.append("W123456789");

Expand Down
8 changes: 2 additions & 6 deletions LightWork_Mapper/Blob.pde
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* @author: Jordi Tost (@jorditost)
*
* University of Applied Sciences Potsdam, 2014
*
* Modified by Leó Stefánsson
*/

class Blob {
Expand Down Expand Up @@ -51,16 +53,10 @@ class Blob {
//set draw location based on displayed camera position, accounts for moving cam in UI
float x = map(r.x, 0, (float)camWidth, (float)camArea.x, camArea.x+camArea.width);
float y = map(r.y, 0, (float)camHeight, (float)camArea.y, camArea.y+camArea.height);
//float opacity = map(timer+1, 0, 255, 0, 127);

//fill(0, 255, 0, opacity);
noFill();
stroke(255, 0, 0);
rect(x, y, r.width, r.height);
//fill(255, 0, 0);
//textSize(12);
//text(id+ ": "+detectedPattern.decodedString.toString(), x+30, y);
//stroke(0, 255, 0);
}

void update(Contour newContour) {
Expand Down
12 changes: 2 additions & 10 deletions LightWork_Mapper/BlobManager.pde
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class BlobManager {
float distanceThreshold = 2;
int lifetime = 200;

//ArrayList<Contour> contours;
// List of detected contours parsed as blobs (every frame)
ArrayList<Contour> newBlobs;
// List of my blob objects (persistent)
Expand All @@ -36,15 +35,11 @@ class BlobManager {
void update(PImage cvOutput) {
contourFinder.loadImage(cvOutput);

// Find all contours
//blobCV.loadImage(opencv.getSnapshot());
//ArrayList<Contour> contours = opencv.findContours();

// Filter contours, remove contours that are too big or too small
// The filtered results are our 'Blobs' (Should be detected LEDs)
ArrayList<Contour> newBlobs = filterContours(contourFinder.findContours()); // Stores all blobs found in this frame

// Note: newBlobs is actually of the Contours datatype
// Note: newBlobs is of the Contours type
// Register all the new blobs if the blobList is empty
if (blobList.isEmpty()) {
//println("Blob List is Empty, adding " + newBlobs.size() + " new blobs.");
Expand Down Expand Up @@ -102,7 +97,7 @@ class BlobManager {
}

// Update the blob age
//for (int i = blobList.size()-1; i > 0; i--) {
// TODO: Reverse iteration
for (int i = 0; i < blobList.size(); i++) {
Blob b = blobList.get(i);
b.countDown();
Expand All @@ -113,7 +108,6 @@ class BlobManager {
}

void display() {

for (Blob b : blobList) {
strokeWeight(1);
b.display();
Expand Down Expand Up @@ -156,6 +150,4 @@ class BlobManager {

return blobs;
}


}
27 changes: 15 additions & 12 deletions LightWork_Mapper/Interface.pde
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* //<>// //<>//
/* //<>//
* LED
*
* This class handles connecting to and switching between PixelPusher, FadeCandy and ArtNet devices.
Expand Down Expand Up @@ -55,7 +55,7 @@ public class Interface {
boolean isConnected =false;

//////////////////////////////////////////////////////////////
//Constructor
// Constructor
/////////////////////////////////////////////////////////////

Interface() {
Expand Down Expand Up @@ -156,7 +156,7 @@ public class Interface {
return isConnected;
}

//Set number of strips and pixels based on pusher config - only pulling for one right now.
// Set number of strips and pixels based on pusher config - only pulling for one right now.
void fetchPPConfig() {
if (mode == device.PIXELPUSHER && isConnected()) {
List<PixelPusher> pps = registry.getPushers();
Expand All @@ -173,12 +173,14 @@ public class Interface {
void populateLeds() {
int val = 0;

// Deal with ArtNet vs. LED structure
if (mode == device.ARTNET) {
val = getNumArtnetFixtures();
}
else {
val = numLeds;
}

// Clear existing LEDs
if (leds.size()>0) {
println("Clearing LED Array");
Expand Down Expand Up @@ -207,19 +209,19 @@ public class Interface {
switch(mode) {
case FADECANDY:
{
//check if opc object exists and is connected before writing data
// Check if OPC object exists and is connected before writing data
if (opc!=null&&opc.isConnected()) {
opc.autoWriteData(colors);
}
break;
}
case PIXELPUSHER:
{
//check if network observer exists and has discovered strips before writing data
// Check if network observer exists and has discovered strips before writing data
if (testObserver!=null&&testObserver.hasStrips) {
registry.startPushing();

//iterate through PP strip objects to set LED colors
// Iterate through PixelPusher strip objects to set LED colors
List<Strip> strips = registry.getStrips();
if (strips.size() > 0) {
int stripNum =0;
Expand Down Expand Up @@ -271,6 +273,8 @@ public class Interface {

void clearLeds() {
int valCount = 0;

// Deal with ArtNet vs. LED addresses
if (mode == device.ARTNET) {
valCount = numArtnetFixtures;
}
Expand All @@ -285,7 +289,7 @@ public class Interface {
}


//open connection to controller
// Open Connection to Controller
void connect(PApplet parent) {
if (isConnected) {
shutdown();
Expand Down Expand Up @@ -323,14 +327,13 @@ public class Interface {
animator.setAllLEDColours(off);
// Update pixels twice (elegant, I know... but it works)
update(animator.getPixels());
//update(animator.getPixels());
println("Connected to Fadecandy OPC server at: "+IP+":"+port);
isConnected =true;
opc.setPixelCount(numLeds);
populateLeds();
}
} else if (mode == device.PIXELPUSHER ) {
// does not like being instantiated a second time
// Does not like being instantiated a second time
if (registry == null) {
registry = new DeviceRegistry();
testObserver = new TestObserver();
Expand Down Expand Up @@ -377,27 +380,27 @@ public class Interface {
}
}

//Close existing connections
// Close existing connections
void shutdown() {
if (mode == device.FADECANDY && opc!=null) {
opc.dispose();
isConnected = false;
//opc = null;
}
if (mode==device.PIXELPUSHER && registry!=null) {
registry.stopPushing() ; //TODO: Need to disconnect devices as well
registry.deleteObserver(testObserver);
isConnected = false;
}
if (mode==device.ARTNET) {
// TODO: deinitialize artnet connection
//artnet = null;
}
if (mode==device.NULL) {
}
}


//toggle verbose logging for PixelPusher
// Toggle verbose logging for PixelPusher
void pusherLogging(boolean b) {
registry.setLogging(b);
}
Expand Down
7 changes: 4 additions & 3 deletions LightWork_Mapper/KeyPress.pde
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
* @authors Leó Stefánsson and Tim Rolls
*/

//ALT-SHIFT-S : Save UI properties to file
//ALT-SHIFT-L : Load UI properties to file
//SHIFT-H : Disable dragging (if accidentally activated with shift)
// Shortcuts:
// ALT-SHIFT-S : Save UI properties to file
// ALT-SHIFT-L : Load UI properties to file
// SHIFT-H : Disable dragging (if accidentally activated with shift)

void keyPressed() {
//if (key == 's') {
Expand Down
3 changes: 1 addition & 2 deletions LightWork_Mapper/LED.pde
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* LED
*
* This class tracks location, pattern and color data per LED
* This class tracks location, pattern and color data for an LED object
*
* Copyright (C) 2017 PWRFL
*
Expand Down Expand Up @@ -33,7 +33,6 @@ public class LED {
void setAddress(int addr) {
address = addr;
binaryPattern.generatePattern(address+bPatternOffset);
//println("LED Address: "+addr+" pattern: "+binaryPattern.binaryPatternString);
}

void setCoord(PVector coordinates) {
Expand Down
Loading

0 comments on commit dec90a2

Please sign in to comment.