Revision 660
stop.c actually does what the folder title implies
It only looks at the homing data and the contact stuff and sends it to the robot
stop.c | ||
---|---|---|
1 | 1 |
#include<avr/io.h> |
2 |
#include <avr/interrupt.h> |
|
2 | 3 |
#include "i2c.h" |
3 | 4 |
|
4 | 5 |
#define LED1 PB4 //Green |
5 | 6 |
#define LED2 PB5 //Red |
6 | 7 |
|
8 |
// for i2c_byte coming from charge board |
|
9 |
//I2C Message Codes |
|
10 |
#define I2C_MSG_ACKNOWLEDGE 'A' |
|
11 |
#define I2C_MSG_BATTERY_CHARGING 'C' |
|
12 |
#define I2C_MSG_DATA 'D' |
|
13 |
#define I2C_MSG_CONTACT_ERROR 'E' |
|
14 |
#define I2C_MSG_BATTERY_FULL 'F' |
|
15 |
#define I2C_MSG_NO_CONTACT 'N' |
|
16 |
#define I2C_MSG_REQUEST_DATA 'R' |
|
17 |
#define I2C_MSG_GO_TO_SLEEP 'Y' |
|
18 |
#define I2C_MSG_ENTERING_SLEEP 'Z' |
|
19 |
#define I2C_MSG_HOMING 'H' |
|
20 |
|
|
21 |
|
|
22 |
#define SW0 PA6 |
|
23 |
#define HOMING_PIN PA7 |
|
24 |
|
|
25 |
uint8_t read_homing(void) |
|
26 |
{ |
|
27 |
uint8_t ret = PINA & _BV(HOMING_PIN); |
|
28 |
if(ret) |
|
29 |
PORTA |= _BV(PA3); |
|
30 |
else |
|
31 |
PORTA &= ~_BV(PA3); |
|
32 |
return ret; |
|
33 |
} |
|
34 |
|
|
35 |
uint8_t get_delay(void) |
|
36 |
{ |
|
37 |
uint8_t count = 0; |
|
38 |
|
|
39 |
PORTB|=_BV(LED2); |
|
40 |
while(read_homing()) |
|
41 |
{ |
|
42 |
delay_ms(1); |
|
43 |
count++; |
|
44 |
|
|
45 |
if (count >= 100) |
|
46 |
return 1; |
|
47 |
} //wait a beacon cycle to make sure we aren't starting the count in the middle of one |
|
48 |
PORTB&=~_BV(LED2); |
|
49 |
count = 0; |
|
50 |
PORTB|=_BV(LED1); |
|
51 |
while(!read_homing()) |
|
52 |
{ |
|
53 |
delay_ms(1); |
|
54 |
count++; |
|
55 |
if(count==255) |
|
56 |
return 2; |
|
57 |
} |
|
58 |
PORTB&=~_BV(LED1); |
|
59 |
|
|
60 |
/*RECH_PUTS("\n\rCount: "); |
|
61 |
RECH_PUTI(count); |
|
62 |
RECH_PUTC('.');*/ |
|
63 |
|
|
64 |
return count; |
|
65 |
} |
|
66 |
|
|
7 | 67 |
int main( void ) |
8 | 68 |
{ |
9 | 69 |
DDRB = _BV(PB0) | _BV(PB5) | _BV(PB4); |
... | ... | |
34 | 94 |
} |
35 | 95 |
else |
36 | 96 |
{ |
37 |
data[1]=I2C_MSG_NO_CONTACT; |
|
38 |
i2c_putpacket(0x01, data, 2); |
|
97 |
data[0]=I2C_MSG_NO_CONTACT; |
|
98 |
|
|
99 |
get_delay(); //reject the first reading //homing import stuff, uncomment this!!!!!! |
|
100 |
data[1]=I2C_MSG_HOMING; |
|
101 |
data[2]=get_delay(); |
|
102 |
i2c_putpacket(0x01, data, 3); |
|
39 | 103 |
} |
40 | 104 |
} |
41 | 105 |
|
Also available in: Unified diff