mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
Switches HAL to manual instead of static initialization (#824)
Only athena. Will fix a whole lot of init issues.
This commit is contained in:
committed by
Peter Johnson
parent
1fa0adb091
commit
8bd48d6c34
@@ -23,12 +23,22 @@ struct Relay {
|
||||
} // namespace
|
||||
|
||||
static IndexedHandleResource<HAL_RelayHandle, Relay, kNumRelayChannels,
|
||||
HAL_HandleEnum::Relay>
|
||||
relayHandles;
|
||||
HAL_HandleEnum::Relay>* relayHandles;
|
||||
|
||||
// Create a mutex to protect changes to the relay values
|
||||
static wpi::mutex digitalRelayMutex;
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializeRelay() {
|
||||
static IndexedHandleResource<HAL_RelayHandle, Relay, kNumRelayChannels,
|
||||
HAL_HandleEnum::Relay>
|
||||
rH;
|
||||
relayHandles = &rH;
|
||||
}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
extern "C" {
|
||||
|
||||
HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle portHandle, HAL_Bool fwd,
|
||||
@@ -45,12 +55,12 @@ HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle portHandle, HAL_Bool fwd,
|
||||
|
||||
if (!fwd) channel += kNumRelayHeaders; // add 4 to reverse channels
|
||||
|
||||
auto handle = relayHandles.Allocate(channel, status);
|
||||
auto handle = relayHandles->Allocate(channel, status);
|
||||
|
||||
if (*status != 0)
|
||||
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
|
||||
|
||||
auto port = relayHandles.Get(handle);
|
||||
auto port = relayHandles->Get(handle);
|
||||
if (port == nullptr) { // would only occur on thread issue.
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return HAL_kInvalidHandle;
|
||||
@@ -71,7 +81,7 @@ HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle portHandle, HAL_Bool fwd,
|
||||
|
||||
void HAL_FreeRelayPort(HAL_RelayHandle relayPortHandle) {
|
||||
// no status, so no need to check for a proper free.
|
||||
relayHandles.Free(relayPortHandle);
|
||||
relayHandles->Free(relayPortHandle);
|
||||
}
|
||||
|
||||
HAL_Bool HAL_CheckRelayChannel(int32_t channel) {
|
||||
@@ -87,7 +97,7 @@ HAL_Bool HAL_CheckRelayChannel(int32_t channel) {
|
||||
*/
|
||||
void HAL_SetRelay(HAL_RelayHandle relayPortHandle, HAL_Bool on,
|
||||
int32_t* status) {
|
||||
auto port = relayHandles.Get(relayPortHandle);
|
||||
auto port = relayHandles->Get(relayPortHandle);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
@@ -119,7 +129,7 @@ void HAL_SetRelay(HAL_RelayHandle relayPortHandle, HAL_Bool on,
|
||||
* Get the current state of the relay channel
|
||||
*/
|
||||
HAL_Bool HAL_GetRelay(HAL_RelayHandle relayPortHandle, int32_t* status) {
|
||||
auto port = relayHandles.Get(relayPortHandle);
|
||||
auto port = relayHandles->Get(relayPortHandle);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user