mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
Compare commits
113 Commits
v2020.1.1-
...
v2020.3.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35eb90c135 | ||
|
|
761f79385a | ||
|
|
554bda3332 | ||
|
|
2a968df779 | ||
|
|
30ccd13b69 | ||
|
|
60c09ea51f | ||
|
|
65eab93527 | ||
|
|
a226ad8509 | ||
|
|
31f4fd70ce | ||
|
|
7275ab9837 | ||
|
|
5b3facc63b | ||
|
|
0f313fb9ab | ||
|
|
05b7593e66 | ||
|
|
1b85066d26 | ||
|
|
e93b64f58d | ||
|
|
f0a18f31e7 | ||
|
|
29c82527a5 | ||
|
|
c165dc5e50 | ||
|
|
42da07396c | ||
|
|
20e6c04059 | ||
|
|
ff5d3e5b36 | ||
|
|
6cc68ab503 | ||
|
|
068465146b | ||
|
|
3bcf8057d4 | ||
|
|
8039a6c525 | ||
|
|
558c020cca | ||
|
|
7797da78f5 | ||
|
|
0ab81d768f | ||
|
|
1cee5ccb93 | ||
|
|
3ce01b5ac2 | ||
|
|
e6aa8f3ff4 | ||
|
|
9d7b087972 | ||
|
|
bb184ed481 | ||
|
|
b9b31069cc | ||
|
|
d0cf4e8882 | ||
|
|
02fb850761 | ||
|
|
ac8177e10d | ||
|
|
2eb5c54476 | ||
|
|
0e206e69cf | ||
|
|
b1357cace7 | ||
|
|
37202b6f28 | ||
|
|
2ac0d52960 | ||
|
|
dbe1e6f466 | ||
|
|
a61fcbd68d | ||
|
|
fe597eeba1 | ||
|
|
e213a47efd | ||
|
|
dcb96cb50c | ||
|
|
60d48fec57 | ||
|
|
ee8475d21f | ||
|
|
f47e318131 | ||
|
|
cb66bcca3c | ||
|
|
73302f6162 | ||
|
|
cba21a768f | ||
|
|
822e75ec45 | ||
|
|
108ddfa1b4 | ||
|
|
d4c8ee5915 | ||
|
|
ab9647ff5b | ||
|
|
6666d3be42 | ||
|
|
795086b4cf | ||
|
|
56765cf49a | ||
|
|
bf7012fa2d | ||
|
|
10e8fdb724 | ||
|
|
790dc552ca | ||
|
|
0ec8ed6c05 | ||
|
|
832693617f | ||
|
|
772ef8f961 | ||
|
|
95b6cd2dd9 | ||
|
|
ce1ac17dfb | ||
|
|
b2f7a6b651 | ||
|
|
bedbef7999 | ||
|
|
bc159a92a7 | ||
|
|
f50d710a5e | ||
|
|
bc8f68bec7 | ||
|
|
32c62449be | ||
|
|
6190fcb237 | ||
|
|
012d93b2bd | ||
|
|
222669dc2c | ||
|
|
abe25b795b | ||
|
|
354185189c | ||
|
|
f14fe434a1 | ||
|
|
e874ba9313 | ||
|
|
96348e835a | ||
|
|
d91796f8d2 | ||
|
|
9abce8eb06 | ||
|
|
8b4508ad53 | ||
|
|
5b7dd186d2 | ||
|
|
6ea13ea8f3 | ||
|
|
44bcf7fb4d | ||
|
|
c7a1dfc0bc | ||
|
|
a12bb447e4 | ||
|
|
c4bd54ef44 | ||
|
|
f9a11cce5e | ||
|
|
6008671c30 | ||
|
|
7b952d599d | ||
|
|
93cdf68694 | ||
|
|
0c6f24562f | ||
|
|
bdc1cab013 | ||
|
|
3259cffc63 | ||
|
|
67b59f2b31 | ||
|
|
1ce24a7a2f | ||
|
|
635882a9f7 | ||
|
|
71a22861eb | ||
|
|
9cb69c5b46 | ||
|
|
5e08bb28f8 | ||
|
|
ea4d1a39e1 | ||
|
|
31b588d961 | ||
|
|
0b80d566ad | ||
|
|
f8294e689b | ||
|
|
b78f115fcf | ||
|
|
b468c51251 | ||
|
|
023c088290 | ||
|
|
8a11d13a39 | ||
|
|
daa81c64a7 |
10
.github/workflows/gradle-wrapper-validation.yml
vendored
Normal file
10
.github/workflows/gradle-wrapper-validation.yml
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
name: "Validate Gradle Wrapper"
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
validation:
|
||||
name: "Validation"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: gradle/wrapper-validation-action@v1
|
||||
@@ -11,6 +11,7 @@ cppSrcFileInclude {
|
||||
generatedFileExclude {
|
||||
FRCNetComm\.java$
|
||||
simulation/gz_msgs/src/include/simulation/gz_msgs/msgs\.h$
|
||||
simulation/halsim_gui/src/main/native/include/portable-file-dialogs\.h$
|
||||
}
|
||||
|
||||
repoRootNameOverride {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"enableCppIntellisense": true,
|
||||
"currentLanguage": "cpp",
|
||||
"projectYear": "Beta2020-2",
|
||||
"projectYear": "2020",
|
||||
"teamNumber": 0
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ option(USE_VCPKG_LIBUV "Use vcpkg libuv" OFF)
|
||||
option(USE_VCPKG_EIGEN "Use vcpkg eigen" OFF)
|
||||
option(FLAT_INSTALL_WPILIB "Use a flat install directory" OFF)
|
||||
option(WITH_SIMULATION_MODULES "build simulation modules" OFF)
|
||||
set(OPENCV_JAVA_INSTALL_DIR "" CACHE PATH "Location to search for the OpenCV jar file")
|
||||
|
||||
if (NOT WITHOUT_JAVA AND NOT BUILD_SHARED_LIBS)
|
||||
message(FATAL_ERROR "
|
||||
@@ -64,6 +65,15 @@ FATAL: Cannot build static libs with Java enabled.
|
||||
")
|
||||
endif()
|
||||
|
||||
if (WITHOUT_JAVA OR WITHOUT_CSCORE)
|
||||
if(NOT "${OPENCV_JAVA_INSTALL_DIR}" STREQUAL "")
|
||||
message(WARNING "
|
||||
WARNING: OpenCV Java dir set but java is not enabled!
|
||||
It will be ignored.
|
||||
")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set( wpilib_dest wpilib)
|
||||
set( include_dest wpilib/include )
|
||||
set( main_lib_dest wpilib/lib )
|
||||
|
||||
@@ -37,7 +37,7 @@ So you want to contribute your changes back to WPILib. Great! We have a few cont
|
||||
|
||||
## Coding Guidelines
|
||||
|
||||
WPILib uses modified Google style guides for both C++ and Java, which can be found in the [styleguide repository](https://github.com/wpilibsuite/styleguide). Autoformatters are available for many popular editors at https://github.com/google/styleguide. Running wpiformat is required for all contributions and is enforced by our continuous integration system. We currently use clang-format 5.0 with wpiformat.
|
||||
WPILib uses modified Google style guides for both C++ and Java, which can be found in the [styleguide repository](https://github.com/wpilibsuite/styleguide). Autoformatters are available for many popular editors at https://github.com/google/styleguide. Running wpiformat is required for all contributions and is enforced by our continuous integration system. We currently use clang-format 6.0 with wpiformat.
|
||||
|
||||
While the library should be fully formatted according to the styles, additional elements of the style guide were not followed when the library was initially created. All new code should follow the guidelines. If you are looking for some easy ramp-up tasks, finding areas that don't follow the style guide and fixing them is very welcome.
|
||||
|
||||
|
||||
15
FasterBuilds.md
Normal file
15
FasterBuilds.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# Faster Builds for Developers
|
||||
|
||||
When you run `./gradlew build`, it builds EVERYTHING. This means debug and release builds for desktop and all installed cross compilers. For many developers, this is way too much, and causes much developer pain.
|
||||
|
||||
To help with some of these things, common tasks have shortcuts to only build necessary things for common development and testing tasks.
|
||||
|
||||
## Development (Desktop)
|
||||
|
||||
For projects `wpiutil`, `ntcore`, `cscore`, `hal` `wpilibOldCommands`, `wpilibNewCommands` and `cameraserver`, a `testDesktopJava` and a `testDesktopCpp` task exists. These can be ran with `./gradlew :projectName:task`, and will only build the minimum things required to run those tests.
|
||||
|
||||
For `wpilibc`, a `testDesktopCpp` task exists. For `wpilibj`, a `testDesktopJava` task exists.
|
||||
|
||||
For `wpilibcExamples`, a `buildDesktopCpp` task exists (These can't be ran, but they can compile).
|
||||
|
||||
For `wpilibjExamples`, a `buildDesktopJava` task exists.
|
||||
@@ -5,8 +5,8 @@ WPILib publishes its built artifacts to our Maven server for use by downstream p
|
||||
## Repositories
|
||||
We provide two repositories. These repositories are:
|
||||
|
||||
* (Release) https://first.wpi.edu/FRC/roborio/maven/release/
|
||||
* (Development) https://first.wpi.edu/FRC/roborio/maven/development/
|
||||
* (Release) https://frcmaven.wpi.edu/artifactory/release/
|
||||
* (Development) https://frcmaven.wpi.edu/artifactory/development/
|
||||
|
||||
The release repository is where official WPILib releases are pushed.
|
||||
The development repository is where development releases of every commit to [master](https://github.com/wpilibsuite/allwpilib/tree/master) is pushed.
|
||||
@@ -72,6 +72,10 @@ All artifacts are based at `edu.wpi.first.artifactname` in the repository.
|
||||
* hal
|
||||
* wpiutil
|
||||
|
||||
* halsim
|
||||
* imgui
|
||||
* wpiutil
|
||||
|
||||
* ntcore
|
||||
* wpiutil
|
||||
|
||||
@@ -85,7 +89,6 @@ All artifacts are based at `edu.wpi.first.artifactname` in the repository.
|
||||
* opencv
|
||||
* wpiutil
|
||||
|
||||
|
||||
* wpilibj
|
||||
* hal
|
||||
* cameraserver
|
||||
@@ -93,10 +96,35 @@ All artifacts are based at `edu.wpi.first.artifactname` in the repository.
|
||||
* cscore
|
||||
* wpiutil
|
||||
|
||||
|
||||
* wpilibc
|
||||
* hal
|
||||
* cameraserver
|
||||
* ntcore
|
||||
* cscore
|
||||
* wpiutil
|
||||
|
||||
* wpilibNewCommands
|
||||
* wpilibc
|
||||
* hal
|
||||
* cameraserver
|
||||
* ntcore
|
||||
* cscore
|
||||
* wpiutil
|
||||
|
||||
* wpilibNewCommands
|
||||
* wpilibc
|
||||
* hal
|
||||
* cameraserver
|
||||
* ntcore
|
||||
* cscore
|
||||
* wpiutil
|
||||
|
||||
### Third Party Artifacts
|
||||
|
||||
This repository provides the builds of the following third party software.
|
||||
|
||||
All artifacts are based at `edu.wpi.first.thirdparty.frcYEAR` in the repository.
|
||||
|
||||
* googletest
|
||||
* imgui
|
||||
* opencv
|
||||
|
||||
@@ -34,6 +34,8 @@ The following build options are available:
|
||||
* TODO
|
||||
* EXTERNAL_HAL_FILE
|
||||
* TODO
|
||||
* OPENCV_JAVA_INSTALL_DIR
|
||||
* Set this option to the location of the archive of the OpenCV Java bindings (it should be called opencv-xxx.jar, with the x'es being version numbers). NOTE: set it to the LOCATION of the file, not the file itself!
|
||||
|
||||
## Build Setup
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ Using Gradle makes building WPILib very straightforward. It only has a few depen
|
||||
- On Linux, GCC works fine
|
||||
- On Windows, you need Visual Studio 2019 (the free community edition works fine).
|
||||
Make sure to select the C++ Programming Language for installation
|
||||
- [ARM Compiler Toolchain](https://github.com/wpilibsuite/toolchain-builder/releases)
|
||||
- [ARM Compiler Toolchain](https://github.com/wpilibsuite/roborio-toolchain/releases)
|
||||
* Note that for 2020 and beyond, you should use version 7 or greater of GCC
|
||||
- Doxygen (Only required if you want to build the C++ documentation)
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ Team 254 Library wpilibj/src/main/java/edu/wpi/first/wpilibj/spline/SplineP
|
||||
wpilibc/src/main/native/include/spline/SplineParameterizer.h
|
||||
wpilibc/src/main/native/include/trajectory/TrajectoryParameterizer.h
|
||||
wpilibc/src/main/native/cpp/trajectory/TrajectoryParameterizer.cpp
|
||||
Portable File Dialogs simulation/halsim_gui/src/main/native/include/portable-file-dialogs.h
|
||||
|
||||
|
||||
==============================================================================
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <networktables/NetworkTable.h>
|
||||
#include <networktables/NetworkTableInstance.h>
|
||||
#include <wpi/DenseMap.h>
|
||||
#include <wpi/ManagedStatic.h>
|
||||
#include <wpi/SmallString.h>
|
||||
#include <wpi/StringMap.h>
|
||||
#include <wpi/mutex.h>
|
||||
@@ -47,8 +48,14 @@ struct CameraServer::Impl {
|
||||
};
|
||||
|
||||
CameraServer* CameraServer::GetInstance() {
|
||||
static CameraServer instance;
|
||||
return &instance;
|
||||
struct Creator {
|
||||
static void* call() { return new CameraServer{}; }
|
||||
};
|
||||
struct Deleter {
|
||||
static void call(void* ptr) { delete static_cast<CameraServer*>(ptr); }
|
||||
};
|
||||
static wpi::ManagedStatic<CameraServer, Creator, Deleter> instance;
|
||||
return &(*instance);
|
||||
}
|
||||
|
||||
static wpi::StringRef MakeSourceValue(CS_Source source,
|
||||
|
||||
@@ -69,7 +69,9 @@ if (NOT WITHOUT_JAVA)
|
||||
|
||||
#find java files, copy them locally
|
||||
|
||||
set(OPENCV_JAVA_INSTALL_DIR ${OpenCV_INSTALL_PATH}/share/OpenCV/java/)
|
||||
if("${OPENCV_JAVA_INSTALL_DIR}" STREQUAL "")
|
||||
set(OPENCV_JAVA_INSTALL_DIR ${OpenCV_INSTALL_PATH}/share/OpenCV/java/)
|
||||
endif()
|
||||
|
||||
find_file(OPENCV_JAR_FILE NAMES opencv-${OpenCV_VERSION_MAJOR}${OpenCV_VERSION_MINOR}${OpenCV_VERSION_PATCH}.jar PATHS ${OPENCV_JAVA_INSTALL_DIR} ${OpenCV_INSTALL_PATH}/bin NO_DEFAULT_PATH)
|
||||
find_file(OPENCV_JNI_FILE NAMES libopencv_java${OpenCV_VERSION_MAJOR}${OpenCV_VERSION_MINOR}${OpenCV_VERSION_PATCH}.so
|
||||
|
||||
@@ -412,7 +412,11 @@ std::unique_ptr<PropertyImpl> HttpCameraImpl::CreateEmptyProperty(
|
||||
}
|
||||
|
||||
bool HttpCameraImpl::CacheProperties(CS_Status* status) const {
|
||||
#ifdef _MSC_VER // work around VS2019 16.4.0 bug
|
||||
std::scoped_lock<wpi::mutex> lock(m_mutex);
|
||||
#else
|
||||
std::scoped_lock lock(m_mutex);
|
||||
#endif
|
||||
|
||||
// Pretty typical set of video modes
|
||||
m_videoModes.clear();
|
||||
|
||||
@@ -78,7 +78,11 @@ template <typename THandle, typename TStruct, int typeValue, typename TMutex>
|
||||
template <typename... Args>
|
||||
THandle UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::Allocate(
|
||||
Args&&... args) {
|
||||
#ifdef _MSC_VER // work around VS2019 16.4.0 bug
|
||||
std::scoped_lock<TMutex> lock(m_handleMutex);
|
||||
#else
|
||||
std::scoped_lock sync(m_handleMutex);
|
||||
#endif
|
||||
size_t i;
|
||||
for (i = 0; i < m_structures.size(); i++) {
|
||||
if (m_structures[i] == nullptr) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -102,7 +102,7 @@ static bool IsPercentageProperty(wpi::StringRef name) {
|
||||
if (name.startswith("raw_")) name = name.substr(4);
|
||||
return name == "brightness" || name == "contrast" || name == "saturation" ||
|
||||
name == "hue" || name == "sharpness" || name == "gain" ||
|
||||
name == "exposure_absolute";
|
||||
name == "exposure_absolute" || name == "exposure_time_absolute";
|
||||
}
|
||||
|
||||
static constexpr const int quirkLifeCamHd3000[] = {
|
||||
@@ -112,6 +112,11 @@ static constexpr char const* quirkPS3EyePropExAuto = "auto_exposure";
|
||||
static constexpr char const* quirkPS3EyePropExValue = "exposure";
|
||||
static constexpr const int quirkPS3EyePropExAutoOn = 0;
|
||||
static constexpr const int quirkPS3EyePropExAutoOff = 1;
|
||||
static constexpr char const* quirkPiCameraPropExAuto = "auto_exposure";
|
||||
static constexpr char const* quirkPiCameraPropExValue =
|
||||
"exposure_time_absolute";
|
||||
static constexpr const int quirkPiCameraPropExAutoOn = 0;
|
||||
static constexpr const int quirkPiCameraPropExAutoOff = 1;
|
||||
|
||||
int UsbCameraImpl::RawToPercentage(const UsbCameraProperty& rawProp,
|
||||
int rawValue) {
|
||||
@@ -1112,6 +1117,25 @@ void UsbCameraImpl::DeviceCacheVideoModes() {
|
||||
}
|
||||
}
|
||||
|
||||
// The Pi camera reports mode ranges, which we don't currently handle, so only
|
||||
// provide a set of discrete modes; list based on
|
||||
// https://picamera.readthedocs.io/en/release-1.10/fov.html
|
||||
if (modes.empty() && m_picamera) {
|
||||
for (VideoMode::PixelFormat pixelFormat :
|
||||
{VideoMode::kYUYV, VideoMode::kMJPEG, VideoMode::kBGR}) {
|
||||
modes.emplace_back(pixelFormat, 1920, 1080, 30);
|
||||
modes.emplace_back(pixelFormat, 2592, 1944, 15);
|
||||
modes.emplace_back(pixelFormat, 1296, 972, 42);
|
||||
modes.emplace_back(pixelFormat, 1296, 730, 49);
|
||||
modes.emplace_back(pixelFormat, 640, 480, 90);
|
||||
modes.emplace_back(pixelFormat, 320, 240, 90);
|
||||
modes.emplace_back(pixelFormat, 160, 120, 90);
|
||||
modes.emplace_back(pixelFormat, 640, 480, 60);
|
||||
modes.emplace_back(pixelFormat, 320, 240, 60);
|
||||
modes.emplace_back(pixelFormat, 160, 120, 60);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
std::scoped_lock lock(m_mutex);
|
||||
m_videoModes.swap(modes);
|
||||
@@ -1192,6 +1216,7 @@ void UsbCameraImpl::SetQuirks() {
|
||||
wpi::StringRef desc = GetDescription(descbuf);
|
||||
m_lifecam_exposure =
|
||||
desc.endswith("LifeCam HD-3000") || desc.endswith("LifeCam Cinema (TM)");
|
||||
m_picamera = desc.startswith("mmal service");
|
||||
|
||||
int deviceNum = GetDeviceNum(m_path.c_str());
|
||||
if (deviceNum >= 0) {
|
||||
@@ -1248,7 +1273,9 @@ void UsbCameraImpl::SetExposureAuto(CS_Status* status) {
|
||||
if (m_ps3eyecam_exposure) {
|
||||
SetProperty(GetPropertyIndex(quirkPS3EyePropExAuto),
|
||||
quirkPS3EyePropExAutoOn, status);
|
||||
|
||||
} else if (m_picamera) {
|
||||
SetProperty(GetPropertyIndex(quirkPiCameraPropExAuto),
|
||||
quirkPiCameraPropExAutoOn, status);
|
||||
} else {
|
||||
SetProperty(GetPropertyIndex(kPropExAuto), 3, status);
|
||||
}
|
||||
@@ -1258,6 +1285,9 @@ void UsbCameraImpl::SetExposureHoldCurrent(CS_Status* status) {
|
||||
if (m_ps3eyecam_exposure) {
|
||||
SetProperty(GetPropertyIndex(quirkPS3EyePropExAuto),
|
||||
quirkPS3EyePropExAutoOff, status); // manual
|
||||
} else if (m_picamera) {
|
||||
SetProperty(GetPropertyIndex(quirkPiCameraPropExAuto),
|
||||
quirkPiCameraPropExAutoOff, status); // manual
|
||||
} else {
|
||||
SetProperty(GetPropertyIndex(kPropExAuto), 1, status); // manual
|
||||
}
|
||||
@@ -1267,6 +1297,9 @@ void UsbCameraImpl::SetExposureManual(int value, CS_Status* status) {
|
||||
if (m_ps3eyecam_exposure) {
|
||||
SetProperty(GetPropertyIndex(quirkPS3EyePropExAuto),
|
||||
quirkPS3EyePropExAutoOff, status); // manual
|
||||
} else if (m_picamera) {
|
||||
SetProperty(GetPropertyIndex(quirkPiCameraPropExAuto),
|
||||
quirkPiCameraPropExAutoOff, status); // manual
|
||||
} else {
|
||||
SetProperty(GetPropertyIndex(kPropExAuto), 1, status); // manual
|
||||
}
|
||||
@@ -1277,6 +1310,8 @@ void UsbCameraImpl::SetExposureManual(int value, CS_Status* status) {
|
||||
}
|
||||
if (m_ps3eyecam_exposure) {
|
||||
SetProperty(GetPropertyIndex(quirkPS3EyePropExValue), value, status);
|
||||
} else if (m_picamera) {
|
||||
SetProperty(GetPropertyIndex(quirkPiCameraPropExValue), value, status);
|
||||
} else {
|
||||
SetProperty(GetPropertyIndex(kPropExValue), value, status);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -166,6 +166,7 @@ class UsbCameraImpl : public SourceImpl {
|
||||
// Quirks
|
||||
bool m_lifecam_exposure{false}; // Microsoft LifeCam exposure
|
||||
bool m_ps3eyecam_exposure{false}; // PS3 Eyecam exposure
|
||||
bool m_picamera{false}; // Raspberry Pi camera
|
||||
|
||||
//
|
||||
// Variables protected by m_mutex
|
||||
|
||||
@@ -57,7 +57,7 @@ set_property(TARGET hal PROPERTY FOLDER "libraries")
|
||||
|
||||
install(TARGETS hal EXPORT hal DESTINATION "${main_lib_dest}")
|
||||
install(DIRECTORY src/main/native/include/ DESTINATION "${include_dest}/hal")
|
||||
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/gen DESTINATION "${include_dest}/hal")
|
||||
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/gen/ DESTINATION "${include_dest}/hal")
|
||||
|
||||
if (MSVC OR FLAT_INSTALL_WPILIB)
|
||||
set (hal_config_dir ${wpilib_dest})
|
||||
|
||||
@@ -3,6 +3,7 @@ kLanguage_CPlusPlus = 2
|
||||
kLanguage_Java = 3
|
||||
kLanguage_Python = 4
|
||||
kLanguage_DotNet = 5
|
||||
kLanguage_Kotlin = 6
|
||||
kCANPlugin_BlackJagBridge = 1
|
||||
kCANPlugin_2CAN = 2
|
||||
kFramework_Iterative = 1
|
||||
@@ -41,4 +42,11 @@ kDriverStationEIO_TouchSlider = 11
|
||||
kADXL345_SPI = 1
|
||||
kADXL345_I2C = 2
|
||||
kCommand_Scheduler = 1
|
||||
kCommand2_Scheduler = 2
|
||||
kSmartDashboard_Instance = 1
|
||||
kKinematics_DifferentialDrive = 1
|
||||
kKinematics_MecanumDrive = 2
|
||||
kKinematics_SwerveDrive = 3
|
||||
kOdometry_DifferentialDrive = 1
|
||||
kOdometry_MecanumDrive = 2
|
||||
kOdometry_SwerveDrive = 3
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -130,6 +130,8 @@ public final class HAL extends JNIWrapper {
|
||||
String details, String location, String callStack,
|
||||
boolean printMsg);
|
||||
|
||||
public static native int sendConsoleLine(String line);
|
||||
|
||||
public static native int getPortWithModule(byte module, byte channel);
|
||||
|
||||
public static native int getPort(byte channel);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -38,4 +38,6 @@ public class InterruptJNI extends JNIWrapper {
|
||||
|
||||
public static native void setInterruptUpSourceEdge(int interruptHandle, boolean risingEdge,
|
||||
boolean fallingEdge);
|
||||
|
||||
public static native void releaseWaitingInterrupt(int interruptHandle);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -61,4 +61,6 @@ public class SPIJNI extends JNIWrapper {
|
||||
double timeout);
|
||||
|
||||
public static native int spiGetAutoDroppedCount(int port);
|
||||
|
||||
public static native void spiConfigureAutoStall(int port, int csToSclkTicks, int stallTicks, int pow2BytesPerRead);
|
||||
}
|
||||
|
||||
@@ -79,6 +79,15 @@ public class DriverStationSim {
|
||||
DriverStationDataJNI.notifyNewData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles suppression of DriverStation.reportError and reportWarning messages.
|
||||
*
|
||||
* @param shouldSend If false then messages will will be suppressed.
|
||||
*/
|
||||
public void setSendError(boolean shouldSend) {
|
||||
DriverStationDataJNI.setSendError(shouldSend);
|
||||
}
|
||||
|
||||
public void resetData() {
|
||||
DriverStationDataJNI.resetData();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -49,5 +49,8 @@ public class DriverStationDataJNI extends JNIWrapper {
|
||||
public static native void registerAllCallbacks(NotifyCallback callback, boolean initialNotify);
|
||||
public static native void notifyNewData();
|
||||
|
||||
public static native void setSendError(boolean shouldSend);
|
||||
public static native void setSendConsoleLine(boolean shouldSend);
|
||||
|
||||
public static native void resetData();
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include <FRC_FPGA_ChipObject/fpgainterfacecapi/NiFpga_HMB.h>
|
||||
|
||||
#include "ConstantsInternal.h"
|
||||
#include "DigitalInternal.h"
|
||||
#include "HALInitializer.h"
|
||||
@@ -19,14 +21,6 @@
|
||||
|
||||
using namespace hal;
|
||||
|
||||
extern "C" {
|
||||
NiFpga_Status NiFpga_ClientFunctionCall(NiFpga_Session session, uint32_t group,
|
||||
uint32_t functionId,
|
||||
const void* inBuffer,
|
||||
size_t inBufferSize, void* outBuffer,
|
||||
size_t outBufferSize);
|
||||
} // extern "C"
|
||||
|
||||
namespace {
|
||||
struct AddressableLED {
|
||||
std::unique_ptr<tLED> led;
|
||||
@@ -52,43 +46,6 @@ void InitializeAddressableLED() {
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
// Shim for broken ChipObject function
|
||||
static const uint32_t clientFeature_hostMemoryBuffer = 0;
|
||||
static const uint32_t hostMemoryBufferFunction_open = 2;
|
||||
|
||||
// Input arguments for HMB open
|
||||
struct AtomicHMBOpenInputs {
|
||||
const char* memoryName;
|
||||
};
|
||||
|
||||
// Output arguments for HMB open
|
||||
struct AtomicHMBOpenOutputs {
|
||||
size_t size;
|
||||
void* virtualAddress;
|
||||
};
|
||||
|
||||
static NiFpga_Status OpenHostMemoryBuffer(NiFpga_Session session,
|
||||
const char* memoryName,
|
||||
void** virtualAddress, size_t* size) {
|
||||
struct AtomicHMBOpenOutputs outputs;
|
||||
|
||||
struct AtomicHMBOpenInputs inputs;
|
||||
inputs.memoryName = memoryName;
|
||||
|
||||
NiFpga_Status retval = NiFpga_ClientFunctionCall(
|
||||
session, clientFeature_hostMemoryBuffer, hostMemoryBufferFunction_open,
|
||||
&inputs, sizeof(struct AtomicHMBOpenInputs), &outputs,
|
||||
sizeof(struct AtomicHMBOpenOutputs));
|
||||
if (NiFpga_IsError(retval)) {
|
||||
return retval;
|
||||
}
|
||||
*virtualAddress = outputs.virtualAddress;
|
||||
if (size != NULL) {
|
||||
*size = outputs.size;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
HAL_AddressableLEDHandle HAL_InitializeAddressableLED(
|
||||
@@ -146,8 +103,8 @@ HAL_AddressableLEDHandle HAL_InitializeAddressableLED(
|
||||
|
||||
uint32_t session = led->led->getSystemInterface()->getHandle();
|
||||
|
||||
*status = OpenHostMemoryBuffer(session, "HMB_0_LED", &led->ledBuffer,
|
||||
&led->ledBufferSize);
|
||||
*status = NiFpga_OpenHostMemoryBuffer(session, "HMB_0_LED", &led->ledBuffer,
|
||||
&led->ledBufferSize);
|
||||
|
||||
if (*status != 0) {
|
||||
addressableLEDHandles->Free(handle);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -75,6 +75,9 @@ void HAL_FreeDutyCycle(HAL_DutyCycleHandle dutyCycleHandle) {
|
||||
dutyCycleHandles->Free(dutyCycleHandle);
|
||||
}
|
||||
|
||||
void HAL_SetDutyCycleSimDevice(HAL_EncoderHandle handle,
|
||||
HAL_SimDeviceHandle device) {}
|
||||
|
||||
int32_t HAL_GetDutyCycleFrequency(HAL_DutyCycleHandle dutyCycleHandle,
|
||||
int32_t* status) {
|
||||
auto dutyCycle = dutyCycleHandles->Get(dutyCycleHandle);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -176,27 +176,27 @@ int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
|
||||
|
||||
if (baseLength + detailsRef.size() + locationRef.size() +
|
||||
callStackRef.size() <=
|
||||
65536) {
|
||||
65535) {
|
||||
// Pass through
|
||||
retval = FRC_NetworkCommunication_sendError(isError, errorCode, isLVCode,
|
||||
details, location, callStack);
|
||||
} else if (baseLength + detailsRef.size() > 65536) {
|
||||
} else if (baseLength + detailsRef.size() > 65535) {
|
||||
// Details too long, cut both location and stack
|
||||
auto newLen = 65536 - baseLength;
|
||||
auto newLen = 65535 - baseLength;
|
||||
std::string newDetails{details, newLen};
|
||||
char empty = '\0';
|
||||
retval = FRC_NetworkCommunication_sendError(
|
||||
isError, errorCode, isLVCode, newDetails.c_str(), &empty, &empty);
|
||||
} else if (baseLength + detailsRef.size() + locationRef.size() > 65536) {
|
||||
} else if (baseLength + detailsRef.size() + locationRef.size() > 65535) {
|
||||
// Location too long, cut stack
|
||||
auto newLen = 65536 - baseLength - detailsRef.size();
|
||||
auto newLen = 65535 - baseLength - detailsRef.size();
|
||||
std::string newLocation{location, newLen};
|
||||
char empty = '\0';
|
||||
retval = FRC_NetworkCommunication_sendError(
|
||||
isError, errorCode, isLVCode, details, newLocation.c_str(), &empty);
|
||||
} else {
|
||||
// Stack too long
|
||||
auto newLen = 65536 - baseLength - detailsRef.size() - locationRef.size();
|
||||
auto newLen = 65535 - baseLength - detailsRef.size() - locationRef.size();
|
||||
std::string newCallStack{callStack, newLen};
|
||||
retval = FRC_NetworkCommunication_sendError(isError, errorCode, isLVCode,
|
||||
details, location,
|
||||
@@ -229,6 +229,18 @@ int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
|
||||
return retval;
|
||||
}
|
||||
|
||||
int32_t HAL_SendConsoleLine(const char* line) {
|
||||
wpi::StringRef lineRef{line};
|
||||
if (lineRef.size() <= 65535) {
|
||||
// Send directly
|
||||
return FRC_NetworkCommunication_sendConsoleLine(line);
|
||||
} else {
|
||||
// Need to truncate
|
||||
std::string newLine{line, 65535};
|
||||
return FRC_NetworkCommunication_sendConsoleLine(newLine.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
int32_t HAL_GetControlWord(HAL_ControlWord* controlWord) {
|
||||
return HAL_GetControlWordInternal(controlWord);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <wpi/timestamp.h>
|
||||
|
||||
#include "HALInitializer.h"
|
||||
#include "HALInternal.h"
|
||||
#include "ctre/ctre.h"
|
||||
#include "hal/ChipObject.h"
|
||||
#include "hal/DriverStation.h"
|
||||
@@ -78,6 +79,15 @@ void InitializeHAL() {
|
||||
InitializeThreads();
|
||||
}
|
||||
} // namespace init
|
||||
|
||||
void ReleaseFPGAInterrupt(int32_t interruptNumber) {
|
||||
if (!global) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
global->writeInterruptForceNumber(static_cast<unsigned char>(interruptNumber),
|
||||
&status);
|
||||
}
|
||||
} // namespace hal
|
||||
|
||||
extern "C" {
|
||||
|
||||
15
hal/src/main/native/athena/HALInternal.h
Normal file
15
hal/src/main/native/athena/HALInternal.h
Normal file
@@ -0,0 +1,15 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace hal {
|
||||
void ReleaseFPGAInterrupt(int32_t interruptNumber);
|
||||
|
||||
} // namespace hal
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -13,9 +13,11 @@
|
||||
|
||||
#include "DigitalInternal.h"
|
||||
#include "HALInitializer.h"
|
||||
#include "HALInternal.h"
|
||||
#include "PortsInternal.h"
|
||||
#include "hal/ChipObject.h"
|
||||
#include "hal/Errors.h"
|
||||
#include "hal/HALBase.h"
|
||||
#include "hal/handles/HandlesInternal.h"
|
||||
#include "hal/handles/LimitedHandleResource.h"
|
||||
|
||||
@@ -268,4 +270,19 @@ void HAL_SetInterruptUpSourceEdge(HAL_InterruptHandle interruptHandle,
|
||||
anInterrupt->anInterrupt->writeConfig_FallingEdge(fallingEdge, status);
|
||||
}
|
||||
|
||||
void HAL_ReleaseWaitingInterrupt(HAL_InterruptHandle interruptHandle,
|
||||
int32_t* status) {
|
||||
auto anInterrupt = interruptHandles->Get(interruptHandle);
|
||||
if (anInterrupt == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t interruptIndex =
|
||||
static_cast<uint32_t>(getHandleIndex(interruptHandle));
|
||||
|
||||
hal::ReleaseFPGAInterrupt(interruptIndex);
|
||||
hal::ReleaseFPGAInterrupt(interruptIndex + 8);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -631,12 +631,21 @@ int32_t HAL_GetSPIAutoDroppedCount(HAL_SPIPort port, int32_t* status) {
|
||||
return spiSystem->readTransferSkippedFullCount(status);
|
||||
}
|
||||
|
||||
// These 2 functions are so the new stall functionality
|
||||
// can be tested. How they're used is not very clear
|
||||
// but I want them to be testable so we can add an impl.
|
||||
// We will not be including these in the headers
|
||||
void* HAL_GetSPIDMAManager() { return spiAutoDMA.get(); }
|
||||
void HAL_ConfigureSPIAutoStall(HAL_SPIPort port, int32_t csToSclkTicks,
|
||||
int32_t stallTicks, int32_t pow2BytesPerRead,
|
||||
int32_t* status) {
|
||||
std::scoped_lock lock(spiAutoMutex);
|
||||
// FPGA only has one auto SPI engine
|
||||
if (port != spiAutoPort) {
|
||||
*status = INCOMPATIBLE_STATE;
|
||||
return;
|
||||
}
|
||||
|
||||
void* HAL_GetSPISystem() { return spiSystem.get(); }
|
||||
tSPI::tStallConfig stallConfig;
|
||||
stallConfig.CsToSclkTicks = static_cast<uint8_t>(csToSclkTicks);
|
||||
stallConfig.StallTicks = static_cast<uint16_t>(stallTicks);
|
||||
stallConfig.Pow2BytesPerRead = static_cast<uint8_t>(pow2BytesPerRead);
|
||||
spiSystem->writeStallConfig(stallConfig, status);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -448,6 +448,21 @@ Java_edu_wpi_first_hal_HAL_sendError
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_HAL
|
||||
* Method: sendConsoleLine
|
||||
* Signature: (Ljava/lang/String;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_HAL_sendConsoleLine
|
||||
(JNIEnv* env, jclass, jstring line)
|
||||
{
|
||||
JStringRef lineStr{env, line};
|
||||
|
||||
jint returnValue = HAL_SendConsoleLine(lineStr.c_str());
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_HAL
|
||||
* Method: getPortWithModule
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -294,4 +294,19 @@ Java_edu_wpi_first_hal_InterruptJNI_setInterruptUpSourceEdge
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_InterruptJNI
|
||||
* Method: releaseWaitingInterrupt
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_InterruptJNI_releaseWaitingInterrupt
|
||||
(JNIEnv* env, jclass, jint interruptHandle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_ReleaseWaitingInterrupt((HAL_InterruptHandle)interruptHandle, &status);
|
||||
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -394,4 +394,20 @@ Java_edu_wpi_first_hal_SPIJNI_spiGetAutoDroppedCount
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_SPIJNI
|
||||
* Method: spiConfigureAutoStall
|
||||
* Signature: (IIII)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_SPIJNI_spiConfigureAutoStall
|
||||
(JNIEnv* env, jclass, jint port, jint csToSclkTicks, jint stallTicks,
|
||||
jint pow2BytesPerRead)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_ConfigureSPIAutoStall(static_cast<HAL_SPIPort>(port), csToSclkTicks,
|
||||
stallTicks, pow2BytesPerRead, &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tDutyCycle.h>
|
||||
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tEncoder.h>
|
||||
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tGlobal.h>
|
||||
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tHMB.h>
|
||||
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tInterrupt.h>
|
||||
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tLED.h>
|
||||
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tPWM.h>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2013-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2013-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -37,6 +37,12 @@ extern "C" {
|
||||
int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
|
||||
const char* details, const char* location,
|
||||
const char* callStack, HAL_Bool printMsg);
|
||||
/**
|
||||
* Sends a line to the driver station console.
|
||||
*
|
||||
* @param line the line to send (null terminated)
|
||||
*/
|
||||
int32_t HAL_SendConsoleLine(const char* line);
|
||||
|
||||
/**
|
||||
* Gets the current control word of the driver station.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -153,6 +153,16 @@ void HAL_AttachInterruptHandlerThreaded(HAL_InterruptHandle interruptHandle,
|
||||
void HAL_SetInterruptUpSourceEdge(HAL_InterruptHandle interruptHandle,
|
||||
HAL_Bool risingEdge, HAL_Bool fallingEdge,
|
||||
int32_t* status);
|
||||
|
||||
/**
|
||||
* Releases a waiting interrupt.
|
||||
*
|
||||
* This will release both rising and falling waiters.
|
||||
*
|
||||
* @param interruptHandle the interrupt handle to release
|
||||
*/
|
||||
void HAL_ReleaseWaitingInterrupt(HAL_InterruptHandle interruptHandle,
|
||||
int32_t* status);
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -244,6 +244,19 @@ int32_t HAL_ReadSPIAutoReceivedData(HAL_SPIPort port, uint32_t* buffer,
|
||||
*/
|
||||
int32_t HAL_GetSPIAutoDroppedCount(HAL_SPIPort port, int32_t* status);
|
||||
|
||||
/**
|
||||
* Configure the Auto SPI Stall time between reads.
|
||||
*
|
||||
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for
|
||||
* MXP.
|
||||
* @param csToSclkTicks the number of ticks to wait before asserting the cs pin
|
||||
* @param stallTicks the number of ticks to stall for
|
||||
* @param pow2BytesPerRead the number of bytes to read before stalling
|
||||
*/
|
||||
void HAL_ConfigureSPIAutoStall(HAL_SPIPort port, int32_t csToSclkTicks,
|
||||
int32_t stallTicks, int32_t pow2BytesPerRead,
|
||||
int32_t* status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -24,4 +24,7 @@ typedef int32_t (*HALSIM_SendErrorHandler)(
|
||||
const char* location, const char* callStack, HAL_Bool printMsg);
|
||||
void HALSIM_SetSendError(HALSIM_SendErrorHandler handler);
|
||||
|
||||
typedef int32_t (*HALSIM_SendConsoleLineHandler)(const char* line);
|
||||
void HALSIM_SetSendConsoleLine(HALSIM_SendConsoleLineHandler handler);
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -74,7 +74,11 @@ class SimCallbackRegistry : public impl::SimCallbackRegistryBase {
|
||||
|
||||
template <typename... U>
|
||||
void Invoke(U&&... u) const {
|
||||
#ifdef _MSC_VER // work around VS2019 16.4.0 bug
|
||||
std::scoped_lock<wpi::recursive_spinlock> lock(m_mutex);
|
||||
#else
|
||||
std::scoped_lock lock(m_mutex);
|
||||
#endif
|
||||
if (m_callbacks) {
|
||||
const char* name = GetName();
|
||||
for (auto&& cb : *m_callbacks)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <wpi/condition_variable.h>
|
||||
#include <wpi/mutex.h>
|
||||
#include <wpi/raw_ostream.h>
|
||||
|
||||
#include "HALInitializer.h"
|
||||
#include "mockdata/DriverStationDataInternal.h"
|
||||
@@ -29,6 +30,8 @@ static wpi::mutex newDSDataAvailableMutex;
|
||||
static int newDSDataAvailableCounter{0};
|
||||
static std::atomic_bool isFinalized{false};
|
||||
static std::atomic<HALSIM_SendErrorHandler> sendErrorHandler{nullptr};
|
||||
static std::atomic<HALSIM_SendConsoleLineHandler> sendConsoleLineHandler{
|
||||
nullptr};
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
@@ -47,6 +50,10 @@ void HALSIM_SetSendError(HALSIM_SendErrorHandler handler) {
|
||||
sendErrorHandler.store(handler);
|
||||
}
|
||||
|
||||
void HALSIM_SetSendConsoleLine(HALSIM_SendConsoleLineHandler handler) {
|
||||
sendConsoleLineHandler.store(handler);
|
||||
}
|
||||
|
||||
int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
|
||||
const char* details, const char* location,
|
||||
const char* callStack, HAL_Bool printMsg) {
|
||||
@@ -105,6 +112,16 @@ int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
|
||||
return retval;
|
||||
}
|
||||
|
||||
int32_t HAL_SendConsoleLine(const char* line) {
|
||||
auto handler = sendConsoleLineHandler.load();
|
||||
if (handler) {
|
||||
return handler(line);
|
||||
}
|
||||
wpi::outs() << line << "\n";
|
||||
wpi::outs().flush();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t HAL_GetControlWord(HAL_ControlWord* controlWord) {
|
||||
controlWord->enabled = SimDriverStationData->enabled;
|
||||
controlWord->autonomous = SimDriverStationData->autonomous;
|
||||
@@ -230,6 +247,10 @@ static int& GetThreadLocalLastCount() {
|
||||
return lastCount;
|
||||
}
|
||||
|
||||
void HAL_WaitForCachedControlData(void) {
|
||||
HAL_WaitForCachedControlDataTimeout(0);
|
||||
}
|
||||
|
||||
HAL_Bool HAL_WaitForCachedControlDataTimeout(double timeout) {
|
||||
int& lastCount = GetThreadLocalLastCount();
|
||||
std::unique_lock lock(newDSDataAvailableMutex);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -566,4 +566,9 @@ void HAL_SetInterruptUpSourceEdge(HAL_InterruptHandle interruptHandle,
|
||||
interrupt->fireOnDown = fallingEdge;
|
||||
interrupt->fireOnUp = risingEdge;
|
||||
}
|
||||
|
||||
void HAL_ReleaseWaitingInterrupt(HAL_InterruptHandle interruptHandle,
|
||||
int32_t* status) {
|
||||
// Requires a fairly large rewrite to get working
|
||||
}
|
||||
} // extern "C"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -17,7 +17,7 @@ constexpr int32_t kNumAnalogOutputs = 2;
|
||||
constexpr int32_t kNumCounters = 8;
|
||||
constexpr int32_t kNumDigitalHeaders = 10;
|
||||
constexpr int32_t kNumPWMHeaders = 10;
|
||||
constexpr int32_t kNumDigitalChannels = 26;
|
||||
constexpr int32_t kNumDigitalChannels = 31;
|
||||
constexpr int32_t kNumPWMChannels = 20;
|
||||
constexpr int32_t kNumDigitalPWMOutputs = 6;
|
||||
constexpr int32_t kNumEncoders = 8;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -18,6 +18,8 @@ void InitializeSPI() {}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
extern "C" {
|
||||
|
||||
void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) {
|
||||
hal::init::CheckInit();
|
||||
SimSPIData[port].initialized = true;
|
||||
@@ -63,3 +65,9 @@ int32_t HAL_ReadSPIAutoReceivedData(HAL_SPIPort port, uint32_t* buffer,
|
||||
int32_t HAL_GetSPIAutoDroppedCount(HAL_SPIPort port, int32_t* status) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void HAL_ConfigureSPIAutoStall(HAL_SPIPort port, int32_t csToSclkTicks,
|
||||
int32_t stallTicks, int32_t pow2BytesPerRead,
|
||||
int32_t* status) {}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "CallbackStore.h"
|
||||
#include "edu_wpi_first_hal_sim_mockdata_DriverStationDataJNI.h"
|
||||
#include "mockdata/DriverStationData.h"
|
||||
#include "mockdata/MockHooks.h"
|
||||
|
||||
using namespace wpi::java;
|
||||
|
||||
@@ -446,6 +447,41 @@ Java_edu_wpi_first_hal_sim_mockdata_DriverStationDataJNI_notifyNewData
|
||||
HALSIM_NotifyDriverStationNewData();
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_sim_mockdata_DriverStationDataJNI
|
||||
* Method: setSendError
|
||||
* Signature: (Z)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_sim_mockdata_DriverStationDataJNI_setSendError
|
||||
(JNIEnv*, jclass, jboolean shouldSend)
|
||||
{
|
||||
if (shouldSend) {
|
||||
HALSIM_SetSendError(nullptr);
|
||||
} else {
|
||||
HALSIM_SetSendError([](HAL_Bool isError, int32_t errorCode,
|
||||
HAL_Bool isLVCode, const char* details,
|
||||
const char* location, const char* callStack,
|
||||
HAL_Bool printMsg) { return 0; });
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_sim_mockdata_DriverStationDataJNI
|
||||
* Method: setSendConsoleLine
|
||||
* Signature: (Z)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_sim_mockdata_DriverStationDataJNI_setSendConsoleLine
|
||||
(JNIEnv*, jclass, jboolean shouldSend)
|
||||
{
|
||||
if (shouldSend) {
|
||||
HALSIM_SetSendConsoleLine(nullptr);
|
||||
} else {
|
||||
HALSIM_SetSendConsoleLine([](const char* line) { return 0; });
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_sim_mockdata_DriverStationDataJNI
|
||||
* Method: resetData
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -22,17 +22,17 @@ void InitializeRoboRioData() {
|
||||
RoboRioData* hal::SimRoboRioData;
|
||||
void RoboRioData::ResetData() {
|
||||
fpgaButton.Reset(false);
|
||||
vInVoltage.Reset(0.0);
|
||||
vInVoltage.Reset(12.0);
|
||||
vInCurrent.Reset(0.0);
|
||||
userVoltage6V.Reset(6.0);
|
||||
userCurrent6V.Reset(0.0);
|
||||
userActive6V.Reset(false);
|
||||
userActive6V.Reset(true);
|
||||
userVoltage5V.Reset(5.0);
|
||||
userCurrent5V.Reset(0.0);
|
||||
userActive5V.Reset(false);
|
||||
userActive5V.Reset(true);
|
||||
userVoltage3V3.Reset(3.3);
|
||||
userCurrent3V3.Reset(0.0);
|
||||
userActive3V3.Reset(false);
|
||||
userActive3V3.Reset(true);
|
||||
userFaults6V.Reset(0);
|
||||
userFaults5V.Reset(0);
|
||||
userFaults3V3.Reset(0);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -30,22 +30,22 @@ class RoboRioData {
|
||||
|
||||
public:
|
||||
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetFPGAButtonName> fpgaButton{false};
|
||||
SimDataValue<double, HAL_MakeDouble, GetVInVoltageName> vInVoltage{0.0};
|
||||
SimDataValue<double, HAL_MakeDouble, GetVInVoltageName> vInVoltage{12.0};
|
||||
SimDataValue<double, HAL_MakeDouble, GetVInCurrentName> vInCurrent{0.0};
|
||||
SimDataValue<double, HAL_MakeDouble, GetUserVoltage6VName> userVoltage6V{6.0};
|
||||
SimDataValue<double, HAL_MakeDouble, GetUserCurrent6VName> userCurrent6V{0.0};
|
||||
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetUserActive6VName> userActive6V{
|
||||
false};
|
||||
true};
|
||||
SimDataValue<double, HAL_MakeDouble, GetUserVoltage5VName> userVoltage5V{5.0};
|
||||
SimDataValue<double, HAL_MakeDouble, GetUserCurrent5VName> userCurrent5V{0.0};
|
||||
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetUserActive5VName> userActive5V{
|
||||
false};
|
||||
true};
|
||||
SimDataValue<double, HAL_MakeDouble, GetUserVoltage3V3Name> userVoltage3V3{
|
||||
3.3};
|
||||
SimDataValue<double, HAL_MakeDouble, GetUserCurrent3V3Name> userCurrent3V3{
|
||||
0.0};
|
||||
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetUserActive3V3Name> userActive3V3{
|
||||
false};
|
||||
true};
|
||||
SimDataValue<int32_t, HAL_MakeInt, GetUserFaults6VName> userFaults6V{0};
|
||||
SimDataValue<int32_t, HAL_MakeInt, GetUserFaults5VName> userFaults5V{0};
|
||||
SimDataValue<int32_t, HAL_MakeInt, GetUserFaults3V3Name> userFaults3V3{0};
|
||||
|
||||
@@ -32,6 +32,11 @@ file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/imgui_ProggyDotted.h
|
||||
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/imgui_ProggyDotted.cpp
|
||||
PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ProggyDotted.inc)
|
||||
|
||||
# stb_image
|
||||
file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/stb_image.cpp
|
||||
CONTENT "#define STBI_WINDOWS_UTF8\n#define STB_IMAGE_IMPLEMENTATION\n#include \"stb_image.h\"\n"
|
||||
)
|
||||
|
||||
# Add imgui directly to our build.
|
||||
set(SAVE_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
|
||||
set(BUILD_SHARED_LIBS OFF)
|
||||
@@ -46,8 +51,8 @@ add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/gl3w-src
|
||||
|
||||
set(imgui_srcdir ${CMAKE_CURRENT_BINARY_DIR}/imgui-src)
|
||||
file(GLOB imgui_sources ${imgui_srcdir}/*.cpp)
|
||||
add_library(imgui STATIC ${imgui_sources} ${imgui_srcdir}/examples/imgui_impl_glfw.cpp ${imgui_srcdir}/examples/imgui_impl_opengl3.cpp ${CMAKE_CURRENT_BINARY_DIR}/imgui_ProggyDotted.cpp)
|
||||
add_library(imgui STATIC ${imgui_sources} ${imgui_srcdir}/examples/imgui_impl_glfw.cpp ${imgui_srcdir}/examples/imgui_impl_opengl3.cpp ${CMAKE_CURRENT_BINARY_DIR}/imgui_ProggyDotted.cpp ${CMAKE_CURRENT_BINARY_DIR}/stb_image.cpp)
|
||||
target_link_libraries(imgui PUBLIC gl3w glfw)
|
||||
target_include_directories(imgui PUBLIC "$<BUILD_INTERFACE:${imgui_srcdir}>" "$<BUILD_INTERFACE:${imgui_srcdir}/examples>" "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>")
|
||||
target_include_directories(imgui PUBLIC "$<BUILD_INTERFACE:${imgui_srcdir}>" "$<BUILD_INTERFACE:${imgui_srcdir}/examples>" "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>" "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/stb-src>")
|
||||
|
||||
set_property(TARGET imgui PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
@@ -41,3 +41,13 @@ ExternalProject_Add(proggyfonts
|
||||
INSTALL_COMMAND ""
|
||||
TEST_COMMAND ""
|
||||
)
|
||||
ExternalProject_Add(stb
|
||||
GIT_REPOSITORY https://github.com/nothings/stb.git
|
||||
GIT_TAG f67165c2bb2af3060ecae7d20d6f731173485ad0
|
||||
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/stb-src"
|
||||
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/stb-build"
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND ""
|
||||
TEST_COMMAND ""
|
||||
)
|
||||
|
||||
@@ -44,6 +44,7 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
public static final int kNetModeClient = 0x02;
|
||||
public static final int kNetModeStarting = 0x04;
|
||||
public static final int kNetModeFailure = 0x08;
|
||||
public static final int kNetModeLocal = 0x10;
|
||||
|
||||
/**
|
||||
* The default port that network tables operates on.
|
||||
@@ -675,6 +676,23 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
return NetworkTablesJNI.getNetworkMode(m_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts local-only operation. Prevents calls to startServer or startClient
|
||||
* from taking effect. Has no effect if startServer or startClient
|
||||
* has already been called.
|
||||
*/
|
||||
public void startLocal() {
|
||||
NetworkTablesJNI.startLocal(m_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops local-only operation. startServer or startClient can be called after
|
||||
* this call to start a server or client.
|
||||
*/
|
||||
public void stopLocal() {
|
||||
NetworkTablesJNI.stopLocal(m_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a server using the networktables.ini as the persistent file,
|
||||
* using the default listening address and port.
|
||||
|
||||
@@ -139,6 +139,8 @@ public final class NetworkTablesJNI {
|
||||
|
||||
public static native void setNetworkIdentity(int inst, String name);
|
||||
public static native int getNetworkMode(int inst);
|
||||
public static native void startLocal(int inst);
|
||||
public static native void stopLocal(int inst);
|
||||
public static native void startServer(int inst, String persistFilename, String listenAddress, int port);
|
||||
public static native void stopServer(int inst);
|
||||
public static native void startClient(int inst);
|
||||
|
||||
@@ -115,6 +115,16 @@ DispatcherBase::~DispatcherBase() { Stop(); }
|
||||
|
||||
unsigned int DispatcherBase::GetNetworkMode() const { return m_networkMode; }
|
||||
|
||||
void DispatcherBase::StartLocal() {
|
||||
{
|
||||
std::scoped_lock lock(m_user_mutex);
|
||||
if (m_active) return;
|
||||
m_active = true;
|
||||
}
|
||||
m_networkMode = NT_NET_MODE_LOCAL;
|
||||
m_storage.SetDispatcher(this, false);
|
||||
}
|
||||
|
||||
void DispatcherBase::StartServer(
|
||||
const Twine& persist_filename,
|
||||
std::unique_ptr<wpi::NetworkAcceptor> acceptor) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2015-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -48,6 +48,7 @@ class DispatcherBase : public IDispatcher {
|
||||
virtual ~DispatcherBase();
|
||||
|
||||
unsigned int GetNetworkMode() const;
|
||||
void StartLocal();
|
||||
void StartServer(const Twine& persist_filename,
|
||||
std::unique_ptr<wpi::NetworkAcceptor> acceptor);
|
||||
void StartClient();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -1368,6 +1368,30 @@ Java_edu_wpi_first_networktables_NetworkTablesJNI_getNetworkMode
|
||||
return nt::GetNetworkMode(inst);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_networktables_NetworkTablesJNI
|
||||
* Method: startLocal
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_networktables_NetworkTablesJNI_startLocal
|
||||
(JNIEnv*, jclass, jint inst)
|
||||
{
|
||||
nt::StartLocal(inst);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_networktables_NetworkTablesJNI
|
||||
* Method: stopLocal
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_networktables_NetworkTablesJNI_stopLocal
|
||||
(JNIEnv*, jclass, jint inst)
|
||||
{
|
||||
nt::StopLocal(inst);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_networktables_NetworkTablesJNI
|
||||
* Method: startServer
|
||||
|
||||
@@ -539,6 +539,10 @@ unsigned int NT_GetNetworkMode(NT_Inst inst) {
|
||||
return nt::GetNetworkMode(inst);
|
||||
}
|
||||
|
||||
void NT_StartLocal(NT_Inst inst) { nt::StartLocal(inst); }
|
||||
|
||||
void NT_StopLocal(NT_Inst inst) { nt::StopLocal(inst); }
|
||||
|
||||
void NT_StartServer(NT_Inst inst, const char* persist_filename,
|
||||
const char* listen_address, unsigned int port) {
|
||||
nt::StartServer(inst, persist_filename, listen_address, port);
|
||||
|
||||
@@ -742,6 +742,20 @@ unsigned int GetNetworkMode(NT_Inst inst) {
|
||||
return ii->dispatcher.GetNetworkMode();
|
||||
}
|
||||
|
||||
void StartLocal(NT_Inst inst) {
|
||||
auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance));
|
||||
if (!ii) return;
|
||||
|
||||
ii->dispatcher.StartLocal();
|
||||
}
|
||||
|
||||
void StopLocal(NT_Inst inst) {
|
||||
auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance));
|
||||
if (!ii) return;
|
||||
|
||||
ii->dispatcher.Stop();
|
||||
}
|
||||
|
||||
void StartServer(StringRef persist_filename, const char* listen_address,
|
||||
unsigned int port) {
|
||||
auto ii = InstanceImpl::GetDefault();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -61,7 +61,8 @@ class NetworkTableInstance final {
|
||||
kNetModeServer = NT_NET_MODE_SERVER,
|
||||
kNetModeClient = NT_NET_MODE_CLIENT,
|
||||
kNetModeStarting = NT_NET_MODE_STARTING,
|
||||
kNetModeFailure = NT_NET_MODE_FAILURE
|
||||
kNetModeFailure = NT_NET_MODE_FAILURE,
|
||||
kNetModeLocal = NT_NET_MODE_LOCAL
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -298,6 +299,19 @@ class NetworkTableInstance final {
|
||||
*/
|
||||
unsigned int GetNetworkMode() const;
|
||||
|
||||
/**
|
||||
* Starts local-only operation. Prevents calls to StartServer or StartClient
|
||||
* from taking effect. Has no effect if StartServer or StartClient
|
||||
* has already been called.
|
||||
*/
|
||||
void StartLocal();
|
||||
|
||||
/**
|
||||
* Stops local-only operation. StartServer or StartClient can be called after
|
||||
* this call to start a server or client.
|
||||
*/
|
||||
void StopLocal();
|
||||
|
||||
/**
|
||||
* Starts a server using the specified filename, listening address, and port.
|
||||
*
|
||||
|
||||
@@ -81,6 +81,10 @@ inline unsigned int NetworkTableInstance::GetNetworkMode() const {
|
||||
return ::nt::GetNetworkMode(m_handle);
|
||||
}
|
||||
|
||||
inline void NetworkTableInstance::StartLocal() { ::nt::StartLocal(m_handle); }
|
||||
|
||||
inline void NetworkTableInstance::StopLocal() { ::nt::StopLocal(m_handle); }
|
||||
|
||||
inline void NetworkTableInstance::StartServer(const Twine& persist_filename,
|
||||
const char* listen_address,
|
||||
unsigned int port) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2015-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -95,6 +95,7 @@ enum NT_NetworkMode {
|
||||
NT_NET_MODE_CLIENT = 0x02, /* running in client mode */
|
||||
NT_NET_MODE_STARTING = 0x04, /* flag for starting (either client or server) */
|
||||
NT_NET_MODE_FAILURE = 0x08, /* flag for failure (either client or server) */
|
||||
NT_NET_MODE_LOCAL = 0x10, /* running in local-only mode */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -1037,6 +1038,19 @@ void NT_SetNetworkIdentity(NT_Inst inst, const char* name, size_t name_len);
|
||||
*/
|
||||
unsigned int NT_GetNetworkMode(NT_Inst inst);
|
||||
|
||||
/**
|
||||
* Starts local-only operation. Prevents calls to NT_StartServer or
|
||||
* NT_StartClient from taking effect. Has no effect if NT_StartServer or
|
||||
* NT_StartClient has already been called.
|
||||
*/
|
||||
void NT_StartLocal(NT_Inst inst);
|
||||
|
||||
/**
|
||||
* Stops local-only operation. NT_StartServer or NT_StartClient can be called
|
||||
* after this call to start a server or client.
|
||||
*/
|
||||
void NT_StopLocal(NT_Inst inst);
|
||||
|
||||
/**
|
||||
* Starts a server using the specified filename, listening address, and port.
|
||||
*
|
||||
|
||||
@@ -1130,6 +1130,19 @@ unsigned int GetNetworkMode();
|
||||
*/
|
||||
unsigned int GetNetworkMode(NT_Inst inst);
|
||||
|
||||
/**
|
||||
* Starts local-only operation. Prevents calls to StartServer or StartClient
|
||||
* from taking effect. Has no effect if StartServer or StartClient
|
||||
* has already been called.
|
||||
*/
|
||||
void StartLocal(NT_Inst inst);
|
||||
|
||||
/**
|
||||
* Stops local-only operation. StartServer or StartClient can be called after
|
||||
* this call to start a server or client.
|
||||
*/
|
||||
void StopLocal(NT_Inst inst);
|
||||
|
||||
/**
|
||||
* Starts a server using the specified filename, listening address, and port.
|
||||
*
|
||||
|
||||
@@ -8,10 +8,10 @@ nativeUtils {
|
||||
wpi {
|
||||
configureDependencies {
|
||||
wpiVersion = "-1"
|
||||
niLibVersion = "2020.9.1"
|
||||
niLibVersion = "2020.10.1"
|
||||
opencvVersion = "3.4.7-2"
|
||||
googleTestVersion = "1.9.0-3-437e100"
|
||||
imguiVersion = "1.72b-2"
|
||||
googleTestVersion = "1.9.0-4-437e100-1"
|
||||
imguiVersion = "1.72b-3"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,10 @@ nativeUtils.wpi.addWarningsAsErrors()
|
||||
|
||||
nativeUtils.setSinglePrintPerPlatform()
|
||||
|
||||
nativeUtils.platformConfigs.named("osxx86-64").configure {
|
||||
it.linker.args << "-headerpad_max_install_names"
|
||||
}
|
||||
|
||||
model {
|
||||
components {
|
||||
all {
|
||||
|
||||
21
shared/cppDesktopTestTask.gradle
Normal file
21
shared/cppDesktopTestTask.gradle
Normal file
@@ -0,0 +1,21 @@
|
||||
model {
|
||||
tasks {
|
||||
def ts = $.testSuites
|
||||
project.tasks.register('testDesktopCpp') { testTask->
|
||||
def systemArch = getCurrentArch()
|
||||
def found = false
|
||||
ts.each {
|
||||
if (it in GoogleTestTestSuiteSpec && it.name == "${nativeName}Test") {
|
||||
it.binaries.each {
|
||||
if (found) return
|
||||
def arch = it.targetPlatform.name
|
||||
if (arch == systemArch && it.buildType.name == 'debug') {
|
||||
testTask.dependsOn it.tasks.run
|
||||
found = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,6 +70,7 @@ task checkCommands(type: Task) {
|
||||
assert it.tags != null
|
||||
assert it.foldername != null
|
||||
assert it.replacename != null
|
||||
assert it.commandversion != null
|
||||
if (project.isCppCommands) {
|
||||
assert it.headers != null
|
||||
assert !it.headers.isEmpty()
|
||||
|
||||
3
shared/javaDesktopTestTask.gradle
Normal file
3
shared/javaDesktopTestTask.gradle
Normal file
@@ -0,0 +1,3 @@
|
||||
tasks.register('testDesktopJava') {
|
||||
dependsOn test
|
||||
}
|
||||
@@ -141,6 +141,9 @@ model {
|
||||
}
|
||||
}
|
||||
|
||||
apply from: "${rootDir}/shared/cppDesktopTestTask.gradle"
|
||||
apply from: "${rootDir}/shared/javaDesktopTestTask.gradle"
|
||||
|
||||
tasks.withType(RunTestExecutable) {
|
||||
args "--gtest_output=xml:test_detail.xml"
|
||||
outputs.dir outputDir
|
||||
|
||||
@@ -275,6 +275,9 @@ model {
|
||||
}
|
||||
}
|
||||
|
||||
apply from: "${rootDir}/shared/cppDesktopTestTask.gradle"
|
||||
apply from: "${rootDir}/shared/javaDesktopTestTask.gradle"
|
||||
|
||||
ext.getJniSpecClass = {
|
||||
return JniNativeLibrarySpec
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -7,10 +7,6 @@
|
||||
|
||||
#include "AddressableLEDGui.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include <hal/Ports.h>
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
@@ -20,77 +16,55 @@
|
||||
|
||||
#include "ExtraGuiWidgets.h"
|
||||
#include "HALSimGui.h"
|
||||
#include "IniSaver.h"
|
||||
#include "IniSaverInfo.h"
|
||||
|
||||
using namespace halsimgui;
|
||||
|
||||
namespace {
|
||||
struct LEDDisplaySettings {
|
||||
struct LEDDisplayInfo {
|
||||
int numColumns = 10;
|
||||
LEDConfig config;
|
||||
|
||||
bool ReadIni(wpi::StringRef name, wpi::StringRef value);
|
||||
void WriteIni(ImGuiTextBuffer* out);
|
||||
};
|
||||
} // namespace
|
||||
|
||||
static std::vector<LEDDisplaySettings> displaySettings;
|
||||
static IniSaver<LEDDisplayInfo> gDisplaySettings{"AddressableLED"};
|
||||
|
||||
// read/write columns setting to ini file
|
||||
static void* AddressableLEDReadOpen(ImGuiContext* ctx,
|
||||
ImGuiSettingsHandler* handler,
|
||||
const char* name) {
|
||||
int num;
|
||||
if (wpi::StringRef{name}.getAsInteger(10, num)) return nullptr;
|
||||
if (num < 0) return nullptr;
|
||||
if (num >= static_cast<int>(displaySettings.size()))
|
||||
displaySettings.resize(num + 1);
|
||||
return &displaySettings[num];
|
||||
}
|
||||
|
||||
static void AddressableLEDReadLine(ImGuiContext* ctx,
|
||||
ImGuiSettingsHandler* handler, void* entry,
|
||||
const char* lineStr) {
|
||||
auto* settings = static_cast<LEDDisplaySettings*>(entry);
|
||||
// format: columns=#
|
||||
wpi::StringRef line{lineStr};
|
||||
auto [name, value] = line.split('=');
|
||||
name = name.trim();
|
||||
value = value.trim();
|
||||
bool LEDDisplayInfo::ReadIni(wpi::StringRef name, wpi::StringRef value) {
|
||||
if (name == "columns") {
|
||||
int num;
|
||||
if (value.getAsInteger(10, num)) return;
|
||||
settings->numColumns = num;
|
||||
if (value.getAsInteger(10, num)) return true;
|
||||
numColumns = num;
|
||||
} else if (name == "serpentine") {
|
||||
int num;
|
||||
if (value.getAsInteger(10, num)) return;
|
||||
settings->config.serpentine = num != 0;
|
||||
if (value.getAsInteger(10, num)) return true;
|
||||
config.serpentine = num != 0;
|
||||
} else if (name == "order") {
|
||||
int num;
|
||||
if (value.getAsInteger(10, num)) return;
|
||||
settings->config.order = static_cast<LEDConfig::Order>(num);
|
||||
if (value.getAsInteger(10, num)) return true;
|
||||
config.order = static_cast<LEDConfig::Order>(num);
|
||||
} else if (name == "start") {
|
||||
int num;
|
||||
if (value.getAsInteger(10, num)) return;
|
||||
settings->config.start = static_cast<LEDConfig::Start>(num);
|
||||
if (value.getAsInteger(10, num)) return true;
|
||||
config.start = static_cast<LEDConfig::Start>(num);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void AddressableLEDWriteAll(ImGuiContext* ctx,
|
||||
ImGuiSettingsHandler* handler,
|
||||
ImGuiTextBuffer* out_buf) {
|
||||
for (size_t i = 0; i < displaySettings.size(); ++i) {
|
||||
out_buf->appendf(
|
||||
"[AddressableLED][%d]\ncolumns=%d\nserpentine=%d\norder=%d\n"
|
||||
"start=%d\n\n",
|
||||
static_cast<int>(i), displaySettings[i].numColumns,
|
||||
displaySettings[i].config.serpentine ? 1 : 0,
|
||||
static_cast<int>(displaySettings[i].config.order),
|
||||
static_cast<int>(displaySettings[i].config.start));
|
||||
}
|
||||
void LEDDisplayInfo::WriteIni(ImGuiTextBuffer* out) {
|
||||
out->appendf("columns=%d\nserpentine=%d\norder=%d\nstart=%d\n", numColumns,
|
||||
config.serpentine ? 1 : 0, static_cast<int>(config.order),
|
||||
static_cast<int>(config.start));
|
||||
}
|
||||
|
||||
static void DisplayAddressableLEDs() {
|
||||
bool hasAny = false;
|
||||
static const int numLED = HAL_GetNumAddressableLEDs();
|
||||
if (numLED > static_cast<int>(displaySettings.size()))
|
||||
displaySettings.resize(numLED);
|
||||
|
||||
for (int i = 0; i < numLED; ++i) {
|
||||
if (!HALSIM_GetAddressableLEDInitialized(i)) continue;
|
||||
@@ -101,26 +75,27 @@ static void DisplayAddressableLEDs() {
|
||||
static HAL_AddressableLEDData data[HAL_kAddressableLEDMaxLength];
|
||||
int length = HALSIM_GetAddressableLEDData(i, data);
|
||||
bool running = HALSIM_GetAddressableLEDRunning(i);
|
||||
auto& info = gDisplaySettings[i];
|
||||
|
||||
ImGui::PushItemWidth(ImGui::GetFontSize() * 6);
|
||||
ImGui::LabelText("Length", "%d", length);
|
||||
ImGui::LabelText("Running", "%s", running ? "Yes" : "No");
|
||||
ImGui::InputInt("Columns", &displaySettings[i].numColumns);
|
||||
ImGui::InputInt("Columns", &info.numColumns);
|
||||
{
|
||||
static const char* options[] = {"Row Major", "Column Major"};
|
||||
int val = displaySettings[i].config.order;
|
||||
int val = info.config.order;
|
||||
if (ImGui::Combo("Order", &val, options, 2))
|
||||
displaySettings[i].config.order = static_cast<LEDConfig::Order>(val);
|
||||
info.config.order = static_cast<LEDConfig::Order>(val);
|
||||
}
|
||||
{
|
||||
static const char* options[] = {"Upper Left", "Lower Left", "Upper Right",
|
||||
"Lower Right"};
|
||||
int val = displaySettings[i].config.start;
|
||||
int val = info.config.start;
|
||||
if (ImGui::Combo("Start", &val, options, 4))
|
||||
displaySettings[i].config.start = static_cast<LEDConfig::Start>(val);
|
||||
info.config.start = static_cast<LEDConfig::Start>(val);
|
||||
}
|
||||
ImGui::Checkbox("Serpentine", &displaySettings[i].config.serpentine);
|
||||
if (displaySettings[i].numColumns < 1) displaySettings[i].numColumns = 1;
|
||||
ImGui::Checkbox("Serpentine", &info.config.serpentine);
|
||||
if (info.numColumns < 1) info.numColumns = 1;
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
// show as LED indicators
|
||||
@@ -137,22 +112,13 @@ static void DisplayAddressableLEDs() {
|
||||
}
|
||||
}
|
||||
|
||||
DrawLEDs(values, length, displaySettings[i].numColumns, colors, 0, 0,
|
||||
displaySettings[i].config);
|
||||
DrawLEDs(values, length, info.numColumns, colors, 0, 0, info.config);
|
||||
}
|
||||
if (!hasAny) ImGui::Text("No addressable LEDs");
|
||||
}
|
||||
|
||||
void AddressableLEDGui::Initialize() {
|
||||
// hook ini handler to save columns settings
|
||||
ImGuiSettingsHandler iniHandler;
|
||||
iniHandler.TypeName = "AddressableLED";
|
||||
iniHandler.TypeHash = ImHashStr(iniHandler.TypeName);
|
||||
iniHandler.ReadOpenFn = AddressableLEDReadOpen;
|
||||
iniHandler.ReadLineFn = AddressableLEDReadLine;
|
||||
iniHandler.WriteAllFn = AddressableLEDWriteAll;
|
||||
ImGui::GetCurrentContext()->SettingsHandlers.push_back(iniHandler);
|
||||
|
||||
gDisplaySettings.Initialize();
|
||||
HALSimGui::AddWindow("Addressable LEDs", DisplayAddressableLEDs,
|
||||
ImGuiWindowFlags_AlwaysAutoResize);
|
||||
HALSimGui::SetWindowVisibility("Addressable LEDs", HALSimGui::kHide);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -7,8 +7,6 @@
|
||||
|
||||
#include "AnalogInputGui.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <hal/Ports.h>
|
||||
#include <imgui.h>
|
||||
#include <mockdata/AnalogGyroData.h>
|
||||
@@ -16,19 +14,35 @@
|
||||
#include <mockdata/SimDeviceData.h>
|
||||
|
||||
#include "HALSimGui.h"
|
||||
#include "IniSaver.h"
|
||||
#include "IniSaverInfo.h"
|
||||
|
||||
using namespace halsimgui;
|
||||
|
||||
static IniSaver<NameInfo> gAnalogInputs{"AnalogInput"}; // indexed by channel
|
||||
|
||||
static void DisplayAnalogInputs() {
|
||||
ImGui::Text("(Use Ctrl+Click to edit value)");
|
||||
bool hasInputs = false;
|
||||
static int numAnalog = HAL_GetNumAnalogInputs();
|
||||
static int numAccum = HAL_GetNumAccumulators();
|
||||
bool first = true;
|
||||
for (int i = 0; i < numAnalog; ++i) {
|
||||
if (HALSIM_GetAnalogInInitialized(i)) {
|
||||
hasInputs = true;
|
||||
char name[32];
|
||||
std::snprintf(name, sizeof(name), "In[%d]", i);
|
||||
|
||||
if (!first) {
|
||||
ImGui::Spacing();
|
||||
ImGui::Spacing();
|
||||
} else {
|
||||
first = false;
|
||||
}
|
||||
|
||||
auto& info = gAnalogInputs[i];
|
||||
// build name
|
||||
char name[128];
|
||||
info.GetName(name, sizeof(name), "In", i);
|
||||
|
||||
if (i < numAccum && HALSIM_GetAnalogGyroInitialized(i)) {
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(96, 96, 96, 255));
|
||||
ImGui::LabelText(name, "AnalogGyro[%d]", i);
|
||||
@@ -42,12 +56,16 @@ static void DisplayAnalogInputs() {
|
||||
if (ImGui::SliderFloat(name, &val, 0.0, 5.0))
|
||||
HALSIM_SetAnalogInVoltage(i, val);
|
||||
}
|
||||
|
||||
// context menu to change name
|
||||
info.PopupEditName(i);
|
||||
}
|
||||
}
|
||||
if (!hasInputs) ImGui::Text("No analog inputs");
|
||||
}
|
||||
|
||||
void AnalogInputGui::Initialize() {
|
||||
gAnalogInputs.Initialize();
|
||||
HALSimGui::AddWindow("Analog Inputs", DisplayAnalogInputs,
|
||||
ImGuiWindowFlags_AlwaysAutoResize);
|
||||
HALSimGui::SetDefaultWindowPos("Analog Inputs", 640, 20);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -7,18 +7,18 @@
|
||||
|
||||
#include "AnalogOutGui.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
#include <hal/Ports.h>
|
||||
#include <imgui.h>
|
||||
#include <mockdata/AnalogOutData.h>
|
||||
|
||||
#include "IniSaver.h"
|
||||
#include "IniSaverInfo.h"
|
||||
#include "SimDeviceGui.h"
|
||||
|
||||
using namespace halsimgui;
|
||||
|
||||
static IniSaver<NameInfo> gAnalogOuts{"AnalogOut"}; // indexed by channel
|
||||
|
||||
static void DisplayAnalogOutputs() {
|
||||
static const int numAnalog = HAL_GetNumAnalogOutputs();
|
||||
static auto init = std::make_unique<bool[]>(numAnalog);
|
||||
@@ -34,14 +34,20 @@ static void DisplayAnalogOutputs() {
|
||||
if (SimDeviceGui::StartDevice("Analog Outputs")) {
|
||||
for (int i = 0; i < numAnalog; ++i) {
|
||||
if (!init[i]) continue;
|
||||
char name[32];
|
||||
std::snprintf(name, sizeof(name), "Out[%d]", i);
|
||||
|
||||
auto& info = gAnalogOuts[i];
|
||||
char name[128];
|
||||
info.GetName(name, sizeof(name), "Out", i);
|
||||
HAL_Value value = HAL_MakeDouble(HALSIM_GetAnalogOutVoltage(i));
|
||||
SimDeviceGui::DisplayValue(name, true, &value);
|
||||
info.PopupEditName(i);
|
||||
}
|
||||
|
||||
SimDeviceGui::FinishDevice();
|
||||
}
|
||||
}
|
||||
|
||||
void AnalogOutGui::Initialize() { SimDeviceGui::Add(DisplayAnalogOutputs); }
|
||||
void AnalogOutGui::Initialize() {
|
||||
gAnalogOuts.Initialize();
|
||||
SimDeviceGui::Add(DisplayAnalogOutputs);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -7,10 +7,6 @@
|
||||
|
||||
#include "DIOGui.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
#include <hal/Ports.h>
|
||||
#include <imgui.h>
|
||||
#include <mockdata/DIOData.h>
|
||||
@@ -20,9 +16,13 @@
|
||||
#include <mockdata/SimDeviceData.h>
|
||||
|
||||
#include "HALSimGui.h"
|
||||
#include "IniSaver.h"
|
||||
#include "IniSaverInfo.h"
|
||||
|
||||
using namespace halsimgui;
|
||||
|
||||
static IniSaver<NameInfo> gDIO{"DIO"};
|
||||
|
||||
static void LabelSimDevice(const char* name, HAL_SimDeviceHandle simDevice) {
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(96, 96, 96, 255));
|
||||
ImGui::LabelText(name, "%s", HALSIM_GetSimDeviceName(simDevice));
|
||||
@@ -71,9 +71,10 @@ static void DisplayDIO() {
|
||||
for (int i = 0; i < numDIO; ++i) {
|
||||
if (HALSIM_GetDIOInitialized(i)) {
|
||||
hasAny = true;
|
||||
char name[32];
|
||||
auto& info = gDIO[i];
|
||||
char name[128];
|
||||
if (pwmMap[i] > 0) {
|
||||
std::snprintf(name, sizeof(name), "PWM[%d]", i);
|
||||
info.GetName(name, sizeof(name), "PWM", i);
|
||||
if (auto simDevice = HALSIM_GetDIOSimDevice(i)) {
|
||||
LabelSimDevice(name, simDevice);
|
||||
} else {
|
||||
@@ -81,7 +82,7 @@ static void DisplayDIO() {
|
||||
HALSIM_GetDigitalPWMDutyCycle(pwmMap[i] - 1));
|
||||
}
|
||||
} else if (encoderMap[i] > 0) {
|
||||
std::snprintf(name, sizeof(name), " In[%d]", i);
|
||||
info.GetName(name, sizeof(name), " In", i);
|
||||
if (auto simDevice = HALSIM_GetEncoderSimDevice(encoderMap[i] - 1)) {
|
||||
LabelSimDevice(name, simDevice);
|
||||
} else {
|
||||
@@ -92,7 +93,7 @@ static void DisplayDIO() {
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
} else if (dutyCycleMap[i] > 0) {
|
||||
std::snprintf(name, sizeof(name), "PWM[%d]", i);
|
||||
info.GetName(name, sizeof(name), "Dty", i);
|
||||
if (auto simDevice =
|
||||
HALSIM_GetDutyCycleSimDevice(dutyCycleMap[i] - 1)) {
|
||||
LabelSimDevice(name, simDevice);
|
||||
@@ -102,7 +103,7 @@ static void DisplayDIO() {
|
||||
HALSIM_SetDutyCycleOutput(dutyCycleMap[i] - 1, val);
|
||||
}
|
||||
} else if (!HALSIM_GetDIOIsInput(i)) {
|
||||
std::snprintf(name, sizeof(name), "Out[%d]", i);
|
||||
info.GetName(name, sizeof(name), "Out", i);
|
||||
if (auto simDevice = HALSIM_GetDIOSimDevice(i)) {
|
||||
LabelSimDevice(name, simDevice);
|
||||
} else {
|
||||
@@ -110,7 +111,7 @@ static void DisplayDIO() {
|
||||
HALSIM_GetDIOValue(i) ? "1 (high)" : "0 (low)");
|
||||
}
|
||||
} else {
|
||||
std::snprintf(name, sizeof(name), " In[%d]", i);
|
||||
info.GetName(name, sizeof(name), " In", i);
|
||||
if (auto simDevice = HALSIM_GetDIOSimDevice(i)) {
|
||||
LabelSimDevice(name, simDevice);
|
||||
} else {
|
||||
@@ -119,6 +120,7 @@ static void DisplayDIO() {
|
||||
if (ImGui::Combo(name, &val, options, 2)) HALSIM_SetDIOValue(i, val);
|
||||
}
|
||||
}
|
||||
info.PopupEditName(i);
|
||||
}
|
||||
}
|
||||
ImGui::PopItemWidth();
|
||||
@@ -126,6 +128,7 @@ static void DisplayDIO() {
|
||||
}
|
||||
|
||||
void DIOGui::Initialize() {
|
||||
gDIO.Initialize();
|
||||
HALSimGui::AddWindow("DIO", DisplayDIO, ImGuiWindowFlags_AlwaysAutoResize);
|
||||
HALSimGui::SetDefaultWindowPos("DIO", 470, 20);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include "ExtraGuiWidgets.h"
|
||||
#include "HALSimGui.h"
|
||||
#include "IniSaverInfo.h"
|
||||
|
||||
using namespace halsimgui;
|
||||
|
||||
@@ -45,6 +46,7 @@ struct SystemJoystick {
|
||||
};
|
||||
|
||||
struct RobotJoystick {
|
||||
NameInfo name;
|
||||
std::string guid;
|
||||
const SystemJoystick* sys = nullptr;
|
||||
bool useGamepad = false;
|
||||
@@ -93,6 +95,8 @@ static void JoystickReadLine(ImGuiContext* ctx, ImGuiSettingsHandler* handler,
|
||||
int num;
|
||||
if (value.getAsInteger(10, num)) return;
|
||||
joy->useGamepad = num;
|
||||
} else {
|
||||
joy->name.ReadIni(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,11 +104,15 @@ static void JoystickWriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler,
|
||||
ImGuiTextBuffer* out_buf) {
|
||||
for (int i = 0; i < HAL_kMaxJoysticks; ++i) {
|
||||
auto& joy = gRobotJoysticks[i];
|
||||
if (!joy.sys) continue;
|
||||
const char* guid = glfwGetJoystickGUID(joy.sys - gSystemJoysticks);
|
||||
if (!guid) continue;
|
||||
out_buf->appendf("[Joystick][%d]\nguid=%s\nuseGamepad=%d\n\n", i, guid,
|
||||
if (!joy.name.HasName() && !joy.sys) continue;
|
||||
out_buf->appendf("[Joystick][%d]\nuseGamepad=%d\n", i,
|
||||
joy.useGamepad ? 1 : 0);
|
||||
if (joy.name.HasName()) joy.name.WriteIni(out_buf);
|
||||
if (joy.sys) {
|
||||
const char* guid = glfwGetJoystickGUID(joy.sys - gSystemJoysticks);
|
||||
if (guid) out_buf->appendf("guid=%s\n", guid);
|
||||
}
|
||||
out_buf->append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -426,8 +434,8 @@ static void DisplayJoysticks() {
|
||||
ImGui::Columns(HAL_kMaxJoysticks, "Joysticks", false);
|
||||
for (int i = 0; i < HAL_kMaxJoysticks; ++i) {
|
||||
auto& joy = gRobotJoysticks[i];
|
||||
char label[30];
|
||||
std::snprintf(label, sizeof(label), "Joystick %d", i);
|
||||
char label[128];
|
||||
joy.name.GetName(label, sizeof(label), "Joystick", i);
|
||||
if (joy.sys) {
|
||||
ImGui::Selectable(label, false);
|
||||
if (ImGui::BeginDragDropSource()) {
|
||||
@@ -455,6 +463,7 @@ static void DisplayJoysticks() {
|
||||
}
|
||||
ImGui::EndDragDropTarget();
|
||||
}
|
||||
joy.name.PopupEditName(i);
|
||||
ImGui::NextColumn();
|
||||
}
|
||||
ImGui::Separator();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -7,49 +7,32 @@
|
||||
|
||||
#include "EncoderGui.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <hal/Ports.h>
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
#include <mockdata/EncoderData.h>
|
||||
#include <mockdata/SimDeviceData.h>
|
||||
#include <wpi/DenseMap.h>
|
||||
#include <wpi/StringRef.h>
|
||||
|
||||
#include "HALSimGui.h"
|
||||
#include "IniSaver.h"
|
||||
#include "IniSaverInfo.h"
|
||||
|
||||
using namespace halsimgui;
|
||||
|
||||
static wpi::DenseMap<int, bool> gEncodersOpen; // indexed by channel A
|
||||
|
||||
// read/write open state to ini file
|
||||
static void* EncodersReadOpen(ImGuiContext* ctx, ImGuiSettingsHandler* handler,
|
||||
const char* name) {
|
||||
int num;
|
||||
if (wpi::StringRef{name}.getAsInteger(10, num)) return nullptr;
|
||||
return &gEncodersOpen[num];
|
||||
}
|
||||
|
||||
static void EncodersReadLine(ImGuiContext* ctx, ImGuiSettingsHandler* handler,
|
||||
void* entry, const char* lineStr) {
|
||||
bool* element = static_cast<bool*>(entry);
|
||||
wpi::StringRef line{lineStr};
|
||||
auto [name, value] = line.split('=');
|
||||
name = name.trim();
|
||||
value = value.trim();
|
||||
if (name == "open") {
|
||||
int num;
|
||||
if (value.getAsInteger(10, num)) return;
|
||||
*element = num;
|
||||
namespace {
|
||||
struct EncoderInfo : public NameInfo, public OpenInfo {
|
||||
bool ReadIni(wpi::StringRef name, wpi::StringRef value) {
|
||||
if (NameInfo::ReadIni(name, value)) return true;
|
||||
if (OpenInfo::ReadIni(name, value)) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
void WriteIni(ImGuiTextBuffer* out) {
|
||||
NameInfo::WriteIni(out);
|
||||
OpenInfo::WriteIni(out);
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
static void EncodersWriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler,
|
||||
ImGuiTextBuffer* out_buf) {
|
||||
for (auto it : gEncodersOpen)
|
||||
out_buf->appendf("[Encoder][%d]\nopen=%d\n\n", it.first, it.second ? 1 : 0);
|
||||
}
|
||||
static IniSaver<EncoderInfo> gEncoders{"Encoder"}; // indexed by channel A
|
||||
|
||||
static void DisplayEncoders() {
|
||||
bool hasAny = false;
|
||||
@@ -58,54 +41,61 @@ static void DisplayEncoders() {
|
||||
for (int i = 0; i < numEncoder; ++i) {
|
||||
if (HALSIM_GetEncoderInitialized(i)) {
|
||||
hasAny = true;
|
||||
char name[32];
|
||||
int chA = HALSIM_GetEncoderDigitalChannelA(i);
|
||||
int chB = HALSIM_GetEncoderDigitalChannelB(i);
|
||||
std::snprintf(name, sizeof(name), "Encoder[%d,%d]", chA, chB);
|
||||
if (auto simDevice = HALSIM_GetEncoderSimDevice(i)) {
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(96, 96, 96, 255));
|
||||
ImGui::Text("%s", HALSIM_GetSimDeviceName(simDevice));
|
||||
ImGui::PopStyleColor();
|
||||
} else if (ImGui::CollapsingHeader(
|
||||
name,
|
||||
gEncodersOpen[chA] ? ImGuiTreeNodeFlags_DefaultOpen : 0)) {
|
||||
gEncodersOpen[chA] = true;
|
||||
|
||||
ImGui::PushID(i);
|
||||
|
||||
// distance per pulse
|
||||
double distancePerPulse = HALSIM_GetEncoderDistancePerPulse(i);
|
||||
ImGui::LabelText("Dist/Count", "%.6f", distancePerPulse);
|
||||
|
||||
// count
|
||||
int count = HALSIM_GetEncoderCount(i);
|
||||
if (ImGui::InputInt("Count", &count)) HALSIM_SetEncoderCount(i, count);
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Reset")) HALSIM_SetEncoderCount(i, 0);
|
||||
|
||||
// max period
|
||||
double maxPeriod = HALSIM_GetEncoderMaxPeriod(i);
|
||||
ImGui::LabelText("Max Period", "%.6f", maxPeriod);
|
||||
|
||||
// period
|
||||
double period = HALSIM_GetEncoderPeriod(i);
|
||||
if (ImGui::InputDouble("Period", &period, 0, 0, "%.6g"))
|
||||
HALSIM_SetEncoderPeriod(i, period);
|
||||
|
||||
// reverse direction
|
||||
ImGui::LabelText(
|
||||
"Reverse Direction", "%s",
|
||||
HALSIM_GetEncoderReverseDirection(i) ? "true" : "false");
|
||||
|
||||
// direction
|
||||
static const char* options[] = {"reverse", "forward"};
|
||||
int direction = HALSIM_GetEncoderDirection(i) ? 1 : 0;
|
||||
if (ImGui::Combo("Direction", &direction, options, 2))
|
||||
HALSIM_SetEncoderDirection(i, direction);
|
||||
|
||||
ImGui::PopID();
|
||||
} else {
|
||||
gEncodersOpen[chA] = false;
|
||||
int chA = HALSIM_GetEncoderDigitalChannelA(i);
|
||||
int chB = HALSIM_GetEncoderDigitalChannelB(i);
|
||||
|
||||
// build header name
|
||||
auto& info = gEncoders[chA];
|
||||
char name[128];
|
||||
info.GetName(name, sizeof(name), "Encoder", chA, chB);
|
||||
|
||||
// header
|
||||
bool open = ImGui::CollapsingHeader(
|
||||
name, gEncoders[chA].IsOpen() ? ImGuiTreeNodeFlags_DefaultOpen : 0);
|
||||
info.SetOpen(open);
|
||||
|
||||
// context menu to change name
|
||||
info.PopupEditName(chA);
|
||||
|
||||
if (open) {
|
||||
ImGui::PushID(i);
|
||||
// distance per pulse
|
||||
double distancePerPulse = HALSIM_GetEncoderDistancePerPulse(i);
|
||||
ImGui::LabelText("Dist/Count", "%.6f", distancePerPulse);
|
||||
|
||||
// count
|
||||
int count = HALSIM_GetEncoderCount(i);
|
||||
if (ImGui::InputInt("Count", &count))
|
||||
HALSIM_SetEncoderCount(i, count);
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Reset")) HALSIM_SetEncoderCount(i, 0);
|
||||
|
||||
// max period
|
||||
double maxPeriod = HALSIM_GetEncoderMaxPeriod(i);
|
||||
ImGui::LabelText("Max Period", "%.6f", maxPeriod);
|
||||
|
||||
// period
|
||||
double period = HALSIM_GetEncoderPeriod(i);
|
||||
if (ImGui::InputDouble("Period", &period, 0, 0, "%.6g"))
|
||||
HALSIM_SetEncoderPeriod(i, period);
|
||||
|
||||
// reverse direction
|
||||
ImGui::LabelText(
|
||||
"Reverse Direction", "%s",
|
||||
HALSIM_GetEncoderReverseDirection(i) ? "true" : "false");
|
||||
|
||||
// direction
|
||||
static const char* options[] = {"reverse", "forward"};
|
||||
int direction = HALSIM_GetEncoderDirection(i) ? 1 : 0;
|
||||
if (ImGui::Combo("Direction", &direction, options, 2))
|
||||
HALSIM_SetEncoderDirection(i, direction);
|
||||
ImGui::PopID();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,15 +104,7 @@ static void DisplayEncoders() {
|
||||
}
|
||||
|
||||
void EncoderGui::Initialize() {
|
||||
// hook ini handler to save settings
|
||||
ImGuiSettingsHandler iniHandler;
|
||||
iniHandler.TypeName = "Encoder";
|
||||
iniHandler.TypeHash = ImHashStr(iniHandler.TypeName);
|
||||
iniHandler.ReadOpenFn = EncodersReadOpen;
|
||||
iniHandler.ReadLineFn = EncodersReadLine;
|
||||
iniHandler.WriteAllFn = EncodersWriteAll;
|
||||
ImGui::GetCurrentContext()->SettingsHandlers.push_back(iniHandler);
|
||||
|
||||
gEncoders.Initialize();
|
||||
HALSimGui::AddWindow("Encoders", DisplayEncoders,
|
||||
ImGuiWindowFlags_AlwaysAutoResize);
|
||||
HALSimGui::SetDefaultWindowPos("Encoders", 640, 215);
|
||||
|
||||
649
simulation/halsim_gui/src/main/native/cpp/Field2D.cpp
Normal file
649
simulation/halsim_gui/src/main/native/cpp/Field2D.cpp
Normal file
@@ -0,0 +1,649 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "Field2D.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <GL/gl3w.h>
|
||||
#include <hal/SimDevice.h>
|
||||
#include <imgui.h>
|
||||
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
#include <imgui_internal.h>
|
||||
#include <mockdata/SimDeviceData.h>
|
||||
#include <units/units.h>
|
||||
#include <wpi/Path.h>
|
||||
#include <wpi/SmallString.h>
|
||||
#include <wpi/json.h>
|
||||
#include <wpi/raw_istream.h>
|
||||
#include <wpi/raw_ostream.h>
|
||||
|
||||
#include "GuiUtil.h"
|
||||
#include "HALSimGui.h"
|
||||
#include "SimDeviceGui.h"
|
||||
#include "portable-file-dialogs.h"
|
||||
|
||||
using namespace halsimgui;
|
||||
|
||||
namespace {
|
||||
|
||||
// Per-frame field data (not persistent)
|
||||
struct FieldFrameData {
|
||||
// in window coordinates
|
||||
ImVec2 imageMin;
|
||||
ImVec2 imageMax;
|
||||
ImVec2 min;
|
||||
ImVec2 max;
|
||||
|
||||
float scale; // scaling from field units to screen units
|
||||
};
|
||||
|
||||
class FieldInfo {
|
||||
public:
|
||||
static constexpr float kDefaultWidth = 15.98f;
|
||||
static constexpr float kDefaultHeight = 8.21f;
|
||||
|
||||
std::unique_ptr<pfd::open_file> m_fileOpener;
|
||||
float m_width = kDefaultWidth;
|
||||
float m_height = kDefaultHeight;
|
||||
|
||||
void Reset();
|
||||
void LoadImage();
|
||||
void LoadJson(const wpi::Twine& jsonfile);
|
||||
FieldFrameData GetFrameData() const;
|
||||
void Draw(ImDrawList* drawList, const ImVec2& windowPos,
|
||||
const FieldFrameData& frameData) const;
|
||||
|
||||
bool ReadIni(wpi::StringRef name, wpi::StringRef value);
|
||||
void WriteIni(ImGuiTextBuffer* out) const;
|
||||
|
||||
private:
|
||||
bool LoadImageImpl(const wpi::Twine& fn);
|
||||
|
||||
std::string m_filename;
|
||||
GLuint m_texture = 0;
|
||||
int m_imageWidth = 0;
|
||||
int m_imageHeight = 0;
|
||||
int m_top = 0;
|
||||
int m_left = 0;
|
||||
int m_bottom = -1;
|
||||
int m_right = -1;
|
||||
};
|
||||
|
||||
// Per-frame robot data (not persistent)
|
||||
struct RobotFrameData {
|
||||
// in window coordinates
|
||||
ImVec2 center;
|
||||
ImVec2 corners[4];
|
||||
ImVec2 arrow[3];
|
||||
|
||||
// scaled width/2 and length/2, in screen units
|
||||
float width2;
|
||||
float length2;
|
||||
};
|
||||
|
||||
class RobotInfo {
|
||||
public:
|
||||
static constexpr float kDefaultWidth = 0.6858f;
|
||||
static constexpr float kDefaultLength = 0.8204f;
|
||||
|
||||
std::unique_ptr<pfd::open_file> m_fileOpener;
|
||||
float m_width = kDefaultWidth;
|
||||
float m_length = kDefaultLength;
|
||||
|
||||
void Reset();
|
||||
void LoadImage();
|
||||
void UpdateFromSimDevice();
|
||||
void SetPosition(double x, double y);
|
||||
// set and get rotation in radians
|
||||
void SetRotation(double rot);
|
||||
double GetRotation() const {
|
||||
return units::convert<units::degrees, units::radians>(m_rot);
|
||||
}
|
||||
RobotFrameData GetFrameData(const FieldFrameData& ffd) const;
|
||||
void Draw(ImDrawList* drawList, const ImVec2& windowPos,
|
||||
const RobotFrameData& frameData, int hit, float hitRadius) const;
|
||||
|
||||
bool ReadIni(wpi::StringRef name, wpi::StringRef value);
|
||||
void WriteIni(ImGuiTextBuffer* out) const;
|
||||
|
||||
private:
|
||||
bool LoadImageImpl(const wpi::Twine& fn);
|
||||
|
||||
std::string m_filename;
|
||||
GLuint m_texture = 0;
|
||||
|
||||
HAL_SimDeviceHandle m_devHandle = 0;
|
||||
hal::SimDouble m_xHandle;
|
||||
hal::SimDouble m_yHandle;
|
||||
hal::SimDouble m_rotHandle;
|
||||
|
||||
double m_x = 0;
|
||||
double m_y = 0;
|
||||
double m_rot = 0;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
static FieldInfo gField;
|
||||
static RobotInfo gRobot;
|
||||
static int gDragRobot = 0;
|
||||
static ImVec2 gDragInitialOffset;
|
||||
static double gDragInitialAngle;
|
||||
|
||||
// read/write settings to ini file
|
||||
static void* Field2DReadOpen(ImGuiContext* ctx, ImGuiSettingsHandler* handler,
|
||||
const char* name) {
|
||||
if (name == wpi::StringRef{"Field"}) return &gField;
|
||||
if (name == wpi::StringRef{"Robot"}) return &gRobot;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void Field2DReadLine(ImGuiContext* ctx, ImGuiSettingsHandler* handler,
|
||||
void* entry, const char* lineStr) {
|
||||
wpi::StringRef line{lineStr};
|
||||
auto [name, value] = line.split('=');
|
||||
name = name.trim();
|
||||
value = value.trim();
|
||||
if (entry == &gField)
|
||||
gField.ReadIni(name, value);
|
||||
else if (entry == &gRobot)
|
||||
gRobot.ReadIni(name, value);
|
||||
}
|
||||
|
||||
static void Field2DWriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler,
|
||||
ImGuiTextBuffer* out_buf) {
|
||||
gField.WriteIni(out_buf);
|
||||
gRobot.WriteIni(out_buf);
|
||||
}
|
||||
|
||||
void FieldInfo::Reset() {
|
||||
if (m_texture != 0) glDeleteTextures(1, &m_texture);
|
||||
m_texture = 0;
|
||||
m_filename.clear();
|
||||
m_imageWidth = 0;
|
||||
m_imageHeight = 0;
|
||||
m_top = 0;
|
||||
m_left = 0;
|
||||
m_bottom = -1;
|
||||
m_right = -1;
|
||||
}
|
||||
|
||||
void FieldInfo::LoadImage() {
|
||||
if (m_fileOpener && m_fileOpener->ready(0)) {
|
||||
auto result = m_fileOpener->result();
|
||||
if (!result.empty()) {
|
||||
if (wpi::StringRef(result[0]).endswith(".json")) {
|
||||
LoadJson(result[0]);
|
||||
} else {
|
||||
LoadImageImpl(result[0]);
|
||||
m_top = 0;
|
||||
m_left = 0;
|
||||
m_bottom = -1;
|
||||
m_right = -1;
|
||||
}
|
||||
}
|
||||
m_fileOpener.reset();
|
||||
}
|
||||
if (m_texture == 0 && !m_filename.empty()) {
|
||||
if (!LoadImageImpl(m_filename)) m_filename.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void FieldInfo::LoadJson(const wpi::Twine& jsonfile) {
|
||||
std::error_code ec;
|
||||
wpi::raw_fd_istream f(jsonfile, ec);
|
||||
if (ec) {
|
||||
wpi::errs() << "GUI: could not open field JSON file\n";
|
||||
return;
|
||||
}
|
||||
|
||||
// parse file
|
||||
wpi::json j;
|
||||
try {
|
||||
j = wpi::json::parse(f);
|
||||
} catch (const wpi::json::parse_error& e) {
|
||||
wpi::errs() << "GUI: JSON: could not parse: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
// top level must be an object
|
||||
if (!j.is_object()) {
|
||||
wpi::errs() << "GUI: JSON: does not contain a top object\n";
|
||||
return;
|
||||
}
|
||||
|
||||
// image filename
|
||||
std::string image;
|
||||
try {
|
||||
image = j.at("field-image").get<std::string>();
|
||||
} catch (const wpi::json::exception& e) {
|
||||
wpi::errs() << "GUI: JSON: could not read field-image: " << e.what()
|
||||
<< '\n';
|
||||
return;
|
||||
}
|
||||
|
||||
// corners
|
||||
int top, left, bottom, right;
|
||||
try {
|
||||
top = j.at("field-corners").at("top-left").at(1).get<int>();
|
||||
left = j.at("field-corners").at("top-left").at(0).get<int>();
|
||||
bottom = j.at("field-corners").at("bottom-right").at(1).get<int>();
|
||||
right = j.at("field-corners").at("bottom-right").at(0).get<int>();
|
||||
} catch (const wpi::json::exception& e) {
|
||||
wpi::errs() << "GUI: JSON: could not read field-corners: " << e.what()
|
||||
<< '\n';
|
||||
return;
|
||||
}
|
||||
|
||||
// size
|
||||
float width;
|
||||
float height;
|
||||
try {
|
||||
width = j.at("field-size").at(0).get<float>();
|
||||
height = j.at("field-size").at(1).get<float>();
|
||||
} catch (const wpi::json::exception& e) {
|
||||
wpi::errs() << "GUI: JSON: could not read field-size: " << e.what() << '\n';
|
||||
return;
|
||||
}
|
||||
|
||||
// units for size
|
||||
std::string unit;
|
||||
try {
|
||||
unit = j.at("field-unit").get<std::string>();
|
||||
} catch (const wpi::json::exception& e) {
|
||||
wpi::errs() << "GUI: JSON: could not read field-unit: " << e.what() << '\n';
|
||||
return;
|
||||
}
|
||||
|
||||
// convert size units to meters
|
||||
if (unit == "foot" || unit == "feet") {
|
||||
width = units::convert<units::feet, units::meters>(width);
|
||||
height = units::convert<units::feet, units::meters>(height);
|
||||
}
|
||||
|
||||
// the image filename is relative to the json file
|
||||
wpi::SmallString<128> pathname;
|
||||
jsonfile.toVector(pathname);
|
||||
wpi::sys::path::remove_filename(pathname);
|
||||
wpi::sys::path::append(pathname, image);
|
||||
|
||||
// load field image
|
||||
if (!LoadImageImpl(pathname)) return;
|
||||
|
||||
// save to field info
|
||||
m_filename = pathname.str();
|
||||
m_top = top;
|
||||
m_left = left;
|
||||
m_bottom = bottom;
|
||||
m_right = right;
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
}
|
||||
|
||||
bool FieldInfo::LoadImageImpl(const wpi::Twine& fn) {
|
||||
wpi::outs() << "GUI: loading field image '" << fn << "'\n";
|
||||
GLuint oldTexture = m_texture;
|
||||
if (!LoadTextureFromFile(fn, &m_texture, &m_imageWidth, &m_imageHeight)) {
|
||||
wpi::errs() << "GUI: could not read field image\n";
|
||||
return false;
|
||||
}
|
||||
if (oldTexture != 0) glDeleteTextures(1, &oldTexture);
|
||||
m_filename = fn.str();
|
||||
return true;
|
||||
}
|
||||
|
||||
FieldFrameData FieldInfo::GetFrameData() const {
|
||||
FieldFrameData ffd;
|
||||
|
||||
// get window content region
|
||||
ffd.imageMin = ImGui::GetWindowContentRegionMin();
|
||||
ffd.imageMax = ImGui::GetWindowContentRegionMax();
|
||||
|
||||
// fit the image into the window
|
||||
if (m_texture != 0 && m_imageHeight != 0 && m_imageWidth != 0)
|
||||
MaxFit(&ffd.imageMin, &ffd.imageMax, m_imageWidth, m_imageHeight);
|
||||
|
||||
ImVec2 min = ffd.imageMin;
|
||||
ImVec2 max = ffd.imageMax;
|
||||
|
||||
// size down the box by the image corners (if any)
|
||||
if (m_bottom > 0 && m_right > 0) {
|
||||
min.x += m_left * (max.x - min.x) / m_imageWidth;
|
||||
min.y += m_top * (max.y - min.y) / m_imageHeight;
|
||||
max.x -= (m_imageWidth - m_right) * (max.x - min.x) / m_imageWidth;
|
||||
max.y -= (m_imageHeight - m_bottom) * (max.y - min.y) / m_imageHeight;
|
||||
}
|
||||
|
||||
// draw the field "active area" as a yellow boundary box
|
||||
MaxFit(&min, &max, m_width, m_height);
|
||||
|
||||
ffd.min = min;
|
||||
ffd.max = max;
|
||||
ffd.scale = (max.x - min.x) / m_width;
|
||||
return ffd;
|
||||
}
|
||||
|
||||
void FieldInfo::Draw(ImDrawList* drawList, const ImVec2& windowPos,
|
||||
const FieldFrameData& ffd) const {
|
||||
if (m_texture != 0 && m_imageHeight != 0 && m_imageWidth != 0) {
|
||||
drawList->AddImage(
|
||||
reinterpret_cast<ImTextureID>(static_cast<uintptr_t>(m_texture)),
|
||||
windowPos + ffd.imageMin, windowPos + ffd.imageMax);
|
||||
}
|
||||
|
||||
// draw the field "active area" as a yellow boundary box
|
||||
drawList->AddRect(windowPos + ffd.min, windowPos + ffd.max,
|
||||
IM_COL32(255, 255, 0, 255));
|
||||
}
|
||||
|
||||
bool FieldInfo::ReadIni(wpi::StringRef name, wpi::StringRef value) {
|
||||
if (name == "image") {
|
||||
m_filename = value;
|
||||
} else if (name == "top") {
|
||||
int num;
|
||||
if (value.getAsInteger(10, num)) return true;
|
||||
m_top = num;
|
||||
} else if (name == "left") {
|
||||
int num;
|
||||
if (value.getAsInteger(10, num)) return true;
|
||||
m_left = num;
|
||||
} else if (name == "bottom") {
|
||||
int num;
|
||||
if (value.getAsInteger(10, num)) return true;
|
||||
m_bottom = num;
|
||||
} else if (name == "right") {
|
||||
int num;
|
||||
if (value.getAsInteger(10, num)) return true;
|
||||
m_right = num;
|
||||
} else if (name == "width") {
|
||||
std::sscanf(value.data(), "%f", &m_width);
|
||||
} else if (name == "height") {
|
||||
std::sscanf(value.data(), "%f", &m_height);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void FieldInfo::WriteIni(ImGuiTextBuffer* out) const {
|
||||
out->appendf(
|
||||
"[Field2D][Field]\nimage=%s\ntop=%d\nleft=%d\nbottom=%d\nright=%d\nwidth="
|
||||
"%f\nheight=%f\n\n",
|
||||
m_filename.c_str(), m_top, m_left, m_bottom, m_right, m_width, m_height);
|
||||
}
|
||||
|
||||
void RobotInfo::Reset() {
|
||||
if (m_texture != 0) glDeleteTextures(1, &m_texture);
|
||||
m_texture = 0;
|
||||
m_filename.clear();
|
||||
}
|
||||
|
||||
void RobotInfo::LoadImage() {
|
||||
if (m_fileOpener && m_fileOpener->ready(0)) {
|
||||
auto result = m_fileOpener->result();
|
||||
if (!result.empty()) LoadImageImpl(result[0]);
|
||||
m_fileOpener.reset();
|
||||
}
|
||||
if (m_texture == 0 && !m_filename.empty()) {
|
||||
if (!LoadImageImpl(m_filename)) m_filename.clear();
|
||||
}
|
||||
}
|
||||
|
||||
bool RobotInfo::LoadImageImpl(const wpi::Twine& fn) {
|
||||
wpi::outs() << "GUI: loading robot image '" << fn << "'\n";
|
||||
GLuint oldTexture = m_texture;
|
||||
if (!LoadTextureFromFile(fn, &m_texture, nullptr, nullptr)) {
|
||||
wpi::errs() << "GUI: could not read robot image\n";
|
||||
return false;
|
||||
}
|
||||
if (oldTexture != 0) glDeleteTextures(1, &oldTexture);
|
||||
m_filename = fn.str();
|
||||
return true;
|
||||
}
|
||||
|
||||
void RobotInfo::UpdateFromSimDevice() {
|
||||
if (m_devHandle == 0) m_devHandle = HALSIM_GetSimDeviceHandle("Field2D");
|
||||
if (m_devHandle == 0) return;
|
||||
|
||||
if (!m_xHandle) m_xHandle = HALSIM_GetSimValueHandle(m_devHandle, "x");
|
||||
if (m_xHandle) m_x = m_xHandle.Get();
|
||||
|
||||
if (!m_yHandle) m_yHandle = HALSIM_GetSimValueHandle(m_devHandle, "y");
|
||||
if (m_yHandle) m_y = m_yHandle.Get();
|
||||
|
||||
if (!m_rotHandle) m_rotHandle = HALSIM_GetSimValueHandle(m_devHandle, "rot");
|
||||
if (m_rotHandle) m_rot = m_rotHandle.Get();
|
||||
}
|
||||
|
||||
void RobotInfo::SetPosition(double x, double y) {
|
||||
m_x = x;
|
||||
m_y = y;
|
||||
if (m_xHandle) m_xHandle.Set(x);
|
||||
if (m_yHandle) m_yHandle.Set(y);
|
||||
}
|
||||
|
||||
void RobotInfo::SetRotation(double rot) {
|
||||
double rotDegrees = units::convert<units::radians, units::degrees>(rot);
|
||||
// force to -180 to +180 range
|
||||
rotDegrees = rotDegrees + std::ceil((-rotDegrees - 180) / 360) * 360;
|
||||
m_rot = rotDegrees;
|
||||
if (m_rotHandle) m_rotHandle.Set(rotDegrees);
|
||||
}
|
||||
|
||||
RobotFrameData RobotInfo::GetFrameData(const FieldFrameData& ffd) const {
|
||||
RobotFrameData rfd;
|
||||
float width2 = ffd.scale * m_width / 2;
|
||||
float length2 = ffd.scale * m_length / 2;
|
||||
|
||||
// (0,0) origin is bottom left
|
||||
ImVec2 center(ffd.min.x + ffd.scale * m_x, ffd.max.y - ffd.scale * m_y);
|
||||
|
||||
// build rotated points around center
|
||||
double rot = GetRotation();
|
||||
float cos_a = std::cos(-rot);
|
||||
float sin_a = std::sin(-rot);
|
||||
|
||||
rfd.corners[0] = center + ImRotate(ImVec2(-length2, -width2), cos_a, sin_a);
|
||||
rfd.corners[1] = center + ImRotate(ImVec2(length2, -width2), cos_a, sin_a);
|
||||
rfd.corners[2] = center + ImRotate(ImVec2(length2, width2), cos_a, sin_a);
|
||||
rfd.corners[3] = center + ImRotate(ImVec2(-length2, width2), cos_a, sin_a);
|
||||
rfd.arrow[0] =
|
||||
center + ImRotate(ImVec2(-length2 / 2, -width2 / 2), cos_a, sin_a);
|
||||
rfd.arrow[1] = center + ImRotate(ImVec2(length2 / 2, 0), cos_a, sin_a);
|
||||
rfd.arrow[2] =
|
||||
center + ImRotate(ImVec2(-length2 / 2, width2 / 2), cos_a, sin_a);
|
||||
|
||||
rfd.center = center;
|
||||
rfd.width2 = width2;
|
||||
rfd.length2 = length2;
|
||||
return rfd;
|
||||
}
|
||||
|
||||
void RobotInfo::Draw(ImDrawList* drawList, const ImVec2& windowPos,
|
||||
const RobotFrameData& rfd, int hit,
|
||||
float hitRadius) const {
|
||||
if (m_texture != 0) {
|
||||
drawList->AddImageQuad(
|
||||
reinterpret_cast<ImTextureID>(static_cast<uintptr_t>(m_texture)),
|
||||
windowPos + rfd.corners[0], windowPos + rfd.corners[1],
|
||||
windowPos + rfd.corners[2], windowPos + rfd.corners[3]);
|
||||
} else {
|
||||
drawList->AddQuad(windowPos + rfd.corners[0], windowPos + rfd.corners[1],
|
||||
windowPos + rfd.corners[2], windowPos + rfd.corners[3],
|
||||
IM_COL32(255, 0, 0, 255), 4.0);
|
||||
drawList->AddTriangle(windowPos + rfd.arrow[0], windowPos + rfd.arrow[1],
|
||||
windowPos + rfd.arrow[2], IM_COL32(0, 255, 0, 255),
|
||||
4.0);
|
||||
}
|
||||
|
||||
if (hit > 0) {
|
||||
if (hit == 1) {
|
||||
drawList->AddCircle(windowPos + rfd.center, hitRadius,
|
||||
IM_COL32(0, 255, 0, 255));
|
||||
} else {
|
||||
drawList->AddCircle(windowPos + rfd.corners[hit - 2], hitRadius,
|
||||
IM_COL32(0, 255, 0, 255));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool RobotInfo::ReadIni(wpi::StringRef name, wpi::StringRef value) {
|
||||
if (name == "image") {
|
||||
m_filename = value;
|
||||
} else if (name == "width") {
|
||||
std::sscanf(value.data(), "%f", &m_width);
|
||||
} else if (name == "length") {
|
||||
std::sscanf(value.data(), "%f", &m_length);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void RobotInfo::WriteIni(ImGuiTextBuffer* out) const {
|
||||
out->appendf("[Field2D][Robot]\nimage=%s\nwidth=%f\nlength=%f\n\n",
|
||||
m_filename.c_str(), m_width, m_length);
|
||||
}
|
||||
|
||||
static void OptionMenuField2D() {
|
||||
if (ImGui::BeginMenu("2D Field View")) {
|
||||
if (ImGui::MenuItem("Choose field image...")) {
|
||||
gField.m_fileOpener = std::make_unique<pfd::open_file>(
|
||||
"Choose field image", "",
|
||||
std::vector<std::string>{"Image File",
|
||||
"*.jpg *.jpeg *.png *.bmp *.psd *.tga *.gif "
|
||||
"*.hdr *.pic *.ppm *.pgm",
|
||||
"PathWeaver JSON File", "*.json"});
|
||||
}
|
||||
if (ImGui::MenuItem("Reset field image")) {
|
||||
gField.Reset();
|
||||
}
|
||||
if (ImGui::MenuItem("Choose robot image...")) {
|
||||
gRobot.m_fileOpener = std::make_unique<pfd::open_file>(
|
||||
"Choose robot image", "",
|
||||
std::vector<std::string>{"Image File",
|
||||
"*.jpg *.jpeg *.png *.bmp *.psd *.tga *.gif "
|
||||
"*.hdr *.pic *.ppm *.pgm"});
|
||||
}
|
||||
if (ImGui::MenuItem("Reset robot image")) {
|
||||
gRobot.Reset();
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
}
|
||||
|
||||
static void DisplayField2DSettings() {
|
||||
ImGui::PushItemWidth(ImGui::GetFontSize() * 4);
|
||||
ImGui::InputFloat("Field Width", &gField.m_width);
|
||||
ImGui::InputFloat("Field Height", &gField.m_height);
|
||||
// ImGui::InputInt("Field Top", &gField.m_top);
|
||||
// ImGui::InputInt("Field Left", &gField.m_left);
|
||||
// ImGui::InputInt("Field Right", &gField.m_right);
|
||||
// ImGui::InputInt("Field Bottom", &gField.m_bottom);
|
||||
ImGui::InputFloat("Robot Width", &gRobot.m_width);
|
||||
ImGui::InputFloat("Robot Length", &gRobot.m_length);
|
||||
ImGui::PopItemWidth();
|
||||
}
|
||||
|
||||
static void DisplayField2D() {
|
||||
// load images
|
||||
gField.LoadImage();
|
||||
gRobot.LoadImage();
|
||||
|
||||
// get robot coordinates from SimDevice
|
||||
gRobot.UpdateFromSimDevice();
|
||||
|
||||
FieldFrameData ffd = gField.GetFrameData();
|
||||
RobotFrameData rfd = gRobot.GetFrameData(ffd);
|
||||
|
||||
ImVec2 windowPos = ImGui::GetWindowPos();
|
||||
|
||||
// for dragging to work, there needs to be a button (otherwise the window is
|
||||
// dragged)
|
||||
ImGui::InvisibleButton("field", ImGui::GetContentRegionAvail());
|
||||
|
||||
// allow dragging the robot around
|
||||
ImVec2 cursor = ImGui::GetIO().MousePos - windowPos;
|
||||
|
||||
int hit = 0;
|
||||
float hitRadius = (std::min)(rfd.width2, rfd.length2) / 2;
|
||||
// only allow initiation of dragging when invisible button is hovered; this
|
||||
// prevents the window resize handles from simultaneously activating the drag
|
||||
// functionality
|
||||
if (ImGui::IsItemHovered()) {
|
||||
float hitRadiusSquared = hitRadius * hitRadius;
|
||||
// it's within the hit radius of the center?
|
||||
if (GetDistSquared(cursor, rfd.center) < hitRadiusSquared)
|
||||
hit = 1;
|
||||
else if (GetDistSquared(cursor, rfd.corners[0]) < hitRadiusSquared)
|
||||
hit = 2;
|
||||
else if (GetDistSquared(cursor, rfd.corners[1]) < hitRadiusSquared)
|
||||
hit = 3;
|
||||
else if (GetDistSquared(cursor, rfd.corners[2]) < hitRadiusSquared)
|
||||
hit = 4;
|
||||
else if (GetDistSquared(cursor, rfd.corners[3]) < hitRadiusSquared)
|
||||
hit = 5;
|
||||
if (hit > 0 && ImGui::IsMouseClicked(0)) {
|
||||
if (hit == 1) {
|
||||
gDragRobot = hit;
|
||||
gDragInitialOffset = cursor - rfd.center;
|
||||
} else {
|
||||
gDragRobot = hit;
|
||||
ImVec2 off = cursor - rfd.center;
|
||||
gDragInitialAngle = std::atan2(off.y, off.x) + gRobot.GetRotation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (gDragRobot > 0 && ImGui::IsMouseDown(0)) {
|
||||
if (gDragRobot == 1) {
|
||||
ImVec2 newPos = cursor - gDragInitialOffset;
|
||||
gRobot.SetPosition(
|
||||
(std::clamp(newPos.x, ffd.min.x, ffd.max.x) - ffd.min.x) / ffd.scale,
|
||||
(ffd.max.y - std::clamp(newPos.y, ffd.min.y, ffd.max.y)) / ffd.scale);
|
||||
rfd = gRobot.GetFrameData(ffd);
|
||||
} else {
|
||||
ImVec2 off = cursor - rfd.center;
|
||||
gRobot.SetRotation(gDragInitialAngle - std::atan2(off.y, off.x));
|
||||
}
|
||||
hit = gDragRobot; // keep it highlighted
|
||||
} else {
|
||||
gDragRobot = 0;
|
||||
}
|
||||
|
||||
// draw
|
||||
auto drawList = ImGui::GetWindowDrawList();
|
||||
gField.Draw(drawList, windowPos, ffd);
|
||||
gRobot.Draw(drawList, windowPos, rfd, hit, hitRadius);
|
||||
}
|
||||
|
||||
void Field2D::Initialize() {
|
||||
// hook ini handler to save settings
|
||||
ImGuiSettingsHandler iniHandler;
|
||||
iniHandler.TypeName = "Field2D";
|
||||
iniHandler.TypeHash = ImHashStr(iniHandler.TypeName);
|
||||
iniHandler.ReadOpenFn = Field2DReadOpen;
|
||||
iniHandler.ReadLineFn = Field2DReadLine;
|
||||
iniHandler.WriteAllFn = Field2DWriteAll;
|
||||
ImGui::GetCurrentContext()->SettingsHandlers.push_back(iniHandler);
|
||||
|
||||
HALSimGui::AddOptionMenu(OptionMenuField2D);
|
||||
|
||||
HALSimGui::AddWindow("2D Field Settings", DisplayField2DSettings,
|
||||
ImGuiWindowFlags_AlwaysAutoResize);
|
||||
HALSimGui::SetWindowVisibility("2D Field Settings", HALSimGui::kHide);
|
||||
HALSimGui::SetDefaultWindowPos("2D Field Settings", 200, 150);
|
||||
|
||||
HALSimGui::AddWindow("2D Field View", DisplayField2D);
|
||||
HALSimGui::SetWindowVisibility("2D Field View", HALSimGui::kHide);
|
||||
HALSimGui::SetDefaultWindowPos("2D Field View", 200, 200);
|
||||
HALSimGui::SetDefaultWindowSize("2D Field View", 400, 200);
|
||||
HALSimGui::SetWindowPadding("2D Field View", 0, 0);
|
||||
|
||||
// SimDeviceGui::Hide("Field2D");
|
||||
}
|
||||
17
simulation/halsim_gui/src/main/native/cpp/Field2D.h
Normal file
17
simulation/halsim_gui/src/main/native/cpp/Field2D.h
Normal file
@@ -0,0 +1,17 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace halsimgui {
|
||||
|
||||
class Field2D {
|
||||
public:
|
||||
static void Initialize();
|
||||
};
|
||||
|
||||
} // namespace halsimgui
|
||||
62
simulation/halsim_gui/src/main/native/cpp/GuiUtil.cpp
Normal file
62
simulation/halsim_gui/src/main/native/cpp/GuiUtil.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "GuiUtil.h"
|
||||
|
||||
#include <stb_image.h>
|
||||
|
||||
#include <wpi/SmallString.h>
|
||||
|
||||
bool halsimgui::LoadTextureFromFile(const wpi::Twine& filename,
|
||||
GLuint* out_texture, int* out_width,
|
||||
int* out_height) {
|
||||
wpi::SmallString<128> buf;
|
||||
|
||||
// Load from file
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
unsigned char* data =
|
||||
stbi_load(filename.toNullTerminatedStringRef(buf).data(), &width, &height,
|
||||
nullptr, 4);
|
||||
if (!data) return false;
|
||||
|
||||
// Create a OpenGL texture identifier
|
||||
GLuint texture;
|
||||
glGenTextures(1, &texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
|
||||
// Setup filtering parameters for display
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
// Upload pixels into texture
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,
|
||||
GL_UNSIGNED_BYTE, data);
|
||||
stbi_image_free(data);
|
||||
|
||||
*out_texture = texture;
|
||||
if (out_width) *out_width = width;
|
||||
if (out_height) *out_height = height;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void halsimgui::MaxFit(ImVec2* min, ImVec2* max, float width, float height) {
|
||||
float destWidth = max->x - min->x;
|
||||
float destHeight = max->y - min->y;
|
||||
if (width == 0 || height == 0) return;
|
||||
if (destWidth * height > destHeight * width) {
|
||||
float outputWidth = width * destHeight / height;
|
||||
min->x += (destWidth - outputWidth) / 2;
|
||||
max->x -= (destWidth - outputWidth) / 2;
|
||||
} else {
|
||||
float outputHeight = height * destWidth / width;
|
||||
min->y += (destHeight - outputHeight) / 2;
|
||||
max->y -= (destHeight - outputHeight) / 2;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -40,6 +40,8 @@ struct WindowInfo {
|
||||
ImGuiCond sizeCond = 0;
|
||||
ImVec2 pos;
|
||||
ImVec2 size;
|
||||
bool setPadding = false;
|
||||
ImVec2 padding;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
@@ -248,6 +250,14 @@ void HALSimGui::SetDefaultWindowSize(const char* name, float width,
|
||||
window.size = ImVec2{width, height};
|
||||
}
|
||||
|
||||
void HALSimGui::SetWindowPadding(const char* name, float x, float y) {
|
||||
auto it = gWindowMap.find(name);
|
||||
if (it == gWindowMap.end()) return;
|
||||
auto& window = gWindows[it->second];
|
||||
window.setPadding = true;
|
||||
window.padding = ImVec2{x, y};
|
||||
}
|
||||
|
||||
bool HALSimGui::AreOutputsDisabled() {
|
||||
return gDisableOutputsOnDSDisable && !HALSIM_GetDriverStationEnabled();
|
||||
}
|
||||
@@ -301,6 +311,12 @@ bool HALSimGui::Initialize() {
|
||||
// Set initial window settings
|
||||
glfwWindowHint(GLFW_MAXIMIZED, gWindowMaximized ? GLFW_TRUE : GLFW_FALSE);
|
||||
|
||||
if (gWindowWidth == 0 || gWindowHeight == 0) {
|
||||
gWindowWidth = 1280;
|
||||
gWindowHeight = 720;
|
||||
gWindowLoadedWidthHeight = false;
|
||||
}
|
||||
|
||||
float windowScale = 1.0;
|
||||
if (!gWindowLoadedWidthHeight) {
|
||||
glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE);
|
||||
@@ -515,9 +531,12 @@ void HALSimGui::Main(void*) {
|
||||
ImGui::SetNextWindowPos(window.pos, window.posCond);
|
||||
if (window.sizeCond != 0)
|
||||
ImGui::SetNextWindowSize(window.size, window.sizeCond);
|
||||
if (window.setPadding)
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, window.padding);
|
||||
if (ImGui::Begin(window.name.c_str(), &window.visible, window.flags))
|
||||
window.display();
|
||||
ImGui::End();
|
||||
if (window.setPadding) ImGui::PopStyleVar();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -591,6 +610,10 @@ void HALSIMGUI_SetDefaultWindowSize(const char* name, float width,
|
||||
HALSimGui::SetDefaultWindowSize(name, width, height);
|
||||
}
|
||||
|
||||
void HALSIMGUI_SetWindowPadding(const char* name, float x, float y) {
|
||||
HALSimGui::SetDefaultWindowSize(name, x, y);
|
||||
}
|
||||
|
||||
int HALSIMGUI_AreOutputsDisabled(void) {
|
||||
return HALSimGui::AreOutputsDisabled();
|
||||
}
|
||||
|
||||
78
simulation/halsim_gui/src/main/native/cpp/IniSaverInfo.cpp
Normal file
78
simulation/halsim_gui/src/main/native/cpp/IniSaverInfo.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "IniSaverInfo.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#include <imgui_internal.h>
|
||||
|
||||
using namespace halsimgui;
|
||||
|
||||
void NameInfo::GetName(char* buf, size_t size, const char* defaultName,
|
||||
int index) {
|
||||
if (m_name[0] != '\0') {
|
||||
std::snprintf(buf, size, "%s [%d]###Name%d", m_name, index, index);
|
||||
} else {
|
||||
std::snprintf(buf, size, "%s[%d]###Name%d", defaultName, index, index);
|
||||
}
|
||||
}
|
||||
|
||||
void NameInfo::GetName(char* buf, size_t size, const char* defaultName,
|
||||
int index, int index2) {
|
||||
if (m_name[0] != '\0') {
|
||||
std::snprintf(buf, size, "%s [%d,%d]###Name%d", m_name, index, index2,
|
||||
index);
|
||||
} else {
|
||||
std::snprintf(buf, size, "%s[%d,%d]###Name%d", defaultName, index, index2,
|
||||
index);
|
||||
}
|
||||
}
|
||||
|
||||
bool NameInfo::ReadIni(wpi::StringRef name, wpi::StringRef value) {
|
||||
if (name != "name") return false;
|
||||
size_t len = (std::min)(value.size(), sizeof(m_name) - 1);
|
||||
std::memcpy(m_name, value.data(), len);
|
||||
m_name[len] = '\0';
|
||||
return true;
|
||||
}
|
||||
|
||||
void NameInfo::WriteIni(ImGuiTextBuffer* out) {
|
||||
out->appendf("name=%s\n", m_name);
|
||||
}
|
||||
|
||||
void NameInfo::PushEditNameId(int index) {
|
||||
char id[64];
|
||||
std::snprintf(id, sizeof(id), "Name%d", index);
|
||||
ImGui::PushID(id);
|
||||
}
|
||||
|
||||
void NameInfo::PopupEditName(int index) {
|
||||
char id[64];
|
||||
std::snprintf(id, sizeof(id), "Name%d", index);
|
||||
if (ImGui::BeginPopupContextItem(id)) {
|
||||
ImGui::Text("Edit name:");
|
||||
if (ImGui::InputText("##edit", m_name, sizeof(m_name),
|
||||
ImGuiInputTextFlags_EnterReturnsTrue))
|
||||
ImGui::CloseCurrentPopup();
|
||||
if (ImGui::Button("Close")) ImGui::CloseCurrentPopup();
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenInfo::ReadIni(wpi::StringRef name, wpi::StringRef value) {
|
||||
if (name != "open") return false;
|
||||
int num;
|
||||
if (value.getAsInteger(10, num)) return true;
|
||||
m_open = num;
|
||||
return true;
|
||||
}
|
||||
|
||||
void OpenInfo::WriteIni(ImGuiTextBuffer* out) {
|
||||
out->appendf("open=%d\n", m_open ? 1 : 0);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -7,7 +7,9 @@
|
||||
|
||||
#include "PDPGui.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
#include <hal/Ports.h>
|
||||
@@ -15,64 +17,82 @@
|
||||
#include <mockdata/PDPData.h>
|
||||
|
||||
#include "HALSimGui.h"
|
||||
#include "IniSaver.h"
|
||||
#include "IniSaverInfo.h"
|
||||
|
||||
using namespace halsimgui;
|
||||
|
||||
static IniSaver<NameInfo> gChannels{"PDP"};
|
||||
|
||||
static void DisplayPDP() {
|
||||
bool hasAny = false;
|
||||
static int numPDP = HAL_GetNumPDPModules();
|
||||
static int numChannels = HAL_GetNumPDPChannels();
|
||||
static auto channelCurrents = std::make_unique<double[]>(numChannels);
|
||||
ImGui::PushItemWidth(ImGui::GetFontSize() * 13);
|
||||
for (int i = 0; i < numPDP; ++i) {
|
||||
if (HALSIM_GetPDPInitialized(i)) {
|
||||
hasAny = true;
|
||||
|
||||
char name[32];
|
||||
char name[128];
|
||||
std::snprintf(name, sizeof(name), "PDP[%d]", i);
|
||||
if (ImGui::CollapsingHeader(name, ImGuiTreeNodeFlags_DefaultOpen)) {
|
||||
ImGui::PushID(i);
|
||||
|
||||
// temperature
|
||||
double temp = HALSIM_GetPDPTemperature(i);
|
||||
if (ImGui::InputDouble("Temp", &temp))
|
||||
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 4);
|
||||
if (ImGui::InputDouble("Temp", &temp, 0, 0, "%.3f"))
|
||||
HALSIM_SetPDPTemperature(i, temp);
|
||||
|
||||
// voltage
|
||||
double volts = HALSIM_GetPDPVoltage(i);
|
||||
if (ImGui::InputDouble("Voltage", &volts))
|
||||
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 4);
|
||||
if (ImGui::InputDouble("Voltage", &volts, 0, 0, "%.3f"))
|
||||
HALSIM_SetPDPVoltage(i, volts);
|
||||
|
||||
// channel currents; show as two columns laid out like PDP
|
||||
HALSIM_GetPDPAllCurrents(i, channelCurrents.get());
|
||||
ImGui::Text("Channel Current (A)");
|
||||
ImGui::Columns(2, "channels", false);
|
||||
float maxWidth = ImGui::GetFontSize() * 13;
|
||||
for (int left = 0, right = numChannels - 1; left < right;
|
||||
++left, --right) {
|
||||
double val;
|
||||
|
||||
std::snprintf(name, sizeof(name), "[%d]", left);
|
||||
auto& leftInfo = gChannels[i * numChannels + left];
|
||||
leftInfo.GetName(name, sizeof(name), "", left);
|
||||
val = channelCurrents[left];
|
||||
if (ImGui::InputDouble(name, &val))
|
||||
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 4);
|
||||
if (ImGui::InputDouble(name, &val, 0, 0, "%.3f"))
|
||||
HALSIM_SetPDPCurrent(i, left, val);
|
||||
float leftWidth = ImGui::GetItemRectSize().x;
|
||||
leftInfo.PopupEditName(left);
|
||||
ImGui::NextColumn();
|
||||
|
||||
std::snprintf(name, sizeof(name), "[%d]", right);
|
||||
auto& rightInfo = gChannels[i * numChannels + right];
|
||||
rightInfo.GetName(name, sizeof(name), "", right);
|
||||
val = channelCurrents[right];
|
||||
if (ImGui::InputDouble(name, &val))
|
||||
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 4);
|
||||
if (ImGui::InputDouble(name, &val, 0, 0, "%.3f"))
|
||||
HALSIM_SetPDPCurrent(i, right, val);
|
||||
float rightWidth = ImGui::GetItemRectSize().x;
|
||||
rightInfo.PopupEditName(right);
|
||||
ImGui::NextColumn();
|
||||
|
||||
float width = (std::max)(leftWidth, rightWidth) * 2;
|
||||
if (width > maxWidth) maxWidth = width;
|
||||
}
|
||||
ImGui::Columns(1);
|
||||
ImGui::Dummy(ImVec2(maxWidth, 0));
|
||||
ImGui::PopID();
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::PopItemWidth();
|
||||
if (!hasAny) ImGui::Text("No PDPs");
|
||||
}
|
||||
|
||||
void PDPGui::Initialize() {
|
||||
gChannels.Initialize();
|
||||
HALSimGui::AddWindow("PDP", DisplayPDP, ImGuiWindowFlags_AlwaysAutoResize);
|
||||
// hide it by default
|
||||
HALSimGui::SetWindowVisibility("PDP", HALSimGui::kHide);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -17,9 +17,13 @@
|
||||
#include <mockdata/PWMData.h>
|
||||
|
||||
#include "HALSimGui.h"
|
||||
#include "IniSaver.h"
|
||||
#include "IniSaverInfo.h"
|
||||
|
||||
using namespace halsimgui;
|
||||
|
||||
static IniSaver<NameInfo> gPWM{"PWM"};
|
||||
|
||||
static void DisplayPWMs() {
|
||||
bool hasOutputs = false;
|
||||
static const int numPWM = HAL_GetNumPWMChannels();
|
||||
@@ -45,6 +49,7 @@ static void DisplayPWMs() {
|
||||
//};
|
||||
// static std::vector<std::unique_ptr<History>> history;
|
||||
bool first = true;
|
||||
ImGui::PushItemWidth(ImGui::GetFontSize() * 4);
|
||||
for (int i = 0; i < numPWM; ++i) {
|
||||
if (HALSIM_GetPWMInitialized(i)) {
|
||||
hasOutputs = true;
|
||||
@@ -54,14 +59,16 @@ static void DisplayPWMs() {
|
||||
else
|
||||
first = false;
|
||||
|
||||
char name[32];
|
||||
std::snprintf(name, sizeof(name), "PWM[%d]", i);
|
||||
char name[128];
|
||||
auto& info = gPWM[i];
|
||||
info.GetName(name, sizeof(name), "PWM", i);
|
||||
if (ledMap[i] > 0) {
|
||||
ImGui::Text("%s: LED[%d]", name, ledMap[i] - 1);
|
||||
ImGui::LabelText(name, "LED[%d]", ledMap[i] - 1);
|
||||
} else {
|
||||
float val = HALSimGui::AreOutputsDisabled() ? 0 : HALSIM_GetPWMSpeed(i);
|
||||
ImGui::Value(name, val, "%0.3f");
|
||||
ImGui::LabelText(name, "%0.3f", val);
|
||||
}
|
||||
info.PopupEditName(i);
|
||||
|
||||
// lazily build history storage
|
||||
// if (static_cast<unsigned int>(i) > history.size())
|
||||
@@ -74,10 +81,12 @@ static void DisplayPWMs() {
|
||||
// );
|
||||
}
|
||||
}
|
||||
ImGui::PopItemWidth();
|
||||
if (!hasOutputs) ImGui::Text("No PWM outputs");
|
||||
}
|
||||
|
||||
void PWMGui::Initialize() {
|
||||
gPWM.Initialize();
|
||||
HALSimGui::AddWindow("PWM Outputs", DisplayPWMs,
|
||||
ImGuiWindowFlags_AlwaysAutoResize);
|
||||
HALSimGui::SetDefaultWindowPos("PWM Outputs", 910, 20);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -16,9 +16,13 @@
|
||||
|
||||
#include "ExtraGuiWidgets.h"
|
||||
#include "HALSimGui.h"
|
||||
#include "IniSaver.h"
|
||||
#include "IniSaverInfo.h"
|
||||
|
||||
using namespace halsimgui;
|
||||
|
||||
static IniSaver<NameInfo> gRelays{"Relay"};
|
||||
|
||||
static void DisplayRelays() {
|
||||
bool hasOutputs = false;
|
||||
bool first = true;
|
||||
@@ -42,7 +46,14 @@ static void DisplayRelays() {
|
||||
forward = HALSIM_GetRelayForward(i);
|
||||
}
|
||||
|
||||
ImGui::Text("Relay[%d]", i);
|
||||
auto& info = gRelays[i];
|
||||
info.PushEditNameId(i);
|
||||
if (info.HasName())
|
||||
ImGui::Text("%s [%d]", info.GetName(), i);
|
||||
else
|
||||
ImGui::Text("Relay[%d]", i);
|
||||
ImGui::PopID();
|
||||
info.PopupEditName(i);
|
||||
ImGui::SameLine();
|
||||
|
||||
// show forward and reverse as LED indicators
|
||||
@@ -58,6 +69,7 @@ static void DisplayRelays() {
|
||||
}
|
||||
|
||||
void RelayGui::Initialize() {
|
||||
gRelays.Initialize();
|
||||
HALSimGui::AddWindow("Relays", DisplayRelays,
|
||||
ImGuiWindowFlags_AlwaysAutoResize);
|
||||
HALSimGui::SetDefaultWindowPos("Relays", 180, 20);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -13,51 +13,22 @@
|
||||
|
||||
#include <hal/SimDevice.h>
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
#include <mockdata/SimDeviceData.h>
|
||||
#include <wpi/StringMap.h>
|
||||
|
||||
#include "HALSimGui.h"
|
||||
#include "IniSaverInfo.h"
|
||||
#include "IniSaverString.h"
|
||||
|
||||
using namespace halsimgui;
|
||||
|
||||
namespace {
|
||||
struct ElementInfo {
|
||||
bool open = false;
|
||||
bool visible = true;
|
||||
struct ElementInfo : public OpenInfo {
|
||||
bool visible = true; // not saved
|
||||
};
|
||||
} // namespace
|
||||
|
||||
static std::vector<std::function<void()>> gDeviceExecutors;
|
||||
static wpi::StringMap<ElementInfo> gElements;
|
||||
|
||||
// read/write open state to ini file
|
||||
static void* DevicesReadOpen(ImGuiContext* ctx, ImGuiSettingsHandler* handler,
|
||||
const char* name) {
|
||||
return &gElements[name];
|
||||
}
|
||||
|
||||
static void DevicesReadLine(ImGuiContext* ctx, ImGuiSettingsHandler* handler,
|
||||
void* entry, const char* lineStr) {
|
||||
ElementInfo* element = static_cast<ElementInfo*>(entry);
|
||||
wpi::StringRef line{lineStr};
|
||||
auto [name, value] = line.split('=');
|
||||
name = name.trim();
|
||||
value = value.trim();
|
||||
if (name == "open") {
|
||||
int num;
|
||||
if (value.getAsInteger(10, num)) return;
|
||||
element->open = num;
|
||||
}
|
||||
}
|
||||
|
||||
static void DevicesWriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler,
|
||||
ImGuiTextBuffer* out_buf) {
|
||||
for (auto&& entry : gElements) {
|
||||
out_buf->appendf("[Device][%s]\nopen=%d\n\n", entry.getKey().data(),
|
||||
entry.getValue().open ? 1 : 0);
|
||||
}
|
||||
}
|
||||
static IniSaverString<ElementInfo> gElements{"Device"};
|
||||
|
||||
void SimDeviceGui::Hide(const char* name) { gElements[name].visible = false; }
|
||||
|
||||
@@ -70,12 +41,13 @@ bool SimDeviceGui::StartDevice(const char* label, ImGuiTreeNodeFlags flags) {
|
||||
if (!element.visible) return false;
|
||||
|
||||
if (ImGui::CollapsingHeader(
|
||||
label, flags | (element.open ? ImGuiTreeNodeFlags_DefaultOpen : 0))) {
|
||||
label,
|
||||
flags | (element.IsOpen() ? ImGuiTreeNodeFlags_DefaultOpen : 0))) {
|
||||
ImGui::PushID(label);
|
||||
element.open = true;
|
||||
element.SetOpen(true);
|
||||
return true;
|
||||
}
|
||||
element.open = false;
|
||||
element.SetOpen(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -201,15 +173,7 @@ static void DisplayDeviceTree() {
|
||||
}
|
||||
|
||||
void SimDeviceGui::Initialize() {
|
||||
// hook ini handler to save device settings
|
||||
ImGuiSettingsHandler iniHandler;
|
||||
iniHandler.TypeName = "Device";
|
||||
iniHandler.TypeHash = ImHashStr(iniHandler.TypeName);
|
||||
iniHandler.ReadOpenFn = DevicesReadOpen;
|
||||
iniHandler.ReadLineFn = DevicesReadLine;
|
||||
iniHandler.WriteAllFn = DevicesWriteAll;
|
||||
ImGui::GetCurrentContext()->SettingsHandlers.push_back(iniHandler);
|
||||
|
||||
gElements.Initialize();
|
||||
HALSimGui::AddWindow("Other Devices", DisplayDeviceTree);
|
||||
HALSimGui::SetDefaultWindowPos("Other Devices", 1025, 20);
|
||||
HALSimGui::SetDefaultWindowSize("Other Devices", 250, 695);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -17,9 +17,14 @@
|
||||
|
||||
#include "ExtraGuiWidgets.h"
|
||||
#include "HALSimGui.h"
|
||||
#include "IniSaver.h"
|
||||
#include "IniSaverInfo.h"
|
||||
|
||||
using namespace halsimgui;
|
||||
|
||||
static IniSaver<OpenInfo> gPCMs{"PCM"};
|
||||
static IniSaver<NameInfo> gSolenoids{"Solenoid"};
|
||||
|
||||
static void DisplaySolenoids() {
|
||||
bool hasOutputs = false;
|
||||
static const int numPCM = HAL_GetNumPCMModules();
|
||||
@@ -43,18 +48,40 @@ static void DisplaySolenoids() {
|
||||
if (!anyInit) continue;
|
||||
hasOutputs = true;
|
||||
|
||||
ImGui::Text("PCM[%d]", i);
|
||||
char name[128];
|
||||
std::snprintf(name, sizeof(name), "PCM[%d]", i);
|
||||
auto& pcmInfo = gPCMs[i];
|
||||
bool open = ImGui::CollapsingHeader(
|
||||
name, pcmInfo.IsOpen() ? ImGuiTreeNodeFlags_DefaultOpen : 0);
|
||||
pcmInfo.SetOpen(open);
|
||||
ImGui::SetItemAllowOverlap();
|
||||
ImGui::SameLine();
|
||||
|
||||
// show channels as LED indicators
|
||||
static const ImU32 colors[] = {IM_COL32(255, 255, 102, 255),
|
||||
IM_COL32(128, 128, 128, 255)};
|
||||
DrawLEDs(channels.data(), channels.size(), channels.size(), colors);
|
||||
|
||||
if (open) {
|
||||
ImGui::PushID(i);
|
||||
ImGui::PushItemWidth(ImGui::GetFontSize() * 4);
|
||||
for (int j = 0; j < numChannels; ++j) {
|
||||
if (channels[j] == -2) continue;
|
||||
auto& info = gSolenoids[i * numChannels + j];
|
||||
info.GetName(name, sizeof(name), "Solenoid", j);
|
||||
ImGui::LabelText(name, "%s", channels[j] == 1 ? "On" : "Off");
|
||||
info.PopupEditName(j);
|
||||
}
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::PopID();
|
||||
}
|
||||
}
|
||||
if (!hasOutputs) ImGui::Text("No solenoids");
|
||||
}
|
||||
|
||||
void SolenoidGui::Initialize() {
|
||||
gPCMs.Initialize();
|
||||
gSolenoids.Initialize();
|
||||
HALSimGui::AddWindow("Solenoids", DisplaySolenoids,
|
||||
ImGuiWindowFlags_AlwaysAutoResize);
|
||||
HALSimGui::SetDefaultWindowPos("Solenoids", 290, 20);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "DIOGui.h"
|
||||
#include "DriverStationGui.h"
|
||||
#include "EncoderGui.h"
|
||||
#include "Field2D.h"
|
||||
#include "HALSimGui.h"
|
||||
#include "PDPGui.h"
|
||||
#include "PWMGui.h"
|
||||
@@ -42,6 +43,7 @@ __declspec(dllexport)
|
||||
HALSimGui::Add(DriverStationGui::Initialize);
|
||||
HALSimGui::Add(DIOGui::Initialize);
|
||||
HALSimGui::Add(EncoderGui::Initialize);
|
||||
HALSimGui::Add(Field2D::Initialize);
|
||||
HALSimGui::Add(PDPGui::Initialize);
|
||||
HALSimGui::Add(PWMGui::Initialize);
|
||||
HALSimGui::Add(RelayGui::Initialize);
|
||||
|
||||
29
simulation/halsim_gui/src/main/native/include/GuiUtil.h
Normal file
29
simulation/halsim_gui/src/main/native/include/GuiUtil.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <GL/gl3w.h>
|
||||
#include <imgui.h>
|
||||
#include <wpi/Twine.h>
|
||||
|
||||
namespace halsimgui {
|
||||
|
||||
bool LoadTextureFromFile(const wpi::Twine& filename, GLuint* out_texture,
|
||||
int* out_width, int* out_height);
|
||||
|
||||
// get distance^2 between two ImVec's
|
||||
inline float GetDistSquared(const ImVec2& a, const ImVec2& b) {
|
||||
float deltaX = b.x - a.x;
|
||||
float deltaY = b.y - a.y;
|
||||
return deltaX * deltaX + deltaY * deltaY;
|
||||
}
|
||||
|
||||
// maximize fit while preserving aspect ratio
|
||||
void MaxFit(ImVec2* min, ImVec2* max, float width, float height);
|
||||
|
||||
} // namespace halsimgui
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -23,6 +23,7 @@ void HALSIMGUI_SetWindowVisibility(const char* name, int32_t visibility);
|
||||
void HALSIMGUI_SetDefaultWindowPos(const char* name, float x, float y);
|
||||
void HALSIMGUI_SetDefaultWindowSize(const char* name, float width,
|
||||
float height);
|
||||
void HALSIMGUI_SetWindowPadding(const char* name, float x, float y);
|
||||
int HALSIMGUI_AreOutputsDisabled(void);
|
||||
|
||||
} // extern "C"
|
||||
@@ -127,6 +128,14 @@ class HALSimGui {
|
||||
*/
|
||||
static void SetDefaultWindowSize(const char* name, float width, float height);
|
||||
|
||||
/**
|
||||
* Sets internal padding of window added with AddWindow().
|
||||
* @param name window name (same as name passed to AddWindow())
|
||||
* @param x horizontal padding
|
||||
* @param y vertical padding
|
||||
*/
|
||||
static void SetWindowPadding(const char* name, float x, float y);
|
||||
|
||||
/**
|
||||
* Returns true if outputs are disabled.
|
||||
*
|
||||
|
||||
47
simulation/halsim_gui/src/main/native/include/IniSaver.h
Normal file
47
simulation/halsim_gui/src/main/native/include/IniSaver.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
#include <wpi/DenseMap.h>
|
||||
|
||||
namespace halsimgui {
|
||||
|
||||
template <typename Info>
|
||||
class IniSaver {
|
||||
public:
|
||||
explicit IniSaver(const char* typeName) : m_typeName(typeName) {}
|
||||
void Initialize();
|
||||
|
||||
// pass through useful functions to map
|
||||
Info& operator[](int index) { return m_map[index]; }
|
||||
|
||||
auto begin() { return m_map.begin(); }
|
||||
auto end() { return m_map.end(); }
|
||||
auto find(int index) { return m_map.find(index); }
|
||||
|
||||
auto begin() const { return m_map.begin(); }
|
||||
auto end() const { return m_map.end(); }
|
||||
auto find(int index) const { return m_map.find(index); }
|
||||
|
||||
private:
|
||||
static void* ReadOpen(ImGuiContext* ctx, ImGuiSettingsHandler* handler,
|
||||
const char* name);
|
||||
static void ReadLine(ImGuiContext* ctx, ImGuiSettingsHandler* handler,
|
||||
void* entry, const char* lineStr);
|
||||
static void WriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler,
|
||||
ImGuiTextBuffer* out_buf);
|
||||
|
||||
const char* m_typeName;
|
||||
wpi::DenseMap<int, Info> m_map;
|
||||
};
|
||||
|
||||
} // namespace halsimgui
|
||||
|
||||
#include "IniSaver.inl"
|
||||
56
simulation/halsim_gui/src/main/native/include/IniSaver.inl
Normal file
56
simulation/halsim_gui/src/main/native/include/IniSaver.inl
Normal file
@@ -0,0 +1,56 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace halsimgui {
|
||||
|
||||
template <typename Info>
|
||||
void IniSaver<Info>::Initialize() {
|
||||
// hook ini handler to save settings
|
||||
ImGuiSettingsHandler iniHandler;
|
||||
iniHandler.TypeName = m_typeName;
|
||||
iniHandler.TypeHash = ImHashStr(m_typeName);
|
||||
iniHandler.ReadOpenFn = ReadOpen;
|
||||
iniHandler.ReadLineFn = ReadLine;
|
||||
iniHandler.WriteAllFn = WriteAll;
|
||||
iniHandler.UserData = this;
|
||||
ImGui::GetCurrentContext()->SettingsHandlers.push_back(iniHandler);
|
||||
}
|
||||
|
||||
template <typename Info>
|
||||
void* IniSaver<Info>::ReadOpen(ImGuiContext* ctx, ImGuiSettingsHandler* handler,
|
||||
const char* name) {
|
||||
auto self = static_cast<IniSaver*>(handler->UserData);
|
||||
int num;
|
||||
if (wpi::StringRef{name}.getAsInteger(10, num)) return nullptr;
|
||||
return &self->m_map[num];
|
||||
}
|
||||
|
||||
template <typename Info>
|
||||
void IniSaver<Info>::ReadLine(ImGuiContext* ctx, ImGuiSettingsHandler* handler,
|
||||
void* entry, const char* lineStr) {
|
||||
auto element = static_cast<Info*>(entry);
|
||||
wpi::StringRef line{lineStr};
|
||||
auto [name, value] = line.split('=');
|
||||
name = name.trim();
|
||||
value = value.trim();
|
||||
element->ReadIni(name, value);
|
||||
}
|
||||
|
||||
template <typename Info>
|
||||
void IniSaver<Info>::WriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler,
|
||||
ImGuiTextBuffer* out_buf) {
|
||||
auto self = static_cast<IniSaver*>(handler->UserData);
|
||||
for (auto&& it : self->m_map) {
|
||||
out_buf->appendf("[%s][%d]\n", self->m_typeName, it.first);
|
||||
it.second.WriteIni(out_buf);
|
||||
out_buf->append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace halsimgui
|
||||
47
simulation/halsim_gui/src/main/native/include/IniSaverInfo.h
Normal file
47
simulation/halsim_gui/src/main/native/include/IniSaverInfo.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <imgui.h>
|
||||
#include <wpi/StringRef.h>
|
||||
|
||||
namespace halsimgui {
|
||||
|
||||
class NameInfo {
|
||||
public:
|
||||
NameInfo() { m_name[0] = '\0'; }
|
||||
|
||||
bool HasName() const { return m_name[0] != '\0'; }
|
||||
const char* GetName() const { return m_name; }
|
||||
void GetName(char* buf, size_t size, const char* defaultName, int index);
|
||||
void GetName(char* buf, size_t size, const char* defaultName, int index,
|
||||
int index2);
|
||||
bool ReadIni(wpi::StringRef name, wpi::StringRef value);
|
||||
void WriteIni(ImGuiTextBuffer* out);
|
||||
void PushEditNameId(int index);
|
||||
void PopupEditName(int index);
|
||||
|
||||
private:
|
||||
char m_name[64];
|
||||
};
|
||||
|
||||
class OpenInfo {
|
||||
public:
|
||||
OpenInfo() = default;
|
||||
explicit OpenInfo(bool open) : m_open(open) {}
|
||||
|
||||
bool IsOpen() const { return m_open; }
|
||||
void SetOpen(bool open) { m_open = open; }
|
||||
bool ReadIni(wpi::StringRef name, wpi::StringRef value);
|
||||
void WriteIni(ImGuiTextBuffer* out);
|
||||
|
||||
private:
|
||||
bool m_open = false;
|
||||
};
|
||||
|
||||
} // namespace halsimgui
|
||||
@@ -0,0 +1,48 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
#include <wpi/StringMap.h>
|
||||
#include <wpi/StringRef.h>
|
||||
|
||||
namespace halsimgui {
|
||||
|
||||
template <typename Info>
|
||||
class IniSaverString {
|
||||
public:
|
||||
explicit IniSaverString(const char* typeName) : m_typeName(typeName) {}
|
||||
void Initialize();
|
||||
|
||||
// pass through useful functions to map
|
||||
Info& operator[](wpi::StringRef key) { return m_map[key]; }
|
||||
|
||||
auto begin() { return m_map.begin(); }
|
||||
auto end() { return m_map.end(); }
|
||||
auto find(wpi::StringRef key) { return m_map.find(key); }
|
||||
|
||||
auto begin() const { return m_map.begin(); }
|
||||
auto end() const { return m_map.end(); }
|
||||
auto find(wpi::StringRef key) const { return m_map.find(key); }
|
||||
|
||||
private:
|
||||
static void* ReadOpen(ImGuiContext* ctx, ImGuiSettingsHandler* handler,
|
||||
const char* name);
|
||||
static void ReadLine(ImGuiContext* ctx, ImGuiSettingsHandler* handler,
|
||||
void* entry, const char* lineStr);
|
||||
static void WriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler,
|
||||
ImGuiTextBuffer* out_buf);
|
||||
|
||||
const char* m_typeName;
|
||||
wpi::StringMap<Info> m_map;
|
||||
};
|
||||
|
||||
} // namespace halsimgui
|
||||
|
||||
#include "IniSaverString.inl"
|
||||
@@ -0,0 +1,57 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace halsimgui {
|
||||
|
||||
template <typename Info>
|
||||
void IniSaverString<Info>::Initialize() {
|
||||
// hook ini handler to save settings
|
||||
ImGuiSettingsHandler iniHandler;
|
||||
iniHandler.TypeName = m_typeName;
|
||||
iniHandler.TypeHash = ImHashStr(m_typeName);
|
||||
iniHandler.ReadOpenFn = ReadOpen;
|
||||
iniHandler.ReadLineFn = ReadLine;
|
||||
iniHandler.WriteAllFn = WriteAll;
|
||||
iniHandler.UserData = this;
|
||||
ImGui::GetCurrentContext()->SettingsHandlers.push_back(iniHandler);
|
||||
}
|
||||
|
||||
template <typename Info>
|
||||
void* IniSaverString<Info>::ReadOpen(ImGuiContext* ctx,
|
||||
ImGuiSettingsHandler* handler,
|
||||
const char* name) {
|
||||
auto self = static_cast<IniSaverString*>(handler->UserData);
|
||||
return &self->m_map[name];
|
||||
}
|
||||
|
||||
template <typename Info>
|
||||
void IniSaverString<Info>::ReadLine(ImGuiContext* ctx,
|
||||
ImGuiSettingsHandler* handler, void* entry,
|
||||
const char* lineStr) {
|
||||
auto element = static_cast<Info*>(entry);
|
||||
wpi::StringRef line{lineStr};
|
||||
auto [name, value] = line.split('=');
|
||||
name = name.trim();
|
||||
value = value.trim();
|
||||
element->ReadIni(name, value);
|
||||
}
|
||||
|
||||
template <typename Info>
|
||||
void IniSaverString<Info>::WriteAll(ImGuiContext* ctx,
|
||||
ImGuiSettingsHandler* handler,
|
||||
ImGuiTextBuffer* out_buf) {
|
||||
auto self = static_cast<IniSaverString*>(handler->UserData);
|
||||
for (auto&& it : self->m_map) {
|
||||
out_buf->appendf("[%s][%s]\n", self->m_typeName, it.getKey().data());
|
||||
it.second.WriteIni(out_buf);
|
||||
out_buf->append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace halsimgui
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -24,6 +24,7 @@ import edu.wpi.first.hal.HAL;
|
||||
import edu.wpi.first.networktables.NetworkTableEntry;
|
||||
import edu.wpi.first.wpilibj.RobotState;
|
||||
import edu.wpi.first.wpilibj.Sendable;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
|
||||
|
||||
@@ -35,7 +36,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
|
||||
* Subsystem#periodic()} methods to be called and for their default commands to be scheduled.
|
||||
*/
|
||||
@SuppressWarnings({"PMD.GodClass", "PMD.TooManyMethods", "PMD.TooManyFields"})
|
||||
public final class CommandScheduler implements Sendable {
|
||||
public final class CommandScheduler implements Sendable, AutoCloseable {
|
||||
/**
|
||||
* The Singleton Instance.
|
||||
*/
|
||||
@@ -70,11 +71,6 @@ public final class CommandScheduler implements Sendable {
|
||||
|
||||
private boolean m_disabled;
|
||||
|
||||
//NetworkTable entries for use in Sendable impl
|
||||
private NetworkTableEntry m_namesEntry;
|
||||
private NetworkTableEntry m_idsEntry;
|
||||
private NetworkTableEntry m_cancelEntry;
|
||||
|
||||
//Lists of user-supplied actions to be executed on scheduling events for every command.
|
||||
private final List<Consumer<Command>> m_initActions = new ArrayList<>();
|
||||
private final List<Consumer<Command>> m_executeActions = new ArrayList<>();
|
||||
@@ -89,8 +85,22 @@ public final class CommandScheduler implements Sendable {
|
||||
|
||||
|
||||
CommandScheduler() {
|
||||
HAL.report(tResourceType.kResourceType_Command, tInstances.kCommand_Scheduler);
|
||||
HAL.report(tResourceType.kResourceType_Command, tInstances.kCommand2_Scheduler);
|
||||
SendableRegistry.addLW(this, "Scheduler");
|
||||
LiveWindow.setEnabledListener(() -> {
|
||||
disable();
|
||||
cancelAll();
|
||||
});
|
||||
LiveWindow.setDisabledListener(() -> {
|
||||
enable();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
SendableRegistry.remove(this);
|
||||
LiveWindow.setEnabledListener(null);
|
||||
LiveWindow.setDisabledListener(null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -375,7 +385,7 @@ public final class CommandScheduler implements Sendable {
|
||||
* Cancels all commands that are currently scheduled.
|
||||
*/
|
||||
public void cancelAll() {
|
||||
for (Command command : m_scheduledCommands.keySet()) {
|
||||
for (Command command : m_scheduledCommands.keySet().toArray(new Command[0])) {
|
||||
cancel(command);
|
||||
}
|
||||
}
|
||||
@@ -473,12 +483,12 @@ public final class CommandScheduler implements Sendable {
|
||||
@Override
|
||||
public void initSendable(SendableBuilder builder) {
|
||||
builder.setSmartDashboardType("Scheduler");
|
||||
m_namesEntry = builder.getEntry("Names");
|
||||
m_idsEntry = builder.getEntry("Ids");
|
||||
m_cancelEntry = builder.getEntry("Cancel");
|
||||
final NetworkTableEntry namesEntry = builder.getEntry("Names");
|
||||
final NetworkTableEntry idsEntry = builder.getEntry("Ids");
|
||||
final NetworkTableEntry cancelEntry = builder.getEntry("Cancel");
|
||||
builder.setUpdateTable(() -> {
|
||||
|
||||
if (m_namesEntry == null || m_idsEntry == null || m_cancelEntry == null) {
|
||||
if (namesEntry == null || idsEntry == null || cancelEntry == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -489,21 +499,21 @@ public final class CommandScheduler implements Sendable {
|
||||
ids.put((double) command.hashCode(), command);
|
||||
}
|
||||
|
||||
double[] toCancel = m_cancelEntry.getDoubleArray(new double[0]);
|
||||
double[] toCancel = cancelEntry.getDoubleArray(new double[0]);
|
||||
if (toCancel.length > 0) {
|
||||
for (double hash : toCancel) {
|
||||
cancel(ids.get(hash));
|
||||
ids.remove(hash);
|
||||
}
|
||||
m_cancelEntry.setDoubleArray(new double[0]);
|
||||
cancelEntry.setDoubleArray(new double[0]);
|
||||
}
|
||||
|
||||
List<String> names = new ArrayList<>();
|
||||
|
||||
ids.values().forEach(command -> names.add(command.getName()));
|
||||
|
||||
m_namesEntry.setStringArray(names.toArray(new String[0]));
|
||||
m_idsEntry.setNumberArray(ids.keySet().toArray(new Double[0]));
|
||||
namesEntry.setStringArray(names.toArray(new String[0]));
|
||||
idsEntry.setNumberArray(ids.keySet().toArray(new Double[0]));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -348,6 +348,6 @@ public class MecanumControllerCommand extends CommandBase {
|
||||
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
return m_timer.hasPeriodPassed(m_trajectory.getTotalTimeSeconds());
|
||||
return m_timer.hasElapsed(m_trajectory.getTotalTimeSeconds());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,10 +25,20 @@ public abstract class PIDSubsystem extends SubsystemBase {
|
||||
* Creates a new PIDSubsystem.
|
||||
*
|
||||
* @param controller the PIDController to use
|
||||
* @param initialPosition the initial setpoint of the subsystem
|
||||
*/
|
||||
public PIDSubsystem(PIDController controller, double initialPosition) {
|
||||
setSetpoint(initialPosition);
|
||||
m_controller = requireNonNullParam(controller, "controller", "PIDSubsystem");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new PIDSubsystem. Initial setpoint is zero.
|
||||
*
|
||||
* @param controller the PIDController to use
|
||||
*/
|
||||
public PIDSubsystem(PIDController controller) {
|
||||
requireNonNullParam(controller, "controller", "PIDSubsystem");
|
||||
m_controller = controller;
|
||||
this(controller, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -113,7 +113,7 @@ public class ProfiledPIDCommand extends CommandBase {
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
m_controller.reset();
|
||||
m_controller.reset(m_measurement.getAsDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -27,10 +27,21 @@ public abstract class ProfiledPIDSubsystem extends SubsystemBase {
|
||||
* Creates a new ProfiledPIDSubsystem.
|
||||
*
|
||||
* @param controller the ProfiledPIDController to use
|
||||
* @param initialPosition the initial goal position of the controller
|
||||
*/
|
||||
public ProfiledPIDSubsystem(ProfiledPIDController controller,
|
||||
double initialPosition) {
|
||||
m_controller = requireNonNullParam(controller, "controller", "ProfiledPIDSubsystem");
|
||||
setGoal(initialPosition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new ProfiledPIDSubsystem. Initial goal position is zero.
|
||||
*
|
||||
* @param controller the ProfiledPIDController to use
|
||||
*/
|
||||
public ProfiledPIDSubsystem(ProfiledPIDController controller) {
|
||||
requireNonNullParam(controller, "controller", "ProfiledPIDSubsystem");
|
||||
m_controller = controller;
|
||||
this(controller, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,7 +93,7 @@ public abstract class ProfiledPIDSubsystem extends SubsystemBase {
|
||||
*/
|
||||
public void enable() {
|
||||
m_enabled = true;
|
||||
m_controller.reset();
|
||||
m_controller.reset(getMeasurement());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -201,6 +201,6 @@ public class RamseteCommand extends CommandBase {
|
||||
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
return m_timer.hasPeriodPassed(m_trajectory.getTotalTimeSeconds());
|
||||
return m_timer.hasElapsed(m_trajectory.getTotalTimeSeconds());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,6 @@ public abstract class SubsystemBase implements Subsystem, Sendable {
|
||||
*/
|
||||
public void addChild(String name, Sendable child) {
|
||||
SendableRegistry.addLW(child, getSubsystem(), name);
|
||||
SendableRegistry.addChild(this, child);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -153,6 +153,6 @@ public class SwerveControllerCommand extends CommandBase {
|
||||
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
return m_timer.hasPeriodPassed(m_trajectory.getTotalTimeSeconds());
|
||||
return m_timer.hasElapsed(m_trajectory.getTotalTimeSeconds());
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user