2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2020-07-15 23:48:09 -07:00
|
|
|
|
|
|
|
|
#include "frc/simulation/PWMSim.h"
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
#include <hal/simulation/PWMData.h>
|
|
|
|
|
|
|
|
|
|
#include "frc/PWM.h"
|
2022-05-06 11:44:59 -04:00
|
|
|
#include "frc/motorcontrol/PWMMotorController.h"
|
2020-07-15 23:48:09 -07:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 19:43:16 -07:00
|
|
|
std::unique_ptr<CallbackStore> PWMSim::RegisterPulseMicrosecondCallback(
|
2020-07-15 23:48:09 -07:00
|
|
|
NotifyCallback callback, bool initialNotify) {
|
|
|
|
|
auto store = std::make_unique<CallbackStore>(
|
2023-06-22 19:43:16 -07:00
|
|
|
m_index, -1, callback, &HALSIM_CancelPWMPulseMicrosecondCallback);
|
|
|
|
|
store->SetUid(HALSIM_RegisterPWMPulseMicrosecondCallback(
|
|
|
|
|
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
2020-07-15 23:48:09 -07:00
|
|
|
return store;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 19:43:16 -07:00
|
|
|
int32_t PWMSim::GetPulseMicrosecond() const {
|
|
|
|
|
return HALSIM_GetPWMPulseMicrosecond(m_index);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2020-07-15 23:48:09 -07:00
|
|
|
|
2023-06-22 19:43:16 -07:00
|
|
|
void PWMSim::SetPulseMicrosecond(int32_t microsecondPulseTime) {
|
|
|
|
|
HALSIM_SetPWMPulseMicrosecond(m_index, microsecondPulseTime);
|
2020-07-15 23:48:09 -07:00
|
|
|
}
|
|
|
|
|
|
2025-03-20 19:23:22 -07:00
|
|
|
std::unique_ptr<CallbackStore> PWMSim::RegisterOutputPeriodCallback(
|
2020-07-15 23:48:09 -07:00
|
|
|
NotifyCallback callback, bool initialNotify) {
|
|
|
|
|
auto store = std::make_unique<CallbackStore>(
|
2025-03-20 19:23:22 -07:00
|
|
|
m_index, -1, callback, &HALSIM_CancelPWMOutputPeriodCallback);
|
|
|
|
|
store->SetUid(HALSIM_RegisterPWMOutputPeriodCallback(
|
2020-07-15 23:48:09 -07:00
|
|
|
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
|
|
|
|
return store;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-20 19:23:22 -07:00
|
|
|
int PWMSim::GetOutputPeriod() const {
|
|
|
|
|
return HALSIM_GetPWMOutputPeriod(m_index);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2020-07-15 23:48:09 -07:00
|
|
|
|
2025-03-20 19:23:22 -07:00
|
|
|
void PWMSim::SetOutputPeriod(int period) {
|
|
|
|
|
HALSIM_SetPWMOutputPeriod(m_index, period);
|
2020-07-15 23:48:09 -07:00
|
|
|
}
|
|
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
void PWMSim::ResetData() {
|
|
|
|
|
HALSIM_ResetPWMData(m_index);
|
|
|
|
|
}
|