WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
Relay.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008-2016. 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 "MotorSafety.h"
11 #include "SensorBase.h"
12 #include "tables/ITableListener.h"
13 #include "LiveWindow/LiveWindowSendable.h"
14 #include "tables/ITable.h"
15 
16 #include <memory>
17 
18 class MotorSafetyHelper;
19 
34 class Relay : public MotorSafety,
35  public SensorBase,
36  public ITableListener,
37  public LiveWindowSendable {
38  public:
39  enum Value { kOff, kOn, kForward, kReverse };
40  enum Direction { kBothDirections, kForwardOnly, kReverseOnly };
41 
42  Relay(uint32_t channel, Direction direction = kBothDirections);
43  virtual ~Relay();
44 
45  void Set(Value value);
46  Value Get() const;
47  uint32_t GetChannel() const;
48 
49  void SetExpiration(float timeout) override;
50  float GetExpiration() const override;
51  bool IsAlive() const override;
52  void StopMotor() override;
53  bool IsSafetyEnabled() const override;
54  void SetSafetyEnabled(bool enabled) override;
55  void GetDescription(std::ostringstream& desc) const override;
56 
57  void ValueChanged(ITable* source, llvm::StringRef key,
58  std::shared_ptr<nt::Value> value, bool isNew) override;
59  void UpdateTable() override;
60  void StartLiveWindowMode() override;
61  void StopLiveWindowMode() override;
62  std::string GetSmartDashboardType() const override;
63  void InitTable(std::shared_ptr<ITable> subTable) override;
64  std::shared_ptr<ITable> GetTable() const override;
65 
66  std::shared_ptr<ITable> m_table;
67 
68  private:
69  uint32_t m_channel;
70  Direction m_direction;
71 
72  std::unique_ptr<MotorSafetyHelper> m_safetyHelper;
73 };
A table whose values can be read and written to.
Definition: ITable.h:43
virtual ~Relay()
Free the resource associated with a relay.
Definition: Relay.cpp:76
float GetExpiration() const override
Return the expiration time for the relay object.
Definition: Relay.cpp:213
Definition: MotorSafety.h:14
void Set(Value value)
Set the relay state.
Definition: Relay.cpp:108
Live Window Sendable is a special type of object sendable to the live window.
Definition: LiveWindowSendable.h:18
bool IsAlive() const override
Check if the relay object is currently alive or stopped due to a timeout.
Definition: Relay.cpp:220
std::string GetSmartDashboardType() const override
Definition: Relay.cpp:285
Base class for all sensors.
Definition: SensorBase.h:20
bool IsSafetyEnabled() const override
Check if motor safety is enabled for this object.
Definition: Relay.cpp:242
std::shared_ptr< ITable > GetTable() const override
Definition: Relay.cpp:292
Definition: MotorSafetyHelper.h:17
void StartLiveWindowMode() override
Start having this sendable object automatically respond to value changes reflect the value on the tab...
Definition: Relay.cpp:273
A listener that listens to changes in values in a ITable.
Definition: ITableListener.h:18
Value Get() const
Get the Relay State.
Definition: Relay.cpp:169
Class for Spike style relay outputs.
Definition: Relay.h:34
Relay(uint32_t channel, Direction direction=kBothDirections)
Relay constructor given a channel.
Definition: Relay.cpp:29
void SetExpiration(float timeout) override
Set the expiration time for the Relay object.
Definition: Relay.cpp:205
void StopLiveWindowMode() override
Stop having this sendable object automatically respond to value changes.
Definition: Relay.cpp:279
void StopMotor() override
Stop the motor associated with this PWM object.
Definition: Relay.cpp:227
void InitTable(std::shared_ptr< ITable > subTable) override
Initializes a table for this sendable object.
Definition: Relay.cpp:287
void UpdateTable() override
Update the table for this sendable object with the latest values.
Definition: Relay.cpp:259
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:39
void SetSafetyEnabled(bool enabled) override
Enable/disable motor safety for this device Turn on and off the motor safety option for this relay ob...
Definition: Relay.cpp:234