[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

@@ -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. */
@@ -19,8 +19,8 @@ CommandTestBase::CommandTestBase() {
CommandScheduler CommandTestBase::GetScheduler() { return CommandScheduler(); }
void CommandTestBase::SetUp() {
HALSIM_SetDriverStationEnabled(true);
while (!HALSIM_GetDriverStationEnabled()) {
frc::sim::DriverStationSim::SetEnabled(true);
while (!frc::sim::DriverStationSim::GetEnabled()) {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
}
@@ -30,8 +30,8 @@ void CommandTestBase::TearDown() {
}
void CommandTestBase::SetDSEnabled(bool enabled) {
HALSIM_SetDriverStationEnabled(enabled);
while (HALSIM_GetDriverStationEnabled() != static_cast<int>(enabled)) {
frc::sim::DriverStationSim::SetEnabled(enabled);
while (frc::sim::DriverStationSim::GetEnabled() != enabled) {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
}

View File

@@ -11,7 +11,6 @@
#include <utility>
#include <frc/simulation/DriverStationSim.h>
#include <hal/simulation/MockHooks.h>
#include "ErrorConfirmer.h"
#include "frc2/command/CommandGroupBase.h"

View File

@@ -6,7 +6,7 @@
/*----------------------------------------------------------------------------*/
#include <frc/Joystick.h>
#include <hal/simulation/DriverStationData.h>
#include <frc/simulation/JoystickSim.h>
#include "CommandTestBase.h"
#include "frc2/command/CommandScheduler.h"
@@ -19,11 +19,9 @@ using namespace frc2;
class POVButtonTest : public CommandTestBase {};
TEST_F(POVButtonTest, SetPOVTest) {
HAL_JoystickPOVs povs;
povs.count = 1;
povs.povs[0] = 0;
HALSIM_SetJoystickPOVs(1, &povs);
HALSIM_NotifyDriverStationNewData();
frc::sim::JoystickSim joysim(1);
joysim.SetPOV(0);
joysim.NotifyNewData();
auto& scheduler = CommandScheduler::GetInstance();
bool finished = false;
@@ -35,9 +33,8 @@ TEST_F(POVButtonTest, SetPOVTest) {
scheduler.Run();
EXPECT_FALSE(scheduler.IsScheduled(&command));
povs.povs[0] = 90;
HALSIM_SetJoystickPOVs(1, &povs);
HALSIM_NotifyDriverStationNewData();
joysim.SetPOV(90);
joysim.NotifyNewData();
scheduler.Run();
EXPECT_TRUE(scheduler.IsScheduled(&command));

View File

@@ -0,0 +1,119 @@
/*----------------------------------------------------------------------------*/
/* 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/AddressableLEDSim.h"
#include <memory>
#include <stdexcept>
#include <utility>
#include <hal/simulation/AddressableLEDData.h>
using namespace frc;
using namespace frc::sim;
AddressableLEDSim::AddressableLEDSim() : m_index{0} {}
AddressableLEDSim::AddressableLEDSim(const AddressableLED& addressableLED)
: m_index{0} {}
AddressableLEDSim AddressableLEDSim::CreateForChannel(int pwmChannel) {
int index = HALSIM_FindAddressableLEDForChannel(pwmChannel);
if (index < 0)
throw std::out_of_range("no addressable LED found for PWM channel");
return AddressableLEDSim{index};
}
AddressableLEDSim AddressableLEDSim::CreateForIndex(int index) {
return AddressableLEDSim{index};
}
std::unique_ptr<CallbackStore> AddressableLEDSim::RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAddressableLEDInitializedCallback);
store->SetUid(HALSIM_RegisterAddressableLEDInitializedCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool AddressableLEDSim::GetInitialized() const {
return HALSIM_GetAddressableLEDInitialized(m_index);
}
void AddressableLEDSim::SetInitialized(bool initialized) {
HALSIM_SetAddressableLEDInitialized(m_index, initialized);
}
std::unique_ptr<CallbackStore> AddressableLEDSim::RegisterOutputPortCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAddressableLEDOutputPortCallback);
store->SetUid(HALSIM_RegisterAddressableLEDOutputPortCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
int AddressableLEDSim::GetOutputPort() const {
return HALSIM_GetAddressableLEDOutputPort(m_index);
}
void AddressableLEDSim::SetOutputPort(int outputPort) {
HALSIM_SetAddressableLEDOutputPort(m_index, outputPort);
}
std::unique_ptr<CallbackStore> AddressableLEDSim::RegisterLengthCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAddressableLEDLengthCallback);
store->SetUid(HALSIM_RegisterAddressableLEDLengthCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
int AddressableLEDSim::GetLength() const {
return HALSIM_GetAddressableLEDLength(m_index);
}
void AddressableLEDSim::SetLength(int length) {
HALSIM_SetAddressableLEDLength(m_index, length);
}
std::unique_ptr<CallbackStore> AddressableLEDSim::RegisterRunningCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAddressableLEDRunningCallback);
store->SetUid(HALSIM_RegisterAddressableLEDRunningCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
int AddressableLEDSim::GetRunning() const {
return HALSIM_GetAddressableLEDRunning(m_index);
}
void AddressableLEDSim::SetRunning(bool running) {
HALSIM_SetAddressableLEDRunning(m_index, running);
}
std::unique_ptr<CallbackStore> AddressableLEDSim::RegisterDataCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAddressableLEDDataCallback);
store->SetUid(HALSIM_RegisterAddressableLEDDataCallback(
m_index, &ConstBufferCallbackStoreThunk, store.get()));
return store;
}
int AddressableLEDSim::GetData(struct HAL_AddressableLEDData* data) const {
return HALSIM_GetAddressableLEDData(m_index, data);
}
void AddressableLEDSim::SetData(struct HAL_AddressableLEDData* data,
int length) {
HALSIM_SetAddressableLEDData(m_index, data, length);
}

View File

@@ -0,0 +1,77 @@
/*----------------------------------------------------------------------------*/
/* 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/AnalogGyroSim.h"
#include <memory>
#include <utility>
#include <hal/simulation/AnalogGyroData.h>
#include "frc/AnalogGyro.h"
#include "frc/AnalogInput.h"
using namespace frc;
using namespace frc::sim;
AnalogGyroSim::AnalogGyroSim(const AnalogGyro& gyro)
: m_index{gyro.GetAnalogInput()->GetChannel()} {}
AnalogGyroSim::AnalogGyroSim(int channel) : m_index{channel} {}
std::unique_ptr<CallbackStore> AnalogGyroSim::RegisterAngleCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogGyroAngleCallback);
store->SetUid(HALSIM_RegisterAnalogGyroAngleCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double AnalogGyroSim::GetAngle() const {
return HALSIM_GetAnalogGyroAngle(m_index);
}
void AnalogGyroSim::SetAngle(double angle) {
HALSIM_SetAnalogGyroAngle(m_index, angle);
}
std::unique_ptr<CallbackStore> AnalogGyroSim::RegisterRateCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogGyroRateCallback);
store->SetUid(HALSIM_RegisterAnalogGyroRateCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double AnalogGyroSim::GetRate() const {
return HALSIM_GetAnalogGyroRate(m_index);
}
void AnalogGyroSim::SetRate(double rate) {
HALSIM_SetAnalogGyroRate(m_index, rate);
}
std::unique_ptr<CallbackStore> AnalogGyroSim::RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogGyroInitializedCallback);
store->SetUid(HALSIM_RegisterAnalogGyroInitializedCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool AnalogGyroSim::GetInitialized() const {
return HALSIM_GetAnalogGyroInitialized(m_index);
}
void AnalogGyroSim::SetInitialized(bool initialized) {
HALSIM_SetAnalogGyroInitialized(m_index, initialized);
}
void AnalogGyroSim::ResetData() { HALSIM_ResetAnalogGyroData(m_index); }

View File

@@ -0,0 +1,182 @@
/*----------------------------------------------------------------------------*/
/* 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/AnalogInputSim.h"
#include <memory>
#include <utility>
#include <hal/simulation/AnalogInData.h>
#include "frc/AnalogInput.h"
using namespace frc;
using namespace frc::sim;
AnalogInputSim::AnalogInputSim(const AnalogInput& analogInput)
: m_index{analogInput.GetChannel()} {}
AnalogInputSim::AnalogInputSim(int channel) : m_index{channel} {}
std::unique_ptr<CallbackStore> AnalogInputSim::RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogInInitializedCallback);
store->SetUid(HALSIM_RegisterAnalogInInitializedCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool AnalogInputSim::GetInitialized() const {
return HALSIM_GetAnalogInInitialized(m_index);
}
void AnalogInputSim::SetInitialized(bool initialized) {
HALSIM_SetAnalogInInitialized(m_index, initialized);
}
std::unique_ptr<CallbackStore> AnalogInputSim::RegisterAverageBitsCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogInAverageBitsCallback);
store->SetUid(HALSIM_RegisterAnalogInAverageBitsCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
int AnalogInputSim::GetAverageBits() const {
return HALSIM_GetAnalogInAverageBits(m_index);
}
void AnalogInputSim::SetAverageBits(int averageBits) {
HALSIM_SetAnalogInAverageBits(m_index, averageBits);
}
std::unique_ptr<CallbackStore> AnalogInputSim::RegisterOversampleBitsCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogInOversampleBitsCallback);
store->SetUid(HALSIM_RegisterAnalogInOversampleBitsCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
int AnalogInputSim::GetOversampleBits() const {
return HALSIM_GetAnalogInOversampleBits(m_index);
}
void AnalogInputSim::SetOversampleBits(int oversampleBits) {
HALSIM_SetAnalogInOversampleBits(m_index, oversampleBits);
}
std::unique_ptr<CallbackStore> AnalogInputSim::RegisterVoltageCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogInVoltageCallback);
store->SetUid(HALSIM_RegisterAnalogInVoltageCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double AnalogInputSim::GetVoltage() const {
return HALSIM_GetAnalogInVoltage(m_index);
}
void AnalogInputSim::SetVoltage(double voltage) {
HALSIM_SetAnalogInVoltage(m_index, voltage);
}
std::unique_ptr<CallbackStore>
AnalogInputSim::RegisterAccumulatorInitializedCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback,
&HALSIM_CancelAnalogInAccumulatorInitializedCallback);
store->SetUid(HALSIM_RegisterAnalogInAccumulatorInitializedCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool AnalogInputSim::GetAccumulatorInitialized() const {
return HALSIM_GetAnalogInAccumulatorInitialized(m_index);
}
void AnalogInputSim::SetAccumulatorInitialized(bool accumulatorInitialized) {
HALSIM_SetAnalogInAccumulatorInitialized(m_index, accumulatorInitialized);
}
std::unique_ptr<CallbackStore> AnalogInputSim::RegisterAccumulatorValueCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogInAccumulatorValueCallback);
store->SetUid(HALSIM_RegisterAnalogInAccumulatorValueCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
int64_t AnalogInputSim::GetAccumulatorValue() const {
return HALSIM_GetAnalogInAccumulatorValue(m_index);
}
void AnalogInputSim::SetAccumulatorValue(int64_t accumulatorValue) {
HALSIM_SetAnalogInAccumulatorValue(m_index, accumulatorValue);
}
std::unique_ptr<CallbackStore> AnalogInputSim::RegisterAccumulatorCountCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogInAccumulatorCountCallback);
store->SetUid(HALSIM_RegisterAnalogInAccumulatorCountCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
int64_t AnalogInputSim::GetAccumulatorCount() const {
return HALSIM_GetAnalogInAccumulatorCount(m_index);
}
void AnalogInputSim::SetAccumulatorCount(int64_t accumulatorCount) {
HALSIM_SetAnalogInAccumulatorCount(m_index, accumulatorCount);
}
std::unique_ptr<CallbackStore>
AnalogInputSim::RegisterAccumulatorCenterCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogInAccumulatorCenterCallback);
store->SetUid(HALSIM_RegisterAnalogInAccumulatorCenterCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
int AnalogInputSim::GetAccumulatorCenter() const {
return HALSIM_GetAnalogInAccumulatorCenter(m_index);
}
void AnalogInputSim::SetAccumulatorCenter(int accumulatorCenter) {
HALSIM_SetAnalogInAccumulatorCenter(m_index, accumulatorCenter);
}
std::unique_ptr<CallbackStore>
AnalogInputSim::RegisterAccumulatorDeadbandCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogInAccumulatorDeadbandCallback);
store->SetUid(HALSIM_RegisterAnalogInAccumulatorDeadbandCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
int AnalogInputSim::GetAccumulatorDeadband() const {
return HALSIM_GetAnalogInAccumulatorDeadband(m_index);
}
void AnalogInputSim::SetAccumulatorDeadband(int accumulatorDeadband) {
HALSIM_SetAnalogInAccumulatorDeadband(m_index, accumulatorDeadband);
}
void AnalogInputSim::ResetData() { HALSIM_ResetAnalogInData(m_index); }

View File

@@ -0,0 +1,59 @@
/*----------------------------------------------------------------------------*/
/* 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/AnalogOutputSim.h"
#include <memory>
#include <utility>
#include <hal/simulation/AnalogOutData.h>
#include "frc/AnalogOutput.h"
using namespace frc;
using namespace frc::sim;
AnalogOutputSim::AnalogOutputSim(const AnalogOutput& analogOutput)
: m_index{analogOutput.GetChannel()} {}
AnalogOutputSim::AnalogOutputSim(int channel) : m_index{channel} {}
std::unique_ptr<CallbackStore> AnalogOutputSim::RegisterVoltageCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogOutVoltageCallback);
store->SetUid(HALSIM_RegisterAnalogOutVoltageCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double AnalogOutputSim::GetVoltage() const {
return HALSIM_GetAnalogOutVoltage(m_index);
}
void AnalogOutputSim::SetVoltage(double voltage) {
HALSIM_SetAnalogOutVoltage(m_index, voltage);
}
std::unique_ptr<CallbackStore> AnalogOutputSim::RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogOutInitializedCallback);
store->SetUid(HALSIM_RegisterAnalogOutInitializedCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool AnalogOutputSim::GetInitialized() const {
return HALSIM_GetAnalogOutInitialized(m_index);
}
void AnalogOutputSim::SetInitialized(bool initialized) {
HALSIM_SetAnalogOutInitialized(m_index, initialized);
}
void AnalogOutputSim::ResetData() { HALSIM_ResetAnalogOutData(m_index); }

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

View File

@@ -0,0 +1,112 @@
/*----------------------------------------------------------------------------*/
/* 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/BuiltInAccelerometerSim.h"
#include <memory>
#include <utility>
#include <hal/simulation/AccelerometerData.h>
#include "frc/BuiltInAccelerometer.h"
using namespace frc;
using namespace frc::sim;
BuiltInAccelerometerSim::BuiltInAccelerometerSim() : m_index{0} {}
BuiltInAccelerometerSim::BuiltInAccelerometerSim(const BuiltInAccelerometer&)
: m_index{0} {}
std::unique_ptr<CallbackStore> BuiltInAccelerometerSim::RegisterActiveCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAccelerometerActiveCallback);
store->SetUid(HALSIM_RegisterAccelerometerActiveCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool BuiltInAccelerometerSim::GetActive() const {
return HALSIM_GetAccelerometerActive(m_index);
}
void BuiltInAccelerometerSim::SetActive(bool active) {
HALSIM_SetAccelerometerActive(m_index, active);
}
std::unique_ptr<CallbackStore> BuiltInAccelerometerSim::RegisterRangeCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAccelerometerRangeCallback);
store->SetUid(HALSIM_RegisterAccelerometerRangeCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
HAL_AccelerometerRange BuiltInAccelerometerSim::GetRange() const {
return HALSIM_GetAccelerometerRange(m_index);
}
void BuiltInAccelerometerSim::SetRange(HAL_AccelerometerRange range) {
HALSIM_SetAccelerometerRange(m_index, range);
}
std::unique_ptr<CallbackStore> BuiltInAccelerometerSim::RegisterXCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAccelerometerXCallback);
store->SetUid(HALSIM_RegisterAccelerometerXCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double BuiltInAccelerometerSim::GetX() const {
return HALSIM_GetAccelerometerX(m_index);
}
void BuiltInAccelerometerSim::SetX(double x) {
HALSIM_SetAccelerometerX(m_index, x);
}
std::unique_ptr<CallbackStore> BuiltInAccelerometerSim::RegisterYCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAccelerometerYCallback);
store->SetUid(HALSIM_RegisterAccelerometerYCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double BuiltInAccelerometerSim::GetY() const {
return HALSIM_GetAccelerometerY(m_index);
}
void BuiltInAccelerometerSim::SetY(double y) {
HALSIM_SetAccelerometerY(m_index, y);
}
std::unique_ptr<CallbackStore> BuiltInAccelerometerSim::RegisterZCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAccelerometerZCallback);
store->SetUid(HALSIM_RegisterAccelerometerZCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double BuiltInAccelerometerSim::GetZ() const {
return HALSIM_GetAccelerometerZ(m_index);
}
void BuiltInAccelerometerSim::SetZ(double z) {
HALSIM_SetAccelerometerZ(m_index, z);
}
void BuiltInAccelerometerSim::ResetData() {
HALSIM_ResetAccelerometerData(m_index);
}

View File

@@ -7,6 +7,9 @@
#include "frc/simulation/CallbackStore.h"
using namespace frc;
using namespace frc::sim;
void frc::sim::CallbackStoreThunk(const char* name, void* param,
const HAL_Value* value) {
reinterpret_cast<CallbackStore*>(param)->callback(name, value);
@@ -18,3 +21,60 @@ void frc::sim::ConstBufferCallbackStoreThunk(const char* name, void* param,
reinterpret_cast<CallbackStore*>(param)->constBufferCallback(name, buffer,
count);
}
CallbackStore::CallbackStore(int32_t i, NotifyCallback cb,
CancelCallbackNoIndexFunc ccf)
: index(i), callback(cb), cancelType(NoIndex) {
this->ccnif = ccf;
}
CallbackStore::CallbackStore(int32_t i, int32_t u, NotifyCallback cb,
CancelCallbackFunc ccf)
: index(i), uid(u), callback(cb), cancelType(Normal) {
this->ccf = ccf;
}
CallbackStore::CallbackStore(int32_t i, int32_t c, int32_t u, NotifyCallback cb,
CancelCallbackChannelFunc ccf)
: index(i), channel(c), uid(u), callback(cb), cancelType(Channel) {
this->cccf = ccf;
}
CallbackStore::CallbackStore(int32_t i, ConstBufferCallback cb,
CancelCallbackNoIndexFunc ccf)
: index(i), constBufferCallback(cb), cancelType(NoIndex) {
this->ccnif = ccf;
}
CallbackStore::CallbackStore(int32_t i, int32_t u, ConstBufferCallback cb,
CancelCallbackFunc ccf)
: index(i), uid(u), constBufferCallback(cb), cancelType(Normal) {
this->ccf = ccf;
}
CallbackStore::CallbackStore(int32_t i, int32_t c, int32_t u,
ConstBufferCallback cb,
CancelCallbackChannelFunc ccf)
: index(i),
channel(c),
uid(u),
constBufferCallback(cb),
cancelType(Channel) {
this->cccf = ccf;
}
CallbackStore::~CallbackStore() {
switch (cancelType) {
case Normal:
ccf(index, uid);
break;
case Channel:
cccf(index, channel, uid);
break;
case NoIndex:
ccnif(uid);
break;
}
}
void CallbackStore::SetUid(int32_t uid) { this->uid = uid; }

View File

@@ -0,0 +1,104 @@
/*----------------------------------------------------------------------------*/
/* 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/DIOSim.h"
#include <memory>
#include <utility>
#include <hal/simulation/DIOData.h>
#include "frc/DigitalInput.h"
#include "frc/DigitalOutput.h"
using namespace frc;
using namespace frc::sim;
DIOSim::DIOSim(const DigitalInput& input) : m_index{input.GetChannel()} {}
DIOSim::DIOSim(const DigitalOutput& output) : m_index{output.GetChannel()} {}
DIOSim::DIOSim(int channel) : m_index{channel} {}
std::unique_ptr<CallbackStore> DIOSim::RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelDIOInitializedCallback);
store->SetUid(HALSIM_RegisterDIOInitializedCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool DIOSim::GetInitialized() const {
return HALSIM_GetDIOInitialized(m_index);
}
void DIOSim::SetInitialized(bool initialized) {
HALSIM_SetDIOInitialized(m_index, initialized);
}
std::unique_ptr<CallbackStore> DIOSim::RegisterValueCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(m_index, -1, callback,
&HALSIM_CancelDIOValueCallback);
store->SetUid(HALSIM_RegisterDIOValueCallback(m_index, &CallbackStoreThunk,
store.get(), initialNotify));
return store;
}
bool DIOSim::GetValue() const { return HALSIM_GetDIOValue(m_index); }
void DIOSim::SetValue(bool value) { HALSIM_SetDIOValue(m_index, value); }
std::unique_ptr<CallbackStore> DIOSim::RegisterPulseLengthCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelDIOPulseLengthCallback);
store->SetUid(HALSIM_RegisterDIOPulseLengthCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double DIOSim::GetPulseLength() const {
return HALSIM_GetDIOPulseLength(m_index);
}
void DIOSim::SetPulseLength(double pulseLength) {
HALSIM_SetDIOPulseLength(m_index, pulseLength);
}
std::unique_ptr<CallbackStore> DIOSim::RegisterIsInputCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelDIOIsInputCallback);
store->SetUid(HALSIM_RegisterDIOIsInputCallback(m_index, &CallbackStoreThunk,
store.get(), initialNotify));
return store;
}
bool DIOSim::GetIsInput() const { return HALSIM_GetDIOIsInput(m_index); }
void DIOSim::SetIsInput(bool isInput) {
HALSIM_SetDIOIsInput(m_index, isInput);
}
std::unique_ptr<CallbackStore> DIOSim::RegisterFilterIndexCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelDIOFilterIndexCallback);
store->SetUid(HALSIM_RegisterDIOFilterIndexCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
int DIOSim::GetFilterIndex() const { return HALSIM_GetDIOFilterIndex(m_index); }
void DIOSim::SetFilterIndex(int filterIndex) {
HALSIM_SetDIOFilterIndex(m_index, filterIndex);
}
void DIOSim::ResetData() { HALSIM_ResetDIOData(m_index); }

View File

@@ -0,0 +1,81 @@
/*----------------------------------------------------------------------------*/
/* 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/DigitalPWMSim.h"
#include <memory>
#include <stdexcept>
#include <utility>
#include <hal/simulation/DigitalPWMData.h>
#include "frc/DigitalOutput.h"
using namespace frc;
using namespace frc::sim;
DigitalPWMSim::DigitalPWMSim(const DigitalOutput& digitalOutput)
: m_index{digitalOutput.GetChannel()} {}
DigitalPWMSim DigitalPWMSim::CreateForChannel(int channel) {
int index = HALSIM_FindDigitalPWMForChannel(channel);
if (index < 0) throw std::out_of_range("no digital PWM found for channel");
return DigitalPWMSim{index};
}
DigitalPWMSim DigitalPWMSim::CreateForIndex(int index) {
return DigitalPWMSim{index};
}
std::unique_ptr<CallbackStore> DigitalPWMSim::RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelDigitalPWMInitializedCallback);
store->SetUid(HALSIM_RegisterDigitalPWMInitializedCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool DigitalPWMSim::GetInitialized() const {
return HALSIM_GetDigitalPWMInitialized(m_index);
}
void DigitalPWMSim::SetInitialized(bool initialized) {
HALSIM_SetDigitalPWMInitialized(m_index, initialized);
}
std::unique_ptr<CallbackStore> DigitalPWMSim::RegisterDutyCycleCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelDigitalPWMDutyCycleCallback);
store->SetUid(HALSIM_RegisterDigitalPWMDutyCycleCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double DigitalPWMSim::GetDutyCycle() const {
return HALSIM_GetDigitalPWMDutyCycle(m_index);
}
void DigitalPWMSim::SetDutyCycle(double dutyCycle) {
HALSIM_SetDigitalPWMDutyCycle(m_index, dutyCycle);
}
std::unique_ptr<CallbackStore> DigitalPWMSim::RegisterPinCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelDigitalPWMPinCallback);
store->SetUid(HALSIM_RegisterDigitalPWMPinCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
int DigitalPWMSim::GetPin() const { return HALSIM_GetDigitalPWMPin(m_index); }
void DigitalPWMSim::SetPin(int pin) { HALSIM_SetDigitalPWMPin(m_index, pin); }
void DigitalPWMSim::ResetData() { HALSIM_ResetDigitalPWMData(m_index); }

View File

@@ -0,0 +1,255 @@
/*----------------------------------------------------------------------------*/
/* 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/DriverStationSim.h"
#include <memory>
#include <utility>
#include <hal/simulation/DriverStationData.h>
#include <hal/simulation/MockHooks.h>
#include "frc/DriverStation.h"
using namespace frc;
using namespace frc::sim;
std::unique_ptr<CallbackStore> DriverStationSim::RegisterEnabledCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelDriverStationEnabledCallback);
store->SetUid(HALSIM_RegisterDriverStationEnabledCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool DriverStationSim::GetEnabled() { return HALSIM_GetDriverStationEnabled(); }
void DriverStationSim::SetEnabled(bool enabled) {
HALSIM_SetDriverStationEnabled(enabled);
}
std::unique_ptr<CallbackStore> DriverStationSim::RegisterAutonomousCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelDriverStationAutonomousCallback);
store->SetUid(HALSIM_RegisterDriverStationAutonomousCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool DriverStationSim::GetAutonomous() {
return HALSIM_GetDriverStationAutonomous();
}
void DriverStationSim::SetAutonomous(bool autonomous) {
HALSIM_SetDriverStationAutonomous(autonomous);
}
std::unique_ptr<CallbackStore> DriverStationSim::RegisterTestCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelDriverStationTestCallback);
store->SetUid(HALSIM_RegisterDriverStationTestCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool DriverStationSim::GetTest() { return HALSIM_GetDriverStationTest(); }
void DriverStationSim::SetTest(bool test) { HALSIM_SetDriverStationTest(test); }
std::unique_ptr<CallbackStore> DriverStationSim::RegisterEStopCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelDriverStationEStopCallback);
store->SetUid(HALSIM_RegisterDriverStationEStopCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool DriverStationSim::GetEStop() { return HALSIM_GetDriverStationEStop(); }
void DriverStationSim::SetEStop(bool eStop) {
HALSIM_SetDriverStationEStop(eStop);
}
std::unique_ptr<CallbackStore> DriverStationSim::RegisterFmsAttachedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelDriverStationFmsAttachedCallback);
store->SetUid(HALSIM_RegisterDriverStationFmsAttachedCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool DriverStationSim::GetFmsAttached() {
return HALSIM_GetDriverStationFmsAttached();
}
void DriverStationSim::SetFmsAttached(bool fmsAttached) {
HALSIM_SetDriverStationFmsAttached(fmsAttached);
}
std::unique_ptr<CallbackStore> DriverStationSim::RegisterDsAttachedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelDriverStationDsAttachedCallback);
store->SetUid(HALSIM_RegisterDriverStationDsAttachedCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool DriverStationSim::GetDsAttached() {
return HALSIM_GetDriverStationDsAttached();
}
void DriverStationSim::SetDsAttached(bool dsAttached) {
HALSIM_SetDriverStationDsAttached(dsAttached);
}
std::unique_ptr<CallbackStore>
DriverStationSim::RegisterAllianceStationIdCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelDriverStationAllianceStationIdCallback);
store->SetUid(HALSIM_RegisterDriverStationAllianceStationIdCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
HAL_AllianceStationID DriverStationSim::GetAllianceStationId() {
return HALSIM_GetDriverStationAllianceStationId();
}
void DriverStationSim::SetAllianceStationId(
HAL_AllianceStationID allianceStationId) {
HALSIM_SetDriverStationAllianceStationId(allianceStationId);
}
std::unique_ptr<CallbackStore> DriverStationSim::RegisterMatchTimeCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelDriverStationMatchTimeCallback);
store->SetUid(HALSIM_RegisterDriverStationMatchTimeCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double DriverStationSim::GetMatchTime() {
return HALSIM_GetDriverStationMatchTime();
}
void DriverStationSim::SetMatchTime(double matchTime) {
HALSIM_SetDriverStationMatchTime(matchTime);
}
void DriverStationSim::NotifyNewData() {
HALSIM_NotifyDriverStationNewData();
DriverStation::GetInstance().WaitForData();
}
void DriverStationSim::SetSendError(bool shouldSend) {
if (shouldSend) {
HALSIM_SetSendError(nullptr);
} else {
HALSIM_SetSendError([](HAL_Bool isError, int32_t errorCode,
HAL_Bool isLVCode, const char* details,
const char* location, const char* callStack,
HAL_Bool printMsg) { return 0; });
}
}
void DriverStationSim::SetSendConsoleLine(bool shouldSend) {
if (shouldSend) {
HALSIM_SetSendConsoleLine(nullptr);
} else {
HALSIM_SetSendConsoleLine([](const char* line) { return 0; });
}
}
int64_t DriverStationSim::GetJoystickOutputs(int stick) {
int64_t outputs = 0;
int32_t leftRumble;
int32_t rightRumble;
HALSIM_GetJoystickOutputs(stick, &outputs, &leftRumble, &rightRumble);
return outputs;
}
int DriverStationSim::GetJoystickRumble(int stick, int rumbleNum) {
int64_t outputs;
int32_t leftRumble = 0;
int32_t rightRumble = 0;
HALSIM_GetJoystickOutputs(stick, &outputs, &leftRumble, &rightRumble);
return rumbleNum == 0 ? leftRumble : rightRumble;
}
void DriverStationSim::SetJoystickButton(int stick, int button, bool state) {
HALSIM_SetJoystickButton(stick, button, state);
}
void DriverStationSim::SetJoystickAxis(int stick, int axis, double value) {
HALSIM_SetJoystickAxis(stick, axis, value);
}
void DriverStationSim::SetJoystickPOV(int stick, int pov, int value) {
HALSIM_SetJoystickPOV(stick, pov, value);
}
void DriverStationSim::SetJoystickButtons(int stick, uint32_t buttons) {
HALSIM_SetJoystickButtonsValue(stick, buttons);
}
void DriverStationSim::SetJoystickAxisCount(int stick, int count) {
HALSIM_SetJoystickAxisCount(stick, count);
}
void DriverStationSim::SetJoystickPOVCount(int stick, int count) {
HALSIM_SetJoystickPOVCount(stick, count);
}
void DriverStationSim::SetJoystickButtonCount(int stick, int count) {
HALSIM_SetJoystickButtonCount(stick, count);
}
void DriverStationSim::SetJoystickIsXbox(int stick, bool isXbox) {
HALSIM_SetJoystickIsXbox(stick, isXbox);
}
void DriverStationSim::SetJoystickType(int stick, int type) {
HALSIM_SetJoystickType(stick, type);
}
void DriverStationSim::SetJoystickName(int stick, const char* name) {
HALSIM_SetJoystickName(stick, name);
}
void DriverStationSim::SetJoystickAxisType(int stick, int axis, int type) {
HALSIM_SetJoystickAxisType(stick, axis, type);
}
void DriverStationSim::SetGameSpecificMessage(const char* message) {
HALSIM_SetGameSpecificMessage(message);
}
void DriverStationSim::SetEventName(const char* name) {
HALSIM_SetEventName(name);
}
void DriverStationSim::SetMatchType(DriverStation::MatchType type) {
HALSIM_SetMatchType(static_cast<HAL_MatchType>(static_cast<int>(type)));
}
void DriverStationSim::SetMatchNumber(int matchNumber) {
HALSIM_SetMatchNumber(matchNumber);
}
void DriverStationSim::SetReplayNumber(int replayNumber) {
HALSIM_SetReplayNumber(replayNumber);
}
void DriverStationSim::ResetData() { HALSIM_ResetDriverStationData(); }

View File

@@ -0,0 +1,85 @@
/*----------------------------------------------------------------------------*/
/* 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. */
/*----------------------------------------------------------------------------*/
#include "frc/simulation/DutyCycleSim.h"
#include <memory>
#include <stdexcept>
#include <utility>
#include <hal/simulation/DutyCycleData.h>
#include "frc/DutyCycle.h"
using namespace frc;
using namespace frc::sim;
DutyCycleSim::DutyCycleSim(const DutyCycle& dutyCycle)
: m_index{dutyCycle.GetFPGAIndex()} {}
DutyCycleSim DutyCycleSim::CreateForChannel(int channel) {
int index = HALSIM_FindDutyCycleForChannel(channel);
if (index < 0) throw std::out_of_range("no duty cycle found for channel");
return DutyCycleSim{index};
}
DutyCycleSim DutyCycleSim::CreateForIndex(int index) {
return DutyCycleSim{index};
}
std::unique_ptr<CallbackStore> DutyCycleSim::RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelDutyCycleInitializedCallback);
store->SetUid(HALSIM_RegisterDutyCycleInitializedCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool DutyCycleSim::GetInitialized() const {
return HALSIM_GetDutyCycleInitialized(m_index);
}
void DutyCycleSim::SetInitialized(bool initialized) {
HALSIM_SetDutyCycleInitialized(m_index, initialized);
}
std::unique_ptr<CallbackStore> DutyCycleSim::RegisterFrequencyCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelDutyCycleFrequencyCallback);
store->SetUid(HALSIM_RegisterDutyCycleFrequencyCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
int DutyCycleSim::GetFrequency() const {
return HALSIM_GetDutyCycleFrequency(m_index);
}
void DutyCycleSim::SetFrequency(int count) {
HALSIM_SetDutyCycleFrequency(m_index, count);
}
std::unique_ptr<CallbackStore> DutyCycleSim::RegisterOutputCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelDutyCycleOutputCallback);
store->SetUid(HALSIM_RegisterDutyCycleOutputCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double DutyCycleSim::GetOutput() const {
return HALSIM_GetDutyCycleOutput(m_index);
}
void DutyCycleSim::SetOutput(double period) {
HALSIM_SetDutyCycleOutput(m_index, period);
}
void DutyCycleSim::ResetData() { HALSIM_ResetDutyCycleData(m_index); }

View File

@@ -0,0 +1,189 @@
/*----------------------------------------------------------------------------*/
/* 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/EncoderSim.h"
#include <memory>
#include <stdexcept>
#include <utility>
#include <hal/simulation/EncoderData.h>
#include "frc/Encoder.h"
using namespace frc;
using namespace frc::sim;
EncoderSim::EncoderSim(const Encoder& encoder)
: m_index{encoder.GetFPGAIndex()} {}
EncoderSim 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};
}
EncoderSim EncoderSim::CreateForIndex(int index) { return EncoderSim{index}; }
std::unique_ptr<CallbackStore> EncoderSim::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;
}
bool EncoderSim::GetInitialized() const {
return HALSIM_GetEncoderInitialized(m_index);
}
void EncoderSim::SetInitialized(bool initialized) {
HALSIM_SetEncoderInitialized(m_index, initialized);
}
std::unique_ptr<CallbackStore> EncoderSim::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;
}
int EncoderSim::GetCount() const { return HALSIM_GetEncoderCount(m_index); }
void EncoderSim::SetCount(int count) { HALSIM_SetEncoderCount(m_index, count); }
std::unique_ptr<CallbackStore> EncoderSim::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;
}
double EncoderSim::GetPeriod() const {
return HALSIM_GetEncoderPeriod(m_index);
}
void EncoderSim::SetPeriod(double period) {
HALSIM_SetEncoderPeriod(m_index, period);
}
std::unique_ptr<CallbackStore> EncoderSim::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 EncoderSim::GetReset() const { return HALSIM_GetEncoderReset(m_index); }
void EncoderSim::SetReset(bool reset) {
HALSIM_SetEncoderReset(m_index, reset);
}
std::unique_ptr<CallbackStore> EncoderSim::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;
}
double EncoderSim::GetMaxPeriod() const {
return HALSIM_GetEncoderMaxPeriod(m_index);
}
void EncoderSim::SetMaxPeriod(double maxPeriod) {
HALSIM_SetEncoderMaxPeriod(m_index, maxPeriod);
}
std::unique_ptr<CallbackStore> EncoderSim::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;
}
bool EncoderSim::GetDirection() const {
return HALSIM_GetEncoderDirection(m_index);
}
void EncoderSim::SetDirection(bool direction) {
HALSIM_SetEncoderDirection(m_index, direction);
}
std::unique_ptr<CallbackStore> EncoderSim::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;
}
bool EncoderSim::GetReverseDirection() const {
return HALSIM_GetEncoderReverseDirection(m_index);
}
void EncoderSim::SetReverseDirection(bool reverseDirection) {
HALSIM_SetEncoderReverseDirection(m_index, reverseDirection);
}
std::unique_ptr<CallbackStore> EncoderSim::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;
}
int EncoderSim::GetSamplesToAverage() const {
return HALSIM_GetEncoderSamplesToAverage(m_index);
}
void EncoderSim::SetSamplesToAverage(int samplesToAverage) {
HALSIM_SetEncoderSamplesToAverage(m_index, samplesToAverage);
}
std::unique_ptr<CallbackStore> EncoderSim::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;
}
double EncoderSim::GetDistancePerPulse() const {
return HALSIM_GetEncoderDistancePerPulse(m_index);
}
void EncoderSim::SetDistancePerPulse(double distancePerPulse) {
HALSIM_SetEncoderDistancePerPulse(m_index, distancePerPulse);
}
void EncoderSim::ResetData() { HALSIM_ResetEncoderData(m_index); }
void EncoderSim::SetDistance(double distance) {
HALSIM_SetEncoderDistance(m_index, distance);
}
double EncoderSim::GetDistance() { return HALSIM_GetEncoderDistance(m_index); }
void EncoderSim::SetRate(double rate) { HALSIM_SetEncoderRate(m_index, rate); }
double EncoderSim::GetRate() { return HALSIM_GetEncoderRate(m_index); }

View File

@@ -0,0 +1,74 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 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/GenericHIDSim.h"
#include "frc/GenericHID.h"
#include "frc/simulation/DriverStationSim.h"
using namespace frc;
using namespace frc::sim;
GenericHIDSim::GenericHIDSim(const GenericHID& joystick)
: m_port{joystick.GetPort()} {}
GenericHIDSim::GenericHIDSim(int port) : m_port{port} {}
void GenericHIDSim::NotifyNewData() { DriverStationSim::NotifyNewData(); }
void GenericHIDSim::SetRawButton(int button, bool value) {
DriverStationSim::SetJoystickButton(m_port, button, value);
}
void GenericHIDSim::SetRawAxis(int axis, double value) {
DriverStationSim::SetJoystickAxis(m_port, axis, value);
}
void GenericHIDSim::SetPOV(int pov, int value) {
DriverStationSim::SetJoystickPOV(m_port, pov, value);
}
void GenericHIDSim::SetPOV(int value) { SetPOV(0, value); }
void GenericHIDSim::SetAxisCount(int count) {
DriverStationSim::SetJoystickAxisCount(m_port, count);
}
void GenericHIDSim::SetPOVCount(int count) {
DriverStationSim::SetJoystickPOVCount(m_port, count);
}
void GenericHIDSim::SetButtonCount(int count) {
DriverStationSim::SetJoystickButtonCount(m_port, count);
}
void GenericHIDSim::SetType(GenericHID::HIDType type) {
DriverStationSim::SetJoystickType(m_port, type);
}
void GenericHIDSim::SetName(const char* name) {
DriverStationSim::SetJoystickName(m_port, name);
}
void GenericHIDSim::SetAxisType(int axis, int type) {
DriverStationSim::SetJoystickAxisType(m_port, axis, type);
}
bool GenericHIDSim::GetOutput(int outputNumber) {
int64_t outputs = GetOutputs();
return (outputs & (static_cast<int64_t>(1) << (outputNumber - 1))) != 0;
}
int64_t GenericHIDSim::GetOutputs() {
return DriverStationSim::GetJoystickOutputs(m_port);
}
double GenericHIDSim::GetRumble(GenericHID::RumbleType type) {
int value = DriverStationSim::GetJoystickRumble(
m_port, type == GenericHID::kLeftRumble ? 0 : 1);
return value / 65535.0;
}

View File

@@ -0,0 +1,63 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 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/JoystickSim.h"
#include "frc/Joystick.h"
#include "frc/simulation/GenericHIDSim.h"
using namespace frc;
using namespace frc::sim;
JoystickSim::JoystickSim(const Joystick& joystick)
: GenericHIDSim{joystick}, m_joystick{&joystick} {
// default to a reasonable joystick configuration
SetAxisCount(5);
SetButtonCount(12);
SetPOVCount(1);
}
JoystickSim::JoystickSim(int port) : GenericHIDSim{port} {
// default to a reasonable joystick configuration
SetAxisCount(5);
SetButtonCount(12);
SetPOVCount(1);
}
void JoystickSim::SetX(double value) {
SetRawAxis(
m_joystick ? m_joystick->GetXChannel() : Joystick::kDefaultXChannel,
value);
}
void JoystickSim::SetY(double value) {
SetRawAxis(
m_joystick ? m_joystick->GetYChannel() : Joystick::kDefaultYChannel,
value);
}
void JoystickSim::SetZ(double value) {
SetRawAxis(
m_joystick ? m_joystick->GetZChannel() : Joystick::kDefaultZChannel,
value);
}
void JoystickSim::SetTwist(double value) {
SetRawAxis(m_joystick ? m_joystick->GetTwistChannel()
: Joystick::kDefaultTwistChannel,
value);
}
void JoystickSim::SetThrottle(double value) {
SetRawAxis(m_joystick ? m_joystick->GetThrottleChannel()
: Joystick::kDefaultThrottleChannel,
value);
}
void JoystickSim::SetTrigger(bool state) { SetRawButton(1, state); }
void JoystickSim::SetTop(bool state) { SetRawButton(2, state); }

View File

@@ -0,0 +1,158 @@
/*----------------------------------------------------------------------------*/
/* 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/PCMSim.h"
#include <memory>
#include <utility>
#include <hal/simulation/PCMData.h>
#include "frc/Compressor.h"
#include "frc/SensorUtil.h"
using namespace frc;
using namespace frc::sim;
PCMSim::PCMSim() : m_index{SensorUtil::GetDefaultSolenoidModule()} {}
PCMSim::PCMSim(int module) : m_index{module} {}
PCMSim::PCMSim(const Compressor& compressor)
: m_index{compressor.GetModule()} {}
std::unique_ptr<CallbackStore> PCMSim::RegisterSolenoidInitializedCallback(
int channel, NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, channel, -1, callback,
&HALSIM_CancelPCMSolenoidInitializedCallback);
store->SetUid(HALSIM_RegisterPCMSolenoidInitializedCallback(
m_index, channel, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool PCMSim::GetSolenoidInitialized(int channel) const {
return HALSIM_GetPCMSolenoidInitialized(m_index, channel);
}
void PCMSim::SetSolenoidInitialized(int channel, bool solenoidInitialized) {
HALSIM_SetPCMSolenoidInitialized(m_index, channel, solenoidInitialized);
}
std::unique_ptr<CallbackStore> PCMSim::RegisterSolenoidOutputCallback(
int channel, NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, channel, -1, callback, &HALSIM_CancelPCMSolenoidOutputCallback);
store->SetUid(HALSIM_RegisterPCMSolenoidOutputCallback(
m_index, channel, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool PCMSim::GetSolenoidOutput(int channel) const {
return HALSIM_GetPCMSolenoidOutput(m_index, channel);
}
void PCMSim::SetSolenoidOutput(int channel, bool solenoidOutput) {
HALSIM_SetPCMSolenoidOutput(m_index, channel, solenoidOutput);
}
std::unique_ptr<CallbackStore> PCMSim::RegisterCompressorInitializedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPCMCompressorInitializedCallback);
store->SetUid(HALSIM_RegisterPCMCompressorInitializedCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool PCMSim::GetCompressorInitialized() const {
return HALSIM_GetPCMCompressorInitialized(m_index);
}
void PCMSim::SetCompressorInitialized(bool compressorInitialized) {
HALSIM_SetPCMCompressorInitialized(m_index, compressorInitialized);
}
std::unique_ptr<CallbackStore> PCMSim::RegisterCompressorOnCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPCMCompressorOnCallback);
store->SetUid(HALSIM_RegisterPCMCompressorOnCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool PCMSim::GetCompressorOn() const {
return HALSIM_GetPCMCompressorOn(m_index);
}
void PCMSim::SetCompressorOn(bool compressorOn) {
HALSIM_SetPCMCompressorOn(m_index, compressorOn);
}
std::unique_ptr<CallbackStore> PCMSim::RegisterClosedLoopEnabledCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPCMClosedLoopEnabledCallback);
store->SetUid(HALSIM_RegisterPCMClosedLoopEnabledCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool PCMSim::GetClosedLoopEnabled() const {
return HALSIM_GetPCMClosedLoopEnabled(m_index);
}
void PCMSim::SetClosedLoopEnabled(bool closedLoopEnabled) {
HALSIM_SetPCMClosedLoopEnabled(m_index, closedLoopEnabled);
}
std::unique_ptr<CallbackStore> PCMSim::RegisterPressureSwitchCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPCMPressureSwitchCallback);
store->SetUid(HALSIM_RegisterPCMPressureSwitchCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool PCMSim::GetPressureSwitch() const {
return HALSIM_GetPCMPressureSwitch(m_index);
}
void PCMSim::SetPressureSwitch(bool pressureSwitch) {
HALSIM_SetPCMPressureSwitch(m_index, pressureSwitch);
}
std::unique_ptr<CallbackStore> PCMSim::RegisterCompressorCurrentCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPCMCompressorCurrentCallback);
store->SetUid(HALSIM_RegisterPCMCompressorCurrentCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double PCMSim::GetCompressorCurrent() const {
return HALSIM_GetPCMCompressorCurrent(m_index);
}
void PCMSim::SetCompressorCurrent(double compressorCurrent) {
HALSIM_SetPCMCompressorCurrent(m_index, compressorCurrent);
}
uint8_t PCMSim::GetAllSolenoidOutputs() const {
uint8_t ret = 0;
HALSIM_GetPCMAllSolenoids(m_index, &ret);
return ret;
}
void PCMSim::SetAllSolenoidOutputs(uint8_t outputs) {
HALSIM_SetPCMAllSolenoids(m_index, outputs);
}
void PCMSim::ResetData() { HALSIM_ResetPCMData(m_index); }

View File

@@ -0,0 +1,98 @@
/*----------------------------------------------------------------------------*/
/* 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/PDPSim.h"
#include <memory>
#include <utility>
#include <hal/simulation/PDPData.h>
#include "frc/PowerDistributionPanel.h"
using namespace frc;
using namespace frc::sim;
PDPSim::PDPSim(int module) : m_index{module} {}
PDPSim::PDPSim(const PowerDistributionPanel& pdp) : m_index{pdp.GetModule()} {}
std::unique_ptr<CallbackStore> PDPSim::RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPDPInitializedCallback);
store->SetUid(HALSIM_RegisterPDPInitializedCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool PDPSim::GetInitialized() const {
return HALSIM_GetPDPInitialized(m_index);
}
void PDPSim::SetInitialized(bool initialized) {
HALSIM_SetPDPInitialized(m_index, initialized);
}
std::unique_ptr<CallbackStore> PDPSim::RegisterTemperatureCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPDPTemperatureCallback);
store->SetUid(HALSIM_RegisterPDPTemperatureCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double PDPSim::GetTemperature() const {
return HALSIM_GetPDPTemperature(m_index);
}
void PDPSim::SetTemperature(double temperature) {
HALSIM_SetPDPTemperature(m_index, temperature);
}
std::unique_ptr<CallbackStore> PDPSim::RegisterVoltageCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPDPVoltageCallback);
store->SetUid(HALSIM_RegisterPDPVoltageCallback(m_index, &CallbackStoreThunk,
store.get(), initialNotify));
return store;
}
double PDPSim::GetVoltage() const { return HALSIM_GetPDPVoltage(m_index); }
void PDPSim::SetVoltage(double voltage) {
HALSIM_SetPDPVoltage(m_index, voltage);
}
std::unique_ptr<CallbackStore> PDPSim::RegisterCurrentCallback(
int channel, NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, channel, -1, callback, &HALSIM_CancelPDPCurrentCallback);
store->SetUid(HALSIM_RegisterPDPCurrentCallback(
m_index, channel, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double PDPSim::GetCurrent(int channel) const {
return HALSIM_GetPDPCurrent(m_index, channel);
}
void PDPSim::SetCurrent(int channel, double current) {
HALSIM_SetPDPCurrent(m_index, channel, current);
}
void PDPSim::GetAllCurrents(double* currents) const {
HALSIM_GetPDPAllCurrents(m_index, currents);
}
void PDPSim::SetAllCurrents(const double* currents) {
HALSIM_SetPDPAllCurrents(m_index, currents);
}
void PDPSim::ResetData() { HALSIM_ResetPDPData(m_index); }

View File

@@ -0,0 +1,114 @@
/*----------------------------------------------------------------------------*/
/* 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/PWMSim.h"
#include <memory>
#include <utility>
#include <hal/simulation/PWMData.h>
#include "frc/PWM.h"
using namespace frc;
using namespace frc::sim;
PWMSim::PWMSim(const PWM& pwm) : m_index{pwm.GetChannel()} {}
PWMSim::PWMSim(int channel) : m_index{channel} {}
std::unique_ptr<CallbackStore> PWMSim::RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPWMInitializedCallback);
store->SetUid(HALSIM_RegisterPWMInitializedCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool PWMSim::GetInitialized() const {
return HALSIM_GetPWMInitialized(m_index);
}
void PWMSim::SetInitialized(bool initialized) {
HALSIM_SetPWMInitialized(m_index, initialized);
}
std::unique_ptr<CallbackStore> PWMSim::RegisterRawValueCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPWMRawValueCallback);
store->SetUid(HALSIM_RegisterPWMRawValueCallback(m_index, &CallbackStoreThunk,
store.get(), initialNotify));
return store;
}
int PWMSim::GetRawValue() const { return HALSIM_GetPWMRawValue(m_index); }
void PWMSim::SetRawValue(int rawValue) {
HALSIM_SetPWMRawValue(m_index, rawValue);
}
std::unique_ptr<CallbackStore> PWMSim::RegisterSpeedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(m_index, -1, callback,
&HALSIM_CancelPWMSpeedCallback);
store->SetUid(HALSIM_RegisterPWMSpeedCallback(m_index, &CallbackStoreThunk,
store.get(), initialNotify));
return store;
}
double PWMSim::GetSpeed() const { return HALSIM_GetPWMSpeed(m_index); }
void PWMSim::SetSpeed(double speed) { HALSIM_SetPWMSpeed(m_index, speed); }
std::unique_ptr<CallbackStore> PWMSim::RegisterPositionCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPWMPositionCallback);
store->SetUid(HALSIM_RegisterPWMPositionCallback(m_index, &CallbackStoreThunk,
store.get(), initialNotify));
return store;
}
double PWMSim::GetPosition() const { return HALSIM_GetPWMPosition(m_index); }
void PWMSim::SetPosition(double position) {
HALSIM_SetPWMPosition(m_index, position);
}
std::unique_ptr<CallbackStore> PWMSim::RegisterPeriodScaleCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPWMPeriodScaleCallback);
store->SetUid(HALSIM_RegisterPWMPeriodScaleCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
int PWMSim::GetPeriodScale() const { return HALSIM_GetPWMPeriodScale(m_index); }
void PWMSim::SetPeriodScale(int periodScale) {
HALSIM_SetPWMPeriodScale(m_index, periodScale);
}
std::unique_ptr<CallbackStore> PWMSim::RegisterZeroLatchCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPWMZeroLatchCallback);
store->SetUid(HALSIM_RegisterPWMZeroLatchCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool PWMSim::GetZeroLatch() const { return HALSIM_GetPWMZeroLatch(m_index); }
void PWMSim::SetZeroLatch(bool zeroLatch) {
HALSIM_SetPWMZeroLatch(m_index, zeroLatch);
}
void PWMSim::ResetData() { HALSIM_ResetPWMData(m_index); }

View File

@@ -0,0 +1,88 @@
/*----------------------------------------------------------------------------*/
/* 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/RelaySim.h"
#include <memory>
#include <utility>
#include <hal/simulation/RelayData.h>
#include "frc/Relay.h"
using namespace frc;
using namespace frc::sim;
RelaySim::RelaySim(const Relay& relay) : m_index{relay.GetChannel()} {}
RelaySim::RelaySim(int channel) : m_index{channel} {}
std::unique_ptr<CallbackStore> RelaySim::RegisterInitializedForwardCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelRelayInitializedForwardCallback);
store->SetUid(HALSIM_RegisterRelayInitializedForwardCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool RelaySim::GetInitializedForward() const {
return HALSIM_GetRelayInitializedForward(m_index);
}
void RelaySim::SetInitializedForward(bool initializedForward) {
HALSIM_SetRelayInitializedForward(m_index, initializedForward);
}
std::unique_ptr<CallbackStore> RelaySim::RegisterInitializedReverseCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelRelayInitializedReverseCallback);
store->SetUid(HALSIM_RegisterRelayInitializedReverseCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool RelaySim::GetInitializedReverse() const {
return HALSIM_GetRelayInitializedReverse(m_index);
}
void RelaySim::SetInitializedReverse(bool initializedReverse) {
HALSIM_SetRelayInitializedReverse(m_index, initializedReverse);
}
std::unique_ptr<CallbackStore> RelaySim::RegisterForwardCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelRelayForwardCallback);
store->SetUid(HALSIM_RegisterRelayForwardCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool RelaySim::GetForward() const { return HALSIM_GetRelayForward(m_index); }
void RelaySim::SetForward(bool forward) {
HALSIM_SetRelayForward(m_index, forward);
}
std::unique_ptr<CallbackStore> RelaySim::RegisterReverseCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelRelayReverseCallback);
store->SetUid(HALSIM_RegisterRelayReverseCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool RelaySim::GetReverse() const { return HALSIM_GetRelayReverse(m_index); }
void RelaySim::SetReverse(bool reverse) {
HALSIM_SetRelayReverse(m_index, reverse);
}
void RelaySim::ResetData() { HALSIM_ResetRelayData(m_index); }

View File

@@ -0,0 +1,255 @@
/*----------------------------------------------------------------------------*/
/* 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/RoboRioSim.h"
#include <memory>
#include <utility>
#include <hal/simulation/RoboRioData.h>
using namespace frc;
using namespace frc::sim;
std::unique_ptr<CallbackStore> RoboRioSim::RegisterFPGAButtonCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioFPGAButtonCallback);
store->SetUid(HALSIM_RegisterRoboRioFPGAButtonCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool RoboRioSim::GetFPGAButton() { return HALSIM_GetRoboRioFPGAButton(); }
void RoboRioSim::SetFPGAButton(bool fPGAButton) {
HALSIM_SetRoboRioFPGAButton(fPGAButton);
}
std::unique_ptr<CallbackStore> RoboRioSim::RegisterVInVoltageCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioVInVoltageCallback);
store->SetUid(HALSIM_RegisterRoboRioVInVoltageCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double RoboRioSim::GetVInVoltage() { return HALSIM_GetRoboRioVInVoltage(); }
void RoboRioSim::SetVInVoltage(double vInVoltage) {
HALSIM_SetRoboRioVInVoltage(vInVoltage);
}
std::unique_ptr<CallbackStore> RoboRioSim::RegisterVInCurrentCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioVInCurrentCallback);
store->SetUid(HALSIM_RegisterRoboRioVInCurrentCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double RoboRioSim::GetVInCurrent() { return HALSIM_GetRoboRioVInCurrent(); }
void RoboRioSim::SetVInCurrent(double vInCurrent) {
HALSIM_SetRoboRioVInCurrent(vInCurrent);
}
std::unique_ptr<CallbackStore> RoboRioSim::RegisterUserVoltage6VCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioUserVoltage6VCallback);
store->SetUid(HALSIM_RegisterRoboRioUserVoltage6VCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double RoboRioSim::GetUserVoltage6V() {
return HALSIM_GetRoboRioUserVoltage6V();
}
void RoboRioSim::SetUserVoltage6V(double userVoltage6V) {
HALSIM_SetRoboRioUserVoltage6V(userVoltage6V);
}
std::unique_ptr<CallbackStore> RoboRioSim::RegisterUserCurrent6VCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioUserCurrent6VCallback);
store->SetUid(HALSIM_RegisterRoboRioUserCurrent6VCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double RoboRioSim::GetUserCurrent6V() {
return HALSIM_GetRoboRioUserCurrent6V();
}
void RoboRioSim::SetUserCurrent6V(double userCurrent6V) {
HALSIM_SetRoboRioUserCurrent6V(userCurrent6V);
}
std::unique_ptr<CallbackStore> RoboRioSim::RegisterUserActive6VCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioUserActive6VCallback);
store->SetUid(HALSIM_RegisterRoboRioUserActive6VCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool RoboRioSim::GetUserActive6V() { return HALSIM_GetRoboRioUserActive6V(); }
void RoboRioSim::SetUserActive6V(bool userActive6V) {
HALSIM_SetRoboRioUserActive6V(userActive6V);
}
std::unique_ptr<CallbackStore> RoboRioSim::RegisterUserVoltage5VCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioUserVoltage5VCallback);
store->SetUid(HALSIM_RegisterRoboRioUserVoltage5VCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double RoboRioSim::GetUserVoltage5V() {
return HALSIM_GetRoboRioUserVoltage5V();
}
void RoboRioSim::SetUserVoltage5V(double userVoltage5V) {
HALSIM_SetRoboRioUserVoltage5V(userVoltage5V);
}
std::unique_ptr<CallbackStore> RoboRioSim::RegisterUserCurrent5VCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioUserCurrent5VCallback);
store->SetUid(HALSIM_RegisterRoboRioUserCurrent5VCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double RoboRioSim::GetUserCurrent5V() {
return HALSIM_GetRoboRioUserCurrent5V();
}
void RoboRioSim::SetUserCurrent5V(double userCurrent5V) {
HALSIM_SetRoboRioUserCurrent5V(userCurrent5V);
}
std::unique_ptr<CallbackStore> RoboRioSim::RegisterUserActive5VCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioUserActive5VCallback);
store->SetUid(HALSIM_RegisterRoboRioUserActive5VCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool RoboRioSim::GetUserActive5V() { return HALSIM_GetRoboRioUserActive5V(); }
void RoboRioSim::SetUserActive5V(bool userActive5V) {
HALSIM_SetRoboRioUserActive5V(userActive5V);
}
std::unique_ptr<CallbackStore> RoboRioSim::RegisterUserVoltage3V3Callback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioUserVoltage3V3Callback);
store->SetUid(HALSIM_RegisterRoboRioUserVoltage3V3Callback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double RoboRioSim::GetUserVoltage3V3() {
return HALSIM_GetRoboRioUserVoltage3V3();
}
void RoboRioSim::SetUserVoltage3V3(double userVoltage3V3) {
HALSIM_SetRoboRioUserVoltage3V3(userVoltage3V3);
}
std::unique_ptr<CallbackStore> RoboRioSim::RegisterUserCurrent3V3Callback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioUserCurrent3V3Callback);
store->SetUid(HALSIM_RegisterRoboRioUserCurrent3V3Callback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double RoboRioSim::GetUserCurrent3V3() {
return HALSIM_GetRoboRioUserCurrent3V3();
}
void RoboRioSim::SetUserCurrent3V3(double userCurrent3V3) {
HALSIM_SetRoboRioUserCurrent3V3(userCurrent3V3);
}
std::unique_ptr<CallbackStore> RoboRioSim::RegisterUserActive3V3Callback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioUserActive3V3Callback);
store->SetUid(HALSIM_RegisterRoboRioUserActive3V3Callback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool RoboRioSim::GetUserActive3V3() { return HALSIM_GetRoboRioUserActive3V3(); }
void RoboRioSim::SetUserActive3V3(bool userActive3V3) {
HALSIM_SetRoboRioUserActive3V3(userActive3V3);
}
std::unique_ptr<CallbackStore> RoboRioSim::RegisterUserFaults6VCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioUserFaults6VCallback);
store->SetUid(HALSIM_RegisterRoboRioUserFaults6VCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
int RoboRioSim::GetUserFaults6V() { return HALSIM_GetRoboRioUserFaults6V(); }
void RoboRioSim::SetUserFaults6V(int userFaults6V) {
HALSIM_SetRoboRioUserFaults6V(userFaults6V);
}
std::unique_ptr<CallbackStore> RoboRioSim::RegisterUserFaults5VCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioUserFaults5VCallback);
store->SetUid(HALSIM_RegisterRoboRioUserFaults5VCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
int RoboRioSim::GetUserFaults5V() { return HALSIM_GetRoboRioUserFaults5V(); }
void RoboRioSim::SetUserFaults5V(int userFaults5V) {
HALSIM_SetRoboRioUserFaults5V(userFaults5V);
}
std::unique_ptr<CallbackStore> RoboRioSim::RegisterUserFaults3V3Callback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioUserFaults3V3Callback);
store->SetUid(HALSIM_RegisterRoboRioUserFaults3V3Callback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
int RoboRioSim::GetUserFaults3V3() { return HALSIM_GetRoboRioUserFaults3V3(); }
void RoboRioSim::SetUserFaults3V3(int userFaults3V3) {
HALSIM_SetRoboRioUserFaults3V3(userFaults3V3);
}
void ResetData() { HALSIM_ResetRoboRioData(); }

View File

@@ -0,0 +1,107 @@
/*----------------------------------------------------------------------------*/
/* 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/SPIAccelerometerSim.h"
#include <memory>
#include <utility>
#include <hal/simulation/SPIAccelerometerData.h>
using namespace frc;
using namespace frc::sim;
SPIAccelerometerSim::SPIAccelerometerSim(int index) { m_index = index; }
std::unique_ptr<CallbackStore> SPIAccelerometerSim::RegisterActiveCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelSPIAccelerometerActiveCallback);
store->SetUid(HALSIM_RegisterSPIAccelerometerActiveCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool SPIAccelerometerSim::GetActive() const {
return HALSIM_GetSPIAccelerometerActive(m_index);
}
void SPIAccelerometerSim::SetActive(bool active) {
HALSIM_SetSPIAccelerometerActive(m_index, active);
}
std::unique_ptr<CallbackStore> SPIAccelerometerSim::RegisterRangeCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelSPIAccelerometerRangeCallback);
store->SetUid(HALSIM_RegisterSPIAccelerometerRangeCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
int SPIAccelerometerSim::GetRange() const {
return HALSIM_GetSPIAccelerometerRange(m_index);
}
void SPIAccelerometerSim::SetRange(int range) {
HALSIM_SetSPIAccelerometerRange(m_index, range);
}
std::unique_ptr<CallbackStore> SPIAccelerometerSim::RegisterXCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelSPIAccelerometerXCallback);
store->SetUid(HALSIM_RegisterSPIAccelerometerXCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double SPIAccelerometerSim::GetX() const {
return HALSIM_GetSPIAccelerometerX(m_index);
}
void SPIAccelerometerSim::SetX(double x) {
HALSIM_SetSPIAccelerometerX(m_index, x);
}
std::unique_ptr<CallbackStore> SPIAccelerometerSim::RegisterYCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelSPIAccelerometerYCallback);
store->SetUid(HALSIM_RegisterSPIAccelerometerYCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double SPIAccelerometerSim::GetY() const {
return HALSIM_GetSPIAccelerometerY(m_index);
}
void SPIAccelerometerSim::SetY(double y) {
HALSIM_SetSPIAccelerometerY(m_index, y);
}
std::unique_ptr<CallbackStore> SPIAccelerometerSim::RegisterZCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelSPIAccelerometerZCallback);
store->SetUid(HALSIM_RegisterSPIAccelerometerZCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double SPIAccelerometerSim::GetZ() const {
return HALSIM_GetSPIAccelerometerZ(m_index);
}
void SPIAccelerometerSim::SetZ(double z) {
HALSIM_SetSPIAccelerometerZ(m_index, z);
}
void SPIAccelerometerSim::ResetData() {
HALSIM_ResetSPIAccelerometerData(m_index);
}

View File

@@ -0,0 +1,47 @@
/*----------------------------------------------------------------------------*/
/* 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. */
/*----------------------------------------------------------------------------*/
#include "frc/simulation/SimDeviceSim.h"
#include <string>
#include <vector>
#include <hal/SimDevice.h>
#include <hal/simulation/SimDeviceData.h>
using namespace frc;
using namespace frc::sim;
SimDeviceSim::SimDeviceSim(const char* name)
: m_handle{HALSIM_GetSimDeviceHandle(name)} {}
hal::SimValue SimDeviceSim::GetValue(const char* name) const {
return HALSIM_GetSimValueHandle(m_handle, name);
}
hal::SimDouble SimDeviceSim::GetDouble(const char* name) const {
return HALSIM_GetSimValueHandle(m_handle, name);
}
hal::SimEnum SimDeviceSim::GetEnum(const char* name) const {
return HALSIM_GetSimValueHandle(m_handle, name);
}
hal::SimBoolean SimDeviceSim::GetBoolean(const char* name) const {
return HALSIM_GetSimValueHandle(m_handle, name);
}
std::vector<std::string> SimDeviceSim::GetEnumOptions(hal::SimEnum val) {
int32_t numOptions;
const char** options = HALSIM_GetSimValueEnumOptions(val, &numOptions);
std::vector<std::string> rv;
rv.reserve(numOptions);
for (int32_t i = 0; i < numOptions; ++i) rv.emplace_back(options[i]);
return rv;
}
void SimDeviceSim::ResetData() { HALSIM_ResetSimDeviceData(); }

View File

@@ -0,0 +1,34 @@
/*----------------------------------------------------------------------------*/
/* 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/SimHooks.h"
#include <hal/simulation/MockHooks.h>
namespace frc {
namespace sim {
void SetRuntimeType(HAL_RuntimeType type) { HALSIM_SetRuntimeType(type); }
void WaitForProgramStart() { HALSIM_WaitForProgramStart(); }
void SetProgramStarted() { HALSIM_SetProgramStarted(); }
bool GetProgramStarted() { return HALSIM_GetProgramStarted(); }
void RestartTiming() { HALSIM_RestartTiming(); }
void PauseTiming() { HALSIM_PauseTiming(); }
void ResumeTiming() { HALSIM_ResumeTiming(); }
bool IsTimingPaused() { return HALSIM_IsTimingPaused(); }
void StepTiming(uint64_t delta) { HALSIM_StepTiming(delta); }
} // namespace sim
} // namespace frc

View File

@@ -0,0 +1,90 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 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/XboxControllerSim.h"
#include "frc/XboxController.h"
using namespace frc;
using namespace frc::sim;
XboxControllerSim::XboxControllerSim(const XboxController& joystick)
: GenericHIDSim{joystick} {
SetAxisCount(6);
SetButtonCount(10);
}
XboxControllerSim::XboxControllerSim(int port) : GenericHIDSim{port} {
SetAxisCount(6);
SetButtonCount(10);
}
void XboxControllerSim::SetX(GenericHID::JoystickHand hand, double value) {
if (hand == GenericHID::kLeftHand) {
SetRawAxis(static_cast<int>(XboxController::Axis::kLeftX), value);
} else {
SetRawAxis(static_cast<int>(XboxController::Axis::kRightX), value);
}
}
void XboxControllerSim::SetY(GenericHID::JoystickHand hand, double value) {
if (hand == GenericHID::kLeftHand) {
SetRawAxis(static_cast<int>(XboxController::Axis::kLeftY), value);
} else {
SetRawAxis(static_cast<int>(XboxController::Axis::kRightY), value);
}
}
void XboxControllerSim::SetTriggerAxis(GenericHID::JoystickHand hand,
double value) {
if (hand == GenericHID::kLeftHand) {
SetRawAxis(static_cast<int>(XboxController::Axis::kLeftTrigger), value);
} else {
SetRawAxis(static_cast<int>(XboxController::Axis::kRightTrigger), value);
}
}
void XboxControllerSim::SetBumper(GenericHID::JoystickHand hand, bool state) {
if (hand == GenericHID::kLeftHand) {
SetRawButton(static_cast<int>(XboxController::Button::kBumperLeft), state);
} else {
SetRawButton(static_cast<int>(XboxController::Button::kBumperRight), state);
}
}
void XboxControllerSim::SetStickButton(GenericHID::JoystickHand hand,
bool state) {
if (hand == GenericHID::kLeftHand) {
SetRawButton(static_cast<int>(XboxController::Button::kStickLeft), state);
} else {
SetRawButton(static_cast<int>(XboxController::Button::kStickRight), state);
}
}
void XboxControllerSim::SetAButton(bool state) {
SetRawButton(static_cast<int>(XboxController::Button::kA), state);
}
void XboxControllerSim::SetBButton(bool state) {
SetRawButton(static_cast<int>(XboxController::Button::kB), state);
}
void XboxControllerSim::SetXButton(bool state) {
SetRawButton(static_cast<int>(XboxController::Button::kX), state);
}
void XboxControllerSim::SetYButton(bool state) {
SetRawButton(static_cast<int>(XboxController::Button::kY), state);
}
void XboxControllerSim::SetBackButton(bool state) {
SetRawButton(static_cast<int>(XboxController::Button::kBack), state);
}
void XboxControllerSim::SetStartButton(bool state) {
SetRawButton(static_cast<int>(XboxController::Button::kStart), state);
}

View File

@@ -7,17 +7,16 @@
#pragma once
#include <exception>
#include <memory>
#include <utility>
#include <hal/simulation/AddressableLEDData.h>
#include <wpi/ArrayRef.h>
#include "frc/simulation/CallbackStore.h"
#include "CallbackStore.h"
#include "frc/AddressableLED.h"
struct HAL_AddressableLEDData;
namespace frc {
class AddressableLED;
namespace sim {
/**
@@ -28,15 +27,14 @@ class AddressableLEDSim {
/**
* Constructs for the first addressable LED.
*/
AddressableLEDSim() : m_index{0} {}
AddressableLEDSim();
/**
* Constructs from an AddressableLED object.
*
* @param addressableLED AddressableLED to simulate
*/
explicit AddressableLEDSim(const AddressableLED& addressableLED)
: m_index{0} {}
explicit AddressableLEDSim(const AddressableLED& addressableLED);
/**
* Creates an AddressableLEDSim for a PWM channel.
@@ -46,12 +44,7 @@ class AddressableLEDSim {
* @throws std::out_of_range if no AddressableLED is configured for that
* channel
*/
static AddressableLEDSim CreateForChannel(int pwmChannel) {
int index = HALSIM_FindAddressableLEDForChannel(pwmChannel);
if (index < 0)
throw std::out_of_range("no addressable LED found for PWM channel");
return AddressableLEDSim{index};
}
static AddressableLEDSim CreateForChannel(int pwmChannel);
/**
* Creates an AddressableLEDSim for a simulated index.
@@ -60,90 +53,42 @@ class AddressableLEDSim {
* @param index simulator index
* @return Simulated object
*/
static AddressableLEDSim CreateForIndex(int index) {
return AddressableLEDSim{index};
}
static AddressableLEDSim CreateForIndex(int index);
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAddressableLEDInitializedCallback);
store->SetUid(HALSIM_RegisterAddressableLEDInitializedCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
bool GetInitialized() const {
return HALSIM_GetAddressableLEDInitialized(m_index);
}
bool GetInitialized() const;
void SetInitialized(bool initialized) {
HALSIM_SetAddressableLEDInitialized(m_index, initialized);
}
void SetInitialized(bool initialized);
std::unique_ptr<CallbackStore> registerOutputPortCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAddressableLEDOutputPortCallback);
store->SetUid(HALSIM_RegisterAddressableLEDOutputPortCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
std::unique_ptr<CallbackStore> RegisterOutputPortCallback(
NotifyCallback callback, bool initialNotify);
int GetOutputPort() const {
return HALSIM_GetAddressableLEDOutputPort(m_index);
}
int GetOutputPort() const;
void SetOutputPort(int outputPort) {
HALSIM_SetAddressableLEDOutputPort(m_index, outputPort);
}
void SetOutputPort(int outputPort);
std::unique_ptr<CallbackStore> RegisterLengthCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAddressableLEDLengthCallback);
store->SetUid(HALSIM_RegisterAddressableLEDLengthCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool initialNotify);
int GetLength() const { return HALSIM_GetAddressableLEDLength(m_index); }
int GetLength() const;
void SetLength(int length) {
HALSIM_SetAddressableLEDLength(m_index, length);
}
void SetLength(int length);
std::unique_ptr<CallbackStore> RegisterRunningCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAddressableLEDRunningCallback);
store->SetUid(HALSIM_RegisterAddressableLEDRunningCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
int GetRunning() const { return HALSIM_GetAddressableLEDRunning(m_index); }
int GetRunning() const;
void SetRunning(bool running) {
HALSIM_SetAddressableLEDRunning(m_index, running);
}
void SetRunning(bool running);
std::unique_ptr<CallbackStore> RegisterDataCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAddressableLEDDataCallback);
store->SetUid(HALSIM_RegisterAddressableLEDDataCallback(
m_index, &ConstBufferCallbackStoreThunk, store.get()));
return store;
}
bool initialNotify);
int GetData(struct HAL_AddressableLEDData* data) const {
return HALSIM_GetAddressableLEDData(m_index, data);
}
int GetData(struct HAL_AddressableLEDData* data) const;
void SetData(struct HAL_AddressableLEDData* data, int length) {
HALSIM_SetAddressableLEDData(m_index, data, length);
}
void SetData(struct HAL_AddressableLEDData* data, int length);
private:
explicit AddressableLEDSim(int index) : m_index{index} {}

View File

@@ -8,15 +8,13 @@
#pragma once
#include <memory>
#include <utility>
#include <hal/simulation/AnalogGyroData.h>
#include "CallbackStore.h"
#include "frc/AnalogGyro.h"
#include "frc/AnalogInput.h"
#include "frc/simulation/CallbackStore.h"
namespace frc {
class AnalogGyro;
namespace sim {
/**
@@ -29,60 +27,37 @@ class AnalogGyroSim {
*
* @param gyro AnalogGyro to simulate
*/
explicit AnalogGyroSim(const AnalogGyro& gyro)
: m_index{gyro.GetAnalogInput()->GetChannel()} {}
explicit AnalogGyroSim(const AnalogGyro& gyro);
/**
* Constructs from an analog input channel number.
*
* @param channel Channel number
*/
explicit AnalogGyroSim(int channel) : m_index{channel} {}
explicit AnalogGyroSim(int channel);
std::unique_ptr<CallbackStore> RegisterAngleCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogGyroAngleCallback);
store->SetUid(HALSIM_RegisterAnalogGyroAngleCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool initialNotify);
double GetAngle() const { return HALSIM_GetAnalogGyroAngle(m_index); }
double GetAngle() const;
void SetAngle(double angle) { HALSIM_SetAnalogGyroAngle(m_index, angle); }
void SetAngle(double angle);
std::unique_ptr<CallbackStore> RegisterRateCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogGyroRateCallback);
store->SetUid(HALSIM_RegisterAnalogGyroRateCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool initialNotify);
double GetRate() const { return HALSIM_GetAnalogGyroRate(m_index); }
double GetRate() const;
void SetRate(double rate) { HALSIM_SetAnalogGyroRate(m_index, rate); }
void SetRate(double rate);
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogGyroInitializedCallback);
store->SetUid(HALSIM_RegisterAnalogGyroInitializedCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
bool GetInitialized() const {
return HALSIM_GetAnalogGyroInitialized(m_index);
}
bool GetInitialized() const;
void SetInitialized(bool initialized) {
HALSIM_SetAnalogGyroInitialized(m_index, initialized);
}
void SetInitialized(bool initialized);
void ResetData() { HALSIM_ResetAnalogGyroData(m_index); }
void ResetData();
private:
int m_index;

View File

@@ -8,14 +8,13 @@
#pragma once
#include <memory>
#include <utility>
#include <hal/simulation/AnalogInData.h>
#include "CallbackStore.h"
#include "frc/AnalogInput.h"
#include "frc/simulation/CallbackStore.h"
namespace frc {
class AnalogInput;
namespace sim {
/**
@@ -28,166 +27,79 @@ class AnalogInputSim {
*
* @param analogInput AnalogInput to simulate
*/
explicit AnalogInputSim(const AnalogInput& analogInput)
: m_index{analogInput.GetChannel()} {}
explicit AnalogInputSim(const AnalogInput& analogInput);
/**
* Constructs from an analog input channel number.
*
* @param channel Channel number
*/
explicit AnalogInputSim(int channel) : m_index{channel} {}
explicit AnalogInputSim(int channel);
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogInInitializedCallback);
store->SetUid(HALSIM_RegisterAnalogInInitializedCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
bool GetInitialized() const { return HALSIM_GetAnalogInInitialized(m_index); }
bool GetInitialized() const;
void SetInitialized(bool initialized) {
HALSIM_SetAnalogInInitialized(m_index, initialized);
}
void SetInitialized(bool initialized);
std::unique_ptr<CallbackStore> RegisterAverageBitsCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogInAverageBitsCallback);
store->SetUid(HALSIM_RegisterAnalogInAverageBitsCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
int GetAverageBits() const { return HALSIM_GetAnalogInAverageBits(m_index); }
int GetAverageBits() const;
void SetAverageBits(int averageBits) {
HALSIM_SetAnalogInAverageBits(m_index, averageBits);
}
void SetAverageBits(int averageBits);
std::unique_ptr<CallbackStore> RegisterOversampleBitsCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogInOversampleBitsCallback);
store->SetUid(HALSIM_RegisterAnalogInOversampleBitsCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
int GetOversampleBits() const {
return HALSIM_GetAnalogInOversampleBits(m_index);
}
int GetOversampleBits() const;
void SetOversampleBits(int oversampleBits) {
HALSIM_SetAnalogInOversampleBits(m_index, oversampleBits);
}
void SetOversampleBits(int oversampleBits);
std::unique_ptr<CallbackStore> RegisterVoltageCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogInVoltageCallback);
store->SetUid(HALSIM_RegisterAnalogInVoltageCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
double GetVoltage() const { return HALSIM_GetAnalogInVoltage(m_index); }
double GetVoltage() const;
void SetVoltage(double voltage) {
HALSIM_SetAnalogInVoltage(m_index, voltage);
}
void SetVoltage(double voltage);
std::unique_ptr<CallbackStore> RegisterAccumulatorInitializedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback,
&HALSIM_CancelAnalogInAccumulatorInitializedCallback);
store->SetUid(HALSIM_RegisterAnalogInAccumulatorInitializedCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
bool GetAccumulatorInitialized() const {
return HALSIM_GetAnalogInAccumulatorInitialized(m_index);
}
bool GetAccumulatorInitialized() const;
void SetAccumulatorInitialized(bool accumulatorInitialized) {
HALSIM_SetAnalogInAccumulatorInitialized(m_index, accumulatorInitialized);
}
void SetAccumulatorInitialized(bool accumulatorInitialized);
std::unique_ptr<CallbackStore> RegisterAccumulatorValueCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogInAccumulatorValueCallback);
store->SetUid(HALSIM_RegisterAnalogInAccumulatorValueCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
int64_t GetAccumulatorValue() const {
return HALSIM_GetAnalogInAccumulatorValue(m_index);
}
int64_t GetAccumulatorValue() const;
void SetAccumulatorValue(int64_t accumulatorValue) {
HALSIM_SetAnalogInAccumulatorValue(m_index, accumulatorValue);
}
void SetAccumulatorValue(int64_t accumulatorValue);
std::unique_ptr<CallbackStore> RegisterAccumulatorCountCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogInAccumulatorCountCallback);
store->SetUid(HALSIM_RegisterAnalogInAccumulatorCountCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
int64_t GetAccumulatorCount() const {
return HALSIM_GetAnalogInAccumulatorCount(m_index);
}
int64_t GetAccumulatorCount() const;
void SetAccumulatorCount(int64_t accumulatorCount) {
HALSIM_SetAnalogInAccumulatorCount(m_index, accumulatorCount);
}
void SetAccumulatorCount(int64_t accumulatorCount);
std::unique_ptr<CallbackStore> RegisterAccumulatorCenterCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogInAccumulatorCenterCallback);
store->SetUid(HALSIM_RegisterAnalogInAccumulatorCenterCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
int GetAccumulatorCenter() const {
return HALSIM_GetAnalogInAccumulatorCenter(m_index);
}
int GetAccumulatorCenter() const;
void SetAccumulatorCenter(int accumulatorCenter) {
HALSIM_SetAnalogInAccumulatorCenter(m_index, accumulatorCenter);
}
void SetAccumulatorCenter(int accumulatorCenter);
std::unique_ptr<CallbackStore> RegisterAccumulatorDeadbandCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback,
&HALSIM_CancelAnalogInAccumulatorDeadbandCallback);
store->SetUid(HALSIM_RegisterAnalogInAccumulatorDeadbandCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
int GetAccumulatorDeadband() const {
return HALSIM_GetAnalogInAccumulatorDeadband(m_index);
}
int GetAccumulatorDeadband() const;
void SetAccumulatorDeadband(int accumulatorDeadband) {
HALSIM_SetAnalogInAccumulatorDeadband(m_index, accumulatorDeadband);
}
void SetAccumulatorDeadband(int accumulatorDeadband);
void ResetData() { HALSIM_ResetAnalogInData(m_index); }
void ResetData();
private:
int m_index;

View File

@@ -8,14 +8,13 @@
#pragma once
#include <memory>
#include <utility>
#include <hal/simulation/AnalogOutData.h>
#include "CallbackStore.h"
#include "frc/AnalogOutput.h"
#include "frc/simulation/CallbackStore.h"
namespace frc {
class AnalogOutput;
namespace sim {
/**
@@ -28,49 +27,30 @@ class AnalogOutputSim {
*
* @param analogOutput AnalogOutput to simulate
*/
explicit AnalogOutputSim(const AnalogOutput& analogOutput)
: m_index{analogOutput.GetChannel()} {}
explicit AnalogOutputSim(const AnalogOutput& analogOutput);
/**
* Constructs from an analog output channel number.
*
* @param channel Channel number
*/
explicit AnalogOutputSim(int channel) : m_index{channel} {}
explicit AnalogOutputSim(int channel);
std::unique_ptr<CallbackStore> RegisterVoltageCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogOutVoltageCallback);
store->SetUid(HALSIM_RegisterAnalogOutVoltageCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
double GetVoltage() const { return HALSIM_GetAnalogOutVoltage(m_index); }
double GetVoltage() const;
void SetVoltage(double voltage) {
HALSIM_SetAnalogOutVoltage(m_index, voltage);
}
void SetVoltage(double voltage);
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogOutInitializedCallback);
store->SetUid(HALSIM_RegisterAnalogOutInitializedCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
bool GetInitialized() const {
return HALSIM_GetAnalogOutInitialized(m_index);
}
bool GetInitialized() const;
void SetInitialized(bool initialized) {
HALSIM_SetAnalogOutInitialized(m_index, initialized);
}
void SetInitialized(bool initialized);
void ResetData() { HALSIM_ResetAnalogOutData(m_index); }
void ResetData();
private:
int m_index;

View File

@@ -7,16 +7,14 @@
#pragma once
#include <exception>
#include <memory>
#include <utility>
#include <hal/simulation/AnalogTriggerData.h>
#include "CallbackStore.h"
#include "frc/AnalogTrigger.h"
#include "frc/simulation/CallbackStore.h"
namespace frc {
class AnalogTrigger;
namespace sim {
/**
@@ -29,8 +27,7 @@ class AnalogTriggerSim {
*
* @param analogTrigger AnalogTrigger to simulate
*/
explicit AnalogTriggerSim(const AnalogTrigger& analogTrigger)
: m_index{analogTrigger.GetIndex()} {}
explicit AnalogTriggerSim(const AnalogTrigger& analogTrigger);
/**
* Creates an AnalogTriggerSim for an analog input channel.
@@ -40,12 +37,7 @@ class AnalogTriggerSim {
* @throws std::out_of_range if no AnalogTrigger is configured for that
* channel
*/
static 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};
}
static AnalogTriggerSim CreateForChannel(int channel);
/**
* Creates an AnalogTriggerSim for a simulated index.
@@ -54,64 +46,30 @@ class AnalogTriggerSim {
* @param index simulator index
* @return Simulated object
*/
static AnalogTriggerSim CreateForIndex(int index) {
return AnalogTriggerSim{index};
}
static AnalogTriggerSim CreateForIndex(int index);
std::unique_ptr<CallbackStore> 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;
}
NotifyCallback callback, bool initialNotify);
bool GetInitialized() const {
return HALSIM_GetAnalogTriggerInitialized(m_index);
}
bool GetInitialized() const;
void SetInitialized(bool initialized) {
HALSIM_SetAnalogTriggerInitialized(m_index, initialized);
}
void SetInitialized(bool initialized);
std::unique_ptr<CallbackStore> 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;
}
NotifyCallback callback, bool initialNotify);
double GetTriggerLowerBound() const {
return HALSIM_GetAnalogTriggerTriggerLowerBound(m_index);
}
double GetTriggerLowerBound() const;
void SetTriggerLowerBound(double triggerLowerBound) {
HALSIM_SetAnalogTriggerTriggerLowerBound(m_index, triggerLowerBound);
}
void SetTriggerLowerBound(double triggerLowerBound);
std::unique_ptr<CallbackStore> 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;
}
NotifyCallback callback, bool initialNotify);
double GetTriggerUpperBound() const {
return HALSIM_GetAnalogTriggerTriggerUpperBound(m_index);
}
double GetTriggerUpperBound() const;
void SetTriggerUpperBound(double triggerUpperBound) {
HALSIM_SetAnalogTriggerTriggerUpperBound(m_index, triggerUpperBound);
}
void SetTriggerUpperBound(double triggerUpperBound);
void ResetData() { HALSIM_ResetAnalogTriggerData(m_index); }
void ResetData();
private:
explicit AnalogTriggerSim(int index) : m_index{index} {}

View File

@@ -8,14 +8,15 @@
#pragma once
#include <memory>
#include <utility>
#include <hal/simulation/AccelerometerData.h>
#include <hal/Accelerometer.h>
#include "CallbackStore.h"
#include "frc/BuiltInAccelerometer.h"
#include "frc/simulation/CallbackStore.h"
namespace frc {
class BuiltInAccelerometer;
namespace sim {
/**
@@ -26,88 +27,51 @@ class BuiltInAccelerometerSim {
/**
* Constructs for the first built-in accelerometer.
*/
BuiltInAccelerometerSim() : m_index{0} {}
BuiltInAccelerometerSim();
/**
* Constructs from a BuiltInAccelerometer object.
*
* @param accel BuiltInAccelerometer to simulate
*/
explicit BuiltInAccelerometerSim(const BuiltInAccelerometer& accel)
: m_index{0} {}
explicit BuiltInAccelerometerSim(const BuiltInAccelerometer& accel);
std::unique_ptr<CallbackStore> RegisterActiveCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAccelerometerActiveCallback);
store->SetUid(HALSIM_RegisterAccelerometerActiveCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool initialNotify);
bool GetActive() const { return HALSIM_GetAccelerometerActive(m_index); }
bool GetActive() const;
void SetActive(bool active) {
HALSIM_SetAccelerometerActive(m_index, active);
}
void SetActive(bool active);
std::unique_ptr<CallbackStore> RegisterRangeCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAccelerometerRangeCallback);
store->SetUid(HALSIM_RegisterAccelerometerRangeCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool initialNotify);
HAL_AccelerometerRange GetRange() const {
return HALSIM_GetAccelerometerRange(m_index);
}
HAL_AccelerometerRange GetRange() const;
void SetRange(HAL_AccelerometerRange range) {
HALSIM_SetAccelerometerRange(m_index, range);
}
void SetRange(HAL_AccelerometerRange range);
std::unique_ptr<CallbackStore> RegisterXCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAccelerometerXCallback);
store->SetUid(HALSIM_RegisterAccelerometerXCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool initialNotify);
double GetX() const { return HALSIM_GetAccelerometerX(m_index); }
double GetX() const;
void SetX(double x) { HALSIM_SetAccelerometerX(m_index, x); }
void SetX(double x);
std::unique_ptr<CallbackStore> RegisterYCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAccelerometerYCallback);
store->SetUid(HALSIM_RegisterAccelerometerYCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool initialNotify);
double GetY() const { return HALSIM_GetAccelerometerY(m_index); }
double GetY() const;
void SetY(double y) { HALSIM_SetAccelerometerY(m_index, y); }
void SetY(double y);
std::unique_ptr<CallbackStore> RegisterZCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAccelerometerZCallback);
store->SetUid(HALSIM_RegisterAccelerometerZCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool initialNotify);
double GetZ() const { return HALSIM_GetAccelerometerZ(m_index); }
double GetZ() const;
void SetZ(double z) { HALSIM_SetAccelerometerZ(m_index, z); }
void SetZ(double z);
void ResetData() { HALSIM_ResetAccelerometerData(m_index); }
void ResetData();
private:
int m_index;

View File

@@ -30,74 +30,29 @@ void ConstBufferCallbackStoreThunk(const char* name, void* param,
class CallbackStore {
public:
CallbackStore(int32_t i, NotifyCallback cb, CancelCallbackNoIndexFunc ccf) {
index = i;
callback = cb;
this->ccnif = ccf;
cancelType = NoIndex;
}
CallbackStore(int32_t i, NotifyCallback cb, CancelCallbackNoIndexFunc ccf);
CallbackStore(int32_t i, int32_t u, NotifyCallback cb,
CancelCallbackFunc ccf) {
index = i;
uid = u;
callback = cb;
this->ccf = ccf;
cancelType = Normal;
}
CancelCallbackFunc ccf);
CallbackStore(int32_t i, int32_t c, int32_t u, NotifyCallback cb,
CancelCallbackChannelFunc ccf) {
index = i;
channel = c;
uid = u;
callback = cb;
this->cccf = ccf;
cancelType = Channel;
}
CancelCallbackChannelFunc ccf);
CallbackStore(int32_t i, ConstBufferCallback cb,
CancelCallbackNoIndexFunc ccf) {
index = i;
constBufferCallback = cb;
this->ccnif = ccf;
cancelType = NoIndex;
}
CancelCallbackNoIndexFunc ccf);
CallbackStore(int32_t i, int32_t u, ConstBufferCallback cb,
CancelCallbackFunc ccf) {
index = i;
uid = u;
constBufferCallback = cb;
this->ccf = ccf;
cancelType = Normal;
}
CancelCallbackFunc ccf);
CallbackStore(int32_t i, int32_t c, int32_t u, ConstBufferCallback cb,
CancelCallbackChannelFunc ccf) {
index = i;
channel = c;
uid = u;
constBufferCallback = cb;
this->cccf = ccf;
cancelType = Channel;
}
CancelCallbackChannelFunc ccf);
~CallbackStore() {
switch (cancelType) {
case Normal:
ccf(index, uid);
break;
case Channel:
cccf(index, channel, uid);
break;
case NoIndex:
ccnif(uid);
break;
}
}
CallbackStore(const CallbackStore&) = delete;
CallbackStore& operator=(const CallbackStore&) = delete;
void SetUid(int32_t uid) { this->uid = uid; }
~CallbackStore();
void SetUid(int32_t uid);
friend void CallbackStoreThunk(const char* name, void* param,
const HAL_Value* value);

View File

@@ -8,15 +8,14 @@
#pragma once
#include <memory>
#include <utility>
#include <hal/simulation/DIOData.h>
#include "CallbackStore.h"
#include "frc/DigitalInput.h"
#include "frc/DigitalOutput.h"
#include "frc/simulation/CallbackStore.h"
namespace frc {
class DigitalInput;
class DigitalOutput;
namespace sim {
/**
@@ -29,94 +28,58 @@ class DIOSim {
*
* @param input DigitalInput to simulate
*/
explicit DIOSim(const DigitalInput& input) : m_index{input.GetChannel()} {}
explicit DIOSim(const DigitalInput& input);
/**
* Constructs from a DigitalOutput object.
*
* @param output DigitalOutput to simulate
*/
explicit DIOSim(const DigitalOutput& output) : m_index{output.GetChannel()} {}
explicit DIOSim(const DigitalOutput& output);
/**
* Constructs from an digital I/O channel number.
*
* @param channel Channel number
*/
explicit DIOSim(int channel) : m_index{channel} {}
explicit DIOSim(int channel);
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelDIOInitializedCallback);
store->SetUid(HALSIM_RegisterDIOInitializedCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
bool GetInitialized() const { return HALSIM_GetDIOInitialized(m_index); }
bool GetInitialized() const;
void SetInitialized(bool initialized) {
HALSIM_SetDIOInitialized(m_index, initialized);
}
void SetInitialized(bool initialized);
std::unique_ptr<CallbackStore> RegisterValueCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelDIOValueCallback);
store->SetUid(HALSIM_RegisterDIOValueCallback(m_index, &CallbackStoreThunk,
store.get(), initialNotify));
return store;
}
bool initialNotify);
bool GetValue() const { return HALSIM_GetDIOValue(m_index); }
bool GetValue() const;
void SetValue(bool value) { HALSIM_SetDIOValue(m_index, value); }
void SetValue(bool value);
std::unique_ptr<CallbackStore> RegisterPulseLengthCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelDIOPulseLengthCallback);
store->SetUid(HALSIM_RegisterDIOPulseLengthCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
double GetPulseLength() const { return HALSIM_GetDIOPulseLength(m_index); }
double GetPulseLength() const;
void SetPulseLength(double pulseLength) {
HALSIM_SetDIOPulseLength(m_index, pulseLength);
}
void SetPulseLength(double pulseLength);
std::unique_ptr<CallbackStore> RegisterIsInputCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelDIOIsInputCallback);
store->SetUid(HALSIM_RegisterDIOIsInputCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
bool GetIsInput() const { return HALSIM_GetDIOIsInput(m_index); }
bool GetIsInput() const;
void SetIsInput(bool isInput) { HALSIM_SetDIOIsInput(m_index, isInput); }
void SetIsInput(bool isInput);
std::unique_ptr<CallbackStore> RegisterFilterIndexCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelDIOFilterIndexCallback);
store->SetUid(HALSIM_RegisterDIOFilterIndexCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
int GetFilterIndex() const { return HALSIM_GetDIOFilterIndex(m_index); }
int GetFilterIndex() const;
void SetFilterIndex(int filterIndex) {
HALSIM_SetDIOFilterIndex(m_index, filterIndex);
}
void SetFilterIndex(int filterIndex);
void ResetData() { HALSIM_ResetDIOData(m_index); }
void ResetData();
private:
int m_index;

View File

@@ -7,16 +7,14 @@
#pragma once
#include <exception>
#include <memory>
#include <utility>
#include <hal/simulation/DigitalPWMData.h>
#include "CallbackStore.h"
#include "frc/DigitalOutput.h"
#include "frc/simulation/CallbackStore.h"
namespace frc {
class DigitalOutput;
namespace sim {
/**
@@ -32,8 +30,7 @@ class DigitalPWMSim {
*
* @param digitalOutput DigitalOutput to simulate
*/
explicit DigitalPWMSim(const DigitalOutput& digitalOutput)
: m_index{digitalOutput.GetChannel()} {}
explicit DigitalPWMSim(const DigitalOutput& digitalOutput);
/**
* Creates an DigitalPWMSim for a digital I/O channel.
@@ -42,11 +39,7 @@ class DigitalPWMSim {
* @return Simulated object
* @throws std::out_of_range if no Digital PWM is configured for that channel
*/
static DigitalPWMSim CreateForChannel(int channel) {
int index = HALSIM_FindDigitalPWMForChannel(channel);
if (index < 0) throw std::out_of_range("no digital PWM found for channel");
return DigitalPWMSim{index};
}
static DigitalPWMSim CreateForChannel(int channel);
/**
* Creates an DigitalPWMSim for a simulated index.
@@ -55,56 +48,30 @@ class DigitalPWMSim {
* @param index simulator index
* @return Simulated object
*/
static DigitalPWMSim CreateForIndex(int index) {
return DigitalPWMSim{index};
}
static DigitalPWMSim CreateForIndex(int index);
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelDigitalPWMInitializedCallback);
store->SetUid(HALSIM_RegisterDigitalPWMInitializedCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
bool GetInitialized() const {
return HALSIM_GetDigitalPWMInitialized(m_index);
}
bool GetInitialized() const;
void SetInitialized(bool initialized) {
HALSIM_SetDigitalPWMInitialized(m_index, initialized);
}
void SetInitialized(bool initialized);
std::unique_ptr<CallbackStore> RegisterDutyCycleCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelDigitalPWMDutyCycleCallback);
store->SetUid(HALSIM_RegisterDigitalPWMDutyCycleCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
double GetDutyCycle() const { return HALSIM_GetDigitalPWMDutyCycle(m_index); }
double GetDutyCycle() const;
void SetDutyCycle(double dutyCycle) {
HALSIM_SetDigitalPWMDutyCycle(m_index, dutyCycle);
}
void SetDutyCycle(double dutyCycle);
std::unique_ptr<CallbackStore> RegisterPinCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelDigitalPWMPinCallback);
store->SetUid(HALSIM_RegisterDigitalPWMPinCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool initialNotify);
int GetPin() const { return HALSIM_GetDigitalPWMPin(m_index); }
int GetPin() const;
void SetPin(int pin) { HALSIM_SetDigitalPWMPin(m_index, pin); }
void SetPin(int pin);
void ResetData() { HALSIM_ResetDigitalPWMData(m_index); }
void ResetData();
private:
explicit DigitalPWMSim(int index) : m_index{index} {}

View File

@@ -8,13 +8,11 @@
#pragma once
#include <memory>
#include <utility>
#include <hal/simulation/DriverStationData.h>
#include <hal/simulation/MockHooks.h>
#include <hal/DriverStationTypes.h>
#include "CallbackStore.h"
#include "frc/DriverStation.h"
#include "frc/simulation/CallbackStore.h"
namespace frc {
namespace sim {
@@ -25,160 +23,80 @@ namespace sim {
class DriverStationSim {
public:
static std::unique_ptr<CallbackStore> RegisterEnabledCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelDriverStationEnabledCallback);
store->SetUid(HALSIM_RegisterDriverStationEnabledCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
static bool GetEnabled() { return HALSIM_GetDriverStationEnabled(); }
static bool GetEnabled();
static void SetEnabled(bool enabled) {
HALSIM_SetDriverStationEnabled(enabled);
}
static void SetEnabled(bool enabled);
static std::unique_ptr<CallbackStore> RegisterAutonomousCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelDriverStationAutonomousCallback);
store->SetUid(HALSIM_RegisterDriverStationAutonomousCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
static bool GetAutonomous() { return HALSIM_GetDriverStationAutonomous(); }
static bool GetAutonomous();
static void SetAutonomous(bool autonomous) {
HALSIM_SetDriverStationAutonomous(autonomous);
}
static void SetAutonomous(bool autonomous);
static std::unique_ptr<CallbackStore> RegisterTestCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelDriverStationTestCallback);
store->SetUid(HALSIM_RegisterDriverStationTestCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
static bool GetTest() { return HALSIM_GetDriverStationTest(); }
static bool GetTest();
static void SetTest(bool test) { HALSIM_SetDriverStationTest(test); }
static void SetTest(bool test);
static std::unique_ptr<CallbackStore> RegisterEStopCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelDriverStationEStopCallback);
store->SetUid(HALSIM_RegisterDriverStationEStopCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
static bool GetEStop() { return HALSIM_GetDriverStationEStop(); }
static bool GetEStop();
static void SetEStop(bool eStop) { HALSIM_SetDriverStationEStop(eStop); }
static void SetEStop(bool eStop);
static std::unique_ptr<CallbackStore> RegisterFmsAttachedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelDriverStationFmsAttachedCallback);
store->SetUid(HALSIM_RegisterDriverStationFmsAttachedCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
static bool GetFmsAttached() { return HALSIM_GetDriverStationFmsAttached(); }
static bool GetFmsAttached();
static void SetFmsAttached(bool fmsAttached) {
HALSIM_SetDriverStationFmsAttached(fmsAttached);
}
static void SetFmsAttached(bool fmsAttached);
static std::unique_ptr<CallbackStore> RegisterDsAttachedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelDriverStationDsAttachedCallback);
store->SetUid(HALSIM_RegisterDriverStationDsAttachedCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
static bool GetDsAttached() { return HALSIM_GetDriverStationDsAttached(); }
static bool GetDsAttached();
static void SetDsAttached(bool dsAttached) {
HALSIM_SetDriverStationDsAttached(dsAttached);
}
static void SetDsAttached(bool dsAttached);
static std::unique_ptr<CallbackStore> RegisterAllianceStationIdCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelDriverStationAllianceStationIdCallback);
store->SetUid(HALSIM_RegisterDriverStationAllianceStationIdCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
static HAL_AllianceStationID GetAllianceStationId() {
return HALSIM_GetDriverStationAllianceStationId();
}
static HAL_AllianceStationID GetAllianceStationId();
static void SetAllianceStationId(HAL_AllianceStationID allianceStationId) {
HALSIM_SetDriverStationAllianceStationId(allianceStationId);
}
static void SetAllianceStationId(HAL_AllianceStationID allianceStationId);
static std::unique_ptr<CallbackStore> RegisterMatchTimeCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelDriverStationMatchTimeCallback);
store->SetUid(HALSIM_RegisterDriverStationMatchTimeCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
static double GetMatchTime() { return HALSIM_GetDriverStationMatchTime(); }
static double GetMatchTime();
static void SetMatchTime(double matchTime) {
HALSIM_SetDriverStationMatchTime(matchTime);
}
static void SetMatchTime(double matchTime);
/**
* Updates DriverStation data so that new values are visible to the user
* program.
*/
static void NotifyNewData() {
HALSIM_NotifyDriverStationNewData();
DriverStation::GetInstance().WaitForData();
}
static void NotifyNewData();
/**
* Sets suppression of DriverStation::ReportError and ReportWarning messages.
*
* @param shouldSend If false then messages will be suppressed.
*/
static void SetSendError(bool shouldSend) {
if (shouldSend) {
HALSIM_SetSendError(nullptr);
} else {
HALSIM_SetSendError([](HAL_Bool isError, int32_t errorCode,
HAL_Bool isLVCode, const char* details,
const char* location, const char* callStack,
HAL_Bool printMsg) { return 0; });
}
}
static void SetSendError(bool shouldSend);
/**
* Sets suppression of DriverStation::SendConsoleLine messages.
*
* @param shouldSend If false then messages will be suppressed.
*/
static void SetSendConsoleLine(bool shouldSend) {
if (shouldSend) {
HALSIM_SetSendConsoleLine(nullptr);
} else {
HALSIM_SetSendConsoleLine([](const char* line) { return 0; });
}
}
static void SetSendConsoleLine(bool shouldSend);
/**
* Gets the joystick outputs.
@@ -186,13 +104,7 @@ class DriverStationSim {
* @param stick The joystick number
* @return The joystick outputs
*/
static int64_t GetJoystickOutputs(int stick) {
int64_t outputs = 0;
int32_t leftRumble;
int32_t rightRumble;
HALSIM_GetJoystickOutputs(stick, &outputs, &leftRumble, &rightRumble);
return outputs;
}
static int64_t GetJoystickOutputs(int stick);
/**
* Gets the joystick rumble.
@@ -201,13 +113,7 @@ class DriverStationSim {
* @param rumbleNum Rumble to get (0=left, 1=right)
* @return The joystick rumble value
*/
static int GetJoystickRumble(int stick, int rumbleNum) {
int64_t outputs;
int32_t leftRumble = 0;
int32_t rightRumble = 0;
HALSIM_GetJoystickOutputs(stick, &outputs, &leftRumble, &rightRumble);
return rumbleNum == 0 ? leftRumble : rightRumble;
}
static int GetJoystickRumble(int stick, int rumbleNum);
/**
* Sets the state of one joystick button. Button indexes begin at 1.
@@ -216,9 +122,7 @@ class DriverStationSim {
* @param button The button index, beginning at 1
* @param state The state of the joystick button
*/
static void SetJoystickButton(int stick, int button, bool state) {
HALSIM_SetJoystickButton(stick, button, state);
}
static void SetJoystickButton(int stick, int button, bool state);
/**
* Gets the value of the axis on a joystick.
@@ -227,9 +131,7 @@ class DriverStationSim {
* @param axis The analog axis number
* @param value The value of the axis on the joystick
*/
static void SetJoystickAxis(int stick, int axis, double value) {
HALSIM_SetJoystickAxis(stick, axis, value);
}
static void SetJoystickAxis(int stick, int axis, double value);
/**
* Gets the state of a POV on a joystick.
@@ -238,9 +140,7 @@ class DriverStationSim {
* @param pov The POV number
* @param value the angle of the POV in degrees, or -1 for not pressed
*/
static void SetJoystickPOV(int stick, int pov, int value) {
HALSIM_SetJoystickPOV(stick, pov, value);
}
static void SetJoystickPOV(int stick, int pov, int value);
/**
* Sets the state of all the buttons on a joystick.
@@ -248,9 +148,7 @@ class DriverStationSim {
* @param stick The joystick number
* @param buttons The bitmap state of the buttons on the joystick
*/
static void SetJoystickButtons(int stick, uint32_t buttons) {
HALSIM_SetJoystickButtonsValue(stick, buttons);
}
static void SetJoystickButtons(int stick, uint32_t buttons);
/**
* Sets the number of axes for a joystick.
@@ -258,9 +156,7 @@ class DriverStationSim {
* @param stick The joystick number
* @param count The number of axes on the indicated joystick
*/
static void SetJoystickAxisCount(int stick, int count) {
HALSIM_SetJoystickAxisCount(stick, count);
}
static void SetJoystickAxisCount(int stick, int count);
/**
* Sets the number of POVs for a joystick.
@@ -268,9 +164,7 @@ class DriverStationSim {
* @param stick The joystick number
* @param count The number of POVs on the indicated joystick
*/
static void SetJoystickPOVCount(int stick, int count) {
HALSIM_SetJoystickPOVCount(stick, count);
}
static void SetJoystickPOVCount(int stick, int count);
/**
* Sets the number of buttons for a joystick.
@@ -278,9 +172,7 @@ class DriverStationSim {
* @param stick The joystick number
* @param count The number of buttons on the indicated joystick
*/
static void SetJoystickButtonCount(int stick, int count) {
HALSIM_SetJoystickButtonCount(stick, count);
}
static void SetJoystickButtonCount(int stick, int count);
/**
* Sets the value of isXbox for a joystick.
@@ -288,9 +180,7 @@ class DriverStationSim {
* @param stick The joystick number
* @param isXbox The value of isXbox
*/
static void SetJoystickIsXbox(int stick, bool isXbox) {
HALSIM_SetJoystickIsXbox(stick, isXbox);
}
static void SetJoystickIsXbox(int stick, bool isXbox);
/**
* Sets the value of type for a joystick.
@@ -298,9 +188,7 @@ class DriverStationSim {
* @param stick The joystick number
* @param type The value of type
*/
static void SetJoystickType(int stick, int type) {
HALSIM_SetJoystickType(stick, type);
}
static void SetJoystickType(int stick, int type);
/**
* Sets the name of a joystick.
@@ -308,9 +196,7 @@ class DriverStationSim {
* @param stick The joystick number
* @param name The value of name
*/
static void SetJoystickName(int stick, const char* name) {
HALSIM_SetJoystickName(stick, name);
}
static void SetJoystickName(int stick, const char* name);
/**
* Sets the types of Axes for a joystick.
@@ -319,54 +205,44 @@ class DriverStationSim {
* @param axis The target axis
* @param type The type of axis
*/
static void SetJoystickAxisType(int stick, int axis, int type) {
HALSIM_SetJoystickAxisType(stick, axis, type);
}
static void SetJoystickAxisType(int stick, int axis, int type);
/**
* Sets the game specific message.
*
* @param message the game specific message
*/
static void SetGameSpecificMessage(const char* message) {
HALSIM_SetGameSpecificMessage(message);
}
static void SetGameSpecificMessage(const char* message);
/**
* Sets the event name.
*
* @param name the event name
*/
static void SetEventName(const char* name) { HALSIM_SetEventName(name); }
static void SetEventName(const char* name);
/**
* Sets the match type.
*
* @param type the match type
*/
static void SetMatchType(DriverStation::MatchType type) {
HALSIM_SetMatchType(static_cast<HAL_MatchType>(static_cast<int>(type)));
}
static void SetMatchType(DriverStation::MatchType type);
/**
* Sets the match number.
*
* @param matchNumber the match number
*/
static void SetMatchNumber(int matchNumber) {
HALSIM_SetMatchNumber(matchNumber);
}
static void SetMatchNumber(int matchNumber);
/**
* Sets the replay number.
*
* @param replayNumber the replay number
*/
static void SetReplayNumber(int replayNumber) {
HALSIM_SetReplayNumber(replayNumber);
}
static void SetReplayNumber(int replayNumber);
static void ResetData() { HALSIM_ResetDriverStationData(); }
static void ResetData();
};
} // namespace sim
} // namespace frc

View File

@@ -7,16 +7,14 @@
#pragma once
#include <exception>
#include <memory>
#include <utility>
#include <hal/simulation/DutyCycleData.h>
#include "CallbackStore.h"
#include "frc/DutyCycle.h"
#include "frc/simulation/CallbackStore.h"
namespace frc {
class DutyCycle;
namespace sim {
/**
@@ -29,8 +27,7 @@ class DutyCycleSim {
*
* @param dutyCycle DutyCycle to simulate
*/
explicit DutyCycleSim(const DutyCycle& dutyCycle)
: m_index{dutyCycle.GetFPGAIndex()} {}
explicit DutyCycleSim(const DutyCycle& dutyCycle);
/**
* Creates a DutyCycleSim for a digital input channel.
@@ -39,11 +36,7 @@ class DutyCycleSim {
* @return Simulated object
* @throws std::out_of_range if no DutyCycle is configured for that channel
*/
static DutyCycleSim CreateForChannel(int channel) {
int index = HALSIM_FindDutyCycleForChannel(channel);
if (index < 0) throw std::out_of_range("no duty cycle found for channel");
return DutyCycleSim{index};
}
static DutyCycleSim CreateForChannel(int channel);
/**
* Creates a DutyCycleSim for a simulated index.
@@ -52,52 +45,30 @@ class DutyCycleSim {
* @param index simulator index
* @return Simulated object
*/
static DutyCycleSim CreateForIndex(int index) { return DutyCycleSim{index}; }
static DutyCycleSim CreateForIndex(int index);
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelDutyCycleInitializedCallback);
store->SetUid(HALSIM_RegisterDutyCycleInitializedCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
bool GetInitialized() const {
return HALSIM_GetDutyCycleInitialized(m_index);
}
bool GetInitialized() const;
void SetInitialized(bool initialized) {
HALSIM_SetDutyCycleInitialized(m_index, initialized);
}
void SetInitialized(bool initialized);
std::unique_ptr<CallbackStore> RegisterFrequencyCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelDutyCycleFrequencyCallback);
store->SetUid(HALSIM_RegisterDutyCycleFrequencyCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
int GetFrequency() const { return HALSIM_GetDutyCycleFrequency(m_index); }
int GetFrequency() const;
void SetFrequency(int count) { HALSIM_SetDutyCycleFrequency(m_index, count); }
void SetFrequency(int count);
std::unique_ptr<CallbackStore> RegisterOutputCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelDutyCycleOutputCallback);
store->SetUid(HALSIM_RegisterDutyCycleOutputCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool initialNotify);
double GetOutput() const { return HALSIM_GetDutyCycleOutput(m_index); }
double GetOutput() const;
void SetOutput(double period) { HALSIM_SetDutyCycleOutput(m_index, period); }
void SetOutput(double period);
void ResetData() { HALSIM_ResetDutyCycleData(m_index); }
void ResetData();
private:
explicit DutyCycleSim(int index) : m_index{index} {}

View File

@@ -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} {}

View File

@@ -7,10 +7,14 @@
#pragma once
#include <stdint.h>
#include "frc/GenericHID.h"
#include "frc/simulation/DriverStationSim.h"
namespace frc {
class GenericHID;
namespace sim {
/**
@@ -23,71 +27,45 @@ class GenericHIDSim {
*
* @param joystick joystick to simulate
*/
explicit GenericHIDSim(const GenericHID& joystick)
: m_port{joystick.GetPort()} {}
explicit GenericHIDSim(const GenericHID& joystick);
/**
* Constructs from a joystick port number.
*
* @param port port number
*/
explicit GenericHIDSim(int port) : m_port{port} {}
explicit GenericHIDSim(int port);
/**
* Updates joystick data so that new values are visible to the user program.
*/
void NotifyNewData() { DriverStationSim::NotifyNewData(); }
void NotifyNewData();
void SetRawButton(int button, bool value) {
DriverStationSim::SetJoystickButton(m_port, button, value);
}
void SetRawButton(int button, bool value);
void SetRawAxis(int axis, double value) {
DriverStationSim::SetJoystickAxis(m_port, axis, value);
}
void SetRawAxis(int axis, double value);
void SetPOV(int pov, int value) {
DriverStationSim::SetJoystickPOV(m_port, pov, value);
}
void SetPOV(int pov, int value);
void SetPOV(int value) { SetPOV(0, value); }
void SetPOV(int value);
void SetAxisCount(int count) {
DriverStationSim::SetJoystickAxisCount(m_port, count);
}
void SetAxisCount(int count);
void SetPOVCount(int count) {
DriverStationSim::SetJoystickPOVCount(m_port, count);
}
void SetPOVCount(int count);
void SetButtonCount(int count) {
DriverStationSim::SetJoystickButtonCount(m_port, count);
}
void SetButtonCount(int count);
void SetType(GenericHID::HIDType type) {
DriverStationSim::SetJoystickType(m_port, type);
}
void SetType(GenericHID::HIDType type);
void SetName(const char* name) {
DriverStationSim::SetJoystickName(m_port, name);
}
void SetName(const char* name);
void SetAxisType(int axis, int type) {
DriverStationSim::SetJoystickAxisType(m_port, axis, type);
}
void SetAxisType(int axis, int type);
bool GetOutput(int outputNumber) {
int64_t outputs = GetOutputs();
return (outputs & (static_cast<int64_t>(1) << (outputNumber - 1))) != 0;
}
bool GetOutput(int outputNumber);
int64_t GetOutputs() { return DriverStationSim::GetJoystickOutputs(m_port); }
int64_t GetOutputs();
double GetRumble(GenericHID::RumbleType type) {
int value = DriverStationSim::GetJoystickRumble(
m_port, type == GenericHID::kLeftRumble ? 0 : 1);
return value / 65535.0;
}
double GetRumble(GenericHID::RumbleType type);
protected:
int m_port;

View File

@@ -7,10 +7,12 @@
#pragma once
#include "frc/Joystick.h"
#include "frc/simulation/GenericHIDSim.h"
namespace frc {
class Joystick;
namespace sim {
/**
@@ -23,59 +25,28 @@ class JoystickSim : public GenericHIDSim {
*
* @param joystick joystick to simulate
*/
explicit JoystickSim(const Joystick& joystick)
: GenericHIDSim{joystick}, m_joystick{&joystick} {
// default to a reasonable joystick configuration
SetAxisCount(5);
SetButtonCount(12);
SetPOVCount(1);
}
explicit JoystickSim(const Joystick& joystick);
/**
* Constructs from a joystick port number.
*
* @param port port number
*/
explicit JoystickSim(int port) : GenericHIDSim{port} {
// default to a reasonable joystick configuration
SetAxisCount(5);
SetButtonCount(12);
SetPOVCount(1);
}
explicit JoystickSim(int port);
void SetX(double value) {
SetRawAxis(
m_joystick ? m_joystick->GetXChannel() : Joystick::kDefaultXChannel,
value);
}
void SetX(double value);
void SetY(double value) {
SetRawAxis(
m_joystick ? m_joystick->GetYChannel() : Joystick::kDefaultYChannel,
value);
}
void SetY(double value);
void SetZ(double value) {
SetRawAxis(
m_joystick ? m_joystick->GetZChannel() : Joystick::kDefaultZChannel,
value);
}
void SetZ(double value);
void SetTwist(double value) {
SetRawAxis(m_joystick ? m_joystick->GetTwistChannel()
: Joystick::kDefaultTwistChannel,
value);
}
void SetTwist(double value);
void SetThrottle(double value) {
SetRawAxis(m_joystick ? m_joystick->GetThrottleChannel()
: Joystick::kDefaultThrottleChannel,
value);
}
void SetThrottle(double value);
void SetTrigger(bool state) { SetRawButton(1, state); }
void SetTrigger(bool state);
void SetTop(bool state) { SetRawButton(2, state); }
void SetTop(bool state);
private:
const Joystick* m_joystick = nullptr;

View File

@@ -8,15 +8,13 @@
#pragma once
#include <memory>
#include <utility>
#include <hal/simulation/PCMData.h>
#include "CallbackStore.h"
#include "frc/Compressor.h"
#include "frc/SensorUtil.h"
#include "frc/simulation/CallbackStore.h"
namespace frc {
class Compressor;
namespace sim {
/**
@@ -24,152 +22,79 @@ namespace sim {
*/
class PCMSim {
public:
/**
* Constructs with the default PCM module number (CAN ID).
*/
PCMSim();
/**
* Constructs from a PCM module number (CAN ID).
*
* @param module module number
*/
explicit PCMSim(int module = SensorUtil::GetDefaultSolenoidModule())
: m_index{module} {}
explicit PCMSim(int module);
/**
* Constructs from a Compressor object.
*
* @param compressor Compressor connected to PCM to simulate
*/
explicit PCMSim(const Compressor& compressor)
: m_index{compressor.GetModule()} {}
explicit PCMSim(const Compressor& compressor);
std::unique_ptr<CallbackStore> RegisterSolenoidInitializedCallback(
int channel, NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, channel, -1, callback,
&HALSIM_CancelPCMSolenoidInitializedCallback);
store->SetUid(HALSIM_RegisterPCMSolenoidInitializedCallback(
m_index, channel, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
int channel, NotifyCallback callback, bool initialNotify);
bool GetSolenoidInitialized(int channel) const {
return HALSIM_GetPCMSolenoidInitialized(m_index, channel);
}
bool GetSolenoidInitialized(int channel) const;
void SetSolenoidInitialized(int channel, bool solenoidInitialized) {
HALSIM_SetPCMSolenoidInitialized(m_index, channel, solenoidInitialized);
}
void SetSolenoidInitialized(int channel, bool solenoidInitialized);
std::unique_ptr<CallbackStore> RegisterSolenoidOutputCallback(
int channel, NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, channel, -1, callback,
&HALSIM_CancelPCMSolenoidOutputCallback);
store->SetUid(HALSIM_RegisterPCMSolenoidOutputCallback(
m_index, channel, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
int channel, NotifyCallback callback, bool initialNotify);
bool GetSolenoidOutput(int channel) const {
return HALSIM_GetPCMSolenoidOutput(m_index, channel);
}
bool GetSolenoidOutput(int channel) const;
void SetSolenoidOutput(int channel, bool solenoidOutput) {
HALSIM_SetPCMSolenoidOutput(m_index, channel, solenoidOutput);
}
void SetSolenoidOutput(int channel, bool solenoidOutput);
std::unique_ptr<CallbackStore> RegisterCompressorInitializedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPCMCompressorInitializedCallback);
store->SetUid(HALSIM_RegisterPCMCompressorInitializedCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
bool GetCompressorInitialized() const {
return HALSIM_GetPCMCompressorInitialized(m_index);
}
bool GetCompressorInitialized() const;
void SetCompressorInitialized(bool compressorInitialized) {
HALSIM_SetPCMCompressorInitialized(m_index, compressorInitialized);
}
void SetCompressorInitialized(bool compressorInitialized);
std::unique_ptr<CallbackStore> RegisterCompressorOnCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPCMCompressorOnCallback);
store->SetUid(HALSIM_RegisterPCMCompressorOnCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
bool GetCompressorOn() const { return HALSIM_GetPCMCompressorOn(m_index); }
bool GetCompressorOn() const;
void SetCompressorOn(bool compressorOn) {
HALSIM_SetPCMCompressorOn(m_index, compressorOn);
}
void SetCompressorOn(bool compressorOn);
std::unique_ptr<CallbackStore> RegisterClosedLoopEnabledCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPCMClosedLoopEnabledCallback);
store->SetUid(HALSIM_RegisterPCMClosedLoopEnabledCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
bool GetClosedLoopEnabled() const {
return HALSIM_GetPCMClosedLoopEnabled(m_index);
}
bool GetClosedLoopEnabled() const;
void SetClosedLoopEnabled(bool closedLoopEnabled) {
HALSIM_SetPCMClosedLoopEnabled(m_index, closedLoopEnabled);
}
void SetClosedLoopEnabled(bool closedLoopEnabled);
std::unique_ptr<CallbackStore> RegisterPressureSwitchCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPCMPressureSwitchCallback);
store->SetUid(HALSIM_RegisterPCMPressureSwitchCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
bool GetPressureSwitch() const {
return HALSIM_GetPCMPressureSwitch(m_index);
}
bool GetPressureSwitch() const;
void SetPressureSwitch(bool pressureSwitch) {
HALSIM_SetPCMPressureSwitch(m_index, pressureSwitch);
}
void SetPressureSwitch(bool pressureSwitch);
std::unique_ptr<CallbackStore> RegisterCompressorCurrentCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPCMCompressorCurrentCallback);
store->SetUid(HALSIM_RegisterPCMCompressorCurrentCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
double GetCompressorCurrent() const {
return HALSIM_GetPCMCompressorCurrent(m_index);
}
double GetCompressorCurrent() const;
void SetCompressorCurrent(double compressorCurrent) {
HALSIM_SetPCMCompressorCurrent(m_index, compressorCurrent);
}
void SetCompressorCurrent(double compressorCurrent);
uint8_t GetAllSolenoidOutputs() {
uint8_t ret = 0;
HALSIM_GetPCMAllSolenoids(m_index, &ret);
return ret;
}
uint8_t GetAllSolenoidOutputs() const;
void SetAllSolenoidOutputs(uint8_t outputs) {
HALSIM_SetPCMAllSolenoids(m_index, outputs);
}
void SetAllSolenoidOutputs(uint8_t outputs);
void ResetData() { HALSIM_ResetPCMData(m_index); }
void ResetData();
private:
int m_index;

View File

@@ -8,14 +8,13 @@
#pragma once
#include <memory>
#include <utility>
#include <hal/simulation/PDPData.h>
#include "CallbackStore.h"
#include "frc/PowerDistributionPanel.h"
#include "frc/simulation/CallbackStore.h"
namespace frc {
class PowerDistributionPanel;
namespace sim {
/**
@@ -28,85 +27,48 @@ class PDPSim {
*
* @param module module number
*/
explicit PDPSim(int module = 0) : m_index{module} {}
explicit PDPSim(int module = 0);
/**
* Constructs from a PowerDistributionPanel object.
*
* @param pdp PowerDistributionPanel to simulate
*/
explicit PDPSim(const PowerDistributionPanel& pdp)
: m_index{pdp.GetModule()} {}
explicit PDPSim(const PowerDistributionPanel& pdp);
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPDPInitializedCallback);
store->SetUid(HALSIM_RegisterPDPInitializedCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
bool GetInitialized() const { return HALSIM_GetPDPInitialized(m_index); }
bool GetInitialized() const;
void SetInitialized(bool initialized) {
HALSIM_SetPDPInitialized(m_index, initialized);
}
void SetInitialized(bool initialized);
std::unique_ptr<CallbackStore> RegisterTemperatureCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPDPTemperatureCallback);
store->SetUid(HALSIM_RegisterPDPTemperatureCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
double GetTemperature() const { return HALSIM_GetPDPTemperature(m_index); }
double GetTemperature() const;
void SetTemperature(double temperature) {
HALSIM_SetPDPTemperature(m_index, temperature);
}
void SetTemperature(double temperature);
std::unique_ptr<CallbackStore> RegisterVoltageCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPDPVoltageCallback);
store->SetUid(HALSIM_RegisterPDPVoltageCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
double GetVoltage() const { return HALSIM_GetPDPVoltage(m_index); }
double GetVoltage() const;
void SetVoltage(double voltage) { HALSIM_SetPDPVoltage(m_index, voltage); }
void SetVoltage(double voltage);
std::unique_ptr<CallbackStore> RegisterCurrentCallback(
int channel, NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, channel, -1, callback, &HALSIM_CancelPDPCurrentCallback);
store->SetUid(HALSIM_RegisterPDPCurrentCallback(
m_index, channel, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
int channel, NotifyCallback callback, bool initialNotify);
double GetCurrent(int channel) const {
return HALSIM_GetPDPCurrent(m_index, channel);
}
double GetCurrent(int channel) const;
void SetCurrent(int channel, double current) {
HALSIM_SetPDPCurrent(m_index, channel, current);
}
void SetCurrent(int channel, double current);
void GetAllCurrents(double* currents) {
HALSIM_GetPDPAllCurrents(m_index, currents);
}
void GetAllCurrents(double* currents) const;
void SetAllCurrents(const double* currents) {
HALSIM_SetPDPAllCurrents(m_index, currents);
}
void SetAllCurrents(const double* currents);
void ResetData() { HALSIM_ResetPDPData(m_index); }
void ResetData();
private:
int m_index;

View File

@@ -8,14 +8,13 @@
#pragma once
#include <memory>
#include <utility>
#include <hal/simulation/PWMData.h>
#include "CallbackStore.h"
#include "frc/PWM.h"
#include "frc/simulation/CallbackStore.h"
namespace frc {
class PWM;
namespace sim {
/**
@@ -28,102 +27,58 @@ class PWMSim {
*
* @param pwm PWM to simulate
*/
explicit PWMSim(const PWM& pwm) : m_index{pwm.GetChannel()} {}
explicit PWMSim(const PWM& pwm);
/**
* Constructs from a PWM channel number.
*
* @param channel Channel number
*/
explicit PWMSim(int channel) : m_index{channel} {}
explicit PWMSim(int channel);
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPWMInitializedCallback);
store->SetUid(HALSIM_RegisterPWMInitializedCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
bool GetInitialized() const { return HALSIM_GetPWMInitialized(m_index); }
bool GetInitialized() const;
void SetInitialized(bool initialized) {
HALSIM_SetPWMInitialized(m_index, initialized);
}
void SetInitialized(bool initialized);
std::unique_ptr<CallbackStore> RegisterRawValueCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPWMRawValueCallback);
store->SetUid(HALSIM_RegisterPWMRawValueCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
int GetRawValue() const { return HALSIM_GetPWMRawValue(m_index); }
int GetRawValue() const;
void SetRawValue(int rawValue) { HALSIM_SetPWMRawValue(m_index, rawValue); }
void SetRawValue(int rawValue);
std::unique_ptr<CallbackStore> RegisterSpeedCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPWMSpeedCallback);
store->SetUid(HALSIM_RegisterPWMSpeedCallback(m_index, &CallbackStoreThunk,
store.get(), initialNotify));
return store;
}
bool initialNotify);
double GetSpeed() const { return HALSIM_GetPWMSpeed(m_index); }
double GetSpeed() const;
void SetSpeed(double speed) { HALSIM_SetPWMSpeed(m_index, speed); }
void SetSpeed(double speed);
std::unique_ptr<CallbackStore> RegisterPositionCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPWMPositionCallback);
store->SetUid(HALSIM_RegisterPWMPositionCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
double GetPosition() const { return HALSIM_GetPWMPosition(m_index); }
double GetPosition() const;
void SetPosition(double position) {
HALSIM_SetPWMPosition(m_index, position);
}
void SetPosition(double position);
std::unique_ptr<CallbackStore> RegisterPeriodScaleCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPWMPeriodScaleCallback);
store->SetUid(HALSIM_RegisterPWMPeriodScaleCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
int GetPeriodScale() const { return HALSIM_GetPWMPeriodScale(m_index); }
int GetPeriodScale() const;
void SetPeriodScale(int periodScale) {
HALSIM_SetPWMPeriodScale(m_index, periodScale);
}
void SetPeriodScale(int periodScale);
std::unique_ptr<CallbackStore> RegisterZeroLatchCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPWMZeroLatchCallback);
store->SetUid(HALSIM_RegisterPWMZeroLatchCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
bool GetZeroLatch() const { return HALSIM_GetPWMZeroLatch(m_index); }
bool GetZeroLatch() const;
void SetZeroLatch(bool zeroLatch) {
HALSIM_SetPWMZeroLatch(m_index, zeroLatch);
}
void SetZeroLatch(bool zeroLatch);
void ResetData() { HALSIM_ResetPWMData(m_index); }
void ResetData();
private:
int m_index;

View File

@@ -8,14 +8,13 @@
#pragma once
#include <memory>
#include <utility>
#include <hal/simulation/RelayData.h>
#include "CallbackStore.h"
#include "frc/Relay.h"
#include "frc/simulation/CallbackStore.h"
namespace frc {
class Relay;
namespace sim {
/**
@@ -28,76 +27,44 @@ class RelaySim {
*
* @param relay Relay to simulate
*/
explicit RelaySim(const Relay& relay) : m_index{relay.GetChannel()} {}
explicit RelaySim(const Relay& relay);
/**
* Constructs from a relay channel number.
*
* @param channel Channel number
*/
explicit RelaySim(int channel) : m_index{channel} {}
explicit RelaySim(int channel);
std::unique_ptr<CallbackStore> RegisterInitializedForwardCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelRelayInitializedForwardCallback);
store->SetUid(HALSIM_RegisterRelayInitializedForwardCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
bool GetInitializedForward() const {
return HALSIM_GetRelayInitializedForward(m_index);
}
bool GetInitializedForward() const;
void SetInitializedForward(bool initializedForward) {
HALSIM_SetRelayInitializedForward(m_index, initializedForward);
}
void SetInitializedForward(bool initializedForward);
std::unique_ptr<CallbackStore> RegisterInitializedReverseCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelRelayInitializedReverseCallback);
store->SetUid(HALSIM_RegisterRelayInitializedReverseCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
bool GetInitializedReverse() const {
return HALSIM_GetRelayInitializedReverse(m_index);
}
bool GetInitializedReverse() const;
void SetInitializedReverse(bool initializedReverse) {
HALSIM_SetRelayInitializedReverse(m_index, initializedReverse);
}
void SetInitializedReverse(bool initializedReverse);
std::unique_ptr<CallbackStore> RegisterForwardCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelRelayForwardCallback);
store->SetUid(HALSIM_RegisterRelayForwardCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
bool GetForward() const { return HALSIM_GetRelayForward(m_index); }
bool GetForward() const;
void SetForward(bool forward) { HALSIM_SetRelayForward(m_index, forward); }
void SetForward(bool forward);
std::unique_ptr<CallbackStore> RegisterReverseCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelRelayReverseCallback);
store->SetUid(HALSIM_RegisterRelayReverseCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
bool GetReverse() const { return HALSIM_GetRelayReverse(m_index); }
bool GetReverse() const;
void SetReverse(bool reverse) { HALSIM_SetRelayReverse(m_index, reverse); }
void SetReverse(bool reverse);
void ResetData() { HALSIM_ResetRelayData(m_index); }
void ResetData();
private:
int m_index;

View File

@@ -8,11 +8,8 @@
#pragma once
#include <memory>
#include <utility>
#include <hal/simulation/RoboRioData.h>
#include "CallbackStore.h"
#include "frc/simulation/CallbackStore.h"
namespace frc {
namespace sim {
@@ -23,235 +20,111 @@ namespace sim {
class RoboRioSim {
public:
static std::unique_ptr<CallbackStore> RegisterFPGAButtonCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioFPGAButtonCallback);
store->SetUid(HALSIM_RegisterRoboRioFPGAButtonCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
static bool GetFPGAButton() { return HALSIM_GetRoboRioFPGAButton(); }
static bool GetFPGAButton();
static void SetFPGAButton(bool fPGAButton) {
HALSIM_SetRoboRioFPGAButton(fPGAButton);
}
static void SetFPGAButton(bool fPGAButton);
static std::unique_ptr<CallbackStore> RegisterVInVoltageCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioVInVoltageCallback);
store->SetUid(HALSIM_RegisterRoboRioVInVoltageCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
static double GetVInVoltage() { return HALSIM_GetRoboRioVInVoltage(); }
static double GetVInVoltage();
static void SetVInVoltage(double vInVoltage) {
HALSIM_SetRoboRioVInVoltage(vInVoltage);
}
static void SetVInVoltage(double vInVoltage);
static std::unique_ptr<CallbackStore> RegisterVInCurrentCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioVInCurrentCallback);
store->SetUid(HALSIM_RegisterRoboRioVInCurrentCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
static double GetVInCurrent() { return HALSIM_GetRoboRioVInCurrent(); }
static double GetVInCurrent();
static void SetVInCurrent(double vInCurrent) {
HALSIM_SetRoboRioVInCurrent(vInCurrent);
}
static void SetVInCurrent(double vInCurrent);
static std::unique_ptr<CallbackStore> RegisterUserVoltage6VCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioUserVoltage6VCallback);
store->SetUid(HALSIM_RegisterRoboRioUserVoltage6VCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
static double GetUserVoltage6V() { return HALSIM_GetRoboRioUserVoltage6V(); }
static double GetUserVoltage6V();
static void SetUserVoltage6V(double userVoltage6V) {
HALSIM_SetRoboRioUserVoltage6V(userVoltage6V);
}
static void SetUserVoltage6V(double userVoltage6V);
static std::unique_ptr<CallbackStore> RegisterUserCurrent6VCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioUserCurrent6VCallback);
store->SetUid(HALSIM_RegisterRoboRioUserCurrent6VCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
static double GetUserCurrent6V() { return HALSIM_GetRoboRioUserCurrent6V(); }
static double GetUserCurrent6V();
static void SetUserCurrent6V(double userCurrent6V) {
HALSIM_SetRoboRioUserCurrent6V(userCurrent6V);
}
static void SetUserCurrent6V(double userCurrent6V);
static std::unique_ptr<CallbackStore> RegisterUserActive6VCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioUserActive6VCallback);
store->SetUid(HALSIM_RegisterRoboRioUserActive6VCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
static bool GetUserActive6V() { return HALSIM_GetRoboRioUserActive6V(); }
static bool GetUserActive6V();
static void SetUserActive6V(bool userActive6V) {
HALSIM_SetRoboRioUserActive6V(userActive6V);
}
static void SetUserActive6V(bool userActive6V);
static std::unique_ptr<CallbackStore> RegisterUserVoltage5VCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioUserVoltage5VCallback);
store->SetUid(HALSIM_RegisterRoboRioUserVoltage5VCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
static double GetUserVoltage5V() { return HALSIM_GetRoboRioUserVoltage5V(); }
static double GetUserVoltage5V();
static void SetUserVoltage5V(double userVoltage5V) {
HALSIM_SetRoboRioUserVoltage5V(userVoltage5V);
}
static void SetUserVoltage5V(double userVoltage5V);
static std::unique_ptr<CallbackStore> RegisterUserCurrent5VCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioUserCurrent5VCallback);
store->SetUid(HALSIM_RegisterRoboRioUserCurrent5VCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
static double GetUserCurrent5V() { return HALSIM_GetRoboRioUserCurrent5V(); }
static double GetUserCurrent5V();
static void SetUserCurrent5V(double userCurrent5V) {
HALSIM_SetRoboRioUserCurrent5V(userCurrent5V);
}
static void SetUserCurrent5V(double userCurrent5V);
static std::unique_ptr<CallbackStore> RegisterUserActive5VCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioUserActive5VCallback);
store->SetUid(HALSIM_RegisterRoboRioUserActive5VCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
static bool GetUserActive5V() { return HALSIM_GetRoboRioUserActive5V(); }
static bool GetUserActive5V();
static void SetUserActive5V(bool userActive5V) {
HALSIM_SetRoboRioUserActive5V(userActive5V);
}
static void SetUserActive5V(bool userActive5V);
static std::unique_ptr<CallbackStore> RegisterUserVoltage3V3Callback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioUserVoltage3V3Callback);
store->SetUid(HALSIM_RegisterRoboRioUserVoltage3V3Callback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
static double GetUserVoltage3V3() {
return HALSIM_GetRoboRioUserVoltage3V3();
}
static double GetUserVoltage3V3();
static void SetUserVoltage3V3(double userVoltage3V3) {
HALSIM_SetRoboRioUserVoltage3V3(userVoltage3V3);
}
static void SetUserVoltage3V3(double userVoltage3V3);
static std::unique_ptr<CallbackStore> RegisterUserCurrent3V3Callback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioUserCurrent3V3Callback);
store->SetUid(HALSIM_RegisterRoboRioUserCurrent3V3Callback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
static double GetUserCurrent3V3() {
return HALSIM_GetRoboRioUserCurrent3V3();
}
static double GetUserCurrent3V3();
static void SetUserCurrent3V3(double userCurrent3V3) {
HALSIM_SetRoboRioUserCurrent3V3(userCurrent3V3);
}
static void SetUserCurrent3V3(double userCurrent3V3);
static std::unique_ptr<CallbackStore> RegisterUserActive3V3Callback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioUserActive3V3Callback);
store->SetUid(HALSIM_RegisterRoboRioUserActive3V3Callback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
static bool GetUserActive3V3() { return HALSIM_GetRoboRioUserActive3V3(); }
static bool GetUserActive3V3();
static void SetUserActive3V3(bool userActive3V3) {
HALSIM_SetRoboRioUserActive3V3(userActive3V3);
}
static void SetUserActive3V3(bool userActive3V3);
static std::unique_ptr<CallbackStore> RegisterUserFaults6VCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioUserFaults6VCallback);
store->SetUid(HALSIM_RegisterRoboRioUserFaults6VCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
static int GetUserFaults6V() { return HALSIM_GetRoboRioUserFaults6V(); }
static int GetUserFaults6V();
static void SetUserFaults6V(int userFaults6V) {
HALSIM_SetRoboRioUserFaults6V(userFaults6V);
}
static void SetUserFaults6V(int userFaults6V);
static std::unique_ptr<CallbackStore> RegisterUserFaults5VCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioUserFaults5VCallback);
store->SetUid(HALSIM_RegisterRoboRioUserFaults5VCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
static int GetUserFaults5V() { return HALSIM_GetRoboRioUserFaults5V(); }
static int GetUserFaults5V();
static void SetUserFaults5V(int userFaults5V) {
HALSIM_SetRoboRioUserFaults5V(userFaults5V);
}
static void SetUserFaults5V(int userFaults5V);
static std::unique_ptr<CallbackStore> RegisterUserFaults3V3Callback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioUserFaults3V3Callback);
store->SetUid(HALSIM_RegisterRoboRioUserFaults3V3Callback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
NotifyCallback callback, bool initialNotify);
static int GetUserFaults3V3() { return HALSIM_GetRoboRioUserFaults3V3(); }
static int GetUserFaults3V3();
static void SetUserFaults3V3(int userFaults3V3) {
HALSIM_SetRoboRioUserFaults3V3(userFaults3V3);
}
static void SetUserFaults3V3(int userFaults3V3);
static void ResetData() { HALSIM_ResetRoboRioData(); }
static void ResetData();
};
} // namespace sim
} // namespace frc

View File

@@ -8,86 +8,51 @@
#pragma once
#include <memory>
#include <utility>
#include <hal/simulation/SPIAccelerometerData.h>
#include "CallbackStore.h"
#include "frc/simulation/CallbackStore.h"
namespace frc {
namespace sim {
class SPIAccelerometerSim {
public:
explicit SPIAccelerometerSim(int index) { m_index = index; }
explicit SPIAccelerometerSim(int index);
std::unique_ptr<CallbackStore> RegisterActiveCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelSPIAccelerometerActiveCallback);
store->SetUid(HALSIM_RegisterSPIAccelerometerActiveCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool initialNotify);
bool GetActive() const { return HALSIM_GetSPIAccelerometerActive(m_index); }
bool GetActive() const;
void SetActive(bool active) {
HALSIM_SetSPIAccelerometerActive(m_index, active);
}
void SetActive(bool active);
std::unique_ptr<CallbackStore> RegisterRangeCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelSPIAccelerometerRangeCallback);
store->SetUid(HALSIM_RegisterSPIAccelerometerRangeCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool initialNotify);
int GetRange() const { return HALSIM_GetSPIAccelerometerRange(m_index); }
int GetRange() const;
void SetRange(int range) { HALSIM_SetSPIAccelerometerRange(m_index, range); }
void SetRange(int range);
std::unique_ptr<CallbackStore> RegisterXCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelSPIAccelerometerXCallback);
store->SetUid(HALSIM_RegisterSPIAccelerometerXCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool initialNotify);
double GetX() const { return HALSIM_GetSPIAccelerometerX(m_index); }
double GetX() const;
void SetX(double x) { HALSIM_SetSPIAccelerometerX(m_index, x); }
void SetX(double x);
std::unique_ptr<CallbackStore> RegisterYCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelSPIAccelerometerYCallback);
store->SetUid(HALSIM_RegisterSPIAccelerometerYCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool initialNotify);
double GetY() const { return HALSIM_GetSPIAccelerometerY(m_index); }
double GetY() const;
void SetY(double y) { HALSIM_SetSPIAccelerometerY(m_index, y); }
void SetY(double y);
std::unique_ptr<CallbackStore> RegisterZCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelSPIAccelerometerZCallback);
store->SetUid(HALSIM_RegisterSPIAccelerometerZCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool initialNotify);
double GetZ() const { return HALSIM_GetSPIAccelerometerZ(m_index); }
double GetZ() const;
void SetZ(double z) { HALSIM_SetSPIAccelerometerZ(m_index, z); }
void SetZ(double z);
void ResetData() { HALSIM_ResetSPIAccelerometerData(m_index); }
void ResetData();
private:
int m_index;

View File

@@ -8,16 +8,12 @@
#pragma once
#include <functional>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include <hal/SimDevice.h>
#include <hal/simulation/SimDeviceData.h>
#include "CallbackStore.h"
namespace frc {
namespace sim {
@@ -31,33 +27,17 @@ class SimDeviceSim {
*
* @param name name of the SimDevice
*/
explicit SimDeviceSim(const char* name)
: m_handle{HALSIM_GetSimDeviceHandle(name)} {}
explicit SimDeviceSim(const char* name);
hal::SimValue GetValue(const char* name) const {
return HALSIM_GetSimValueHandle(m_handle, name);
}
hal::SimValue GetValue(const char* name) const;
hal::SimDouble GetDouble(const char* name) const {
return HALSIM_GetSimValueHandle(m_handle, name);
}
hal::SimDouble GetDouble(const char* name) const;
hal::SimEnum GetEnum(const char* name) const {
return HALSIM_GetSimValueHandle(m_handle, name);
}
hal::SimEnum GetEnum(const char* name) const;
hal::SimBoolean GetBoolean(const char* name) const {
return HALSIM_GetSimValueHandle(m_handle, name);
}
hal::SimBoolean GetBoolean(const char* name) const;
static std::vector<std::string> GetEnumOptions(hal::SimEnum val) {
int32_t numOptions;
const char** options = HALSIM_GetSimValueEnumOptions(val, &numOptions);
std::vector<std::string> rv;
rv.reserve(numOptions);
for (int32_t i = 0; i < numOptions; ++i) rv.emplace_back(options[i]);
return rv;
}
static std::vector<std::string> GetEnumOptions(hal::SimEnum val);
template <typename F>
void EnumerateValues(F callback) const {
@@ -80,7 +60,7 @@ class SimDeviceSim {
});
}
static void ResetData() { HALSIM_ResetSimDeviceData(); }
static void ResetData();
private:
HAL_SimDeviceHandle m_handle;

View File

@@ -7,30 +7,30 @@
#pragma once
#include <hal/simulation/MockHooks.h>
#include <stdint.h>
#include <hal/HALBase.h>
namespace frc {
namespace sim {
inline void SetRuntimeType(HAL_RuntimeType type) {
HALSIM_SetRuntimeType(type);
}
void SetRuntimeType(HAL_RuntimeType type);
inline void WaitForProgramStart() { HALSIM_WaitForProgramStart(); }
void WaitForProgramStart();
inline void SetProgramStarted() { HALSIM_SetProgramStarted(); }
void SetProgramStarted();
inline bool GetProgramStarted() { return HALSIM_GetProgramStarted(); }
bool GetProgramStarted();
inline void RestartTiming() { HALSIM_RestartTiming(); }
void RestartTiming();
inline void PauseTiming() { HALSIM_PauseTiming(); }
void PauseTiming();
inline void ResumeTiming() { HALSIM_ResumeTiming(); }
void ResumeTiming();
inline bool IsTimingPaused() { return HALSIM_IsTimingPaused(); }
bool IsTimingPaused();
inline void StepTiming(uint64_t delta) { HALSIM_StepTiming(delta); }
void StepTiming(uint64_t delta);
} // namespace sim
} // namespace frc

View File

@@ -7,10 +7,12 @@
#pragma once
#include "frc/XboxController.h"
#include "frc/simulation/GenericHIDSim.h"
namespace frc {
class XboxController;
namespace sim {
/**
@@ -23,88 +25,36 @@ class XboxControllerSim : public GenericHIDSim {
*
* @param joystick controller to simulate
*/
explicit XboxControllerSim(const XboxController& joystick)
: GenericHIDSim{joystick} {
SetAxisCount(6);
SetButtonCount(10);
}
explicit XboxControllerSim(const XboxController& joystick);
/**
* Constructs from a joystick port number.
*
* @param port port number
*/
explicit XboxControllerSim(int port) : GenericHIDSim{port} {
SetAxisCount(6);
SetButtonCount(10);
}
explicit XboxControllerSim(int port);
void SetX(GenericHID::JoystickHand hand, double value) {
if (hand == GenericHID::kLeftHand) {
SetRawAxis(static_cast<int>(XboxController::Axis::kLeftX), value);
} else {
SetRawAxis(static_cast<int>(XboxController::Axis::kRightX), value);
}
}
void SetX(GenericHID::JoystickHand hand, double value);
void SetY(GenericHID::JoystickHand hand, double value) {
if (hand == GenericHID::kLeftHand) {
SetRawAxis(static_cast<int>(XboxController::Axis::kLeftY), value);
} else {
SetRawAxis(static_cast<int>(XboxController::Axis::kRightY), value);
}
}
void SetY(GenericHID::JoystickHand hand, double value);
void SetTriggerAxis(GenericHID::JoystickHand hand, double value) {
if (hand == GenericHID::kLeftHand) {
SetRawAxis(static_cast<int>(XboxController::Axis::kLeftTrigger), value);
} else {
SetRawAxis(static_cast<int>(XboxController::Axis::kRightTrigger), value);
}
}
void SetTriggerAxis(GenericHID::JoystickHand hand, double value);
void SetBumper(GenericHID::JoystickHand hand, bool state) {
if (hand == GenericHID::kLeftHand) {
SetRawButton(static_cast<int>(XboxController::Button::kBumperLeft),
state);
} else {
SetRawButton(static_cast<int>(XboxController::Button::kBumperRight),
state);
}
}
void SetBumper(GenericHID::JoystickHand hand, bool state);
void SetStickButton(GenericHID::JoystickHand hand, bool state) {
if (hand == GenericHID::kLeftHand) {
SetRawButton(static_cast<int>(XboxController::Button::kStickLeft), state);
} else {
SetRawButton(static_cast<int>(XboxController::Button::kStickRight),
state);
}
}
void SetStickButton(GenericHID::JoystickHand hand, bool state);
void SetAButton(bool state) {
SetRawButton(static_cast<int>(XboxController::Button::kA), state);
}
void SetAButton(bool state);
void SetBButton(bool state) {
SetRawButton(static_cast<int>(XboxController::Button::kB), state);
}
void SetBButton(bool state);
void SetXButton(bool state) {
SetRawButton(static_cast<int>(XboxController::Button::kX), state);
}
void SetXButton(bool state);
void SetYButton(bool state) {
SetRawButton(static_cast<int>(XboxController::Button::kY), state);
}
void SetYButton(bool state);
void SetBackButton(bool state) {
SetRawButton(static_cast<int>(XboxController::Button::kBack), state);
}
void SetBackButton(bool state);
void SetStartButton(bool state) {
SetRawButton(static_cast<int>(XboxController::Button::kStart), state);
}
void SetStartButton(bool state);
};
} // namespace sim