Now you can download a copy of these docs so you can use them offline! Download now
Compressor.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 "Compressor.h" 00008 #include "DigitalInput.h" 00009 #include "Timer.h" 00010 #include "WPIErrors.h" 00011 00020 static void compressorChecker(Compressor *c) 00021 { 00022 while (1) 00023 { 00024 if (c->Enabled()) 00025 { 00026 c->SetRelayValue( c->GetPressureSwitchValue() == 0 ? Relay::kOn : Relay::kOff ); 00027 } 00028 else 00029 { 00030 c->SetRelayValue(Relay::kOff); 00031 } 00032 Wait(0.5); 00033 } 00034 } 00035 00044 void Compressor::InitCompressor(UINT8 pressureSwitchModuleNumber, 00045 UINT32 pressureSwitchChannel, 00046 UINT8 compresssorRelayModuleNumber, 00047 UINT32 compressorRelayChannel) 00048 { 00049 m_enabled = false; 00050 m_pressureSwitch = new DigitalInput(pressureSwitchModuleNumber, pressureSwitchChannel); 00051 m_relay = new Relay(compresssorRelayModuleNumber, compressorRelayChannel, Relay::kForwardOnly); 00052 00053 if (!m_task.Start((INT32)this)) 00054 { 00055 wpi_setWPIError(CompressorTaskError); 00056 } 00057 } 00058 00070 Compressor::Compressor(UINT8 pressureSwitchModuleNumber, 00071 UINT32 pressureSwitchChannel, 00072 UINT8 compresssorRelayModuleNumber, 00073 UINT32 compressorRelayChannel) 00074 : m_task ("Compressor", (FUNCPTR)compressorChecker) 00075 { 00076 InitCompressor(pressureSwitchModuleNumber, 00077 pressureSwitchChannel, 00078 compresssorRelayModuleNumber, 00079 compressorRelayChannel); 00080 } 00081 00092 Compressor::Compressor(UINT32 pressureSwitchChannel, UINT32 compressorRelayChannel) 00093 : m_task ("Compressor", (FUNCPTR)compressorChecker) 00094 { 00095 InitCompressor(GetDefaultDigitalModule(), 00096 pressureSwitchChannel, 00097 GetDefaultDigitalModule(), 00098 compressorRelayChannel); 00099 } 00100 00106 Compressor::~Compressor() 00107 { 00108 delete m_pressureSwitch; 00109 delete m_relay; 00110 } 00111 00117 void Compressor::SetRelayValue(Relay::Value relayValue) 00118 { 00119 m_relay->Set(relayValue); 00120 } 00121 00128 UINT32 Compressor::GetPressureSwitchValue() 00129 { 00130 return m_pressureSwitch->Get(); 00131 } 00132 00138 void Compressor::Start() 00139 { 00140 m_enabled = true; 00141 } 00142 00147 void Compressor::Stop() 00148 { 00149 m_enabled = false; 00150 } 00151 00159 bool Compressor::Enabled() 00160 { 00161 return m_enabled; 00162 } 00163
Generated on Thu Jan 12 2012 22:35:18 for WPILibC++ by
1.7.1