Revision 2011
Some fixes to forklift demo, and added most recent forklift code to warehouse project.
Forklift.cpp | ||
---|---|---|
1 |
#define USE_ALT_TWI // an alternative to libdragonfly's i2c code, in twi.cpp |
|
2 |
|
|
1 | 3 |
#include "Forklift.h" |
2 | 4 |
extern "C" |
3 | 5 |
{ |
4 |
#include "i2c.h" |
|
5 | 6 |
#include <util/delay.h> |
6 | 7 |
} |
7 | 8 |
|
9 |
#ifdef USE_ALT_TWI |
|
10 |
# include "twi.h" |
|
11 |
#else |
|
12 |
extern "C" |
|
13 |
{ |
|
14 |
# include "i2c.h" |
|
15 |
} |
|
16 |
#endif |
|
17 |
|
|
8 | 18 |
#define SCOUT_AVR_ADDR 0x01 |
9 | 19 |
|
10 | 20 |
#define FORKLIFT_ADDR 0x41 |
... | ... | |
20 | 30 |
|
21 | 31 |
#define FORKLIFT_DATA_LEN 7 |
22 | 32 |
|
23 |
using namespace Forklift; |
|
24 |
|
|
25 | 33 |
char volatile response; |
26 | 34 |
char volatile received; |
27 | 35 |
|
... | ... | |
37 | 45 |
|
38 | 46 |
static int read_addr(char addr) |
39 | 47 |
{ |
48 |
#ifdef USE_ALT_TWI |
|
49 |
return FORKLIFT_ERROR; |
|
50 |
#else |
|
40 | 51 |
if (i2c_send(FORKLIFT_ADDR, &addr, 1)) |
41 | 52 |
return FORKLIFT_ERROR; |
42 | 53 |
received = 0; |
... | ... | |
49 | 60 |
return response; |
50 | 61 |
} |
51 | 62 |
return FORKLIFT_ERROR; |
63 |
#endif |
|
52 | 64 |
} |
53 | 65 |
|
54 | 66 |
static int write_addr(char addr, char data) |
... | ... | |
56 | 68 |
char buf[2]; |
57 | 69 |
buf[0] = addr; |
58 | 70 |
buf[1] = data; |
71 |
#ifdef USE_ALT_TWI |
|
72 |
if (twi_writeTo(FORKLIFT_ADDR, (uint8_t*) buf, 2, 1)) |
|
73 |
return FORKLIFT_ERROR; |
|
74 |
#else |
|
59 | 75 |
if (i2c_send(FORKLIFT_ADDR, buf, 2)) |
60 | 76 |
return FORKLIFT_ERROR; |
61 |
else
|
|
62 |
return 0;
|
|
77 |
#endif
|
|
78 |
return 0; |
|
63 | 79 |
} |
64 | 80 |
|
65 | 81 |
void Forklift::forklift_init() |
66 | 82 |
{ |
83 |
#ifdef USE_ALT_TWI |
|
84 |
twi_init(); |
|
85 |
twi_setAddress(SCOUT_AVR_ADDR); |
|
86 |
#else |
|
67 | 87 |
i2c_init(SCOUT_AVR_ADDR, mrecv, srecv, ssend); |
88 |
#endif |
|
68 | 89 |
} |
69 | 90 |
|
70 | 91 |
int Forklift::get_tracking_id() |
Also available in: Unified diff