mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
Major formatting changes (breaks diffs). No code changes.
The changes made in this commit do not affect any actual code,
they are purely aesthetic. I ran clang-format with google style
over all .h/.cpp files in wpilibc that weren't in wpilibC++Sim
or gtest, and the eclipse formatter over all of the Java files
using the Google eclipse formatting configuration.
Change-Id: I9627bca0bc103c398ecc1c5ba17467193291ae63
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* Copyright (c) FIRST 2008. All Rights Reserved.
|
||||
*/
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code
|
||||
*/
|
||||
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
@@ -17,50 +19,47 @@ static Resource *relayChannels = NULL;
|
||||
|
||||
/**
|
||||
* Common relay initialization method.
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
void Relay::InitRelay()
|
||||
{
|
||||
m_table = NULL;
|
||||
char buf[64];
|
||||
Resource::CreateResourceObject(&relayChannels, dio_kNumSystems * kRelayChannels * 2);
|
||||
if (!SensorBase::CheckRelayChannel(m_channel))
|
||||
{
|
||||
snprintf(buf, 64, "Relay Channel %d", m_channel);
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf);
|
||||
return;
|
||||
}
|
||||
void Relay::InitRelay() {
|
||||
m_table = NULL;
|
||||
char buf[64];
|
||||
Resource::CreateResourceObject(&relayChannels,
|
||||
dio_kNumSystems * kRelayChannels * 2);
|
||||
if (!SensorBase::CheckRelayChannel(m_channel)) {
|
||||
snprintf(buf, 64, "Relay Channel %d", m_channel);
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf);
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_direction == kBothDirections || m_direction == kForwardOnly)
|
||||
{
|
||||
snprintf(buf, 64, "Forward Relay %d", m_channel);
|
||||
if (relayChannels->Allocate(m_channel * 2, buf) == ~0ul)
|
||||
{
|
||||
CloneError(relayChannels);
|
||||
return;
|
||||
}
|
||||
if (m_direction == kBothDirections || m_direction == kForwardOnly) {
|
||||
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);
|
||||
}
|
||||
if (m_direction == kBothDirections || m_direction == kReverseOnly)
|
||||
{
|
||||
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);
|
||||
}
|
||||
if (m_direction == kBothDirections || m_direction == kReverseOnly) {
|
||||
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);
|
||||
}
|
||||
HALReport(HALUsageReporting::kResourceType_Relay, m_channel + 128);
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
setRelayForward(m_relay_ports[m_channel], false, &status);
|
||||
setRelayReverse(m_relay_ports[m_channel], false, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
int32_t status = 0;
|
||||
setRelayForward(m_relay_ports[m_channel], false, &status);
|
||||
setRelayReverse(m_relay_ports[m_channel], false, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
|
||||
LiveWindow::GetInstance()->AddActuator("Relay", 1, m_channel, this);
|
||||
LiveWindow::GetInstance()->AddActuator("Relay", 1, m_channel, this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,109 +68,94 @@ void Relay::InitRelay()
|
||||
* @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();
|
||||
: m_channel(channel), m_direction(direction) {
|
||||
InitRelay();
|
||||
}
|
||||
|
||||
/**
|
||||
* Free the resource associated with a relay.
|
||||
* The relay channels are set to free and the relay output is turned off.
|
||||
*/
|
||||
Relay::~Relay()
|
||||
{
|
||||
Relay::~Relay() {
|
||||
int32_t status = 0;
|
||||
setRelayForward(m_relay_ports[m_channel], false, &status);
|
||||
setRelayReverse(m_relay_ports[m_channel], false, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
|
||||
int32_t status = 0;
|
||||
setRelayForward(m_relay_ports[m_channel], false, &status);
|
||||
setRelayReverse(m_relay_ports[m_channel], false, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
|
||||
if (m_direction == kBothDirections || m_direction == kForwardOnly)
|
||||
{
|
||||
relayChannels->Free(m_channel * 2);
|
||||
}
|
||||
if (m_direction == kBothDirections || m_direction == kReverseOnly)
|
||||
{
|
||||
relayChannels->Free(m_channel * 2 + 1);
|
||||
}
|
||||
if (m_direction == kBothDirections || m_direction == kForwardOnly) {
|
||||
relayChannels->Free(m_channel * 2);
|
||||
}
|
||||
if (m_direction == kBothDirections || m_direction == kReverseOnly) {
|
||||
relayChannels->Free(m_channel * 2 + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the relay state.
|
||||
*
|
||||
* Valid values depend on which directions of the relay are controlled by the object.
|
||||
* 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
|
||||
* 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.
|
||||
* 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)
|
||||
{
|
||||
if (StatusIsFatal()) return;
|
||||
void Relay::Set(Relay::Value value) {
|
||||
if (StatusIsFatal()) return;
|
||||
|
||||
int32_t status = 0;
|
||||
int32_t status = 0;
|
||||
|
||||
switch (value)
|
||||
{
|
||||
case kOff:
|
||||
if (m_direction == kBothDirections || m_direction == kForwardOnly)
|
||||
{
|
||||
setRelayForward(m_relay_ports[m_channel], false, &status);
|
||||
}
|
||||
if (m_direction == kBothDirections || m_direction == kReverseOnly)
|
||||
{
|
||||
setRelayReverse(m_relay_ports[m_channel], false, &status);
|
||||
}
|
||||
break;
|
||||
case kOn:
|
||||
if (m_direction == kBothDirections || m_direction == kForwardOnly)
|
||||
{
|
||||
setRelayForward(m_relay_ports[m_channel], true, &status);
|
||||
}
|
||||
if (m_direction == kBothDirections || m_direction == kReverseOnly)
|
||||
{
|
||||
setRelayReverse(m_relay_ports[m_channel], true, &status);
|
||||
}
|
||||
break;
|
||||
case kForward:
|
||||
if (m_direction == kReverseOnly)
|
||||
{
|
||||
wpi_setWPIError(IncompatibleMode);
|
||||
break;
|
||||
}
|
||||
if (m_direction == kBothDirections || m_direction == kForwardOnly)
|
||||
{
|
||||
setRelayForward(m_relay_ports[m_channel], true, &status);
|
||||
}
|
||||
if (m_direction == kBothDirections)
|
||||
{
|
||||
setRelayReverse(m_relay_ports[m_channel], false, &status);
|
||||
}
|
||||
break;
|
||||
case kReverse:
|
||||
if (m_direction == kForwardOnly)
|
||||
{
|
||||
wpi_setWPIError(IncompatibleMode);
|
||||
break;
|
||||
}
|
||||
if (m_direction == kBothDirections)
|
||||
{
|
||||
setRelayForward(m_relay_ports[m_channel], false, &status);
|
||||
}
|
||||
if (m_direction == kBothDirections || m_direction == kReverseOnly)
|
||||
{
|
||||
setRelayReverse(m_relay_ports[m_channel], true, &status);
|
||||
}
|
||||
break;
|
||||
}
|
||||
switch (value) {
|
||||
case kOff:
|
||||
if (m_direction == kBothDirections || m_direction == kForwardOnly) {
|
||||
setRelayForward(m_relay_ports[m_channel], false, &status);
|
||||
}
|
||||
if (m_direction == kBothDirections || m_direction == kReverseOnly) {
|
||||
setRelayReverse(m_relay_ports[m_channel], false, &status);
|
||||
}
|
||||
break;
|
||||
case kOn:
|
||||
if (m_direction == kBothDirections || m_direction == kForwardOnly) {
|
||||
setRelayForward(m_relay_ports[m_channel], true, &status);
|
||||
}
|
||||
if (m_direction == kBothDirections || m_direction == kReverseOnly) {
|
||||
setRelayReverse(m_relay_ports[m_channel], true, &status);
|
||||
}
|
||||
break;
|
||||
case kForward:
|
||||
if (m_direction == kReverseOnly) {
|
||||
wpi_setWPIError(IncompatibleMode);
|
||||
break;
|
||||
}
|
||||
if (m_direction == kBothDirections || m_direction == kForwardOnly) {
|
||||
setRelayForward(m_relay_ports[m_channel], true, &status);
|
||||
}
|
||||
if (m_direction == kBothDirections) {
|
||||
setRelayReverse(m_relay_ports[m_channel], false, &status);
|
||||
}
|
||||
break;
|
||||
case kReverse:
|
||||
if (m_direction == kForwardOnly) {
|
||||
wpi_setWPIError(IncompatibleMode);
|
||||
break;
|
||||
}
|
||||
if (m_direction == kBothDirections) {
|
||||
setRelayForward(m_relay_ports[m_channel], false, &status);
|
||||
}
|
||||
if (m_direction == kBothDirections || m_direction == kReverseOnly) {
|
||||
setRelayReverse(m_relay_ports[m_channel], true, &status);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,79 +169,77 @@ void Relay::Set(Relay::Value value)
|
||||
* @return The current state of the relay as a Relay::Value
|
||||
*/
|
||||
Relay::Value Relay::Get() const {
|
||||
int32_t status;
|
||||
int32_t status;
|
||||
|
||||
if(getRelayForward(m_relay_ports[m_channel], &status)) {
|
||||
if(getRelayReverse(m_relay_ports[m_channel], &status)) {
|
||||
return kOn;
|
||||
} else {
|
||||
if(m_direction == kForwardOnly) {
|
||||
return kOn;
|
||||
} else {
|
||||
return kForward;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(getRelayReverse(m_relay_ports[m_channel], &status)) {
|
||||
if(m_direction == kReverseOnly) {
|
||||
return kOn;
|
||||
} else {
|
||||
return kReverse;
|
||||
}
|
||||
} else {
|
||||
return kOff;
|
||||
}
|
||||
}
|
||||
if (getRelayForward(m_relay_ports[m_channel], &status)) {
|
||||
if (getRelayReverse(m_relay_ports[m_channel], &status)) {
|
||||
return kOn;
|
||||
} else {
|
||||
if (m_direction == kForwardOnly) {
|
||||
return kOn;
|
||||
} else {
|
||||
return kForward;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (getRelayReverse(m_relay_ports[m_channel], &status)) {
|
||||
if (m_direction == kReverseOnly) {
|
||||
return kOn;
|
||||
} else {
|
||||
return kReverse;
|
||||
}
|
||||
} else {
|
||||
return kOff;
|
||||
}
|
||||
}
|
||||
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
}
|
||||
|
||||
void Relay::ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew) {
|
||||
std::string *val = (std::string *) value.ptr;
|
||||
if (*val == "Off") Set(kOff);
|
||||
else if (*val == "On") Set(kOn);
|
||||
else if (*val == "Forward") Set(kForward);
|
||||
else if (*val == "Reverse") Set(kReverse);
|
||||
void Relay::ValueChanged(ITable *source, const std::string &key,
|
||||
EntryValue value, bool isNew) {
|
||||
std::string *val = (std::string *)value.ptr;
|
||||
if (*val == "Off")
|
||||
Set(kOff);
|
||||
else if (*val == "On")
|
||||
Set(kOn);
|
||||
else if (*val == "Forward")
|
||||
Set(kForward);
|
||||
else if (*val == "Reverse")
|
||||
Set(kReverse);
|
||||
}
|
||||
|
||||
void Relay::UpdateTable() {
|
||||
if(m_table != NULL){
|
||||
if (Get() == kOn) {
|
||||
m_table->PutString("Value", "On");
|
||||
}
|
||||
else if (Get() == kForward) {
|
||||
m_table->PutString("Value", "Forward");
|
||||
}
|
||||
else if (Get() == kReverse) {
|
||||
m_table->PutString("Value", "Reverse");
|
||||
}
|
||||
else {
|
||||
m_table->PutString("Value", "Off");
|
||||
}
|
||||
}
|
||||
if (m_table != NULL) {
|
||||
if (Get() == kOn) {
|
||||
m_table->PutString("Value", "On");
|
||||
} else if (Get() == kForward) {
|
||||
m_table->PutString("Value", "Forward");
|
||||
} else if (Get() == kReverse) {
|
||||
m_table->PutString("Value", "Reverse");
|
||||
} else {
|
||||
m_table->PutString("Value", "Off");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Relay::StartLiveWindowMode() {
|
||||
if(m_table != NULL){
|
||||
m_table->AddTableListener("Value", this, true);
|
||||
}
|
||||
if (m_table != NULL) {
|
||||
m_table->AddTableListener("Value", this, true);
|
||||
}
|
||||
}
|
||||
|
||||
void Relay::StopLiveWindowMode() {
|
||||
if(m_table != NULL){
|
||||
m_table->RemoveTableListener(this);
|
||||
}
|
||||
if (m_table != NULL) {
|
||||
m_table->RemoveTableListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
std::string Relay::GetSmartDashboardType() const {
|
||||
return "Relay";
|
||||
}
|
||||
std::string Relay::GetSmartDashboardType() const { return "Relay"; }
|
||||
|
||||
void Relay::InitTable(ITable *subTable) {
|
||||
m_table = subTable;
|
||||
UpdateTable();
|
||||
m_table = subTable;
|
||||
UpdateTable();
|
||||
}
|
||||
|
||||
ITable * Relay::GetTable() const {
|
||||
return m_table;
|
||||
}
|
||||
ITable *Relay::GetTable() const { return m_table; }
|
||||
|
||||
Reference in New Issue
Block a user