Now you can download a copy of these docs so you can use them offline! Download now
Solenoid.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 "Solenoid.h" 00008 #include "WPIErrors.h" 00009 00013 void Solenoid::InitSolenoid() 00014 { 00015 char buf[64]; 00016 if (!CheckSolenoidModule(m_moduleNumber)) 00017 { 00018 snprintf(buf, 64, "Solenoid Module %d", m_moduleNumber); 00019 wpi_setWPIErrorWithContext(ModuleIndexOutOfRange, buf); 00020 return; 00021 } 00022 if (!CheckSolenoidChannel(m_channel)) 00023 { 00024 snprintf(buf, 64, "Solenoid Channel %d", m_channel); 00025 wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf); 00026 return; 00027 } 00028 Resource::CreateResourceObject(&m_allocated, tSolenoid::kNumDO7_0Elements * kSolenoidChannels); 00029 00030 snprintf(buf, 64, "Solenoid %d (Module: %d)", m_channel, m_moduleNumber); 00031 if (m_allocated->Allocate((m_moduleNumber - 1) * kSolenoidChannels + m_channel - 1, buf) == ~0ul) 00032 { 00033 CloneError(m_allocated); 00034 return; 00035 } 00036 } 00037 00043 Solenoid::Solenoid(UINT32 channel) 00044 : SolenoidBase (GetDefaultSolenoidModule()) 00045 , m_channel (channel) 00046 { 00047 InitSolenoid(); 00048 } 00049 00056 Solenoid::Solenoid(UINT8 moduleNumber, UINT32 channel) 00057 : SolenoidBase (moduleNumber) 00058 , m_channel (channel) 00059 { 00060 InitSolenoid(); 00061 } 00062 00066 Solenoid::~Solenoid() 00067 { 00068 if (CheckSolenoidModule(m_moduleNumber)) 00069 { 00070 m_allocated->Free((m_moduleNumber - 1) * kSolenoidChannels + m_channel - 1); 00071 } 00072 } 00073 00079 void Solenoid::Set(bool on) 00080 { 00081 if (StatusIsFatal()) return; 00082 UINT8 value = on ? 0xFF : 0x00; 00083 UINT8 mask = 1 << (m_channel - 1); 00084 00085 SolenoidBase::Set(value, mask); 00086 } 00087 00093 bool Solenoid::Get() 00094 { 00095 if (StatusIsFatal()) return false; 00096 UINT8 value = GetAll() & ( 1 << (m_channel - 1)); 00097 return (value != 0); 00098 }
Generated on Thu Jan 12 2012 22:35:24 for WPILibC++ by
1.7.1