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

📄 cgeartooth.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 "CGearTooth.h"
#include "DigitalModule.h"

static GearTooth* gearToothSensors[SensorBase::kChassisSlots][SensorBase::kDigitalChannels];
static bool initialized = false;

/**
 * Get a pointer to the gear tooth sensor given a slot and a channel.
 * This is an internal routine to allocate (if necessary) a gear tooth
 * object from inputs.
 * @param slot The slot the GearTooth sensor is plugged into.
 * @param channel The channel the GearTooth sensor is plugged into.
 */
static GearTooth *GTptr(UINT32 slot, UINT32 channel)
{
	if (!initialized)
	{
		initialized = true;
		for (unsigned i = 0; i < SensorBase::kChassisSlots; i++)
			for (unsigned j = 0; j < SensorBase::kDigitalChannels; j++)
				gearToothSensors[i][j] = NULL;
	}
	GearTooth *gt = NULL;
	if (SensorBase::CheckDigitalModule(slot) && SensorBase::CheckDigitalChannel(channel))
	{
		UINT32 slotIndex = DigitalModule::SlotToIndex(slot);
		gt = gearToothSensors[slotIndex][channel - 1];
		if (gt == NULL)
		{
			gt = new GearTooth(slot, channel);
			gearToothSensors[slotIndex][channel - 1] = gt;
		}
	}
	return gt;
}

/**
 * Initialize the gear tooth sensor.
 *
 * @param slot The slot the digital module is plugged into
 * @param channel The digital I/O channel the sensor is plugged into
 * @param directionSensitive True if this geartooth sensor can differentiate between
 * foward and backward movement.
 */
void InitGearTooth(UINT32 slot, UINT32 channel, bool directionSensitive)
{
	GearTooth *gt = GTptr(slot, channel);
	if (gt) gt->EnableDirectionSensing(directionSensitive);
}

/**
 * Initialize the gear tooth sensor.
 *
 * @param channel The digital I/O channel the sensor is plugged into
 * @param directionSensitive True if this geartooth sensor can differentiate between
 * foward and backward movement.
 */
void InitGearTooth(UINT32 channel, bool directionSensitive)
{
	InitGearTooth(SensorBase::GetDefaultDigitalModule(), channel, directionSensitive);
}

/**
 * Start the GearTooth sensor counting.
 * Start the counting for the geartooth sensor. Before this, the sensor is allocated
 * but not counting pulses.
 * * @param slot The slot the digital module is plugged into
 * @param channel The digital I/O channel the sensor is plugged into
 */
void StartGearTooth(UINT32 slot, UINT32 channel)
{
	GearTooth *gt = GTptr(slot, channel);
	if (gt) gt->Start();
}

/**
 * Start the GearTooth sensor counting.
 * Start the counting for the geartooth sensor. Before this, the sensor is allocated
 * but not counting pulses.
 *
 * @param channel The digital I/O channel the sensor is plugged into
 */
void StartGearTooth(UINT32 channel)
{
	StartGearTooth(SensorBase::GetDefaultDigitalModule(), channel);
}

/**
 * Stop the gear tooth sensor from counting.
 * The counting is disabled on the underlying Counter object.
 * * @param slot The slot the digital module is plugged into
 * @param channel The digital I/O channel the sensor is plugged into
 */
void StopGearTooth(UINT32 slot, UINT32 channel)
{
	GearTooth *gt = GTptr(slot, channel);
	if (gt) gt->Stop();
}

/**
 * Stop the gear tooth sensor from counting.
 * The counting is disabled on the underlying Counter object.
 *
 * @param channel The digital I/O channel the sensor is plugged into
 */
void StopGearTooth(UINT32 channel)
{
	StopGearTooth(SensorBase::GetDefaultDigitalModule(), channel);
}

/**
 * Get value from GearTooth sensor.
 * Get the current count from the sensor.
 * * @param slot The slot the digital module is plugged into
 * @param channel The digital I/O channel the sensor is plugged into
 */
INT32 GetGearTooth(UINT32 slot, UINT32 channel)
{
	GearTooth *gt = GTptr(slot, channel);
	if (gt) return gt->Get();
	return 0;
}

/**
 * Get value from GearTooth sensor.
 * Get the current count from the sensor.
 *
 * @param channel The digital I/O channel the sensor is plugged into
 */
INT32 GetGearTooth(UINT32 channel)
{
	return GetGearTooth(SensorBase::GetDefaultDigitalModule(), channel);
}

/**
 * Reset the GearTooth sensor.
 * Reset the count to zero for the gear tooth sensor.
 *
 * @param slot The slot the digital module is plugged into
 * @param channel The digital I/O channel the sensor is plugged into
 */
void ResetGearTooth(UINT32 slot, UINT32 channel)
{
	GearTooth *gt = GTptr(slot, channel);
	if (gt) gt->Reset();
}

/**
 * Reset the GearTooth sensor.
 * Reset the count to zero for the gear tooth sensor.
 *
 * @param channel The digital I/O channel the sensor is plugged into
 */
void ResetGearTooth(UINT32 channel)
{
	ResetGearTooth(SensorBase::GetDefaultDigitalModule(), channel);
}

/**
 * Free the resources associated with this gear tooth sensor.
 * Delete the underlying object and free the resources for this geartooth
 * sensor.
 * * @param slot The slot the digital module is plugged into
 * @param channel The digital I/O channel the sensor is plugged into
 */
void DeleteGearTooth(UINT32 slot, UINT32 channel)
{
	if (SensorBase::CheckDigitalModule(slot) && SensorBase::CheckDigitalChannel(channel))
	{
		UINT32 slotIndex = DigitalModule::SlotToIndex(slot);
		delete gearToothSensors[slotIndex][channel - 1];
		gearToothSensors[slotIndex][channel - 1] = NULL;
	}
}

/**
 * Free the resources associated with this gear tooth sensor.
 * Delete the underlying object and free the resources for this geartooth
 * sensor.
 *
 * @param channel The digital I/O channel the sensor is plugged into
 */
void DeleteGearTooth(UINT32 channel)
{
	DeleteGearTooth(SensorBase::GetDefaultDigitalModule(), channel);
}

⌨️ 快捷键说明

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