mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[sim] Move WPILib C++ sim implementations out of line (#2598)
This makes the sim classes consistent with the rest of the WPILibC classes.
This commit is contained in:
81
wpilibc/src/main/native/cpp/simulation/DigitalPWMSim.cpp
Normal file
81
wpilibc/src/main/native/cpp/simulation/DigitalPWMSim.cpp
Normal 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); }
|
||||
Reference in New Issue
Block a user