Renamed "pin" to "channel" and variables with underscores now use mixed case (#194)

This commit is contained in:
Tyler Veness
2016-08-12 13:45:28 -07:00
committed by Peter Johnson
parent 227fdc1a60
commit 45b8e9ab4f
67 changed files with 941 additions and 917 deletions

View File

@@ -15,12 +15,12 @@ using namespace hal;
namespace {
struct Relay {
uint8_t pin;
uint8_t channel;
bool fwd;
};
}
static IndexedHandleResource<HAL_RelayHandle, Relay, kNumRelayPins,
static IndexedHandleResource<HAL_RelayHandle, Relay, kNumRelayChannels,
HAL_HandleEnum::Relay>
relayHandles;
@@ -28,21 +28,21 @@ static IndexedHandleResource<HAL_RelayHandle, Relay, kNumRelayPins,
static priority_recursive_mutex digitalRelayMutex;
extern "C" {
HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle port_handle,
HAL_Bool fwd, int32_t* status) {
HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle portHandle, HAL_Bool fwd,
int32_t* status) {
initializeDigital(status);
if (*status != 0) return HAL_kInvalidHandle;
int16_t pin = getPortHandlePin(port_handle);
if (pin == InvalidHandleIndex) {
int16_t channel = getPortHandleChannel(portHandle);
if (channel == InvalidHandleIndex) {
*status = PARAMETER_OUT_OF_RANGE;
return HAL_kInvalidHandle;
}
if (!fwd) pin += kNumRelayHeaders; // add 4 to reverse pins
if (!fwd) channel += kNumRelayHeaders; // add 4 to reverse channels
auto handle = relayHandles.Allocate(pin, status);
auto handle = relayHandles.Allocate(channel, status);
if (*status != 0)
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
@@ -54,35 +54,37 @@ HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle port_handle,
}
if (!fwd) {
pin -= kNumRelayHeaders; // subtract number of headers to put pin in range.
port->fwd = false; // set to reverse
// Subtract number of headers to put channel in range
channel -= kNumRelayHeaders;
port->fwd = false; // set to reverse
} else {
port->fwd = true; // set to forward
}
port->pin = static_cast<uint8_t>(pin);
port->channel = static_cast<uint8_t>(channel);
return handle;
}
void HAL_FreeRelayPort(HAL_RelayHandle relay_port_handle) {
void HAL_FreeRelayPort(HAL_RelayHandle relayPortHandle) {
// no status, so no need to check for a proper free.
relayHandles.Free(relay_port_handle);
relayHandles.Free(relayPortHandle);
}
HAL_Bool HAL_CheckRelayChannel(int32_t pin) {
HAL_Bool HAL_CheckRelayChannel(int32_t channel) {
// roboRIO only has 4 headers, and the FPGA has
// seperate functions for forward and reverse,
// instead of seperate pin IDs
return pin < kNumRelayHeaders && pin >= 0;
// instead of seperate channel IDs
return channel < kNumRelayHeaders && channel >= 0;
}
/**
* Set the state of a relay.
* Set the state of a relay output.
*/
void HAL_SetRelay(HAL_RelayHandle relay_port_handle, HAL_Bool on,
void HAL_SetRelay(HAL_RelayHandle relayPortHandle, HAL_Bool on,
int32_t* status) {
auto port = relayHandles.Get(relay_port_handle);
auto port = relayHandles.Get(relayPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -98,9 +100,9 @@ void HAL_SetRelay(HAL_RelayHandle relay_port_handle, HAL_Bool on,
if (*status != 0) return; // bad status read
if (on) {
relays |= 1 << port->pin;
relays |= 1 << port->channel;
} else {
relays &= ~(1 << port->pin);
relays &= ~(1 << port->channel);
}
if (port->fwd) {
@@ -113,8 +115,8 @@ void HAL_SetRelay(HAL_RelayHandle relay_port_handle, HAL_Bool on,
/**
* Get the current state of the relay channel
*/
HAL_Bool HAL_GetRelay(HAL_RelayHandle relay_port_handle, int32_t* status) {
auto port = relayHandles.Get(relay_port_handle);
HAL_Bool HAL_GetRelay(HAL_RelayHandle relayPortHandle, int32_t* status) {
auto port = relayHandles.Get(relayPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return false;
@@ -127,6 +129,6 @@ HAL_Bool HAL_GetRelay(HAL_RelayHandle relay_port_handle, int32_t* status) {
relays = relaySystem->readValue_Reverse(status);
}
return (relays & (1 << port->pin)) != 0;
return (relays & (1 << port->channel)) != 0;
}
}