root / trunk / code / projects / test / test_wireless.c @ 1427
History | View | Annotate | Download (3.02 KB)
1 |
/**
|
---|---|
2 |
* Instructions:
|
3 |
* - wait for both robots to show ORB 1 RED and ORB 2 GREEN
|
4 |
* - press BUTTON 1 on robot to send first (ROBOT 1) - orbs should turn PURPLE
|
5 |
* - press BUTTON 2 on robot to receive first (ROBOT 2) - orbs should turn ORANGE
|
6 |
* - wait at least a second, then press BUTTON 1 on both robots SIMULTANEOUSLY
|
7 |
* - ROBOT 2 orbs should cycle ORANGE to RED to BLUE
|
8 |
* - then ROBOT 1 orbs should cycle PURPLE to RED to BLUE
|
9 |
* - then orbs on both robots should turn GREEN
|
10 |
* - test will reset to ORB 1 RED and ORB 2 CYAN
|
11 |
* - test should take ~7 seconds
|
12 |
*
|
13 |
* Depends on:
|
14 |
* - Orbs (Lights)
|
15 |
* - Serial (for debugging)
|
16 |
**/
|
17 |
|
18 |
#include <dragonfly_lib.h> |
19 |
#include <wl_basic.h> |
20 |
|
21 |
unsigned char* packet; |
22 |
int length;
|
23 |
|
24 |
int testwireless(void) { |
25 |
int count = 0; |
26 |
int is_sender = 0; |
27 |
|
28 |
wl_basic_init_default(); |
29 |
wl_set_channel(0x0E);
|
30 |
|
31 |
orb1_set_color(RED); |
32 |
orb2_set_color(GREEN); |
33 |
delay_ms(500);
|
34 |
while (count < 1) { |
35 |
if (button1_click()) {
|
36 |
is_sender = 1;
|
37 |
orb_set_color(PURPLE); |
38 |
count++; |
39 |
} |
40 |
if (button2_click()) {
|
41 |
is_sender = 0;
|
42 |
orb_set_color(ORANGE); |
43 |
count++; |
44 |
} |
45 |
} |
46 |
count = 0;
|
47 |
|
48 |
delay_ms(1000);
|
49 |
|
50 |
button1_wait(); |
51 |
|
52 |
delay_ms(500);
|
53 |
|
54 |
if (is_sender == 1) { |
55 |
delay_ms(1000);
|
56 |
wl_basic_send_global_packet(1, "r", 2); |
57 |
usb_puts("sent RED packet\r\n");
|
58 |
delay_ms(1000);
|
59 |
wl_basic_send_global_packet(1, "b", 2); |
60 |
usb_puts("sent BLUE packet\r\n");
|
61 |
while(count < 2) { |
62 |
packet = wl_basic_do_default(&length); |
63 |
if (packet != 0) { |
64 |
if (length > 0) { |
65 |
if (packet[0] == 'r') { |
66 |
orb_set_color(RED); |
67 |
usb_puts("received RED packet\r\n");
|
68 |
count++; |
69 |
} |
70 |
else if (packet[0] == 'b') { |
71 |
orb_set_color(BLUE); |
72 |
usb_puts("received BLUE packet\r\n");
|
73 |
count++; |
74 |
} |
75 |
} |
76 |
} |
77 |
} |
78 |
} |
79 |
else {
|
80 |
while(count < 2) { |
81 |
packet = wl_basic_do_default(&length); |
82 |
if (packet != 0) { |
83 |
if (length > 0) { |
84 |
if (packet[0] == 'r') { |
85 |
orb_set_color(RED); |
86 |
usb_puts("received RED packet\r\n");
|
87 |
count++; |
88 |
} |
89 |
else if (packet[0] == 'b') { |
90 |
orb_set_color(BLUE); |
91 |
usb_puts("received BLUE packet\r\n");
|
92 |
count++; |
93 |
} |
94 |
} |
95 |
} |
96 |
} |
97 |
delay_ms(1000);
|
98 |
wl_basic_send_global_packet(1, "r", 2); |
99 |
usb_puts("sent RED packet\r\n");
|
100 |
delay_ms(1000);
|
101 |
wl_basic_send_global_packet(1, "b", 2); |
102 |
usb_puts("sent BLUE packet\r\n");
|
103 |
} |
104 |
delay_ms(1000);
|
105 |
|
106 |
wl_terminate(); |
107 |
|
108 |
orb_set_color(GREEN); |
109 |
|
110 |
delay_ms(2000);
|
111 |
|
112 |
return 0; |
113 |
} |
114 |
|