mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[hal] Add systemcore duty cycle (#7682)
This commit is contained in:
@@ -4,50 +4,37 @@
|
||||
|
||||
#include "frc/DutyCycle.h"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include <hal/DutyCycle.h>
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
#include <hal/HALBase.h>
|
||||
#include <wpi/NullDeleter.h>
|
||||
#include <wpi/StackTrace.h>
|
||||
#include <wpi/sendable/SendableBuilder.h>
|
||||
|
||||
#include "frc/DigitalSource.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/SensorUtil.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
DutyCycle::DutyCycle(DigitalSource* source)
|
||||
: m_source{source, wpi::NullDeleter<DigitalSource>()} {
|
||||
if (!m_source) {
|
||||
throw FRC_MakeError(err::NullParameter, "source");
|
||||
}
|
||||
InitDutyCycle();
|
||||
}
|
||||
|
||||
DutyCycle::DutyCycle(DigitalSource& source)
|
||||
: m_source{&source, wpi::NullDeleter<DigitalSource>()} {
|
||||
InitDutyCycle();
|
||||
}
|
||||
|
||||
DutyCycle::DutyCycle(std::shared_ptr<DigitalSource> source)
|
||||
: m_source{std::move(source)} {
|
||||
if (!m_source) {
|
||||
throw FRC_MakeError(err::NullParameter, "source");
|
||||
DutyCycle::DutyCycle(int channel) : m_channel{channel} {
|
||||
if (!SensorUtil::CheckDigitalChannel(channel)) {
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange, "Channel {}", channel);
|
||||
}
|
||||
InitDutyCycle();
|
||||
}
|
||||
|
||||
void DutyCycle::InitDutyCycle() {
|
||||
int32_t status = 0;
|
||||
m_handle =
|
||||
HAL_InitializeDutyCycle(m_source->GetPortHandleForRouting(),
|
||||
static_cast<HAL_AnalogTriggerType>(
|
||||
m_source->GetAnalogTriggerTypeForRouting()),
|
||||
&status);
|
||||
std::string stackTrace = wpi::GetStackTrace(1);
|
||||
m_handle = HAL_InitializeDutyCycle(HAL_GetPort(m_channel), stackTrace.c_str(),
|
||||
&status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
int index = GetFPGAIndex();
|
||||
HAL_Report(HALUsageReporting::kResourceType_DutyCycle, index + 1);
|
||||
wpi::SendableRegistry::AddLW(this, "Duty Cycle", index);
|
||||
HAL_Report(HALUsageReporting::kResourceType_DutyCycle, m_channel + 1);
|
||||
wpi::SendableRegistry::AddLW(this, "Duty Cycle", m_channel);
|
||||
}
|
||||
|
||||
int DutyCycle::GetFPGAIndex() const {
|
||||
@@ -86,7 +73,7 @@ unsigned int DutyCycle::GetOutputScaleFactor() const {
|
||||
}
|
||||
|
||||
int DutyCycle::GetSourceChannel() const {
|
||||
return m_source->GetChannel();
|
||||
return m_channel;
|
||||
}
|
||||
|
||||
void DutyCycle::InitSendable(wpi::SendableBuilder& builder) {
|
||||
|
||||
Reference in New Issue
Block a user