mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
[hal,wpilib] Add DS Display API (#8975)
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package org.wpilib.examples.driverstationdisplayansi;
|
||||
|
||||
import org.wpilib.driverstation.DriverStationDisplay;
|
||||
import org.wpilib.driverstation.DriverStationDisplay.Mode;
|
||||
import org.wpilib.opmode.PeriodicOpMode;
|
||||
import org.wpilib.opmode.Teleop;
|
||||
import org.wpilib.system.Timer;
|
||||
|
||||
@Teleop(name = "Default Teleop")
|
||||
public class DefaultTeleop extends PeriodicOpMode {
|
||||
private static final int[] COLORS = {
|
||||
196, 202, 208, 214, 220, 226, 118, 46, 48, 51,
|
||||
45, 39, 33, 27, 21, 57, 93, 129, 165, 201
|
||||
};
|
||||
|
||||
private final Timer timer = new Timer();
|
||||
private int seconds;
|
||||
|
||||
/** Called once when the robot is enabled. */
|
||||
@Override
|
||||
public void start() {
|
||||
DriverStationDisplay.setMode(Mode.RawAnsi);
|
||||
timer.restart();
|
||||
seconds = 0;
|
||||
|
||||
DriverStationDisplay.writeRawAnsi(
|
||||
"\033[2J\033[H"
|
||||
+ "DriverStationDisplay ANSI mode\n"
|
||||
+ "This header and footer stay on screen.\n"
|
||||
+ "Seconds elapsed: \n"
|
||||
+ "Only the number above is rewritten.");
|
||||
updateSecondsDisplay();
|
||||
}
|
||||
|
||||
/** Called periodically while the robot is enabled. */
|
||||
@Override
|
||||
public void periodic() {
|
||||
if (timer.advanceIfElapsed(1.0)) {
|
||||
seconds++;
|
||||
updateSecondsDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSecondsDisplay() {
|
||||
int color = COLORS[seconds % COLORS.length];
|
||||
DriverStationDisplay.writeRawAnsi(
|
||||
String.format("\033[3;18H\033[38;5;%dm%5d\033[0m", color, seconds));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package org.wpilib.examples.driverstationdisplayansi;
|
||||
|
||||
import org.wpilib.framework.OpModeRobot;
|
||||
|
||||
/**
|
||||
* Demonstrates DriverStationDisplay raw ANSI mode. The default teleop opmode writes static display
|
||||
* text once, then updates a value and its color in place once per second.
|
||||
*/
|
||||
public class Robot extends OpModeRobot {}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package org.wpilib.examples.driverstationdisplaylines;
|
||||
|
||||
import org.wpilib.driverstation.DriverStationDisplay;
|
||||
import org.wpilib.driverstation.DriverStationDisplay.Mode;
|
||||
import org.wpilib.opmode.PeriodicOpMode;
|
||||
import org.wpilib.opmode.Teleop;
|
||||
import org.wpilib.system.Timer;
|
||||
|
||||
@Teleop(name = "Default Teleop")
|
||||
public class DefaultTeleop extends PeriodicOpMode {
|
||||
private final Timer timer = new Timer();
|
||||
private int loopCount;
|
||||
|
||||
/** Called once when the robot is enabled. */
|
||||
@Override
|
||||
public void start() {
|
||||
DriverStationDisplay.setMode(Mode.Line);
|
||||
timer.restart();
|
||||
loopCount = 0;
|
||||
}
|
||||
|
||||
/** Called periodically while the robot is enabled. */
|
||||
@Override
|
||||
public void periodic() {
|
||||
DriverStationDisplay.addLine("DriverStationDisplay line mode");
|
||||
DriverStationDisplay.addData("Runtime", "%.1f seconds", timer.get());
|
||||
DriverStationDisplay.addData("Loop Count", "%d", loopCount++);
|
||||
DriverStationDisplay.updateLines();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package org.wpilib.examples.driverstationdisplaylines;
|
||||
|
||||
import org.wpilib.framework.OpModeRobot;
|
||||
|
||||
/**
|
||||
* Demonstrates DriverStationDisplay line mode. The default teleop opmode adds all lines each loop
|
||||
* and updateLines() sends the pending set to the Driver Station display.
|
||||
*/
|
||||
public class Robot extends OpModeRobot {}
|
||||
@@ -289,6 +289,30 @@
|
||||
"robotclass": "Robot",
|
||||
"commandversion": 2
|
||||
},
|
||||
{
|
||||
"name": "Driver Station Display Lines",
|
||||
"description": "Display lines on the Driver Station display and update them every robot loop.",
|
||||
"tags": [
|
||||
"Basic Robot",
|
||||
"Driver Station"
|
||||
],
|
||||
"foldername": "driverstationdisplaylines",
|
||||
"gradlebase": "java",
|
||||
"robotclass": "Robot",
|
||||
"commandversion": 2
|
||||
},
|
||||
{
|
||||
"name": "Driver Station Display ANSI",
|
||||
"description": "Stream ANSI text to the Driver Station display and update a value in place once per second.",
|
||||
"tags": [
|
||||
"Basic Robot",
|
||||
"Driver Station"
|
||||
],
|
||||
"foldername": "driverstationdisplayansi",
|
||||
"gradlebase": "java",
|
||||
"robotclass": "Robot",
|
||||
"commandversion": 2
|
||||
},
|
||||
{
|
||||
"name": "DriveDistanceOffboard",
|
||||
"description": "Drive a differential drivetrain a set distance using TrapezoidProfile and smart motor controller PID.",
|
||||
|
||||
Reference in New Issue
Block a user