2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/* 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. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "SolenoidBase.h"
|
|
|
|
|
|
|
|
|
|
// Needs to be global since the protected resource spans all Solenoid objects.
|
|
|
|
|
Resource *SolenoidBase::m_allocated = NULL;
|
|
|
|
|
|
2015-06-17 14:42:09 -04:00
|
|
|
void* SolenoidBase::m_ports[m_maxModules][m_maxPorts];
|
2013-12-15 18:30:16 -05:00
|
|
|
/**
|
|
|
|
|
* Constructor
|
|
|
|
|
*
|
2014-12-29 14:09:37 -05:00
|
|
|
* @param moduleNumber The CAN PCM ID.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
|
|
|
|
SolenoidBase::SolenoidBase(uint8_t moduleNumber)
|
|
|
|
|
: m_moduleNumber (moduleNumber)
|
|
|
|
|
{
|
2015-06-17 14:42:09 -04:00
|
|
|
for (uint32_t i = 0; i < kSolenoidChannels; i++)
|
2013-12-15 18:30:16 -05:00
|
|
|
{
|
2015-06-17 14:42:09 -04:00
|
|
|
void* port = getPortWithModule(moduleNumber, i);
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
SolenoidBase::m_ports[moduleNumber][i] = initializeSolenoidPort(port, &status);
|
|
|
|
|
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Destructor.
|
|
|
|
|
*/
|
|
|
|
|
SolenoidBase::~SolenoidBase()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the value of a solenoid.
|
|
|
|
|
*
|
|
|
|
|
* @param value The value you want to set on the module.
|
|
|
|
|
* @param mask The channels you want to be affected.
|
|
|
|
|
*/
|
2015-06-17 14:42:09 -04:00
|
|
|
void SolenoidBase::Set(uint8_t value, uint8_t mask, int module)
|
2013-12-15 18:30:16 -05:00
|
|
|
{
|
|
|
|
|
int32_t status = 0;
|
2015-06-17 14:42:09 -04:00
|
|
|
for (int i = 0; i < m_maxPorts; i++) {
|
2013-12-15 18:30:16 -05:00
|
|
|
uint8_t local_mask = 1 << i;
|
|
|
|
|
if (mask & local_mask)
|
2015-06-17 14:42:09 -04:00
|
|
|
setSolenoid(m_ports[module][i], value & local_mask, &status);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read all 8 solenoids as a single byte
|
|
|
|
|
*
|
|
|
|
|
* @return The current value of all 8 solenoids on the module.
|
|
|
|
|
*/
|
2015-06-19 17:23:54 -07:00
|
|
|
uint8_t SolenoidBase::GetAll(int module) const
|
2013-12-15 18:30:16 -05:00
|
|
|
{
|
|
|
|
|
uint8_t value = 0;
|
|
|
|
|
int32_t status = 0;
|
2015-06-17 14:42:09 -04:00
|
|
|
for (int i = 0; i < m_maxPorts; i++) {
|
|
|
|
|
value |= getSolenoid(m_ports[module][i], &status) << i;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
return value;
|
|
|
|
|
}
|
2014-12-26 19:40:39 -05:00
|
|
|
/**
|
|
|
|
|
* Reads complete solenoid blacklist for all 8 solenoids as a single byte.
|
|
|
|
|
*
|
|
|
|
|
* If a solenoid is shorted, it is added to the blacklist and
|
|
|
|
|
* disabled until power cycle, or until faults are cleared.
|
|
|
|
|
* @see ClearAllPCMStickyFaults()
|
|
|
|
|
*
|
|
|
|
|
* @return The solenoid blacklist of all 8 solenoids on the module.
|
|
|
|
|
*/
|
2015-06-19 17:23:54 -07:00
|
|
|
uint8_t SolenoidBase::GetPCMSolenoidBlackList(int module) const
|
2014-12-26 19:40:39 -05:00
|
|
|
{
|
|
|
|
|
int32_t status = 0;
|
2015-06-17 14:42:09 -04:00
|
|
|
return getPCMSolenoidBlackList(m_ports[module][0], &status);
|
2014-12-26 19:40:39 -05:00
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @return true if PCM sticky fault is set : The common
|
|
|
|
|
* highside solenoid voltage rail is too low,
|
|
|
|
|
* most likely a solenoid channel is shorted.
|
|
|
|
|
*/
|
2015-06-19 17:23:54 -07:00
|
|
|
bool SolenoidBase::GetPCMSolenoidVoltageStickyFault(int module) const
|
2014-12-26 19:40:39 -05:00
|
|
|
{
|
|
|
|
|
int32_t status = 0;
|
2015-06-17 14:42:09 -04:00
|
|
|
return getPCMSolenoidVoltageStickyFault(m_ports[module][0], &status);
|
2014-12-26 19:40:39 -05:00
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @return true if PCM is in fault state : The common
|
|
|
|
|
* highside solenoid voltage rail is too low,
|
|
|
|
|
* most likely a solenoid channel is shorted.
|
|
|
|
|
*/
|
2015-06-19 17:23:54 -07:00
|
|
|
bool SolenoidBase::GetPCMSolenoidVoltageFault(int module) const
|
2014-12-26 19:40:39 -05:00
|
|
|
{
|
|
|
|
|
int32_t status = 0;
|
2015-06-17 14:42:09 -04:00
|
|
|
return getPCMSolenoidVoltageFault(m_ports[module][0], &status);
|
2014-12-26 19:40:39 -05:00
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Clear ALL sticky faults inside PCM that Compressor is wired to.
|
|
|
|
|
*
|
|
|
|
|
* If a sticky fault is set, then it will be persistently cleared. Compressor drive
|
|
|
|
|
* maybe momentarily disable while flags are being cleared. Care should be
|
|
|
|
|
* taken to not call this too frequently, otherwise normal compressor
|
|
|
|
|
* functionality may be prevented.
|
|
|
|
|
*
|
|
|
|
|
* If no sticky faults are set then this call will have no effect.
|
|
|
|
|
*/
|
2015-06-17 14:42:09 -04:00
|
|
|
void SolenoidBase::ClearAllPCMStickyFaults(int module)
|
2014-12-26 19:40:39 -05:00
|
|
|
{
|
|
|
|
|
int32_t status = 0;
|
2015-06-17 14:42:09 -04:00
|
|
|
return clearAllPCMStickyFaults_sol(m_ports[module][0], &status);
|
2014-12-26 19:40:39 -05:00
|
|
|
}
|