Пример #1
0
void hexbright::read_accelerometer() {
  /*unsigned long time = 0;
    if((millis()-init_time)>*/
  // advance which vector is considered the first
  next_vector();
  while(1) {
    Wire.beginTransmission(ACC_ADDRESS);
    Wire.write(ACC_REG_XOUT);          // starting with ACC_REG_XOUT,
    Wire.endTransmission(false);
    Wire.requestFrom(ACC_ADDRESS, 4);  // read 4 registers (X,Y,Z), TILT
    for(int i=0; i<4; i++) {
      if (!Wire.available())
        continue;
      char tmp = Wire.read();
      if(tmp & 0x40) // Bx1xxxxxx, re-read per data sheet page 14
        continue;
      if(i==3){ //read tilt register
        tilt = tmp;
      } else { // read vector
        if(tmp & 0x20) // Bxx1xxxxx, it's negative
          tmp |= 0xC0; // extend to B111xxxxx
	vectors[current_vector+i] = stdev_filter3(vector(1)[i], tmp*(100/21.3));
      }
    }
    break;
  }
}
Пример #2
0
void hexbright::fake_read_accelerometer(int* new_vector) {
  next_vector();
  for(int i=0; i<3; i++) {
    vector(0)[i] = stdev_filter3(vector(1)[i], new_vector[i]);
    //vector(0)[i] = new_vector[i];
  }
}
Пример #3
0
/* Generic function for finding the distance to the closest sea, land, or
   mountain
*/
static int
distance_to_what(int x, int y, int flag)
{
    int j, d, px, py;

    for (d = 1; d < 5; ++d) {
	for (j = 0; j < d; ++j)
	    vector[j] = 0;
	do {
	    px = x;
	    py = y;
	    for (j = 0; j < d; ++j) {
		px = new_x(px + dirx[vector[j]]);
		py = new_y(py + diry[vector[j]]);
	    }
	    switch (flag) {
	    case 0:		/* distance to sea */
		if (own[px][py] == -1)
		    return d;
		break;
	    case 1:		/* distance to land */
		if (own[px][py] != -1)
		    return d;
		break;
	    case 2:		/* distance to mountain */
		if (elev[px][py] == INFINITY)
		    return d;
		break;
	    }
	} while (next_vector(d));
    }
    return d;
}
Пример #4
0
/* Test to see if we're allowed to grow there: the arguments di and id
*/
static int
try_to_grow(int c, int newx, int newy, int d)
{
    int i, j, px, py;

    for (i = 1; i <= d; ++i) {
	for (j = 0; j < i; ++j)
	    vector[j] = 0;
	do {
	    px = newx;
	    py = newy;
	    for (j = 0; j < i; ++j) {
		px = new_x(px + dirx[vector[j]]);
		py = new_y(py + diry[vector[j]]);
	    }
	    if (own[px][py] != -1 &&
		own[px][py] != c &&
		(DISTINCT_ISLANDS || own[px][py] < nc))
		return 0;
	} while (next_vector(i));
    }
    sectx[c][secs] = newx;
    secty[c][secs] = newy;
    own[newx][newy] = c;
    return 1;
}
Пример #5
0
INT number_partition::next()
{
	// cout << "number_partition::next()\n";
	if (s_type() == PARTITION_TYPE_EXPONENT)
		return next_exponent();
	else
		return next_vector();
}