Example #1
0
void Client::sendPlayerPos()
{
	LocalPlayer *myplayer = m_env.getLocalPlayer();
	if(myplayer == NULL)
		return;

	// Save bandwidth by only updating position when something changed
	if(myplayer->last_position        == myplayer->getPosition() &&
			myplayer->last_speed      == myplayer->getSpeed()    &&
			myplayer->last_pitch      == myplayer->getPitch()    &&
			myplayer->last_yaw        == myplayer->getYaw()      &&
			myplayer->last_keyPressed == myplayer->keyPressed)
		return;

	myplayer->last_position   = myplayer->getPosition();
	myplayer->last_speed      = myplayer->getSpeed();
	myplayer->last_pitch      = myplayer->getPitch();
	myplayer->last_yaw        = myplayer->getYaw();
	myplayer->last_keyPressed = myplayer->keyPressed;

	u16 our_peer_id;
	{
		//JMutexAutoLock lock(m_con_mutex); //bulk comment-out
		our_peer_id = m_con.GetPeerID();
	}

	// Set peer id if not set already
	if(myplayer->peer_id == PEER_ID_INEXISTENT)
		myplayer->peer_id = our_peer_id;

	assert(myplayer->peer_id == our_peer_id);

	v3f pf         = myplayer->getPosition();
	v3f sf         = myplayer->getSpeed();
	s32 pitch      = myplayer->getPitch() * 100;
	s32 yaw        = myplayer->getYaw() * 100;
	u32 keyPressed = myplayer->keyPressed;

	v3s32 position(pf.X*100, pf.Y*100, pf.Z*100);
	v3s32 speed(sf.X*100, sf.Y*100, sf.Z*100);
	/*
		Format:
		[0] v3s32 position*100
		[12] v3s32 speed*100
		[12+12] s32 pitch*100
		[12+12+4] s32 yaw*100
		[12+12+4+4] u32 keyPressed
	*/

	NetworkPacket pkt(TOSERVER_PLAYERPOS, 12 + 12 + 4 + 4 + 4);

	pkt << position << speed << pitch << yaw << keyPressed;

	Send(&pkt);
}
Example #2
0
void frog::keyup(unsigned char key) {
    switch (key) {
    case 'o':
        speed().x() += SPEED_X;
        orientation_ -= 45;
        break;
    case 'p':
        speed().x() -= SPEED_X;
        orientation_ += 45;
        break;
    case 'q':
        speed().z() += SPEED_Z;
        break;
    case 'a':
        speed().z() -= SPEED_Z;
        break;
    default:
        break;
    }
}
Example #3
0
int main(void)
{
	init_MCU();
	LED_R_ON;

	speed(0,0);
	while(1)
	{
		ctrrobot();
	}
}
TEST(ValidMoveRightTest, ValidMoveReturnsSameMoveIfItIsValid){
	std::list<Position> allPosns;
	allPosns.push_back(Position(Vector2(0, 0), 50, 50));

	ValidMove validity(Position(Vector2(0, 0), 500, 500), allPosns);
	Vector2 speed(25, 0);
	Position nextMove(Vector2(25, 0), 50, 50);
	Position validMove = validity.getValidMove(Position(Vector2(0, 0), 50, 50), speed);
	
	EXPECT_EQ(validMove, nextMove); 
}
Example #5
0
void Loadbar::createAnimation()
{
    fillCubeArray(0x00);
    for (quint8 i = 0; i < CUBE_SIZE; i++)
    {
        setPlane(m_axis, i);
        if(m_abort)
            return;
        waitMs(speed());
    }
    waitMs(speed() * 2);
    for (quint8 i = 0; i < CUBE_SIZE; i++)
    {
        clearPlane(m_axis, i);
        if(m_abort)
            return;
        waitMs(speed());
    }
    Q_EMIT done();
}
Example #6
0
uint8 CPU::op_read(uint32 addr) {
  debugger.op_read(addr);

  status.clock_count = speed(addr);
  dma_edge();
  add_clocks(status.clock_count - 4);
  regs.mdr = bus.read(addr);
  add_clocks(4);
  alu_edge();
  return regs.mdr;
}
Example #7
0
/* ARGSUSED */
void
variable(int cc)
{
	char	buf[256];

	if (prompt("[set] ", buf, sizeof (buf)))
		return;
	vlex(buf);
	if (vtable[BEAUTIFY].v_access&CHANGED) {
		vtable[BEAUTIFY].v_access &= ~CHANGED;
		(void) kill(pid, SIGSYS);
	}
	if (vtable[SCRIPT].v_access&CHANGED) {
		vtable[SCRIPT].v_access &= ~CHANGED;
		setscript();
		/*
		 * So that "set record=blah script" doesn't
		 *  cause two transactions to occur.
		 */
		if (vtable[RECORD].v_access&CHANGED)
			vtable[RECORD].v_access &= ~CHANGED;
	}
	if (vtable[RECORD].v_access&CHANGED) {
		vtable[RECORD].v_access &= ~CHANGED;
		if (boolean(value(SCRIPT)))
			setscript();
	}
	if (vtable[TAND].v_access&CHANGED) {
		vtable[TAND].v_access &= ~CHANGED;
		if (boolean(value(TAND)))
			tandem("on");
		else
			tandem("off");
	}
	if (vtable[LECHO].v_access&CHANGED) {
		vtable[LECHO].v_access &= ~CHANGED;
		boolean(value(HALFDUPLEX)) = boolean(value(LECHO));
	}
	if (vtable[PARITY].v_access&CHANGED) {
		vtable[PARITY].v_access &= ~CHANGED;
		setparity(NULL);
	}
	if (vtable[BAUDRATE].v_access&CHANGED) {
		vtable[BAUDRATE].v_access &= ~CHANGED;
		ttysetup(speed(number(value(BAUDRATE))));
	}
	if (vtable[HARDWAREFLOW].v_access & CHANGED) {
		vtable[HARDWAREFLOW].v_access &= ~CHANGED;
		if (boolean(value(HARDWAREFLOW)))
			hardwareflow("on");
		else
			hardwareflow("off");
	}
}
int main(){


    long n(0), k(0); scanf("%ld %ld\n", &n, &k);
    std::vector<long> speed(n,0);
    for(int p = 0; p < n; p++){scanf("%ld", &speed[p]);}
    std::sort(speed.begin(), speed.end());
    printf("%ld\n", speed[n - k]);

    return 0;
}
Example #9
0
void KJob::emitSpeed(unsigned long value)
{
    Q_D(KJob);
    if (!d->speedTimer) {
        d->speedTimer = new QTimer(this);
        connect(d->speedTimer, SIGNAL(timeout()), SLOT(_k_speedTimeout()));
    }

    emit speed(this, value);
    d->speedTimer->start(5000);   // 5 seconds interval should be enough
}
Example #10
0
void CVarPlatform::process()
{
    int xBlockPos = target.x - getXPosition();
    int yBlockPos = target.y - getYPosition();
    
    const int xBlockPosAbs = (xBlockPos<0) ? -xBlockPos : xBlockPos;
    const int yBlockPosAbs = (yBlockPos<0) ? -yBlockPos : yBlockPos;
    
    if( xBlockPosAbs < MOVE_SPEED && yBlockPosAbs < MOVE_SPEED )
    {
        const Uint16 object = mpMap->getPlaneDataAt(2, target.x, target.y);

        Vector2D<int> speed(xBlockPos, yBlockPos);
        movePlat(speed);

        readDirection(object, xDirection, yDirection );
        detectNextTarget(target, xDirection, yDirection);
    }
    
    if(yDirection == UP && blockedu)
        yDirection = DOWN;
    else if(yDirection == DOWN && blockedd)
        yDirection = UP;
    
    if(xDirection == RIGHT && blockedr)
        xDirection = LEFT;
    else if(xDirection == LEFT && blockedl)
        xDirection = RIGHT;
    
    Vector2D<int> speed;
    
    if(yDirection == UP)
    {
        speed.y = -MOVE_SPEED;
    }
    else if(yDirection == DOWN)
    {
        speed.y = MOVE_SPEED;
    }
    
    
    if(xDirection == RIGHT)
    {
        speed.x = MOVE_SPEED;
    }
    else if(xDirection == LEFT)
    {
        speed.x = -MOVE_SPEED;
    }
    
    movePlat(speed);
    
    CPlatform::process();
}
void T12SuperBallPayload::setup(tgWorld& world)
{

    const tgRod::Config rodConfig(c.radius, c.density, c.friction, 
				c.rollFriction, c.restitution);
    /// @todo acceleration constraint was removed on 12/10/14 Replace with tgKinematicActuator as appropreate
    tgBasicActuator::Config muscleConfig(c.stiffness, c.damping, c.pretension,
					    c.history, c.maxTens, c.targetVelocity);
            
    // Start creating the structure
    tgStructure s;
    addNodes(s);
    addRods(s);
    addMuscles(s);

//    // Add a rotation. This is needed if the ground slopes too much,
//    // otherwise  glitches put a rod below the ground.
//    btVector3 rotationPoint = btVector3(0, 0, 0); // origin
//    btVector3 rotationAxis = btVector3(0, 1, 0);  // y-axis
//    double rotationAngle = M_PI/2;
//    s.addRotation(rotationPoint, rotationAxis, rotationAngle);

    //s.move(btVector3(0,30,0));

    // Create the build spec that uses tags to turn the structure into a real model
    tgBuildSpec spec;
    spec.addBuilder("rod", new tgRodInfo(rodConfig));
    spec.addBuilder("muscle", new tgBasicActuatorInfo(muscleConfig));
    
    // Create your structureInfo
    tgStructureInfo structureInfo(s, spec);

    // Use the structureInfo to build ourselves
    structureInfo.buildInto(*this, world);

    // We could now use tgCast::filter or similar to pull out the
    // models (e.g. muscles) that we want to control. 
    allMuscles = tgCast::filter<tgModel, tgBasicActuator> (getDescendants());

    // call the onSetup methods of all observed things e.g. controllers
    notifySetup();

    // Actually setup the children
    tgModel::setup(world);

    //map the rods and add the markers to them
    addMarkers(s);

    btVector3 location(0,10.0,0);
    btVector3 rotation(0.0,0.6,0.8);
  	btVector3 speed(0,20,100);
    this->moveModel(location,rotation,speed);
}
TEST(ValidMoveLeftTest, IfThinPieceCenterCloserThanThickPieceCenterThickPieceStillConsideredClosest){
	std::list<Position> allPosns;
	allPosns.push_back(Position(Vector2(150, 20), 50, 50));
	allPosns.push_back(Position(Vector2(75, 0), 10, 50));
	allPosns.push_back(Position(Vector2(75, 50), 50, 50));
	ValidMove validity(Position(Vector2(0, 0), 500, 500), allPosns);

	Position expectedNextMove(Vector2(126, 20), 50, 50);
	Vector2 speed(-150, 0);
	Position validMove = validity.getValidMove(Position(Vector2(150, 20), 50, 50), speed);
	EXPECT_EQ(validMove, expectedNextMove)<< "Got: " << validMove.getX() << " " << validMove.getY();
}
Example #13
0
void KPrPageEffect::saveOdfSmilAttributes( KoGenStyle & style ) const
{
    QString speed("slow");
    if (m_duration < 2500) {
        speed = "fast";
    }
    else if (m_duration < 7500) {
        speed = "medium";
    }
    style.addProperty("presentation:transition-speed", speed);
    return m_strategy->saveOdfSmilAttributes(style);
}
TEST(ValidMoveDownTest, StandardMoveDownWorks){
	std::list<Position> allPosns;
	Position myPosn = Position(Vector2(20, 10), 20, 10);
	allPosns.push_back(Position(Vector2(30, 30), 10, 10));
	allPosns.push_back(myPosn);
	ValidMove validity(Position(Vector2(0, 0), 500, 500), allPosns);

	Position expectedNextMove(Vector2(20, 19), 20, 10);
	Vector2 speed(0, 50);
	Position validMove = validity.getValidMove(myPosn, speed);
	EXPECT_EQ(validMove, expectedNextMove)<< "Got: " << validMove.getX() << " " << validMove.getY();
}
Example #15
0
void Ship::fire(std::vector<Shoot>&salvo, Fleet *enemy)
{
    double ourspeed = speed();
    for (auto weapon : weapons)
    {
        std::shared_ptr<Weapon> gun = weapon.lock();
        if (gun)
        {
            gun->fire(salvo, enemy, ourspeed);
        }
    }
}
TEST(ValidMoveLeftTest, ValidMoveReturnsClosestPositionToEdgeIfMoveNotValid){
	std::list<Position> allPosns;
	allPosns.push_back(Position(Vector2(150, 0), 50, 50));
	allPosns.push_back(Position(Vector2(75, 0), 50, 50));
	
	ValidMove validity(Position(Vector2(0, 0), 500, 500), allPosns);

	Position expectedNextMove(Vector2(126, 0), 50, 50);
	Vector2 speed(-50, 0);
	Position validMove = validity.getValidMove(Position(Vector2(150, 0), 50, 50), speed);
	EXPECT_EQ(validMove, expectedNextMove)<< "Got: " << validMove.getX() << " " << validMove.getY();
}
Example #17
0
int main(){
    double V0x,V0y,h,t,h0;
    printf("h:\n");
    scanf("%lf",&h0);
    printf("V0y:\n");
    scanf("%lf",&V0y);
    t=0;
    h=0;
    while(h>=0){
    h=h0-dist(V0y,t);
    printf("t=%lf Speed=%lf  h=%lf",t,speed(V0y,t),h);
    usleep(100);
    t=t+0.0001;
    fflush(stdout);
    printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
    }
    printf("t=%lf Speed=%lf  h=%lf\n",t,speed(V0y,t),h);



}
Example #18
0
void Car::update(double delta_t) {
	bool pressed = false;
	_acceleration = 0;
	Vector3 speed(cos((_turnAngle)*(PI / 180)), sin((_turnAngle)*(PI / 180)), 0);

	if (upKeyPressed) {
		pressed = true;
		_acceleration = FORWARD_ACCELERATION;
		if (_currentSpeed + (delta_t * _acceleration) < MAX_FORWARD_SPEED) {
			_currentSpeed = _currentSpeed + (delta_t * _acceleration);
		}
		else {
			_currentSpeed = MAX_FORWARD_SPEED;
		}
	}
	else if (downKeyPressed) {
		pressed = true;
		_acceleration = -BACKWARDS_ACCELERATION;
		if (_currentSpeed + (delta_t * _acceleration) > -MAX_BACKWARDS_SPEED) {
			_currentSpeed = _currentSpeed + (delta_t * _acceleration);
		}
		else {
			_currentSpeed = -MAX_BACKWARDS_SPEED;
		}
	}
	if (leftKeyPressed) {
		_turnAngle += ANGLE_INCREASE;
	}
	if (rightKeyPressed) {
		_turnAngle -= ANGLE_INCREASE;
	}
	if (!pressed) {
		if (_currentSpeed > 0) {
			if (_currentSpeed - (delta_t)* 0.0005 > 0) {
				_currentSpeed -= (delta_t)* 0.0005;
			}
			else {
				_currentSpeed = 0;
			}
		}
		else if (_currentSpeed < 0) {
			if (_currentSpeed + (delta_t)* FRICTION < 0) {
				_currentSpeed += (delta_t)* FRICTION;
			}
			else {
				_currentSpeed = 0;
			}
		}
	}

	_speed = speed * _currentSpeed;
	_position = (_position + _speed);
}
Example #19
0
int do_ball(int cn,int x,int y)
{
	int dir;

	if (cn<1 || cn>=MAXCHARS) { error=ERR_ILLEGAL_CHARNO; return 0; }

	if (ch[cn].flags&(CF_DEAD)) { error=ERR_DEAD; return 0; }

	if ((ch[cn].flags&CF_NOMAGIC) && !(ch[cn].flags&CF_NONOMAGIC)) { error=ERR_UNCONCIOUS; return 0; }

	if (warcried(cn)) { error=ERR_UNCONCIOUS; return 0; }

	if (!ch[cn].value[0][V_FLASH]) { error=ERR_UNKNOWN_SPELL; return 0; }

	if (x<1 || x>=MAXMAP-1 || y<1 || y>=MAXMAP-1) { error=ERR_ILLEGAL_COORDS; return 0; }

	if (ch[cn].mana<FLASHCOST) { error=ERR_MANA_LOW; return 0; }

        dir=offset2dx(ch[cn].x,ch[cn].y,x,y);
	if (!dir) {
		if (!may_add_spell(cn,IDR_FLASH)) { error=ERR_ALREADY_WORKING; return 0; }
		ch[cn].action=AC_FLASH;
		ch[cn].duration=speed(ch[cn].value[0][V_SPEED],ch[cn].speed_mode,DUR_MAGIC_ACTION);
		ch[cn].dir=bigdir(ch[cn].dir);
	} else {
		ch[cn].action=AC_BALL1;
		ch[cn].act1=x;
		ch[cn].act2=y;
		ch[cn].duration=speed(ch[cn].value[0][V_SPEED],ch[cn].speed_mode,DUR_MAGIC_ACTION/2);
		ch[cn].dir=dir;
	}

	ch[cn].mana-=FLASHCOST;

	
	if (ch[cn].speed_mode==SM_FAST) ch[cn].endurance-=end_cost(cn);

        return 1;
}
Example #20
0
/*
 X(n+1) = Xn - F(Xn)/F'(Xn)
 */
double XPQBezier::invertLength(double t, double l)
{
    double t1 = t, t2;
    
    do
    {
        t2 = t1 - (getBezierLength(t1) - l) / speed(t1);
        if(fabs(t1 - t2) < 0.0001) break;
        t1 = t2;
    } while(true);
    
    return t2;
}
Example #21
0
task syncController()
{
    int leftVal;
    int rightVal;
    int delta, max = 0;
    bool done = false;

    nMotorEncoder[leftElevator] = 0;
    nMotorEncoder[rightElevator] = 0;

    while (!done) {
	    leftVal = nMotorEncoder[leftElevator];
	    rightVal = nMotorEncoder[rightElevator];

        nxtDisplayCenteredTextLine(1, "left: %d", leftVal);
        nxtDisplayCenteredTextLine(2, "right: %d", rightVal);

        delta = abs(leftVal - rightVal);
        nxtDisplayCenteredTextLine(3, "delta: %d", delta);

        if (delta > max) {
            max = delta;
            nxtDisplayCenteredTextLine(5, "max: %d", max);
        }

	    if (abs(leftVal - rightVal) > SLOP_FACTOR) {
            if (left < right) {
                nxtDisplayCenteredTextLine(4, "stop right");
                speed(0);
            } else if (right < left) {
                nxtDisplayCenteredTextLine(4, "stop left");
                speed(0);
            }
	    } else {
            nxtDisplayCenteredTextLine(4, "go all");
            speed(20);
        }
    }
}
Example #22
0
int main()
{
	input = malloc(4096);
	output = malloc(4096);
	setup();
	if (1) {
		verify();
	} else {
		sleep(10);
		speed();
	}
	sleep(120);
}
Example #23
0
OpenSteer::Vec3 
OpenSteer::SimpleVehicle::adjustRawSteeringForce (const Vec3& force,
                                                  const float /* deltaTime */)
{
    const float maxAdjustedSpeed = 0.2f * maxSpeed ();

    if ((speed () > maxAdjustedSpeed) || (force == Vec3::zero))
    {
        return force;
    }
    else
    {
        const float range = speed() / maxAdjustedSpeed;
        // const float cosine = interpolate (pow (range, 6), 1.0f, -1.0f);
        // const float cosine = interpolate (pow (range, 10), 1.0f, -1.0f);
        // const float cosine = interpolate (pow (range, 20), 1.0f, -1.0f);
        // const float cosine = interpolate (pow (range, 100), 1.0f, -1.0f);
        // const float cosine = interpolate (pow (range, 50), 1.0f, -1.0f);
        const float cosine = interpolate (pow (range, 20), 1.0f, -1.0f);
        return limitMaxDeviationAngle (force, cosine, forward());
    }
}
Example #24
0
void Drawable::handle_action(double elapsed)
{
	cooldown -= elapsed;
	double modElapsed = reduce_duration(elapsed);

	rotation += rot_speed_*elapsed;
	//double dist = speed*modElapsed;

	switch (action)
	{
	case ACT_MOVE_UP:
        move(0, -(speed()*modElapsed));
		break;
	case ACT_MOVE_DOWN:
        move(0, (speed()*modElapsed));
		break;
	case ACT_MOVE_LEFT:
        move(-(speed()*modElapsed), 0);
		break;
	case ACT_MOVE_RIGHT:
        move((speed()*modElapsed), 0);
		break;
    case ACT_REPULSE_UP:
        move(0, -(REPULSE_SPEED*modElapsed));
        break;
    case ACT_REPULSE_DOWN:
        move(0, (REPULSE_SPEED*modElapsed));
        break;
    case ACT_REPULSE_LEFT:
        move(-(REPULSE_SPEED*modElapsed), 0);
        break;
    case ACT_REPULSE_RIGHT:
        move((REPULSE_SPEED*modElapsed), 0);
        break;
	};

	act_duration_ -= elapsed;
}
Example #25
0
void
go (int x, int y)
{
  /* find the heading we need to get to the desired corner */
  int angle = plot_course (x, y);

  /* start drive train, full speed */
  drive (angle, 100);

  /* keep traveling until we are within 100 meters */
  /* speed is checked in case we run into wall, other robot */
  /* not terribly great, since we are doing nothing while moving */
  while (distance (loc_x (), loc_y (), x, y) > 100 && speed () > 0)
    cycle ();

  /* cut speed, and creep the rest of the way */
  drive (angle, 20);
  while (distance (loc_x (), loc_y (), x, y) > 10 && speed () > 0)
    cycle ();

  /* stop drive, should coast in the rest of the way */
  drive (angle, 0);
}
Example #26
0
void
Robot::paintWithPainter (QPainter &painter)
{
    Vector2D myPosition = position(),
             mySpeed = speed();

    painter.setBrush(QBrush());
    painter.setPen(blue);
    painter.drawEllipse(int(10 * (myPosition.x - 10)), int(10 * (myPosition.y - 10)), 200, 200);
    painter.drawLine(int(10 * myPosition.x),
                     int(10 * myPosition.y),
                     int(10 * (myPosition.x + 50 * mySpeed.x)),
                     int(10 * (myPosition.y + 50 * mySpeed.y)));
}
void path_follower_motor(int detectline)
{
    char direction;
    switch(detectline)
    {
    case 1:	//forward
        direction=0x81;
        speed(direction,190);
        return;
    case 2:	//right
        direction=0x41;
        speed(direction,220);
        return;
    case 3:	//left
        direction=0x82;
        speed(direction,220);
        return;
    case 4:	//stop
        direction=0x00;
        speed(direction,255);
        return;
    }
}
Example #28
0
inline void load_score_file(std::ifstream& fscore,
                            ContestResult& score)
{
  double tmp;
  fscore >> tmp; score.score = (fixed)tmp;
  fscore >> tmp; score.distance = (fixed)tmp;
  fscore >> tmp; fixed speed(tmp);
  if (speed>fixed(0)) {
    score.time = fixed(3600)*score.distance/speed;
  } else {
    score.time = fixed(0);
  }
  score.distance *= fixed(1000);
}
/*
* Entry point
*/
void main() {
  // Variables
  char speedBuf[5] = {0,0,0,0,0};
  char totalBuf[] = {0,0,0,0,0,0,0,0,0,0};
  char empty[] = "                ";
  union eeprom_int totalKm;
  int kph = 1;

  // Initialization
  initialize();
  
  // 0x10 = first byte of the actual int value
  // 0x11 = second byte of the actual int value
  totalKm.memory[0] = EEPROM_Read(KM_ADDR);
  totalKm.memory[1] = EEPROM_Read(KM_ADDR+1);

  // 0xFF is 8 bit, an uint is 2 byte = 16 bit, so we need 0xFFFF
  if(totalKm.value == 0xFFFF) {
    totalKm.value = 0;
  }
  
  do {
    // Reads the value of the RA2 Analog knob.
    adcInput = ADC_Read(2);

    
    if(shouldUpdateSpeedometer == 1) {
      shouldUpdateSpeedometer = 0;
      // Update speedometer LCD here
      speed(speedBuf, adcInput, &kph);
      Lcd_Out(1,1,empty);
      Lcd_Out(1,1,"km/t: ");
      Lcd_Out(1,7,speedBuf);
    }
    
    if(shouldUpdateTotal) {
      shouldUpdateTotal = 0;
      // Update LCD and save total here
      total(totalBuf, &totalKm.value, kph);
      
      EEPROM_Write(KM_ADDR, totalKm.memory[0]);
      EEPROM_Write(KM_ADDR+1, totalKm.memory[1]);
      Lcd_Out(2,1,empty);
      Lcd_Out(2,1, "Total: ");
      Lcd_Out(2,8, totalBuf);
    }
    
  }while(1);
}
Example #30
0
static int find_testdev(const char *name, const struct stat *sb, int flag)
{
	FILE				*fd;
	int				ifnum;
	struct testdev			*entry;

	(void)sb; /* unused */

	if (flag != FTW_F)
		return 0;
	/* ignore /proc/bus/usb/{devices,drivers} */
	if (strrchr(name, '/')[1] == 'd')
		return 0;

	fd = fopen(name, "rb");
	if (!fd) {
		perror(name);
		return 0;
	}

	ifnum = testdev_ifnum(fd);
	fclose(fd);
	if (ifnum < 0)
		return 0;

	entry = calloc(1, sizeof *entry);
	if (!entry)
		goto nomem;

	entry->name = strdup(name);
	if (!entry->name) {
		free(entry);
nomem:
		perror("malloc");
		return 0;
	}

	entry->ifnum = ifnum;

	/* FIXME ask usbfs what speed; update USBDEVFS_CONNECTINFO so
	 * it tells about high speed etc */

	fprintf(stderr, "%s speed\t%s\t%u\n",
		speed(entry->speed), entry->name, entry->ifnum);

	entry->next = testdevs;
	testdevs = entry;
	return 0;
}