Project

General

Profile

Statistics
| Revision:

root / branches / autonomous_recharging / code / projects / autonomous_recharging / archs / Robot Debug / main.c @ 762

History | View | Annotate | Download (1.37 KB)

1 266 bneuman
#include <dragonfly_lib.h>
2
#include <i2c.h>
3
4 410 bneuman
volatile uint32_t byte;
5
volatile short code, next;
6
7 266 bneuman
void recv(char i2c_byte){
8 410 bneuman
    static char str[8];
9
10
    if(code){
11
        if(next==0){
12
            byte = i2c_byte<<8; //get first byte in int
13
            next = 1;
14
        }
15
        else{
16
            byte |= i2c_byte; //get second byte in int
17
            itoa(byte,str,10);
18
19
            usb_puts(str);
20
            usb_putc('\t');
21
22
            if(code==2)
23
                usb_puts("\r\n"); //newline for easy to read output
24
25
            byte=0;
26
            code=0;
27
            next=0;
28
        }
29
    }
30
    else {
31
32
        //if the byte is a debug control then set code to 1, otherwise, print it
33
        switch(i2c_byte){
34
            case 'C':
35
            case 'P':
36
            case 'I':
37
            case 'V':
38
                code = 1;
39
                break;
40
            case 'T':
41
                code = 2; //T is last, put a newline after it
42
                break;
43
44
            default:
45
                usb_putc(i2c_byte);
46
                break;
47
        }
48
49
    }
50 383 bneuman
}
51 266 bneuman
52 410 bneuman
int main( void ){
53 266 bneuman
54
        dragonfly_init(ALL_ON);
55 383 bneuman
        sei();
56 410 bneuman
    code = 0;
57
    byte = 0;
58
    next = 0;
59 383 bneuman
        i2c_init(0x01, NULL, recv, NULL);
60 266 bneuman
61 762 bneuman
        //usb_puts("init'd everything.\r\n");
62 266 bneuman
63 383 bneuman
        while(1) {
64
                delay_ms(2000);
65
        }
66 267 bneuman
}