mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
Compare commits
147 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 | ||
|
|
e20d96ea4e | ||
|
|
a76d006a07 | ||
|
|
24c031d692 | ||
|
|
6b4eecf5fe | ||
|
|
ccdd0fbdb2 | ||
|
|
5c6b8a0f45 | ||
|
|
67d2fed685 | ||
|
|
d8f11eb149 | ||
|
|
b2ae75acd8 | ||
|
|
4f951789fe | ||
|
|
005c4c5beb | ||
|
|
34f6b3f4c0 | ||
|
|
f7a93713fa | ||
|
|
8c2ff94d70 | ||
|
|
d003ec2dc9 | ||
|
|
8e7cc3fe78 | ||
|
|
6c8f6cf479 | ||
|
|
e37ecd33ae | ||
|
|
57c5523d67 | ||
|
|
7b9c6ebc2f | ||
|
|
9a515c80f8 | ||
|
|
5b73c17f25 | ||
|
|
b8c1024261 | ||
|
|
2622c6c291 | ||
|
|
f66ae59992 | ||
|
|
5e97c81d80 | ||
|
|
f79b7a058a | ||
|
|
e49494830f | ||
|
|
b67d049ac2 | ||
|
|
70102a60b7 | ||
|
|
6dcd2b0e2c | ||
|
|
ce3973435e | ||
|
|
3fcfc8ea72 | ||
|
|
6ceafe3cd0 |
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",
|
||||
"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
|
||||
|
||||
|
||||
==============================================================================
|
||||
|
||||
@@ -1,19 +1,91 @@
|
||||
# Starter pipeline
|
||||
# Start with a minimal pipeline that you can customize to build and deploy your code.
|
||||
# Add steps that build, run tests, deploy, and more:
|
||||
# https://aka.ms/yaml
|
||||
|
||||
trigger:
|
||||
- master
|
||||
|
||||
pool:
|
||||
vmImage: 'ubuntu-latest'
|
||||
|
||||
steps:
|
||||
- script: echo Hello, world!
|
||||
displayName: 'Run a one-line script'
|
||||
|
||||
- script: |
|
||||
echo Add other tasks to build, test, and deploy your project.
|
||||
echo See https://aka.ms/yaml
|
||||
displayName: 'Run a multi-line script'
|
||||
# Testing steps for real hardware
|
||||
|
||||
trigger:
|
||||
batch: true
|
||||
branches:
|
||||
include:
|
||||
- master
|
||||
|
||||
stages:
|
||||
- stage: Build
|
||||
jobs:
|
||||
- job: IntegrationTests
|
||||
displayName: Integration Tests
|
||||
pool:
|
||||
vmImage: 'Ubuntu 16.04'
|
||||
|
||||
container:
|
||||
image: wpilib/roborio-cross-ubuntu:2020-18.04
|
||||
|
||||
timeoutInMinutes: 0
|
||||
|
||||
steps:
|
||||
- task: Gradle@2
|
||||
condition: and(succeeded(), not(startsWith(variables['Build.SourceBranch'], 'refs/tags/v')))
|
||||
inputs:
|
||||
workingDirectory: ''
|
||||
gradleWrapperFile: 'gradlew'
|
||||
gradleOptions: '-Xmx3072m'
|
||||
publishJUnitResults: false
|
||||
testResultsFiles: '**/TEST-*.xml'
|
||||
tasks: 'copyWpilibJIntegrationTestJarToOutput copyWpilibCTestLibrariesToOutput'
|
||||
options: '-Ponlylinuxathena -PbuildServer'
|
||||
|
||||
- task: PublishPipelineArtifact@0
|
||||
inputs:
|
||||
artifactName: 'Integration Tests'
|
||||
targetPath: 'build/integrationTestFiles'
|
||||
|
||||
- stage: TestBench
|
||||
displayName: Test Bench
|
||||
jobs:
|
||||
- job: Cpp
|
||||
displayName: C++
|
||||
pool: RoboRioConnections
|
||||
timeoutInMinutes: 30
|
||||
workspace:
|
||||
clean: all
|
||||
steps:
|
||||
- task: DownloadPipelineArtifact@0
|
||||
inputs:
|
||||
artifactName: 'Integration Tests'
|
||||
targetPath: 'build/integrationTestFiles'
|
||||
|
||||
- task: ShellScript@2
|
||||
displayName: Run C++ Tests
|
||||
inputs:
|
||||
scriptPath: test-scripts/deploy-and-run-test-on-robot.sh
|
||||
args: 'cpp -A "--gtest_output=xml:/home/admin/testResults/cppreport.xml"'
|
||||
|
||||
- task: PublishTestResults@2
|
||||
displayName: Publish C++ Test Results
|
||||
inputs:
|
||||
testResultsFormat: 'JUnit'
|
||||
testResultsFiles: '*.xml'
|
||||
testRunTitle: 'C++ Test Report'
|
||||
searchFolder: '$(System.DefaultWorkingDirectory)/test-reports'
|
||||
|
||||
- job: Java
|
||||
pool: RoboRioConnections
|
||||
timeoutInMinutes: 30
|
||||
workspace:
|
||||
clean: all
|
||||
steps:
|
||||
- task: DownloadPipelineArtifact@0
|
||||
inputs:
|
||||
artifactName: 'Integration Tests'
|
||||
targetPath: 'build/integrationTestFiles'
|
||||
|
||||
- task: ShellScript@2
|
||||
displayName: Run Java Tests
|
||||
inputs:
|
||||
scriptPath: test-scripts/deploy-and-run-test-on-robot.sh
|
||||
args: 'java'
|
||||
|
||||
- task: PublishTestResults@2
|
||||
displayName: Publish Java Test Results
|
||||
inputs:
|
||||
testResultsFormat: 'JUnit'
|
||||
testResultsFiles: '*.xml'
|
||||
testRunTitle: 'Java Test Report'
|
||||
searchFolder: '$(System.DefaultWorkingDirectory)/test-reports'
|
||||
|
||||
@@ -6,7 +6,7 @@ plugins {
|
||||
id 'edu.wpi.first.wpilib.repositories.WPILibRepositoriesPlugin' version '2020.2'
|
||||
id 'edu.wpi.first.NativeUtils' apply false
|
||||
id 'edu.wpi.first.GradleJni' version '0.10.1'
|
||||
id 'edu.wpi.first.GradleVsCode' version '0.10.0'
|
||||
id 'edu.wpi.first.GradleVsCode' version '0.11.0'
|
||||
id 'idea'
|
||||
id 'visual-studio'
|
||||
id 'net.ltgt.errorprone' version '1.1.1' apply false
|
||||
|
||||
@@ -5,5 +5,5 @@ repositories {
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
implementation "edu.wpi.first:native-utils:2020.5.2"
|
||||
implementation "edu.wpi.first:native-utils:2020.7.2"
|
||||
}
|
||||
|
||||
@@ -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,12 +1216,13 @@ 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) {
|
||||
int vendorId, productId;
|
||||
if (GetVendorProduct(deviceNum, &vendorId, &productId)) {
|
||||
m_ps3eyecam_exposure = vendorId == 0x2000 && productId == 0x0145;
|
||||
m_ps3eyecam_exposure = vendorId == 0x1415 && productId == 0x2000;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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})
|
||||
|
||||
@@ -192,7 +192,7 @@ model {
|
||||
if (!(it instanceof NativeBinarySpec)) return
|
||||
if (it.component.name != 'hal' && it.component.name != 'halBase') return
|
||||
if (it.targetPlatform.name != nativeUtils.wpi.platforms.roborio) return
|
||||
nativeUtils.useRequiredLibrary(it, 'netcomm_shared', 'chipobject_shared')
|
||||
nativeUtils.useRequiredLibrary(it, 'netcomm_shared', 'chipobject_shared', 'visa_shared')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
94
hal/src/main/java/edu/wpi/first/hal/sim/SimDeviceSim.java
Normal file
94
hal/src/main/java/edu/wpi/first/hal/sim/SimDeviceSim.java
Normal file
@@ -0,0 +1,94 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.hal.sim;
|
||||
|
||||
import edu.wpi.first.hal.SimBoolean;
|
||||
import edu.wpi.first.hal.SimDouble;
|
||||
import edu.wpi.first.hal.SimEnum;
|
||||
import edu.wpi.first.hal.SimValue;
|
||||
import edu.wpi.first.hal.sim.mockdata.SimDeviceDataJNI;
|
||||
|
||||
public class SimDeviceSim {
|
||||
private final int m_handle;
|
||||
|
||||
public SimDeviceSim(String name) {
|
||||
m_handle = SimDeviceDataJNI.getSimDeviceHandle(name);
|
||||
}
|
||||
|
||||
public SimValue getValue(String name) {
|
||||
int handle = SimDeviceDataJNI.getSimValueHandle(m_handle, name);
|
||||
if (handle <= 0) {
|
||||
return null;
|
||||
}
|
||||
return new SimValue(handle);
|
||||
}
|
||||
|
||||
public SimDouble getDouble(String name) {
|
||||
int handle = SimDeviceDataJNI.getSimValueHandle(m_handle, name);
|
||||
if (handle <= 0) {
|
||||
return null;
|
||||
}
|
||||
return new SimDouble(handle);
|
||||
}
|
||||
|
||||
public SimEnum getEnum(String name) {
|
||||
int handle = SimDeviceDataJNI.getSimValueHandle(m_handle, name);
|
||||
if (handle <= 0) {
|
||||
return null;
|
||||
}
|
||||
return new SimEnum(handle);
|
||||
}
|
||||
|
||||
public SimBoolean getBoolean(String name) {
|
||||
int handle = SimDeviceDataJNI.getSimValueHandle(m_handle, name);
|
||||
if (handle <= 0) {
|
||||
return null;
|
||||
}
|
||||
return new SimBoolean(handle);
|
||||
}
|
||||
|
||||
public static String[] getEnumOptions(SimEnum val) {
|
||||
return SimDeviceDataJNI.getSimValueEnumOptions(val.getNativeHandle());
|
||||
}
|
||||
|
||||
public SimDeviceDataJNI.SimValueInfo[] enumerateValues() {
|
||||
return SimDeviceDataJNI.enumerateSimValues(m_handle);
|
||||
}
|
||||
|
||||
public int getNativeHandle() {
|
||||
return m_handle;
|
||||
}
|
||||
|
||||
public CallbackStore registerValueCreatedCallback(SimValueCallback callback, boolean initialNotify) {
|
||||
int uid = SimDeviceDataJNI.registerSimValueCreatedCallback(m_handle, callback, initialNotify);
|
||||
return new CallbackStore(uid, SimDeviceDataJNI::cancelSimValueCreatedCallback);
|
||||
}
|
||||
|
||||
public CallbackStore registerValueChangedCallback(SimValueCallback callback, boolean initialNotify) {
|
||||
int uid = SimDeviceDataJNI.registerSimValueChangedCallback(m_handle, callback, initialNotify);
|
||||
return new CallbackStore(uid, SimDeviceDataJNI::cancelSimValueChangedCallback);
|
||||
}
|
||||
|
||||
public static SimDeviceDataJNI.SimDeviceInfo[] enumerateDevices(String prefix) {
|
||||
return SimDeviceDataJNI.enumerateSimDevices(prefix);
|
||||
}
|
||||
|
||||
public CallbackStore registerDeviceCreatedCallback(String prefix, SimDeviceCallback callback, boolean initialNotify) {
|
||||
int uid = SimDeviceDataJNI.registerSimDeviceCreatedCallback(prefix, callback, initialNotify);
|
||||
return new CallbackStore(uid, SimDeviceDataJNI::cancelSimDeviceCreatedCallback);
|
||||
}
|
||||
|
||||
public CallbackStore registerDeviceFreedCallback(String prefix, SimDeviceCallback callback) {
|
||||
int uid = SimDeviceDataJNI.registerSimDeviceFreedCallback(prefix, callback);
|
||||
return new CallbackStore(uid, SimDeviceDataJNI::cancelSimDeviceFreedCallback);
|
||||
}
|
||||
|
||||
public static void resetData() {
|
||||
SimDeviceDataJNI.resetSimDeviceData();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -21,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;
|
||||
@@ -54,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(
|
||||
@@ -148,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);
|
||||
|
||||
@@ -224,26 +224,38 @@ double HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analogPortHandle,
|
||||
|
||||
int32_t HAL_GetAnalogLSBWeight(HAL_AnalogInputHandle analogPortHandle,
|
||||
int32_t* status) {
|
||||
auto port = analogInputHandles->Get(analogPortHandle);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
int32_t lsbWeight = FRC_NetworkCommunication_nAICalibration_getLSBWeight(
|
||||
0, port->channel, status); // XXX: aiSystemIndex == 0?
|
||||
return lsbWeight;
|
||||
// On the roboRIO, LSB is the same for all channels. So the channel lookup can
|
||||
// be avoided
|
||||
return FRC_NetworkCommunication_nAICalibration_getLSBWeight(0, 0, status);
|
||||
|
||||
// Keep the old code for future hardware
|
||||
|
||||
// auto port = analogInputHandles->Get(analogPortHandle);
|
||||
// if (port == nullptr) {
|
||||
// *status = HAL_HANDLE_ERROR;
|
||||
// return 0;
|
||||
// }
|
||||
// int32_t lsbWeight = FRC_NetworkCommunication_nAICalibration_getLSBWeight(
|
||||
// 0, port->channel, status); // XXX: aiSystemIndex == 0?
|
||||
// return lsbWeight;
|
||||
}
|
||||
|
||||
int32_t HAL_GetAnalogOffset(HAL_AnalogInputHandle analogPortHandle,
|
||||
int32_t* status) {
|
||||
auto port = analogInputHandles->Get(analogPortHandle);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
int32_t offset = FRC_NetworkCommunication_nAICalibration_getOffset(
|
||||
0, port->channel, status); // XXX: aiSystemIndex == 0?
|
||||
return offset;
|
||||
// On the roboRIO, offset is the same for all channels. So the channel lookup
|
||||
// can be avoided
|
||||
return FRC_NetworkCommunication_nAICalibration_getOffset(0, 0, status);
|
||||
|
||||
// Keep the old code for future hardware
|
||||
|
||||
// auto port = analogInputHandles->Get(analogPortHandle);
|
||||
// if (port == nullptr) {
|
||||
// *status = HAL_HANDLE_ERROR;
|
||||
// return 0;
|
||||
// }
|
||||
// int32_t offset = FRC_NetworkCommunication_nAICalibration_getOffset(
|
||||
// 0, port->channel, status); // XXX: aiSystemIndex == 0?
|
||||
// return offset;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
#include "AnalogInternal.h"
|
||||
#include "DigitalInternal.h"
|
||||
@@ -28,7 +29,8 @@
|
||||
|
||||
using namespace hal;
|
||||
|
||||
static_assert(std::is_pod_v<HAL_DMASample>, "DMA Sample must be POD");
|
||||
static_assert(std::is_standard_layout_v<HAL_DMASample>,
|
||||
"HAL_DMASample must have standard layout");
|
||||
|
||||
namespace {
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -118,7 +120,11 @@ void* HAL_CleanInterrupts(HAL_InterruptHandle interruptHandle,
|
||||
if (anInterrupt == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
anInterrupt->manager->disable(status);
|
||||
|
||||
if (anInterrupt->manager->isEnabled(status)) {
|
||||
anInterrupt->manager->disable(status);
|
||||
}
|
||||
|
||||
void* param = anInterrupt->param;
|
||||
return param;
|
||||
}
|
||||
@@ -152,7 +158,10 @@ void HAL_EnableInterrupts(HAL_InterruptHandle interruptHandle,
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
anInterrupt->manager->enable(status);
|
||||
|
||||
if (!anInterrupt->manager->isEnabled(status)) {
|
||||
anInterrupt->manager->enable(status);
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_DisableInterrupts(HAL_InterruptHandle interruptHandle,
|
||||
@@ -162,7 +171,9 @@ void HAL_DisableInterrupts(HAL_InterruptHandle interruptHandle,
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
anInterrupt->manager->disable(status);
|
||||
if (anInterrupt->manager->isEnabled(status)) {
|
||||
anInterrupt->manager->disable(status);
|
||||
}
|
||||
}
|
||||
|
||||
int64_t HAL_ReadInterruptRisingTimestamp(HAL_InterruptHandle interruptHandle,
|
||||
@@ -259,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"
|
||||
|
||||
@@ -175,7 +175,11 @@ double HAL_GetPDPTemperature(HAL_PDPHandle handle, int32_t* status) {
|
||||
HAL_ReadCANPacketTimeout(handle, Status3, pdpStatus.data, &length,
|
||||
&receivedTimestamp, TimeoutMs, status);
|
||||
|
||||
return pdpStatus.bits.temp * 1.03250836957542 - 67.8564500484966;
|
||||
if (*status != 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return pdpStatus.bits.temp * 1.03250836957542 - 67.8564500484966;
|
||||
}
|
||||
}
|
||||
|
||||
double HAL_GetPDPVoltage(HAL_PDPHandle handle, int32_t* status) {
|
||||
@@ -186,7 +190,11 @@ double HAL_GetPDPVoltage(HAL_PDPHandle handle, int32_t* status) {
|
||||
HAL_ReadCANPacketTimeout(handle, Status3, pdpStatus.data, &length,
|
||||
&receivedTimestamp, TimeoutMs, status);
|
||||
|
||||
return pdpStatus.bits.busVoltage * 0.05 + 4.0; /* 50mV per unit plus 4V. */
|
||||
if (*status != 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return pdpStatus.bits.busVoltage * 0.05 + 4.0; /* 50mV per unit plus 4V. */
|
||||
}
|
||||
}
|
||||
|
||||
double HAL_GetPDPChannelCurrent(HAL_PDPHandle handle, int32_t channel,
|
||||
@@ -205,6 +213,9 @@ double HAL_GetPDPChannelCurrent(HAL_PDPHandle handle, int32_t channel,
|
||||
PdpStatus1 pdpStatus;
|
||||
HAL_ReadCANPacketTimeout(handle, Status1, pdpStatus.data, &length,
|
||||
&receivedTimestamp, TimeoutMs, status);
|
||||
if (*status != 0) {
|
||||
return 0;
|
||||
}
|
||||
switch (channel) {
|
||||
case 0:
|
||||
raw = (static_cast<uint32_t>(pdpStatus.bits.chan1_h8) << 2) |
|
||||
@@ -235,6 +246,9 @@ double HAL_GetPDPChannelCurrent(HAL_PDPHandle handle, int32_t channel,
|
||||
PdpStatus2 pdpStatus;
|
||||
HAL_ReadCANPacketTimeout(handle, Status2, pdpStatus.data, &length,
|
||||
&receivedTimestamp, TimeoutMs, status);
|
||||
if (*status != 0) {
|
||||
return 0;
|
||||
}
|
||||
switch (channel) {
|
||||
case 6:
|
||||
raw = (static_cast<uint32_t>(pdpStatus.bits.chan7_h8) << 2) |
|
||||
@@ -265,6 +279,9 @@ double HAL_GetPDPChannelCurrent(HAL_PDPHandle handle, int32_t channel,
|
||||
PdpStatus3 pdpStatus;
|
||||
HAL_ReadCANPacketTimeout(handle, Status3, pdpStatus.data, &length,
|
||||
&receivedTimestamp, TimeoutMs, status);
|
||||
if (*status != 0) {
|
||||
return 0;
|
||||
}
|
||||
switch (channel) {
|
||||
case 12:
|
||||
raw = (static_cast<uint32_t>(pdpStatus.bits.chan13_h8) << 2) |
|
||||
@@ -365,6 +382,9 @@ double HAL_GetPDPTotalCurrent(HAL_PDPHandle handle, int32_t* status) {
|
||||
|
||||
HAL_ReadCANPacketTimeout(handle, StatusEnergy, pdpStatus.data, &length,
|
||||
&receivedTimestamp, TimeoutMs, status);
|
||||
if (*status != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t raw;
|
||||
raw = pdpStatus.bits.TotalCurrent_125mAperunit_h8;
|
||||
@@ -380,6 +400,9 @@ double HAL_GetPDPTotalPower(HAL_PDPHandle handle, int32_t* status) {
|
||||
|
||||
HAL_ReadCANPacketTimeout(handle, StatusEnergy, pdpStatus.data, &length,
|
||||
&receivedTimestamp, TimeoutMs, status);
|
||||
if (*status != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t raw;
|
||||
raw = pdpStatus.bits.Power_125mWperunit_h4;
|
||||
@@ -397,6 +420,9 @@ double HAL_GetPDPTotalEnergy(HAL_PDPHandle handle, int32_t* status) {
|
||||
|
||||
HAL_ReadCANPacketTimeout(handle, StatusEnergy, pdpStatus.data, &length,
|
||||
&receivedTimestamp, TimeoutMs, status);
|
||||
if (*status != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t raw;
|
||||
raw = pdpStatus.bits.Energy_125mWPerUnitXTmeas_h4;
|
||||
|
||||
@@ -565,7 +565,7 @@ void HAL_StopSPIAuto(HAL_SPIPort port, int32_t* status) {
|
||||
void HAL_SetSPIAutoTransmitData(HAL_SPIPort port, const uint8_t* dataToSend,
|
||||
int32_t dataSize, int32_t zeroSize,
|
||||
int32_t* status) {
|
||||
if (dataSize < 0 || dataSize > 16) {
|
||||
if (dataSize < 0 || dataSize > 32) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
return;
|
||||
}
|
||||
@@ -589,7 +589,7 @@ void HAL_SetSPIAutoTransmitData(HAL_SPIPort port, const uint8_t* dataToSend,
|
||||
// set byte counts
|
||||
tSPI::tAutoByteCount config;
|
||||
config.ZeroByteCount = static_cast<unsigned>(zeroSize) & 0x7f;
|
||||
config.TxByteCount = static_cast<unsigned>(dataSize) & 0xf;
|
||||
config.TxByteCount = static_cast<unsigned>(dataSize) & 0x1f;
|
||||
spiSystem->writeAutoByteCount(config, status);
|
||||
}
|
||||
|
||||
@@ -631,4 +631,21 @@ int32_t HAL_GetSPIAutoDroppedCount(HAL_SPIPort port, int32_t* status) {
|
||||
return spiSystem->readTransferSkippedFullCount(status);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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) 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. */
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "hal/Types.h"
|
||||
|
||||
/**
|
||||
* @defgroup hal_extensions Simulator Extensions
|
||||
* @ingroup hal_capi
|
||||
@@ -41,5 +43,19 @@ int HAL_LoadOneExtension(const char* library);
|
||||
* @return the succes state of the initialization
|
||||
*/
|
||||
int HAL_LoadExtensions(void);
|
||||
|
||||
/**
|
||||
* Enables or disables the message saying no HAL extensions were found.
|
||||
*
|
||||
* Some apps don't care, and the message create clutter. For general team code,
|
||||
* we want it.
|
||||
*
|
||||
* This must be called before HAL_Initialize is called.
|
||||
*
|
||||
* This defaults to true.
|
||||
*
|
||||
* @param showMessage true to show message, false to not.
|
||||
*/
|
||||
void HAL_SetShowExtensionsNotFoundMessages(HAL_Bool showMessage);
|
||||
} // extern "C"
|
||||
/** @} */
|
||||
|
||||
@@ -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)
|
||||
|
||||
79
hal/src/main/native/include/simulation/SimDeviceSim.h
Normal file
79
hal/src/main/native/include/simulation/SimDeviceSim.h
Normal file
@@ -0,0 +1,79 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "CallbackStore.h"
|
||||
#include "hal/SimDevice.h"
|
||||
#include "mockdata/SimDeviceData.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
class SimDeviceSim {
|
||||
public:
|
||||
explicit SimDeviceSim(const char* name)
|
||||
: m_handle{HALSIM_GetSimDeviceHandle(name)} {}
|
||||
|
||||
hal::SimValue GetValue(const char* name) const {
|
||||
return HALSIM_GetSimValueHandle(m_handle, name);
|
||||
}
|
||||
|
||||
hal::SimDouble GetDouble(const char* name) const {
|
||||
return HALSIM_GetSimValueHandle(m_handle, name);
|
||||
}
|
||||
|
||||
hal::SimEnum GetEnum(const char* name) const {
|
||||
return HALSIM_GetSimValueHandle(m_handle, name);
|
||||
}
|
||||
|
||||
hal::SimBoolean GetBoolean(const char* name) const {
|
||||
return HALSIM_GetSimValueHandle(m_handle, name);
|
||||
}
|
||||
|
||||
static std::vector<std::string> GetEnumOptions(hal::SimEnum val) {
|
||||
int32_t numOptions;
|
||||
const char** options = HALSIM_GetSimValueEnumOptions(val, &numOptions);
|
||||
std::vector<std::string> rv;
|
||||
rv.reserve(numOptions);
|
||||
for (int32_t i = 0; i < numOptions; ++i) rv.emplace_back(options[i]);
|
||||
return rv;
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
void EnumerateValues(F callback) const {
|
||||
return HALSIM_EnumerateSimValues(
|
||||
m_handle, &callback,
|
||||
[](const char* name, void* param, HAL_SimValueHandle handle,
|
||||
HAL_Bool readonly, const struct HAL_Value* value) {
|
||||
std::invoke(*static_cast<F*>(param), name, handle, readonly, value);
|
||||
});
|
||||
}
|
||||
|
||||
operator HAL_SimDeviceHandle() const { return m_handle; }
|
||||
|
||||
template <typename F>
|
||||
static void EnumerateDevices(const char* prefix, F callback) {
|
||||
return HALSIM_EnumerateSimDevices(
|
||||
prefix, &callback,
|
||||
[](const char* name, void* param, HAL_SimDeviceHandle handle) {
|
||||
std::invoke(*static_cast<F*>(param), name, handle);
|
||||
});
|
||||
}
|
||||
|
||||
static void ResetData() { HALSIM_ResetSimDeviceData(); }
|
||||
|
||||
private:
|
||||
HAL_SimDeviceHandle m_handle;
|
||||
};
|
||||
} // namespace sim
|
||||
} // namespace frc
|
||||
@@ -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. */
|
||||
@@ -26,8 +26,16 @@ void HAL_CAN_SendMessage(uint32_t messageID, const uint8_t* data,
|
||||
void HAL_CAN_ReceiveMessage(uint32_t* messageID, uint32_t messageIDMask,
|
||||
uint8_t* data, uint8_t* dataSize,
|
||||
uint32_t* timeStamp, int32_t* status) {
|
||||
// Use a data size of 42 as call check. Difficult to add check to invoke
|
||||
// handler
|
||||
*dataSize = 42;
|
||||
auto tmpStatus = *status;
|
||||
SimCanData->receiveMessage(messageID, messageIDMask, data, dataSize,
|
||||
timeStamp, status);
|
||||
// If no handler invoked, return message not found
|
||||
if (*dataSize == 42 && *status == tmpStatus) {
|
||||
*status = HAL_ERR_CANSessionMux_MessageNotFound;
|
||||
}
|
||||
}
|
||||
void HAL_CAN_OpenStreamSession(uint32_t* sessionHandle, uint32_t messageID,
|
||||
uint32_t messageIDMask, uint32_t maxMessages,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -41,6 +41,11 @@ void InitializeExtensions() {}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
static bool& GetShowNotFoundMessage() {
|
||||
static bool showMsg = true;
|
||||
return showMsg;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
int HAL_LoadOneExtension(const char* library) {
|
||||
@@ -91,8 +96,10 @@ int HAL_LoadExtensions(void) {
|
||||
wpi::SmallVector<wpi::StringRef, 2> libraries;
|
||||
const char* e = std::getenv("HALSIM_EXTENSIONS");
|
||||
if (!e) {
|
||||
wpi::outs() << "HAL Extensions: No extensions found\n";
|
||||
wpi::outs().flush();
|
||||
if (GetShowNotFoundMessage()) {
|
||||
wpi::outs() << "HAL Extensions: No extensions found\n";
|
||||
wpi::outs().flush();
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
wpi::StringRef env{e};
|
||||
@@ -105,4 +112,8 @@ int HAL_LoadExtensions(void) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
void HAL_SetShowExtensionsNotFoundMessages(HAL_Bool showMessage) {
|
||||
GetShowNotFoundMessage() = showMessage;
|
||||
}
|
||||
|
||||
} // 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. */
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.hal.sim;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import edu.wpi.first.hal.SimBoolean;
|
||||
import edu.wpi.first.hal.SimDevice;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class SimDeviceSimTest {
|
||||
@Test
|
||||
void testBasic() {
|
||||
SimDevice dev = SimDevice.create("test");
|
||||
SimBoolean devBool = dev.createBoolean("bool", false, false);
|
||||
|
||||
SimDeviceSim sim = new SimDeviceSim("test");
|
||||
SimBoolean simBool = sim.getBoolean("bool");
|
||||
|
||||
assertFalse(simBool.get());
|
||||
simBool.set(true);
|
||||
assertTrue(devBool.get());
|
||||
}
|
||||
}
|
||||
40
hal/src/test/native/cpp/sim/SimDeviceSimTest.cpp
Normal file
40
hal/src/test/native/cpp/sim/SimDeviceSimTest.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include <wpi/StringRef.h>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "hal/SimDevice.h"
|
||||
#include "simulation/SimDeviceSim.h"
|
||||
|
||||
using namespace frc::sim;
|
||||
|
||||
namespace hal {
|
||||
|
||||
TEST(SimDeviceSimTests, TestBasic) {
|
||||
SimDevice dev{"test"};
|
||||
SimBoolean devBool = dev.CreateBoolean("bool", false, false);
|
||||
|
||||
SimDeviceSim sim{"test"};
|
||||
SimBoolean simBool = sim.GetBoolean("bool");
|
||||
EXPECT_FALSE(simBool.Get());
|
||||
simBool.Set(true);
|
||||
EXPECT_TRUE(devBool.Get());
|
||||
}
|
||||
|
||||
TEST(SimDeviceSimTests, TestEnumerateDevices) {
|
||||
SimDevice dev{"test"};
|
||||
|
||||
bool foundit = false;
|
||||
SimDeviceSim::EnumerateDevices(
|
||||
"te", [&](const char* name, HAL_SimDeviceHandle handle) {
|
||||
if (wpi::StringRef(name) == "test") foundit = true;
|
||||
});
|
||||
EXPECT_TRUE(foundit);
|
||||
}
|
||||
|
||||
} // namespace hal
|
||||
@@ -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 ""
|
||||
)
|
||||
|
||||
@@ -86,18 +86,27 @@ deploy {
|
||||
}
|
||||
|
||||
tasks.register('deployJava') {
|
||||
dependsOn tasks.named('deployJreRoborio')
|
||||
dependsOn tasks.named('deployMyRobotJavaRoborio')
|
||||
dependsOn tasks.named('deployMyRobotCppLibrariesRoborio')
|
||||
try {
|
||||
dependsOn tasks.named('deployJreRoborio')
|
||||
dependsOn tasks.named('deployMyRobotJavaRoborio')
|
||||
dependsOn tasks.named('deployMyRobotCppLibrariesRoborio')
|
||||
} catch (ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register('deployShared') {
|
||||
dependsOn tasks.named('deployMyRobotCppLibrariesRoborio')
|
||||
dependsOn tasks.named('deployMyRobotCppRoborio')
|
||||
try {
|
||||
dependsOn tasks.named('deployMyRobotCppLibrariesRoborio')
|
||||
dependsOn tasks.named('deployMyRobotCppRoborio')
|
||||
} catch (ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register('deployStatic') {
|
||||
dependsOn tasks.named('deployMyRobotCppStaticRoborio')
|
||||
try {
|
||||
dependsOn tasks.named('deployMyRobotCppStaticRoborio')
|
||||
} catch (ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
mainClassName = 'Main'
|
||||
@@ -148,7 +157,7 @@ model {
|
||||
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
|
||||
lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
|
||||
if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
|
||||
nativeUtils.useRequiredLibrary(binary, 'netcomm_shared', 'chipobject_shared', 'ni_runtime_shared')
|
||||
nativeUtils.useRequiredLibrary(binary, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -177,7 +186,7 @@ model {
|
||||
lib project: ':wpiutil', library: 'wpiutil', linkage: 'static'
|
||||
lib project: ':cameraserver', library: 'cameraserver', linkage: 'static'
|
||||
if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
|
||||
nativeUtils.useRequiredLibrary(binary, 'netcomm_shared', 'chipobject_shared', 'ni_runtime_shared')
|
||||
nativeUtils.useRequiredLibrary(binary, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.7.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
|
||||
|
||||
@@ -200,7 +200,7 @@ model {
|
||||
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
|
||||
}
|
||||
if (nativeName == 'hal' && it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
|
||||
nativeUtils.useRequiredLibrary(it, 'netcomm_shared', 'chipobject_shared', 'ni_runtime_shared')
|
||||
nativeUtils.useRequiredLibrary(it, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -235,7 +235,7 @@ model {
|
||||
if (!project.hasProperty('noWpiutil')) {
|
||||
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
|
||||
if (nativeName == 'hal' && it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
|
||||
nativeUtils.useRequiredLibrary(it, 'netcomm_shared', 'chipobject_shared', 'ni_runtime_shared')
|
||||
nativeUtils.useRequiredLibrary(it, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -275,6 +275,9 @@ model {
|
||||
}
|
||||
}
|
||||
|
||||
apply from: "${rootDir}/shared/cppDesktopTestTask.gradle"
|
||||
apply from: "${rootDir}/shared/javaDesktopTestTask.gradle"
|
||||
|
||||
ext.getJniSpecClass = {
|
||||
return JniNativeLibrarySpec
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ if (!project.hasProperty('onlylinuxathena')) {
|
||||
}
|
||||
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
|
||||
if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
|
||||
nativeUtils.useRequiredLibrary(it, 'netcomm_shared', 'chipobject_shared', 'ni_runtime_shared')
|
||||
nativeUtils.useRequiredLibrary(it, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared')
|
||||
}
|
||||
} else {
|
||||
it.buildable = false
|
||||
|
||||
@@ -49,7 +49,7 @@ model {
|
||||
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
|
||||
lib library: pluginName, linkage: 'shared'
|
||||
if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
|
||||
nativeUtils.useRequiredLibrary(it, 'netcomm_shared', 'chipobject_shared', 'ni_runtime_shared')
|
||||
nativeUtils.useRequiredLibrary(it, 'netcomm_shared', 'chipobject_shared', 'visa_shared', 'ni_runtime_shared')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,54 +16,55 @@
|
||||
|
||||
#include "ExtraGuiWidgets.h"
|
||||
#include "HALSimGui.h"
|
||||
#include "IniSaver.h"
|
||||
#include "IniSaverInfo.h"
|
||||
|
||||
using namespace halsimgui;
|
||||
|
||||
static constexpr int kDefaultColumns = 10;
|
||||
static std::vector<int> numColumns;
|
||||
namespace {
|
||||
struct LEDDisplayInfo {
|
||||
int numColumns = 10;
|
||||
LEDConfig config;
|
||||
|
||||
// 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>(numColumns.size()))
|
||||
numColumns.resize(num + 1, kDefaultColumns);
|
||||
return &numColumns[num];
|
||||
}
|
||||
bool ReadIni(wpi::StringRef name, wpi::StringRef value);
|
||||
void WriteIni(ImGuiTextBuffer* out);
|
||||
};
|
||||
} // namespace
|
||||
|
||||
static void AddressableLEDReadLine(ImGuiContext* ctx,
|
||||
ImGuiSettingsHandler* handler, void* entry,
|
||||
const char* lineStr) {
|
||||
int* cols = static_cast<int*>(entry);
|
||||
// format: columns=#
|
||||
wpi::StringRef line{lineStr};
|
||||
auto [name, value] = line.split('=');
|
||||
name = name.trim();
|
||||
value = value.trim();
|
||||
static IniSaver<LEDDisplayInfo> gDisplaySettings{"AddressableLED"};
|
||||
|
||||
bool LEDDisplayInfo::ReadIni(wpi::StringRef name, wpi::StringRef value) {
|
||||
if (name == "columns") {
|
||||
int num;
|
||||
if (value.getAsInteger(10, num)) return;
|
||||
*cols = num;
|
||||
if (value.getAsInteger(10, num)) return true;
|
||||
numColumns = num;
|
||||
} else if (name == "serpentine") {
|
||||
int num;
|
||||
if (value.getAsInteger(10, num)) return true;
|
||||
config.serpentine = num != 0;
|
||||
} else if (name == "order") {
|
||||
int 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 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 < numColumns.size(); ++i) {
|
||||
out_buf->appendf("[AddressableLED][%d]\ncolumns=%d\n\n",
|
||||
static_cast<int>(i), numColumns[i]);
|
||||
}
|
||||
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>(numColumns.size()))
|
||||
numColumns.resize(numLED, kDefaultColumns);
|
||||
|
||||
for (int i = 0; i < numLED; ++i) {
|
||||
if (!HALSIM_GetAddressableLEDInitialized(i)) continue;
|
||||
@@ -78,12 +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", &numColumns[i]);
|
||||
if (numColumns[i] < 1) numColumns[i] = 1;
|
||||
ImGui::InputInt("Columns", &info.numColumns);
|
||||
{
|
||||
static const char* options[] = {"Row Major", "Column Major"};
|
||||
int val = info.config.order;
|
||||
if (ImGui::Combo("Order", &val, options, 2))
|
||||
info.config.order = static_cast<LEDConfig::Order>(val);
|
||||
}
|
||||
{
|
||||
static const char* options[] = {"Upper Left", "Lower Left", "Upper Right",
|
||||
"Lower Right"};
|
||||
int val = info.config.start;
|
||||
if (ImGui::Combo("Start", &val, options, 4))
|
||||
info.config.start = static_cast<LEDConfig::Start>(val);
|
||||
}
|
||||
ImGui::Checkbox("Serpentine", &info.config.serpentine);
|
||||
if (info.numColumns < 1) info.numColumns = 1;
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
// show as LED indicators
|
||||
@@ -100,21 +112,13 @@ static void DisplayAddressableLEDs() {
|
||||
}
|
||||
}
|
||||
|
||||
DrawLEDs(values, length, numColumns[i], colors);
|
||||
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);
|
||||
|
||||
@@ -10,30 +10,87 @@
|
||||
namespace halsimgui {
|
||||
|
||||
void DrawLEDs(const int* values, int numValues, int cols, const ImU32* colors,
|
||||
float size, float spacing) {
|
||||
if (numValues == 0) return;
|
||||
float size, float spacing, const LEDConfig& config) {
|
||||
if (numValues == 0 || cols < 1) return;
|
||||
if (size == 0) size = ImGui::GetFontSize() / 2.0;
|
||||
if (spacing == 0) spacing = ImGui::GetFontSize() / 3.0;
|
||||
|
||||
int rows = (numValues + cols - 1) / cols;
|
||||
float inc = size + spacing;
|
||||
|
||||
ImDrawList* drawList = ImGui::GetWindowDrawList();
|
||||
const ImVec2 p = ImGui::GetCursorScreenPos();
|
||||
float x = p.x + size / 2, y = p.y + size / 2;
|
||||
int rows = 1;
|
||||
for (int i = 0; i < numValues; ++i) {
|
||||
if (i >= (rows * cols)) {
|
||||
++rows;
|
||||
x = p.x + size / 2;
|
||||
y += size + spacing;
|
||||
}
|
||||
if (values[i] > 0)
|
||||
drawList->AddRectFilled(ImVec2(x, y), ImVec2(x + size, y + size),
|
||||
colors[values[i] - 1]);
|
||||
else if (values[i] < 0)
|
||||
drawList->AddRect(ImVec2(x, y), ImVec2(x + size, y + size),
|
||||
colors[-values[i] - 1], 0.0f, 0, 1.0);
|
||||
x += size + spacing;
|
||||
|
||||
float ystart, yinc;
|
||||
if (config.start & 1) {
|
||||
// lower
|
||||
ystart = p.y + size / 2 + inc * (rows - 1);
|
||||
yinc = -inc;
|
||||
} else {
|
||||
// upper
|
||||
ystart = p.y + size / 2;
|
||||
yinc = inc;
|
||||
}
|
||||
ImGui::Dummy(ImVec2((size + spacing) * cols, (size + spacing) * rows));
|
||||
|
||||
float xstart, xinc;
|
||||
if (config.start & 2) {
|
||||
// right
|
||||
xstart = p.x + size / 2 + inc * (cols - 1);
|
||||
xinc = -inc;
|
||||
} else {
|
||||
// left
|
||||
xstart = p.x + size / 2;
|
||||
xinc = inc;
|
||||
}
|
||||
|
||||
float x = xstart, y = ystart;
|
||||
if (config.order == LEDConfig::RowMajor) {
|
||||
// row major
|
||||
int row = 1;
|
||||
for (int i = 0; i < numValues; ++i) {
|
||||
if (i >= (row * cols)) {
|
||||
++row;
|
||||
if (config.serpentine) {
|
||||
x -= xinc;
|
||||
xinc = -xinc;
|
||||
} else {
|
||||
x = xstart;
|
||||
}
|
||||
y += yinc;
|
||||
}
|
||||
if (values[i] > 0)
|
||||
drawList->AddRectFilled(ImVec2(x, y), ImVec2(x + size, y + size),
|
||||
colors[values[i] - 1]);
|
||||
else if (values[i] < 0)
|
||||
drawList->AddRect(ImVec2(x, y), ImVec2(x + size, y + size),
|
||||
colors[-values[i] - 1], 0.0f, 0, 1.0);
|
||||
x += xinc;
|
||||
}
|
||||
} else {
|
||||
// column major
|
||||
int col = 1;
|
||||
for (int i = 0; i < numValues; ++i) {
|
||||
if (i >= (col * rows)) {
|
||||
++col;
|
||||
if (config.serpentine) {
|
||||
y -= yinc;
|
||||
yinc = -yinc;
|
||||
} else {
|
||||
y = ystart;
|
||||
}
|
||||
x += xinc;
|
||||
}
|
||||
if (values[i] > 0)
|
||||
drawList->AddRectFilled(ImVec2(x, y), ImVec2(x + size, y + size),
|
||||
colors[values[i] - 1]);
|
||||
else if (values[i] < 0)
|
||||
drawList->AddRect(ImVec2(x, y), ImVec2(x + size, y + size),
|
||||
colors[-values[i] - 1], 0.0f, 0, 1.0);
|
||||
y += yinc;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::Dummy(ImVec2(inc * cols, inc * rows));
|
||||
}
|
||||
|
||||
} // namespace halsimgui
|
||||
|
||||
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);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user