Skip to content
This repository has been archived by the owner on Nov 24, 2024. It is now read-only.

bad apple #29

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ def includeDesktopSupport = false
// Defining my dependencies. In this case, WPILib (+ friends), and vendor libraries.
// Also defines JUnit 5.
dependencies {
implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.2'
implementation 'com.fasterxml.jackson.core:jackson-core:2.17.2'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.13.0'
implementation 'org.apache.commons:commons-lang3:3.6'
implementation 'org.apache.commons:commons-math3:3.6.1'
implementation 'com.github.shueja:Monologue:v1.0.0-beta6'
Expand Down
1 change: 1 addition & 0 deletions src/main/deploy/badapple.json

Large diffs are not rendered by default.

11 changes: 0 additions & 11 deletions src/main/java/frc/robot/subsystems/led/LEDConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,4 @@ public final class LEDConstants {

public static final int kLEDWidth = 32;
public static final int kLEDHeight = 8;

public static final String[] based = {
"B10000001111001111110011111011000",
"B10000010000101000000010000010100",
"B10000010000101000000010000010010",
"B10000010000101111110010000010001",
"B11111011111100000010011111010001",
"B10001010000100000010010000010001",
"B10001010000101111110010000010001",
"B11011010000100000000011111011111"
};
}
75 changes: 75 additions & 0 deletions src/main/java/frc/robot/subsystems/led/commands/BadApple.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright (c) 2024 FRC 3256
// https://github.com/Team3256
//
// Use of this source code is governed by a
// license that can be found in the LICENSE file at
// the root directory of this project.

package frc.robot.subsystems.led.commands;

import java.io.File;
import java.io.IOException;

import edu.wpi.first.wpilibj.Filesystem;
import frc.robot.helpers.DebugCommandBase;
import frc.robot.subsystems.led.IndicatorAnimation;
import frc.robot.subsystems.led.LED;
import com.fasterxml.jackson.databind.ObjectMapper;

// Please run this at 10 HZ or the animation will not work
public class BadApple extends DebugCommandBase {
private LED led;
private int currentFrame;
private String[][] frames;

public BadApple(LED led) {
this.led = led;
this.currentFrame = 0;
addRequirements(led);
}

@Override
public void initialize() {
super.initialize();
ObjectMapper objectMapper = new ObjectMapper();
try {
frames = objectMapper.readValue(new File(Filesystem.getDeployDirectory(), "badapple.json"),
String[][].class);
} catch (IOException e) {
e.printStackTrace();
frames = new String[0][0];
}
// new CoordinatesButItsMultiple(led, getCoordinates(ledStates), r, g, b,
// w).schedule();
}

@Override
public void execute() {
super.execute();
new CoordinatesButItsMultiple(led, getCoordinates(frames[currentFrame]), 255, 255, 255,
1).schedule();
currentFrame++;
currentFrame %= frames.length;
}

private int[][] getCoordinates(String[] ledStates) {

int[][] coordinates = new int[ledStates.length][2];
int height = ledStates.length - 1;
for (int y = 0; y < ledStates.length; y++) {
String row = ledStates[y];
for (int x = 0; x < row.length(); x++) {
if (row.charAt(x) == '1') {
coordinates[y] = new int[] { x, height - y };
}
}
}
return coordinates;
}

@Override
public void end(boolean interrupted) {
super.end(interrupted);
led.animate(IndicatorAnimation.Default);
}
}
Loading