void rob_serial_receive_ring_usb_comm (char * pBuffer, unsigned char size)
{
    vTaskSuspendAll();
    {
        serial_receive_ring (USB_COMM, pBuffer, size);
    }
    xTaskResumeAll();
}
Example #2
0
int main()
{
	clear();	// clear the LCD
	print("Send serial");
	lcd_goto_xy(0, 1);	// go to start of second LCD row
	print("or press B");

	// Set the baud rate to 9600 bits per second.  Each byte takes ten bit
	// times, so you can get at most 960 bytes per second at this speed.
	serial_set_baud_rate(USB_COMM, 9600);

	// Start receiving bytes in the ring buffer.
	serial_receive_ring(USB_COMM, receive_buffer, sizeof(receive_buffer));

    while(1)
    {
		// USB_COMM is always in SERIAL_CHECK mode, so we need to call this
		// function often to make sure serial receptions and transmissions
		// occur.
		serial_check();

		// Deal with any new bytes received.
		check_for_new_bytes_received();

		// If the user presses the middle button, send "Hi there!"
		// and wait until the user releases the button.
		if (button_is_pressed(MIDDLE_BUTTON))
		{
			wait_for_sending_to_finish();
			memcpy_P(send_buffer, PSTR("Hi there!\r\n"), 11);
			serial_send(USB_COMM, send_buffer, 11);
			send_buffer[11] = 0;	// terminate the string
			clear();				// clear the LCD
			lcd_goto_xy(0, 1);		// go to start of second LCD row
			print("TX: ");
			print(send_buffer);

			// Wait for the user to release the button.  While the processor is
			// waiting, the OrangutanSerial library will not be able to receive
			// bytes from the USB_COMM port since this requires calls to the
			// serial_check() function, which could cause serial bytes to be
			// lost.  It will also not be able to send any bytes, so the bytes
			// bytes we just queued for transmission will not be sent until
			// after the following blocking function exits once the button is
			// released.  If any of this is a concern, you can replace the
			// following line with:
			// do
			// {
			//   while (button_is_pressed(MIDDLE_BUTTON))
			//     serial_check();	// receive and transmit as needed
			//   delay_ms(10);		// debounce the button press/release
			// }
			// while (button_is_pressed(MIDDLE_BUTTON));
			wait_for_button_release(MIDDLE_BUTTON);
		}
    }
}
Example #3
0
void initialize()
{
	play_from_program_space(welcome);

#ifdef DEBUG
	// start receiving data at 9600 baud.
	serial_set_baud_rate(9600);
	serial_receive_ring(buffer, 100);
#endif

	// initialize your QTR sensors
	//  unsigned char qtr_rc_pins[] = {IO_C0, IO_C1, IO_C2};
//	unsigned char qtr_rc_pins[] = {IO_C0, IO_C1, IO_C2, IO_C3, IO_C4, IO_C5, IO_D7, IO_D4};
	unsigned char qtr_rc_pins[] = {IO_D4, IO_D7, IO_C5, IO_C4, IO_C3, IO_C2, IO_C1, IO_C0};
	qtr_rc_init(qtr_rc_pins, 8, 2000, IO_D2);  // 800 us timeout, emitter pin PD2

#ifdef DEBUG
	serial_send_blocking("Press Button A to start calibrating...\n", 39);
#endif
	wait_for_button_press(BUTTON_A);
	// Always wait for the button to be released so that the robot doesn't
	// start moving until your hand is away from it.
	wait_for_button_release(BUTTON_A);
	delay_ms(800);

	// then start calibration phase and move the sensors over both
	// reflectance extremes they will encounter in your application:
	// We use a value of 2000 for the timeout, which
	// corresponds to 2000*0.4 us = 0.8 ms on our 20 MHz processor.
	unsigned int counter; // used as a simple timer
	for(counter = 0; counter < 82; counter++)
	{
		if(counter < 20 || counter >= 60)
			set_motors(60,-60);
		else
			set_motors(-60,60);

		qtr_calibrate(QTR_EMITTERS_ON);

		// Since our counter runs to 80, the total delay will be
		// 80*20 = 1600 ms.
		delay_ms(20);
	}
	set_motors(0,0);

#ifdef DEBUG
	serial_send_blocking("Press Button A to start line following...\n", 42);
#endif
	wait_for_button_press(BUTTON_A);
	wait_for_button_release(BUTTON_A);
}
Example #4
0
/*
 * Initialize the menuing system
 */
int cli_init(void)
{
    // Set the baud rate to 9600 bits per second.  Each byte takes ten bit
    // times, so you can get at most 960 bytes per second at this speed.
    serial_set_baud_rate(USB_COMM, 9600);
    serial_set_mode(USB_COMM, SERIAL_CHECK);
    serial_receive_ring(
            USB_COMM, g_receive_buffer.ring_buffer,
            sizeof(g_receive_buffer.ring_buffer));
    LOG("USB Serial Initialized\r\n");
    LOG("#> ");
    CLI_REGISTER({"?", "Show Commands", clicmd_show_commands});
    return 0;
}
Example #5
0
void serial_init( )
{
	// Set the baud rate to 9600 bits per second.  Each byte takes ten bit
	// times, so you can get at most 960 bytes per second at this speed.
	serial_set_baud_rate(USB_COMM, 9600);

	// Start receiving bytes in the ring buffer.
	serial_receive_ring(USB_COMM, receive_buffer, sizeof(receive_buffer));
	
	memset( my_received_buffer, 0, sizeof(my_received_buffer));
	
	serial_print_string( "USB Serial Initialized" );
	serial_print_string( "" );
	print_menu();
}
Example #6
0
int s_read(char* buf, int want, int msecTimeout)
{
	static int ringNext = -1; // -1 means uninitialized
	static char ringBuffer[kBufSize]; // size must fit in unsigned char

	if (want <= 0 || buf == 0)
		return 0;

	int maxRead = kBufSize - 1;
	if (want > maxRead)
		want = maxRead;

	if (ringNext < 0)
	{
		serial_receive_ring(USB_COMM, ringBuffer, kBufSize);
		ringNext = 0;
	}

	int avail = 0;
	int done = 0;
	while (!done)
	{
		serial_check();
		int nbytes = serial_get_received_bytes(USB_COMM);
		avail = (nbytes - ringNext) & kSizeMask;
		if (avail > 0 || msecTimeout <= 0)
			done = 1;
		else
		{
			delay_ms(1);
			--msecTimeout;
		}
	}

	if (want > avail)
		want = avail;

	int got = 0;
	while (got < want)
	{
		buf[got++] = ringBuffer[ringNext++];
		ringNext &= kSizeMask;
	}

	return got;
}
Example #7
0
//------------------------------------------------------------------------------------------
// Initialize serial communication through USB and print menu options
// This immediately readies the board for serial comm
void init_menu() {
	
	//char printBuffer[32];
	
	// Set the baud rate to 9600 bits per second.  Each byte takes ten bit
	// times, so you can get at most 960 bytes per second at this speed.
	serial_set_baud_rate(USB_COMM, 9600);

	// Start receiving bytes in the ring buffer.
	serial_receive_ring(USB_COMM, receive_buffer, sizeof(receive_buffer));

	//memcpy_P( send_buffer, PSTR("USB Serial Initialized\r\n"), 24 );
	//snprintf( printBuffer, 24, "USB Serial Initialized\r\n");
	//print_usb( printBuffer, 24 );
	print_usb( "\r\n\nUSB Serial Initialized\r\n" );

	//memcpy_P( send_buffer, MENU, MENU_LENGTH );
	print_usb( MENU );
}
Example #8
0
/*==========la fonction main()=======*/
int main(void) {

    lcd_init_printf();
    pololu_3pi_init(2000);  
    play_mode(PLAY_CHECK);
    clear();
    print("Hello!");
    play("L16 ceg>c");
    // start receiving data at 9600 baud
    serial_set_baud_rate(9600);
    serial_receive_ring(buffer, 100);
      
    int i=0;
    char dirct,chaine[4], comp='C',*recuper = NULL, *ok;
    long val, veri=0;
    char command;
	/* la boucle qui permet de recuperer la trame caractere par caractere */
    while(1){
	
        for(i=0;i<4;i++){
            command = read_next_byte();
            if (command)
            {
                chaine[i] = command;
            }
        }
         /*recuperation de la lettre recu dans la trame */ 
        dirct = chaine[0];
        
        /*recuperation du reste de la trame en chaine de caractere */
        recuper = strchr(chaine,chaine[1]);
        
        /*conversion de cette chaine recuperer en entier (type long)*/
        val = strtol(recuper, &ok,10);
        
	    /* cette condition permet d'eviter l'execution de la meme trame plusieurs fois*/        
        if(dirct != comp || veri != val)
        {
        clear();
        printf("%s",chaine);
        switch(dirct)
        {
            case 'A':
                avancer(val);
                break;
            case 'R':
                reculer(val);
                break;
            case 'D':
                droit(val);
                break;
            case 'G':
                gauche(val);
                break;
            case 'M':
                melodie();
                break;
            default:
                set_motors(0,0);
                break;
            }
            comp = dirct;
            veri = val;
        }
    }
return 0;
}
Example #9
0
int main()
{
	pololu_3pi_init(2000);  
	play_mode(PLAY_CHECK);
	clear();

	// start receiving data at 115.2 kbaud
	serial_set_baud_rate(115200);
	serial_receive_ring(buffer, 100);

	while(1)
	{
		// wait for a command
		char command = read_next_byte();

		// The list of commands is below: add your own simply by
		// choosing a command byte and introducing another case
		// statement.
		switch(command)
		{
		case (char)0x00:
			// silent error - probable master resetting
			break;

		case (char)0x81:
			send_signature();
			break;
		case (char)0x86:
			send_raw_sensor_values();
			break;
		case (char)0x87:
			send_calibrated_sensor_values(1);
			break;
		case (char)0xB0:
			send_trimpot();
			break;
		case (char)0xB1:
			send_battery_millivolts();
			break;
		case (char)0xB3:
			do_play();
			break;
		case (char)0xB4:
			calibrate_line_sensors(IR_EMITTERS_ON);
			send_calibrated_sensor_values(1);
			break;
		case (char)0xB5:
			line_sensors_reset_calibration();
			break;
		case (char)0xB6:
			send_line_position();
			break;
		case (char)0xB7:
			do_clear();
			break;
		case (char)0xB8:
			do_print();
			break;
		case (char)0xB9:
			do_lcd_goto_xy();
			break;
		case (char)0xBA:
			auto_calibrate();
			break;
		case (char)0xBB:
			set_pid();
			break;
		case (char)0xBC:
			stop_pid();
			break;

		case (char)0xC1:
			m1_forward();
			break;
		case (char)0xC2:
			m1_backward();
			break;
		case (char)0xC5:
			m2_forward();
			break;
		case (char)0xC6:
			m2_backward();
			break;

		default:
			clear();
			print("Bad cmd");
			lcd_goto_xy(0,1);
			print_hex_byte(command);

			play("o7l16crc");
			continue; // bad command
		}
	}
}