Example #1
0
/**
@brief Performs post-filtering on single line comments, by setting comment blocks to trivial
@param [in]  LineStr				- Line of string to check that must be NULL terminated.
@param [in,out]  Op				- This variable is set to trivial if block should be ignored.
@param [in]  filtercommentsset	- Comment marker set used to indicate comment blocks.
@param [in]  PartOfMultiLineCheck- Set to true, if this block is a multiple line block
*/
static void PostFilterSingleLine(const char* LineStr, OP_TYPE &Op,
	const FilterCommentsSet& filtercommentsset, bool PartOfMultiLineCheck)
{
	if (Op == OP_TRIVIAL)
		return;
	if (filtercommentsset.InlineMarker.empty())
	{//If filtercommentsset.InlineMarker is empty, then no support for single line comment
		return;
	}
	const char *	EndLine = strchr(LineStr, '\0');
	if (EndLine)
	{
		std::string LineData(LineStr, EndLine);
		if (LineData.empty() && PartOfMultiLineCheck)
		{
			Op = OP_TRIVIAL;
			return;
		}

		size_t CommentStr = LineData.find(filtercommentsset.InlineMarker);
		if (CommentStr == std::string::npos)
			return;
		if (!CommentStr)
		{//If it begins with comment string, then this is a trivial difference
			Op = OP_TRIVIAL;
			return;
		}
		//Consider adding code here to check if there's any significant code before the comment string
	}

}
Example #2
0
		Matrix<type>::Matrix( ty_size _lsize , ty_size _csize , type * data )
		{
			this->lineSize		=	_lsize;
			this->columnSize	=	_csize;
			for( ty_size i =0 ; i < this->lineSize ; i++)
			{
				this->matrix_data.push_back( LineData(this->columnSize , data+i*this->columnSize ) );
			}
		}
Example #3
0
File: ain.c Project: lluchs/asuro
int main (void) {
	unsigned int data[2];
	Init();
	while(1) {
		LineData(data);
		PrintInt(data[LEFT]);
		SerPrint("\n");
		PrintInt(data[RIGHT]);
		SerPrint("\n\n\n");
		Msleep(500);
	}
}
Example #4
0
void measureDataPoint(void) {
	unsigned int tmp[2];
	LineData(tmp);
	tmpMeasures[rawCounter] = util_lineCorrection(tmp[LEFT]);
	rawCounter++;;
	
	if (rawCounter >= M_RAW_DATAPOINTS) {
		rawCounter = 0;
		int i;
		int sum = 0;
		for(i = 0; i < M_RAW_DATAPOINTS; i++) {
			sum += tmpMeasures[i];
		}
		sum /= M_RAW_DATAPOINTS;
		
		latestLineData = (latestLineData+1) % M_WINDOW_SIZE;
		lineData[latestLineData] = sum;
	}
}
Example #5
0
void calibrate() {
    // SetMotorPower(M_SLOW, M_SLOW);

    uint linedata[2];
    LineData(linedata);
    uint16_t lds = linedata[0] + linedata[1];

    if (lds<lds_min) {
        lds_min = lds;
    } else if (lds>lds_max) {
        lds_max = lds;
    }

    if (send_lds_data) {
        syd_send_data("line_data", 'h', 2, sizeof(uint), linedata);
        syd_send_data("lds", 'h', 1, sizeof(uint16_t), &lds);
        syd_send_data("lds_min", 'h', 1, sizeof(uint16_t), &lds_min);
        syd_send_data("lds_max", 'h', 1, sizeof(uint16_t), &lds_max);
    }
}
Example #6
0
void count() {
    uint linedata[2];
    LineData(linedata);
    uint16_t lds = linedata[0] + linedata[1];

    uint8_t surface_new;

    if (lds<(uint16_t)(lds_min*1.25)) {
        surface_new = SURFACE_BLACK;
    } else if (lds>(uint16_t)(lds_max*0.75)) {
        surface_new = SURFACE_WHITE;
    }

    if (surface != surface_new) {
        surface_changes++;
        if (surface_new==SURFACE_BLACK) {
            black_stripes++;
        }
        surface = surface_new;
        dump_counters();
    }
}
void CIniFileBase::SaveCurrentSection ( void )
{
	if (!m_CurrentSectionDirty)
	{
		return;
	}
	m_CurrentSectionDirty = false;
	if (m_CurrentSection.length() == 0)
	{
		m_CurrentSection = "default";
	}

	int lineFeedLen = (int)strlen(m_LineFeed);

	if (m_CurrentSectionFilePos == -1)
	{
		//Section has not been added yet
		m_File.Seek(0,CFileBase::end);

		int len = (int)m_CurrentSection.length() + (lineFeedLen * 2) + 5;
		AUTO_PTR<char> SectionName(new char[len]);
		if (m_File.GetLength() < (int)strlen(m_LineFeed))
		{
			sprintf(SectionName.get(),"[%s]%s",m_CurrentSection.c_str(),m_LineFeed);
		}
		else
		{
			sprintf(SectionName.get(),"%s[%s]%s",m_LineFeed,m_CurrentSection.c_str(),m_LineFeed);
		}
		m_File.Write(SectionName.get(),(int)strlen(SectionName.get()));
		m_CurrentSectionFilePos = m_File.GetPosition();
		m_SectionsPos.insert(FILELOC::value_type(m_CurrentSection,m_CurrentSectionFilePos));
	}
	else
	{
		//increase/decrease space needed
		int NeededBufferLen = 0;
		{
			AUTO_PTR<char> LineData(NULL);
			int len = 0;

			for (KeyValueList::iterator iter = m_CurrentSectionData.begin(); iter != m_CurrentSectionData.end(); iter++)
			{
				int newLen = (int)iter->first.length() + (int)iter->second.length() + lineFeedLen + 5;
				if (newLen > len)
				{
					LineData.reset(new char[newLen]);
					len = newLen;
				}
				sprintf(LineData.get(),"%s=%s%s",iter->first.c_str(),iter->second.c_str(),m_LineFeed);
				NeededBufferLen += (int)strlen(LineData.get());
			}
		}
		int currentLen = 0;

		m_File.Seek(m_CurrentSectionFilePos, CFileBase::begin);

		int MaxDataSize = 0, DataSize = 0, ReadPos = 0, result;
		char *Input = NULL, *Data = NULL;
	
		//Skip first line as it is the section name
		int StartPos = m_CurrentSectionFilePos;
		int EndPos = StartPos;
		do {
			result = GetStringFromFile(Input,Data,MaxDataSize,DataSize,ReadPos);
			if (result <= 1) { continue; }
			if (strlen(CleanLine(Input)) <= 1 || Input[0] != '[')
			{
				EndPos = ((m_File.GetPosition() - DataSize) + ReadPos);

				continue; 
			}
			if (Input[0] == '[')
			{
				NeededBufferLen += lineFeedLen;
			}
			break;
		} while (result >= 0);
		currentLen = EndPos - StartPos;

		if (Data) {  delete [] Data;  Data = NULL; }

		if (NeededBufferLen != currentLen)
		{
			fInsertSpaces(StartPos,NeededBufferLen - currentLen);
			m_File.Flush();
			ClearSectionPosList(StartPos);
		}
		//set pointer to beginning of the start pos
		m_File.Seek(StartPos, CFileBase::begin);
	}


	{
		AUTO_PTR<char> LineData(NULL);
		int len = 0;
		
		for (KeyValueList::iterator iter = m_CurrentSectionData.begin(); iter != m_CurrentSectionData.end(); iter++)
		{
			int newLen = (int)iter->first.length() + (int)iter->second.length() + lineFeedLen + 5;
			if (newLen > len)
			{
				LineData.reset(new char[newLen]);
				len = newLen;
			}
			sprintf(LineData.get(),"%s=%s%s",iter->first.c_str(),iter->second.c_str(),m_LineFeed);
			m_File.Write(LineData.get(),(int)strlen(LineData.get()));
		}
	}
	m_File.Flush();
}
Example #8
0
void main(void) {
    Init();
    
    FrontLED(ON);
    int i=0;
    int linienEnde = 0;
    int fast = 200;
    
    unsigned int stData = 0, schwarz = 0;
    //Weißwert festlegen
    unsigned int data[2];
    LineData(data);
    stData = data[LEFT] + data[RIGHT] + 50;
    
    StatusLED(GREEN);
    msleep(3000);
    StatusLED(YELLOW);
    
    //Schwarzwert setzen
    LineData(data);
    schwarz = data[LEFT] + data[RIGHT];
    
    msleep(1000);
    StatusLED(GREEN);
    
    
    MotorSpeed(fast,fast);
    StatusLED(YELLOW);
    
    while(1){
		
		
		LineData(data);
		
		if(data[LEFT] > data[RIGHT]){
			MotorDir(FWD,FREE);
			BackLED(ON,OFF);
			
		}else if(data[RIGHT] > data[LEFT]){
			MotorDir(FREE,FWD);
			BackLED(OFF,ON); ;
		}
		
		if(data[LEFT]+data[RIGHT]>stData){
			StatusLED(RED);
			i++;
		}else{
			i=0;
			StatusLED(YELLOW);
		}
		
		if(i>100){
			linienEnde = 1;
		}
		
		while(linienEnde){
			MotorDir(FWD,RWD);
			LineData(data);
			
			if(data[LEFT]+data[RIGHT] < schwarz+100){
				MotorDir(BREAK,BREAK);
				msleep(50);
				
				while(linienEnde){
					MotorSpeed(80,80);
					MotorDir(RWD,FWD);
					LineData(data);
					
					if(data[LEFT] + data[RIGHT] < schwarz+100){
							linienEnde = 0;
					}
				}
				MotorSpeed(fast,fast);
			}
		}
		
		Kollision();
	}
}
Example #9
0
/**
	@brief Performs post-filtering, by setting comment blocks to trivial
	@param [in]  StartPos			- First line number to read
	@param [in]  EndPos				- The line number PASS the last line number to read
	@param [in]  QtyLinesInBlock		- Number of lines in diff block.  Not needed in backward direction.
	@param [in]  Direction			- This should be 1 or -1, to indicate which direction to read (backward or forward)
	@param [in,out]  Op				- This variable is set to trivial if block should be ignored.
	@param [in]  FileNo				- Should be 0 or 1, to indicate left or right file.
	@param [in]  filtercommentsset	- Comment marker set used to indicate comment blocks.
	@return		Always returns true in reverse direction.
				In forward direction, returns false if none trivial data is found within QtyLinesInBlock
*/
static bool PostFilter(int StartPos, int EndPos, int Direction,
	int QtyLinesInBlock, OP_TYPE &Op, int FileNo,
	const FilterCommentsSet& filtercommentsset)
{
	const char* EolIndicators = "\r\n"; //List of characters used as EOL
	if (Op == OP_TRIVIAL) //If already set to trivial, then exit.
		return true;
	bool OpShouldBeTrivial = false;
	int QtyTrivialLines = 0;
	for(int i = StartPos + ((Direction == -1)?-1:0); i != EndPos;i += Direction)
	{
		if ((i - StartPos) == QtyLinesInBlock && 
			QtyLinesInBlock == QtyTrivialLines)
		{
			OpShouldBeTrivial = true;
			break;
		}

		const char *LineStr = files[FileNo].linbuf[i];
		std::string LineData(LineStr, linelen(LineStr));

		const char * StartOfComment		= FindCommentMarker(LineData.c_str(), filtercommentsset.StartMarker.c_str());
		const char * EndOfComment		= FindCommentMarker(LineData.c_str(), filtercommentsset.EndMarker.c_str());
		const char * InLineComment		= FindCommentMarker(LineData.c_str(), filtercommentsset.InlineMarker.c_str());
		//The following logic determines if the entire block is a comment block, and only marks it as trivial
		//if all the changes are within a comment block.
		if (Direction == -1)
		{
			if (!StartOfComment && EndOfComment)
				break;
			
			if (StartOfComment && (!EndOfComment || EndOfComment < StartOfComment) && (!InLineComment || InLineComment > StartOfComment))
			{
				OpShouldBeTrivial = true;
				break;
			}
		}
		else if (Direction == 1)
		{
			if (IsTrivialBytes(LineData.c_str(), LineData.c_str()+LineData.size(), filtercommentsset) || 
				IsTrivialLine(LineData, StartOfComment,	EndOfComment, InLineComment, filtercommentsset))
			{
				++QtyTrivialLines;
			}

			if (!EndOfComment && StartOfComment)
			{
				if (i == (StartPos + QtyTrivialLines) )
				{
					if (StartOfComment == LineData.c_str())
					{//If this is at the beginning of the first line, then lets continue
						continue;
					}
					if (IsTrivialBytes(LineData.c_str(), StartOfComment, filtercommentsset))
					{//If only trivial bytes before comment marker, then continue
						continue;
					}
					break;
				}
				//If this is not the first line, then assume
				//previous lines are non-trivial, and return true.
				return false;
			}

			if (EndOfComment && 
				(!StartOfComment || StartOfComment > EndOfComment) && 
				(!InLineComment || InLineComment > EndOfComment) )
			{
				if (!IsTrivialBytes(EndOfComment+filtercommentsset.EndMarker.size(), LineData.c_str()+LineData.size(), filtercommentsset))
				{
					return false;
				}

				if ((i - StartPos) >=  (QtyLinesInBlock-1))
				{
					OpShouldBeTrivial = true;
					break;
				}

				//Lets check if the remaining lines only contain trivial data
				bool AllRemainingLinesContainTrivialData = true;
				int TrivLinePos = i+1;
				for(; TrivLinePos != (StartPos + QtyLinesInBlock);++TrivLinePos)
				{
					std::string LineDataTrvCk(files[FileNo].linbuf[TrivLinePos]);
					size_t EolPos = LineDataTrvCk.find_first_of(EolIndicators);
					if (EolPos != std::string::npos)
					{
						LineDataTrvCk.erase(EolPos);
					}
					if (LineDataTrvCk.size() &&
						!IsTrivialBytes(LineDataTrvCk.c_str(), LineDataTrvCk.c_str() + LineDataTrvCk.size(), filtercommentsset))
					{
						AllRemainingLinesContainTrivialData = false;
						break;
					}
				}
				if (AllRemainingLinesContainTrivialData)
				{
					OpShouldBeTrivial = true;
					break;
				}
				if (TrivLinePos != (StartPos + QtyLinesInBlock) )
				{
					return PostFilter(TrivLinePos, EndPos, Direction, QtyLinesInBlock - (TrivLinePos - StartPos), Op, FileNo, filtercommentsset);
				}
			}
		}
	}
	if (OpShouldBeTrivial)
	{
		Op = OP_TRIVIAL;
	}
	return true;
}
Example #10
0
int count_bar() {
	static unsigned int data[2];
	LineData(data);
	return next_brightness((data[0] + data[1]) / 2);
}
Example #11
0
void TextScrollModel::appendMenuText( const ZString &label, const ZString &message )
{
  d->data.push_back( LineData(message, label) );
}
Example #12
0
void TextScrollModel::appendPrettyText( const ZString &message )
{
  d->data.push_back( LineData(message, true) );
}