mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
[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:
@@ -7,16 +7,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <exception>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include <hal/simulation/EncoderData.h>
|
||||
|
||||
#include "CallbackStore.h"
|
||||
#include "frc/Encoder.h"
|
||||
#include "frc/simulation/CallbackStore.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class Encoder;
|
||||
|
||||
namespace sim {
|
||||
|
||||
/**
|
||||
@@ -29,8 +27,7 @@ class EncoderSim {
|
||||
*
|
||||
* @param encoder Encoder to simulate
|
||||
*/
|
||||
explicit EncoderSim(const Encoder& encoder)
|
||||
: m_index{encoder.GetFPGAIndex()} {}
|
||||
explicit EncoderSim(const Encoder& encoder);
|
||||
|
||||
/**
|
||||
* Creates an EncoderSim for a digital input channel. Encoders take two
|
||||
@@ -40,11 +37,7 @@ class EncoderSim {
|
||||
* @return Simulated object
|
||||
* @throws NoSuchElementException if no Encoder is configured for that channel
|
||||
*/
|
||||
static EncoderSim CreateForChannel(int channel) {
|
||||
int index = HALSIM_FindEncoderForChannel(channel);
|
||||
if (index < 0) throw std::out_of_range("no encoder found for channel");
|
||||
return EncoderSim{index};
|
||||
}
|
||||
static EncoderSim CreateForChannel(int channel);
|
||||
|
||||
/**
|
||||
* Creates an EncoderSim for a simulated index.
|
||||
@@ -53,154 +46,80 @@ class EncoderSim {
|
||||
* @param index simulator index
|
||||
* @return Simulated object
|
||||
*/
|
||||
static EncoderSim CreateForIndex(int index) { return EncoderSim{index}; }
|
||||
static EncoderSim CreateForIndex(int index);
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelEncoderInitializedCallback);
|
||||
store->SetUid(HALSIM_RegisterEncoderInitializedCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
NotifyCallback callback, bool initialNotify);
|
||||
|
||||
bool GetInitialized() const { return HALSIM_GetEncoderInitialized(m_index); }
|
||||
bool GetInitialized() const;
|
||||
|
||||
void SetInitialized(bool initialized) {
|
||||
HALSIM_SetEncoderInitialized(m_index, initialized);
|
||||
}
|
||||
void SetInitialized(bool initialized);
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterCountCallback(NotifyCallback callback,
|
||||
bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelEncoderCountCallback);
|
||||
store->SetUid(HALSIM_RegisterEncoderCountCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
bool initialNotify);
|
||||
|
||||
int GetCount() const { return HALSIM_GetEncoderCount(m_index); }
|
||||
int GetCount() const;
|
||||
|
||||
void SetCount(int count) { HALSIM_SetEncoderCount(m_index, count); }
|
||||
void SetCount(int count);
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterPeriodCallback(NotifyCallback callback,
|
||||
bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelEncoderPeriodCallback);
|
||||
store->SetUid(HALSIM_RegisterEncoderPeriodCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
bool initialNotify);
|
||||
|
||||
double GetPeriod() const { return HALSIM_GetEncoderPeriod(m_index); }
|
||||
double GetPeriod() const;
|
||||
|
||||
void SetPeriod(double period) { HALSIM_SetEncoderPeriod(m_index, period); }
|
||||
void SetPeriod(double period);
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterResetCallback(NotifyCallback callback,
|
||||
bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelEncoderResetCallback);
|
||||
store->SetUid(HALSIM_RegisterEncoderResetCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
bool initialNotify);
|
||||
|
||||
bool GetReset() const { return HALSIM_GetEncoderReset(m_index); }
|
||||
bool GetReset() const;
|
||||
|
||||
void SetReset(bool reset) { HALSIM_SetEncoderReset(m_index, reset); }
|
||||
void SetReset(bool reset);
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterMaxPeriodCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelEncoderMaxPeriodCallback);
|
||||
store->SetUid(HALSIM_RegisterEncoderMaxPeriodCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
NotifyCallback callback, bool initialNotify);
|
||||
|
||||
double GetMaxPeriod() const { return HALSIM_GetEncoderMaxPeriod(m_index); }
|
||||
double GetMaxPeriod() const;
|
||||
|
||||
void SetMaxPeriod(double maxPeriod) {
|
||||
HALSIM_SetEncoderMaxPeriod(m_index, maxPeriod);
|
||||
}
|
||||
void SetMaxPeriod(double maxPeriod);
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterDirectionCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelEncoderDirectionCallback);
|
||||
store->SetUid(HALSIM_RegisterEncoderDirectionCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
NotifyCallback callback, bool initialNotify);
|
||||
|
||||
bool GetDirection() const { return HALSIM_GetEncoderDirection(m_index); }
|
||||
bool GetDirection() const;
|
||||
|
||||
void SetDirection(bool direction) {
|
||||
HALSIM_SetEncoderDirection(m_index, direction);
|
||||
}
|
||||
void SetDirection(bool direction);
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterReverseDirectionCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelEncoderReverseDirectionCallback);
|
||||
store->SetUid(HALSIM_RegisterEncoderReverseDirectionCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
NotifyCallback callback, bool initialNotify);
|
||||
|
||||
bool GetReverseDirection() const {
|
||||
return HALSIM_GetEncoderReverseDirection(m_index);
|
||||
}
|
||||
bool GetReverseDirection() const;
|
||||
|
||||
void SetReverseDirection(bool reverseDirection) {
|
||||
HALSIM_SetEncoderReverseDirection(m_index, reverseDirection);
|
||||
}
|
||||
void SetReverseDirection(bool reverseDirection);
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterSamplesToAverageCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelEncoderSamplesToAverageCallback);
|
||||
store->SetUid(HALSIM_RegisterEncoderSamplesToAverageCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
NotifyCallback callback, bool initialNotify);
|
||||
|
||||
int GetSamplesToAverage() const {
|
||||
return HALSIM_GetEncoderSamplesToAverage(m_index);
|
||||
}
|
||||
int GetSamplesToAverage() const;
|
||||
|
||||
void SetSamplesToAverage(int samplesToAverage) {
|
||||
HALSIM_SetEncoderSamplesToAverage(m_index, samplesToAverage);
|
||||
}
|
||||
void SetSamplesToAverage(int samplesToAverage);
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterDistancePerPulseCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelEncoderDistancePerPulseCallback);
|
||||
store->SetUid(HALSIM_RegisterEncoderDistancePerPulseCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
NotifyCallback callback, bool initialNotify);
|
||||
|
||||
double GetDistancePerPulse() const {
|
||||
return HALSIM_GetEncoderDistancePerPulse(m_index);
|
||||
}
|
||||
double GetDistancePerPulse() const;
|
||||
|
||||
void SetDistancePerPulse(double distancePerPulse) {
|
||||
HALSIM_SetEncoderDistancePerPulse(m_index, distancePerPulse);
|
||||
}
|
||||
void SetDistancePerPulse(double distancePerPulse);
|
||||
|
||||
void ResetData() { HALSIM_ResetEncoderData(m_index); }
|
||||
void ResetData();
|
||||
|
||||
void SetDistance(double distance) {
|
||||
HALSIM_SetEncoderDistance(m_index, distance);
|
||||
}
|
||||
void SetDistance(double distance);
|
||||
|
||||
double GetDistance() { return HALSIM_GetEncoderDistance(m_index); }
|
||||
double GetDistance();
|
||||
|
||||
void SetRate(double rate) { HALSIM_SetEncoderRate(m_index, rate); }
|
||||
void SetRate(double rate);
|
||||
|
||||
double GetRate() { return HALSIM_GetEncoderRate(m_index); }
|
||||
double GetRate();
|
||||
|
||||
private:
|
||||
explicit EncoderSim(int index) : m_index{index} {}
|
||||
|
||||
Reference in New Issue
Block a user