Skip to content

Commit

Permalink
Add a mechanism for strip age
Browse files Browse the repository at this point in the history
The getPushedAt() method in Strip allows you to determine how recently
a strip was pushed.  Since PixelPusher is asynchronous, it might sit in
the pipeline for some time, and this allows applications to determine
how long.

A value of 0 indicates that the strip has not yet been pushed since it
was last updated;  otherwise, the value is in the same timebase as
System.nanoTime().
  • Loading branch information
jasstrong committed Aug 29, 2014
1 parent dfb04d0 commit ed306f4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ private int sendPacketToPusher(PixelPusher pusher) {
} else {
stripPacket = strip.serialize(DeviceRegistry.getOverallBrightnessScale());
}
strip.setPushedAt(System.nanoTime());
strip.markClean();
this.packet[packetLength++] = (byte) strip.getStripNumber();
if (fileIsOpen) {
Expand Down
17 changes: 17 additions & 0 deletions src/com/heroicrobot/dropbit/devices/pixelpusher/Strip.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public PixelPusher getPusher() {
return pusher;
}

private long pushedAt;
private int stripNumber;
private boolean touched;
private double powerScale;
Expand Down Expand Up @@ -155,6 +156,7 @@ public long getStripIdentifier() {
public synchronized void setPixels(Pixel[] pixels) {
this.pixels = Arrays.copyOfRange(pixels, 0, this.pixels.length);
this.touched = true;
pushedAt = 0;
pusher.markTouched();
}

Expand All @@ -171,6 +173,7 @@ public synchronized void setPixelRed(byte intensity, int position) {
nope.printStackTrace();
}
this.touched = true;
pushedAt = 0;
pusher.markTouched();
}

Expand All @@ -187,6 +190,7 @@ public synchronized void setPixelBlue(byte intensity, int position) {
nope.printStackTrace();
}
this.touched = true;
pushedAt = 0;
pusher.markTouched();
}

Expand All @@ -203,6 +207,7 @@ public synchronized void setPixelGreen(byte intensity, int position) {
nope.printStackTrace();
}
this.touched = true;
pushedAt = 0;
pusher.markTouched();
}

Expand All @@ -219,6 +224,7 @@ public synchronized void setPixelOrange(byte intensity, int position) {
nope.printStackTrace();
}
this.touched = true;
pushedAt = 0;
pusher.markTouched();
}

Expand All @@ -235,6 +241,7 @@ public synchronized void setPixelWhite(byte intensity, int position) {
nope.printStackTrace();
}
this.touched = true;
pushedAt = 0;
pusher.markTouched();
}

Expand All @@ -251,6 +258,7 @@ public synchronized void setPixel(int color, int position) {
nope.printStackTrace();
}
this.touched = true;
pushedAt = 0;
pusher.markTouched();
}

Expand All @@ -260,6 +268,7 @@ public synchronized void setPixel(Pixel pixel, int position) {
else
this.pixels[position].setColor(pixel);
this.touched = true;
pushedAt = 0;
pusher.markTouched();
}

Expand Down Expand Up @@ -346,4 +355,12 @@ public boolean isNotIdempotent() {
public void setNotIdempotent(boolean isNotIdempotent) {
this.isNotIdempotent = isNotIdempotent;
}

public long getPushedAt() {
return pushedAt;
}

public void setPushedAt(long pushedAt) {
this.pushedAt = pushedAt;
}
}

0 comments on commit ed306f4

Please sign in to comment.