mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-04 03:11:43 +00:00
[hal,wpilib] Add support for joystick outputs (#8385)
Support joystick outputs, including Rumble and LEDs. Also requires an update to Joystick descriptors, as that has also changed in mrccomm to support showing what outputs are supported.
This commit is contained in:
@@ -171,14 +171,28 @@ Java_org_wpilib_hardware_hal_DriverStationJNI_getAllJoystickData
|
||||
|
||||
/*
|
||||
* Class: org_wpilib_hardware_hal_DriverStationJNI
|
||||
* Method: setJoystickOutputs
|
||||
* Signature: (BIII)I
|
||||
* Method: setJoystickRumble
|
||||
* Signature: (BIIII)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_wpilib_hardware_hal_DriverStationJNI_setJoystickOutputs
|
||||
(JNIEnv*, jclass, jbyte port, jint outputs, jint leftRumble, jint rightRumble)
|
||||
Java_org_wpilib_hardware_hal_DriverStationJNI_setJoystickRumble
|
||||
(JNIEnv*, jclass, jbyte port, jint leftRumble, jint rightRumble,
|
||||
jint leftTriggerRumble, jint rightTriggerRumble)
|
||||
{
|
||||
return HAL_SetJoystickOutputs(port, outputs, leftRumble, rightRumble);
|
||||
return HAL_SetJoystickRumble(port, leftRumble, rightRumble, leftTriggerRumble,
|
||||
rightTriggerRumble);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_wpilib_hardware_hal_DriverStationJNI
|
||||
* Method: setJoystickLeds
|
||||
* Signature: (BI)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_wpilib_hardware_hal_DriverStationJNI_setJoystickLeds
|
||||
(JNIEnv*, jclass, jbyte port, jint leds)
|
||||
{
|
||||
return HAL_SetJoystickLeds(port, leds);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -195,14 +209,26 @@ Java_org_wpilib_hardware_hal_DriverStationJNI_getJoystickIsGamepad
|
||||
|
||||
/*
|
||||
* Class: org_wpilib_hardware_hal_DriverStationJNI
|
||||
* Method: getJoystickType
|
||||
* Method: getJoystickSupportedOutputs
|
||||
* Signature: (B)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_wpilib_hardware_hal_DriverStationJNI_getJoystickType
|
||||
Java_org_wpilib_hardware_hal_DriverStationJNI_getJoystickSupportedOutputs
|
||||
(JNIEnv*, jclass, jbyte port)
|
||||
{
|
||||
return HAL_GetJoystickType(port);
|
||||
return HAL_GetJoystickSupportedOutputs(port);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_wpilib_hardware_hal_DriverStationJNI
|
||||
* Method: getJoystickGamepadType
|
||||
* Signature: (B)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_wpilib_hardware_hal_DriverStationJNI_getJoystickGamepadType
|
||||
(JNIEnv*, jclass, jbyte port)
|
||||
{
|
||||
return HAL_GetJoystickGamepadType(port);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -493,18 +493,16 @@ Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setJoystickButtons
|
||||
|
||||
/*
|
||||
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
|
||||
* Method: getJoystickOutputs
|
||||
* Signature: (I)J
|
||||
* Method: getJoystickLeds
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_getJoystickOutputs
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_getJoystickLeds
|
||||
(JNIEnv* env, jclass, jint stick)
|
||||
{
|
||||
int64_t outputs = 0;
|
||||
int32_t leftRumble;
|
||||
int32_t rightRumble;
|
||||
HALSIM_GetJoystickOutputs(stick, &outputs, &leftRumble, &rightRumble);
|
||||
return outputs;
|
||||
int32_t leds = 0;
|
||||
HALSIM_GetJoystickLeds(stick, &leds);
|
||||
return leds;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -516,11 +514,24 @@ JNIEXPORT jint JNICALL
|
||||
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_getJoystickRumble
|
||||
(JNIEnv* env, jclass, jint stick, jint rumbleNum)
|
||||
{
|
||||
int64_t outputs;
|
||||
int32_t leftRumble = 0;
|
||||
int32_t rightRumble = 0;
|
||||
HALSIM_GetJoystickOutputs(stick, &outputs, &leftRumble, &rightRumble);
|
||||
return rumbleNum == 0 ? leftRumble : rightRumble;
|
||||
int32_t leftTriggerRumble = 0;
|
||||
int32_t rightTriggerRumble = 0;
|
||||
HALSIM_GetJoystickRumbles(stick, &leftRumble, &rightRumble,
|
||||
&leftTriggerRumble, &rightTriggerRumble);
|
||||
switch (rumbleNum) {
|
||||
case 0:
|
||||
return leftRumble;
|
||||
case 1:
|
||||
return rightRumble;
|
||||
case 2:
|
||||
return leftTriggerRumble;
|
||||
case 3:
|
||||
return rightTriggerRumble;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -713,14 +724,26 @@ Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setJoystickIsGamepa
|
||||
|
||||
/*
|
||||
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
|
||||
* Method: setJoystickType
|
||||
* Method: setJoystickGamepadType
|
||||
* Signature: (II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setJoystickType
|
||||
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setJoystickGamepadType
|
||||
(JNIEnv*, jclass, jint stick, jint type)
|
||||
{
|
||||
HALSIM_SetJoystickType(stick, type);
|
||||
HALSIM_SetJoystickGamepadType(stick, type);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_wpilib_hardware_hal_simulation_DriverStationDataJNI
|
||||
* Method: setJoystickSupportedOutputs
|
||||
* Signature: (II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_wpilib_hardware_hal_simulation_DriverStationDataJNI_setJoystickSupportedOutputs
|
||||
(JNIEnv*, jclass, jint stick, jint supportedOutputs)
|
||||
{
|
||||
HALSIM_SetJoystickSupportedOutputs(stick, supportedOutputs);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// 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 <utility>
|
||||
|
||||
#include "wpi/hal/proto/ControlData.h"
|
||||
#include "wpi/util/protobuf/ProtobufCallbacks.hpp"
|
||||
|
||||
@@ -85,7 +87,7 @@ std::optional<mrc::ControlData> wpi::util::Protobuf<mrc::ControlData>::Unpack(
|
||||
ControlData.SetJoystickCount(Joysticks.size());
|
||||
|
||||
for (size_t i = 0; i < ControlData.GetJoystickCount(); i++) {
|
||||
ControlData.Joysticks()[i] = Joysticks[i];
|
||||
ControlData.Joysticks()[i] = std::move(Joysticks[i]);
|
||||
}
|
||||
|
||||
return ControlData;
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "wpi/hal/proto/JoystickDescriptor.h"
|
||||
#include "wpi/util/protobuf/ProtobufCallbacks.hpp"
|
||||
|
||||
std::optional<mrc::JoystickDescriptor>
|
||||
wpi::util::Protobuf<mrc::JoystickDescriptor>::Unpack(InputStream& Stream) {
|
||||
wpi::util::UnpackCallback<std::string> JoystickNameCb;
|
||||
wpi::util::UnpackCallback<uint8_t, MRC_MAX_NUM_AXES> AxisTypesCb;
|
||||
|
||||
mrc_proto_ProtobufJoystickDescriptor Msg;
|
||||
Msg.JoystickName = JoystickNameCb.Callback();
|
||||
Msg.AxisTypes = AxisTypesCb.Callback();
|
||||
|
||||
if (!Stream.Decode(Msg)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto JoystickName = JoystickNameCb.Items();
|
||||
auto AxisTypes = AxisTypesCb.Items();
|
||||
|
||||
if (JoystickName.empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
mrc::JoystickDescriptor OutputData;
|
||||
OutputData.MoveName(std::move(JoystickName[0]));
|
||||
|
||||
OutputData.SetAxesCount(AxisTypes.size());
|
||||
|
||||
for (size_t i = 0; i < OutputData.GetAxesCount(); i++) {
|
||||
OutputData.AxesTypes()[i] = AxisTypes[i];
|
||||
}
|
||||
|
||||
OutputData.SetPovsCount(Msg.PovCount);
|
||||
OutputData.SetButtonsCount(Msg.ButtonCount);
|
||||
|
||||
OutputData.IsGamepad = Msg.IsGamepad ? 1 : 0;
|
||||
OutputData.Type = Msg.JoystickType;
|
||||
OutputData.RumbleCount = Msg.RumbleCount;
|
||||
|
||||
return OutputData;
|
||||
}
|
||||
|
||||
bool wpi::util::Protobuf<mrc::JoystickDescriptor>::Pack(
|
||||
OutputStream& Stream, const mrc::JoystickDescriptor& Value) {
|
||||
std::string_view JoystickName = Value.GetName();
|
||||
wpi::util::PackCallback JoystickNameCb{&JoystickName};
|
||||
|
||||
std::span<const uint8_t> AxisTypes = Value.AxesTypes();
|
||||
wpi::util::PackCallback AxisTypesCb{AxisTypes};
|
||||
|
||||
mrc_proto_ProtobufJoystickDescriptor Msg{
|
||||
.JoystickName = JoystickNameCb.Callback(),
|
||||
.AxisTypes = AxisTypesCb.Callback(),
|
||||
.IsGamepad = Value.IsGamepad ? true : false,
|
||||
.JoystickType = Value.Type,
|
||||
.ButtonCount = static_cast<int32_t>(Value.GetButtonsCount()),
|
||||
.PovCount = static_cast<int32_t>(Value.GetPovsCount()),
|
||||
.RumbleCount = Value.RumbleCount,
|
||||
};
|
||||
|
||||
return Stream.Encode(Msg);
|
||||
}
|
||||
84
hal/src/main/native/cpp/proto/JoystickDescriptorsProto.cpp
Normal file
84
hal/src/main/native/cpp/proto/JoystickDescriptorsProto.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "wpi/hal/proto/JoystickDescriptors.h"
|
||||
#include "wpi/util/protobuf/ProtobufCallbacks.hpp"
|
||||
|
||||
std::optional<mrc::JoystickDescriptors>
|
||||
wpi::util::Protobuf<mrc::JoystickDescriptors>::Unpack(InputStream& Stream) {
|
||||
wpi::util::UnpackCallback<mrc::JoystickDescriptor, MRC_MAX_NUM_JOYSTICKS>
|
||||
JoystickDescriptorsCb;
|
||||
|
||||
mrc_proto_ProtobufJoystickDescriptors Msg;
|
||||
Msg.Descriptors = JoystickDescriptorsCb.Callback();
|
||||
|
||||
if (!Stream.Decode(Msg)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto Descriptors = JoystickDescriptorsCb.Items();
|
||||
|
||||
mrc::JoystickDescriptors OutputData;
|
||||
OutputData.SetDescriptorCount(Descriptors.size());
|
||||
for (size_t i = 0; i < OutputData.GetDescriptorCount(); i++) {
|
||||
OutputData.Descriptors()[i] = std::move(Descriptors[i]);
|
||||
}
|
||||
|
||||
return OutputData;
|
||||
}
|
||||
|
||||
bool wpi::util::Protobuf<mrc::JoystickDescriptors>::Pack(
|
||||
OutputStream& Stream, const mrc::JoystickDescriptors& Value) {
|
||||
std::span<const mrc::JoystickDescriptor> Descriptors = Value.Descriptors();
|
||||
wpi::util::PackCallback JoystickDescriptorsCb{Descriptors};
|
||||
|
||||
mrc_proto_ProtobufJoystickDescriptors Msg{
|
||||
.Descriptors = JoystickDescriptorsCb.Callback(),
|
||||
};
|
||||
|
||||
return Stream.Encode(Msg);
|
||||
}
|
||||
|
||||
std::optional<mrc::JoystickDescriptor>
|
||||
wpi::util::Protobuf<mrc::JoystickDescriptor>::Unpack(InputStream& Stream) {
|
||||
wpi::util::UnpackCallback<std::string> JoystickNameCb;
|
||||
|
||||
mrc_proto_ProtobufJoystickDescriptor Msg;
|
||||
Msg.JoystickName = JoystickNameCb.Callback();
|
||||
|
||||
if (!Stream.Decode(Msg)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto JoystickName = JoystickNameCb.Items();
|
||||
|
||||
mrc::JoystickDescriptor OutputData;
|
||||
if (!JoystickName.empty()) {
|
||||
OutputData.MoveName(std::move(JoystickName[0]));
|
||||
}
|
||||
|
||||
OutputData.IsGamepad = Msg.IsGamepad ? 1 : 0;
|
||||
OutputData.GamepadType = Msg.GamepadType;
|
||||
OutputData.SupportedOutputs = Msg.SupportedOutputs;
|
||||
|
||||
return OutputData;
|
||||
}
|
||||
|
||||
bool wpi::util::Protobuf<mrc::JoystickDescriptor>::Pack(
|
||||
OutputStream& Stream, const mrc::JoystickDescriptor& Value) {
|
||||
std::string_view JoystickName = Value.GetName();
|
||||
wpi::util::PackCallback JoystickNameCb{&JoystickName};
|
||||
|
||||
mrc_proto_ProtobufJoystickDescriptor Msg{
|
||||
.JoystickName = JoystickNameCb.Callback(),
|
||||
.IsGamepad = Value.IsGamepad ? true : false,
|
||||
.GamepadType = Value.GamepadType,
|
||||
.SupportedOutputs = Value.SupportedOutputs,
|
||||
};
|
||||
|
||||
return Stream.Encode(Msg);
|
||||
}
|
||||
79
hal/src/main/native/cpp/proto/JoystickOutputDataProto.cpp
Normal file
79
hal/src/main/native/cpp/proto/JoystickOutputDataProto.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "wpi/hal/proto/JoystickOutput.h"
|
||||
#include "wpi/util/protobuf/ProtobufCallbacks.hpp"
|
||||
|
||||
std::optional<mrc::JoystickOutputs>
|
||||
wpi::util::Protobuf<mrc::JoystickOutputs>::Unpack(InputStream& Stream) {
|
||||
wpi::util::UnpackCallback<mrc::JoystickOutput, MRC_MAX_NUM_JOYSTICKS>
|
||||
JoystickOutputsCb;
|
||||
|
||||
mrc_proto_ProtobufJoystickOutputs Msg;
|
||||
Msg.Outputs = JoystickOutputsCb.Callback();
|
||||
|
||||
if (!Stream.Decode(Msg)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto Outputs = JoystickOutputsCb.Items();
|
||||
|
||||
mrc::JoystickOutputs OutputData;
|
||||
OutputData.SetOutputCount(Outputs.size());
|
||||
for (size_t i = 0; i < OutputData.GetOutputCount(); i++) {
|
||||
OutputData.Outputs()[i] = std::move(Outputs[i]);
|
||||
}
|
||||
|
||||
return OutputData;
|
||||
}
|
||||
|
||||
bool wpi::util::Protobuf<mrc::JoystickOutputs>::Pack(
|
||||
OutputStream& Stream, const mrc::JoystickOutputs& Value) {
|
||||
std::span<const mrc::JoystickOutput> Outputs = Value.Outputs();
|
||||
wpi::util::PackCallback JoystickOutputsCb{Outputs};
|
||||
|
||||
mrc_proto_ProtobufJoystickOutputs Msg{
|
||||
.Outputs = JoystickOutputsCb.Callback(),
|
||||
};
|
||||
|
||||
return Stream.Encode(Msg);
|
||||
}
|
||||
|
||||
std::optional<mrc::JoystickOutput>
|
||||
wpi::util::Protobuf<mrc::JoystickOutput>::Unpack(InputStream& Stream) {
|
||||
mrc_proto_ProtobufJoystickOutput Msg;
|
||||
|
||||
if (!Stream.Decode(Msg)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return mrc::JoystickOutput{
|
||||
.R = static_cast<uint8_t>((Msg.LEDs >> 16) & 0xFF),
|
||||
.G = static_cast<uint8_t>((Msg.LEDs >> 8) & 0xFF),
|
||||
.B = static_cast<uint8_t>(Msg.LEDs & 0xFF),
|
||||
.LeftRumble = static_cast<uint16_t>((Msg.Rumble >> 16) & 0xFFFF),
|
||||
.RightRumble = static_cast<uint16_t>(Msg.Rumble & 0xFFFF),
|
||||
.LeftTriggerRumble =
|
||||
static_cast<uint16_t>((Msg.TriggerRumble >> 16) & 0xFFFF),
|
||||
.RightTriggerRumble = static_cast<uint16_t>(Msg.TriggerRumble & 0xFFFF),
|
||||
};
|
||||
}
|
||||
|
||||
bool wpi::util::Protobuf<mrc::JoystickOutput>::Pack(
|
||||
OutputStream& Stream, const mrc::JoystickOutput& Value) {
|
||||
mrc_proto_ProtobufJoystickOutput Msg{
|
||||
.LEDs = (static_cast<uint32_t>(Value.R) << 16) |
|
||||
(static_cast<uint32_t>(Value.G) << 8) |
|
||||
static_cast<uint32_t>(Value.B),
|
||||
.Rumble = (static_cast<uint32_t>(Value.LeftRumble) << 16) |
|
||||
static_cast<uint32_t>(Value.RightRumble),
|
||||
.TriggerRumble = (static_cast<uint32_t>(Value.LeftTriggerRumble) << 16) |
|
||||
static_cast<uint32_t>(Value.RightTriggerRumble),
|
||||
};
|
||||
|
||||
return Stream.Encode(Msg);
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "wpi/hal/proto/JoystickRumbleData.h"
|
||||
#include "wpi/util/protobuf/ProtobufCallbacks.hpp"
|
||||
|
||||
std::optional<mrc::JoystickRumbleData>
|
||||
wpi::util::Protobuf<mrc::JoystickRumbleData>::Unpack(InputStream& Stream) {
|
||||
wpi::util::UnpackCallback<uint16_t, MRC_MAX_NUM_RUMBLE> RumbleCb;
|
||||
|
||||
mrc_proto_ProtobufJoystickRumbleData Msg{
|
||||
.Value = RumbleCb.Callback(),
|
||||
};
|
||||
|
||||
if (!Stream.Decode(Msg)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto Rumbles = RumbleCb.Items();
|
||||
|
||||
mrc::JoystickRumbleData Rumble;
|
||||
Rumble.SetCount(Rumbles.size());
|
||||
|
||||
for (size_t i = 0; i < Rumble.GetCount(); i++) {
|
||||
Rumble.Rumbles()[i] = Rumbles[i];
|
||||
}
|
||||
|
||||
return Rumble;
|
||||
}
|
||||
|
||||
bool wpi::util::Protobuf<mrc::JoystickRumbleData>::Pack(
|
||||
OutputStream& Stream, const mrc::JoystickRumbleData& Value) {
|
||||
wpi::util::PackCallback RumbleCb{Value.Rumbles()};
|
||||
|
||||
mrc_proto_ProtobufJoystickRumbleData Msg{
|
||||
.Value = RumbleCb.Callback(),
|
||||
};
|
||||
|
||||
return Stream.Encode(Msg);
|
||||
}
|
||||
@@ -131,13 +131,20 @@ HAL_Bool HAL_GetJoystickIsGamepad(int32_t joystickNum);
|
||||
/**
|
||||
* Gets the type of joystick connected.
|
||||
*
|
||||
* This is device specific, and different depending on what system input type
|
||||
* the joystick uses.
|
||||
* This maps to SDL_GamepadType
|
||||
*
|
||||
* @param joystickNum the joystick number
|
||||
* @return the enumerated joystick type
|
||||
* @return the enumerated gamepad type
|
||||
*/
|
||||
int32_t HAL_GetJoystickType(int32_t joystickNum);
|
||||
int32_t HAL_GetJoystickGamepadType(int32_t joystickNum);
|
||||
|
||||
/**
|
||||
* Gets the supported outputs of a specific joystick.
|
||||
*
|
||||
* @param joystickNum the joystick number
|
||||
* @return bitmask of supported outputs
|
||||
*/
|
||||
int32_t HAL_GetJoystickSupportedOutputs(int32_t joystickNum);
|
||||
|
||||
/**
|
||||
* Gets the name of a joystick.
|
||||
@@ -150,16 +157,26 @@ int32_t HAL_GetJoystickType(int32_t joystickNum);
|
||||
void HAL_GetJoystickName(struct WPI_String* name, int32_t joystickNum);
|
||||
|
||||
/**
|
||||
* Set joystick outputs.
|
||||
* Set joystick rumbles.
|
||||
*
|
||||
* @param joystickNum the joystick number
|
||||
* @param outputs bitmask of outputs, 1 for on 0 for off
|
||||
* @param leftRumble the left rumble value (0-FFFF)
|
||||
* @param rightRumble the right rumble value (0-FFFF)
|
||||
* @param leftTriggerRumble the left trigger rumble value (0-FFFF)
|
||||
* @param rightTriggerRumble the right trigger rumble value (0-FFFF)
|
||||
* @return the error code, or 0 for success
|
||||
*/
|
||||
int32_t HAL_SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
|
||||
int32_t leftRumble, int32_t rightRumble);
|
||||
int32_t HAL_SetJoystickRumble(int32_t joystickNum, int32_t leftRumble,
|
||||
int32_t rightRumble, int32_t leftTriggerRumble,
|
||||
int32_t rightTriggerRumble);
|
||||
|
||||
/**
|
||||
* Set joystick LEDs.
|
||||
* @param joystickNum the joystick number
|
||||
* @param leds the rgb led color value (0xRRGGBB)
|
||||
* @return the error code, or 0 for success
|
||||
*/
|
||||
int32_t HAL_SetJoystickLeds(int32_t joystickNum, int32_t leds);
|
||||
|
||||
/**
|
||||
* Return the approximate match time. The FMS does not send an official match
|
||||
|
||||
@@ -109,7 +109,8 @@ typedef struct HAL_JoystickButtons HAL_JoystickButtons;
|
||||
|
||||
struct HAL_JoystickDescriptor {
|
||||
uint8_t isGamepad;
|
||||
uint8_t type;
|
||||
uint8_t gamepadType;
|
||||
uint8_t supportedOutputs;
|
||||
char name[256];
|
||||
};
|
||||
typedef struct HAL_JoystickDescriptor HAL_JoystickDescriptor;
|
||||
|
||||
@@ -10,6 +10,15 @@
|
||||
#include "mrc/NetComm.h"
|
||||
#include "wpi/util/protobuf/Protobuf.hpp"
|
||||
|
||||
template <>
|
||||
struct wpi::util::Protobuf<mrc::JoystickDescriptors> {
|
||||
using MessageStruct = mrc_proto_ProtobufJoystickDescriptors;
|
||||
using InputStream = wpi::util::ProtoInputStream<mrc::JoystickDescriptors>;
|
||||
using OutputStream = wpi::util::ProtoOutputStream<mrc::JoystickDescriptors>;
|
||||
static std::optional<mrc::JoystickDescriptors> Unpack(InputStream& Stream);
|
||||
static bool Pack(OutputStream& Stream, const mrc::JoystickDescriptors& Value);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct wpi::util::Protobuf<mrc::JoystickDescriptor> {
|
||||
using MessageStruct = mrc_proto_ProtobufJoystickDescriptor;
|
||||
29
hal/src/main/native/include/wpi/hal/proto/JoystickOutput.h
Normal file
29
hal/src/main/native/include/wpi/hal/proto/JoystickOutput.h
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "MrcComm.npb.h"
|
||||
#include "mrc/NetComm.h"
|
||||
#include "wpi/util/protobuf/Protobuf.hpp"
|
||||
|
||||
template <>
|
||||
struct wpi::util::Protobuf<mrc::JoystickOutput> {
|
||||
using MessageStruct = mrc_proto_ProtobufJoystickOutput;
|
||||
using InputStream = wpi::util::ProtoInputStream<mrc::JoystickOutput>;
|
||||
using OutputStream = wpi::util::ProtoOutputStream<mrc::JoystickOutput>;
|
||||
static std::optional<mrc::JoystickOutput> Unpack(InputStream& Stream);
|
||||
static bool Pack(OutputStream& Stream, const mrc::JoystickOutput& Value);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct wpi::util::Protobuf<mrc::JoystickOutputs> {
|
||||
using MessageStruct = mrc_proto_ProtobufJoystickOutputs;
|
||||
using InputStream = wpi::util::ProtoInputStream<mrc::JoystickOutputs>;
|
||||
using OutputStream = wpi::util::ProtoOutputStream<mrc::JoystickOutputs>;
|
||||
static std::optional<mrc::JoystickOutputs> Unpack(InputStream& Stream);
|
||||
static bool Pack(OutputStream& Stream, const mrc::JoystickOutputs& Value);
|
||||
};
|
||||
@@ -1,20 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "MrcComm.npb.h"
|
||||
#include "mrc/NetComm.h"
|
||||
#include "wpi/util/protobuf/Protobuf.hpp"
|
||||
|
||||
template <>
|
||||
struct wpi::util::Protobuf<mrc::JoystickRumbleData> {
|
||||
using MessageStruct = mrc_proto_ProtobufJoystickRumbleData;
|
||||
using InputStream = wpi::util::ProtoInputStream<mrc::JoystickRumbleData>;
|
||||
using OutputStream = wpi::util::ProtoOutputStream<mrc::JoystickRumbleData>;
|
||||
static std::optional<mrc::JoystickRumbleData> Unpack(InputStream& Stream);
|
||||
static bool Pack(OutputStream& Stream, const mrc::JoystickRumbleData& Value);
|
||||
};
|
||||
@@ -1,20 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "MrcComm.npb.h"
|
||||
#include "mrc/NetComm.h"
|
||||
#include "wpi/util/protobuf/Protobuf.hpp"
|
||||
|
||||
template <>
|
||||
struct wpi::util::Protobuf<mrc::VersionInfo> {
|
||||
using MessageStruct = mrc_proto_ProtobufVersionInfo;
|
||||
using InputStream = wpi::util::ProtoInputStream<mrc::VersionInfo>;
|
||||
using OutputStream = wpi::util::ProtoOutputStream<mrc::VersionInfo>;
|
||||
static std::optional<mrc::VersionInfo> Unpack(InputStream& Stream);
|
||||
static bool Pack(OutputStream& Stream, const mrc::VersionInfo& Value);
|
||||
};
|
||||
@@ -23,10 +23,11 @@ typedef void (*HAL_JoystickButtonsCallback)(const char* name, void* param,
|
||||
typedef void (*HAL_JoystickDescriptorCallback)(
|
||||
const char* name, void* param, int32_t joystickNum,
|
||||
const HAL_JoystickDescriptor* descriptor);
|
||||
typedef void (*HAL_JoystickOutputsCallback)(const char* name, void* param,
|
||||
int32_t joystickNum,
|
||||
int64_t outputs, int32_t leftRumble,
|
||||
int32_t rightRumble);
|
||||
typedef void (*HAL_JoystickLedsCallback)(const char* name, void* param,
|
||||
int32_t joystickNum, int32_t leds);
|
||||
typedef void (*HAL_JoystickRumblesCallback)(
|
||||
const char* name, void* param, int32_t joystickNum, int32_t leftRumble,
|
||||
int32_t rightRumble, int32_t leftTriggerRumble, int32_t rightTriggerRumble);
|
||||
typedef void (*HAL_MatchInfoCallback)(const char* name, void* param,
|
||||
const HAL_MatchInfo* info);
|
||||
|
||||
@@ -121,14 +122,24 @@ void HALSIM_GetJoystickDescriptor(int32_t joystickNum,
|
||||
void HALSIM_SetJoystickDescriptor(int32_t joystickNum,
|
||||
const HAL_JoystickDescriptor* descriptor);
|
||||
|
||||
int32_t HALSIM_RegisterJoystickOutputsCallback(
|
||||
int32_t joystickNum, HAL_JoystickOutputsCallback callback, void* param,
|
||||
int32_t HALSIM_RegisterJoystickLedsCallback(int32_t joystickNum,
|
||||
HAL_JoystickLedsCallback callback,
|
||||
void* param,
|
||||
HAL_Bool initialNotify);
|
||||
void HALSIM_CancelJoystickLedsCallback(int32_t uid);
|
||||
void HALSIM_GetJoystickLeds(int32_t joystickNum, int32_t* leds);
|
||||
void HALSIM_SetJoystickLeds(int32_t joystickNum, int32_t leds);
|
||||
|
||||
int32_t HALSIM_RegisterJoystickRumblesCallback(
|
||||
int32_t joystickNum, HAL_JoystickRumblesCallback callback, void* param,
|
||||
HAL_Bool initialNotify);
|
||||
void HALSIM_CancelJoystickOutputsCallback(int32_t uid);
|
||||
void HALSIM_GetJoystickOutputs(int32_t joystickNum, int64_t* outputs,
|
||||
int32_t* leftRumble, int32_t* rightRumble);
|
||||
void HALSIM_SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
|
||||
int32_t leftRumble, int32_t rightRumble);
|
||||
void HALSIM_CancelJoystickRumblesCallback(int32_t uid);
|
||||
void HALSIM_GetJoystickRumbles(int32_t joystickNum, int32_t* leftRumble,
|
||||
int32_t* rightRumble, int32_t* leftTriggerRumble,
|
||||
int32_t* rightTriggerRumble);
|
||||
void HALSIM_SetJoystickRumbles(int32_t joystickNum, int32_t leftRumble,
|
||||
int32_t rightRumble, int32_t leftTriggerRumble,
|
||||
int32_t rightTriggerRumble);
|
||||
|
||||
int32_t HALSIM_RegisterMatchInfoCallback(HAL_MatchInfoCallback callback,
|
||||
void* param, HAL_Bool initialNotify);
|
||||
@@ -148,8 +159,10 @@ void HALSIM_GetJoystickAvailables(int32_t stick, uint16_t* axesAvailable,
|
||||
uint8_t* povsAvailable);
|
||||
|
||||
void HALSIM_SetJoystickIsGamepad(int32_t stick, HAL_Bool isGamepad);
|
||||
void HALSIM_SetJoystickType(int32_t stick, int32_t type);
|
||||
void HALSIM_SetJoystickGamepadType(int32_t stick, int32_t type);
|
||||
void HALSIM_SetJoystickName(int32_t stick, const struct WPI_String* name);
|
||||
void HALSIM_SetJoystickSupportedOutputs(int32_t stick,
|
||||
int32_t supportedOutputs);
|
||||
|
||||
void HALSIM_SetGameSpecificMessage(const struct WPI_String* message);
|
||||
void HALSIM_SetEventName(const struct WPI_String* name);
|
||||
|
||||
@@ -295,12 +295,21 @@ HAL_Bool HAL_GetJoystickIsGamepad(int32_t joystickNum) {
|
||||
}
|
||||
}
|
||||
|
||||
int32_t HAL_GetJoystickType(int32_t joystickNum) {
|
||||
int32_t HAL_GetJoystickGamepadType(int32_t joystickNum) {
|
||||
HAL_JoystickDescriptor joystickDesc;
|
||||
if (HAL_GetJoystickDescriptor(joystickNum, &joystickDesc) < 0) {
|
||||
return -1;
|
||||
} else {
|
||||
return joystickDesc.type;
|
||||
return joystickDesc.gamepadType;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t HAL_GetJoystickSupportedOutputs(int32_t joystickNum) {
|
||||
HAL_JoystickDescriptor joystickDesc;
|
||||
if (HAL_GetJoystickDescriptor(joystickNum, &joystickDesc) < 0) {
|
||||
return -1;
|
||||
} else {
|
||||
return joystickDesc.supportedOutputs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,10 +324,17 @@ void HAL_GetJoystickName(struct WPI_String* name, int32_t joystickNum) {
|
||||
std::memcpy(write, cName, len);
|
||||
}
|
||||
|
||||
int32_t HAL_SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
|
||||
int32_t leftRumble, int32_t rightRumble) {
|
||||
SimDriverStationData->SetJoystickOutputs(joystickNum, outputs, leftRumble,
|
||||
rightRumble);
|
||||
int32_t HAL_SetJoystickRumble(int32_t joystickNum, int32_t leftRumble,
|
||||
int32_t rightRumble, int32_t leftTriggerRumble,
|
||||
int32_t rightTriggerRumble) {
|
||||
SimDriverStationData->SetJoystickRumbles(joystickNum, leftRumble, rightRumble,
|
||||
leftTriggerRumble,
|
||||
rightTriggerRumble);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t HAL_SetJoystickLeds(int32_t joystickNum, int32_t leds) {
|
||||
SimDriverStationData->SetJoystickLeds(joystickNum, leds);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,14 +36,22 @@ void DriverStationData::ResetData() {
|
||||
m_joystickAxesCallbacks.Reset();
|
||||
m_joystickPOVsCallbacks.Reset();
|
||||
m_joystickButtonsCallbacks.Reset();
|
||||
m_joystickOutputsCallbacks.Reset();
|
||||
m_joystickLedsCallbacks.Reset();
|
||||
m_joystickRumblesCallbacks.Reset();
|
||||
m_joystickDescriptorCallbacks.Reset();
|
||||
for (int i = 0; i < kNumJoysticks; i++) {
|
||||
m_joystickData[i].axes = HAL_JoystickAxes{};
|
||||
m_joystickData[i].povs = HAL_JoystickPOVs{};
|
||||
m_joystickData[i].buttons = HAL_JoystickButtons{};
|
||||
m_joystickData[i].descriptor = HAL_JoystickDescriptor{};
|
||||
m_joystickData[i].descriptor.type = -1;
|
||||
m_joystickData[i].outputs.leds = 0;
|
||||
m_joystickData[i].outputs.leftRumble = 0;
|
||||
m_joystickData[i].outputs.rightRumble = 0;
|
||||
m_joystickData[i].outputs.leftTriggerRumble = 0;
|
||||
m_joystickData[i].outputs.rightTriggerRumble = 0;
|
||||
m_joystickData[i].descriptor.gamepadType = 0;
|
||||
m_joystickData[i].descriptor.isGamepad = 0;
|
||||
m_joystickData[i].descriptor.supportedOutputs = 0;
|
||||
m_joystickData[i].descriptor.name[0] = '\0';
|
||||
}
|
||||
}
|
||||
@@ -121,50 +129,96 @@ void DriverStationData::SetJoystickDescriptor(
|
||||
m_joystickDescriptorCallbacks(joystickNum, descriptor);
|
||||
}
|
||||
|
||||
int32_t DriverStationData::RegisterJoystickOutputsCallback(
|
||||
int32_t joystickNum, HAL_JoystickOutputsCallback callback, void* param,
|
||||
int32_t DriverStationData::RegisterJoystickLedsCallback(
|
||||
int32_t joystickNum, HAL_JoystickLedsCallback callback, void* param,
|
||||
HAL_Bool initialNotify) {
|
||||
if (joystickNum < 0 || joystickNum >= DriverStationData::kNumJoysticks) {
|
||||
return 0;
|
||||
}
|
||||
std::scoped_lock lock(m_joystickDataMutex);
|
||||
int32_t uid = m_joystickOutputsCallbacks.Register(callback, param);
|
||||
int32_t uid = m_joystickLedsCallbacks.Register(callback, param);
|
||||
if (initialNotify) {
|
||||
const auto& outputs = m_joystickData[joystickNum].outputs;
|
||||
callback(DriverStationData::GetJoystickOutputsName(), param, joystickNum,
|
||||
outputs.outputs, outputs.leftRumble, outputs.rightRumble);
|
||||
callback(DriverStationData::GetJoystickLedsName(), param, joystickNum,
|
||||
outputs.leds);
|
||||
}
|
||||
return uid;
|
||||
}
|
||||
|
||||
void DriverStationData::CancelJoystickOutputsCallback(int32_t uid) {
|
||||
m_joystickOutputsCallbacks.Cancel(uid);
|
||||
void DriverStationData::CancelJoystickLedsCallback(int32_t uid) {
|
||||
m_joystickLedsCallbacks.Cancel(uid);
|
||||
}
|
||||
|
||||
void DriverStationData::GetJoystickOutputs(int32_t joystickNum,
|
||||
int64_t* outputs,
|
||||
void DriverStationData::GetJoystickLeds(int32_t joystickNum, int32_t* leds) {
|
||||
if (joystickNum < 0 || joystickNum >= kNumJoysticks) {
|
||||
return;
|
||||
}
|
||||
std::scoped_lock lock(m_joystickDataMutex);
|
||||
*leds = m_joystickData[joystickNum].outputs.leds;
|
||||
}
|
||||
|
||||
void DriverStationData::SetJoystickLeds(int32_t joystickNum, int32_t leds) {
|
||||
if (joystickNum < 0 || joystickNum >= kNumJoysticks) {
|
||||
return;
|
||||
}
|
||||
std::scoped_lock lock(m_joystickDataMutex);
|
||||
m_joystickData[joystickNum].outputs.leds = leds;
|
||||
m_joystickLedsCallbacks(joystickNum, leds);
|
||||
}
|
||||
|
||||
int32_t DriverStationData::RegisterJoystickRumblesCallback(
|
||||
int32_t joystickNum, HAL_JoystickRumblesCallback callback, void* param,
|
||||
HAL_Bool initialNotify) {
|
||||
if (joystickNum < 0 || joystickNum >= DriverStationData::kNumJoysticks) {
|
||||
return 0;
|
||||
}
|
||||
std::scoped_lock lock(m_joystickDataMutex);
|
||||
int32_t uid = m_joystickRumblesCallbacks.Register(callback, param);
|
||||
if (initialNotify) {
|
||||
const auto& outputs = m_joystickData[joystickNum].outputs;
|
||||
callback(DriverStationData::GetJoystickRumblesName(), param, joystickNum,
|
||||
outputs.leftRumble, outputs.rightRumble, outputs.leftTriggerRumble,
|
||||
outputs.rightTriggerRumble);
|
||||
}
|
||||
return uid;
|
||||
}
|
||||
|
||||
void DriverStationData::CancelJoystickRumblesCallback(int32_t uid) {
|
||||
m_joystickRumblesCallbacks.Cancel(uid);
|
||||
}
|
||||
|
||||
void DriverStationData::GetJoystickRumbles(int32_t joystickNum,
|
||||
int32_t* leftRumble,
|
||||
int32_t* rightRumble) {
|
||||
int32_t* rightRumble,
|
||||
int32_t* leftTriggerRumble,
|
||||
int32_t* rightTriggerRumble) {
|
||||
if (joystickNum < 0 || joystickNum >= kNumJoysticks) {
|
||||
return;
|
||||
}
|
||||
std::scoped_lock lock(m_joystickDataMutex);
|
||||
*leftRumble = m_joystickData[joystickNum].outputs.leftRumble;
|
||||
*outputs = m_joystickData[joystickNum].outputs.outputs;
|
||||
*rightRumble = m_joystickData[joystickNum].outputs.rightRumble;
|
||||
const auto& outputs = m_joystickData[joystickNum].outputs;
|
||||
*leftRumble = outputs.leftRumble;
|
||||
*rightRumble = outputs.rightRumble;
|
||||
*leftTriggerRumble = outputs.leftTriggerRumble;
|
||||
*rightTriggerRumble = outputs.rightTriggerRumble;
|
||||
}
|
||||
|
||||
void DriverStationData::SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
|
||||
void DriverStationData::SetJoystickRumbles(int32_t joystickNum,
|
||||
int32_t leftRumble,
|
||||
int32_t rightRumble) {
|
||||
int32_t rightRumble,
|
||||
int32_t leftTriggerRumble,
|
||||
int32_t rightTriggerRumble) {
|
||||
if (joystickNum < 0 || joystickNum >= kNumJoysticks) {
|
||||
return;
|
||||
}
|
||||
std::scoped_lock lock(m_joystickDataMutex);
|
||||
m_joystickData[joystickNum].outputs.leftRumble = leftRumble;
|
||||
m_joystickData[joystickNum].outputs.outputs = outputs;
|
||||
m_joystickData[joystickNum].outputs.rightRumble = rightRumble;
|
||||
m_joystickOutputsCallbacks(joystickNum, outputs, leftRumble, rightRumble);
|
||||
auto& outputs = m_joystickData[joystickNum].outputs;
|
||||
outputs.leftRumble = leftRumble;
|
||||
outputs.rightRumble = rightRumble;
|
||||
outputs.leftTriggerRumble = leftTriggerRumble;
|
||||
outputs.rightTriggerRumble = rightTriggerRumble;
|
||||
m_joystickRumblesCallbacks(joystickNum, leftRumble, rightRumble,
|
||||
leftTriggerRumble, rightTriggerRumble);
|
||||
}
|
||||
|
||||
int32_t DriverStationData::RegisterMatchInfoCallback(
|
||||
@@ -328,12 +382,22 @@ void DriverStationData::SetJoystickIsGamepad(int32_t stick,
|
||||
m_joystickDescriptorCallbacks(stick, &m_joystickData[stick].descriptor);
|
||||
}
|
||||
|
||||
void DriverStationData::SetJoystickType(int32_t stick, int32_t type) {
|
||||
void DriverStationData::SetJoystickGamepadType(int32_t stick, int32_t type) {
|
||||
if (stick < 0 || stick >= kNumJoysticks) {
|
||||
return;
|
||||
}
|
||||
std::scoped_lock lock(m_joystickDataMutex);
|
||||
m_joystickData[stick].descriptor.type = type;
|
||||
m_joystickData[stick].descriptor.gamepadType = type;
|
||||
m_joystickDescriptorCallbacks(stick, &m_joystickData[stick].descriptor);
|
||||
}
|
||||
|
||||
void DriverStationData::SetJoystickSupportedOutputs(int32_t stick,
|
||||
int32_t supportedOutputs) {
|
||||
if (stick < 0 || stick >= kNumJoysticks) {
|
||||
return;
|
||||
}
|
||||
std::scoped_lock lock(m_joystickDataMutex);
|
||||
m_joystickData[stick].descriptor.supportedOutputs = supportedOutputs;
|
||||
m_joystickDescriptorCallbacks(stick, &m_joystickData[stick].descriptor);
|
||||
}
|
||||
|
||||
@@ -428,27 +492,51 @@ DEFINE_CAPI(POVs, povs)
|
||||
DEFINE_CAPI(Buttons, buttons)
|
||||
DEFINE_CAPI(Descriptor, descriptor)
|
||||
|
||||
int32_t HALSIM_RegisterJoystickOutputsCallback(
|
||||
int32_t joystickNum, HAL_JoystickOutputsCallback callback, void* param,
|
||||
HAL_Bool initialNotify) {
|
||||
return SimDriverStationData->RegisterJoystickOutputsCallback(
|
||||
int32_t HALSIM_RegisterJoystickLedsCallback(int32_t joystickNum,
|
||||
HAL_JoystickLedsCallback callback,
|
||||
void* param,
|
||||
HAL_Bool initialNotify) {
|
||||
return SimDriverStationData->RegisterJoystickLedsCallback(
|
||||
joystickNum, callback, param, initialNotify);
|
||||
}
|
||||
|
||||
void HALSIM_CancelJoystickOutputsCallback(int32_t uid) {
|
||||
SimDriverStationData->CancelJoystickOutputsCallback(uid);
|
||||
void HALSIM_CancelJoystickLedsCallback(int32_t uid) {
|
||||
SimDriverStationData->CancelJoystickLedsCallback(uid);
|
||||
}
|
||||
|
||||
void HALSIM_GetJoystickOutputs(int32_t joystickNum, int64_t* outputs,
|
||||
int32_t* leftRumble, int32_t* rightRumble) {
|
||||
SimDriverStationData->GetJoystickOutputs(joystickNum, outputs, leftRumble,
|
||||
rightRumble);
|
||||
void HALSIM_GetJoystickLeds(int32_t joystickNum, int32_t* leds) {
|
||||
SimDriverStationData->GetJoystickLeds(joystickNum, leds);
|
||||
}
|
||||
|
||||
void HALSIM_SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
|
||||
int32_t leftRumble, int32_t rightRumble) {
|
||||
SimDriverStationData->SetJoystickOutputs(joystickNum, outputs, leftRumble,
|
||||
rightRumble);
|
||||
void HALSIM_SetJoystickLeds(int32_t joystickNum, int32_t leds) {
|
||||
SimDriverStationData->SetJoystickLeds(joystickNum, leds);
|
||||
}
|
||||
|
||||
int32_t HALSIM_RegisterJoystickRumblesCallback(
|
||||
int32_t joystickNum, HAL_JoystickRumblesCallback callback, void* param,
|
||||
HAL_Bool initialNotify) {
|
||||
return SimDriverStationData->RegisterJoystickRumblesCallback(
|
||||
joystickNum, callback, param, initialNotify);
|
||||
}
|
||||
|
||||
void HALSIM_CancelJoystickRumblesCallback(int32_t uid) {
|
||||
SimDriverStationData->CancelJoystickRumblesCallback(uid);
|
||||
}
|
||||
|
||||
void HALSIM_GetJoystickRumbles(int32_t joystickNum, int32_t* leftRumble,
|
||||
int32_t* rightRumble, int32_t* leftTriggerRumble,
|
||||
int32_t* rightTriggerRumble) {
|
||||
SimDriverStationData->GetJoystickRumbles(joystickNum, leftRumble, rightRumble,
|
||||
leftTriggerRumble,
|
||||
rightTriggerRumble);
|
||||
}
|
||||
|
||||
void HALSIM_SetJoystickRumbles(int32_t joystickNum, int32_t leftRumble,
|
||||
int32_t rightRumble, int32_t leftTriggerRumble,
|
||||
int32_t rightTriggerRumble) {
|
||||
SimDriverStationData->SetJoystickRumbles(joystickNum, leftRumble, rightRumble,
|
||||
leftTriggerRumble,
|
||||
rightTriggerRumble);
|
||||
}
|
||||
|
||||
int32_t HALSIM_RegisterMatchInfoCallback(HAL_MatchInfoCallback callback,
|
||||
@@ -523,8 +611,13 @@ void HALSIM_SetJoystickIsGamepad(int32_t stick, HAL_Bool isGamepad) {
|
||||
SimDriverStationData->SetJoystickIsGamepad(stick, isGamepad);
|
||||
}
|
||||
|
||||
void HALSIM_SetJoystickType(int32_t stick, int32_t type) {
|
||||
SimDriverStationData->SetJoystickType(stick, type);
|
||||
void HALSIM_SetJoystickGamepadType(int32_t stick, int32_t type) {
|
||||
SimDriverStationData->SetJoystickGamepadType(stick, type);
|
||||
}
|
||||
|
||||
void HALSIM_SetJoystickSupportedOutputs(int32_t stick,
|
||||
int32_t supportedOutputs) {
|
||||
SimDriverStationData->SetJoystickSupportedOutputs(stick, supportedOutputs);
|
||||
}
|
||||
|
||||
void HALSIM_SetJoystickName(int32_t stick, const WPI_String* name) {
|
||||
|
||||
@@ -26,7 +26,8 @@ class DriverStationData {
|
||||
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(JoystickPOVs)
|
||||
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(JoystickButtons)
|
||||
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(JoystickDescriptor)
|
||||
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(JoystickOutputs)
|
||||
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(JoystickLeds)
|
||||
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(JoystickRumbles)
|
||||
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(MatchInfo)
|
||||
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(NewData)
|
||||
|
||||
@@ -70,14 +71,22 @@ class DriverStationData {
|
||||
void SetJoystickDescriptor(int32_t joystickNum,
|
||||
const HAL_JoystickDescriptor* descriptor);
|
||||
|
||||
int32_t RegisterJoystickOutputsCallback(int32_t joystickNum,
|
||||
HAL_JoystickOutputsCallback callback,
|
||||
int32_t RegisterJoystickLedsCallback(int32_t joystickNum,
|
||||
HAL_JoystickLedsCallback callback,
|
||||
void* param, HAL_Bool initialNotify);
|
||||
void CancelJoystickLedsCallback(int32_t uid);
|
||||
void GetJoystickLeds(int32_t joystickNum, int32_t* leds);
|
||||
void SetJoystickLeds(int32_t joystickNum, int32_t leds);
|
||||
int32_t RegisterJoystickRumblesCallback(int32_t joystickNum,
|
||||
HAL_JoystickRumblesCallback callback,
|
||||
void* param, HAL_Bool initialNotify);
|
||||
void CancelJoystickOutputsCallback(int32_t uid);
|
||||
void GetJoystickOutputs(int32_t joystickNum, int64_t* outputs,
|
||||
int32_t* leftRumble, int32_t* rightRumble);
|
||||
void SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
|
||||
int32_t leftRumble, int32_t rightRumble);
|
||||
void CancelJoystickRumblesCallback(int32_t uid);
|
||||
void GetJoystickRumbles(int32_t joystickNum, int32_t* leftRumble,
|
||||
int32_t* rightRumble, int32_t* leftTriggerRumble,
|
||||
int32_t* rightTriggerRumble);
|
||||
void SetJoystickRumbles(int32_t joystickNum, int32_t leftRumble,
|
||||
int32_t rightRumble, int32_t leftTriggerRumble,
|
||||
int32_t rightTriggerRumble);
|
||||
|
||||
int32_t RegisterMatchInfoCallback(HAL_MatchInfoCallback callback, void* param,
|
||||
HAL_Bool initialNotify);
|
||||
@@ -106,8 +115,9 @@ class DriverStationData {
|
||||
uint8_t* povsAvailable);
|
||||
|
||||
void SetJoystickIsGamepad(int32_t stick, HAL_Bool isGamepad);
|
||||
void SetJoystickType(int32_t stick, int32_t type);
|
||||
void SetJoystickGamepadType(int32_t stick, int32_t type);
|
||||
void SetJoystickName(int32_t stick, std::string_view message);
|
||||
void SetJoystickSupportedOutputs(int32_t stick, int32_t supportedOutputs);
|
||||
|
||||
void SetGameSpecificMessage(std::string_view message);
|
||||
void SetEventName(std::string_view name);
|
||||
@@ -134,8 +144,10 @@ class DriverStationData {
|
||||
m_joystickPOVsCallbacks;
|
||||
SimCallbackRegistry<HAL_JoystickButtonsCallback, GetJoystickButtonsName>
|
||||
m_joystickButtonsCallbacks;
|
||||
SimCallbackRegistry<HAL_JoystickOutputsCallback, GetJoystickOutputsName>
|
||||
m_joystickOutputsCallbacks;
|
||||
SimCallbackRegistry<HAL_JoystickLedsCallback, GetJoystickLedsName>
|
||||
m_joystickLedsCallbacks;
|
||||
SimCallbackRegistry<HAL_JoystickRumblesCallback, GetJoystickRumblesName>
|
||||
m_joystickRumblesCallbacks;
|
||||
SimCallbackRegistry<HAL_JoystickDescriptorCallback, GetJoystickDescriptorName>
|
||||
m_joystickDescriptorCallbacks;
|
||||
SimCallbackRegistry<HAL_MatchInfoCallback, GetMatchInfoName>
|
||||
@@ -143,9 +155,11 @@ class DriverStationData {
|
||||
SimCallbackRegistry<HAL_NotifyCallback, GetNewDataName> m_newDataCallbacks;
|
||||
|
||||
struct JoystickOutputStore {
|
||||
int64_t outputs = 0;
|
||||
int32_t leds = 0;
|
||||
int32_t leftRumble = 0;
|
||||
int32_t rightRumble = 0;
|
||||
int32_t leftTriggerRumble = 0;
|
||||
int32_t rightTriggerRumble = 0;
|
||||
};
|
||||
|
||||
struct JoystickData {
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
#include "wpi/hal/Errors.h"
|
||||
#include "wpi/hal/proto/ControlData.h"
|
||||
#include "wpi/hal/proto/ErrorInfo.h"
|
||||
#include "wpi/hal/proto/JoystickDescriptor.h"
|
||||
#include "wpi/hal/proto/JoystickRumbleData.h"
|
||||
#include "wpi/hal/proto/JoystickDescriptors.h"
|
||||
#include "wpi/hal/proto/JoystickOutput.h"
|
||||
#include "wpi/hal/proto/MatchInfo.h"
|
||||
#include "wpi/hal/proto/OpMode.h"
|
||||
#include "wpi/nt/BooleanTopic.hpp"
|
||||
@@ -72,17 +72,16 @@ struct SystemServerDriverStation {
|
||||
wpi::nt::ProtobufSubscriber<mrc::MatchInfo> matchInfoSubscriber;
|
||||
wpi::nt::StringSubscriber gameSpecificMessageSubscriber;
|
||||
|
||||
std::array<wpi::nt::ProtobufSubscriber<mrc::JoystickDescriptor>,
|
||||
MRC_MAX_NUM_JOYSTICKS>
|
||||
joystickDescriptorTopics;
|
||||
wpi::nt::ProtobufSubscriber<mrc::JoystickDescriptors>
|
||||
joystickDescriptorsTopic;
|
||||
|
||||
wpi::nt::StringPublisher versionPublisher;
|
||||
wpi::nt::StringPublisher consoleLinePublisher;
|
||||
wpi::nt::ProtobufPublisher<mrc::ErrorInfo> errorInfoPublisher;
|
||||
|
||||
std::array<wpi::nt::ProtobufPublisher<mrc::JoystickRumbleData>,
|
||||
std::array<wpi::nt::ProtobufPublisher<mrc::JoystickOutput>,
|
||||
MRC_MAX_NUM_JOYSTICKS>
|
||||
joystickRumbleTopics;
|
||||
joystickOutputTopics;
|
||||
|
||||
wpi::nt::ProtobufPublisher<std::vector<mrc::OpMode>> teleopOpModes;
|
||||
wpi::nt::ProtobufPublisher<std::vector<mrc::OpMode>> autoOpModes;
|
||||
@@ -95,6 +94,9 @@ struct SystemServerDriverStation {
|
||||
wpi::util::ProtobufMessage<mrc::ControlData> controlDataMsg;
|
||||
wpi::nt::Value lastValue;
|
||||
|
||||
wpi::util::mutex joystickOutputMutexes[MRC_MAX_NUM_JOYSTICKS];
|
||||
mrc::JoystickOutput joystickOutputs[MRC_MAX_NUM_JOYSTICKS];
|
||||
|
||||
explicit SystemServerDriverStation(wpi::nt::NetworkTableInstance inst) {
|
||||
ntInst = inst;
|
||||
|
||||
@@ -106,12 +108,11 @@ struct SystemServerDriverStation {
|
||||
hasUserCodeReadyPublisher =
|
||||
ntInst.GetBooleanTopic(ROBOT_HAS_USER_CODE_READY_PATH).Publish(options);
|
||||
|
||||
for (size_t count = 0; count < joystickRumbleTopics.size(); count++) {
|
||||
std::string name = ROBOT_JOYSTICK_RUMBLE_PATH;
|
||||
for (size_t count = 0; count < joystickOutputTopics.size(); count++) {
|
||||
std::string name = ROBOT_JOYSTICK_OUTPUTS_PATH;
|
||||
name += std::to_string(count);
|
||||
joystickRumbleTopics[count] =
|
||||
ntInst.GetProtobufTopic<mrc::JoystickRumbleData>(name).Publish(
|
||||
options);
|
||||
joystickOutputTopics[count] =
|
||||
ntInst.GetProtobufTopic<mrc::JoystickOutput>(name).Publish(options);
|
||||
}
|
||||
|
||||
hasUserCodePublisher =
|
||||
@@ -142,12 +143,10 @@ struct SystemServerDriverStation {
|
||||
gameSpecificMessageSubscriber =
|
||||
ntInst.GetStringTopic(ROBOT_GAME_SPECIFIC_MESSAGE_PATH).Subscribe({});
|
||||
|
||||
for (size_t count = 0; count < joystickDescriptorTopics.size(); count++) {
|
||||
std::string name = ROBOT_JOYSTICK_DESCRIPTORS_PATH;
|
||||
name += std::to_string(count);
|
||||
joystickDescriptorTopics[count] =
|
||||
ntInst.GetProtobufTopic<mrc::JoystickDescriptor>(name).Subscribe({});
|
||||
}
|
||||
joystickDescriptorsTopic = ntInst
|
||||
.GetProtobufTopic<mrc::JoystickDescriptors>(
|
||||
ROBOT_JOYSTICK_DESCRIPTORS_PATH)
|
||||
.Subscribe({});
|
||||
|
||||
teleopOpModes = ntInst
|
||||
.GetProtobufTopic<std::vector<mrc::OpMode>>(
|
||||
@@ -333,14 +332,17 @@ void TcpCache::Update() {
|
||||
}
|
||||
matchInfo.gameSpecificMessageSize = gameDataLen;
|
||||
|
||||
for (size_t count = 0;
|
||||
count < systemServerDs->joystickDescriptorTopics.size(); count++) {
|
||||
auto newDesc = systemServerDs->joystickDescriptorTopics[count].Get();
|
||||
const auto descriptorsMsg = systemServerDs->joystickDescriptorsTopic.Get();
|
||||
size_t descriptorCount = descriptorsMsg.GetDescriptorCount();
|
||||
|
||||
for (size_t count = 0; count < descriptorCount; count++) {
|
||||
const auto& newDesc = descriptorsMsg.Descriptors()[count];
|
||||
|
||||
auto& desc = descriptors[count];
|
||||
|
||||
desc.isGamepad = newDesc.IsGamepad;
|
||||
desc.type = newDesc.Type;
|
||||
desc.supportedOutputs = newDesc.SupportedOutputs;
|
||||
desc.gamepadType = newDesc.GamepadType;
|
||||
|
||||
auto joystickName = newDesc.GetName();
|
||||
auto joystickNameLen =
|
||||
@@ -519,12 +521,21 @@ HAL_Bool HAL_GetJoystickIsGamepad(int32_t joystickNum) {
|
||||
}
|
||||
}
|
||||
|
||||
int32_t HAL_GetJoystickType(int32_t joystickNum) {
|
||||
int32_t HAL_GetJoystickGamepadType(int32_t joystickNum) {
|
||||
HAL_JoystickDescriptor joystickDesc;
|
||||
if (HAL_GetJoystickDescriptor(joystickNum, &joystickDesc) < 0) {
|
||||
return -1;
|
||||
} else {
|
||||
return joystickDesc.type;
|
||||
return joystickDesc.gamepadType;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t HAL_GetJoystickSupportedOutputs(int32_t joystickNum) {
|
||||
HAL_JoystickDescriptor joystickDesc;
|
||||
if (HAL_GetJoystickDescriptor(joystickNum, &joystickDesc) < 0) {
|
||||
return -1;
|
||||
} else {
|
||||
return joystickDesc.supportedOutputs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -539,22 +550,37 @@ void HAL_GetJoystickName(struct WPI_String* name, int32_t joystickNum) {
|
||||
std::memcpy(write, cName, len);
|
||||
}
|
||||
|
||||
int32_t HAL_SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
|
||||
int32_t leftRumble, int32_t rightRumble) {
|
||||
int32_t HAL_SetJoystickRumble(int32_t joystickNum, int32_t leftRumble,
|
||||
int32_t rightRumble, int32_t leftTriggerRumble,
|
||||
int32_t rightTriggerRumble) {
|
||||
CHECK_JOYSTICK_NUMBER(joystickNum);
|
||||
|
||||
// TODO Update this API
|
||||
std::scoped_lock lock{systemServerDs->joystickOutputMutexes[joystickNum]};
|
||||
systemServerDs->joystickOutputs[joystickNum].LeftRumble =
|
||||
std::clamp(leftRumble, 0, UINT16_MAX);
|
||||
systemServerDs->joystickOutputs[joystickNum].RightRumble =
|
||||
std::clamp(rightRumble, 0, UINT16_MAX);
|
||||
systemServerDs->joystickOutputs[joystickNum].LeftTriggerRumble =
|
||||
std::clamp(leftTriggerRumble, 0, UINT16_MAX);
|
||||
systemServerDs->joystickOutputs[joystickNum].RightTriggerRumble =
|
||||
std::clamp(rightTriggerRumble, 0, UINT16_MAX);
|
||||
|
||||
// mrc::JoystickOutputData outputData{
|
||||
// .HidOutputs = static_cast<uint32_t>(outputs),
|
||||
// .LeftRumble = std::clamp(leftRumble, 0, UINT16_MAX) /
|
||||
// static_cast<float>(UINT16_MAX),
|
||||
// .RightRumble = std::clamp(rightRumble, 0, UINT16_MAX) /
|
||||
// static_cast<float>(UINT16_MAX),
|
||||
// };
|
||||
systemServerDs->joystickOutputTopics[joystickNum].Set(
|
||||
systemServerDs->joystickOutputs[joystickNum]);
|
||||
|
||||
// systemServerDs->joystickRumbleTopics[joystickNum].Set(outputData);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t HAL_SetJoystickLeds(int32_t joystickNum, int32_t leds) {
|
||||
CHECK_JOYSTICK_NUMBER(joystickNum);
|
||||
|
||||
std::scoped_lock lock{systemServerDs->joystickOutputMutexes[joystickNum]};
|
||||
systemServerDs->joystickOutputs[joystickNum].R = (leds >> 16) & 0xFF;
|
||||
systemServerDs->joystickOutputs[joystickNum].G = (leds >> 8) & 0xFF;
|
||||
systemServerDs->joystickOutputs[joystickNum].B = leds & 0xFF;
|
||||
|
||||
systemServerDs->joystickOutputTopics[joystickNum].Set(
|
||||
systemServerDs->joystickOutputs[joystickNum]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,19 +43,34 @@ DEFINE_CAPI(POVs, povs)
|
||||
DEFINE_CAPI(Buttons, buttons)
|
||||
DEFINE_CAPI(Descriptor, descriptor)
|
||||
|
||||
int32_t HALSIM_RegisterJoystickOutputsCallback(
|
||||
int32_t joystickNum, HAL_JoystickOutputsCallback callback, void* param,
|
||||
int32_t HALSIM_RegisterJoystickLedsCallback(int32_t joystickNum,
|
||||
HAL_JoystickLedsCallback callback,
|
||||
void* param,
|
||||
HAL_Bool initialNotify) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void HALSIM_CancelJoystickLedsCallback(int32_t uid) {}
|
||||
|
||||
void HALSIM_GetJoystickLeds(int32_t joystickNum, int32_t* leds) {}
|
||||
|
||||
void HALSIM_SetJoystickLeds(int32_t joystickNum, int32_t leds) {}
|
||||
|
||||
int32_t HALSIM_RegisterJoystickRumblesCallback(
|
||||
int32_t joystickNum, HAL_JoystickRumblesCallback callback, void* param,
|
||||
HAL_Bool initialNotify) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void HALSIM_CancelJoystickOutputsCallback(int32_t uid) {}
|
||||
void HALSIM_CancelJoystickRumblesCallback(int32_t uid) {}
|
||||
|
||||
void HALSIM_GetJoystickOutputs(int32_t joystickNum, int64_t* outputs,
|
||||
int32_t* leftRumble, int32_t* rightRumble) {}
|
||||
void HALSIM_GetJoystickRumbles(int32_t joystickNum, int32_t* leftRumble,
|
||||
int32_t* rightRumble, int32_t* leftTriggerRumble,
|
||||
int32_t* rightTriggerRumble) {}
|
||||
|
||||
void HALSIM_SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
|
||||
int32_t leftRumble, int32_t rightRumble) {}
|
||||
void HALSIM_SetJoystickRumbles(int32_t joystickNum, int32_t leftRumble,
|
||||
int32_t rightRumble, int32_t leftTriggerRumble,
|
||||
int32_t rightTriggerRumble) {}
|
||||
|
||||
int32_t HALSIM_RegisterMatchInfoCallback(HAL_MatchInfoCallback callback,
|
||||
void* param, HAL_Bool initialNotify) {
|
||||
@@ -102,10 +117,13 @@ void HALSIM_GetJoystickAvailables(int32_t stick, uint16_t* axesAvailable,
|
||||
|
||||
void HALSIM_SetJoystickIsGamepad(int32_t stick, HAL_Bool isGamepad) {}
|
||||
|
||||
void HALSIM_SetJoystickType(int32_t stick, int32_t type) {}
|
||||
void HALSIM_SetJoystickGamepadType(int32_t stick, int32_t type) {}
|
||||
|
||||
void HALSIM_SetJoystickName(int32_t stick, const struct WPI_String* name) {}
|
||||
|
||||
void HALSIM_SetJoystickSupportedOutputs(int32_t stick,
|
||||
int32_t supportedOutputs) {}
|
||||
|
||||
void HALSIM_SetGameSpecificMessage(const struct WPI_String* message) {}
|
||||
|
||||
void HALSIM_SetEventName(const struct WPI_String* name) {}
|
||||
|
||||
Reference in New Issue
Block a user