Exemplo n.º 1
0
//------------------------------------------------------------------------------
// initNetwork() -- Initialize the multicast network
//------------------------------------------------------------------------------
bool NetIO::initNetwork()
{
    // ---
    // Create the federate unique ambassador
    // ---
    fedAmb = createFederateAmbassador();
    bool ok = (fedAmb != 0);

    // ---
    // join the federation
    // ---
    if (ok) {
        ok = createAndJoinFederation();
        doTick();
    }

    // initialize time constraints, etc.
    //if (getRegulating() || getConstrained())
    //{
    //    setLookAhead(deltaTime);
    //    setTimeIncrement(deltaTime);
    //    setFederationTime(0.0);
    //    initializeTimeManagement();
    //    doTick();
    //}

    if (ok) {
        ok = publishAndSubscribe();
        doTick();
    }

    return true;
}
Exemplo n.º 2
0
void loop() {
  unsigned char ticks_needed = TICKS_TO_GATHER;
  while(1){
    doTick(); // 1
    doSleep(); // 2
    if (q_random() % 4) {
      // Be normal. A "second" is 10 ticks long.
      for(unsigned char i = 0; i < IRQS_PER_SECOND - 2; i++)
        doSleep();
    } else {
      // This is a special "second" - it's *11* ticks long.
      // Every tenth one, we're goging to insert a "stutter tick"
      if (--ticks_needed == 0) {
        doTick();
        for(unsigned char i = 0; i < PAUSE_TICKS; i++)
          doSleep();
        ticks_needed = TICKS_TO_GATHER;
      } else {
        doSleep();
      }
      for (unsigned char i = 0; i < IRQS_PER_SECOND - 2; i++) // yes, -2, not -3.
        doSleep();
    }
  }
}
Exemplo n.º 3
0
void AccelerationState::tick()
{
    
    doTick(input->forward(), cForward, vPropForwardVel, 2, 0.97, Const::TICKSFORWARD);

    doTick(input->side(), cSide, vPropSideVel, 4, 0.93, Const::TICKSSIDE);
    
    doTick(input->up(), cUp, vPropUpVel, 4, 0.95, Const::TICKSUP);
    
    doTick(input->yaw(), cYaw, vPropYawVel, 2, 0.9, Const::TICKSYAW);
    
    doTick(input->pitch(), cPitch, vPropPitchVel, 2, 0.95, Const::TICKSPITCH);
    
    /*
    doTick(input->forward(), cForward, vPropForwardVel, 0.97, Const::TICKSFORWARD);

    doTick(input->side(), cSide, vPropSideVel, 0.9, Const::TICKSSIDE);
    
    doTick(input->up(), cUp, vPropUpVel, 0.95, Const::TICKSUP);
    
    doTick(input->yaw(), cYaw, vPropYawVel, 0.9, Const::TICKSYAW);
    
    doTick(input->pitch(), cPitch, vPropPitchVel, 0.95, Const::TICKSPITCH);
    
    
    double tmp = input->forward();
    if( tmp == 0 ) cForward = 0.9 * cForward;
    cForward += tmp;
    vPropForwardVel = calc( cForward, Const::TICKSFORWARD );
    
    tmp = input->side();
    if( tmp == 0 ) cSide = 0.9 * cSide;
    cSide += tmp;
    vPropSideVel = calc( cSide, Const::TICKSSIDE );
    
    tmp = input->up();
    if( tmp == 0 ) cUp = 0.9 * cUp;
    cUp += tmp;
    vPropUpVel = calc( cUp, Const::TICKSUP );
    
    tmp = input->yaw();
    if( tmp == 0 ) cYaw = 0.6 * cYaw;
    cYaw += tmp;
    vPropYawVel = calc( cYaw, Const::TICKSYAW );
    
    tmp = input->pitch();
    if( tmp == 0 ) cPitch = 0.6 * cPitch;
    cPitch += tmp;
    vPropPitchVel = calc( cPitch, Const::TICKSYAW );
    */
}
Exemplo n.º 4
0
MetronomeWindow::MetronomeWindow(MetronomeConf* conf)
{
	setupUi(this);

	this->statusBar()->showMessage("Stopped");

	timer = new QTimer(this);
	this->setTimerInterval();

	this->conf = conf;
	ticker = new Ticker( this->conf );

	this->tickIndex = 0;
	this->setAccents( this->accentsBox->value() );

	connect( this->timer, SIGNAL(timeout()), this, SLOT(doTick()) );
	connect( this->startStopTickingButton, SIGNAL(clicked()), this, SLOT(startStopTicking()) );
	connect( this->setBpmButton, SIGNAL(clicked()), this, SLOT(setBPM()) );
	connect( this->accentsBox, SIGNAL(valueChanged(int)), this, SLOT(setAccents(int)) );
	connect( this->quitAction, SIGNAL(triggered()), qApp, SLOT(quit()) );
	connect( this->aboutAction, SIGNAL(triggered()), this, SLOT(showAboutBox()) );

	connect( this->bpm60, SIGNAL(clicked()), this, SLOT(bpmPreset60()) );
	connect( this->bpm70, SIGNAL(clicked()), this, SLOT(bpmPreset70()) );
	connect( this->bpm80, SIGNAL(clicked()), this, SLOT(bpmPreset80()) );
	connect( this->bpm90, SIGNAL(clicked()), this, SLOT(bpmPreset90()) );
	connect( this->bpm100, SIGNAL(clicked()), this, SLOT(bpmPreset100()) );
	connect( this->bpm110, SIGNAL(clicked()), this, SLOT(bpmPreset110()) );
	connect( this->bpm120, SIGNAL(clicked()), this, SLOT(bpmPreset120()) );
}
Exemplo n.º 5
0
void Apple::tick(Game & game)
{
  const Vector snakePos = game.getWorld().getSnake().getHeadPos();
  // We've been eaten by the snake
  if(snakePos == myPos)
    eaten(game);
  else
    doTick(game);
}
Exemplo n.º 6
0
void loop() {
  while(1) {
    // Do this about once a minute-ish.
    if (q_random() % 30 != 0) {
      // a normal second.
      doTick();
      for(int i = 0; i < IRQS_PER_SECOND - 1; i++)
        doSleep();
      continue;
    }

    // Time to play a song!
    unsigned int song = q_random() % SONG_COUNT;
    unsigned char *current_song = (unsigned char*)pgm_read_ptr(song_table + song);
    while(1) {
      unsigned char song_data = pgm_read_byte(current_song++);
      if (song_data == 0) break; // song over
      doTick();
      for(int i = 0; i < song_data; i++)
        doSleep();
    }
  }
}
Exemplo n.º 7
0
void loop() {
  static unsigned int fractional_position = 0;
  static unsigned int tick_counter = 0;

  unsigned int limit = WHOLE;
  if (fractional_position < NUMERATOR) limit++;
  if (tick_counter++ >= limit) {
    tick_counter = 0;
    fractional_position++;
    if (fractional_position >= DENOMINATOR) fractional_position = 0;
    doTick();
  } else {
    doSleep();
  }
}
Exemplo n.º 8
0
void IsoView::draw(AGPainter &p)//const AGRect &r)
{
  if(!inited)
    {
      init();
      inited=true;
      shallUpdate=false;
    }
  if(shallUpdate)
    {
      update();
      shallUpdate=false;
    }

  updatePositions();

  doTick();
  mTime+=getTimeDiff();

  AntargisView::draw(p);

  // overlay selection-rectangle and energy

  std::set
    <AVItem*>::iterator i=mSelected.begin();
  for(;i!=mSelected.end() ;i++)
    {
      AGRect ar=getRect(*i);
      //      ar=r.project(ar);
      p.drawRect(ar,getSelectColor());
    }

  std::map<AVItem*,AntEntity*>::iterator k=mEntities.end();// FIXME: don't draw anything ATM begin();
  for(;k!=mEntities.end();k++)
    {
      AGRect ar=getRect(k->first);
      //      ar=r.project(ar);
      // draw energy
      ar.y-=10;
      ar.h=6;
      p.drawRect(ar,AGColor(0xFF,0,0)); // first red
      ar.w=(short)(ar.w*k->second->getEnergy());
      p.drawRect(ar,AGColor(0,0xFF,0)); // overpaint with green
    }

  // overlay rain
  mRain.draw(p);
}
Exemplo n.º 9
0
void loop() {
  unsigned char cycle_direction = 0; // fast
  unsigned long cycle_position = 0;
  while(1) {
    for(unsigned char i = 0; i < IRQS_PER_SECOND + (CYCLE_MAGNITUDE * (cycle_direction?-1:1)); i++) {
      if (i == 0)
        doTick();
      else
        doSleep();
    }
    if (cycle_position++ >= CYCLE_LENGTH) {
      cycle_position = 0;
      cycle_direction = !cycle_direction;
    }
  }
} 
Exemplo n.º 10
0
	void ServerHost::run( int port )
	{
		RakNet::SocketDescriptor socketDescriptors;
		socketDescriptors.port=port;
		socketDescriptors.socketFamily=AF_INET; // Test out IPV4
		m_server->SetMaximumIncomingConnections(400);
		// Try again, but leave out IPV6
		bool b = m_server->Startup(400, &socketDescriptors, 1 )==RakNet::RAKNET_STARTED;
		if (!b)
		{
			puts("Server failed to start.  Terminating.");
			exit(1);
		}

		m_server->SetTimeoutTime(10000,RakNet::UNASSIGNED_SYSTEM_ADDRESS);
		m_server->SetOccasionalPing(true);
		//m_server->SetUnreliableTimeout(1000);

		prerun(port);
		RakNet::TimeMS time0 = RakNet::GetTimeMS();
		while(true)
		{
			    doTick();
				runtick();
				RakSleep(30);

				RakNet::TimeMS time1 = RakNet::GetTimeMS();
				RakNet::TimeMS difference = time1 - time0;
				if(difference >= 1000)
				{
					time0 = RakNet::GetTimeMS();
					tick();
				}
		}
		postrun();
	}
Exemplo n.º 11
0
void loop() {
  if (safeMode) { // safeMode engaged, enter blocking loop wait for an OTA update
    int safeDelay=30000; // five minutes in 100ms counts
    while (safeDelay--) {
      ArduinoOTA.handle();
      delay(100);
    }
    ESP.reset(); // restart, try again
    delay(5000); // give esp time to reboot
  }

  if(wifiMulti.run() != WL_CONNECTED) { // reboot if wifi connection drops
      ESP.reset();
      delay(5000);
  }

  if (!mqtt.connected()) {
    mqttreconnect(); // check mqqt status
  }

  doTick();

  if (hasRSSI) doRSSI();
  if (hasTout) doTout();
  if (hasVout) doVout();
  if (hasIout) doIout();
  if (getRGB) doRGBout();
  if (hasSpeed) doSpeed();

  if ( (doUpdate) || (updateCnt>= 60 / ((updateRate * 20) / 1000) ) ) runUpdate(); // check for config update as requested or every 60 loops

  if (wsConcount>0) wsData();
  if (useMQTT) mqttData(); // regular update for non RGB controllers
  if (prtConfig) printConfig(); // config print was requested

  sprintf(str,"Sleeping in %u seconds.", (updateRate*20/1000));
  if ((!skipSleep) && (sleepEn)) {
    if (useMQTT) mqtt.publish(mqttpub, str);
  }

  int cnt = 30;
  if (updateRate>30) cnt=updateRate;
  while(cnt--) {
    ArduinoOTA.handle();
    if (useMQTT) mqtt.loop();

#ifndef _MINI
    httpd.handleClient();
#endif
    webSocket.loop();

    if (getTime) updateNTP(); // update time if requested by command
    if (scanI2C) i2c_scan();

    if (hasRGB) doRGB(); // rgb updates as fast as possible
    if (rgbTest) testRGB();

#ifndef _MINI

    if (doUpload) { // upload file to spiffs by command
      doUpload = false; fileSet = false;
      int stat = uploadFile(fileName, fileURL);
      sprintf(str, "Upload complete: %s %d bytes.",fileName,stat);
      if (useMQTT) mqtt.publish(mqttpub, str);
    }
#endif

    if (setPolo) {
      setPolo = false; // respond to an mqtt 'ping' of sorts
      if (useMQTT) mqtt.publish(mqttpub, "Polo");
    }

    if (doReset) { // reboot on command
      if (useMQTT) {
        mqtt.publish(mqttpub, "Rebooting!");
        mqtt.loop();
      }
      delay(50);
      ESP.reset();
      delay(5000); // allow time for reboot
    }

    if (!hasRGB) delay(20); // don't delay for rgb controller
  }

  if ((!skipSleep) && (sleepEn)) {
    if ((sleepPeriod<60) || (sleepPeriod>43200)) sleepPeriod=900; // prevent sleeping for less than 1 minute or more than 12 hours
    sprintf(myChr,"Back in %d minutes", sleepPeriod/60);
    if (useMQTT) {
      mqtt.publish(mqttpub, myChr);
      mqtt.loop();
    }

    ESP.deepSleep(1000000 * sleepPeriod, WAKE_RF_DEFAULT); // sleep for 15 min
    delay(5000); // give esp time to fall asleep

  }
  skipSleep = false;
  updateCnt++;
}
Exemplo n.º 12
0
//------------------------------------------------------------------------------
// netInputHander() -- Network input handler
//------------------------------------------------------------------------------
void NetIO::netInputHander()
{
    doTick();
}