code/WPILib/CInterfaces/CUltrasonic.cpp
/**
 * Internal routine to allocate and initialize resources for an Ultrasonic sensor
 * Allocate the actual Ultrasonic sensor object and the slot/channels associated with them. Then
 * initialize the sensor.
 *
 * @param pingSlot The slot for the digital module for the ping connection
 * @param pingChannel The channel on the digital module for the ping connection
 * @param echoSlot The slot for the digital module for the echo connection
 * @param echoChannel The channel on the digital module for the echo connection
 */
Internal routine to allocate and initialize resources for an Ultrasonic sensor
Allocate the actual Ultrasonic sensor object and the slot/channels associated with them. Then
initialize the sensor.

@param pingSlot The slot for the digital module for the ping connection
@param pingChannel The channel on the digital module for the ping connection
@param echoSlot The slot for the digital module for the echo connection
@param echoChannel The channel on the digital module for the echo connection
Internal routine to allocate and initialize resources for an Ultrasonic sensor Allocate the actual Ultrasonic sensor object and the slot / channels associated with them . Then initialize the sensor . @param pingSlot The slot for the digital module for the ping connection @param pingChannel The channel on the digital module for the ping connection @param echoSlot The slot for the digital module for the echo connection @param echoChannel The channel on the digital module for the echo connection
static void USinit(UINT32 pingSlot, UINT32 pingChannel, UINT32 echoSlot, UINT32 echoChannel)
{
	if (!initialized)
	{
		initialized = true;
		for (unsigned i = 0; i < SensorBase::kChassisSlots; i++)
			for (unsigned j = 0; j < SensorBase::kDigitalChannels; j++)
				ultrasonics[i][j] = NULL;
	}
	if (SensorBase::CheckDigitalModule(pingSlot)
			&& SensorBase::CheckDigitalChannel(pingChannel)
		 	&& SensorBase::CheckDigitalModule(echoSlot)
			&& SensorBase::CheckDigitalChannel(echoChannel))
	{
		if (ultrasonics[DigitalModule::SlotToIndex(pingSlot)][pingChannel - 1] == NULL)
		{
			ultrasonics[DigitalModule::SlotToIndex(pingSlot)][pingChannel - 1] = new Ultrasonic(pingSlot, pingChannel, echoSlot, echoChannel);
			printf("new Ultrasonic(%d, %d, %d, %d)\n", pingSlot, pingChannel, echoSlot, echoChannel);
		}
		Ultrasonic::SetAutomaticMode(true);
	}
}
static void USinit ( UINT32 pingSlot , UINT32 pingChannel , UINT32 echoSlot , UINT32 echoChannel ) { if ( ! initialized ) { initialized = true ; for ( unsigned i = 0 ; i < SensorBase :: kChassisSlots ; i ++ ) for ( unsigned j = 0 ; j < SensorBase :: kDigitalChannels ; j ++ ) ultrasonics [ i ] [ j ] = NULL ; } if ( SensorBase :: CheckDigitalModule ( pingSlot ) && SensorBase :: CheckDigitalChannel ( pingChannel ) && SensorBase :: CheckDigitalModule ( echoSlot ) && SensorBase :: CheckDigitalChannel ( echoChannel ) ) { if ( ultrasonics [ DigitalModule :: SlotToIndex ( pingSlot ) ] [ pingChannel - 1 ] == NULL ) { ultrasonics [ DigitalModule :: SlotToIndex ( pingSlot ) ] [ pingChannel - 1 ] = new Ultrasonic ( pingSlot , pingChannel , echoSlot , echoChannel ) ; printf ( " \n " , pingSlot , pingChannel , echoSlot , echoChannel ) ; } Ultrasonic :: SetAutomaticMode ( true ) ; } }
Internal routine to allocate and initialize resources for an Ultrasonic sensor
 Allocate the actual Ultrasonic sensor object and the slot/channels associated with them.
Internal routine to allocate and initialize resources for an Ultrasonic sensor Allocate the actual Ultrasonic sensor object and the slot / channels associated with them .