Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (1.36 KB)

1
#include <dragonfly_lib.h>
2
#include <i2c.h>
3

    
4
volatile uint32_t byte;
5
volatile short code, next;
6

    
7
void recv(char i2c_byte){
8
    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
}
51

    
52
int main( void ){
53

    
54
        dragonfly_init(ALL_ON);
55
        sei();
56
    code = 0;
57
    byte = 0;
58
    next = 0;
59
        i2c_init(0x01, NULL, recv, NULL);
60
        
61
        usb_puts("init'd everything.\r\n");
62
        
63
        while(1) {
64
                delay_ms(2000);
65
        }
66
}