Now you can download a copy of these docs so you can use them offline! Download now
AnalogTrigger.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 "AnalogTrigger.h" 00008 00009 #include "AnalogChannel.h" 00010 #include "AnalogModule.h" 00011 #include "Resource.h" 00012 #include "WPIErrors.h" 00013 00014 static Resource *triggers = NULL; 00015 00020 void AnalogTrigger::InitTrigger(UINT8 moduleNumber, UINT32 channel) 00021 { 00022 Resource::CreateResourceObject(&triggers, tAnalogTrigger::kNumSystems); 00023 UINT32 index = triggers->Allocate("Analog Trigger"); 00024 if (index == ~0ul) 00025 { 00026 CloneError(triggers); 00027 return; 00028 } 00029 m_index = (UINT8)index; 00030 m_channel = channel; 00031 m_analogModule = AnalogModule::GetInstance(moduleNumber); 00032 00033 tRioStatusCode localStatus = NiFpga_Status_Success; 00034 m_trigger = tAnalogTrigger::create(m_index, &localStatus); 00035 m_trigger->writeSourceSelect_Channel(m_channel - 1, &localStatus); 00036 m_trigger->writeSourceSelect_Module(moduleNumber - 1, &localStatus); 00037 wpi_setError(localStatus); 00038 } 00039 00046 AnalogTrigger::AnalogTrigger(UINT32 channel) 00047 { 00048 InitTrigger(GetDefaultAnalogModule(), channel); 00049 } 00050 00057 AnalogTrigger::AnalogTrigger(UINT8 moduleNumber, UINT32 channel) 00058 { 00059 InitTrigger(moduleNumber, channel); 00060 } 00061 00067 AnalogTrigger::AnalogTrigger(AnalogChannel *channel) 00068 { 00069 InitTrigger(channel->GetModuleNumber(), channel->GetChannel()); 00070 } 00071 00072 AnalogTrigger::~AnalogTrigger() 00073 { 00074 triggers->Free(m_index); 00075 delete m_trigger; 00076 } 00077 00083 void AnalogTrigger::SetLimitsRaw(INT32 lower, INT32 upper) 00084 { 00085 if (StatusIsFatal()) return; 00086 if (lower > upper) 00087 { 00088 wpi_setWPIError(AnalogTriggerLimitOrderError); 00089 } 00090 tRioStatusCode localStatus = NiFpga_Status_Success; 00091 m_trigger->writeLowerLimit(lower, &localStatus); 00092 m_trigger->writeUpperLimit(upper, &localStatus); 00093 wpi_setError(localStatus); 00094 } 00095 00100 void AnalogTrigger::SetLimitsVoltage(float lower, float upper) 00101 { 00102 if (StatusIsFatal()) return; 00103 if (lower > upper) 00104 { 00105 wpi_setWPIError(AnalogTriggerLimitOrderError); 00106 } 00107 // TODO: This depends on the averaged setting. Only raw values will work as is. 00108 tRioStatusCode localStatus = NiFpga_Status_Success; 00109 m_trigger->writeLowerLimit(m_analogModule->VoltsToValue(m_channel, lower), &localStatus); 00110 m_trigger->writeUpperLimit(m_analogModule->VoltsToValue(m_channel, upper), &localStatus); 00111 wpi_setError(localStatus); 00112 } 00113 00119 void AnalogTrigger::SetAveraged(bool useAveragedValue) 00120 { 00121 if (StatusIsFatal()) return; 00122 tRioStatusCode localStatus = NiFpga_Status_Success; 00123 if (m_trigger->readSourceSelect_Filter(&localStatus) != 0) 00124 wpi_setWPIErrorWithContext(IncompatibleMode, "Hardware does not support average and filtering at the same time."); 00125 m_trigger->writeSourceSelect_Averaged(useAveragedValue, &localStatus); 00126 wpi_setError(localStatus); 00127 } 00128 00134 void AnalogTrigger::SetFiltered(bool useFilteredValue) 00135 { 00136 if (StatusIsFatal()) return; 00137 tRioStatusCode localStatus = NiFpga_Status_Success; 00138 if (m_trigger->readSourceSelect_Averaged(&localStatus) != 0) 00139 wpi_setWPIErrorWithContext(IncompatibleMode, "Hardware does not support average and filtering at the same time."); 00140 m_trigger->writeSourceSelect_Filter(useFilteredValue, &localStatus); 00141 wpi_setError(localStatus); 00142 } 00143 00149 UINT32 AnalogTrigger::GetIndex() 00150 { 00151 if (StatusIsFatal()) return ~0ul; 00152 return m_index; 00153 } 00154 00160 bool AnalogTrigger::GetInWindow() 00161 { 00162 if (StatusIsFatal()) return false; 00163 tRioStatusCode localStatus = NiFpga_Status_Success; 00164 bool result = m_trigger->readOutput_InHysteresis(m_index, &localStatus) != 0; 00165 wpi_setError(localStatus); 00166 return result; 00167 } 00168 00176 bool AnalogTrigger::GetTriggerState() 00177 { 00178 if (StatusIsFatal()) return false; 00179 tRioStatusCode localStatus = NiFpga_Status_Success; 00180 bool result = m_trigger->readOutput_OverLimit(m_index, &localStatus) != 0; 00181 wpi_setError(localStatus); 00182 return result; 00183 } 00184 00192 AnalogTriggerOutput *AnalogTrigger::CreateOutput(AnalogTriggerOutput::Type type) 00193 { 00194 if (StatusIsFatal()) return NULL; 00195 return new AnalogTriggerOutput(this, type); 00196 } 00197
Generated on Thu Jan 12 2012 22:35:17 for WPILibC++ by
1.7.1