mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51: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,116 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 <memory>
|
||||
#include <utility>
|
||||
|
||||
#include <hal/simulation/AccelerometerData.h>
|
||||
|
||||
#include "CallbackStore.h"
|
||||
#include "frc/BuiltInAccelerometer.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
|
||||
/**
|
||||
* Class to control a simulated built-in accelerometer.
|
||||
*/
|
||||
class BuiltInAccelerometerSim {
|
||||
public:
|
||||
/**
|
||||
* 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) {
|
||||
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 GetActive() const { return HALSIM_GetAccelerometerActive(m_index); }
|
||||
|
||||
void SetActive(bool active) {
|
||||
HALSIM_SetAccelerometerActive(m_index, 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;
|
||||
}
|
||||
|
||||
HAL_AccelerometerRange GetRange() const {
|
||||
return HALSIM_GetAccelerometerRange(m_index);
|
||||
}
|
||||
|
||||
void SetRange(HAL_AccelerometerRange range) {
|
||||
HALSIM_SetAccelerometerRange(m_index, 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;
|
||||
}
|
||||
|
||||
double GetX() const { return HALSIM_GetAccelerometerX(m_index); }
|
||||
|
||||
void SetX(double x) { HALSIM_SetAccelerometerX(m_index, 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;
|
||||
}
|
||||
|
||||
double GetY() const { return HALSIM_GetAccelerometerY(m_index); }
|
||||
|
||||
void SetY(double y) { HALSIM_SetAccelerometerY(m_index, 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;
|
||||
}
|
||||
|
||||
double GetZ() const { return HALSIM_GetAccelerometerZ(m_index); }
|
||||
|
||||
void SetZ(double z) { HALSIM_SetAccelerometerZ(m_index, z); }
|
||||
|
||||
void ResetData() { HALSIM_ResetAccelerometerData(m_index); }
|
||||
|
||||
private:
|
||||
int m_index;
|
||||
};
|
||||
} // namespace sim
|
||||
} // namespace frc
|
||||
Reference in New Issue
Block a user