void main(void) { init(); nx_systick_wait_ms(5000); /* vDisplaySensorsValues(); U32 pos1=0; U32 pos2=0; vForwardStop(&pos1,&pos2,500); nx_systick_wait_ms(1000); vTurnRight(&pos1,&pos2); nx_systick_wait_ms(1000); vForwardStop(&pos1,&pos2,250); nx_systick_wait_ms(1000); vTurnLeft(&pos1,&pos2); nx_systick_wait_ms(1000); vForwardStop(&pos1,&pos2,250); nx_systick_wait_ms(1000); vTurnRight(&pos1,&pos2); nx_systick_wait_ms(1000); vForwardStop(&pos1,&pos2,250); nx_systick_wait_ms(1000); vTurnRight(&pos1,&pos2); nx_systick_wait_ms(1000); vForwardStop(&pos1,&pos2,500); nx_systick_wait_ms(1000); vTurnRight(&pos1,&pos2); nx_systick_wait_ms(1000); vForwardStop(&pos1,&pos2,250); nx_systick_wait_ms(1000); vTurnLeft(&pos1,&pos2); nx_systick_wait_ms(1000); vForwardStop(&pos1,&pos2,250); */ nx_display_cursor_set_pos(0, 5); nx_display_string("en attente"); while (!quit) { if (!nx_bt_stream_opened() || nx_bt_connection_pending()) bt_wait_connection(); else { nx_sound_freq(DO, 200); nx_sound_freq(DO, 200); nx_sound_freq(DO, 200); handle_cmd(); } } die(); }
void tests_bt(void) { U16 i; U16 lng = 0; int port_handle __attribute__ ((unused)); int connection_handle = -1; int bleh = -1; char buffer[BT_PACKET_SIZE]; port_handle = -1; for (i = 0 ; i < BT_PACKET_SIZE ; i++) buffer[i] = 0; lng = 0; nx_bt_init(); hello(); nx_display_cursor_set_pos(0, 0); nx_display_string("Setting discoverable ..."); nx_bt_set_friendly_name("Tulipe"); nx_bt_set_discoverable(TRUE); port_handle = nx_bt_open_port(); nx_display_clear(); nx_display_cursor_set_pos(0, 0); nx_display_string("Waiting connection ..."); while(TRUE) { for (i = 0 ; i < 800 && (!nx_bt_stream_opened() || nx_bt_stream_data_read() < 2); i++) { if (connection_handle >= 0) { nx_display_cursor_set_pos(0, 2); nx_display_string("Waiting command ..."); } if (nx_bt_has_dev_waiting_for_pin()) { nx_bt_send_pin("1234"); } else if (nx_bt_connection_pending()) { nx_bt_accept_connection(TRUE); while ( (bleh = nx_bt_connection_established()) < 0) nx_systick_wait_ms(100); connection_handle = bleh; nx_bt_debug(); nx_bt_stream_open(connection_handle); nx_bt_debug(); nx_bt_stream_read((U8 *)&buffer, 2); /* we read the packet size first */ nx_display_cursor_set_pos(0, 4); } nx_bt_debug(); nx_systick_wait_ms(100); } if (!nx_bt_stream_opened() || i >= 800) break; lng = buffer[0] + (buffer[1] << 8); nx_display_clear(); nx_display_cursor_set_pos(0, 0); nx_display_string("Reading ..."); nx_display_cursor_set_pos(0, 1); nx_display_uint(lng); nx_bt_stream_read((U8 *)&buffer, lng); for(i = 0; nx_bt_stream_opened() && nx_bt_stream_data_read() < lng && i < 100; i++) nx_systick_wait_ms(100); if (!nx_bt_stream_opened() || i >= 100) break; /* Start interpreting */ i = tests_command(buffer); nx_bt_stream_read((U8 *)&buffer, 2); if (i == 2) { break; } /* if (i == 1) { nx_bt_stream_write((U8 *)CMD_UNKNOWN, sizeof(CMD_UNKNOWN)-1); } if (i == 0) { nx_bt_stream_write((U8 *)CMD_OK, sizeof(CMD_OK)-1); } */ nx_systick_wait_ms(100); nx_display_clear(); } if (nx_bt_stream_opened()) nx_bt_stream_close(); nx_systick_wait_ms(1000); nx_bt_debug(); goodbye(); }