root / branches / autonomous_recharging / code / projects / autonomous_recharging / archs / Robot Debug / main.c @ 956
History | View | Annotate | Download (1.54 KB)
1 |
#include <dragonfly_lib.h> |
---|---|
2 |
#include <i2c.h> |
3 |
|
4 |
volatile uint32_t byte;
|
5 |
volatile short code, next; |
6 |
|
7 |
/* column definitions
|
8 |
1: time
|
9 |
2: OCR1B (control)
|
10 |
3: current
|
11 |
4: voltage
|
12 |
5: temp
|
13 |
*/
|
14 |
|
15 |
|
16 |
void recv(char i2c_byte){ |
17 |
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 |
} |
60 |
|
61 |
int main( void ){ |
62 |
|
63 |
dragonfly_init(ALL_ON); |
64 |
sei(); |
65 |
code = 0;
|
66 |
byte = 0;
|
67 |
next = 0;
|
68 |
i2c_init(0x01, NULL, recv, NULL); |
69 |
//i2c_init();
|
70 |
char packet;
|
71 |
char *get = &packet;
|
72 |
usb_puts("init'd everything.\r\n");
|
73 |
|
74 |
while(1) { |
75 |
i2c_getpacket(get); |
76 |
recv(packet); |
77 |
delay_ms(2000);
|
78 |
} |
79 |
} |