Revision 1345
Final spline code for master/slave
updated outdated libdragonfly and libwireless
dragonfly_lib.c | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (c) 2007 Colony Project |
|
3 |
* |
|
4 |
* Permission is hereby granted, free of charge, to any person |
|
5 |
* obtaining a copy of this software and associated documentation |
|
6 |
* files (the "Software"), to deal in the Software without |
|
7 |
* restriction, including without limitation the rights to use, |
|
8 |
* copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
9 |
* copies of the Software, and to permit persons to whom the |
|
10 |
* Software is furnished to do so, subject to the following |
|
11 |
* conditions: |
|
12 |
* |
|
13 |
* The above copyright notice and this permission notice shall be |
|
14 |
* included in all copies or substantial portions of the Software. |
|
15 |
* |
|
16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
18 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
19 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
20 |
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
21 |
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
22 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
23 |
* OTHER DEALINGS IN THE SOFTWARE. |
|
24 |
**/ |
|
25 |
|
|
26 |
|
|
27 |
/** |
|
28 |
* @file dragonfly_lib.c |
|
29 |
* @brief Dragonfly initialization |
|
30 |
* |
|
31 |
* Contains implementation of dragonfly_init. |
|
32 |
* |
|
33 |
* @author Colony Project, CMU Robotics Club |
|
34 |
**/ |
|
35 |
|
|
1 | 36 |
#include <dragonfly_lib.h> |
2 | 37 |
|
3 | 38 |
/* init_dragonfly - Initializes functions based on configuration parameters |
... | ... | |
27 | 62 |
* @see analog_init, usb_init, xbee_init, buzzer_init, |
28 | 63 |
* bom_init, orb_init, motors_init, lcd_init |
29 | 64 |
**/ |
65 |
|
|
66 |
void flash_red(void); |
|
67 |
|
|
30 | 68 |
void dragonfly_init(int config) |
31 | 69 |
{ |
32 |
// Set directionality of various IO pins |
|
33 |
DDRG &= ~(_BV(PING0)|_BV(PING1)); |
|
34 |
PORTG |= _BV(PING0)|_BV(PING1); |
|
35 |
|
|
36 |
if(config & ANALOG) { |
|
37 |
analog_init(); |
|
38 |
} |
|
39 |
|
|
40 |
if(config & COMM) { |
|
41 |
//Defaults to 115200. Check serial.h for more information. |
|
42 | 70 |
sei(); |
43 |
usb_init(); |
|
44 |
xbee_init(); |
|
45 |
} |
|
46 |
|
|
47 |
if(config & BUZZER) { |
|
48 |
sei(); |
|
49 |
buzzer_init(); |
|
50 |
} |
|
51 |
|
|
52 |
if(config & ORB) { |
|
53 |
sei(); |
|
54 |
orb_init(); |
|
55 |
} |
|
56 |
|
|
57 |
if(config & MOTORS) { |
|
58 |
motors_init(); |
|
59 |
} |
|
60 |
|
|
61 |
if(config & SERVOS) { |
|
62 |
sei(); |
|
63 |
//Servos not yet implemented |
|
64 |
//servo_init(); |
|
65 |
} |
|
71 |
// Set directionality of various IO pins |
|
72 |
DDRG &= ~(_BV(PING0)|_BV(PING1)); |
|
73 |
PORTG |= _BV(PING0)|_BV(PING1); |
|
74 |
|
|
75 |
if(config & ANALOG) |
|
76 |
analog_init(ADC_START); |
|
77 |
|
|
78 |
if(config & COMM) |
|
79 |
{ |
|
80 |
//Defaults to 115200. Check serial.h for more information. |
|
81 |
usb_init(); |
|
82 |
xbee_init(); |
|
83 |
} |
|
84 |
|
|
85 |
if(config & BUZZER) |
|
86 |
{ |
|
87 |
sei(); |
|
88 |
buzzer_init(); |
|
89 |
} |
|
90 |
|
|
91 |
if(config & ORB) |
|
92 |
{ |
|
93 |
sei(); |
|
94 |
orb_init(); |
|
95 |
} |
|
96 |
|
|
97 |
if(config & MOTORS) |
|
98 |
motors_init(); |
|
66 | 99 |
|
67 |
if(config & LCD) { |
|
68 |
lcd_init(); |
|
69 |
} |
|
70 |
|
|
71 |
if(config & (SERVOS | ORB)) { |
|
100 |
if(config & LCD) |
|
101 |
lcd_init(); |
|
102 |
|
|
103 |
if(config & RANGE) |
|
104 |
range_init(); |
|
105 |
|
|
106 |
if(config & BOM) |
|
107 |
{ |
|
108 |
unsigned char bom_read = get_bom_type(); |
|
109 |
if(bom_read == 0xFF) |
|
110 |
//warn that bom initialization failed |
|
111 |
flash_red(); |
|
112 |
else |
|
113 |
bom_init(bom_read); |
|
114 |
} |
|
115 |
// delay a bit for stability |
|
116 |
_delay_ms(1); |
|
117 |
} |
|
118 |
|
|
119 |
//flash lights red three times and restore ports |
|
120 |
void flash_red(void) |
|
121 |
{ |
|
122 |
cli(); |
|
123 |
char dd = DDRC; |
|
124 |
char po = PORTC; |
|
125 |
char i; |
|
126 |
DDRC = 0x77; |
|
127 |
for(i = 0; i<3; i++) |
|
128 |
{ |
|
129 |
PORTC = 0x77; |
|
130 |
delay_ms(300); |
|
131 |
PORTC = 0x66; |
|
132 |
delay_ms(300); |
|
133 |
} |
|
134 |
|
|
135 |
DDRC = dd; |
|
136 |
PORTC = po; |
|
72 | 137 |
sei(); |
73 |
orb_init(); |
|
74 |
//Servos not yet implemented |
|
75 |
} |
|
76 |
|
|
77 |
// delay a bit for stability |
|
78 |
_delay_ms(1); |
|
79 | 138 |
} |
80 |
|
|
81 |
|
|
82 | 139 |
/** @} **/ //end defgroup |
83 | 140 |
|
Also available in: Unified diff