Parker Schuh | d3b7a887 | 2018-02-19 16:42:27 -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 | #pragma once |
| 9 | |
| 10 | #include <memory> |
| 11 | #include <string> |
| 12 | |
| 13 | #include "HAL/Types.h" |
| 14 | #include "frc971/wpilib/ahal/SensorBase.h" |
| 15 | |
| 16 | namespace frc { |
| 17 | |
| 18 | /** |
| 19 | * Class for Spike style relay outputs. |
| 20 | * Relays are intended to be connected to spikes or similar relays. The relay |
| 21 | * channels controls a pair of pins that are either both off, one on, the other |
| 22 | * on, or both on. This translates into two spike outputs at 0v, one at 12v and |
| 23 | * one at 0v, one at 0v and the other at 12v, or two spike outputs at 12V. This |
| 24 | * allows off, full forward, or full reverse control of motors without variable |
| 25 | * speed. It also allows the two channels (forward and reverse) to be used |
| 26 | * independently for something that does not care about voltage polarity (like |
| 27 | * a solenoid). |
| 28 | */ |
| 29 | class Relay { |
| 30 | public: |
| 31 | enum Value { kOff, kOn, kForward, kReverse }; |
| 32 | enum Direction { kBothDirections, kForwardOnly, kReverseOnly }; |
| 33 | |
| 34 | explicit Relay(int channel, Direction direction = kBothDirections); |
| 35 | virtual ~Relay(); |
| 36 | |
| 37 | void Set(Value value); |
| 38 | Value Get() const; |
| 39 | int GetChannel() const; |
| 40 | |
| 41 | private: |
| 42 | int m_channel; |
| 43 | Direction m_direction; |
| 44 | |
| 45 | HAL_RelayHandle m_forwardHandle = HAL_kInvalidHandle; |
| 46 | HAL_RelayHandle m_reverseHandle = HAL_kInvalidHandle; |
| 47 | }; |
| 48 | |
| 49 | } // namespace frc |