Example #1
0
void Moids::init()
{
	m_dontReadCounter = 0;
	m_numOtherMoids = 0;
	m_firstTimeAfterStateTransition = false;
	m_relayOnTimeCounter = 0;
	m_waitAfterDetectCounter = 0;
	m_timerCounter = 0;
	m_micOffset = 0;
	m_nopWait = (unsigned long) 500;
	m_nopWaitCounter = 0;
	m_needOscillation = false;
	m_relayOffTime = 0;
	m_relayOffCounter = 0;
	m_oscillatorCountMax = 0;
	m_oscillation_high = false;

	for (int i = 0; i < NUM_OTHER_MOIDS; i++)
	{
		m_otherMoids[i] = NULL;
	}

	makeOffset();
	changeState(ReadAnalog);
}
 Direction::Direction()
 :myAttributes( std::make_shared<DirectionAttributes>() )
 ,myDirectionTypeSet()
 ,myOffset( makeOffset() )
 ,myHasOffset( false )
 ,myEditorialVoiceDirectionGroup( makeEditorialVoiceDirectionGroup() )
 ,myStaff( makeStaff() )
 ,myHasStaff( false )
 ,mySound( makeSound() )
 ,myHasSound( false )
 {
     myDirectionTypeSet.push_back( makeDirectionType() );
 }
Example #3
0
void Moids::readAnalogInput()
{
	if (m_dontReadCounter)
	{
		return;
	}

	if (m_firstTimeAfterStateTransition)
	{
		m_firstTimeAfterStateTransition = false;
		makeOffset();

		int read = analogRead(m_inputMicPin) - m_micOffset;
		for (int i = 0; i < MIC_INPUT_ARRAY_LENGTH; i++)
		{
			m_micInput[i] = read;
		}
	}

	// read Input
	m_micInput[0] = analogRead(m_inputMicPin) - m_micOffset;

	// check threshold
	bool changed = checkInput();
	m_micInput[1] = m_micInput[0];

	if (changed)
	{
		if (STRICT_CHECKING) {
			// double checking
			m_micInput[0] = analogRead(m_inputMicPin) - m_micOffset;
			changed = checkInput();
			m_micInput[1] = m_micInput[0];
		}

		if (changed) {
			changeState(SoundInput);
		}
	}
}
Example #4
0
uint32_t WorldRegion::findFreeChunkSectorOffset(Chunk* chunk, uint32_t neededSize)
{
	size_t index = getChunkIndex(chunk->mX, chunk->mY, chunk->mZ);
	uint8_t neededSectors = (neededSize / ChunkFileSectorSize) + 1;

	uint32_t offset = mChunkOffsets[index];
	if (getSectorSizeFromOffset(offset) < neededSectors) {
		// Need more space, search a bigger place

		// At first, mark old sectors as free
		for (uint32_t i = getSectorFromOffset(offset); i < getSectorSizeFromOffset(offset); ++i) {
			mFreeChunkSectors[i] = true;
		}

		// Set result to not found
		offset = 0;

		// Now search for a big enough space
		auto startIt = mFreeChunkSectors.begin();
		auto endIt = mFreeChunkSectors.end();
		while (startIt != endIt) {
			// Find first free
			auto posIt = std::find(startIt, endIt, true);

			// Save first free for index calculation
			startIt = posIt;

			// Test if enough space is free
			uint8_t free;
			for (free = 1; free < neededSectors; ++free) {
				++posIt;
				if (*posIt == false || posIt == endIt) {
					break;
				}
			}
			if (free == neededSectors) {
				// Found big enough place
				uint32_t sector = std::distance(mFreeChunkSectors.begin(), startIt);
				offset = makeOffset(sector, neededSectors);
				
				if (sector + neededSectors > mFreeChunkSectors.size()) {
					mFreeChunkSectors.resize(mFreeChunkSectors.size() * 2, true);
				}

				// Mark found sectors as used
				mChunkOffsets[index] = offset;
				for (uint32_t i = sector; i < sector + neededSectors; ++i) {
					mFreeChunkSectors[i] = false;
				}

				break;
			} else {
				// not big enough, start over
				startIt = posIt;
			}
		}

	} else {
		// Old space is big enough, reuse it
	}

	return offset;
}