mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
[hal, wpilib] Remove DigitalSource and AnalogTrigger (#7753)
This commit is contained in:
@@ -1,132 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#include "frc/AnalogTrigger.h"
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include <hal/AnalogTrigger.h>
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
#include <wpi/NullDeleter.h>
|
||||
#include <wpi/sendable/SendableRegistry.h>
|
||||
|
||||
#include "frc/AnalogInput.h"
|
||||
#include "frc/DutyCycle.h"
|
||||
#include "frc/Errors.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
AnalogTrigger::AnalogTrigger(int channel)
|
||||
: AnalogTrigger(std::make_shared<AnalogInput>(channel)) {
|
||||
m_ownsAnalog = true;
|
||||
wpi::SendableRegistry::AddChild(this, m_analogInput.get());
|
||||
}
|
||||
|
||||
AnalogTrigger::AnalogTrigger(AnalogInput& input)
|
||||
: AnalogTrigger{{&input, wpi::NullDeleter<AnalogInput>{}}} {}
|
||||
|
||||
AnalogTrigger::AnalogTrigger(AnalogInput* input)
|
||||
: AnalogTrigger{{input, wpi::NullDeleter<AnalogInput>{}}} {}
|
||||
|
||||
AnalogTrigger::AnalogTrigger(std::shared_ptr<AnalogInput> input)
|
||||
: m_analogInput{std::move(input)} {
|
||||
int32_t status = 0;
|
||||
m_trigger = HAL_InitializeAnalogTrigger(m_analogInput->m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_analogInput->GetChannel());
|
||||
int index = GetIndex();
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_AnalogTrigger, index + 1);
|
||||
wpi::SendableRegistry::Add(this, "AnalogTrigger", index);
|
||||
}
|
||||
|
||||
AnalogTrigger::AnalogTrigger(DutyCycle& input)
|
||||
: AnalogTrigger{{&input, wpi::NullDeleter<DutyCycle>{}}} {}
|
||||
|
||||
AnalogTrigger::AnalogTrigger(DutyCycle* input)
|
||||
: AnalogTrigger{{input, wpi::NullDeleter<DutyCycle>{}}} {}
|
||||
|
||||
AnalogTrigger::AnalogTrigger(std::shared_ptr<DutyCycle> input)
|
||||
: m_dutyCycle{input} {
|
||||
int32_t status = 0;
|
||||
m_trigger = HAL_InitializeAnalogTriggerDutyCycle(input->m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_dutyCycle->GetSourceChannel());
|
||||
int index = GetIndex();
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_AnalogTrigger, index + 1);
|
||||
wpi::SendableRegistry::Add(this, "AnalogTrigger", index);
|
||||
}
|
||||
|
||||
void AnalogTrigger::SetLimitsVoltage(double lower, double upper) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogTriggerLimitsVoltage(m_trigger, lower, upper, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
}
|
||||
|
||||
void AnalogTrigger::SetLimitsDutyCycle(double lower, double upper) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogTriggerLimitsDutyCycle(m_trigger, lower, upper, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
}
|
||||
|
||||
void AnalogTrigger::SetLimitsRaw(int lower, int upper) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogTriggerLimitsRaw(m_trigger, lower, upper, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
}
|
||||
|
||||
void AnalogTrigger::SetAveraged(bool useAveragedValue) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogTriggerAveraged(m_trigger, useAveragedValue, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
}
|
||||
|
||||
void AnalogTrigger::SetFiltered(bool useFilteredValue) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogTriggerFiltered(m_trigger, useFilteredValue, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
}
|
||||
|
||||
int AnalogTrigger::GetIndex() const {
|
||||
int32_t status = 0;
|
||||
auto ret = HAL_GetAnalogTriggerFPGAIndex(m_trigger, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool AnalogTrigger::GetInWindow() {
|
||||
int32_t status = 0;
|
||||
bool result = HAL_GetAnalogTriggerInWindow(m_trigger, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
return result;
|
||||
}
|
||||
|
||||
bool AnalogTrigger::GetTriggerState() {
|
||||
int32_t status = 0;
|
||||
bool result = HAL_GetAnalogTriggerTriggerState(m_trigger, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", GetSourceChannel());
|
||||
return result;
|
||||
}
|
||||
|
||||
std::shared_ptr<AnalogTriggerOutput> AnalogTrigger::CreateOutput(
|
||||
AnalogTriggerType type) const {
|
||||
return std::shared_ptr<AnalogTriggerOutput>(
|
||||
new AnalogTriggerOutput(*this, type));
|
||||
}
|
||||
|
||||
void AnalogTrigger::InitSendable(wpi::SendableBuilder& builder) {
|
||||
if (m_ownsAnalog) {
|
||||
m_analogInput->InitSendable(builder);
|
||||
}
|
||||
}
|
||||
|
||||
int AnalogTrigger::GetSourceChannel() const {
|
||||
if (m_analogInput) {
|
||||
return m_analogInput->GetChannel();
|
||||
} else if (m_dutyCycle) {
|
||||
return m_dutyCycle->GetSourceChannel();
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#include "frc/AnalogTriggerOutput.h"
|
||||
|
||||
#include <hal/AnalogTrigger.h>
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
|
||||
#include "frc/AnalogTrigger.h"
|
||||
#include "frc/AnalogTriggerType.h"
|
||||
#include "frc/Errors.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
bool AnalogTriggerOutput::Get() const {
|
||||
int32_t status = 0;
|
||||
bool result = HAL_GetAnalogTriggerOutput(
|
||||
m_trigger->m_trigger, static_cast<HAL_AnalogTriggerType>(m_outputType),
|
||||
&status);
|
||||
FRC_CheckErrorStatus(status, "Get");
|
||||
return result;
|
||||
}
|
||||
|
||||
HAL_Handle AnalogTriggerOutput::GetPortHandleForRouting() const {
|
||||
return m_trigger->m_trigger;
|
||||
}
|
||||
|
||||
AnalogTriggerType AnalogTriggerOutput::GetAnalogTriggerTypeForRouting() const {
|
||||
return m_outputType;
|
||||
}
|
||||
|
||||
bool AnalogTriggerOutput::IsAnalogTrigger() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
int AnalogTriggerOutput::GetChannel() const {
|
||||
return m_trigger->GetIndex();
|
||||
}
|
||||
|
||||
void AnalogTriggerOutput::InitSendable(wpi::SendableBuilder&) {}
|
||||
|
||||
AnalogTriggerOutput::AnalogTriggerOutput(const AnalogTrigger& trigger,
|
||||
AnalogTriggerType outputType)
|
||||
: m_trigger(&trigger), m_outputType(outputType) {
|
||||
HAL_Report(HALUsageReporting::kResourceType_AnalogTriggerOutput,
|
||||
trigger.GetIndex() + 1, static_cast<uint8_t>(outputType) + 1);
|
||||
}
|
||||
@@ -42,18 +42,6 @@ bool DigitalInput::Get() const {
|
||||
return value;
|
||||
}
|
||||
|
||||
HAL_Handle DigitalInput::GetPortHandleForRouting() const {
|
||||
return m_handle;
|
||||
}
|
||||
|
||||
AnalogTriggerType DigitalInput::GetAnalogTriggerTypeForRouting() const {
|
||||
return static_cast<AnalogTriggerType>(0);
|
||||
}
|
||||
|
||||
bool DigitalInput::IsAnalogTrigger() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void DigitalInput::SetSimDevice(HAL_SimDeviceHandle device) {
|
||||
HAL_SetDIOSimDevice(m_handle, device);
|
||||
}
|
||||
|
||||
@@ -60,18 +60,6 @@ bool DigitalOutput::Get() const {
|
||||
return val;
|
||||
}
|
||||
|
||||
HAL_Handle DigitalOutput::GetPortHandleForRouting() const {
|
||||
return m_handle;
|
||||
}
|
||||
|
||||
AnalogTriggerType DigitalOutput::GetAnalogTriggerTypeForRouting() const {
|
||||
return static_cast<AnalogTriggerType>(0);
|
||||
}
|
||||
|
||||
bool DigitalOutput::IsAnalogTrigger() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
int DigitalOutput::GetChannel() const {
|
||||
return m_channel;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include <wpi/StackTrace.h>
|
||||
#include <wpi/sendable/SendableBuilder.h>
|
||||
|
||||
#include "frc/DigitalSource.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/SensorUtil.h"
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include <wpi/sendable/SendableBuilder.h>
|
||||
|
||||
#include "frc/DigitalInput.h"
|
||||
#include "frc/DigitalSource.h"
|
||||
#include "frc/DutyCycle.h"
|
||||
#include "frc/MathUtil.h"
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include <wpi/StackTrace.h>
|
||||
#include <wpi/sendable/SendableBuilder.h>
|
||||
|
||||
#include "frc/DigitalSource.h"
|
||||
#include "frc/Errors.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#include "frc/simulation/AnalogTriggerSim.h"
|
||||
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <hal/simulation/AnalogTriggerData.h>
|
||||
|
||||
#include "frc/AnalogTrigger.h"
|
||||
|
||||
using namespace frc;
|
||||
using namespace frc::sim;
|
||||
|
||||
AnalogTriggerSim::AnalogTriggerSim(const AnalogTrigger& analogTrigger)
|
||||
: m_index{analogTrigger.GetIndex()} {}
|
||||
|
||||
AnalogTriggerSim 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};
|
||||
}
|
||||
|
||||
AnalogTriggerSim AnalogTriggerSim::CreateForIndex(int index) {
|
||||
return AnalogTriggerSim{index};
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> AnalogTriggerSim::RegisterInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelAnalogTriggerInitializedCallback);
|
||||
store->SetUid(HALSIM_RegisterAnalogTriggerInitializedCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
bool AnalogTriggerSim::GetInitialized() const {
|
||||
return HALSIM_GetAnalogTriggerInitialized(m_index);
|
||||
}
|
||||
|
||||
void AnalogTriggerSim::SetInitialized(bool initialized) {
|
||||
HALSIM_SetAnalogTriggerInitialized(m_index, initialized);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore>
|
||||
AnalogTriggerSim::RegisterTriggerLowerBoundCallback(NotifyCallback callback,
|
||||
bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback,
|
||||
&HALSIM_CancelAnalogTriggerTriggerLowerBoundCallback);
|
||||
store->SetUid(HALSIM_RegisterAnalogTriggerTriggerLowerBoundCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
double AnalogTriggerSim::GetTriggerLowerBound() const {
|
||||
return HALSIM_GetAnalogTriggerTriggerLowerBound(m_index);
|
||||
}
|
||||
|
||||
void AnalogTriggerSim::SetTriggerLowerBound(double triggerLowerBound) {
|
||||
HALSIM_SetAnalogTriggerTriggerLowerBound(m_index, triggerLowerBound);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore>
|
||||
AnalogTriggerSim::RegisterTriggerUpperBoundCallback(NotifyCallback callback,
|
||||
bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback,
|
||||
&HALSIM_CancelAnalogTriggerTriggerUpperBoundCallback);
|
||||
store->SetUid(HALSIM_RegisterAnalogTriggerTriggerUpperBoundCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
double AnalogTriggerSim::GetTriggerUpperBound() const {
|
||||
return HALSIM_GetAnalogTriggerTriggerUpperBound(m_index);
|
||||
}
|
||||
|
||||
void AnalogTriggerSim::SetTriggerUpperBound(double triggerUpperBound) {
|
||||
HALSIM_SetAnalogTriggerTriggerUpperBound(m_index, triggerUpperBound);
|
||||
}
|
||||
|
||||
void AnalogTriggerSim::ResetData() {
|
||||
HALSIM_ResetAnalogTriggerData(m_index);
|
||||
}
|
||||
Reference in New Issue
Block a user