Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (1.49 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

    
27
        if(type == ENCODER)
28
        { 
29
                if(id == -1)
30
                        id = source;
31
                if(source != id)
32
                        motor1_set(1, 200);
33
                usb_putc(packet[0]);
34
                usb_putc(packet[1]);
35
//                usb_putc(packet[2]);
36
//                usb_putc(packet[3]);
37
        }                                  
38
        
39
}
40

    
41
int main (void) {
42

    
43
        dragonfly_init(ALL_ON);
44
        wl_init();
45
        lcd_init();
46

    
47
        lcd_puts("STARTING");
48
        position = usb_getc();
49
        lcd_puts("position is ");
50
        lcd_puti(position);
51

    
52
        if(position == SENDER)
53
        {
54
                //Read in from server
55
                lcd_puts("starting init");
56
                data[0] = usb_getc(); 
57
                data[1] = usb_getc();
58
                //data[2] = usb_getc();
59
                //data[3] = usb_getc();
60
                
61
                lcd_puts("Done with init\n");
62

    
63
                wl_send_global_packet(GROUP, MOTOR, data, 2, 0);
64
        }
65
        else
66
        {
67
                wl_register_packet_group(&packetHandler);
68
        }
69

    
70
//        lcd_clear_screen();
71
  while (1) {
72
  if(position == SENDER)
73
  {
74
                data[0] = usb_getc(); 
75
                data[1] = usb_getc();
76
                //data[2] = usb_getc();
77
                //data[3] = usb_getc();
78
                wl_send_global_packet(GROUP, MOTOR, data, 2, 0);
79
        }        
80

    
81
          wl_do();
82
  }
83
  
84
}
85