/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }