Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (1.26 KB)

1 1197 ayeager
#include <dragonfly_lib.h>
2
#include <wireless.h>
3 1216 chihsiuh
//#include <termios.h>
4 1197 ayeager
#include <stdio.h>
5 1216 chihsiuh
//#include <unistd.h>
6 1197 ayeager
7
#define GROUP 1
8 1224 chihsiuh
#define MOTOR 0
9 1344 ayeager
#define ENCODER 132
10 1197 ayeager
11 1224 chihsiuh
#define SENDER 1
12
#define RECEIVER 0
13
14 1344 ayeager
int id = -1;
15 1216 chihsiuh
16 1344 ayeager
char data[2];
17
18 1222 chihsiuh
sentCount = 0;
19 1224 chihsiuh
char position = 0;
20 1222 chihsiuh
21 1344 ayeager
void packet_receive (char type, int source, char* packet, int length);
22 1197 ayeager
23
PacketGroupHandler packetHandler = {GROUP, 0, 0, &packet_receive, 0};
24
25 1344 ayeager
void packet_receive (char type, int source, char* packet, int length) {
26 1224 chihsiuh
        if(type == ENCODER)
27 1344 ayeager
        {
28
                if(id == -1)
29
                        id = source;
30
                if(source != id)
31
                        motor1_set(1, 200);
32 1224 chihsiuh
                usb_putc(packet[0]);
33
                usb_putc(packet[1]);
34 1344 ayeager
        }
35 1197 ayeager
}
36
37
int main (void) {
38 1224 chihsiuh
39 1216 chihsiuh
        dragonfly_init(ALL_ON);
40 1197 ayeager
        wl_init();
41 1216 chihsiuh
        lcd_init();
42
43 1224 chihsiuh
        lcd_puts("STARTING");
44
        position = usb_getc();
45
        lcd_puts("position is ");
46
        lcd_puti(position);
47 1216 chihsiuh
48 1224 chihsiuh
        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 1345 chihsiuh
55 1224 chihsiuh
                lcd_puts("Done with init\n");
56 1222 chihsiuh
57 1344 ayeager
                wl_send_global_packet(GROUP, MOTOR, data, 2, 0);
58 1224 chihsiuh
        }
59
        else
60
        {
61
                wl_register_packet_group(&packetHandler);
62
        }
63
64 1345 chihsiuh
        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 1224 chihsiuh
72 1345 chihsiuh
                wl_do();
73
        }
74
75 1197 ayeager
}