-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36b13f1
commit 7ebc816
Showing
4 changed files
with
151 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,7 +138,7 @@ $RECYCLE.BIN/ | |
|
||
### Gradle ### | ||
.gradle | ||
/build/ | ||
build/ | ||
|
||
# Ignore Gradle GUI config | ||
gradle-app.setting | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
plugins { | ||
id "java" | ||
id 'application' | ||
id 'com.github.johnrengelman.shadow' version '8.1.1' | ||
id "edu.wpi.first.GradleRIO" version "2024.3.2" | ||
id 'edu.wpi.first.WpilibTools' version '1.3.0' | ||
} | ||
|
||
application { | ||
mainClass = 'io.github.roboblazers7617.robot2024.buttonbox.ButtonBoxBridge' | ||
} | ||
|
||
wpilibTools.deps.wpilibVersion = wpi.versions.wpilibVersion.get() | ||
|
||
def nativeConfigName = 'wpilibNatives' | ||
def nativeConfig = configurations.create(nativeConfigName) | ||
|
||
def nativeTasks = wpilibTools.createExtractionTasks { | ||
configurationName = nativeConfigName | ||
} | ||
|
||
nativeTasks.addToSourceSetResources(sourceSets.main) | ||
nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpimath") | ||
nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpinet") | ||
nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpiutil") | ||
nativeConfig.dependencies.add wpilibTools.deps.wpilib("ntcore") | ||
nativeConfig.dependencies.add wpilibTools.deps.wpilib("cscore") | ||
nativeConfig.dependencies.add wpilibTools.deps.wpilibOpenCv("frc" + wpi.frcYear.get(), wpi.versions.opencvVersion.get()) | ||
|
||
// Add the ButtonBox dependency | ||
repositories { | ||
flatDir { | ||
dirs "../libs" | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation wpilibTools.deps.wpilibJava("wpiutil") | ||
implementation wpilibTools.deps.wpilibJava("wpimath") | ||
implementation wpilibTools.deps.wpilibJava("wpinet") | ||
implementation wpilibTools.deps.wpilibJava("ntcore") | ||
implementation wpilibTools.deps.wpilibJava("cscore") | ||
implementation wpilibTools.deps.wpilibJava("cameraserver") | ||
implementation wpilibTools.deps.wpilibOpenCvJava("frc" + wpi.frcYear.get(), wpi.versions.opencvVersion.get()) | ||
|
||
implementation group: "com.fasterxml.jackson.core", name: "jackson-annotations", version: wpi.versions.jacksonVersion.get() | ||
implementation group: "com.fasterxml.jackson.core", name: "jackson-core", version: wpi.versions.jacksonVersion.get() | ||
implementation group: "com.fasterxml.jackson.core", name: "jackson-databind", version: wpi.versions.jacksonVersion.get() | ||
|
||
implementation group: "org.ejml", name: "ejml-simple", version: wpi.versions.ejmlVersion.get() | ||
implementation group: "us.hebi.quickbuf", name: "quickbuf-runtime", version: wpi.versions.quickbufVersion.get(); | ||
|
||
implementation name: 'buttonbox-lib' | ||
implementation name: 'buttonbox-bridge-midi' | ||
} | ||
|
||
shadowJar { | ||
archiveBaseName = "2024RobotButtonBoxBridge" | ||
archiveVersion = "" | ||
exclude("module-info.class") | ||
archiveClassifier.set(wpilibTools.currentPlatform.platformName) | ||
} |
86 changes: 86 additions & 0 deletions
86
...x-bridge/src/main/java/io/github/roboblazers7617/robot2024/buttonbox/ButtonBoxBridge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package io.github.roboblazers7617.robot2024.buttonbox; | ||
|
||
import edu.wpi.first.networktables.NetworkTableInstance; | ||
import edu.wpi.first.networktables.NetworkTablesJNI; | ||
import edu.wpi.first.util.CombinedRuntimeLoader; | ||
|
||
import java.io.IOException; | ||
|
||
import java.util.Vector; | ||
|
||
import edu.wpi.first.math.WPIMathJNI; | ||
import edu.wpi.first.util.WPIUtilJNI; | ||
|
||
import javax.sound.midi.MidiDevice; | ||
import javax.sound.midi.MidiDevice.Info; | ||
import javax.sound.midi.MidiSystem; | ||
import javax.sound.midi.MidiUnavailableException; | ||
import javax.sound.midi.Synthesizer; | ||
import javax.sound.midi.ShortMessage; | ||
|
||
import io.github.roboblazers7617.buttonbox.ButtonBoxClient; | ||
import io.github.roboblazers7617.buttonbox.controls.TestControlMIDI; | ||
import io.github.roboblazers7617.buttonbox.controls.ButtonMIDI; | ||
import io.github.roboblazers7617.buttonbox.midi.MIDIDevice; | ||
import io.github.roboblazers7617.buttonbox.midi.MIDIAddress; | ||
|
||
/** | ||
* Bridge program to connect the 2024Robot ButtonBox hardware to NetworkTables. | ||
*/ | ||
public class ButtonBoxBridge { | ||
public static void main(String[] args) throws IOException, MidiUnavailableException { | ||
NetworkTablesJNI.Helper.setExtractOnStaticLoad(false); | ||
WPIUtilJNI.Helper.setExtractOnStaticLoad(false); | ||
WPIMathJNI.Helper.setExtractOnStaticLoad(false); | ||
|
||
CombinedRuntimeLoader.loadLibraries(ButtonBoxBridge.class, "wpiutiljni", "wpimathjni", "ntcorejni"); | ||
|
||
new ButtonBoxBridge().run(); | ||
} | ||
|
||
public void run() throws MidiUnavailableException { | ||
NetworkTableInstance inst = NetworkTableInstance.getDefault(); | ||
inst.startClient4("ButtonBox Bridge"); | ||
inst.setServer("localhost"); // where TEAM=190, 294, etc, or use inst.setServer("hostname") or similar | ||
inst.startDSClient(); // recommended if running on DS computer; this gets the robot IP from the DS | ||
|
||
// Obtain information about all the installed synthesizers. | ||
Vector<Info> synthInfos = new Vector<>(); | ||
MidiDevice device; | ||
MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo(); | ||
for (int i = 0; i < infos.length; i++) { | ||
try { | ||
device = MidiSystem.getMidiDevice(infos[i]); | ||
if (device instanceof Synthesizer) { | ||
synthInfos.add(infos[i]); | ||
} | ||
System.out.printf("%d: %s %s\n", i, infos[i].getClass(), infos[i].getName()); | ||
} catch (MidiUnavailableException ex) { | ||
// Handle or throw exception... | ||
} | ||
} | ||
|
||
Synthesizer synth = MidiSystem.getSynthesizer(); | ||
synth.open(); | ||
MidiDevice rxDevice = MidiSystem.getMidiDevice(infos[18]); | ||
MidiDevice txDevice = MidiSystem.getMidiDevice(infos[20]); | ||
rxDevice.open(); | ||
txDevice.open(); | ||
MIDIDevice midiDevice = new MIDIDevice(rxDevice, txDevice); | ||
|
||
ButtonBoxClient client = new ButtonBoxClient(inst); | ||
|
||
client.addControl(new TestControlMIDI("Test Control", new MIDIAddress(midiDevice, ShortMessage.CONTROL_CHANGE, 0, 0))); | ||
client.addControl(new ButtonMIDI("Test Button", new MIDIAddress(midiDevice, ShortMessage.NOTE_ON, 0, 0))); | ||
|
||
while (true) { | ||
try { | ||
Thread.sleep(10); | ||
} catch (InterruptedException ex) { | ||
System.out.println("interrupted"); | ||
return; | ||
} | ||
client.periodic(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters