⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 csolenoid.cpp

📁 good luck to everyone!
💻 CPP
字号:
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.							  */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib.  */
/*----------------------------------------------------------------------------*/

#include "Solenoid.h"
#include "CSolenoid.h"

static Solenoid *solenoids[SensorBase::kSolenoidChannels];
static bool initialized = false;

/**
 * Internal allocation function for Solenoid channels.
 * The function is used interally to allocate the Solenoid object and keep track
 * of the channel mapping to the object for subsequent calls.
 *
 * @param channel The channel for the solenoid */
static Solenoid *allocateSolenoid(UINT32 channel)
{
	if (!initialized)
	{
		initialized = true;
		for (unsigned i = 0; i < SensorBase::kSolenoidChannels; i++)
			solenoids[i] = new Solenoid(i + 1);
	}
	if (channel < 1 || channel > SensorBase::kSolenoidChannels)
		return NULL;
	return solenoids[channel - 1];
}

/**
 * Set the value of a solenoid.
 *
 * @param channel The channel on the Solenoid module
 * @param on Turn the solenoid output off or on.
 */
void SetSolenoid(UINT32 channel, bool on)
{
	Solenoid *s = allocateSolenoid(channel);
	if (s != NULL)
		s->Set(on);
}

/**
 * Read the current value of the solenoid.
 *
 * @param channel The channel in the Solenoid module
 * @return The current value of the solenoid.
 */
bool GetSolenoid(UINT32 channel)
{
	Solenoid *s = allocateSolenoid(channel);
	if (s == NULL)
		return false;
	return s->Get();
}

/**
 * Free the resources associated with the Solenoid channel.
 * Free the resources including the Solenoid object for this channel.
 *
 * @param channel The channel in the Solenoid module */
void DeleteSolenoid(UINT32 channel)
{
	if (channel >= 1 && channel <= SensorBase::kSolenoidChannels)
	{
		delete solenoids[channel - 1];
		solenoids[channel - 1] = NULL;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -