From ccd3a512d69ed2b855a487b74b5d765d96097d99 Mon Sep 17 00:00:00 2001 From: Chris Gerth Date: Fri, 21 Oct 2022 17:10:32 -0500 Subject: [PATCH] Add additional try/catch to prevent pigpio communication issues from crashing the main thread (#511) --- .../common/hardware/VisionLED.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/photon-core/src/main/java/org/photonvision/common/hardware/VisionLED.java b/photon-core/src/main/java/org/photonvision/common/hardware/VisionLED.java index 880619e23..5f72ad4ad 100644 --- a/photon-core/src/main/java/org/photonvision/common/hardware/VisionLED.java +++ b/photon-core/src/main/java/org/photonvision/common/hardware/VisionLED.java @@ -85,6 +85,8 @@ public class VisionLED { pigpioSocket.generateAndSendWaveform(pulseLengthMillis, blinkCount, ledPins); } catch (PigpioException e) { logger.error("Failed to blink!", e); + } catch (NullPointerException e) { + logger.error("Failed to blink, pigpio internal issue!", e); } } else { for (GPIOBase led : visionLEDs) { @@ -100,13 +102,19 @@ public class VisionLED { pigpioSocket.waveTxStop(); } catch (PigpioException e) { logger.error("Failed to stop blink!", e); + } catch (NullPointerException e) { + logger.error("Failed to blink, pigpio internal issue!", e); } } - // if the user has set an LED brightness other than 100%, use that instead - if (mappedBrightnessPercentage == 100 || !state) { - visionLEDs.forEach((led) -> led.setState(state)); - } else { - visionLEDs.forEach((led) -> led.setBrightness(mappedBrightnessPercentage)); + try { + // if the user has set an LED brightness other than 100%, use that instead + if (mappedBrightnessPercentage == 100 || !state) { + visionLEDs.forEach((led) -> led.setState(state)); + } else { + visionLEDs.forEach((led) -> led.setBrightness(mappedBrightnessPercentage)); + } + } catch (NullPointerException e) { + logger.error("Failed to blink, pigpio internal issue!", e); } }