WPILibC++  2019.1.1-beta-2-31-g26e8e58
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Relay.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2018 FIRST. 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 
12 #include <hal/Types.h>
13 #include <wpi/raw_ostream.h>
14 
15 #include "frc/ErrorBase.h"
16 #include "frc/MotorSafety.h"
17 #include "frc/smartdashboard/SendableBase.h"
18 
19 namespace frc {
20 
33 class Relay : public MotorSafety, public SendableBase {
34  public:
35  enum Value { kOff, kOn, kForward, kReverse };
36  enum Direction { kBothDirections, kForwardOnly, kReverseOnly };
37 
47  explicit Relay(int channel, Direction direction = kBothDirections);
48 
54  ~Relay() override;
55 
56  Relay(Relay&& rhs);
57  Relay& operator=(Relay&& rhs);
58 
74  void Set(Value value);
75 
86  Value Get() const;
87 
88  int GetChannel() const;
89 
90  // MotorSafety interface
91  void StopMotor() override;
92 
93  void GetDescription(wpi::raw_ostream& desc) const override;
94 
95  void InitSendable(SendableBuilder& builder) override;
96 
97  private:
98  int m_channel;
99  Direction m_direction;
100 
101  HAL_RelayHandle m_forwardHandle = HAL_kInvalidHandle;
102  HAL_RelayHandle m_reverseHandle = HAL_kInvalidHandle;
103 };
104 
105 } // namespace frc
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
Value Get() const
Get the Relay State.
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
Class for Spike style relay outputs.
Definition: Relay.h:33
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
This base class runs a watchdog timer and calls the subclass's StopMotor() function if the timeout ex...
Definition: MotorSafety.h:26
Relay(int channel, Direction direction=kBothDirections)
Relay constructor given a channel.
void Set(Value value)
Set the relay state.
~Relay() override
Free the resource associated with a relay.
Definition: SendableBase.h:19
Definition: SendableBuilder.h:23