Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / diagnostic_station / station / main.c @ 1153

History | View | Annotate | Download (2.07 KB)

1
#include <dragonfly_lib.h>
2

    
3
#include "global.h"
4
#include "station_hardware.h"
5

    
6
#include "test_comm.h"
7
#include "test_bom.h"
8
#include "test_rangefinders.h"
9
#include "test_encoders.h"
10
#include "test_motors.h"
11

    
12
bool communication_ok=false;
13

    
14
bool require_comm (void)
15
{
16
        if (!communication_ok)
17
                communication_ok=test_comm ();
18

    
19
        if (!communication_ok)
20
                usb_puts ("Communications required. Stop." NL);
21

    
22
        return communication_ok;
23
}
24

    
25
void test_all (void)
26
{
27
        // test_all tests comm itself because we want to test comm, even if it
28
        // succeeded before (that's what test_all means).
29
        if (!test_comm ())
30
        {
31
                usb_puts ("Communications require. Stop." NL);
32
                return;
33
        }
34
        
35
        test_bom (true, true);
36
        test_rangefinders ();
37
        test_encoders ();
38
        test_motors ();
39
}
40

    
41
void interactive_main (void)
42
{
43
        while (1)
44
        {
45
                // Set the orbs to green/green
46
                orbs_set (0,255,0, 0,255,0);
47

    
48
                usb_puts (NL);
49
                usb_puts ("Diagnostic station interactive mode" NL);
50
                usb_puts ("Test (s)elf, (a)ll, (c)omm, (b)om, (r)angefinders, (e)ncoders, (m)otors" NL);
51

    
52
                char choice = usb_getc ();
53
                switch (choice) {
54
                        case 'c': case 'C': test_comm ();                               break;
55
                        case 'a': case 'A': test_all ();                                break; // test_all will test comm itself
56
                        case 'b': case 'B': if (require_comm ()) test_bom (true, true); break;
57
                        case 'r': case 'R': if (require_comm ()) test_rangefinders ();  break;
58
                        case 'e': case 'E': if (require_comm ()) test_encoders ();      break;
59
                        case 'm': case 'M': if (require_comm ()) test_motors ();        break;
60
                        case 's': case 'S': self_test ();                               break;
61
                        default: break; // ignore it
62
//                                usb_puts("Received invalid input ");
63
//                                usb_putc(choice);
64
//                                usb_puts(NL);
65
                }
66
        }
67
}
68

    
69
void server_main (void)
70
{
71
        // Set the orbs to green/yellow
72
        orbs_set (0,255,0, 255,127,0);
73

    
74
        while (1);
75
}
76

    
77
int main (void)
78
{
79
        dragonfly_init(0);
80
        usb_init ();
81
        orb_init ();
82

    
83
        usb_puts(NL NL NL);
84
        usb_puts("Diagnostic station version " version_string " starting" NL);
85
        hardware_init ();
86
        
87
        if (button2_read ())
88
                server_main ();
89
        else
90
                interactive_main ();
91

    
92
        while (1);
93
}