Changes HAL Port from a pointer to a handle (#93)

HAL Port is using a special handle, where the module and pin are bit
shifted straight into the handle. This is one of the few special cases
we have, but for the way port is used it is much cleaner and uses much
less memory.  Plus it is generic and not specific to one type.
This commit is contained in:
Thad House
2016-06-05 15:23:58 -07:00
committed by Peter Johnson
parent 5a82f73d9b
commit fc515f4572
44 changed files with 288 additions and 233 deletions

View File

@@ -10,8 +10,8 @@
#include "ChipObject.h"
#include "FRC_NetworkCommunication/LoadOut.h"
#include "HAL/Errors.h"
#include "HAL/Port.h"
#include "ctre/PCM.h"
#include "handles/HandlesInternal.h"
static const int NUM_MODULE_NUMBERS = 63;
@@ -28,15 +28,23 @@ void initializePCM(int module) {
}
}
using namespace hal;
extern "C" {
void* initializeSolenoidPort(void* port_pointer, int32_t* status) {
Port* port = (Port*)port_pointer;
initializePCM(port->module);
void* initializeSolenoidPort(HalPortHandle port_handle, int32_t* status) {
int16_t pin = getPortHandlePin(port_handle);
int16_t module = getPortHandleModule(port_handle);
if (pin == HAL_HANDLE_INVALID_TYPE) {
*status = PARAMETER_OUT_OF_RANGE;
return nullptr;
}
initializePCM(module);
solenoid_port_t* solenoid_port = new solenoid_port_t;
solenoid_port->module = PCM_modules[port->module];
solenoid_port->pin = port->pin;
solenoid_port->module = PCM_modules[module];
solenoid_port->pin = pin;
return solenoid_port;
}