コード例 #1
0
ファイル: Solenoid.cpp プロジェクト: FRC2539/wpilib
/**
 * Destructor.
 */
Solenoid::~Solenoid()
{
	if (CheckSolenoidModule(m_moduleNumber))
	{
		m_allocated->Free((m_moduleNumber - 1) * kSolenoidChannels + m_channel - 1);
	}
}
コード例 #2
0
ファイル: Solenoid.cpp プロジェクト: FRC2539/wpilib
/**
 * Common function to implement constructor behavior.
 */
void Solenoid::InitSolenoid()
{
	m_table = NULL;
	char buf[64];
	if (!CheckSolenoidModule(m_moduleNumber))
	{
		snprintf(buf, 64, "Solenoid Module %d", m_moduleNumber);
		wpi_setWPIErrorWithContext(ModuleIndexOutOfRange, buf);
		return;
	}
	if (!CheckSolenoidChannel(m_channel))
	{
		snprintf(buf, 64, "Solenoid Channel %d", m_channel);
		wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf);
		return;
	}
	Resource::CreateResourceObject(&m_allocated, tSolenoid::kNumDO7_0Elements * kSolenoidChannels);

	snprintf(buf, 64, "Solenoid %d (Module: %d)", m_channel, m_moduleNumber);
	if (m_allocated->Allocate((m_moduleNumber - 1) * kSolenoidChannels + m_channel - 1, buf) == ~0ul)
	{
		CloneError(m_allocated);
		return;
	}

	LiveWindow::GetInstance()->AddActuator("Solenoid", m_moduleNumber, m_channel, this);
	nUsageReporting::report(nUsageReporting::kResourceType_Solenoid, m_channel, m_moduleNumber - 1);
}
コード例 #3
0
/**
 * Constructor.
 *
 * @param moduleNumber The CAN ID of the PCM the solenoid is attached to
 * @param channel The channel on the PCM to control (0..7).
 */
Solenoid::Solenoid(uint8_t moduleNumber, uint32_t channel)
    : SolenoidBase(moduleNumber), m_channel(channel) {
  std::stringstream buf;
  if (!CheckSolenoidModule(m_moduleNumber)) {
    buf << "Solenoid Module " << m_moduleNumber;
    wpi_setWPIErrorWithContext(ModuleIndexOutOfRange, buf.str());
    return;
  }
  if (!CheckSolenoidChannel(m_channel)) {
    buf << "Solenoid Module " << m_channel;
    wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
    return;
  }
  Resource::CreateResourceObject(m_allocated, m_maxModules * m_maxPorts);
  buf << "Solenoid " << m_channel << " (Module: " << m_moduleNumber << ")";
  if (m_allocated->Allocate(m_moduleNumber * kSolenoidChannels + m_channel,
                            buf.str()) ==
      std::numeric_limits<uint32_t>::max()) {
    CloneError(*m_allocated);
    return;
  }

#if FULL_WPILIB
  LiveWindow::GetInstance()->AddActuator("Solenoid", m_moduleNumber, m_channel,
                                         this);
#endif
  HALReport(HALUsageReporting::kResourceType_Solenoid, m_channel,
            m_moduleNumber);
}
コード例 #4
0
ファイル: DoubleSolenoid.cpp プロジェクト: HiceS/synthesis
/**
 * Destructor.
 */
DoubleSolenoid::~DoubleSolenoid()
{
	if (CheckSolenoidModule(m_moduleNumber))
	{
		m_allocated->Free((m_moduleNumber - 1) * kSolenoidChannels + m_forwardChannel - 1);
		m_allocated->Free((m_moduleNumber - 1) * kSolenoidChannels + m_reverseChannel - 1);
	}
}
コード例 #5
0
/**
 * Destructor.
 */
Solenoid::~Solenoid() {
  if (CheckSolenoidModule(m_moduleNumber)) {
    m_allocated->Free(m_moduleNumber * kSolenoidChannels + m_channel);
  }
#if FULL_WPILIB
  if (m_table != nullptr) m_table->RemoveTableListener(this);
#endif
}
コード例 #6
0
ファイル: SolenoidBase.cpp プロジェクト: 128keaton/wpilib
/**
 * Read all 8 solenoids as a single byte
 * 
 * @return The current value of all 8 solenoids on the module.
 */
UINT8 SolenoidBase::GetAll()
{
	if (CheckSolenoidModule(m_moduleNumber))
	{
		tRioStatusCode localStatus = NiFpga_Status_Success;
		UINT8 solenoids = m_fpgaSolenoidModule->readDO7_0(m_moduleNumber - 1, &localStatus);
		wpi_setError(localStatus);
		return solenoids;
	}
	return 0;
}
コード例 #7
0
ファイル: SolenoidBase.cpp プロジェクト: 128keaton/wpilib
/**
 * Destructor.
 */
SolenoidBase::~SolenoidBase()
{
	Synchronized sync(m_semaphore);
	if (CheckSolenoidModule(m_moduleNumber))
	{
		if (m_refCount == 1)
		{
			delete m_fpgaSolenoidModule;
			m_fpgaSolenoidModule = NULL;
		}
		m_refCount--;
	}
}
コード例 #8
0
ファイル: SolenoidBase.cpp プロジェクト: 128keaton/wpilib
/**
 * 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.
 */
void SolenoidBase::Set(UINT8 value, UINT8 mask)
{
	tRioStatusCode localStatus = NiFpga_Status_Success;
	if (CheckSolenoidModule(m_moduleNumber))
	{
		Synchronized sync(m_semaphore);
		UINT8 currentValue = m_fpgaSolenoidModule->readDO7_0(m_moduleNumber - 1, &localStatus);
		// Zero out the values to change
		currentValue = currentValue & ~mask;
		currentValue = currentValue | (value & mask);
		m_fpgaSolenoidModule->writeDO7_0(m_moduleNumber - 1, currentValue, &localStatus);
	}
	wpi_setError(localStatus);
}
コード例 #9
0
ファイル: Solenoid.cpp プロジェクト: FRC980/FRC-Team-980
/**
 * Common function to implement constructor behavior.
 */
void Solenoid::InitSolenoid()
{
	Resource::CreateResourceObject(&allocated, tSolenoid::kNumSystems * kSolenoidChannels);
	CheckSolenoidModule(m_chassisSlot);
	CheckSolenoidChannel(m_channel);

	m_refCount++;
	if (m_refCount == 1)
	{
		// Needs to be global since the protected resource spans all Solenoid objects.
		m_semaphore = semMCreate(SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE);
		m_fpgaSolenoidModule = new tSolenoid(&status);
	}

	allocated->Allocate(SlotToIndex(m_chassisSlot) * kSolenoidChannels + m_channel - 1);
	wpi_assertCleanStatus(status);
}
コード例 #10
0
/**
 * Common function to implement constructor behavior.
 */
void DoubleSolenoid::InitSolenoid()
{
    char buf[64];
    if (!CheckSolenoidModule(m_moduleNumber))
    {
	snprintf(buf, 64, "Solenoid Module %lu", m_moduleNumber);
	wpi_setWPIErrorWithContext(ModuleIndexOutOfRange, buf);
	return;
    }
    if (!CheckSolenoidChannel(m_forwardChannel))
    {
	snprintf(buf, 64, "Solenoid Channel %lu", m_forwardChannel);
	wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf);
	return;
    }
    if (!CheckSolenoidChannel(m_reverseChannel))
    {
	snprintf(buf, 64, "Solenoid Channel %lu", m_reverseChannel);
	wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf);
	return;
    }
    Resource::CreateResourceObject(&m_allocated, tSolenoid::kNumDO7_0Elements * kSolenoidChannels);

    snprintf(buf, 64, "Solenoid %lu (Module %lu)", m_forwardChannel, m_moduleNumber);
    if (m_allocated->Allocate((m_moduleNumber - 1) * kSolenoidChannels + m_forwardChannel - 1, buf) == ~0ul)
    {
	CloneError(m_allocated);
	return;
    }
    snprintf(buf, 64, "Solenoid %lu (Module %lu)", m_reverseChannel, m_moduleNumber);
    if (m_allocated->Allocate((m_moduleNumber - 1) * kSolenoidChannels + m_reverseChannel - 1, buf) == ~0ul)
    {
	CloneError(m_allocated);
	return;
    }
    m_forwardMask = 1 << (m_forwardChannel - 1);
    m_reverseMask = 1 << (m_reverseChannel - 1);

    nUsageReporting::report(nUsageReporting::kResourceType_Solenoid, m_forwardChannel, m_moduleNumber - 1);
    nUsageReporting::report(nUsageReporting::kResourceType_Solenoid, m_reverseChannel, m_moduleNumber - 1);

    LiveWindow::GetInstance()->AddActuator("Double Solenoid", m_moduleNumber, m_forwardChannel, this);
}