Now you can download a copy of these docs so you can use them offline! Download now
SolenoidBase.cpp
00001 /*----------------------------------------------------------------------------*/ 00002 /* Copyright (c) FIRST 2008. All Rights Reserved. */ 00003 /* Open Source Software - may be modified and shared by FRC teams. The code */ 00004 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ 00005 /*----------------------------------------------------------------------------*/ 00006 00007 #include "SolenoidBase.h" 00008 00009 #include "Synchronized.h" 00010 00011 SEM_ID SolenoidBase::m_semaphore = NULL; 00012 Resource *SolenoidBase::m_allocated = NULL; 00013 00014 tSolenoid *SolenoidBase::m_fpgaSolenoidModule = NULL; 00015 UINT32 SolenoidBase::m_refCount = 0; 00016 00017 00023 SolenoidBase::SolenoidBase(UINT8 moduleNumber) 00024 : m_moduleNumber (moduleNumber) 00025 { 00026 m_refCount++; 00027 if (m_refCount == 1) 00028 { 00029 // Needs to be global since the protected resource spans all Solenoid objects. 00030 m_semaphore = semMCreate(SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE); 00031 tRioStatusCode localStatus = NiFpga_Status_Success; 00032 m_fpgaSolenoidModule = tSolenoid::create(&localStatus); 00033 wpi_setError(localStatus); 00034 } 00035 } 00036 00040 SolenoidBase::~SolenoidBase() 00041 { 00042 if (CheckSolenoidModule(m_moduleNumber)) 00043 { 00044 if (m_refCount == 1) 00045 { 00046 delete m_fpgaSolenoidModule; 00047 m_fpgaSolenoidModule = NULL; 00048 semDelete(m_semaphore); 00049 m_semaphore = NULL; 00050 } 00051 m_refCount--; 00052 } 00053 } 00054 00061 void SolenoidBase::Set(UINT8 value, UINT8 mask) 00062 { 00063 tRioStatusCode localStatus = NiFpga_Status_Success; 00064 if (CheckSolenoidModule(m_moduleNumber)) 00065 { 00066 Synchronized sync(m_semaphore); 00067 UINT8 currentValue = m_fpgaSolenoidModule->readDO7_0(m_moduleNumber - 1, &localStatus); 00068 // Zero out the values to change 00069 currentValue = currentValue & ~mask; 00070 currentValue = currentValue | (value & mask); 00071 m_fpgaSolenoidModule->writeDO7_0(m_moduleNumber - 1, currentValue, &localStatus); 00072 } 00073 wpi_setError(localStatus); 00074 } 00075 00081 UINT8 SolenoidBase::GetAll() 00082 { 00083 if (CheckSolenoidModule(m_moduleNumber)) 00084 { 00085 tRioStatusCode localStatus = NiFpga_Status_Success; 00086 UINT8 solenoids = m_fpgaSolenoidModule->readDO7_0(m_moduleNumber - 1, &localStatus); 00087 wpi_setError(localStatus); 00088 return solenoids; 00089 } 00090 return 0; 00091 }
Generated on Thu Jan 12 2012 22:35:24 for WPILibC++ by
1.7.1