9 #include "DigitalModule.h"
10 #include "NetworkCommunication/UsageReporting.h"
12 #include "WPIErrors.h"
13 #include "LiveWindow/LiveWindow.h"
16 static Resource *relayChannels = NULL;
26 void Relay::InitRelay (uint8_t moduleNumber)
33 snprintf(buf, 64,
"Digital Module %d", moduleNumber);
34 wpi_setWPIErrorWithContext(ModuleIndexOutOfRange, buf);
39 snprintf(buf, 64,
"Relay Channel %d", m_channel);
40 wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf);
44 if (m_direction == kBothDirections || m_direction == kForwardOnly)
46 snprintf(buf, 64,
"Forward Relay %d (Module: %d)", m_channel, moduleNumber);
47 if (relayChannels->
Allocate(((moduleNumber - 1) * kRelayChannels + m_channel - 1) * 2, buf) == ~0ul)
49 CloneError(relayChannels);
53 nUsageReporting::report(nUsageReporting::kResourceType_Relay, m_channel, moduleNumber - 1);
55 if (m_direction == kBothDirections || m_direction == kReverseOnly)
57 snprintf(buf, 64,
"Reverse Relay %d (Module: %d)", m_channel, moduleNumber);
58 if (relayChannels->
Allocate(((moduleNumber - 1) * kRelayChannels + m_channel - 1) * 2 + 1, buf) == ~0ul)
60 CloneError(relayChannels);
64 nUsageReporting::report(nUsageReporting::kResourceType_Relay, m_channel + 128, moduleNumber - 1);
79 Relay::Relay(uint8_t moduleNumber, uint32_t channel, Relay::Direction direction)
81 , m_direction (direction)
83 InitRelay(moduleNumber);
93 , m_direction (direction)
95 InitRelay(GetDefaultDigitalModule());
107 if (m_direction == kBothDirections || m_direction == kForwardOnly)
109 relayChannels->
Free(((m_module->GetNumber() - 1) * kRelayChannels + m_channel - 1) * 2);
111 if (m_direction == kBothDirections || m_direction == kReverseOnly)
113 relayChannels->
Free(((m_module->GetNumber() - 1) * kRelayChannels + m_channel - 1) * 2 + 1);
137 if (m_direction == kBothDirections || m_direction == kForwardOnly)
141 if (m_direction == kBothDirections || m_direction == kReverseOnly)
147 if (m_direction == kBothDirections || m_direction == kForwardOnly)
151 if (m_direction == kBothDirections || m_direction == kReverseOnly)
157 if (m_direction == kReverseOnly)
159 wpi_setWPIError(IncompatibleMode);
162 if (m_direction == kBothDirections || m_direction == kForwardOnly)
166 if (m_direction == kBothDirections)
172 if (m_direction == kForwardOnly)
174 wpi_setWPIError(IncompatibleMode);
177 if (m_direction == kBothDirections)
181 if (m_direction == kBothDirections || m_direction == kReverseOnly)
204 if(m_direction == kForwardOnly) {
212 if(m_direction == kReverseOnly) {
224 std::string *val = (std::string *) value.ptr;
225 if (*val ==
"Off")
Set(kOff);
226 else if (*val ==
"Forward")
Set(kForward);
227 else if (*val ==
"Reverse")
Set(kReverse);
235 else if (
Get() == kForward) {
238 else if (
Get() == kReverse) {
void SetRelayReverse(uint32_t channel, bool on)
virtual void RemoveTableListener(ITableListener *listener)=0
void AddActuator(const char *subsystem, const char *name, LiveWindowSendable *component)
std::string GetSmartDashboardType()
virtual void AddTableListener(ITableListener *listener)=0
void SetRelayForward(uint32_t channel, bool on)
void StartLiveWindowMode()
void StopLiveWindowMode()
static bool CheckRelayModule(uint8_t moduleNumber)
Relay(uint32_t channel, Direction direction=kBothDirections)
void Free(uint32_t index)
uint32_t Allocate(const char *resourceDesc)
void InitTable(ITable *subTable)
static LiveWindow * GetInstance()
virtual bool StatusIsFatal() const
Check if the current error code represents a fatal error.
void ValueChanged(ITable *source, const std::string &key, EntryValue value, bool isNew)
static DigitalModule * GetInstance(uint8_t moduleNumber)
bool GetRelayForward(uint32_t channel)
static void CreateResourceObject(Resource **r, uint32_t elements)
static bool CheckRelayChannel(uint32_t channel)
bool GetRelayReverse(uint32_t channel)
virtual void PutString(std::string key, std::string value)=0