Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (1.54 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 882 bneuman
/* column definitions
8
1: time
9
2: OCR1B (control)
10
3: current
11
4: voltage
12
5: temp
13
*/
14
15
16 266 bneuman
void recv(char i2c_byte){
17 410 bneuman
    static char str[8];
18
19
    if(code){
20
        if(next==0){
21
            byte = i2c_byte<<8; //get first byte in int
22
            next = 1;
23
        }
24
        else{
25
            byte |= i2c_byte; //get second byte in int
26
            itoa(byte,str,10);
27
28
            usb_puts(str);
29
            usb_putc('\t');
30
31
            if(code==2)
32
                usb_puts("\r\n"); //newline for easy to read output
33
34
            byte=0;
35
            code=0;
36
            next=0;
37
        }
38
    }
39
    else {
40
41
        //if the byte is a debug control then set code to 1, otherwise, print it
42
        switch(i2c_byte){
43
            case 'C':
44
            case 'P':
45
            case 'I':
46
            case 'V':
47
                code = 1;
48
                break;
49
            case 'T':
50
                code = 2; //T is last, put a newline after it
51
                break;
52
53
            default:
54
                usb_putc(i2c_byte);
55
                break;
56
        }
57
58
    }
59 383 bneuman
}
60 266 bneuman
61 410 bneuman
int main( void ){
62 266 bneuman
63
        dragonfly_init(ALL_ON);
64 383 bneuman
        sei();
65 410 bneuman
    code = 0;
66
    byte = 0;
67
    next = 0;
68 383 bneuman
        i2c_init(0x01, NULL, recv, NULL);
69 956 nhergert
        //i2c_init();
70
        char packet;
71
        char *get = &packet;
72
        usb_puts("init'd everything.\r\n");
73 266 bneuman
74 383 bneuman
        while(1) {
75 956 nhergert
                i2c_getpacket(get);
76
                recv(packet);
77 383 bneuman
                delay_ms(2000);
78
        }
79 267 bneuman
}