Exemple #1
0
void Radar::run()
{
    frontDistance = middleSonar.ping() / US_ROUNDTRIP_CM; 
    leftDistance = leftSonar.ping() / US_ROUNDTRIP_CM; 
    rightDistance = rightSonar.ping() / US_ROUNDTRIP_CM; 
    runned();
}
void TempController::run()
{
    float tempHigh, tempLow;
    tempHigh = pTempSensorHigh->getTemp();
    tempLow = pTempSensorLow->getTemp();

    if (tempHigh >= tempParameters.maxUpperTemp)
    {
        if (pFans->getIsExtracting() == false)
        {
            pFans->extractForSeconds(60);
        }
    }

    /* If it's night time */
    if (pLightController->getIsLightOn() == false)
    {
        if (tempHigh < tempParameters.minNightUpperTemp)
        {
            if (pHeaterRelayCommand->getRelayStatus() == false)
            {
                pHeaterRelayCommand->on();    
            }    
        }
        else 
        {
            if (pHeaterRelayCommand->getRelayStatus() == true)
            {
                pHeaterRelayCommand->off();
            }
        }
        if (tempLow < tempParameters.minNightLowerTemp)
        {
            if (pFans->getIsAiring() == false)
            {
                pFans->airInForSeconds(300, 255);
            }
        }
    }
    /* Day time */
    else
    {
        if (pHeaterRelayCommand->getRelayStatus() == true)
        {
            pHeaterRelayCommand->off();    
        }
        if (tempLow < tempParameters.minDayLowerTemp)
        {
            if (pFans->getIsAiring() == false)
            {
                pFans->airInForSeconds(60, 255);
            }
        }
    }

    runned();
}
/*
	ThreadController run() (cool stuf)
*/
void ThreadController::run(){
	// Run this thread before
	if(_onRun != NULL)
		_onRun();

	long time = millis();
	int checks = 0;
	for(int i = 0; i < MAX_THREADS && checks <= cached_size; i++){
		// Object exists? Is enabled? Timeout exceeded?
		if(thread[i]){
			checks++;
			if(thread[i]->shouldRun(time)){
				thread[i]->run();
			}
		}
	}
	// ThreadController extends Thread, so we should flag as runned thread
	runned();
}
void DS18B20TempSensorThread::run()
{
    uint8_t data[9];

    ds->reset();             // On reset le bus 1-Wire
    ds->select(addr);        // On sélectionne le DS18B20

    ds->write(0x44, 1);      // On lance une prise de mesure de température
    delay(800);             // Et on attend la fin de la mesure

    ds->reset();             // On reset le bus 1-Wire
    ds->select(addr);        // On sélectionne le DS18B20
    ds->write(0xBE);         // On envoie une demande de lecture du scratchpad

    for (byte i = 0; i < 9; i++) // On lit le scratchpad
    data[i] = ds->read();       // Et on stock les octets reçus

    // Calcul de la température en degré Celsius
    temp = ((data[1] << 8) | data[0]) * 0.0625; 

    computeMinMax();
    runned();
}
Exemple #5
0
// static VCS sslAccept; // gilgil temp 2014.03.24
void VSslServer::myRun(VTcpSession* tcpSession)
{
  tag = 3000; // gilgil temp 2014.04.04
  VSslServerSession *sslSession = new VSslServerSession;
  {
    //VLock lock(sslAccept); // gilgil temp 2014.03.24
    sslSession->owner       = this;
    sslSession->tcpSession  = tcpSession;
    // sslSession->handle      = tcpSession->handle; // gilgil temp 2014.04.03
    sslSession->ctx         = m_ctx;
    if (!sslSession->open()) goto _end;
    // LOG_DEBUG("beg sslSession=%p con=%p", sslSession, sslSession->con); // gilgil temp 2014.03.07

    if (processConnectMessage)
    {
      QByteArray ba;
      int readLen = tcpSession->read(ba);
      if (readLen == VError::FAIL) goto _end;
      tcpSession->write("HTTP/1.0 200 Connection established\r\n\r\n");
    }

    SSL_set_accept_state(sslSession->con);
    while (true)
    {
      if (SSL_is_init_finished(sslSession->con)) break;
      int res = 0;
      {
        //VLock lock(sslAccept); // gilgil temp 2014.03.24
        res = SSL_accept(sslSession->con);
      }
      if (res < 0)
      {
        LOG_DEBUG("SSL_accept return %d error=%d", res, SSL_get_error(sslSession->con, res));
        goto _end;
      }
      else if (res == 0) // may be the TLS/SSL handshake was not successful
      {
        LOG_DEBUG("SSL_accept return zero");
        goto _end;
      } else // res > 0
      {
        break;
      }
    }
  }

  sslSessionList.lock();
  sslSessionList.push_back(sslSession);
  sslSessionList.unlock();

  emit runned(sslSession);

  sslSessionList.lock();
  sslSessionList.removeOne(sslSession);
  sslSessionList.unlock();

_end:
  // LOG_DEBUG("end sslSession=%p con=%p", sslSession, sslSession->con);  // gilgil temp 2014.03.14
  delete sslSession;
  tag = 4000; // gilgil temp 2014.04.04
}
	void LinearActuatorNoPot::run() {
		runned();

		if (_state == ActuatorState_Initializing)
		{
			_runTime = millis() - _lastTime;
			if (Travel() > _actuatorLength)
			{
				enabled = false;
				_currentPosition = 0;
				Stop();
				Serial.println(_name + F(" actuator retracted and initialized"));
			}
		}
		else
		{
			float currentAngle = CurrentAngleFlipped();
			float delta = abs(currentAngle - _requestedAngle);
			Serial.print(_name + F(" tracking currentAngle: "));
			Serial.print(currentAngle);
			Serial.print(F(" _requestedAngle: "));
			Serial.print(_requestedAngle);
			Serial.print(F(" delta: "));
			Serial.print(delta);
			Serial.print(F(" _currentPosition: "));
			Serial.println(_currentPosition);
			if (delta <= histeresis)
			{
				Stop();
				Serial.println(_name + F(" actuator tracking complete "));
			}
			else if (currentAngle < _requestedAngle)
			{
				if (_state != ActuatorState_MovingOut)
				{
					MoveOut();
					_lastTime = millis();
					Serial.println(_name + F(" actuator MoveOut "));
				}
			}
			else if (currentAngle > _requestedAngle)
			{
				if (_state != ActuatorState_MovingIn)
				{
					MoveIn();
					_lastTime = millis();
					Serial.println(_name + F(" actuator MoveIn "));
				}
			}
			long now = millis();
			_runTime = now - _lastTime;
			_lastTime = now;
			if (_state == ActuatorState_MovingOut)
			{
				_currentPosition += Travel(); // inch step ((time in millis * 1000)  * speed
			}
			else if (_state == ActuatorState_MovingIn)
			{
				_currentPosition -= Travel(); // inch step ((time in millis * 1000)  * speed
			}
		}
	}