Beispiel #1
0
bool Skitt::initalize()
{
	/* Check the settings the gave us. */

	/* Configure GPIO pins. */

	if (!is_pin_exported(good_led_pin)) {
		set_mux("gpmc_ad4", "7");
		set_mux("gpmc_ad0", "7");
		set_mux("lcd_vsync", "7");
		set_mux("lcd_hsync", "7");
		set_mux("lcd_data6", "7");
		set_mux("lcd_data4", "7");

		set_mux("gpmc_ad15", "7");
		set_mux("gpmc_ad11", "7");
		set_mux("gpmc_ad13", "7");

		export_pin(mux_pins[0][0]);
		export_pin(mux_pins[0][1]);
		export_pin(mux_pins[0][2]);
		export_pin(mux_pins[1][0]);
		export_pin(mux_pins[1][1]);
		export_pin(mux_pins[1][2]);

		export_pin(good_led_pin);
		export_pin(error_led_pin);
		export_pin(streaming_led_pin);

		set_pin_direction(mux_pins[0][0], OUT);
		set_pin_direction(mux_pins[0][1], OUT);
		set_pin_direction(mux_pins[0][2], OUT);
		set_pin_direction(mux_pins[1][0], OUT);
		set_pin_direction(mux_pins[1][1], OUT);
		set_pin_direction(mux_pins[1][2], OUT);

		set_pin_direction(good_led_pin, OUT);
		set_pin_direction(error_led_pin, OUT);
		set_pin_direction(streaming_led_pin, OUT);
	}

	/* Configure SPI connection. */
	if (!connect_to_spi("/dev/spidev2.0")) {
		return false;
	}
	return true;
}
Beispiel #2
0
int main( int argc, char** argv )
{
    try
    {
        std::string config_string; 
        std::string direction;
        unsigned int pin; 
        boost::program_options::options_description description( "options" );
        description.add_options()
            ( "help,h", "display help message" )
            ( "verbose,v", "more output; --help --verbose: more help message" )
            ( "config", boost::program_options::value< std::string >( &config_string ), "configuration file for the camera or semicolon-separated name=value string, run 'fire-cat -h -v' for more details" )
            ( "pin", boost::program_options::value< unsigned int >( &pin )->default_value( 0 ), "apply operation to the specified pin (default: 0)" )
            ( "direction", boost::program_options::value< std::string >( &direction ), "set pin direction to 'in' or 'out'" );
        boost::program_options::variables_map vm;
        boost::program_options::store( boost::program_options::parse_command_line( argc, argv, description), vm );
        boost::program_options::parsed_options parsed = boost::program_options::command_line_parser(argc, argv).options( description ).allow_unregistered().run();
        boost::program_options::notify( vm );
        if ( vm.count( "help" ) || vm.count( "verbose" ) )
        {
            std::cerr << "perform operations specific to point-grey cameras" << std::endl;
            std::cerr << "Usage: " << name() << " [options] \n" << std::endl;
            std::cerr << description << std::endl;
            std::cerr << std::endl;
            std::cerr << "examples:" << std::endl;
            std::cerr << "\tset direction of pin=2 to 'out': " << name() << " --config=bumblebee.config --pin=2 --direction=out" << std::endl;
            std::cerr << std::endl;
            return 1;
        }
        if( config_string.empty() ) { std::cerr << name() << ": --config is not given" << std::endl; return 1; }
        snark::camera::dc1394::config config;
        bool config_from_command_line = config_string.find_first_of( '=' ) != std::string::npos; // quick and dirty
        if( config_from_command_line )
        {
            config = comma::name_value::parser( ';', '=' ).get< snark::camera::dc1394::config >( config_string );
        }
        else
        {
            std::vector< std::string > v = comma::split( config_string, ':' );
            if( v.size() > 2 ) { std::cerr << name() << ": expected --config=filename or --config=filename:xpath, got '" << config_string << "'" << std::endl; return 1; }
            std::string filename = v[0];
            std::string xpath = ( v.size() == 1 ) ? "" : v[1];
            config = comma::read< snark::camera::dc1394::config >( filename, xpath.c_str() );
        }
        snark::camera::dc1394 camera( config );
        if( pin >= number_of_pins ) { std::cerr <<  name() << "expected pin to be from 0 to " << number_of_pins - 1 << ", got " << pin << std::endl; return 1; }
        if( vm.count( "direction" ) )
        {
            if( direction != "in" && direction != "out" ) { std::cerr << name() << ": expected direction to be either 'in' or 'out', got " << direction << std::endl; }
            set_pin_direction( camera, pin, ( direction == "out" ) );
        }
        return 0;
    }
    catch( std::exception& ex )
    {
        std::cerr << argv[0] << ": " << ex.what() << std::endl;
    }
    catch( ... )
    {
        std::cerr << argv[0] << ": unknown exception" << std::endl;
    }
    return 1;
}