mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-05 03:21:42 +00:00
Removed analog and digital module numbers
AnalogModule and DigitalModule classes still exist, at least until they are refactored into the classes that use them. Change-Id: I5544d5418822f19d54ba0a5d651e64fad8b7b10d
This commit is contained in:
@@ -19,21 +19,12 @@ static Resource *relayChannels = NULL;
|
||||
* Common relay intitialization methode.
|
||||
* This code is common to all Relay constructors and initializes the relay and reserves
|
||||
* all resources that need to be locked. Initially the relay is set to both lines at 0v.
|
||||
* @param slot The module slot number this relay is connected to.
|
||||
*
|
||||
* @param moduleNumber The digital module this relay is connected to (1 or 2).
|
||||
*/
|
||||
void Relay::InitRelay (uint8_t moduleNumber)
|
||||
void Relay::InitRelay()
|
||||
{
|
||||
m_table = NULL;
|
||||
char buf[64];
|
||||
Resource::CreateResourceObject(&relayChannels, dio_kNumSystems * kRelayChannels * 2);
|
||||
if (!SensorBase::CheckRelayModule(moduleNumber))
|
||||
{
|
||||
snprintf(buf, 64, "Digital Module %d", moduleNumber);
|
||||
wpi_setWPIErrorWithContext(ModuleIndexOutOfRange, buf);
|
||||
return;
|
||||
}
|
||||
if (!SensorBase::CheckRelayChannel(m_channel))
|
||||
{
|
||||
snprintf(buf, 64, "Relay Channel %d", m_channel);
|
||||
@@ -43,56 +34,42 @@ void Relay::InitRelay (uint8_t moduleNumber)
|
||||
|
||||
if (m_direction == kBothDirections || m_direction == kForwardOnly)
|
||||
{
|
||||
snprintf(buf, 64, "Forward Relay %d (Module: %d)", m_channel, moduleNumber);
|
||||
if (relayChannels->Allocate(((moduleNumber - 1) * kRelayChannels + m_channel) * 2, buf) == ~0ul)
|
||||
snprintf(buf, 64, "Forward Relay %d", m_channel);
|
||||
if (relayChannels->Allocate(m_channel * 2, buf) == ~0ul)
|
||||
{
|
||||
CloneError(relayChannels);
|
||||
return;
|
||||
}
|
||||
|
||||
HALReport(HALUsageReporting::kResourceType_Relay, m_channel, moduleNumber - 1);
|
||||
HALReport(HALUsageReporting::kResourceType_Relay, m_channel);
|
||||
}
|
||||
if (m_direction == kBothDirections || m_direction == kReverseOnly)
|
||||
{
|
||||
snprintf(buf, 64, "Reverse Relay %d (Module: %d)", m_channel, moduleNumber);
|
||||
if (relayChannels->Allocate(((moduleNumber - 1) * kRelayChannels + m_channel) * 2 + 1, buf) == ~0ul)
|
||||
snprintf(buf, 64, "Reverse Relay %d", m_channel);
|
||||
if (relayChannels->Allocate(m_channel * 2 + 1, buf) == ~0ul)
|
||||
{
|
||||
CloneError(relayChannels);
|
||||
return;
|
||||
}
|
||||
|
||||
HALReport(HALUsageReporting::kResourceType_Relay, m_channel + 128, moduleNumber - 1);
|
||||
HALReport(HALUsageReporting::kResourceType_Relay, m_channel + 128);
|
||||
}
|
||||
m_module = DigitalModule::GetInstance(moduleNumber);
|
||||
m_module = DigitalModule::GetInstance(1);
|
||||
m_module->SetRelayForward(m_channel, false);
|
||||
m_module->SetRelayReverse(m_channel, false);
|
||||
LiveWindow::GetInstance()->AddActuator("Relay", moduleNumber, m_channel, this);
|
||||
LiveWindow::GetInstance()->AddActuator("Relay", 1, m_channel, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Relay constructor given the module and the channel.
|
||||
*
|
||||
* @param moduleNumber The digital module this relay is connected to (1 or 2).
|
||||
* @param channel The channel number within the module for this relay.
|
||||
* @param direction The direction that the Relay object will control.
|
||||
*/
|
||||
Relay::Relay(uint8_t moduleNumber, uint32_t channel, Relay::Direction direction)
|
||||
: m_channel (channel)
|
||||
, m_direction (direction)
|
||||
{
|
||||
InitRelay(moduleNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Relay constructor given a channel only where the default digital module is used.
|
||||
* @param channel The channel number within the default module for this relay.
|
||||
* Relay constructor given a channel.
|
||||
* @param channel The channel number.
|
||||
* @param direction The direction that the Relay object will control.
|
||||
*/
|
||||
Relay::Relay(uint32_t channel, Relay::Direction direction)
|
||||
: m_channel (channel)
|
||||
, m_direction (direction)
|
||||
{
|
||||
InitRelay(GetDefaultDigitalModule());
|
||||
InitRelay();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,26 +83,26 @@ Relay::~Relay()
|
||||
|
||||
if (m_direction == kBothDirections || m_direction == kForwardOnly)
|
||||
{
|
||||
relayChannels->Free(((m_module->GetNumber() - 1) * kRelayChannels + m_channel) * 2);
|
||||
relayChannels->Free(m_channel * 2);
|
||||
}
|
||||
if (m_direction == kBothDirections || m_direction == kReverseOnly)
|
||||
{
|
||||
relayChannels->Free(((m_module->GetNumber() - 1) * kRelayChannels + m_channel) * 2 + 1);
|
||||
relayChannels->Free(m_channel * 2 + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the relay state.
|
||||
*
|
||||
*
|
||||
* Valid values depend on which directions of the relay are controlled by the object.
|
||||
*
|
||||
*
|
||||
* When set to kBothDirections, the relay can be any of the four states:
|
||||
* 0v-0v, 0v-12v, 12v-0v, 12v-12v
|
||||
*
|
||||
*
|
||||
* When set to kForwardOnly or kReverseOnly, you can specify the constant for the
|
||||
* direction or you can simply specify kOff and kOn. Using only kOff and kOn is
|
||||
* recommended.
|
||||
*
|
||||
*
|
||||
* @param value The state to set the relay.
|
||||
*/
|
||||
void Relay::Set(Relay::Value value)
|
||||
@@ -188,12 +165,12 @@ void Relay::Set(Relay::Value value)
|
||||
|
||||
/**
|
||||
* Get the Relay State
|
||||
*
|
||||
*
|
||||
* Gets the current state of the relay.
|
||||
*
|
||||
*
|
||||
* When set to kForwardOnly or kReverseOnly, value is returned as kOn/kOff not
|
||||
* kForward/kReverse (per the recommendation in Set)
|
||||
*
|
||||
*
|
||||
* @return The current state of the relay as a Relay::Value
|
||||
*/
|
||||
Relay::Value Relay::Get() {
|
||||
@@ -217,7 +194,7 @@ Relay::Value Relay::Get() {
|
||||
} else {
|
||||
return kOff;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Relay::ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew) {
|
||||
@@ -268,5 +245,3 @@ void Relay::InitTable(ITable *subTable) {
|
||||
ITable * Relay::GetTable() {
|
||||
return m_table;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user