2013-12-15 18:30:16 -05:00
|
|
|
|
2014-05-02 17:54:01 -04:00
|
|
|
#include "HAL/Solenoid.hpp"
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
#include "Port.h"
|
2014-05-02 17:54:01 -04:00
|
|
|
#include "HAL/Errors.hpp"
|
2013-12-15 18:30:16 -05:00
|
|
|
#include "ChipObject.h"
|
2014-05-02 17:54:01 -04:00
|
|
|
#include "HAL/cpp/Synchronized.hpp"
|
2013-12-15 18:30:16 -05:00
|
|
|
#include "NetworkCommunication/LoadOut.h"
|
2014-05-29 14:25:09 -04:00
|
|
|
#include "ctre/PCM.h"
|
|
|
|
|
|
2014-07-02 15:15:56 -04:00
|
|
|
static const int NUM_MODULE_NUMBERS = 63;
|
2014-05-29 14:25:09 -04:00
|
|
|
|
2014-07-02 15:15:56 -04:00
|
|
|
PCM *modules[NUM_MODULE_NUMBERS] = { NULL };
|
2014-05-29 14:25:09 -04:00
|
|
|
|
|
|
|
|
struct solenoid_port_t {
|
|
|
|
|
PCM *module;
|
|
|
|
|
uint32_t pin;
|
|
|
|
|
};
|
|
|
|
|
|
2014-07-02 15:15:56 -04:00
|
|
|
void initializePCM(int module) {
|
|
|
|
|
if(!modules[module]) {
|
|
|
|
|
modules[module] = new PCM(module);
|
2014-05-29 14:25:09 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void* initializeSolenoidPort(void *port_pointer, int32_t *status) {
|
|
|
|
|
Port* port = (Port*) port_pointer;
|
2014-07-02 15:15:56 -04:00
|
|
|
initializePCM(port->module);
|
|
|
|
|
|
2014-05-29 14:25:09 -04:00
|
|
|
solenoid_port_t *solenoid_port = new solenoid_port_t;
|
2014-07-02 15:15:56 -04:00
|
|
|
solenoid_port->module = modules[port->module];
|
2014-05-29 14:25:09 -04:00
|
|
|
solenoid_port->pin = port->pin;
|
2014-06-16 10:24:48 -04:00
|
|
|
|
2014-05-29 14:25:09 -04:00
|
|
|
return solenoid_port;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool checkSolenoidModule(uint8_t module) {
|
2014-07-02 15:15:56 -04:00
|
|
|
return module < NUM_MODULE_NUMBERS;
|
2014-05-29 14:25:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool getSolenoid(void* solenoid_port_pointer, int32_t *status) {
|
|
|
|
|
solenoid_port_t* port = (solenoid_port_t*) solenoid_port_pointer;
|
|
|
|
|
bool value;
|
2014-06-16 10:24:48 -04:00
|
|
|
|
2014-05-29 14:25:09 -04:00
|
|
|
*status = port->module->GetSolenoid(port->pin, value);
|
2014-06-16 10:24:48 -04:00
|
|
|
|
2014-05-29 14:25:09 -04:00
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setSolenoid(void* solenoid_port_pointer, bool value, int32_t *status) {
|
|
|
|
|
solenoid_port_t* port = (solenoid_port_t*) solenoid_port_pointer;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2014-06-16 10:24:48 -04:00
|
|
|
port->module->SetSolenoid(port->pin, value);
|
|
|
|
|
}
|