Project

General

Profile

Statistics
| Revision:

root / branches / encoders / code / behaviors / spline / master / master.c @ 1345

History | View | Annotate | Download (1.26 KB)

1
#include <dragonfly_lib.h>
2
#include <wireless.h>
3
//#include <termios.h>           
4
#include <stdio.h>
5
//#include <unistd.h>
6

    
7
#define GROUP 1
8
#define MOTOR 0
9
#define ENCODER 132
10

    
11
#define SENDER 1
12
#define RECEIVER 0
13

    
14
int id = -1;
15

    
16
char data[2];
17

    
18
sentCount = 0;
19
char position = 0;
20

    
21
void packet_receive (char type, int source, char* packet, int length);
22

    
23
PacketGroupHandler packetHandler = {GROUP, 0, 0, &packet_receive, 0};
24

    
25
void packet_receive (char type, int source, char* packet, int length) {
26
        if(type == ENCODER)
27
        { 
28
                if(id == -1)
29
                        id = source;
30
                if(source != id)
31
                        motor1_set(1, 200);
32
                usb_putc(packet[0]);
33
                usb_putc(packet[1]);
34
        }                                  
35
}
36

    
37
int main (void) {
38

    
39
        dragonfly_init(ALL_ON);
40
        wl_init();
41
        lcd_init();
42

    
43
        lcd_puts("STARTING");
44
        position = usb_getc();
45
        lcd_puts("position is ");
46
        lcd_puti(position);
47

    
48
        if(position == SENDER)
49
        {
50
                //Read in from server
51
                lcd_puts("starting init");
52
                data[0] = usb_getc(); 
53
                data[1] = usb_getc();
54

    
55
                lcd_puts("Done with init\n");
56

    
57
                wl_send_global_packet(GROUP, MOTOR, data, 2, 0);
58
        }
59
        else
60
        {
61
                wl_register_packet_group(&packetHandler);
62
        }
63

    
64
        while (1) {
65
                if(position == SENDER)
66
                {
67
                        data[0] = usb_getc(); 
68
                        data[1] = usb_getc();
69
                        wl_send_global_packet(GROUP, MOTOR, data, 2, 0);
70
                }        
71

    
72
                wl_do();
73
        }
74

    
75
}
76