Skip to content

Commit b9feb3d

Browse files
committed
Add timeout fallback
1 parent ee49989 commit b9feb3d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

libraries/Portenta_Camera/extras/CameraRawBytesVisualizer/CameraRawBytesVisualizer.pde

+8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ final int bytesPerFrame = cameraPixelCount * cameraBytesPerPixel;
2121

2222
PImage myImage;
2323
byte[] frameBuffer = new byte[bytesPerFrame];
24+
int lastUpdate = 0;
2425

2526
void setup() {
2627
size(640, 480);
@@ -46,9 +47,16 @@ void draw() {
4647
PImage img = myImage.copy();
4748
img.resize(640, 480);
4849
image(img, 0, 0);
50+
// Time out after 1.5 seconds and ask for new data
51+
if(millis() - lastUpdate > 1500) {
52+
println("Connection timed out.");
53+
myPort.write(1);
54+
}
4955
}
5056

5157
void serialEvent(Serial myPort) {
58+
lastUpdate = millis();
59+
5260
// read the received bytes
5361
myPort.readBytes(frameBuffer);
5462

0 commit comments

Comments
 (0)