mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-27 02:01:42 +00:00
[sim] Add WPILib-class-taking constructors (#2538)
When not direct mapped, make index constructors private and add factory functions for channel and index. Co-authored-by: GabrielDeml <gabrielddeml@gmail.com>
This commit is contained in:
@@ -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. */
|
||||
@@ -85,6 +85,7 @@ HAL_AnalogTriggerHandle HAL_InitializeAnalogTrigger(
|
||||
trigger->index = static_cast<uint8_t>(getHandleIndex(handle));
|
||||
|
||||
SimAnalogTriggerData[trigger->index].initialized = true;
|
||||
SimAnalogTriggerData[trigger->index].inputPort = analog_port->channel;
|
||||
|
||||
trigger->trigState = false;
|
||||
|
||||
|
||||
@@ -291,4 +291,16 @@ Java_edu_wpi_first_hal_simulation_AddressableLEDDataJNI_resetData
|
||||
HALSIM_ResetAddressableLEDData(index);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_AddressableLEDDataJNI
|
||||
* Method: findForChannel
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_AddressableLEDDataJNI_findForChannel
|
||||
(JNIEnv*, jclass, jint channel)
|
||||
{
|
||||
return HALSIM_FindAddressableLEDForChannel(channel);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -180,4 +180,16 @@ Java_edu_wpi_first_hal_simulation_AnalogTriggerDataJNI_resetData
|
||||
HALSIM_ResetAnalogTriggerData(index);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_AnalogTriggerDataJNI
|
||||
* Method: findForChannel
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_AnalogTriggerDataJNI_findForChannel
|
||||
(JNIEnv*, jclass, jint channel)
|
||||
{
|
||||
return HALSIM_FindAnalogTriggerForChannel(channel);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -177,4 +177,16 @@ Java_edu_wpi_first_hal_simulation_DigitalPWMDataJNI_resetData
|
||||
HALSIM_ResetDigitalPWMData(index);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_DigitalPWMDataJNI
|
||||
* Method: findForChannel
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_DigitalPWMDataJNI_findForChannel
|
||||
(JNIEnv*, jclass, jint channel)
|
||||
{
|
||||
return HALSIM_FindDigitalPWMForChannel(channel);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -177,4 +177,16 @@ Java_edu_wpi_first_hal_simulation_DutyCycleDataJNI_resetData
|
||||
HALSIM_ResetDutyCycleData(index);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_DutyCycleDataJNI
|
||||
* Method: findForChannel
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_DutyCycleDataJNI_findForChannel
|
||||
(JNIEnv*, jclass, jint channel)
|
||||
{
|
||||
return HALSIM_FindDutyCycleForChannel(channel);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -475,4 +475,16 @@ Java_edu_wpi_first_hal_simulation_EncoderDataJNI_resetData
|
||||
HALSIM_ResetEncoderData(index);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_EncoderDataJNI
|
||||
* Method: findForChannel
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_EncoderDataJNI_findForChannel
|
||||
(JNIEnv*, jclass, jint channel)
|
||||
{
|
||||
return HALSIM_FindEncoderForChannel(channel);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -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. */
|
||||
@@ -49,6 +49,16 @@ int32_t AddressableLEDData::GetData(HAL_AddressableLEDData* d) {
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
int32_t HALSIM_FindAddressableLEDForChannel(int32_t channel) {
|
||||
for (int i = 0; i < kNumAddressableLEDs; ++i) {
|
||||
if (SimAddressableLEDData[i].initialized &&
|
||||
SimAddressableLEDData[i].outputPort == channel)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void HALSIM_ResetAddressableLEDData(int32_t index) {
|
||||
SimAddressableLEDData[index].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. */
|
||||
@@ -28,6 +28,16 @@ void AnalogTriggerData::ResetData() {
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
int32_t HALSIM_FindAnalogTriggerForChannel(int32_t channel) {
|
||||
for (int i = 0; i < kNumAnalogTriggers; ++i) {
|
||||
if (SimAnalogTriggerData[i].initialized &&
|
||||
SimAnalogTriggerData[i].inputPort == channel)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void HALSIM_ResetAnalogTriggerData(int32_t index) {
|
||||
SimAnalogTriggerData[index].ResetData();
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ class AnalogTriggerData {
|
||||
SimDataValue<HALSIM_AnalogTriggerMode, MakeTriggerModeValue,
|
||||
GetTriggerModeName>
|
||||
triggerMode{static_cast<HALSIM_AnalogTriggerMode>(0)};
|
||||
std::atomic<int32_t> inputPort;
|
||||
|
||||
virtual void 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. */
|
||||
@@ -27,6 +27,14 @@ void DigitalPWMData::ResetData() {
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
int32_t HALSIM_FindDigitalPWMForChannel(int32_t channel) {
|
||||
for (int i = 0; i < kNumDigitalPWMOutputs; ++i) {
|
||||
if (SimDigitalPWMData[i].initialized && SimDigitalPWMData[i].pin == channel)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void HALSIM_ResetDigitalPWMData(int32_t index) {
|
||||
SimDigitalPWMData[index].ResetData();
|
||||
}
|
||||
|
||||
@@ -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. */
|
||||
@@ -30,6 +30,15 @@ void DutyCycleData::ResetData() {
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
int32_t HALSIM_FindDutyCycleForChannel(int32_t channel) {
|
||||
for (int i = 0; i < kNumDutyCycles; ++i) {
|
||||
if (SimDutyCycleData[i].initialized &&
|
||||
SimDutyCycleData[i].digitalChannel == channel)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void HALSIM_ResetDutyCycleData(int32_t index) {
|
||||
SimDutyCycleData[index].ResetData();
|
||||
}
|
||||
|
||||
@@ -36,6 +36,16 @@ void EncoderData::ResetData() {
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
int32_t HALSIM_FindEncoderForChannel(int32_t channel) {
|
||||
for (int i = 0; i < kNumEncoders; ++i) {
|
||||
if (!SimEncoderData[i].initialized) continue;
|
||||
if (SimEncoderData[i].digitalChannelA == channel ||
|
||||
SimEncoderData[i].digitalChannelB == channel)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void HALSIM_ResetEncoderData(int32_t index) {
|
||||
SimEncoderData[index].ResetData();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user