Skip to content

Commit

Permalink
Merge branch 'main' into upstream-utils-commands
Browse files Browse the repository at this point in the history
  • Loading branch information
KangarooKoala committed Jul 16, 2024
2 parents 53e90d0 + 7d64d4e commit 4e15117
Show file tree
Hide file tree
Showing 79 changed files with 784 additions and 341 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/command-robotpy-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
types:
- opened
paths:
- 'wpilibNewCommands/**'
- 'wpilibNewCommands/src/**/*.java'

jobs:
comment:
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
message(STATUS "Platform version: ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
endif()

cmake_minimum_required(VERSION 3.11)
cmake_minimum_required(VERSION 3.21)
project(allwpilib)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")

Expand Down
16 changes: 5 additions & 11 deletions apriltag/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,16 @@ endif()

if(WITH_JAVA_SOURCE)
include(UseJava)
file(GLOB APRILTAG_SOURCES src/main/java/edu/wpi/first/apriltag/*.java)
add_jar(
include(CreateSourceJar)
add_source_jar(
apriltag_src_jar
RESOURCES
NAMESPACE "edu/wpi/first/apriltag" ${APRILTAG_SOURCES}
NAMESPACE
"edu/wpi/first/apriltag/jni"
src/main/java/edu/wpi/first/apriltag/jni/AprilTagJNI.java
BASE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/src/main/java
OUTPUT_NAME apriltag-sources
OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest}
)

get_property(APRILTAG_SRC_JAR_FILE TARGET apriltag_src_jar PROPERTY JAR_FILE)
install(FILES ${APRILTAG_SRC_JAR_FILE} DESTINATION "${java_lib_dest}")

set_property(TARGET apriltag_src_jar PROPERTY FOLDER "java")

install_jar(apriltag_src_jar DESTINATION ${java_lib_dest})
endif()

generate_resources(
Expand Down
15 changes: 5 additions & 10 deletions cameraserver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,16 @@ endif()

if(WITH_JAVA_SOURCE)
include(UseJava)
file(GLOB CAMERASERVER_SOURCES src/main/java/edu/wpi/first/cameraserver/*.java)
file(GLOB VISION_SOURCES src/main/java/edu/wpi/first/vision/*.java)
add_jar(
include(CreateSourceJar)
add_source_jar(
cameraserver_src_jar
RESOURCES
NAMESPACE "edu/wpi/first/cameraserver" ${CAMERASERVER_SOURCES}
NAMESPACE "edu/wpi/first/vision" ${VISION_SOURCES}
BASE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/src/main/java
OUTPUT_NAME cameraserver-sources
OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest}
)

get_property(CAMERASERVER_SRC_JAR_FILE TARGET cameraserver_src_jar PROPERTY JAR_FILE)
install(FILES ${CAMERASERVER_SRC_JAR_FILE} DESTINATION "${java_lib_dest}")

set_property(TARGET cameraserver_src_jar PROPERTY FOLDER "java")

install_jar(cameraserver_src_jar DESTINATION ${java_lib_dest})
endif()

file(GLOB_RECURSE cameraserver_native_src src/main/native/cpp/*.cpp)
Expand Down
5 changes: 5 additions & 0 deletions cmake/modules/CompileWarnings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,9 @@ macro(wpilib_target_warnings target)
)
target_compile_options(${target} PRIVATE -gz=zlib)
endif()

# Disable std::mutex constexpr constructor on MSVC
if(MSVC)
target_compile_options(${target} PRIVATE /D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR)
endif()
endmacro()
34 changes: 34 additions & 0 deletions cmake/modules/CreateSourceJar.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
macro(add_source_jar target)
set(oneValueArgs OUTPUT_NAME OUTPUT_DIR)
cmake_parse_arguments(SOURCE_JAR "" "${oneValueArgs}" "BASE_DIRECTORIES" ${ARGN})
foreach(base_package_dir ${SOURCE_JAR_BASE_DIRECTORIES})
file(GLOB_RECURSE directories LIST_DIRECTORIES true ${base_package_dir}/*.directoriesonly)
# Find all packages
foreach(directory ${directories})
cmake_path(
RELATIVE_PATH
directory
BASE_DIRECTORY ${base_package_dir}
OUTPUT_VARIABLE package_name
)
file(GLOB package_sources ${directory}/*.java)
if(package_sources STREQUAL "")
continue()
endif()
# If package sources are scattered across different places, consolidate them under one package
list(FIND packages ${package_name} index)
if(index EQUAL -1)
list(APPEND packages ${package_name})
endif()
list(APPEND ${package_name} ${package_sources})
endforeach()
endforeach()
set(resources "")
foreach(package ${packages})
string(APPEND resources "NAMESPACE \"${package}\" ${${package}} ")
endforeach()
cmake_language(
EVAL CODE
"add_jar(${target} RESOURCES ${resources} OUTPUT_NAME ${SOURCE_JAR_OUTPUT_NAME} OUTPUT_DIR ${SOURCE_JAR_OUTPUT_DIR})"
)
endmacro()
15 changes: 5 additions & 10 deletions cscore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,16 @@ endif()

if(WITH_JAVA_SOURCE)
include(UseJava)
file(GLOB CSCORE_SOURCES src/main/java/edu/wpi/first/cscore/*.java)
file(GLOB CSCORE_RAW_SOURCES src/main/java/edu/wpi/first/cscore/raw/*.java)
add_jar(
include(CreateSourceJar)
add_source_jar(
cscore_src_jar
RESOURCES
NAMESPACE "edu/wpi/first/cscore" ${CSCORE_SOURCES}
NAMESPACE "edu/wpi/first/cscore/raw" ${CSCORE_RAW_SOURCES}
BASE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/src/main/java
OUTPUT_NAME cscore-sources
OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest}
)

get_property(CSCORE_SRC_JAR_FILE TARGET cscore_src_jar PROPERTY JAR_FILE)
install(FILES ${CSCORE_SRC_JAR_FILE} DESTINATION "${java_lib_dest}")

set_property(TARGET cscore_src_jar PROPERTY FOLDER "java")

install_jar(cscore_src_jar DESTINATION ${java_lib_dest})
endif()

if(WITH_TESTS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

#include "glass/hardware/PCM.h"
#include "glass/hardware/Pneumatic.h"

#include <cstdio>
#include <cstring>
Expand All @@ -20,8 +20,8 @@

using namespace glass;

bool glass::DisplayPCMSolenoids(PCMModel* model, int index,
bool outputsEnabled) {
bool glass::DisplayPneumaticControlSolenoids(PneumaticControlModel* model,
int index, bool outputsEnabled) {
wpi::SmallVector<int, 16> channels;
model->ForEachSolenoid([&](SolenoidModel& solenoid, int j) {
if (auto data = solenoid.GetOutputData()) {
Expand Down Expand Up @@ -50,7 +50,8 @@ bool glass::DisplayPCMSolenoids(PCMModel* model, int index,
wpi::format_to_n_c_str(label, sizeof(label), "{} [{}]###header", name,
index);
} else {
wpi::format_to_n_c_str(label, sizeof(label), "PCM[{}]###header", index);
wpi::format_to_n_c_str(label, sizeof(label), "{}[{}]###header",
model->GetName(), index);
}

// header
Expand Down Expand Up @@ -85,32 +86,29 @@ bool glass::DisplayPCMSolenoids(PCMModel* model, int index,
return true;
}

void glass::DisplayPCMsSolenoids(PCMsModel* model, bool outputsEnabled,
std::string_view noneMsg) {
void glass::DisplayPneumaticControlsSolenoids(PneumaticControlsModel* model,
bool outputsEnabled,
std::string_view noneMsg) {
bool hasAny = false;
model->ForEachPCM([&](PCMModel& pcm, int i) {
PushID(i);
if (DisplayPCMSolenoids(&pcm, i, outputsEnabled)) {
hasAny = true;
}
PopID();
});
model->ForEachPneumaticControl(
[&](PneumaticControlModel& pneumaticControl, int i) {
PushID(i);
if (DisplayPneumaticControlSolenoids(&pneumaticControl, i,
outputsEnabled)) {
hasAny = true;
}
PopID();
});
if (!hasAny && !noneMsg.empty()) {
ImGui::TextUnformatted(noneMsg.data(), noneMsg.data() + noneMsg.size());
}
}

void glass::DisplayCompressorDevice(PCMModel* model, int index,
void glass::DisplayCompressorDevice(CompressorModel* model, int index,
bool outputsEnabled) {
auto compressor = model->GetCompressor();
if (!compressor || !compressor->Exists()) {
if (!model || !model->Exists()) {
return;
}
DisplayCompressorDevice(compressor, index, outputsEnabled);
}

void glass::DisplayCompressorDevice(CompressorModel* model, int index,
bool outputsEnabled) {
char name[32];
wpi::format_to_n_c_str(name, sizeof(name), "Compressor[{}]", index);

Expand Down Expand Up @@ -155,8 +153,11 @@ void glass::DisplayCompressorDevice(CompressorModel* model, int index,
}
}

void glass::DisplayCompressorsDevice(PCMsModel* model, bool outputsEnabled) {
model->ForEachPCM([&](PCMModel& pcm, int i) {
DisplayCompressorDevice(&pcm, i, outputsEnabled);
});
void glass::DisplayCompressorsDevice(PneumaticControlsModel* model,
bool outputsEnabled) {
model->ForEachPneumaticControl(
[&](PneumaticControlModel& pneumaticControl, int i) {
DisplayCompressorDevice(pneumaticControl.GetCompressor(), i,
outputsEnabled);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

#pragma once

#include <memory>
#include <string_view>
#include <utility>

#include <wpi/function_ref.h>

Expand Down Expand Up @@ -34,27 +36,45 @@ class SolenoidModel : public Model {
virtual void SetOutput(bool val) = 0;
};

class PCMModel : public Model {
class PneumaticControlModel : public Model {
public:
virtual CompressorModel* GetCompressor() = 0;

virtual void ForEachSolenoid(
wpi::function_ref<void(SolenoidModel& model, int index)> func) = 0;

virtual std::string_view GetName() = 0;
};

class PCMsModel : public Model {
class PneumaticControlsModel : public Model {
public:
virtual void ForEachPCM(
wpi::function_ref<void(PCMModel& model, int index)> func) = 0;
virtual void ForEachPneumaticControl(
wpi::function_ref<void(PneumaticControlModel& model, int index)>
func) = 0;
};

struct AllPneumaticControlsModel : public Model {
AllPneumaticControlsModel(std::unique_ptr<PneumaticControlsModel> pcms,
std::unique_ptr<PneumaticControlsModel> phs)
: pcms{std::move(pcms)}, phs{std::move(phs)} {};
std::unique_ptr<PneumaticControlsModel> pcms;
std::unique_ptr<PneumaticControlsModel> phs;
void Update() override {
pcms->Update();
phs->Update();
};
bool Exists() override { return true; }
};

bool DisplayPCMSolenoids(PCMModel* model, int index, bool outputsEnabled);
void DisplayPCMsSolenoids(PCMsModel* model, bool outputsEnabled,
std::string_view noneMsg = "No solenoids");
bool DisplayPneumaticControlSolenoids(PneumaticControlModel* model, int index,
bool outputsEnabled);
void DisplayPneumaticControlsSolenoids(
PneumaticControlsModel* model, bool outputsEnabled,
std::string_view noneMsg = "No solenoids");

void DisplayCompressorDevice(PCMModel* model, int index, bool outputsEnabled);
void DisplayCompressorDevice(CompressorModel* model, int index,
bool outputsEnabled);
void DisplayCompressorsDevice(PCMsModel* model, bool outputsEnabled);
void DisplayCompressorsDevice(PneumaticControlsModel* model,
bool outputsEnabled);

} // namespace glass
24 changes: 7 additions & 17 deletions hal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,18 @@ endif()

if(WITH_JAVA_SOURCE)
include(UseJava)
file(GLOB HAL_SOURCES src/main/java/edu/wpi/first/hal/*.java src/generated/main/java/*.java)
file(GLOB HAL_CAN_SOURCES src/main/java/edu/wpi/first/hal/can/*.java)
file(GLOB HAL_SIMULATION_SOURCES src/main/java/edu/wpi/first/hal/simulation/*.java)
file(GLOB HAL_UTIL_SOURCES src/main/java/edu/wpi/first/hal/util/*.java)
add_jar(
include(CreateSourceJar)
add_source_jar(
hal_src_jar
RESOURCES
NAMESPACE "edu/wpi/first/hal" ${HAL_SOURCES}
NAMESPACE "edu/wpi/first/hal/can" ${HAL_CAN_SOURCES}
NAMESPACE
"edu/wpi/first/hal/communication"
src/main/java/edu/wpi/first/hal/communication/NIRioStatus.java
NAMESPACE "edu/wpi/first/hal/simulation" ${HAL_SIMULATION_SOURCES}
NAMESPACE "edu/wpi/first/hal/util" ${HAL_UTIL_SOURCES}
BASE_DIRECTORIES
${CMAKE_CURRENT_SOURCE_DIR}/src/main/java
${CMAKE_CURRENT_SOURCE_DIR}/src/generated/main/java
OUTPUT_NAME wpiHal-sources
OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest}
)

get_property(HAL_SRC_JAR_FILE TARGET hal_src_jar PROPERTY JAR_FILE)
install(FILES ${HAL_SRC_JAR_FILE} DESTINATION "${java_lib_dest}")

set_property(TARGET hal_src_jar PROPERTY FOLDER "java")

install_jar(hal_src_jar DESTINATION ${java_lib_dest})
endif()

if(WITH_TESTS)
Expand Down
19 changes: 7 additions & 12 deletions ntcore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,18 @@ endif()

if(WITH_JAVA_SOURCE)
include(UseJava)
file(
GLOB NTCORE_SOURCES
src/main/java/edu/wpi/first/networktables/*.java
src/generated/main/java/*.java
)
add_jar(
include(CreateSourceJar)
add_source_jar(
ntcore_src_jar
RESOURCES
NAMESPACE "edu/wpi/first/networktables" ${NTCORE_SOURCES}
BASE_DIRECTORIES
${CMAKE_CURRENT_SOURCE_DIR}/src/main/java
${CMAKE_CURRENT_SOURCE_DIR}/src/generated/main/java
OUTPUT_NAME ntcore-sources
OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest}
)

get_property(NTCORE_SRC_JAR_FILE TARGET ntcore_src_jar PROPERTY JAR_FILE)
install(FILES ${NTCORE_SRC_JAR_FILE} DESTINATION "${java_lib_dest}")

set_property(TARGET ntcore_src_jar PROPERTY FOLDER "java")

install_jar(ntcore_src_jar DESTINATION ${java_lib_dest})
endif()

add_executable(ntcoredev src/dev/native/cpp/main.cpp)
Expand Down
13 changes: 5 additions & 8 deletions romiVendordep/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,16 @@ endif()

if(WITH_JAVA_SOURCE)
include(UseJava)
file(GLOB_RECURSE ROMIVENDORDEP_SOURCES src/main/java/*.java)
add_jar(
include(CreateSourceJar)
add_source_jar(
romiVendordep_src_jar
RESOURCES
NAMESPACE "edu/wpi/first/wpilibj/romi" ${ROMIVENDORDEP_SOURCES}
BASE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/src/main/java
OUTPUT_NAME romiVendordep-sources
OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest}
)

get_property(ROMIVENDORDEP_SRC_JAR_FILE TARGET romiVendordep_src_jar PROPERTY JAR_FILE)
install(FILES ${ROMIVENDORDEP_JAR_FILE} DESTINATION "${java_lib_dest}")

set_property(TARGET romiVendordep_src_jar PROPERTY FOLDER "java")

install_jar(romiVendordep_src_jar DESTINATION ${java_lib_dest})
endif()

file(GLOB_RECURSE romiVendordep_native_src src/main/native/cpp/*.cpp)
Expand Down
Loading

0 comments on commit 4e15117

Please sign in to comment.