Skip to content

Commit 9f2131a

Browse files
Track output state to update brightness more clearly.
1 parent be9ccd4 commit 9f2131a

File tree

1 file changed

+10
-3
lines changed
  • photon-core/src/main/java/org/photonvision/common/hardware

1 file changed

+10
-3
lines changed

photon-core/src/main/java/org/photonvision/common/hardware/VisionLED.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class VisionLED implements AutoCloseable {
4343

4444
private VisionLEDMode currentLedMode = VisionLEDMode.kDefault;
4545
private BooleanSupplier pipelineModeSupplier;
46+
private boolean currentOutputState = false;
4647

4748
private float mappedBrightness = 0.0f;
4849

@@ -85,7 +86,11 @@ public void setPipelineModeSupplier(BooleanSupplier pipelineModeSupplier) {
8586
public void setBrightness(int percentage) {
8687
mappedBrightness =
8788
(float) (MathUtils.map(percentage, 0.0, 100.0, brightnessMin, brightnessMax) / 100.0);
88-
setInternal(currentLedMode, false);
89+
if (currentOutputState) {
90+
for (PwmLed led : dimmableVisionLEDs) {
91+
led.setValue(mappedBrightness);
92+
}
93+
}
8994
}
9095

9196
public void blink(int pulseLengthMillis, int blinkCount) {
@@ -102,7 +107,8 @@ private void blinkImpl(int pulseLengthMillis, int blinkCount) {
102107
.addTask(
103108
blinkTaskID,
104109
() -> {
105-
for (LED led : visionLEDs) {
110+
currentOutputState = !currentOutputState;
111+
for (LED led : visionLEDs) {
106112
led.toggle();
107113
}
108114
for (PwmLed led : dimmableVisionLEDs) {
@@ -117,6 +123,7 @@ private void blinkImpl(int pulseLengthMillis, int blinkCount) {
117123

118124
private void setStateImpl(boolean state) {
119125
TimedTaskManager.getInstance().cancelTask(blinkTaskID);
126+
currentOutputState = state;
120127
for (LED led : visionLEDs) {
121128
led.setOn(state);
122129
}
@@ -165,7 +172,7 @@ private void setInternal(VisionLEDMode newLedMode, boolean fromNT) {
165172

166173
var lastLedMode = currentLedMode;
167174

168-
if (fromNT || currentLedMode == VisionLEDMode.kDefault || currentLedMode == newLedMode) {
175+
if (fromNT || currentLedMode == VisionLEDMode.kDefault) {
169176
switch (newLedMode) {
170177
case kDefault -> setStateImpl(pipelineModeSupplier.getAsBoolean());
171178
case kOff -> setStateImpl(false);

0 commit comments

Comments
 (0)