Skip to content

Commit

Permalink
correct button (bumper)
Browse files Browse the repository at this point in the history
  • Loading branch information
v1x2 committed Nov 13, 2024
1 parent fea1f3b commit ec3970d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/main/java/frc/team5115/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public void robotPeriodic() {
noteDetectedEntry.setBoolean(feeder.noteDetected());
}
//
boolean aligning = joyDrive.getHID().getRawButton(XboxController.Button.kB.value);
boolean aligning = joyManip.getHID().getRightBumperPressed();
boolean inRange = false; // ?
if(lights != null){
lights.update(aligning, inRange);
Expand Down
121 changes: 62 additions & 59 deletions src/main/java/frc/team5115/subsystems/lights/Lights.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,36 +44,47 @@ public void start(){
public void stop(){
leds.stop();
}

public void update(boolean aligning, boolean inRange) {
AnimationState state = AnimationState.Idle;

if (inRange) {
state = AnimationState.InRange;
} else if (aligning) {
state = AnimationState.Aligning;
} else if (!reflectiveSensor.get()) {
state = AnimationState.ControllingNote;
public void iterateAllLeds(Function<Integer, Integer[]> function){
for(int i = 0; i <ledCount; i++){
Integer[] color = function.apply(i);
buffer.setRGB(i, color[0], color[1], color[2]);
}
leds.setData(buffer);
}

switch (state) {
case ControllingNote:
setUniformColor(0, 150, 0);
break;
case Aligning:
updateAlignAnimation();
break;
case InRange:
timer_align = 0;
position_align = 0;
setUniformColor(0xA5, 0x10, 0x90);
break;
case Idle:
default:
updateIdleAnimation();
break;
public void setUniformColor(int r, int g, int b){
iterateAllLeds((index) -> {
return new Integer[] {r, g, b};
});
}

public void updateIdleAnimation() {
timer_idle ++;
if (timer_idle >= period) {
timer_idle = 0;
} else {
return;
}

counter_idle += direction_idle;
if (counter_idle == ledCount || counter_idle == -1) {
direction_idle = -direction_idle;
counter_idle += 2 * direction_idle;
}
iterateAllLeds((index) -> {
double percent = buffer.getLED(index).red - minPower / 1d / maxPower - decay;
percent = Math.max(percent, 0);

if (index == counter_idle) {
percent = 1.0;
}

final double power = (percent * (maxPower - minPower)) + minPower;
return new Integer[] { (int)power, 0, 0 };
});
}

private void updateAlignAnimation() {
timer_align ++;
if (timer_align >= period) {
Expand All @@ -100,43 +111,35 @@ private void updateAlignAnimation() {
}
});
}

public void update(boolean aligning, boolean inRange) {
AnimationState state = AnimationState.Idle;

public void updateIdleAnimation() {
timer_idle ++;
if (timer_idle >= period) {
timer_idle = 0;
} else {
return;
}

counter_idle += direction_idle;
if (counter_idle == ledCount || counter_idle == -1) {
direction_idle = -direction_idle;
counter_idle += 2 * direction_idle;
if (inRange) {
state = AnimationState.InRange;
} else if (aligning) {
state = AnimationState.Aligning;
} else if (!reflectiveSensor.get()) {
state = AnimationState.ControllingNote;
}
iterateAllLeds((index) -> {
double percent = buffer.getLED(index).red - minPower / 1d / maxPower - decay;
percent = Math.max(percent, 0);

if (index == counter_idle) {
percent = 1.0;
}

final double power = (percent * (maxPower - minPower)) + minPower;
return new Integer[] { (int)power, 0, 0 };
});
}
public void setUniformColor(int r, int g, int b){
iterateAllLeds((index) -> {
return new Integer[] {r, g, b};
});
}
public void iterateAllLeds(Function<Integer, Integer[]> function){
for(int i = 0; i <ledCount; i++){
Integer[] color = function.apply(i);
buffer.setRGB(i, color[0], color[1], color[2]);
switch (state) {
case ControllingNote:
setUniformColor(0, 150, 0);
break;
case Aligning:
updateAlignAnimation();
break;
case InRange:
timer_align = 0;
position_align = 0;
setUniformColor(0xA5, 0x10, 0x90);
break;
case Idle:
default:
updateIdleAnimation();
break;
}
leds.setData(buffer);
}

}

0 comments on commit ec3970d

Please sign in to comment.