mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
* Use explicit this capture required by C++20 * Use C++20 span * Replace wpi::numbers with std::numbers * Fix C++20 clang-tidy warning false positive in fmt * Remove ciso646 include since C++20 removed that header * Fix global-buffer-overflow asan warnings in ntcore tests * Add DIOSetProxy constructor to HAL * Upgrade MSVC compiler to 2022 * Bump native-utils to 2023.2.7 (changes to std=c++20) Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
51 lines
1.7 KiB
C++
51 lines
1.7 KiB
C++
// 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/AnalogPotentiometer.h"
|
|
|
|
#include <utility>
|
|
|
|
#include <wpi/NullDeleter.h>
|
|
#include <wpi/sendable/SendableBuilder.h>
|
|
#include <wpi/sendable/SendableRegistry.h>
|
|
|
|
#include "frc/RobotController.h"
|
|
|
|
using namespace frc;
|
|
|
|
AnalogPotentiometer::AnalogPotentiometer(int channel, double fullRange,
|
|
double offset)
|
|
: AnalogPotentiometer(std::make_shared<AnalogInput>(channel), fullRange,
|
|
offset) {
|
|
wpi::SendableRegistry::AddChild(this, m_analog_input.get());
|
|
}
|
|
|
|
AnalogPotentiometer::AnalogPotentiometer(AnalogInput* input, double fullRange,
|
|
double offset)
|
|
: AnalogPotentiometer(
|
|
std::shared_ptr<AnalogInput>(input, wpi::NullDeleter<AnalogInput>()),
|
|
fullRange, offset) {}
|
|
|
|
AnalogPotentiometer::AnalogPotentiometer(std::shared_ptr<AnalogInput> input,
|
|
double fullRange, double offset)
|
|
: m_analog_input(std::move(input)),
|
|
m_fullRange(fullRange),
|
|
m_offset(offset) {
|
|
wpi::SendableRegistry::AddLW(this, "AnalogPotentiometer",
|
|
m_analog_input->GetChannel());
|
|
}
|
|
|
|
double AnalogPotentiometer::Get() const {
|
|
return (m_analog_input->GetAverageVoltage() /
|
|
RobotController::GetVoltage5V()) *
|
|
m_fullRange +
|
|
m_offset;
|
|
}
|
|
|
|
void AnalogPotentiometer::InitSendable(wpi::SendableBuilder& builder) {
|
|
builder.SetSmartDashboardType("Analog Input");
|
|
builder.AddDoubleProperty(
|
|
"Value", [=, this] { return Get(); }, nullptr);
|
|
}
|