Esempio n. 1
0
// learn some stuff
// shuffle the array of purchases
// and then consume all of it
void run() {
    clock_t start = clock();
    clock_t now;
    debug("Shuffling...");
    shuffle_purchases();
    debug("Finished shuffle.");
    linenum = 0;

    for (long long i=0; i<INTERACTIONS; i++) {
        linenum = i;
        onestep(purchases[i]);

        if (i%10000==0) {
            now = clock();
            int seconds_remaining = (int)((now - start)/(CLOCKS_PER_SEC+0.)*INTERACTIONS/(linenum+0.));
            int hours = seconds_remaining/(60*60);
            seconds_remaining -= hours*60*60;
            int minutes = seconds_remaining/60;
            seconds_remaining -= minutes*60;
            printf("%c%lldK lines processed. %.2f%% done. est time remaining %dh%2dm             ", 
                    13, linenum/1000, linenum/(INTERACTIONS+0.)*100., hours, minutes);
            fflush(stdout);
        }
    }
}
Esempio n. 2
0
static unsigned long
spotlight_draw (Display *dpy, Window window, void *closure)
{
  struct state *st = (struct state *) closure;
  onestep(st, st->first_p);
  st->first_p = False;
  return st->delay;
}
/**
 * Uses bresenham's line algorithm to move both motors
 * @input newx the destination x position
 * @input newy the destination y position
 **/
void line(float newx,float newy) {
  long dx=newx-px;
  long dy=newy-py;
  int dirx=dx>0?1:-1;
  int diry=dy>0?-1:1;  // because the motors are mounted in opposite directions
  dx=abs(dx);
  dy=abs(dy);

  long i;
  long over=0;

#ifdef VERBOSE
  Serial.println(F("Start >"));
#endif

  if(dx>dy) {
    for(i=0;i<dx;++i) {
      onestep(1,dirx);
      over+=dy;
      if(over>=dx) {
        over-=dx;
        onestep(2,diry);
      }
      tick();
    }
  } else {
    for(i=0;i<dy;++i) {
      onestep(2,diry);
      over+=dx;
      if(over>=dy) {
        over-=dy;
        onestep(1,dirx);
      }
      tick();
    }
  }

#ifdef VERBOSE
  Serial.println(F("< Done."));
#endif

  px=newx;
  py=newy;
}
void AF_Stepper::step(uint16_t steps, uint8_t dir,  uint8_t style) {
  uint32_t uspers = usperstep;
  uint8_t ret = 0;

  if (style == INTERLEAVE) {
    uspers /= 2;
  }
#ifdef MICROSTEPPING
 else if (style == MICROSTEP) {
    uspers /= MICROSTEPS;
    steps *= MICROSTEPS;
#ifdef MOTORDEBUG
    Serial.print("steps = "); Serial.println(steps, DEC);
#endif
  }
#endif

  while (steps--) {
    ret = onestep(dir, style);
    delay(uspers/1000); // in ms
    steppingcounter += (uspers % 1000);
    if (steppingcounter >= 1000) {
      delay(1);
      steppingcounter -= 1000;
    }
  }
#ifdef MICROSTEPPING
  if (style == MICROSTEP) {
    //Serial.print("last ret = "); Serial.println(ret, DEC);
    while ((ret != 0) && (ret != MICROSTEPS)) {
      ret = onestep(dir, style);
      delay(uspers/1000); // in ms
      steppingcounter += (uspers % 1000);
      if (steppingcounter >= 1000) {
	delay(1);
	steppingcounter -= 1000;
      } 
    }
  }
#endif

}
void AF_Stepper::step(uint16_t steps, uint8_t dir) {
  uint32_t uspers = usperstep;

  while (steps--) {
    onestep(dir);
/*
    delay(uspers/1000);  // in ms
    steppingcounter += (uspers % 1000);
    if (steppingcounter >= 1000) {
      delay(1);
      steppingcounter -= 1000;
    }
//*/
    delayMicroseconds(uspers);
  }
}
void Adafruit_StepperMotor::step(uint16_t steps, uint8_t dir,  uint8_t style) {
  uint32_t uspers = usperstep;
  uint8_t ret = 0;

  if (style == INTERLEAVE) {
    uspers /= 2;
  }
 else if (style == MICROSTEP) {
    uspers /= MICROSTEPS;
    steps *= MICROSTEPS;
#ifdef MOTORDEBUG
    Serial.print("steps = "); Serial.println(steps, DEC);
#endif
  }

  while (steps--) {
    //Serial.println("step!"); Serial.println(uspers);
    ret = onestep(dir, style);
    delayMicroseconds(uspers);
  }
}
main()
{
setlocale(LC_ALL, "en_US.UTF-8");
	WINDOW * mainwin;

 if ( (mainwin = initscr()) == NULL ) {
	fprintf(stderr, "Error initialising ncurses.\n");
	exit(EXIT_FAILURE);
    }
int height = 29;
int width = 80;

	mvaddstr(0, 0, "+------------------------------------------------------------------------------+");

	int u;
	for(u=1;u<height;u++)
	{
		mvaddstr(u,0,"|                                                                              |");
	}
	mvaddstr(height, 0, "+------------------------------------------------------------------------------+");

	/*setvbuf (stdout, NULL, _IONBF, 0);
	printf("asds \n");*/

	
	int gridHeight= 15;
	int gridWidth= 15;
	int** grid = createGrid(gridHeight,gridWidth);
	/*grid[2][2]=1;grid[3][2]=1;grid[2][1]=1;grid[2][3]=1;*//*grid[1][2]=1;*/
	grid[1][0]=1;grid[0][2]=1;grid[1][2]=1;grid[2][2]=1;grid[2][1]=1;
/*grid[4][4]=1;grid[4][3]=1;grid[4][5]=1;*/
	makeDisp(grid, gridHeight, gridWidth);sleep(3);
	int** newgrid;
	int o = 0;
	while(o<1)
	{
	/*usleep(125000);*/
	
	newgrid = onestep(grid, gridHeight, gridWidth);
	int i;
	/*for(i=0;i<gridHeight;i++)
		free(grid[i]);
	free(grid);*/

	/*printf("\n");*/
	printGrid(newgrid, gridHeight, gridWidth);
	o++;
	grid = newgrid;
	}


wchar_t* wstr = L"\u2593";
mvwaddwstr(mainwin, 1, 1, wstr);
    	refresh();sleep(2);
    	usleep(500000);
	mvaddstr(1, 2, "e");
    	refresh();
    	usleep(500000);
	mvaddstr(1, 3, "l");
    	refresh();
    	usleep(500000);
	mvaddstr(1, 4, "l");
    	refresh();
    	usleep(500000);
	mvaddstr(1, 5, "o");
    	refresh();
    	usleep(500000);
	mvaddstr(1, 6, "!");
    	refresh();
    	usleep(500000);


	delwin(mainwin);
	endwin();
	refresh();
	
	

	return 0;
}