[sim] Move WPILib C++ sim implementations out of line (#2598)

This makes the sim classes consistent with the rest of the WPILibC classes.
This commit is contained in:
Peter Johnson
2020-07-15 23:48:09 -07:00
committed by GitHub
parent b9feb81226
commit c2cc90b27d
49 changed files with 3068 additions and 1621 deletions

View File

@@ -0,0 +1,89 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018-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. */
/*----------------------------------------------------------------------------*/
#include "frc/simulation/AnalogTriggerSim.h"
#include <memory>
#include <stdexcept>
#include <utility>
#include <hal/simulation/AnalogTriggerData.h>
#include "frc/AnalogTrigger.h"
using namespace frc;
using namespace frc::sim;
AnalogTriggerSim::AnalogTriggerSim(const AnalogTrigger& analogTrigger)
: m_index{analogTrigger.GetIndex()} {}
AnalogTriggerSim AnalogTriggerSim::CreateForChannel(int channel) {
int index = HALSIM_FindAnalogTriggerForChannel(channel);
if (index < 0) throw std::out_of_range("no analog trigger found for channel");
return AnalogTriggerSim{index};
}
AnalogTriggerSim AnalogTriggerSim::CreateForIndex(int index) {
return AnalogTriggerSim{index};
}
std::unique_ptr<CallbackStore> AnalogTriggerSim::RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogTriggerInitializedCallback);
store->SetUid(HALSIM_RegisterAnalogTriggerInitializedCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool AnalogTriggerSim::GetInitialized() const {
return HALSIM_GetAnalogTriggerInitialized(m_index);
}
void AnalogTriggerSim::SetInitialized(bool initialized) {
HALSIM_SetAnalogTriggerInitialized(m_index, initialized);
}
std::unique_ptr<CallbackStore>
AnalogTriggerSim::RegisterTriggerLowerBoundCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback,
&HALSIM_CancelAnalogTriggerTriggerLowerBoundCallback);
store->SetUid(HALSIM_RegisterAnalogTriggerTriggerLowerBoundCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double AnalogTriggerSim::GetTriggerLowerBound() const {
return HALSIM_GetAnalogTriggerTriggerLowerBound(m_index);
}
void AnalogTriggerSim::SetTriggerLowerBound(double triggerLowerBound) {
HALSIM_SetAnalogTriggerTriggerLowerBound(m_index, triggerLowerBound);
}
std::unique_ptr<CallbackStore>
AnalogTriggerSim::RegisterTriggerUpperBoundCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback,
&HALSIM_CancelAnalogTriggerTriggerUpperBoundCallback);
store->SetUid(HALSIM_RegisterAnalogTriggerTriggerUpperBoundCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double AnalogTriggerSim::GetTriggerUpperBound() const {
return HALSIM_GetAnalogTriggerTriggerUpperBound(m_index);
}
void AnalogTriggerSim::SetTriggerUpperBound(double triggerUpperBound) {
HALSIM_SetAnalogTriggerTriggerUpperBound(m_index, triggerUpperBound);
}
void AnalogTriggerSim::ResetData() { HALSIM_ResetAnalogTriggerData(m_index); }