[sim] Add SimDeviceSim ctor overloads (#3134)

Better parallelism with SimDevice.create(), so teams don't have to mess with concatenating the index/channel themselves.
This commit is contained in:
Starlight220
2021-02-13 08:17:13 +02:00
committed by GitHub
parent 247420c9c1
commit d447c7dc32
3 changed files with 56 additions and 0 deletions

View File

@@ -9,6 +9,8 @@
#include <hal/SimDevice.h>
#include <hal/simulation/SimDeviceData.h>
#include <wpi/SmallString.h>
#include <wpi/raw_ostream.h>
using namespace frc;
using namespace frc::sim;
@@ -16,6 +18,22 @@ using namespace frc::sim;
SimDeviceSim::SimDeviceSim(const char* name)
: m_handle{HALSIM_GetSimDeviceHandle(name)} {}
SimDeviceSim::SimDeviceSim(const char* name, int index) {
wpi::SmallString<128> fullname;
wpi::raw_svector_ostream os(fullname);
os << name << '[' << index << ']';
m_handle = HALSIM_GetSimDeviceHandle(fullname.c_str());
}
SimDeviceSim::SimDeviceSim(const char* name, int index, int channel) {
wpi::SmallString<128> fullname;
wpi::raw_svector_ostream os(fullname);
os << name << '[' << index << ',' << channel << ']';
m_handle = HALSIM_GetSimDeviceHandle(fullname.c_str());
}
hal::SimValue SimDeviceSim::GetValue(const char* name) const {
return HALSIM_GetSimValueHandle(m_handle, name);
}