mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
[sim] Add WPILib-class-taking constructors (#2538)
When not direct mapped, make index constructors private and add factory functions for channel and index. Co-authored-by: GabrielDeml <gabrielddeml@gmail.com>
This commit is contained in:
@@ -0,0 +1,154 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <exception>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include <hal/simulation/AddressableLEDData.h>
|
||||
#include <wpi/ArrayRef.h>
|
||||
|
||||
#include "CallbackStore.h"
|
||||
#include "frc/AddressableLED.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
|
||||
/**
|
||||
* Class to control a simulated addressable LED.
|
||||
*/
|
||||
class AddressableLEDSim {
|
||||
public:
|
||||
/**
|
||||
* Constructs for the first addressable LED.
|
||||
*/
|
||||
AddressableLEDSim() : m_index{0} {}
|
||||
|
||||
/**
|
||||
* Constructs from an AddressableLED object.
|
||||
*
|
||||
* @param addressableLED AddressableLED to simulate
|
||||
*/
|
||||
explicit AddressableLEDSim(const AddressableLED& addressableLED)
|
||||
: m_index{0} {}
|
||||
|
||||
/**
|
||||
* Creates an AddressableLEDSim for a PWM channel.
|
||||
*
|
||||
* @param pwmChannel PWM channel
|
||||
* @return Simulated object
|
||||
* @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};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an AddressableLEDSim for a simulated index.
|
||||
* The index is incremented for each simulated AddressableLED.
|
||||
*
|
||||
* @param index simulator index
|
||||
* @return Simulated object
|
||||
*/
|
||||
static AddressableLEDSim CreateForIndex(int index) {
|
||||
return AddressableLEDSim{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;
|
||||
}
|
||||
|
||||
bool GetInitialized() const {
|
||||
return HALSIM_GetAddressableLEDInitialized(m_index);
|
||||
}
|
||||
|
||||
void SetInitialized(bool initialized) {
|
||||
HALSIM_SetAddressableLEDInitialized(m_index, 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;
|
||||
}
|
||||
|
||||
int GetOutputPort() const {
|
||||
return HALSIM_GetAddressableLEDOutputPort(m_index);
|
||||
}
|
||||
|
||||
void SetOutputPort(int outputPort) {
|
||||
HALSIM_SetAddressableLEDOutputPort(m_index, 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;
|
||||
}
|
||||
|
||||
int GetLength() const { return HALSIM_GetAddressableLEDLength(m_index); }
|
||||
|
||||
void SetLength(int length) {
|
||||
HALSIM_SetAddressableLEDLength(m_index, 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;
|
||||
}
|
||||
|
||||
int GetRunning() const { return HALSIM_GetAddressableLEDRunning(m_index); }
|
||||
|
||||
void SetRunning(bool running) {
|
||||
HALSIM_SetAddressableLEDRunning(m_index, 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;
|
||||
}
|
||||
|
||||
int GetData(struct HAL_AddressableLEDData* data) const {
|
||||
return HALSIM_GetAddressableLEDData(m_index, data);
|
||||
}
|
||||
|
||||
void SetData(struct HAL_AddressableLEDData* data, int length) {
|
||||
HALSIM_SetAddressableLEDData(m_index, data, length);
|
||||
}
|
||||
|
||||
private:
|
||||
explicit AddressableLEDSim(int index) : m_index{index} {}
|
||||
|
||||
int m_index;
|
||||
};
|
||||
} // namespace sim
|
||||
} // namespace frc
|
||||
@@ -13,12 +13,31 @@
|
||||
#include <hal/simulation/AnalogGyroData.h>
|
||||
|
||||
#include "CallbackStore.h"
|
||||
#include "frc/AnalogGyro.h"
|
||||
#include "frc/AnalogInput.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
|
||||
/**
|
||||
* Class to control a simulated analog gyro.
|
||||
*/
|
||||
class AnalogGyroSim {
|
||||
public:
|
||||
explicit AnalogGyroSim(int index) { m_index = index; }
|
||||
/**
|
||||
* Constructs from an AnalogGyro object.
|
||||
*
|
||||
* @param gyro AnalogGyro to simulate
|
||||
*/
|
||||
explicit AnalogGyroSim(const AnalogGyro& gyro)
|
||||
: m_index{gyro.GetAnalogInput()->GetChannel()} {}
|
||||
|
||||
/**
|
||||
* Constructs from an analog input channel number.
|
||||
*
|
||||
* @param channel Channel number
|
||||
*/
|
||||
explicit AnalogGyroSim(int channel) : m_index{channel} {}
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterAngleCallback(NotifyCallback callback,
|
||||
bool initialNotify) {
|
||||
|
||||
@@ -13,12 +13,30 @@
|
||||
#include <hal/simulation/AnalogInData.h>
|
||||
|
||||
#include "CallbackStore.h"
|
||||
#include "frc/AnalogInput.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
class AnalogInSim {
|
||||
|
||||
/**
|
||||
* Class to control a simulated analog input.
|
||||
*/
|
||||
class AnalogInputSim {
|
||||
public:
|
||||
explicit AnalogInSim(int index) { m_index = index; }
|
||||
/**
|
||||
* Constructs from an AnalogInput object.
|
||||
*
|
||||
* @param analogInput AnalogInput to simulate
|
||||
*/
|
||||
explicit AnalogInputSim(const AnalogInput& analogInput)
|
||||
: m_index{analogInput.GetChannel()} {}
|
||||
|
||||
/**
|
||||
* Constructs from an analog input channel number.
|
||||
*
|
||||
* @param channel Channel number
|
||||
*/
|
||||
explicit AnalogInputSim(int channel) : m_index{channel} {}
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
@@ -13,12 +13,30 @@
|
||||
#include <hal/simulation/AnalogOutData.h>
|
||||
|
||||
#include "CallbackStore.h"
|
||||
#include "frc/AnalogOutput.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
class AnalogOutSim {
|
||||
|
||||
/**
|
||||
* Class to control a simulated analog output.
|
||||
*/
|
||||
class AnalogOutputSim {
|
||||
public:
|
||||
explicit AnalogOutSim(int index) { m_index = index; }
|
||||
/**
|
||||
* Constructs from an AnalogOutput object.
|
||||
*
|
||||
* @param analogOutput AnalogOutput to simulate
|
||||
*/
|
||||
explicit AnalogOutputSim(const AnalogOutput& analogOutput)
|
||||
: m_index{analogOutput.GetChannel()} {}
|
||||
|
||||
/**
|
||||
* Constructs from an analog output channel number.
|
||||
*
|
||||
* @param channel Channel number
|
||||
*/
|
||||
explicit AnalogOutputSim(int channel) : m_index{channel} {}
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterVoltageCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
@@ -7,18 +7,56 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <exception>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include <hal/simulation/AnalogTriggerData.h>
|
||||
|
||||
#include "CallbackStore.h"
|
||||
#include "frc/AnalogTrigger.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
|
||||
/**
|
||||
* Class to control a simulated analog trigger.
|
||||
*/
|
||||
class AnalogTriggerSim {
|
||||
public:
|
||||
explicit AnalogTriggerSim(int index) { m_index = index; }
|
||||
/**
|
||||
* Constructs from an AnalogTrigger object.
|
||||
*
|
||||
* @param analogTrigger AnalogTrigger to simulate
|
||||
*/
|
||||
explicit AnalogTriggerSim(const AnalogTrigger& analogTrigger)
|
||||
: m_index{analogTrigger.GetIndex()} {}
|
||||
|
||||
/**
|
||||
* Creates an AnalogTriggerSim for an analog input channel.
|
||||
*
|
||||
* @param channel analog input channel
|
||||
* @return Simulated object
|
||||
* @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};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an AnalogTriggerSim for a simulated index.
|
||||
* The index is incremented for each simulated AnalogTrigger.
|
||||
*
|
||||
* @param index simulator index
|
||||
* @return Simulated object
|
||||
*/
|
||||
static AnalogTriggerSim CreateForIndex(int index) {
|
||||
return AnalogTriggerSim{index};
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
@@ -76,6 +114,8 @@ class AnalogTriggerSim {
|
||||
void ResetData() { HALSIM_ResetAnalogTriggerData(m_index); }
|
||||
|
||||
private:
|
||||
explicit AnalogTriggerSim(int index) : m_index{index} {}
|
||||
|
||||
int m_index;
|
||||
};
|
||||
} // namespace sim
|
||||
|
||||
@@ -13,12 +13,28 @@
|
||||
#include <hal/simulation/AccelerometerData.h>
|
||||
|
||||
#include "CallbackStore.h"
|
||||
#include "frc/BuiltInAccelerometer.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
class AccelerometerSim {
|
||||
|
||||
/**
|
||||
* Class to control a simulated built-in accelerometer.
|
||||
*/
|
||||
class BuiltInAccelerometerSim {
|
||||
public:
|
||||
explicit AccelerometerSim(int index) { m_index = index; }
|
||||
/**
|
||||
* Constructs for the first built-in accelerometer.
|
||||
*/
|
||||
BuiltInAccelerometerSim() : m_index{0} {}
|
||||
|
||||
/**
|
||||
* Constructs from a BuiltInAccelerometer object.
|
||||
*
|
||||
* @param accel BuiltInAccelerometer to simulate
|
||||
*/
|
||||
explicit BuiltInAccelerometerSim(const BuiltInAccelerometer& accel)
|
||||
: m_index{0} {}
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterActiveCallback(NotifyCallback callback,
|
||||
bool initialNotify) {
|
||||
@@ -16,12 +16,17 @@ namespace frc {
|
||||
namespace sim {
|
||||
|
||||
using NotifyCallback = std::function<void(wpi::StringRef, const HAL_Value*)>;
|
||||
using ConstBufferCallback = std::function<void(
|
||||
wpi::StringRef, const unsigned char* buffer, unsigned int count)>;
|
||||
typedef void (*CancelCallbackFunc)(int32_t index, int32_t uid);
|
||||
typedef void (*CancelCallbackNoIndexFunc)(int32_t uid);
|
||||
typedef void (*CancelCallbackChannelFunc)(int32_t index, int32_t channel,
|
||||
int32_t uid);
|
||||
|
||||
void CallbackStoreThunk(const char* name, void* param, const HAL_Value* value);
|
||||
void ConstBufferCallbackStoreThunk(const char* name, void* param,
|
||||
const unsigned char* buffer,
|
||||
unsigned int count);
|
||||
|
||||
class CallbackStore {
|
||||
public:
|
||||
@@ -51,6 +56,33 @@ class CallbackStore {
|
||||
cancelType = Channel;
|
||||
}
|
||||
|
||||
CallbackStore(int32_t i, ConstBufferCallback cb,
|
||||
CancelCallbackNoIndexFunc ccf) {
|
||||
index = i;
|
||||
constBufferCallback = cb;
|
||||
this->ccnif = ccf;
|
||||
cancelType = NoIndex;
|
||||
}
|
||||
|
||||
CallbackStore(int32_t i, int32_t u, ConstBufferCallback cb,
|
||||
CancelCallbackFunc ccf) {
|
||||
index = i;
|
||||
uid = u;
|
||||
constBufferCallback = cb;
|
||||
this->ccf = ccf;
|
||||
cancelType = Normal;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
~CallbackStore() {
|
||||
switch (cancelType) {
|
||||
case Normal:
|
||||
@@ -70,12 +102,17 @@ class CallbackStore {
|
||||
friend void CallbackStoreThunk(const char* name, void* param,
|
||||
const HAL_Value* value);
|
||||
|
||||
friend void ConstBufferCallbackStoreThunk(const char* name, void* param,
|
||||
const unsigned char* buffer,
|
||||
unsigned int count);
|
||||
|
||||
private:
|
||||
int32_t index;
|
||||
int32_t channel;
|
||||
int32_t uid;
|
||||
|
||||
NotifyCallback callback;
|
||||
ConstBufferCallback constBufferCallback;
|
||||
union {
|
||||
CancelCallbackFunc ccf;
|
||||
CancelCallbackChannelFunc cccf;
|
||||
|
||||
@@ -13,12 +13,37 @@
|
||||
#include <hal/simulation/DIOData.h>
|
||||
|
||||
#include "CallbackStore.h"
|
||||
#include "frc/DigitalInput.h"
|
||||
#include "frc/DigitalOutput.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
|
||||
/**
|
||||
* Class to control a simulated digital input or output.
|
||||
*/
|
||||
class DIOSim {
|
||||
public:
|
||||
explicit DIOSim(int index) { m_index = index; }
|
||||
/**
|
||||
* Constructs from a DigitalInput object.
|
||||
*
|
||||
* @param input DigitalInput to simulate
|
||||
*/
|
||||
explicit DIOSim(const DigitalInput& input) : m_index{input.GetChannel()} {}
|
||||
|
||||
/**
|
||||
* Constructs from a DigitalOutput object.
|
||||
*
|
||||
* @param output DigitalOutput to simulate
|
||||
*/
|
||||
explicit DIOSim(const DigitalOutput& output) : m_index{output.GetChannel()} {}
|
||||
|
||||
/**
|
||||
* Constructs from an digital I/O channel number.
|
||||
*
|
||||
* @param channel Channel number
|
||||
*/
|
||||
explicit DIOSim(int channel) : m_index{channel} {}
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
|
||||
@@ -7,18 +7,57 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <exception>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include <hal/simulation/DigitalPWMData.h>
|
||||
|
||||
#include "CallbackStore.h"
|
||||
#include "frc/DigitalOutput.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
|
||||
/**
|
||||
* Class to control a simulated digital PWM output.
|
||||
*
|
||||
* This is for duty cycle PWM outputs on a DigitalOutput, not for the servo
|
||||
* style PWM outputs on a PWM channel.
|
||||
*/
|
||||
class DigitalPWMSim {
|
||||
public:
|
||||
explicit DigitalPWMSim(int index) { m_index = index; }
|
||||
/**
|
||||
* Constructs from a DigitalOutput object.
|
||||
*
|
||||
* @param digitalOutput DigitalOutput to simulate
|
||||
*/
|
||||
explicit DigitalPWMSim(const DigitalOutput& digitalOutput)
|
||||
: m_index{digitalOutput.GetChannel()} {}
|
||||
|
||||
/**
|
||||
* Creates an DigitalPWMSim for a digital I/O channel.
|
||||
*
|
||||
* @param channel DIO channel
|
||||
* @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};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an DigitalPWMSim for a simulated index.
|
||||
* The index is incremented for each simulated DigitalPWM.
|
||||
*
|
||||
* @param index simulator index
|
||||
* @return Simulated object
|
||||
*/
|
||||
static DigitalPWMSim CreateForIndex(int index) {
|
||||
return DigitalPWMSim{index};
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
@@ -68,6 +107,8 @@ class DigitalPWMSim {
|
||||
void ResetData() { HALSIM_ResetDigitalPWMData(m_index); }
|
||||
|
||||
private:
|
||||
explicit DigitalPWMSim(int index) : m_index{index} {}
|
||||
|
||||
int m_index;
|
||||
};
|
||||
} // namespace sim
|
||||
|
||||
@@ -16,9 +16,13 @@
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
|
||||
/**
|
||||
* Class to control a simulated driver station.
|
||||
*/
|
||||
class DriverStationSim {
|
||||
public:
|
||||
std::unique_ptr<CallbackStore> RegisterEnabledCallback(
|
||||
static std::unique_ptr<CallbackStore> RegisterEnabledCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
-1, callback, &HALSIM_CancelDriverStationEnabledCallback);
|
||||
@@ -27,11 +31,13 @@ class DriverStationSim {
|
||||
return store;
|
||||
}
|
||||
|
||||
bool GetEnabled() const { return HALSIM_GetDriverStationEnabled(); }
|
||||
static bool GetEnabled() { return HALSIM_GetDriverStationEnabled(); }
|
||||
|
||||
void SetEnabled(bool enabled) { HALSIM_SetDriverStationEnabled(enabled); }
|
||||
static void SetEnabled(bool enabled) {
|
||||
HALSIM_SetDriverStationEnabled(enabled);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterAutonomousCallback(
|
||||
static std::unique_ptr<CallbackStore> RegisterAutonomousCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
-1, callback, &HALSIM_CancelDriverStationAutonomousCallback);
|
||||
@@ -40,14 +46,14 @@ class DriverStationSim {
|
||||
return store;
|
||||
}
|
||||
|
||||
bool GetAutonomous() const { return HALSIM_GetDriverStationAutonomous(); }
|
||||
static bool GetAutonomous() { return HALSIM_GetDriverStationAutonomous(); }
|
||||
|
||||
void SetAutonomous(bool autonomous) {
|
||||
static void SetAutonomous(bool autonomous) {
|
||||
HALSIM_SetDriverStationAutonomous(autonomous);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterTestCallback(NotifyCallback callback,
|
||||
bool initialNotify) {
|
||||
static std::unique_ptr<CallbackStore> RegisterTestCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
-1, callback, &HALSIM_CancelDriverStationTestCallback);
|
||||
store->SetUid(HALSIM_RegisterDriverStationTestCallback(
|
||||
@@ -55,12 +61,12 @@ class DriverStationSim {
|
||||
return store;
|
||||
}
|
||||
|
||||
bool GetTest() const { return HALSIM_GetDriverStationTest(); }
|
||||
static bool GetTest() { return HALSIM_GetDriverStationTest(); }
|
||||
|
||||
void SetTest(bool test) { HALSIM_SetDriverStationTest(test); }
|
||||
static void SetTest(bool test) { HALSIM_SetDriverStationTest(test); }
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterEStopCallback(NotifyCallback callback,
|
||||
bool initialNotify) {
|
||||
static std::unique_ptr<CallbackStore> RegisterEStopCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
-1, callback, &HALSIM_CancelDriverStationEStopCallback);
|
||||
store->SetUid(HALSIM_RegisterDriverStationEStopCallback(
|
||||
@@ -68,11 +74,11 @@ class DriverStationSim {
|
||||
return store;
|
||||
}
|
||||
|
||||
bool GetEStop() const { return HALSIM_GetDriverStationEStop(); }
|
||||
static bool GetEStop() { return HALSIM_GetDriverStationEStop(); }
|
||||
|
||||
void SetEStop(bool eStop) { HALSIM_SetDriverStationEStop(eStop); }
|
||||
static void SetEStop(bool eStop) { HALSIM_SetDriverStationEStop(eStop); }
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterFmsAttachedCallback(
|
||||
static std::unique_ptr<CallbackStore> RegisterFmsAttachedCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
-1, callback, &HALSIM_CancelDriverStationFmsAttachedCallback);
|
||||
@@ -81,13 +87,13 @@ class DriverStationSim {
|
||||
return store;
|
||||
}
|
||||
|
||||
bool GetFmsAttached() const { return HALSIM_GetDriverStationFmsAttached(); }
|
||||
static bool GetFmsAttached() { return HALSIM_GetDriverStationFmsAttached(); }
|
||||
|
||||
void SetFmsAttached(bool fmsAttached) {
|
||||
static void SetFmsAttached(bool fmsAttached) {
|
||||
HALSIM_SetDriverStationFmsAttached(fmsAttached);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterDsAttachedCallback(
|
||||
static std::unique_ptr<CallbackStore> RegisterDsAttachedCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
-1, callback, &HALSIM_CancelDriverStationDsAttachedCallback);
|
||||
@@ -96,15 +102,15 @@ class DriverStationSim {
|
||||
return store;
|
||||
}
|
||||
|
||||
bool GetDsAttached() const { return HALSIM_GetDriverStationDsAttached(); }
|
||||
static bool GetDsAttached() { return HALSIM_GetDriverStationDsAttached(); }
|
||||
|
||||
void SetDsAttached(bool dsAttached) {
|
||||
static void SetDsAttached(bool dsAttached) {
|
||||
HALSIM_SetDriverStationDsAttached(dsAttached);
|
||||
}
|
||||
|
||||
void NotifyNewData() { HALSIM_NotifyDriverStationNewData(); }
|
||||
static void NotifyNewData() { HALSIM_NotifyDriverStationNewData(); }
|
||||
|
||||
void ResetData() { HALSIM_ResetDriverStationData(); }
|
||||
static void ResetData() { HALSIM_ResetDriverStationData(); }
|
||||
};
|
||||
} // namespace sim
|
||||
} // namespace frc
|
||||
|
||||
@@ -7,18 +7,52 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <exception>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include <hal/simulation/DutyCycleData.h>
|
||||
|
||||
#include "CallbackStore.h"
|
||||
#include "frc/DutyCycle.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
|
||||
/**
|
||||
* Class to control a simulated duty cycle digital input.
|
||||
*/
|
||||
class DutyCycleSim {
|
||||
public:
|
||||
explicit DutyCycleSim(int index) { m_index = index; }
|
||||
/**
|
||||
* Constructs from a DutyCycle object.
|
||||
*
|
||||
* @param dutyCycle DutyCycle to simulate
|
||||
*/
|
||||
explicit DutyCycleSim(const DutyCycle& dutyCycle)
|
||||
: m_index{dutyCycle.GetFPGAIndex()} {}
|
||||
|
||||
/**
|
||||
* Creates a DutyCycleSim for a digital input channel.
|
||||
*
|
||||
* @param channel digital input channel
|
||||
* @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};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a DutyCycleSim for a simulated index.
|
||||
* The index is incremented for each simulated DutyCycle.
|
||||
*
|
||||
* @param index simulator index
|
||||
* @return Simulated object
|
||||
*/
|
||||
static DutyCycleSim CreateForIndex(int index) { return DutyCycleSim{index}; }
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
@@ -66,6 +100,8 @@ class DutyCycleSim {
|
||||
void ResetData() { HALSIM_ResetDutyCycleData(m_index); }
|
||||
|
||||
private:
|
||||
explicit DutyCycleSim(int index) : m_index{index} {}
|
||||
|
||||
int m_index;
|
||||
};
|
||||
} // namespace sim
|
||||
|
||||
@@ -7,18 +7,53 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <exception>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include <hal/simulation/EncoderData.h>
|
||||
|
||||
#include "CallbackStore.h"
|
||||
#include "frc/Encoder.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
|
||||
/**
|
||||
* Class to control a simulated encoder.
|
||||
*/
|
||||
class EncoderSim {
|
||||
public:
|
||||
explicit EncoderSim(int index) { m_index = index; }
|
||||
/**
|
||||
* Constructs from an Encoder object.
|
||||
*
|
||||
* @param encoder Encoder to simulate
|
||||
*/
|
||||
explicit EncoderSim(const Encoder& encoder)
|
||||
: m_index{encoder.GetFPGAIndex()} {}
|
||||
|
||||
/**
|
||||
* Creates an EncoderSim for a digital input channel. Encoders take two
|
||||
* channels, so either one may be specified.
|
||||
*
|
||||
* @param channel digital input channel
|
||||
* @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};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an EncoderSim for a simulated index.
|
||||
* The index is incremented for each simulated Encoder.
|
||||
*
|
||||
* @param index simulator index
|
||||
* @return Simulated object
|
||||
*/
|
||||
static EncoderSim CreateForIndex(int index) { return EncoderSim{index}; }
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
@@ -168,6 +203,8 @@ class EncoderSim {
|
||||
double GetRate() { return HALSIM_GetEncoderRate(m_index); }
|
||||
|
||||
private:
|
||||
explicit EncoderSim(int index) : m_index{index} {}
|
||||
|
||||
int m_index;
|
||||
};
|
||||
} // namespace sim
|
||||
|
||||
@@ -13,12 +13,32 @@
|
||||
#include <hal/simulation/PCMData.h>
|
||||
|
||||
#include "CallbackStore.h"
|
||||
#include "frc/Compressor.h"
|
||||
#include "frc/SensorUtil.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
|
||||
/**
|
||||
* Class to control a simulated Pneumatic Control Module (PCM).
|
||||
*/
|
||||
class PCMSim {
|
||||
public:
|
||||
explicit PCMSim(int index) { m_index = index; }
|
||||
/**
|
||||
* Constructs from a PCM module number (CAN ID).
|
||||
*
|
||||
* @param module module number
|
||||
*/
|
||||
explicit PCMSim(int module = SensorUtil::GetDefaultSolenoidModule())
|
||||
: m_index{module} {}
|
||||
|
||||
/**
|
||||
* Constructs from a Compressor object.
|
||||
*
|
||||
* @param compressor Compressor connected to PCM to simulate
|
||||
*/
|
||||
explicit PCMSim(const Compressor& compressor)
|
||||
: m_index{compressor.GetModule()} {}
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterSolenoidInitializedCallback(
|
||||
int channel, NotifyCallback callback, bool initialNotify) {
|
||||
|
||||
@@ -13,12 +13,30 @@
|
||||
#include <hal/simulation/PDPData.h>
|
||||
|
||||
#include "CallbackStore.h"
|
||||
#include "frc/PowerDistributionPanel.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
|
||||
/**
|
||||
* Class to control a simulated Power Distribution Panel (PDP).
|
||||
*/
|
||||
class PDPSim {
|
||||
public:
|
||||
explicit PDPSim(int index) { m_index = index; }
|
||||
/**
|
||||
* Constructs from a PDP module number (CAN ID).
|
||||
*
|
||||
* @param module module number
|
||||
*/
|
||||
explicit PDPSim(int module = 0) : m_index{module} {}
|
||||
|
||||
/**
|
||||
* Constructs from a PowerDistributionPanel object.
|
||||
*
|
||||
* @param pdp PowerDistributionPanel to simulate
|
||||
*/
|
||||
explicit PDPSim(const PowerDistributionPanel& pdp)
|
||||
: m_index{pdp.GetModule()} {}
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
|
||||
@@ -13,12 +13,29 @@
|
||||
#include <hal/simulation/PWMData.h>
|
||||
|
||||
#include "CallbackStore.h"
|
||||
#include "frc/PWM.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
|
||||
/**
|
||||
* Class to control a simulated PWM output.
|
||||
*/
|
||||
class PWMSim {
|
||||
public:
|
||||
explicit PWMSim(int index) { m_index = index; }
|
||||
/**
|
||||
* Constructs from a PWM object.
|
||||
*
|
||||
* @param pwm PWM to simulate
|
||||
*/
|
||||
explicit PWMSim(const PWM& pwm) : m_index{pwm.GetChannel()} {}
|
||||
|
||||
/**
|
||||
* Constructs from a PWM channel number.
|
||||
*
|
||||
* @param channel Channel number
|
||||
*/
|
||||
explicit PWMSim(int channel) : m_index{channel} {}
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
|
||||
@@ -13,12 +13,29 @@
|
||||
#include <hal/simulation/RelayData.h>
|
||||
|
||||
#include "CallbackStore.h"
|
||||
#include "frc/Relay.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
|
||||
/**
|
||||
* Class to control a simulated relay.
|
||||
*/
|
||||
class RelaySim {
|
||||
public:
|
||||
explicit RelaySim(int index) { m_index = index; }
|
||||
/**
|
||||
* Constructs from a Relay object.
|
||||
*
|
||||
* @param relay Relay to simulate
|
||||
*/
|
||||
explicit RelaySim(const Relay& relay) : m_index{relay.GetChannel()} {}
|
||||
|
||||
/**
|
||||
* Constructs from a relay channel number.
|
||||
*
|
||||
* @param channel Channel number
|
||||
*/
|
||||
explicit RelaySim(int channel) : m_index{channel} {}
|
||||
|
||||
std::unique_ptr<CallbackStore> RegisterInitializedForwardCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
|
||||
@@ -20,8 +20,17 @@
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
|
||||
/**
|
||||
* Class to control the simulation side of a SimDevice.
|
||||
*/
|
||||
class SimDeviceSim {
|
||||
public:
|
||||
/**
|
||||
* Constructs a SimDeviceSim.
|
||||
*
|
||||
* @param name name of the SimDevice
|
||||
*/
|
||||
explicit SimDeviceSim(const char* name)
|
||||
: m_handle{HALSIM_GetSimDeviceHandle(name)} {}
|
||||
|
||||
|
||||
@@ -12,23 +12,25 @@
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
|
||||
void SetRuntimeType(HAL_RuntimeType type) { HALSIM_SetRuntimeType(type); }
|
||||
inline void SetRuntimeType(HAL_RuntimeType type) {
|
||||
HALSIM_SetRuntimeType(type);
|
||||
}
|
||||
|
||||
void WaitForProgramStart() { HALSIM_WaitForProgramStart(); }
|
||||
inline void WaitForProgramStart() { HALSIM_WaitForProgramStart(); }
|
||||
|
||||
void SetProgramStarted() { HALSIM_SetProgramStarted(); }
|
||||
inline void SetProgramStarted() { HALSIM_SetProgramStarted(); }
|
||||
|
||||
bool GetProgramStarted() { return HALSIM_GetProgramStarted(); }
|
||||
inline bool GetProgramStarted() { return HALSIM_GetProgramStarted(); }
|
||||
|
||||
void RestartTiming() { HALSIM_RestartTiming(); }
|
||||
inline void RestartTiming() { HALSIM_RestartTiming(); }
|
||||
|
||||
void PauseTiming() { HALSIM_PauseTiming(); }
|
||||
inline void PauseTiming() { HALSIM_PauseTiming(); }
|
||||
|
||||
void ResumeTiming() { HALSIM_ResumeTiming(); }
|
||||
inline void ResumeTiming() { HALSIM_ResumeTiming(); }
|
||||
|
||||
bool IsTimingPaused() { return HALSIM_IsTimingPaused(); }
|
||||
inline bool IsTimingPaused() { return HALSIM_IsTimingPaused(); }
|
||||
|
||||
void StepTiming(uint64_t delta) { HALSIM_StepTiming(delta); }
|
||||
inline void StepTiming(uint64_t delta) { HALSIM_StepTiming(delta); }
|
||||
|
||||
} // namespace sim
|
||||
} // namespace frc
|
||||
|
||||
Reference in New Issue
Block a user