WPILibC++  2020.3.2
Relay.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2019 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/Sendable.h"
18 #include "frc/smartdashboard/SendableHelper.h"
19 
20 namespace frc {
21 
22 class SendableBuilder;
23 
36 class Relay : public MotorSafety,
37  public Sendable,
38  public SendableHelper<Relay> {
39  public:
40  enum Value { kOff, kOn, kForward, kReverse };
41  enum Direction { kBothDirections, kForwardOnly, kReverseOnly };
42 
52  explicit Relay(int channel, Direction direction = kBothDirections);
53 
59  ~Relay() override;
60 
61  Relay(Relay&&) = default;
62  Relay& operator=(Relay&&) = default;
63 
79  void Set(Value value);
80 
91  Value Get() const;
92 
93  int GetChannel() const;
94 
95  // MotorSafety interface
96  void StopMotor() override;
97 
98  void GetDescription(wpi::raw_ostream& desc) const override;
99 
100  void InitSendable(SendableBuilder& builder) override;
101 
102  private:
103  int m_channel;
104  Direction m_direction;
105 
106  hal::Handle<HAL_RelayHandle> m_forwardHandle;
107  hal::Handle<HAL_RelayHandle> m_reverseHandle;
108 };
109 
110 } // namespace frc
frc::Relay
Class for Spike style relay outputs.
Definition: Relay.h:36
frc::Relay::InitSendable
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
frc::MotorSafety
This base class runs a watchdog timer and calls the subclass's StopMotor() function if the timeout ex...
Definition: MotorSafety.h:24
frc::Relay::Set
void Set(Value value)
Set the relay state.
frc::Relay::~Relay
~Relay() override
Free the resource associated with a relay.
frc::Relay::Relay
Relay(int channel, Direction direction=kBothDirections)
Relay constructor given a channel.
frc::Sendable
Interface for Sendable objects.
Definition: Sendable.h:17
frc
A class that enforces constraints on the differential drive kinematics.
Definition: SPIAccelerometerSim.h:16
wpi::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:47
frc::Relay::Get
Value Get() const
Get the Relay State.
frc::SendableHelper
A helper class for use with objects that add themselves to SendableRegistry.
Definition: SendableHelper.h:28
frc::SendableBuilder
Definition: SendableBuilder.h:23