
//this
#include "SerLED.H"

//c- c++
#include "iostream"

using namespace std;

//////////////////////////////////
// Activate(unsigned int nr)	//
//////////////////////////////////

void SerLED :: Activate(unsigned int nr)
	{
	cerr<<"Activate called for state "<<nr<<endl;
	cerr<<"_states.size()="<<_states.size()<<endl;
	_active[nr]=true;
//check for active states with higher priority
	if(nr>0)
		{
		cerr<<"CCC"<<endl;
		for(unsigned int i=0; i<nr; i++)
			{
			cerr<<"Checking for higher priority "<<i<<endl;
			if(_states[i]->IsActive()) return;
			}
		}
//check for active states with lower priority
	for(unsigned int i=nr+1; i<_states.size(); i++)
		{
		cerr<<"Checking for lower priority "<<i<<endl;
		if(_states[i]->IsActive()) 
			{
			_states[i]->DeActivate();
			break;
			}
		}
//activate state
	cerr<<"activate"<<endl;
	_states[nr]->Activate();
	}


void SerLED :: DeActivate(unsigned int nr)
	{
	_active[nr]=false;
//if state nr is active deactivate and check for states with lower priority
	if(_states[nr]->IsActive())
		{
		_states[nr]->DeActivate();
		if(nr+1<_states.size())
			for(unsigned int i=nr+1; i<_states.size(); i++)
				{
				if(_active[i]) _states[i]->Activate();
				return;
				}
		}
	}
