Project

General

Profile

Revision 1354

Added by Chris Mar over 10 years ago

adding keyboard remote control for testing...still in progress.

View differences:

slave.c
2 2
#include <wireless.h>
3 3
#include "../../../common/colonet_defs.h"
4 4

  
5
/* Command Types */
6
#define CNTL_FORWARD 'f'
7
#define CNTL_STOP    's'
8
#define CNTL_BACK    'b'
9
#define CNTL_LEFT    'l'
10
#define CNTL_RIGHT   'r'
11
#define CNTL_BUZZ0   't'
12
#define CNTL_BUZZ1   'u'
13

  
14
#define WL_CNTL_GROUP 4
15

  
5 16
void packet_receive (char type, int source, unsigned char* packet, int length);
6 17

  
7
PacketGroupHandler packetHandler = {4, NULL, NULL, &packet_receive, NULL};
18
PacketGroupHandler packetHandler = {WL_CNTL_GROUP, NULL, NULL, &packet_receive, NULL};
8 19

  
9 20
int main (void) {
10
  dragonfly_init(SERIAL | USB | COMM | ORB | ANALOG | MOTORS | BUZZER);
21
	dragonfly_init(SERIAL | USB | COMM | ORB | ANALOG | MOTORS | BUZZER);
11 22
	ADCSRA = _BV(ADEN) | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0);
12
	//xbee_init();
13 23
    wl_init();
14 24
    wl_register_packet_group(&packetHandler);
15 25
	orb_set_color(PURPLE);
16 26
  
17
  /*char buf[100];
18
  char c;*/
19
  while (1) {
20
    //usb_puts("entering while loop\n");
21
    wl_do();
22
//    c = xbee_getc();
23
//    orb_set_color(GREEN);
24
//    sprintf(buf, "got char: %c\n", c);
25
//    usb_puts(buf);
26
    
27
    /*if (c == 'f') {
28
      orb_set_color(GREEN);
29
      motor1_set(1, 250);
30
      motor2_set(1, 250);
31
    }
32
    if (c == 'b') {
33
      orb_set_color(BLUE);
34
      motor1_set(0, 250);
35
      motor2_set(0, 250);
36
    }
37
    if (c == 'l') {
38
      orb_set_color(ORANGE);
39
      motor1_set(0, 250);
40
      motor2_set(1, 250);
41
    }
42
    if (c == 'r') {
43
      orb_set_color(YELLOW);
44
      motor1_set(1, 250);
45
      motor2_set(0, 250);
46
    }
47
    if (c == 's') {
48
      orb_set_color(RED);
49
      motor1_set(0, 0);
50
      motor2_set(0, 0);
51
    }
52
    if (c == 't') {
53
      orb_set_color(PURPLE);
54
      buzzer_chirp(1000, C5);
55
    }
56
    if (c == 'u') {
57
      orb_set_color(YELLOW);
58
      buzzer_chirp(1000, A4);
59
    }
60
    
61
    delay_ms(100);*/
62
  }
63
  
27
  	while (1) {
28
    	wl_do();
29
    	delay_ms(100);
30
  	}
64 31
}
65 32

  
66 33
void packet_receive (char type, int source, unsigned char* packet, int length) {
67 34
    switch (type) {
68
        case 'f':
35
        case CNTL_FORWARD:
69 36
            orb_set_color(GREEN);
70 37
            motor1_set(1, 250);
71 38
            motor2_set(1, 250);
72 39
            break;
73
        case 's':
40
        case CNTL_STOP:
74 41
            orb_set_color(RED);
75 42
            motor1_set(0, 0);
76 43
            motor2_set(0, 0);
77 44
            break;
78
        case 'b':
45
        case CNTL_BACK:
79 46
            orb_set_color(BLUE);
80 47
            motor1_set(0, 250);
81 48
            motor2_set(0, 250);
82 49
            break;
83
        case 'l':
50
        case CNTL_LEFT:
84 51
            orb_set_color(ORANGE);
85 52
            motor1_set(0, 250);
86 53
            motor2_set(1, 250);
87 54
            break;
88
        case 'r':
55
        case CNTL_RIGHT:
89 56
            orb_set_color(YELLOW);
90 57
            motor1_set(1, 250);
91 58
            motor2_set(0, 250);
92 59
            break;
93
        case 't':
60
        case CNTL_BUZZ0:
94 61
            orb_set_color(PURPLE);
95 62
            buzzer_chirp(1000, C5);
96 63
            break;
97
        case 'u':
64
        case CNTL_BUZZ1:
98 65
            orb_set_color(YELLOW);
99 66
            buzzer_chirp(1000, A4);
100 67
            break;

Also available in: Unified diff