root / trunk / code / projects / diagnostic_station / station / main.c @ 1159
History | View | Annotate | Download (2.35 KB)
1 |
#include <dragonfly_lib.h> |
---|---|
2 |
#include <wireless.h> |
3 |
#include <xbee.h> |
4 |
|
5 |
#include "../common/comm_station_robot.h" |
6 |
|
7 |
#include "global.h" |
8 |
#include "station_hardware.h" |
9 |
|
10 |
#include "test_comm.h" |
11 |
#include "test_bom.h" |
12 |
#include "test_rangefinders.h" |
13 |
#include "test_motors.h" |
14 |
#include "test_encoders.h" |
15 |
|
16 |
bool communication_ok=false; |
17 |
|
18 |
bool require_comm (void) |
19 |
{ |
20 |
if (!communication_ok)
|
21 |
communication_ok=test_comm (); |
22 |
|
23 |
if (!communication_ok)
|
24 |
usb_puts ("Communications required. Stop." NL);
|
25 |
|
26 |
return communication_ok;
|
27 |
} |
28 |
|
29 |
void test_all (void) |
30 |
{ |
31 |
// test_all tests comm itself because we want to test comm, even if it
|
32 |
// succeeded before (that's what test_all means).
|
33 |
if (!test_comm ())
|
34 |
{ |
35 |
usb_puts ("Communications require. Stop." NL);
|
36 |
return;
|
37 |
} |
38 |
|
39 |
test_bom (true, true); |
40 |
test_rangefinders (); |
41 |
test_encoders (); |
42 |
test_motors (); |
43 |
} |
44 |
|
45 |
void interactive_main (void) |
46 |
{ |
47 |
while (1) |
48 |
{ |
49 |
// Set the orbs to green/green
|
50 |
orbs_set (0,255,0, 0,255,0); |
51 |
|
52 |
usb_puts (NL); |
53 |
usb_puts ("Diagnostic station interactive mode" NL);
|
54 |
usb_puts ("Test (s)elf, (a)ll, (c)omm, (b)om, (r)angefinders, (m)otors, (e)ncoders" NL);
|
55 |
|
56 |
char choice = usb_getc ();
|
57 |
switch (choice) {
|
58 |
case 'c': case 'C': test_comm (); break; |
59 |
case 'a': case 'A': test_all (); break; // test_all will test comm itself |
60 |
case 'b': case 'B': if (require_comm ()) test_bom (true, true); break; |
61 |
case 'r': case 'R': if (require_comm ()) test_rangefinders (); break; |
62 |
case 'm': case 'M': if (require_comm ()) test_motors (); break; |
63 |
case 'e': case 'E': if (require_comm ()) test_encoders (); break; |
64 |
case 's': case 'S': self_test (); break; |
65 |
default: break; // ignore it |
66 |
// usb_puts("Received invalid input ");
|
67 |
// usb_putc(choice);
|
68 |
// usb_puts(NL);
|
69 |
} |
70 |
} |
71 |
} |
72 |
|
73 |
void server_main (void) |
74 |
{ |
75 |
// Set the orbs to green/yellow
|
76 |
orbs_set (0,255,0, 255,127,0); |
77 |
|
78 |
while (1); |
79 |
} |
80 |
|
81 |
int main (void) |
82 |
{ |
83 |
#include <dragonfly_lib.h> |
84 |
#include <wireless.h> |
85 |
|
86 |
dragonfly_init(0);
|
87 |
|
88 |
usb_init (); |
89 |
|
90 |
usb_puts(NL NL NL); |
91 |
usb_puts("Diagnostic station version " version_string " starting" NL); |
92 |
|
93 |
orb_init_pwm (); |
94 |
hardware_init (); |
95 |
|
96 |
orb1_set (255, 0, 0); usb_puts("Initializing wireless" NL); |
97 |
xbee_init (); |
98 |
wl_init(); |
99 |
orb2_set (255, 0, 0); usb_puts("Done" NL); |
100 |
|
101 |
if (button2_read ())
|
102 |
server_main (); |
103 |
else
|
104 |
interactive_main (); |
105 |
|
106 |
while (1); |
107 |
} |