Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 1 | // Copyright (c) FIRST and other WPILib contributors. |
| 2 | // Open Source Software; you can modify and/or share it under the terms of |
| 3 | // the WPILib BSD license file in the root directory of this project. |
| 4 | |
| 5 | #include "frc/PneumaticsBase.h" |
| 6 | |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 7 | #include <hal/REVPH.h> |
| 8 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 9 | #include "frc/Errors.h" |
| 10 | #include "frc/PneumaticHub.h" |
| 11 | #include "frc/PneumaticsControlModule.h" |
| 12 | #include "frc/SensorUtil.h" |
| 13 | |
| 14 | using namespace frc; |
| 15 | |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 16 | static_assert( |
| 17 | static_cast<int>(CompressorConfigType::Disabled) == |
| 18 | HAL_REVPHCompressorConfigType::HAL_REVPHCompressorConfigType_kDisabled); |
| 19 | static_assert( |
| 20 | static_cast<int>(CompressorConfigType::Digital) == |
| 21 | HAL_REVPHCompressorConfigType::HAL_REVPHCompressorConfigType_kDigital); |
| 22 | static_assert( |
| 23 | static_cast<int>(CompressorConfigType::Analog) == |
| 24 | HAL_REVPHCompressorConfigType::HAL_REVPHCompressorConfigType_kAnalog); |
| 25 | static_assert( |
| 26 | static_cast<int>(CompressorConfigType::Hybrid) == |
| 27 | HAL_REVPHCompressorConfigType::HAL_REVPHCompressorConfigType_kHybrid); |
| 28 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 29 | std::shared_ptr<PneumaticsBase> PneumaticsBase::GetForType( |
| 30 | int module, PneumaticsModuleType moduleType) { |
| 31 | if (moduleType == PneumaticsModuleType::CTREPCM) { |
| 32 | return PneumaticsControlModule::GetForModule(module); |
| 33 | } else if (moduleType == PneumaticsModuleType::REVPH) { |
| 34 | return PneumaticHub::GetForModule(module); |
| 35 | } |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 36 | throw FRC_MakeError(err::InvalidParameter, "{}", |
| 37 | static_cast<int>(moduleType)); |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | int PneumaticsBase::GetDefaultForType(PneumaticsModuleType moduleType) { |
| 41 | if (moduleType == PneumaticsModuleType::CTREPCM) { |
| 42 | return SensorUtil::GetDefaultCTREPCMModule(); |
| 43 | } else if (moduleType == PneumaticsModuleType::REVPH) { |
| 44 | return SensorUtil::GetDefaultREVPHModule(); |
| 45 | } |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 46 | throw FRC_MakeError(err::InvalidParameter, "{}", |
| 47 | static_cast<int>(moduleType)); |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 48 | } |