/**
 * @name processAutomatic(EngineData *inp)
 * @param inp pointer to EngineData structure
 * processes the whole sequence from reading inputs to writing outputs
 */
void TruthTableEngine::processAutomatic(EngineData *inp) {
	readInputs(inp);		// read inputs
	preProcess(inp);		// pre process into testbyte
	process(inp);			// search for valid combination
	postProcess(inp);		// copy result to output array
	writeOutputs(inp);		// write digital pins based on active levels
}
Example #2
0
int main (int argc, char* argv[]){	
	
	if (argc != 3){
		printf("Incorrect arguments for comb. Please enter your circuit description file, followed by your input file.\n");
		return 0;
	}
	
	int i, j, numInput;
	block* var = malloc(26 * sizeof(block));
	block* tvar = malloc(26 * sizeof(block));
	instruct* instructions = malloc(100 * sizeof(instruct));
	
	for (i = 0; i < 26; i++)
	var[i].name = (char *) malloc (sizeof(char) * 11);
	for (i = 0; i < 26; i++)
	tvar[i].name = (char *) malloc (sizeof(char) * 11);
	for (i = 0; i < 100; i++){
		instructions[i].gate = (char *) malloc (sizeof(char) * 11);
		instructions[i].vari = malloc(100 * sizeof(char *));
		for (j = 0; j < 100; j++)
		instructions[i].vari[j] = malloc(100 * sizeof(char));
	}

	readInputs(argv[1], numInput, instructions, var, tvar);
	
	
	
	readStates(argv[2], var);

	
	
	printer(var, tvar, instructions);
	return 0;
}
Example #3
0
void MAPSPredictor::Core() 
{
	str.Clear();
	readInputs();
	framerate = (int)GetIntegerProperty("framerate");
	// We must check if we have minimun 2 frames for that we can do a prediction
	if (!ready)
	{
		if (completedL[0] && completedL[1] && completedC[0] && completedC[1])
		{
			ready = true;
		}
	}// When we have 2 frames the algorith start
	else {
		//Here we check if there are any change in the previus data if not is not necesary to recalculate.
		//If not has been predicted previusly 
		if (!predicted || updated[0] || updated[1]) {
			predecir();
		}
		// We use this function to alculate how  much time have been passed
		QueryPerformanceCounter(&EndingTime);
		ElapsedTime = (double)(EndingTime.QuadPart - StartingTime.QuadPart) * 1000 / Frecuency.QuadPart;
		if (ElapsedTime>framerate)
		{
			StartingTime = EndingTime;
			WriteOutputs();
		}
	}
	//ReportInfo(str);
}
Example #4
0
File: comp.c Project: enyone/cvavr
void main(void)
{
  initd();
       
  LED1 = 0;
  LED2 = 0;
  initIdle();
  
  initTimers();
  
  while (1)
  {
    readInputs();
    
    if(timerflag)
    {
      bcount ++;
      if(bcount >= blinkspeed)
      {
        if(blink == 0) blink = 1; else blink = 0;
        LED1 = blink;
        bcount = 0;
      }
      
      if(scount <= 1) { scount ++; LED2 = 0; }
      else LED2 = 1;
      
      sendcount ++;
      
      if(serial0_null <= 4) serial0_null ++;
      else u0 = 0;
      
      if(wakecheck > 0) wakecheck --;
      else initReset();
      
      timerflag = 0;
    }
    
    if(sendcount >= 25)
    {
      if(tied.onoff)
      {
        sendLcdChar(kmh);
        sendLcdChar(rpm);
        sendLcdChar(20);
        sendLcdChar(20);
        sendLcdChar(1);
        sendLcdChar(1);
        sendLcdChar(matka>>8);
        sendLcdChar(matka);
        sendcount = 0;
        matka = 0;
      }
    }    
  }
Example #5
0
void sense(void *args){
	rt_task_set_periodic(NULL,TM_NOW,PLCperiod);
	while(!stopped){
		/*
		 *	Read inputs status
		*/
		sensors = readInputs();
		rt_sem_v(&readDone);
		rt_task_wait_period(NULL);
	}
}
Example #6
0
/*
 * Main program
 */
void main() 
{
	unsigned long i=0, j=0, k=0;
	unsigned char pwmpos=0, pwmled=0;
	on_init();
	timer1_init();
	firstInit();
	programInit();
	
	while(1)
	{
		if (!wait)
		{
			for(pwmled=0; pwmled<23; pwmled++)
			{
				setLEDDiscrete(pwmled, PWM[pwmled] > pwmpos);
			}
			pwmpos++;
			if (pwmpos >= PWM_LENGTH) pwmpos = 0;
			
			if (k>20) {
				for(pwmled=0; pwmled<23; pwmled++)
				{
					if (framebuffer[pwmled] < PWM[pwmled]) PWM[pwmled]--;
					if (framebuffer[pwmled] > PWM[pwmled]) PWM[pwmled]++;
				}
				k=0;
			}
			
			if (i > (100*delay))
			{
				programRun();
				i=0;
			}
		}
		
		if (j>10)  {
			readInputs();
			j=0;
		}
		
		i++;
		j++;
		k++;
	}
}
Example #7
0
void CGeneratorInput::readInputFile(const std::string& fileName, CPinPass::States& states)
{
	TiXmlDocument document;

	if(!base::loadXml(fileName, document))
	{
		base::lerr<<"Can't open input XML file \""<<fileName<<"\".";
		return;
	}

	TiXmlElement* root = document.FirstChildElement("EffectGeneratorParameters");

	if(!root)
	{
		base::lerr<<"Can't find root element in input XML file \""<<fileName<<"\".";
		return;
	}

	TiXmlElement* elem = root->FirstChildElement();

	while(elem != NULL)
	{
		std::string name = elem->Value();

		if(name == "constants")
			readConstants(elem);
		else
		if(name == "includes")
			readIncludes(elem);
		else
		if(name == "states")
			readStates(elem, states);
		else
		if(name == "pins")
			readPins(elem, states);
		else
		if(name == "inputs")
			readInputs(elem, states);
		else
			base::lwrn<<"Found element \""<<name<<"\" while parsing input file \""<<
						fileName<<"\". Nothing know about this type. Skipping...";

		elem = elem->NextSiblingElement();
	}
}
Example #8
0
void main(void) 
{
    // initialise the RTC communication line
    I2C_Init() ;
    // initialise the LCD display
    LCDInit(LS_NONE);
    // initialise the actual RTC
    DS1307_Init() ;

    //clear the display
    LCDClear();
    
    // read back our running time
    DS1307_readRam(&runningMinutes,0,2) ;
    DS1307_readRam(&runningHours,2,2) ;
    
    LCDWriteString("Starting counter");
    LCDGotoXY(0,1) ;
    LCDWriteString("at ");
    LCDWriteInt(runningHours,1);
    LCDWriteString(":");
    LCDWriteInt(runningMinutes,1);
    __delay_ms(750) ;
    __delay_ms(750) ;
    __delay_ms(750) ;
    __delay_ms(750) ;

    // compensate for our handling on the first run of the readClock routine
    runningMinutes-- ;

    LCDClear();
    // infinite loop, read the clock, display on the LCD, check for the button, and if needed, process the menus
   while(1)
  {       
      readClock();
      
      showClock() ;           
      
      readInputs() ;
      
      if (bButton)
        doMenu();
      else if (state & 0x30)
      {
          // rotate the encoder to select a menu function, well, that was the aim, but encoder reading
          // seems a tad slow or inaccurate.
          //
          // there is a timeout if the button isn't pressed after selecting the menu option
          
          if (state & DIR_CW)
          {
              menuFunction++ ;
              if (menuFunction == MENU_LAST)
                  menuFunction = MENU_NONE ;
          }
          else if (state & DIR_CCW)
          {
              menuFunction-- ;
              if (menuFunction < MENU_NONE)
                  menuFunction = MENU_LAST-1 ;
          }
          
          if (menuFunction != MENU_NONE)
          {
              next_menu_clear = minute * 60 + seconds + 20 ;
              LCDGotoXY(9,0);
              if (menuFunction == MENU_TIME)
                LCDWriteString("Time ?");
              if (menuFunction == MENU_DATE)
                LCDWriteString("Date ?");
          }
          else
              clearPrompt();
      }
      else if (next_menu_clear && ((minute * 60 + seconds) > next_menu_clear))
      {
          clearPrompt();
      }
  }
}
Example #9
0
void doMenu()
{   
    while(bButton)
        readInputs();
    
    // set the new time
    if (menuFunction == MENU_NONE | menuFunction == MENU_TIME)
    {
        int h,m,s ;
        
        h = hour ;
        m = minute ;
        s = seconds ;
        
        LCDClear();
        LCDWriteString(setText);
        LCDWriteString("Hours");
        
        LCDGotoXY(0,1) ;
        showTime();

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                hour++;
                if (hour > 23)
                    hour = 0 ;
            }
            else if (state & DIR_CCW)
            {
                hour--;
                if (hour < 0)
                    hour = 0 ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showTime();
            }
        }
        
        while(bButton)
            readInputs();
    
        LCDGotoXY(0,0) ;
        LCDWriteString(setText);
        LCDWriteString("Minutes");

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                minute++;
                if (minute > 59)
                    minute = 0 ;
            }
            else if (state & DIR_CCW)
            {
                minute--;
                if (minute < 0)
                    minute = 0 ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showTime();
            }
        }
        
        while(bButton)
            readInputs();

        LCDGotoXY(0,0) ;
        LCDWriteString(setText);
        LCDWriteString("Seconds");

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                seconds++;
                if (seconds > 59)
                    seconds = 0 ;
            }
            else if (state & DIR_CCW)
            {
                seconds--;
                if (seconds < 0)
                    seconds = 0 ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showTime();
            }
        }
        
        // save changes
        if (h != hour || m != minute || s != seconds)
        { // we only update the RTC if changes have been made
            h = ((hour / 10) << 4) + hour % 10 ;
            m = ((minute / 10) << 4) + minute % 10 ;
            s = ((seconds / 10) << 4) + seconds % 10 ;

            DS1307_SetTime(h,m,s) ;
            
            runningMinute = minute ;
        }
        
        while(bButton)
            readInputs();
    }
    
    // set the new date
    if (menuFunction == MENU_NONE | menuFunction == MENU_DATE)
    {
        int n,d,m,y ;
        
        n = day ;
        d = date ;
        m = month ;
        y = year ;
        
        LCDClear();
        LCDWriteString(setText);
        LCDWriteString("Year");
        
        LCDGotoXY(0,1) ;
        showDate();

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                year++;
                if (year > 99)
                    year = 0 ;
            }
            else if (state & DIR_CCW)
            {
                year--;
                if (year < 0)
                    date = 99 ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showDate();
            }
        }
        
        while(bButton)
            readInputs();
    
        LCDGotoXY(0,0) ;
        LCDWriteString(setText);
        LCDWriteString("Month");

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                month++;
                if (month > 12)
                    month = 1 ;
            }
            else if (state & DIR_CCW)
            {
                month--;
                if (!month)
                    month = 12 ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showDate();
            }
        }
        
        while(bButton)
            readInputs();

        LCDGotoXY(0,0) ;
        LCDWriteString(setText);
        LCDWriteString("Date ");

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                date++;
                if (date > monthDays[month-1])
                    date = 1 ;
            }
            else if (state & DIR_CCW)
            {
                date--;
                if (date < 0)
                    date = monthDays[month-1] ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showDate();
            }
        }
        
        while(bButton)
            readInputs();

        LCDGotoXY(0,0) ;
        LCDWriteString(setText);
        LCDWriteString("Day  ");

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                day++;
                if (day > 7)
                    day = 1 ;
            }
            else if (state & DIR_CCW)
            {
                day--;
                if (day < 0)
                    day = 7 ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showDate();
            }
        }

        if (n != day || d != date || m != month || y != year)
        { // again, we only update the RTC if changes have been made
            n = ((day / 10) << 4) + day % 10 ;
            d = ((date / 10) << 4) + date % 10 ;
            m = ((month / 10) << 4) + month % 10 ;
            y = ((year / 10) << 4) + year % 10 ;

            DS1307_SetDate(n,d,m,y) ;
        }

        
        while(bButton)
            readInputs();
    }
}
Example #10
0
// ##################################################################
// begin main program
// ##################################################################
int main(int argc, char **argv)
{
   int i,ierr,nproc,myid;

   // start MPI communication
   ierr = MPI_Init(&argc,&argv);
   ierr = MPI_Comm_rank(MPI_COMM_WORLD, &myid);
   ierr = MPI_Comm_size(MPI_COMM_WORLD, &nproc);

   // welcome
   if(myid == 0) welcome();
 
   // read inputs
   readInputs(myid);

   ierr = MPI_Barrier(MPI_COMM_WORLD);

   // create output folder to store data in
   createOutputFolder(myid);
   
   // create list of triangles containing a given node
   createTriangleList(&g[myid]);

   // find cell loops and vertex loops
   triCellAndVertexLoops(&g[myid]);

   // colouring algorithm
   greedyColouringAlgorithm(&g[myid]);

   // extract edges from triangulation 
   findTriangleEdges(&g[myid]);
            
   // invert edge list (reverse list)
   createEdgeList(&g[myid]);

   // create vertices on each edge (and quad edges)
   createVerticesOnEdge(&g[myid]);

   // create quad cells
   createInteriorVertices(&g[myid]);

   // find quad loops
   quadLoops(&g[myid]);

   // smoothing
   if(strcmp(smoothTechnique,"lagrangian")==0)
   {
   	smoothGrid(&g[myid],numSmooth);
	}
	else if(strcmp(smoothTechnique,"blend")==0)
	{
		smoothTriangleGrid(&g[myid],numSmooth);
     	recreateVerticesOnEdge(&g[myid]);
     	recreateInteriorVertices(&g[myid]);
	}

   // create boundary information
   boundaryNodeConnection_MPI(myid); 

   // create strand template
   if(iStrand) 
   {      
      // wait till thread 0 has finished
      ierr = MPI_Barrier(MPI_COMM_WORLD);

      createStrands(myid, &g[myid]);
   }

   // check quality and output statistics
   meshQuality(myid,&g[myid]);   
      
   // write tecplot outputs
   writeTecplot(myid,&g[myid]);

   ierr = MPI_Barrier(MPI_COMM_WORLD);

   //thanks
   if(myid == 0) thanks();

   MPI_Finalize();
	return 0;	
}
void TableBehaviorSnake::doLoop()
{
   paintAll(CRGB::Black, false);

    int newPosX = -1;
    int newPosY = -1;

    int randomTryCount = 0;

    while(newPosX == -1 && randomTryCount < 500){


        switch (mDirection) {
        case 0:
            if(isPositionEmpty(mSnake[0]->x - 1, mSnake[0]->y) == 1){
                newPosX = mSnake[0]->x - 1;
                newPosY = mSnake[0]->y;
            }
            break;

        case 1:
            if(isPositionEmpty(mSnake[0]->x + 1, mSnake[0]->y) == 1){
                newPosX = mSnake[0]->x + 1;
                newPosY = mSnake[0]->y;
            }
            break;
        case 2:
            if(isPositionEmpty(mSnake[0]->x, mSnake[0]->y - 1) == 1){
                newPosX = mSnake[0]->x;
                newPosY = mSnake[0]->y - 1;
            }
            break;
        case 3:
            if(isPositionEmpty(mSnake[0]->x, mSnake[0]->y + 1) == 1){
                newPosX = mSnake[0]->x;
                newPosY = mSnake[0]->y + 1;
            }
            break;
        default:
            break;
        }

        if (newPosX == -1){
            mDirection = random(4);
            randomTryCount++;
        }
    }

    // Gameover ?
    if (newPosX == -1 || newPosY == -1){

        delay(1000);
        mSnakeSize = 3;
        mSnake[0]->set(9, 4);
        mSnake[1]->set(9, 3);
        mSnake[2]->set(9, 2);

    }else{
        // move the snake
        SnakeUnit previousValues;
        SnakeUnit newValues;
        for (int i = 0; i < mSnakeSize; ++i) {

            int tmpX = mSnake[i]->x;
            int tmpY = mSnake[i]->y;


            // if 'head' else 'body'
            if (i == 0){
                newValues.x = newPosX;
                newValues.y = newPosY;

            }else{
                newValues.x = previousValues.x;
                newValues.y = previousValues.y;
            }

            // Apply new values
            mSnake[i]->x = newValues.x;
            mSnake[i]->y = newValues.y;

            // Store old values
            previousValues.x = tmpX;
            previousValues.y = tmpY;

            setCorrectColor(mSnake[i]->x,  mSnake[i]->y, mSnakeColor);
        }
    }

    // Sometimes change the direction
    if (random(100) > 80){
        mDirection = random(4);
    }

    // Sometimes growup
    if (random(100) > 95){
        growUp();
    }

    FastLED.show();

    delay(50);

    // read any changes on Potentiometer and Button B
    readInputs();
}
Example #12
0
static long process(struct cvtRecord *pcvt)
{
    long status = 0;

    pcvt->pact = TRUE;
    status = dbGetLink(&pcvt->inil, DBR_UCHAR, &pcvt->init, 0, 0);
    pcvt->pact = FALSE;

    if (status) {
        recGblSetSevr(pcvt, LINK_ALARM, INVALID_ALARM);
        goto error;
    }
    if (checkInit(pcvt)) {
        recGblSetSevr(pcvt, SOFT_ALARM, INVALID_ALARM);
        recGblResetAlarms(pcvt);
        pcvt->pact = TRUE;
        return -1;
    }

    pcvt->pact = TRUE;
    status = readInputs(pcvt);
    pcvt->pact = FALSE;

    if (status) {
        goto error;
    }

    status = convert(pcvt);

error:
    checkAlarms(pcvt);

    pcvt->pact = TRUE;
    if (pcvt->nsev < INVALID_ALARM) {
        status = dbPutLink(&pcvt->out, DBR_DOUBLE, &pcvt->val, 1);
    }
    else {
        switch (pcvt->ivoa) {
        case (menuIvoaSet_output_to_IVOV):
            pcvt->val = pcvt->ivov;
            /* note: this falls through to the case below */
        case (menuIvoaContinue_normally):
            status = dbPutLink(&pcvt->out, DBR_DOUBLE, &pcvt->val, 1);
        case (menuIvoaDon_t_drive_outputs):
            break;
        default:
            status = S_db_badField;
            errmsg("internal error: Illegal value in IVOA field");
            recGblSetSevr(pcvt, SOFT_ALARM, INVALID_ALARM);
            recGblResetAlarms(pcvt);
            return status;
        }
    }

    recGblGetTimeStamp(pcvt);
    monitor(pcvt);
    recGblFwdLink(pcvt);

    pcvt->pact = FALSE;

    return status;
}
Example #13
0
void loop () {
	readInputs ();
	cycle ();
	writeOutputs ();
}