mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpilib] Remove automatic PD type from module type enum (#3732)
Using automatic type doesn't work with any module number, so the API was confusing.
This commit is contained in:
@@ -15,9 +15,6 @@
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/SensorUtil.h"
|
||||
|
||||
static_assert(static_cast<HAL_PowerDistributionType>(
|
||||
frc::PowerDistribution::ModuleType::kAutomatic) ==
|
||||
HAL_PowerDistributionType::HAL_PowerDistributionType_kAutomatic);
|
||||
static_assert(static_cast<HAL_PowerDistributionType>(
|
||||
frc::PowerDistribution::ModuleType::kCTRE) ==
|
||||
HAL_PowerDistributionType::HAL_PowerDistributionType_kCTRE);
|
||||
@@ -29,8 +26,21 @@ static_assert(frc::PowerDistribution::kDefaultModule ==
|
||||
|
||||
using namespace frc;
|
||||
|
||||
PowerDistribution::PowerDistribution()
|
||||
: PowerDistribution(-1, ModuleType::kAutomatic) {}
|
||||
PowerDistribution::PowerDistribution() {
|
||||
auto stack = wpi::GetStackTrace(1);
|
||||
|
||||
int32_t status = 0;
|
||||
m_handle = HAL_InitializePowerDistribution(
|
||||
kDefaultModule,
|
||||
HAL_PowerDistributionType::HAL_PowerDistributionType_kAutomatic,
|
||||
stack.c_str(), &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", kDefaultModule);
|
||||
m_module = HAL_GetPowerDistributionModuleNumber(m_handle, &status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_PDP, m_module + 1);
|
||||
wpi::SendableRegistry::AddLW(this, "PowerDistribution", m_module);
|
||||
}
|
||||
|
||||
PowerDistribution::PowerDistribution(int module, ModuleType moduleType) {
|
||||
auto stack = wpi::GetStackTrace(1);
|
||||
|
||||
@@ -18,12 +18,12 @@ class PowerDistribution : public wpi::Sendable,
|
||||
public wpi::SendableHelper<PowerDistribution> {
|
||||
public:
|
||||
static constexpr int kDefaultModule = -1;
|
||||
enum class ModuleType { kAutomatic = 0, kCTRE = 1, kRev = 2 };
|
||||
enum class ModuleType { kCTRE = 1, kRev = 2 };
|
||||
|
||||
/**
|
||||
* Constructs a PowerDistribution.
|
||||
*
|
||||
* Uses the default CAN ID.
|
||||
* Uses the default CAN ID (0 for CTRE and 1 for REV).
|
||||
*/
|
||||
PowerDistribution();
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ public class PowerDistribution implements Sendable, AutoCloseable {
|
||||
public static final int kDefaultModule = PowerDistributionJNI.DEFAULT_MODULE;
|
||||
|
||||
public enum ModuleType {
|
||||
kAutomatic(PowerDistributionJNI.AUTOMATIC_TYPE),
|
||||
kCTRE(PowerDistributionJNI.CTRE_TYPE),
|
||||
kRev(PowerDistributionJNI.REV_TYPE);
|
||||
|
||||
@@ -37,7 +36,7 @@ public class PowerDistribution implements Sendable, AutoCloseable {
|
||||
* Constructs a PowerDistribution.
|
||||
*
|
||||
* @param module The CAN ID of the PDP.
|
||||
* @param moduleType Module type (automatic, CTRE, or REV).
|
||||
* @param moduleType Module type (CTRE or REV).
|
||||
*/
|
||||
public PowerDistribution(int module, ModuleType moduleType) {
|
||||
m_handle = PowerDistributionJNI.initialize(module, moduleType.value);
|
||||
@@ -50,10 +49,14 @@ public class PowerDistribution implements Sendable, AutoCloseable {
|
||||
/**
|
||||
* Constructs a PowerDistribution.
|
||||
*
|
||||
* <p>Uses the default CAN ID.
|
||||
* <p>Uses the default CAN ID (0 for CTRE and 1 for REV).
|
||||
*/
|
||||
public PowerDistribution() {
|
||||
this(kDefaultModule, ModuleType.kAutomatic);
|
||||
m_handle = PowerDistributionJNI.initialize(kDefaultModule, PowerDistributionJNI.AUTOMATIC_TYPE);
|
||||
m_module = PowerDistributionJNI.getModuleNumber(m_handle);
|
||||
|
||||
HAL.report(tResourceType.kResourceType_PDP, m_module + 1);
|
||||
SendableRegistry.addLW(this, "PowerDistribution", m_module);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user