mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[examples] DigitalCommunication, I2CCommunication: Add tests (#4865)
This commit is contained in:
@@ -14,10 +14,10 @@ import edu.wpi.first.wpilibj.TimedRobot;
|
||||
*/
|
||||
public class Robot extends TimedRobot {
|
||||
// define ports for digitalcommunication with light controller
|
||||
private static final int kAlliancePort = 0;
|
||||
private static final int kEnabledPort = 1;
|
||||
private static final int kAutonomousPort = 2;
|
||||
private static final int kAlertPort = 3;
|
||||
static final int kAlliancePort = 0;
|
||||
static final int kEnabledPort = 1;
|
||||
static final int kAutonomousPort = 2;
|
||||
static final int kAlertPort = 3;
|
||||
|
||||
private final DigitalOutput m_allianceOutput = new DigitalOutput(kAlliancePort);
|
||||
private final DigitalOutput m_enabledOutput = new DigitalOutput(kEnabledPort);
|
||||
@@ -39,4 +39,14 @@ public class Robot extends TimedRobot {
|
||||
var matchTime = DriverStation.getMatchTime();
|
||||
m_alertOutput.set(matchTime <= 30 && matchTime >= 25);
|
||||
}
|
||||
|
||||
/** Close all resources. */
|
||||
@Override
|
||||
public void close() {
|
||||
m_allianceOutput.close();
|
||||
m_enabledOutput.close();
|
||||
m_autonomousOutput.close();
|
||||
m_alertOutput.close();
|
||||
super.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -803,7 +803,8 @@
|
||||
"name": "Digital Communication Sample",
|
||||
"description": "An example program that communicates with external devices (such as an Arduino) using the roboRIO's DIO",
|
||||
"tags": [
|
||||
"Digital"
|
||||
"Digital",
|
||||
"Unit Testing"
|
||||
],
|
||||
"foldername": "digitalcommunication",
|
||||
"gradlebase": "java",
|
||||
|
||||
@@ -6,6 +6,7 @@ package edu.wpi.first.wpilibj.examples.i2ccommunication;
|
||||
|
||||
import edu.wpi.first.wpilibj.DriverStation;
|
||||
import edu.wpi.first.wpilibj.I2C;
|
||||
import edu.wpi.first.wpilibj.I2C.Port;
|
||||
import edu.wpi.first.wpilibj.TimedRobot;
|
||||
|
||||
/**
|
||||
@@ -13,9 +14,10 @@ import edu.wpi.first.wpilibj.TimedRobot;
|
||||
* code using the roboRIO's I2C port.
|
||||
*/
|
||||
public class Robot extends TimedRobot {
|
||||
private static int kDeviceAddress = 4;
|
||||
static final Port kPort = Port.kOnboard;
|
||||
private static final int kDeviceAddress = 4;
|
||||
|
||||
private static I2C m_arduino = new I2C(I2C.Port.kOnboard, kDeviceAddress);
|
||||
private final I2C m_arduino = new I2C(kPort, kDeviceAddress);
|
||||
|
||||
private void writeString(String input) {
|
||||
// Creates a char array from the input string
|
||||
@@ -30,7 +32,7 @@ public class Robot extends TimedRobot {
|
||||
}
|
||||
|
||||
// Writes bytes over I2C
|
||||
m_arduino.transaction(data, data.length, null, 0);
|
||||
m_arduino.transaction(data, data.length, new byte[] {}, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,4 +56,11 @@ public class Robot extends TimedRobot {
|
||||
|
||||
writeString(stateMessage.toString());
|
||||
}
|
||||
|
||||
/** Close all resources. */
|
||||
@Override
|
||||
public void close() {
|
||||
m_arduino.close();
|
||||
super.close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user