Skip to content

Commit 76c4735

Browse files
OtakeOtake
authored andcommitted
Fixed Pixy Buffer Length Being Max
1 parent e655587 commit 76c4735

4 files changed

Lines changed: 7 additions & 3 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ publishing {
5151
artifact javadocJar
5252
groupId = 'pw.otake.pseudoresonance'
5353
artifactId = 'pixy2-java-api'
54-
version = '1.1'
54+
version = '1.2'
5555
pom {
5656
name = 'Pixy2JavaAPI'
5757
description = 'Java port of Pixy2 API for FIRST Robotics'

src/main/java/io/github/pseudoresonance/pixy2api/Pixy2.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public enum LinkType {
8585
protected int length = 0;
8686
protected int type = 0;
8787
protected byte[] bufferPayload = null;
88+
protected int receiveLength = 0;
8889

8990
protected int frameWidth = -1;
9091
protected int frameHeight = -1;
@@ -389,6 +390,7 @@ protected int receivePacket() {
389390
csSerial = ((buffer[3] & 0xff) << 8) | (buffer[2] & 0xff);
390391

391392
res = link.receive(buffer, length, csCalc);
393+
receiveLength = length;
392394

393395
if (res < 0)
394396
return res;
@@ -403,6 +405,8 @@ protected int receivePacket() {
403405
length = buffer[1];
404406

405407
res = link.receive(buffer, length);
408+
receiveLength = length;
409+
406410
if (res < 0)
407411
return res;
408412
}

src/main/java/io/github/pseudoresonance/pixy2api/Pixy2CCC.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public int getBlocks(boolean wait, int sigmap, int maxBlocks) {
9494
if (pixy.receivePacket() == 0) {
9595
if (pixy.type == CCC_RESPONSE_BLOCKS) {
9696
blocks = new ArrayList<Block>();
97-
for (int i = 0; i + 13 < pixy.buffer.length; i += 14) {
97+
for (int i = 0; i + 13 < pixy.receiveLength; i += 14) {
9898
Block b = new Block(((pixy.buffer[i + 1] & 0xff) << 8) | (pixy.buffer[i] & 0xff),
9999
((pixy.buffer[i + 3] & 0xff) << 8) | (pixy.buffer[i + 2] & 0xff),
100100
((pixy.buffer[i + 5] & 0xff) << 8) | (pixy.buffer[i + 4] & 0xff),

src/main/java/io/github/pseudoresonance/pixy2api/Pixy2Line.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public byte getFeatures(byte type, byte features, boolean wait) {
120120
for (offset = 0, res = 0; pixy.length > offset; offset += fsize + 2) {
121121
ftype = pixy.buffer[offset];
122122
fsize = pixy.buffer[offset + 1];
123-
fdata = Arrays.copyOfRange(pixy.buffer, offset + 2, pixy.buffer.length);
123+
fdata = Arrays.copyOfRange(pixy.buffer, offset + 2, pixy.receiveLength);
124124
if (ftype == LINE_VECTOR) {
125125
vectors = new Vector[(int) Math.floor(fdata.length / 6)];
126126
for (int i = 0; (i + 1) * 6 < fdata.length; i++) {

0 commit comments

Comments
 (0)