Brian Silverman | f7f267a | 2017-02-04 16:16:08 -0800 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2008-2017. All Rights Reserved. */ |
| 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
| 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ |
| 5 | /* the project. */ |
| 6 | /*----------------------------------------------------------------------------*/ |
| 7 | |
| 8 | #include "SensorBase.h" |
| 9 | |
| 10 | #include "WPIErrors.h" |
| 11 | |
| 12 | using namespace frc; |
| 13 | |
| 14 | const int SensorBase::kDigitalChannels; |
| 15 | const int SensorBase::kAnalogInputs; |
| 16 | const int SensorBase::kSolenoidChannels; |
| 17 | const int SensorBase::kSolenoidModules; |
| 18 | const int SensorBase::kPwmChannels; |
| 19 | const int SensorBase::kRelayChannels; |
| 20 | const int SensorBase::kPDPChannels; |
| 21 | |
| 22 | /** |
| 23 | * Check that the solenoid module number is valid. |
| 24 | * |
| 25 | * @return Solenoid module number is valid |
| 26 | */ |
| 27 | bool SensorBase::CheckSolenoidModule(int moduleNumber) { |
| 28 | return moduleNumber >= 0 && moduleNumber < kSolenoidModules; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Check that the digital channel number is valid. |
| 33 | * |
| 34 | * Verify that the channel number is one of the legal channel numbers. Channel |
| 35 | * numbers are 0-based. |
| 36 | * |
| 37 | * @return Digital channel is valid |
| 38 | */ |
| 39 | bool SensorBase::CheckDigitalChannel(int channel) { |
| 40 | if (channel >= 0 && channel < kDigitalChannels) return true; |
| 41 | return false; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Check that the digital channel number is valid. |
| 46 | * |
| 47 | * Verify that the channel number is one of the legal channel numbers. Channel |
| 48 | * numbers are 0-based. |
| 49 | * |
| 50 | * @return Relay channel is valid |
| 51 | */ |
| 52 | bool SensorBase::CheckRelayChannel(int channel) { |
| 53 | if (channel >= 0 && channel < kRelayChannels) return true; |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Check that the digital channel number is valid. |
| 59 | * |
| 60 | * Verify that the channel number is one of the legal channel numbers. Channel |
| 61 | * numbers are 0-based. |
| 62 | * |
| 63 | * @return PWM channel is valid |
| 64 | */ |
| 65 | bool SensorBase::CheckPWMChannel(int channel) { |
| 66 | if (channel >= 0 && channel < kPwmChannels) return true; |
| 67 | return false; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Check that the analog input number is valid. |
| 72 | * |
| 73 | * Verify that the analog input number is one of the legal channel numbers. |
| 74 | * Channel numbers are 0-based. |
| 75 | * |
| 76 | * @return Analog channel is valid |
| 77 | */ |
| 78 | bool SensorBase::CheckAnalogInputChannel(int channel) { |
| 79 | if (channel >= 0 && channel < kAnalogInputs) return true; |
| 80 | return false; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Check that the analog output number is valid. |
| 85 | * |
| 86 | * Verify that the analog output number is one of the legal channel numbers. |
| 87 | * Channel numbers are 0-based. |
| 88 | * |
| 89 | * @return Analog channel is valid |
| 90 | */ |
| 91 | bool SensorBase::CheckAnalogOutputChannel(int channel) { |
| 92 | if (channel >= 0 && channel < kAnalogOutputs) return true; |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Verify that the solenoid channel number is within limits. |
| 98 | * |
| 99 | * @return Solenoid channel is valid |
| 100 | */ |
| 101 | bool SensorBase::CheckSolenoidChannel(int channel) { |
| 102 | if (channel >= 0 && channel < kSolenoidChannels) return true; |
| 103 | return false; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Verify that the power distribution channel number is within limits. |
| 108 | * |
| 109 | * @return PDP channel is valid |
| 110 | */ |
| 111 | bool SensorBase::CheckPDPChannel(int channel) { |
| 112 | if (channel >= 0 && channel < kPDPChannels) return true; |
| 113 | return false; |
| 114 | } |