Now you can download a copy of these docs so you can use them offline! Download now
SolenoidBase.cpp
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
5 /*----------------------------------------------------------------------------*/
6 
7 #include "SolenoidBase.h"
8 
9 // Needs to be global since the protected resource spans all Solenoid objects.
10 ReentrantSemaphore SolenoidBase::m_semaphore;
11 Resource *SolenoidBase::m_allocated = NULL;
12 
13 tSolenoid *SolenoidBase::m_fpgaSolenoidModule = NULL;
14 uint32_t SolenoidBase::m_refCount = 0;
15 
16 
22 SolenoidBase::SolenoidBase(uint8_t moduleNumber)
23  : m_moduleNumber (moduleNumber)
24 {
25  Synchronized sync(m_semaphore);
26  m_refCount++;
27  if (m_refCount == 1)
28  {
29  tRioStatusCode localStatus = NiFpga_Status_Success;
30  m_fpgaSolenoidModule = tSolenoid::create(&localStatus);
31  wpi_setError(localStatus);
32  }
33 }
34 
39 {
40  Synchronized sync(m_semaphore);
42  {
43  if (m_refCount == 1)
44  {
45  delete m_fpgaSolenoidModule;
46  m_fpgaSolenoidModule = NULL;
47  }
48  m_refCount--;
49  }
50 }
51 
58 void SolenoidBase::Set(uint8_t value, uint8_t mask)
59 {
60  tRioStatusCode localStatus = NiFpga_Status_Success;
62  {
63  Synchronized sync(m_semaphore);
64  uint8_t currentValue = m_fpgaSolenoidModule->readDO7_0(m_moduleNumber - 1, &localStatus);
65  // Zero out the values to change
66  currentValue = currentValue & ~mask;
67  currentValue = currentValue | (value & mask);
68  m_fpgaSolenoidModule->writeDO7_0(m_moduleNumber - 1, currentValue, &localStatus);
69  }
70  wpi_setError(localStatus);
71 }
72 
79 {
81  {
82  tRioStatusCode localStatus = NiFpga_Status_Success;
83  uint8_t solenoids = m_fpgaSolenoidModule->readDO7_0(m_moduleNumber - 1, &localStatus);
84  wpi_setError(localStatus);
85  return solenoids;
86  }
87  return 0;
88 }
virtual ~SolenoidBase()
uint32_t m_moduleNumber
Slot number where the module is plugged into the chassis.
Definition: SolenoidBase.h:29
static bool CheckSolenoidModule(uint8_t moduleNumber)
Definition: SensorBase.cpp:118
uint8_t GetAll()
SolenoidBase(uint8_t moduleNumber)
void Set(uint8_t value, uint8_t mask)

Generated on Sat Apr 26 2014 12:26:45 for WPILibC++ by doxygen 1.8.6