Beispiel #1
0
void HidnSeek::checkBattery() {
    if (millis() - _lastCheck > 2000UL) {
        _lastCheck = millis();
        boolean _grst = PORTB & (1<<2);
        PORTB |= (1 << 2);
        if (!_grst) delay(50);
        unsigned int value = analogRead(A1);
        if (value < 900) setSupply(false);   // Below 3,7V shutdown the supply
        if (!_grst) PORTB &= ~(1<<2);
    }
}
Beispiel #2
0
void UIShipData::update(HumanGameView* hgv)
{
  // Adjust for prettiness
  setCharacterSize(static_cast<double>(hgv->getMapTileSize()) * 0.75);

  // Grab convenience pointer to ship
  const Ship* ship = hgv->getGameLogic()->getShip();

  setRum(ship->getRum());
  setGold(ship->getGold());
  setSupply(ship->getMaxRum());

  updateText();
}
//get the total number of the combinations between supply and demand
int ProfileMatchView::getSDCombinations(int i, int count, int combinations)
{
	int combinations_check = count;
	int inc_index = combinations-1;
	int start;

	QVector<int> demand_index_count;
	QVector<int> index_count;
	demand_index_count.clear();
	demand_index_count.push_back(i);

	//set up the counting index vector
	for (int j=0; j<combinations; ++j)
	{
		index_count.push_back(j);
	}

//nRE - represents the number of supply profiles
	int nSupplys = (int)sPButtonList.count();

	for (int a=0; a<nSupplys; ++a)
	{
		if (index_count[combinations-1]<nSupplys)
		{
			do{
				m_CurrentDemand=i;
				setDemand(i,true); //this is the function to paint the demand button
				selectedDemandIndexVector.push_back(demand_index_count);

				//set the relevant supply checked...
				for (int k=0; k<combinations; ++k)
				{
					setSupply(index_count[k],true); //this is the function to paint the supply button							
				}
		    //make pair the supply and demand combinations and save to a defined vector
				selectedSupplyIndexVector.push_back(index_count);
////////////////////////////////////////////////////////////////////////////
//set up match vector for search function
				setupMatchIdVector(demand_index_count,index_count);
				setupMatchStatisticsVector(demand_index_count,index_count);
				setupMatchRateVector();
				setupMatchRankVector();


//				TRACE("\n");
/////////////////////////////////////////////////
//leave this function will implement the match function later
//				GetMatch(true);
///////////////////////////////////////////////////////////
				count++;
				++index_count[combinations-1];
			//////////////	
				int demo = index_count[combinations-1];
				///////////

				if (index_count[combinations-1]==nSupplys)
				{
					if (index_count[inc_index]!=nSupplys)
					{
						start = index_count[inc_index];
						++start;
						if (start+combinations-inc_index > nSupplys)
						{
							--inc_index;
							start = index_count[inc_index];
							++start;
							if (start+combinations-inc_index > nSupplys)
							{
								--inc_index;
								start = index_count[inc_index];
								++start;
							}
						}
						if (inc_index+combinations<=nSupplys)
						{
							for (int j=inc_index; j<inc_index+combinations; ++j)
							{
								if (j<combinations)
								{
									index_count[j]= start+j-inc_index;
								}
							}
						}
					}
					else
					{
						--inc_index;
						if (inc_index>=0 && inc_index <= combinations)
						{
							++index_count[inc_index];
							start = index_count[inc_index];
							for (int j=inc_index; j<inc_index+combinations; ++j)
							{
								if (j<combinations)
								{
									index_count[j]= start+j-inc_index;
								}
							}
						}
						else
						{
							++inc_index;
							++index_count[inc_index];
							start = index_count[inc_index];
							for (int j=inc_index; j<inc_index+combinations; ++j)
							{
								if (j<combinations)
								{
									index_count[j]= start+j-inc_index;
								}
							}
						}
					}
				}
				if (inc_index == 0)
				{
					inc_index = combinations-1;
				}
			}while(nSupplys>index_count[combinations-1]);
		}
//		m_Timer->stop(); //emit timeout signal
		
//		QTimer::singleShot(1000, this, SLOT(update()));
//		m_bPaintButton = true;
//		repaint(this->dPButtonL);
//		repaint(this->sPButtonList);
	}
	if (combinations_check == count)
	{
		count = 0;
	}
	return count;
}
////get the demand combinations with the specified single supply
int ProfileMatchView::getDSCombinations(int i, int count, int combinations)
{
	int combinations_check = count;
	int inc_index = combinations-1;
	int start;

	QVector<int> index_count;

	QVector<int> supply_index_count;
	supply_index_count.clear();
	supply_index_count.push_back(i);
	//set up the counting index vector
	for (int j=0; j<combinations; ++j)
	{
		index_count.push_back(j);
	}

	int nDemands = (int)dPButtonList.count();
	for (int a=0; a<nDemands; ++a)
	{
		if (index_count[combinations-1]<nDemands)
		{
			do{
				m_CurrentSupply=i;
				setSupply(i,true);//this is the function to paint the demand button
				selectedSupplyIndexVector.push_back(supply_index_count);

				for (int k=0; k<combinations; ++k)
				{
					setDemand(index_count[k],true);
				}
		    //make pair the supply and demand combinations and save to a defined vector
				selectedDemandIndexVector.push_back(index_count);
////////////////////////////////////////////////////////////////////////////
//set up match vector for search function
				setupMatchIdVector(index_count, supply_index_count);
				setupMatchStatisticsVector(index_count, supply_index_count);
				setupMatchRateVector();
				setupMatchRankVector();

				count++;
				++index_count[combinations-1];
				////////////////////////
				int demo = index_count[combinations-1];
				/////////////////////////////
//				LogInfo(count);

				if (index_count[combinations-1]==nDemands)
				{
					if (index_count[inc_index]!=nDemands)
					{
						start = index_count[inc_index];
						++start;
						if (start+combinations-inc_index > nDemands)
						{
							--inc_index;
							start = index_count[inc_index];
							++start;
							if (start+combinations-inc_index > nDemands)
							{
								--inc_index;
								start = index_count[inc_index];
								++start;
							}
						}
						if (inc_index+combinations<=nDemands)
						{
							for (int j=inc_index; j<inc_index+combinations; ++j)
							{
								if (j<combinations)
								{
									index_count[j]= start+j-inc_index;
								}
							}
						}
					}
					else
					{
						--inc_index;
						if (inc_index>=0 && inc_index <= combinations)
						{
							++index_count[inc_index];
							start = index_count[inc_index];
							for (int j=inc_index; j<inc_index+combinations; ++j)
							{
								if (j<combinations)
								{
									index_count[j]= start+j-inc_index;
								}
							}
						}
						else
						{
							++inc_index;
							++index_count[inc_index];
							start = index_count[inc_index];
							for (int j=inc_index; j<inc_index+combinations; ++j)
							{
								if (j<combinations)
								{
									index_count[j]= start+j-inc_index;
								}
							}
						}
					}
				}
				if (inc_index == 0)
				{
					inc_index = combinations-1;
				}
			}while(nDemands>index_count[combinations-1]);
		}
	}
	if (combinations_check == count)
	{
		count = 0;
	}
	return count;
}
int ProfileMatchView::getCombinations(int supplycombinations, QVector<int>& supply_index_count, int count, int combinations)
{
	int combinations_check = count;
	int inc_index = combinations-1;
	int start;
	QVector<int> index_count;

//set up the counting index vector
	for (int j=0; j<combinations; ++j)
	{
		index_count.push_back(j);
	}

//the total number of the available demand profiles
	int nDemands = (int)dPButtonList.count();
	for (int a=0; a<nDemands-1; a++)
	{
		if (index_count[combinations-1]<nDemands)
		{
			do{
				m_CurrentSupply=supply_index_count[0]; //index of the current supply
				for (int k=0; k<supplycombinations; ++k) //set the supplies checked for the current combination
				{
					setSupply(supply_index_count[k],true);
				}
//save the index of supply
				selectedSupplyIndexVector.push_back(supply_index_count);

				for (int k=0; k<combinations; ++k) //set the demand checked for the current demand combination
				{
					setDemand(index_count[k],true);
				}
//save the index of the demand
				selectedDemandIndexVector.push_back(index_count);
////////////////////////////////////////////////////////////////////////////
//set up match vector for search function
				setupMatchIdVector(index_count,supply_index_count);
				setupMatchStatisticsVector(index_count,supply_index_count);
				setupMatchRateVector();
				setupMatchRankVector();
///////////////////////////////////////////////////////////////////////////
////////////////////////////////
//implement this function later, when the data is available
//				GetMatch(true);
/////////////////////////////////

				count++;
				++index_count[combinations-1];

				if (index_count[combinations-1]==nDemands)
				{
					if (index_count[inc_index]!=nDemands)
					{
						start = index_count[inc_index];
						++start;
						if (start+combinations-inc_index > nDemands)
						{
							--inc_index;
							start = index_count[inc_index];
							++start;
							if (start+combinations-inc_index > nDemands)
							{
								--inc_index;
								start = index_count[inc_index];
								++start;
							}
						}
						if (inc_index+combinations<=nDemands)
						{
							for (int j=inc_index; j<inc_index+combinations; ++j)
							{
								if (j<combinations)
								{
									index_count[j]= start+j-inc_index;
								}
							}
						}
					}
					else
					{
						--inc_index;
						if (inc_index>=0 && inc_index <= combinations)
						{
							++index_count[inc_index];
							start = index_count[inc_index];
							for (int j=inc_index; j<inc_index+combinations; ++j)
							{
								if (j<combinations)
								{
									index_count[j]= start+j-inc_index;
								}
							}
						}
						else
						{
							++inc_index;
							++index_count[inc_index];
							start = index_count[inc_index];
							for (int j=inc_index; j<inc_index+combinations; ++j)
							{
								if (j<combinations)
								{
									index_count[j]= start+j-inc_index;
								}
							}
						}
					}
				}
				if (inc_index == 0)
				{
					inc_index = combinations-1;
				}
			}while(nDemands>index_count[combinations-1]);
		}
	}
	if (combinations_check == count)
	{
		count = 0;
	}
	return count;
}