[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:
Peter Johnson
2020-07-04 10:10:43 -07:00
committed by GitHub
parent 80a1fa9ece
commit 3050e935a1
75 changed files with 1281 additions and 126 deletions

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
};

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}