Ejemplo n.º 1
0
int main( void )
{
	char s[ 256 ];
	int i;
	uint8_t sn;

	printf( "Waiting the EV3 brick online...\n" );
	if ( ev3_init() < 1 ) return ( 1 );

	printf( "*** ( EV3 ) Hello! ***\n" );
	ev3_port_init();

	printf( "Found ports:\n" );
	for ( i = 0; i < DESC_LIMIT; i++ ) {
		if ( ev3_port[ i ].type_inx != PORT_TYPE__NONE_ ) {
			printf( "  type = %s\n", ev3_port_type( ev3_port[ i ].type_inx ));
			printf( "  port = %s\n", ev3_port_port_name( i, s ));
			if ( get_port_mode( i, s, sizeof( s ))) {
				printf( "  mode = %s\n", s );
			}
		}
	}
	sn = ev3_search_port( INPUT_2, EXT_PORT__NONE_ );
	printf( "Port '%s'\n", ev3_port_name( INPUT_2, EXT_PORT__NONE_, 0, s ));
	if ( get_port_modes( sn, s, sizeof( s ))) {
		printf( "Modes: %s\n", s );
	} else {
		printf( "ERROR: get_port_modes()\n" );
	}
	ev3_uninit();
	printf( "*** ( EV3 ) Bye! ***\n" );

	return ( 0 );
}
Ejemplo n.º 2
0
int app_init( void )
{
	char s[ 16 ];

	if ( ev3_search_tacho_plugged_in( L_MOTOR_PORT, L_MOTOR_EXT_PORT, motor + L, 0 )) {
		get_tacho_max_speed( motor[ L ], &max_speed );
		/* Reset the motor */
		set_tacho_command_inx( motor[ L ], TACHO_RESET );
	} else {
		printf( "LEFT motor (%s) is NOT found.\n", ev3_port_name( L_MOTOR_PORT, L_MOTOR_EXT_PORT, 0, s ));
		/* Inoperative without left motor */
		return ( 0 );
	}
	if ( ev3_search_tacho_plugged_in( R_MOTOR_PORT, R_MOTOR_EXT_PORT, motor + R, 0 )) {
		/* Reset the motor */
		set_tacho_command_inx( motor[ R ], TACHO_RESET );
	} else {
		printf( "RIGHT motor (%s) is NOT found.\n", ev3_port_name( R_MOTOR_PORT, R_MOTOR_EXT_PORT, 0, s ));
		/* Inoperative without right motor */
		return ( 0 );
	}
	command	= moving = MOVE_NONE;

	if ( ev3_search_sensor( LEGO_EV3_IR, &ir, 0 )) {
		_set_mode( MODE_REMOTE );
	} else {
		printf( "IR sensor is NOT found.\n" );
		/* Inoperative without IR sensor */
		return ( 0 );
	}
	printf(	"IR remote control:\n"
	"RED UP & BLUE UP     - forward\n"
	"RED DOWN & BLUE DOWN - backward\n"
	"RED UP | BLUE DOWN   - left\n"
	"RED DOWN | BLUE UP   - right\n"
	"To switch between IR remote control and\n"
	"self-driving" );
	if ( ev3_search_sensor( LEGO_EV3_TOUCH, &touch, 0 )) {
		printf( " use the TOUCH sensor.\n" );
	} else {
		touch = DESC_LIMIT;
		printf( " press UP on the EV3 brick.\n" );
	}
	printf( "Press BACK on the EV3 brick for EXIT...\n" );
	return ( 1 );
}
Ejemplo n.º 3
0
char *ev3_servo_port_name( uint8_t sn, char *buf )
{
    return ( ev3_port_name( ev3_servo_desc( sn )->port, ev3_servo_desc( sn )->extport, ev3_servo_desc( sn )->addr, buf ));
}