root / trunk / code / projects / test / test_wireless.c @ 1426
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 |
|
23 |
int testwireless(void) { |
24 |
int count = 0; |
25 |
int is_sender = 0; |
26 |
|
27 |
wl_basic_init_default(); |
28 |
wl_set_channel(0x0E);
|
29 |
|
30 |
orb1_set_color(RED); |
31 |
orb2_set_color(GREEN); |
32 |
delay_ms(500);
|
33 |
while (count < 1) { |
34 |
if (button1_click()) {
|
35 |
is_sender = 1;
|
36 |
orb_set_color(PURPLE); |
37 |
count++; |
38 |
} |
39 |
if (button2_click()) {
|
40 |
is_sender = 0;
|
41 |
orb_set_color(ORANGE); |
42 |
count++; |
43 |
} |
44 |
} |
45 |
count = 0;
|
46 |
|
47 |
delay_ms(1000);
|
48 |
|
49 |
button1_wait(); |
50 |
|
51 |
delay_ms(500);
|
52 |
|
53 |
if (is_sender == 1) { |
54 |
delay_ms(1000);
|
55 |
wl_basic_send_global_packet(1, "r", 2); |
56 |
usb_puts("sent RED packet\r\n");
|
57 |
delay_ms(1000);
|
58 |
wl_basic_send_global_packet(1, "b", 2); |
59 |
usb_puts("sent BLUE packet\r\n");
|
60 |
while(count < 2) { |
61 |
packet = wl_basic_do_default(); |
62 |
if (packet != 0) { |
63 |
if (current_packet.length > 0) { |
64 |
if (packet[0] == 'r') { |
65 |
orb_set_color(RED); |
66 |
usb_puts("received RED packet\r\n");
|
67 |
count++; |
68 |
} |
69 |
else if (packet[0] == 'b') { |
70 |
orb_set_color(BLUE); |
71 |
usb_puts("received BLUE packet\r\n");
|
72 |
count++; |
73 |
} |
74 |
} |
75 |
} |
76 |
} |
77 |
} |
78 |
else {
|
79 |
while(count < 2) { |
80 |
packet = wl_basic_do_default(); |
81 |
if (packet != 0) { |
82 |
if (current_packet.length > 0) { |
83 |
if (packet[0] == 'r') { |
84 |
orb_set_color(RED); |
85 |
usb_puts("received RED packet\r\n");
|
86 |
count++; |
87 |
} |
88 |
else if (packet[0] == 'b') { |
89 |
orb_set_color(BLUE); |
90 |
usb_puts("received BLUE packet\r\n");
|
91 |
count++; |
92 |
} |
93 |
} |
94 |
} |
95 |
} |
96 |
delay_ms(1000);
|
97 |
wl_basic_send_global_packet(1, "r", 2); |
98 |
usb_puts("sent RED packet\r\n");
|
99 |
delay_ms(1000);
|
100 |
wl_basic_send_global_packet(1, "b", 2); |
101 |
usb_puts("sent BLUE packet\r\n");
|
102 |
} |
103 |
delay_ms(1000);
|
104 |
|
105 |
wl_terminate(); |
106 |
|
107 |
orb_set_color(GREEN); |
108 |
|
109 |
delay_ms(2000);
|
110 |
|
111 |
return 0; |
112 |
} |
113 |
|