Brian Silverman | f7f267a | 2017-02-04 16:16:08 -0800 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2016-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 "HAL/Compressor.h" |
| 9 | |
| 10 | #include "HAL/Errors.h" |
| 11 | #include "HAL/handles/HandlesInternal.h" |
| 12 | #include "PCMInternal.h" |
| 13 | #include "PortsInternal.h" |
| 14 | #include "ctre/PCM.h" |
| 15 | |
| 16 | using namespace hal; |
| 17 | |
| 18 | extern "C" { |
| 19 | |
| 20 | HAL_CompressorHandle HAL_InitializeCompressor(int32_t module, int32_t* status) { |
| 21 | // Use status to check for invalid index |
| 22 | initializePCM(module, status); |
| 23 | if (*status != 0) { |
| 24 | return HAL_kInvalidHandle; |
| 25 | } |
| 26 | |
| 27 | // As compressors can have unlimited objects, just create a |
| 28 | // handle with the module number as the index. |
| 29 | |
| 30 | return (HAL_CompressorHandle)createHandle(static_cast<int16_t>(module), |
| 31 | HAL_HandleEnum::Compressor); |
| 32 | } |
| 33 | |
| 34 | HAL_Bool HAL_CheckCompressorModule(int32_t module) { |
| 35 | return module < kNumPCMModules && module >= 0; |
| 36 | } |
| 37 | |
| 38 | HAL_Bool HAL_GetCompressor(HAL_CompressorHandle compressorHandle, |
| 39 | int32_t* status) { |
| 40 | int16_t index = |
| 41 | getHandleTypedIndex(compressorHandle, HAL_HandleEnum::Compressor); |
| 42 | if (index == InvalidHandleIndex) { |
| 43 | *status = HAL_HANDLE_ERROR; |
| 44 | return false; |
| 45 | } |
| 46 | bool value; |
| 47 | |
| 48 | *status = PCM_modules[index]->GetCompressor(value); |
| 49 | |
| 50 | return value; |
| 51 | } |
| 52 | |
| 53 | void HAL_SetCompressorClosedLoopControl(HAL_CompressorHandle compressorHandle, |
| 54 | HAL_Bool value, int32_t* status) { |
| 55 | int16_t index = |
| 56 | getHandleTypedIndex(compressorHandle, HAL_HandleEnum::Compressor); |
| 57 | if (index == InvalidHandleIndex) { |
| 58 | *status = HAL_HANDLE_ERROR; |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | *status = PCM_modules[index]->SetClosedLoopControl(value); |
| 63 | } |
| 64 | |
| 65 | HAL_Bool HAL_GetCompressorClosedLoopControl( |
| 66 | HAL_CompressorHandle compressorHandle, int32_t* status) { |
| 67 | int16_t index = |
| 68 | getHandleTypedIndex(compressorHandle, HAL_HandleEnum::Compressor); |
| 69 | if (index == InvalidHandleIndex) { |
| 70 | *status = HAL_HANDLE_ERROR; |
| 71 | return false; |
| 72 | } |
| 73 | bool value; |
| 74 | |
| 75 | *status = PCM_modules[index]->GetClosedLoopControl(value); |
| 76 | |
| 77 | return value; |
| 78 | } |
| 79 | |
| 80 | HAL_Bool HAL_GetCompressorPressureSwitch(HAL_CompressorHandle compressorHandle, |
| 81 | int32_t* status) { |
| 82 | int16_t index = |
| 83 | getHandleTypedIndex(compressorHandle, HAL_HandleEnum::Compressor); |
| 84 | if (index == InvalidHandleIndex) { |
| 85 | *status = HAL_HANDLE_ERROR; |
| 86 | return false; |
| 87 | } |
| 88 | bool value; |
| 89 | |
| 90 | *status = PCM_modules[index]->GetPressure(value); |
| 91 | |
| 92 | return value; |
| 93 | } |
| 94 | |
| 95 | double HAL_GetCompressorCurrent(HAL_CompressorHandle compressorHandle, |
| 96 | int32_t* status) { |
| 97 | int16_t index = |
| 98 | getHandleTypedIndex(compressorHandle, HAL_HandleEnum::Compressor); |
| 99 | if (index == InvalidHandleIndex) { |
| 100 | *status = HAL_HANDLE_ERROR; |
| 101 | return 0; |
| 102 | } |
| 103 | float value; |
| 104 | |
| 105 | *status = PCM_modules[index]->GetCompressorCurrent(value); |
| 106 | |
| 107 | return value; |
| 108 | } |
| 109 | HAL_Bool HAL_GetCompressorCurrentTooHighFault( |
| 110 | HAL_CompressorHandle compressorHandle, int32_t* status) { |
| 111 | int16_t index = |
| 112 | getHandleTypedIndex(compressorHandle, HAL_HandleEnum::Compressor); |
| 113 | if (index == InvalidHandleIndex) { |
| 114 | *status = HAL_HANDLE_ERROR; |
| 115 | return false; |
| 116 | } |
| 117 | bool value; |
| 118 | |
| 119 | *status = PCM_modules[index]->GetCompressorCurrentTooHighFault(value); |
| 120 | |
| 121 | return value; |
| 122 | } |
| 123 | HAL_Bool HAL_GetCompressorCurrentTooHighStickyFault( |
| 124 | HAL_CompressorHandle compressorHandle, int32_t* status) { |
| 125 | int16_t index = |
| 126 | getHandleTypedIndex(compressorHandle, HAL_HandleEnum::Compressor); |
| 127 | if (index == InvalidHandleIndex) { |
| 128 | *status = HAL_HANDLE_ERROR; |
| 129 | return false; |
| 130 | } |
| 131 | bool value; |
| 132 | |
| 133 | *status = PCM_modules[index]->GetCompressorCurrentTooHighStickyFault(value); |
| 134 | |
| 135 | return value; |
| 136 | } |
| 137 | HAL_Bool HAL_GetCompressorShortedStickyFault( |
| 138 | HAL_CompressorHandle compressorHandle, int32_t* status) { |
| 139 | int16_t index = |
| 140 | getHandleTypedIndex(compressorHandle, HAL_HandleEnum::Compressor); |
| 141 | if (index == InvalidHandleIndex) { |
| 142 | *status = HAL_HANDLE_ERROR; |
| 143 | return false; |
| 144 | } |
| 145 | bool value; |
| 146 | |
| 147 | *status = PCM_modules[index]->GetCompressorShortedStickyFault(value); |
| 148 | |
| 149 | return value; |
| 150 | } |
| 151 | HAL_Bool HAL_GetCompressorShortedFault(HAL_CompressorHandle compressorHandle, |
| 152 | int32_t* status) { |
| 153 | int16_t index = |
| 154 | getHandleTypedIndex(compressorHandle, HAL_HandleEnum::Compressor); |
| 155 | if (index == InvalidHandleIndex) { |
| 156 | *status = HAL_HANDLE_ERROR; |
| 157 | return false; |
| 158 | } |
| 159 | bool value; |
| 160 | |
| 161 | *status = PCM_modules[index]->GetCompressorShortedFault(value); |
| 162 | |
| 163 | return value; |
| 164 | } |
| 165 | HAL_Bool HAL_GetCompressorNotConnectedStickyFault( |
| 166 | HAL_CompressorHandle compressorHandle, int32_t* status) { |
| 167 | int16_t index = |
| 168 | getHandleTypedIndex(compressorHandle, HAL_HandleEnum::Compressor); |
| 169 | if (index == InvalidHandleIndex) { |
| 170 | *status = HAL_HANDLE_ERROR; |
| 171 | return false; |
| 172 | } |
| 173 | bool value; |
| 174 | |
| 175 | *status = PCM_modules[index]->GetCompressorNotConnectedStickyFault(value); |
| 176 | |
| 177 | return value; |
| 178 | } |
| 179 | HAL_Bool HAL_GetCompressorNotConnectedFault( |
| 180 | HAL_CompressorHandle compressorHandle, int32_t* status) { |
| 181 | int16_t index = |
| 182 | getHandleTypedIndex(compressorHandle, HAL_HandleEnum::Compressor); |
| 183 | if (index == InvalidHandleIndex) { |
| 184 | *status = HAL_HANDLE_ERROR; |
| 185 | return false; |
| 186 | } |
| 187 | bool value; |
| 188 | |
| 189 | *status = PCM_modules[index]->GetCompressorNotConnectedFault(value); |
| 190 | |
| 191 | return value; |
| 192 | } |
| 193 | } // extern "C" |