blob: aa6708a52999aa7f7cb187f8cff3643dc558937d [file] [log] [blame]
jerrymf1579332013-02-07 01:56:28 +00001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2008. 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 $(WIND_BASE)/WPILib. */
5/*----------------------------------------------------------------------------*/
6
7#ifndef RELAY_H_
8#define RELAY_H_
9
10#include "SensorBase.h"
11#include "tables/ITableListener.h"
12#include "LiveWindow/LiveWindowSendable.h"
13#include "tables/ITable.h"
14
15class DigitalModule;
16
17/**
18 * Class for Spike style relay outputs.
19 * Relays are intended to be connected to spikes or similar relays. The relay channels controls
20 * a pair of pins that are either both off, one on, the other on, or both on. This translates into
21 * two spike outputs at 0v, one at 12v and one at 0v, one at 0v and the other at 12v, or two
22 * spike outputs at 12V. This allows off, full forward, or full reverse control of motors without
23 * variable speed. It also allows the two channels (forward and reverse) to be used independently
24 * for something that does not care about voltage polatiry (like a solenoid).
25 */
26class Relay : public SensorBase, public ITableListener, public LiveWindowSendable {
27public:
28 typedef enum {kOff, kOn, kForward, kReverse} Value;
29 typedef enum {kBothDirections, kForwardOnly, kReverseOnly} Direction;
30
31 Relay(UINT32 channel, Direction direction = kBothDirections);
32 Relay(UINT8 moduleNumber, UINT32 channel, Direction direction = kBothDirections);
33 virtual ~Relay();
34
35 void Set(Value value);
36 Value Get();
37
38 void ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew);
39 void UpdateTable();
40 void StartLiveWindowMode();
41 void StopLiveWindowMode();
42 std::string GetSmartDashboardType();
43 void InitTable(ITable *subTable);
44 ITable * GetTable();
45
46 ITable *m_table;
47
48private:
49 void InitRelay(UINT8 moduleNumber);
50
51 UINT32 m_channel;
52 Direction m_direction;
53 DigitalModule *m_module;
54};
55
56#endif