Revision 1543
Added a bunch of debug prints to the library
branches/init_refactor/code/projects/libdragonfly/motor.c | ||
---|---|---|
56 | 56 |
**/ |
57 | 57 |
int motors_init( void ) { |
58 | 58 |
|
59 |
if(motors_initd) |
|
59 |
if(motors_initd) { |
|
60 |
DRAGONFLY_DEBUG_PRINT("ERROR: motors already init'd\r\n"); |
|
60 | 61 |
return ERROR_INIT_ALREADY_INITD; |
62 |
} |
|
61 | 63 |
|
62 | 64 |
|
63 | 65 |
// Configure counter such that we use phase correct |
... | ... | |
92 | 94 |
* @see motor_r_set, motors_init |
93 | 95 |
**/ |
94 | 96 |
int motor_l_set(int direction, int speed) { |
95 |
if(!motors_initd) |
|
97 |
if(!motors_initd) { |
|
98 |
DRAGONFLY_DEBUG_PRINT("ERROR: motors not init'd\r\n"); |
|
96 | 99 |
return ERROR_LIBRARY_NOT_INITD; |
100 |
} |
|
97 | 101 |
|
98 | 102 |
if(direction == 0) { |
99 | 103 |
// turn off PWM first if switching directions |
... | ... | |
131 | 135 |
* @see motor_l_set, motors_init |
132 | 136 |
**/ |
133 | 137 |
int motor_r_set(int direction, int speed) { |
134 |
if(!motors_initd) |
|
138 |
if(!motors_initd) { |
|
139 |
DRAGONFLY_DEBUG_PRINT("ERROR: encoders not init'd\r\n"); |
|
135 | 140 |
return ERROR_LIBRARY_NOT_INITD; |
141 |
} |
|
136 | 142 |
|
137 | 143 |
if(direction == 0) { |
138 | 144 |
// PORTD |= 0x20; |
... | ... | |
198 | 204 |
* @see motors_init |
199 | 205 |
**/ |
200 | 206 |
int motors_off( void ) { |
201 |
if(!motors_initd) |
|
207 |
if(!motors_initd) { |
|
208 |
DRAGONFLY_DEBUG_PRINT("ERROR: encoders not init'd\r\n"); |
|
202 | 209 |
return ERROR_LIBRARY_NOT_INITD; |
210 |
} |
|
203 | 211 |
|
204 | 212 |
OCR1AL = 0x0; |
205 | 213 |
OCR1BL = 0x0; |
branches/init_refactor/code/projects/libdragonfly/dragonfly_lib.c | ||
---|---|---|
69 | 69 |
{ |
70 | 70 |
int ret = 0; |
71 | 71 |
|
72 |
DRAGONFLY_DEBUG_PRINT("in dragonfly_init\r\n"); |
|
73 |
|
|
72 | 74 |
sei(); |
73 | 75 |
// Set directionality of various IO pins |
74 | 76 |
DDRG &= ~(_BV(PING0)|_BV(PING1)); |
75 | 77 |
PORTG |= _BV(PING0)|_BV(PING1); |
76 | 78 |
|
77 | 79 |
if(config & ANALOG) { |
78 |
analog_init(ADC_START); |
|
80 |
if((ret = analog_init(ADC_START))) { |
|
81 |
DRAGONFLY_DEBUG_PRINT("analog_init returned "); |
|
82 |
DRAGONFLY_DEBUG_PRINT_INT(ret); |
|
83 |
DRAGONFLY_DEBUG_PRINT_STR("\r\n"); |
|
84 |
} |
|
85 |
/*TODO: return error already init'd or maybe something else if |
|
86 |
one of these inits returns that? */ |
|
79 | 87 |
} |
80 | 88 |
|
81 | 89 |
if(config & COMM) |
82 | 90 |
{ |
83 | 91 |
//Defaults to 115200. Check serial.h for more information. |
84 |
usb_init(); |
|
85 |
xbee_init(); |
|
92 |
if((ret = usb_init())) { |
|
93 |
DRAGONFLY_DEBUG_PRINT("usb_init returned "); |
|
94 |
DRAGONFLY_DEBUG_PRINT_INT(ret); |
|
95 |
DRAGONFLY_DEBUG_PRINT_STR("\r\n"); |
|
96 |
} |
|
97 |
if((ret = xbee_init())) { |
|
98 |
DRAGONFLY_DEBUG_PRINT("xbee_init returned "); |
|
99 |
DRAGONFLY_DEBUG_PRINT_INT(ret); |
|
100 |
DRAGONFLY_DEBUG_PRINT_STR("\r\n"); |
|
101 |
} |
|
86 | 102 |
} |
87 | 103 |
|
88 | 104 |
if(config & BUZZER) |
89 | 105 |
{ |
90 |
sei();
|
|
91 |
buzzer_init();
|
|
106 |
//sei(); This is already done above
|
|
107 |
buzzer_init(); |
|
92 | 108 |
} |
93 | 109 |
|
94 | 110 |
if(config & ORB) |
95 | 111 |
{ |
96 |
sei();
|
|
97 |
orb_init();
|
|
112 |
//sei(); This is already done above
|
|
113 |
orb_init(); |
|
98 | 114 |
} |
99 | 115 |
|
100 |
if(config & MOTORS) |
|
101 |
motors_init(); |
|
116 |
if(config & MOTORS) { |
|
117 |
if((ret = motors_init())) { |
|
118 |
DRAGONFLY_DEBUG_PRINT("motors_init returned "); |
|
119 |
DRAGONFLY_DEBUG_PRINT_INT(ret); |
|
120 |
DRAGONFLY_DEBUG_PRINT_STR("\r\n"); |
|
121 |
} |
|
122 |
} |
|
102 | 123 |
|
103 |
if(config & LCD) |
|
104 |
lcd_init(); |
|
124 |
if(config & LCD) { |
|
125 |
lcd_init(); |
|
126 |
} |
|
105 | 127 |
|
106 |
if(config & RANGE) |
|
107 |
range_init(); |
|
128 |
if(config & RANGE) { |
|
129 |
|
|
130 |
if((ret = range_init())) { |
|
131 |
DRAGONFLY_DEBUG_PRINT("range_init returned "); |
|
132 |
DRAGONFLY_DEBUG_PRINT_INT(ret); |
|
133 |
DRAGONFLY_DEBUG_PRINT_STR("\r\n"); |
|
134 |
} |
|
135 |
} |
|
108 | 136 |
|
109 | 137 |
if(config & BOM) |
110 | 138 |
{ |
111 | 139 |
unsigned char bom_read = get_bom_type(); |
140 |
DRAGONFLY_DEBUG_PRINT("Got BOM type "); |
|
141 |
DRAGONFLY_DEBUG_PRINT_INT(bom_read); |
|
142 |
DRAGONFLY_DEBUG_PRINT_STR("\r\n"); |
|
143 |
|
|
112 | 144 |
if(bom_read == 0xFF) { |
113 |
//warn that bom initialization failed |
|
114 |
flash_red(); |
|
115 |
return ERROR_INIT_FAILED; |
|
145 |
//warn that bom initialization failed |
|
146 |
DRAGONFLY_DEBUG_PRINT("WARNING: invalid BOM type!\r\n"); |
|
147 |
flash_red(); |
|
148 |
return ERROR_INIT_FAILED; |
|
116 | 149 |
} |
117 |
else |
|
118 |
if (bom_init(bom_read) != 0) |
|
150 |
else { |
|
151 |
if ((ret = bom_init(bom_read))) { |
|
152 |
DRAGONFLY_DEBUG_PRINT("bom_init returned "); |
|
153 |
DRAGONFLY_DEBUG_PRINT_INT(ret); |
|
154 |
DRAGONFLY_DEBUG_PRINT_STR("\r\n"); |
|
119 | 155 |
return ERROR_INIT_FAILED; |
156 |
} |
|
157 |
} |
|
120 | 158 |
} |
121 | 159 |
|
122 | 160 |
if (config & ENCODERS) |
123 | 161 |
{ |
124 |
encoders_init(); |
|
162 |
if((ret = encoders_init())) { |
|
163 |
DRAGONFLY_DEBUG_PRINT("encoders_init returned "); |
|
164 |
DRAGONFLY_DEBUG_PRINT_INT(ret); |
|
165 |
DRAGONFLY_DEBUG_PRINT_STR("\r\n"); |
|
166 |
} |
|
167 |
|
|
125 | 168 |
} |
126 | 169 |
|
170 |
DRAGONFLY_DEBUG_PRINT("dragonfly_init complete\r\n"); |
|
171 |
|
|
127 | 172 |
// delay a bit for stability |
128 | 173 |
_delay_ms(1); |
129 | 174 |
|
branches/init_refactor/code/projects/libdragonfly/i2c.c | ||
---|---|---|
112 | 112 |
**/ |
113 | 113 |
int i2c_init(char addr, fun_mrecv_t master_recv, fun_srecv_t slave_recv, fun_send_t slave_send) { |
114 | 114 |
|
115 |
if(i2c_initd) |
|
115 |
if(i2c_initd) { |
|
116 |
DRAGONFLY_DEBUG_PRINT("ERROR: i2c already init'd\r\n"); |
|
116 | 117 |
return ERROR_INIT_ALREADY_INITD; |
118 |
} |
|
117 | 119 |
|
118 | 120 |
|
119 | 121 |
master_recv_function = master_recv; |
... | ... | |
153 | 155 |
int i2c_send(char dest, char *data, unsigned int bytes) { |
154 | 156 |
int i; |
155 | 157 |
|
156 |
if(!i2c_initd) |
|
158 |
if(!i2c_initd) { |
|
159 |
DRAGONFLY_DEBUG_PRINT("ERROR: i2c not init'd\r\n"); |
|
157 | 160 |
return ERROR_LIBRARY_NOT_INITD; |
161 |
} |
|
158 | 162 |
|
159 | 163 |
|
160 | 164 |
/* adding data to be sent to ring buffers is not atomic, |
... | ... | |
163 | 167 |
for(i = 0; i < bytes; i++) { |
164 | 168 |
if(RING_BUFFER_FULL(i2c_write_buff)) { |
165 | 169 |
sei(); |
170 |
DRAGONFLY_DEBUG_PRINT("ERROR: i2c buffer full!\r\n"); |
|
166 | 171 |
return -1; |
167 | 172 |
} |
168 | 173 |
|
... | ... | |
196 | 201 |
* @return 0 for success, nonzero for failure |
197 | 202 |
**/ |
198 | 203 |
int i2c_request(char dest) { |
199 |
if(!i2c_initd) |
|
200 |
return ERROR_LIBRARY_NOT_INITD; |
|
204 |
if(!i2c_initd) { |
|
205 |
DRAGONFLY_DEBUG_PRINT("ERROR: encoders not init'd\r\n"); |
|
206 |
return ERROR_LIBRARY_NOT_INITD; |
|
207 |
} |
|
201 | 208 |
|
202 | 209 |
if(RING_BUFFER_FULL(i2c_write_buff)) |
203 | 210 |
return -1; |
branches/init_refactor/code/projects/libdragonfly/serial.c | ||
---|---|---|
108 | 108 |
int xbee_init() { |
109 | 109 |
|
110 | 110 |
if(xbee_initd) { |
111 |
DRAGONFLY_DEBUG_PRINT("ERROR: xbee already init'd\r\n"); |
|
111 | 112 |
return ERROR_INIT_ALREADY_INITD; |
112 | 113 |
} |
113 | 114 |
|
... | ... | |
170 | 171 |
**/ |
171 | 172 |
int xbee_putc(char c) { |
172 | 173 |
|
173 |
if(!xbee_initd) |
|
174 |
if(!xbee_initd) { |
|
175 |
DRAGONFLY_DEBUG_PRINT("ERROR: xbee not init'd\r\n"); |
|
174 | 176 |
return ERROR_LIBRARY_NOT_INITD; |
177 |
} |
|
175 | 178 |
|
176 | 179 |
// Wait until buffer is clear for sending |
177 | 180 |
loop_until_bit_is_set(UCSR1A, UDRE1); |
... | ... | |
190 | 193 |
int usb_puts(char *s) { |
191 | 194 |
char *t = s; |
192 | 195 |
|
193 |
if(!usb_initd) |
|
196 |
if(!usb_initd) { |
|
197 |
DRAGONFLY_DEBUG_PRINT("ERROR: xbee not init'd\r\n"); |
|
194 | 198 |
return ERROR_LIBRARY_NOT_INITD; |
199 |
} |
|
195 | 200 |
|
196 | 201 |
while (*t != 0) { |
197 | 202 |
usb_putc(*t); |
... | ... | |
210 | 215 |
int usb_puts_P (PGM_P s) { |
211 | 216 |
char buf; |
212 | 217 |
|
213 |
if(!usb_initd) |
|
218 |
if(!usb_initd) { |
|
219 |
DRAGONFLY_DEBUG_PRINT("ERROR: xbee not init'd\r\n"); |
|
214 | 220 |
return ERROR_LIBRARY_NOT_INITD; |
221 |
} |
|
215 | 222 |
|
216 | 223 |
while (memcpy_P (&buf, s, sizeof (char)), buf!=0) { |
217 | 224 |
usb_putc (buf); |
... | ... | |
256 | 263 |
**/ |
257 | 264 |
int xbee_getc(void) { |
258 | 265 |
|
259 |
if(!usb_initd) |
|
266 |
if(!usb_initd) { |
|
267 |
DRAGONFLY_DEBUG_PRINT("ERROR: xbee not init'd\r\n"); |
|
260 | 268 |
return -1; |
269 |
} |
|
261 | 270 |
|
262 | 271 |
// Wait for the receive buffer to be filled |
263 | 272 |
loop_until_bit_is_set(UCSR1A, RXC1); |
... | ... | |
307 | 316 |
* @see xbee_init, xbee_getc |
308 | 317 |
**/ |
309 | 318 |
int xbee_getc_nb(char *c) { |
310 |
if(!xbee_initd) |
|
319 |
if(!xbee_initd) { |
|
320 |
DRAGONFLY_DEBUG_PRINT("ERROR: xbee not init'd\r\n"); |
|
311 | 321 |
return ERROR_LIBRARY_NOT_INITD; |
322 |
} |
|
312 | 323 |
|
313 | 324 |
// check if the receive buffer is filled |
314 | 325 |
if (UCSR1A & _BV(RXC1)) { |
branches/init_refactor/code/projects/libdragonfly/spi.c | ||
---|---|---|
27 | 27 |
int spi_init (spi_fun_recv_t recv_func, spi_fun_recv_complete_t recv_complete_func) |
28 | 28 |
{ |
29 | 29 |
if(spi_initd) { |
30 |
DRAGONFLY_DEBUG_PRINT("ERROR: SPI already init'd\r\n"); |
|
30 | 31 |
return ERROR_INIT_ALREADY_INITD; |
31 | 32 |
} |
32 | 33 |
|
... | ... | |
58 | 59 |
**/ |
59 | 60 |
int spi_transfer(char bytes) |
60 | 61 |
{ |
61 |
if(!spi_initd) |
|
62 |
return ERROR_LIBRARY_NOT_INITD; |
|
62 |
if(!spi_initd) { |
|
63 |
DRAGONFLY_DEBUG_PRINT("ERROR: SPI not init'd\r\n"); |
|
64 |
return ERROR_LIBRARY_NOT_INITD; |
|
65 |
} |
|
63 | 66 |
|
64 | 67 |
spi_bytes = bytes; |
65 | 68 |
PORTB &= ~SS; /* Set SS low to initiate transmission */ |
branches/init_refactor/code/projects/libdragonfly/time.c | ||
---|---|---|
133 | 133 |
int rtc_init(int prescale_opt, void (*rtc_func)(void)) { |
134 | 134 |
|
135 | 135 |
if(time_initd) { |
136 |
DRAGONFLY_DEBUG_PRINT("ERROR: time already init'd\r\n"); |
|
136 | 137 |
return ERROR_INIT_ALREADY_INITD; |
137 | 138 |
} |
138 | 139 |
|
... | ... | |
179 | 180 |
* @see rtc_init, rtc_reset |
180 | 181 |
**/ |
181 | 182 |
int rtc_get(void) { |
183 |
if(!time_initd) { |
|
184 |
DRAGONFLY_DEBUG_PRINT("ERROR: time not init'd\r\n"); |
|
185 |
return -1; |
|
186 |
} |
|
187 |
|
|
182 | 188 |
return _rtc_val; |
183 | 189 |
} |
184 | 190 |
|
branches/init_refactor/code/projects/libdragonfly/analog.c | ||
---|---|---|
81 | 81 |
* |
82 | 82 |
**/ |
83 | 83 |
int analog_init(int start_conversion) { |
84 |
if(analog_initd) |
|
84 |
if(analog_initd){ |
|
85 |
DRAGONFLY_DEBUG_PRINT("ERROR: analog already init'd\r\n"); |
|
85 | 86 |
return ERROR_INIT_ALREADY_INITD; |
87 |
} |
|
86 | 88 |
|
87 | 89 |
for (int i = 0; i < 11; i++) { |
88 | 90 |
an_val[i].adc10 = 0; |
... | ... | |
188 | 190 |
* @see analog_stop_loop, analog_loop_status |
189 | 191 |
**/ |
190 | 192 |
int analog_start_loop(void) { |
191 |
if(!analog_initd) |
|
193 |
if(!analog_initd) { |
|
194 |
DRAGONFLY_DEBUG_PRINT("ERROR: analog not init'd\r\n"); |
|
192 | 195 |
return ERROR_LIBRARY_NOT_INITD; |
196 |
} |
|
193 | 197 |
|
194 | 198 |
if(adc_loop_status != ADC_LOOP_RUNNING){ |
195 | 199 |
//Start the conversion, enable ADC interrupt |
... | ... | |
212 | 216 |
* @see analog_start_loop, analog_loop_status |
213 | 217 |
**/ |
214 | 218 |
int analog_stop_loop() { |
215 |
if(!analog_initd) |
|
219 |
if(!analog_initd) { |
|
220 |
DRAGONFLY_DEBUG_PRINT("ERROR: analog not init'd\r\n"); |
|
216 | 221 |
return ERROR_LIBRARY_NOT_INITD; |
222 |
} |
|
217 | 223 |
|
218 | 224 |
//Signal to stop after the next conversion |
219 | 225 |
adc_sig_stop_loop = 1; |
branches/init_refactor/code/projects/libdragonfly/encoders.c | ||
---|---|---|
91 | 91 |
int encoders_init(void){ |
92 | 92 |
int i; |
93 | 93 |
|
94 |
if(encoders_initd) |
|
94 |
if(encoders_initd) { |
|
95 |
DRAGONFLY_DEBUG_PRINT("ERROR: encoders already init'd\r\n"); |
|
95 | 96 |
return ERROR_INIT_ALREADY_INITD; |
97 |
} |
|
96 | 98 |
|
97 | 99 |
data_ready=0; |
98 | 100 |
|
99 |
if(spi_init(encoder_recv, encoder_recv_complete)) |
|
101 |
if(spi_init(encoder_recv, encoder_recv_complete)) { |
|
102 |
DRAGONFLY_DEBUG_PRINT("ERROR: SPI was already init'd, bailing out\r\n"); |
|
100 | 103 |
return -1; //if spi was inited for something else, bail out |
104 |
} |
|
101 | 105 |
encoder_buf_index = 0; |
102 | 106 |
left_data_buf = 0; |
103 | 107 |
right_data_buf= 0; |
... | ... | |
134 | 138 |
* the encoder. |
135 | 139 |
**/ |
136 | 140 |
int encoder_read(char encoder){ |
137 |
if(!encoders_initd) |
|
141 |
if(!encoders_initd) { |
|
142 |
DRAGONFLY_DEBUG_PRINT("ERROR: encoders not init'd\r\n"); |
|
138 | 143 |
return -2; |
144 |
} |
|
139 | 145 |
|
140 | 146 |
if(encoder==LEFT) { |
141 | 147 |
return left_data; |
... | ... | |
216 | 222 |
**/ |
217 | 223 |
int encoder_rst_dx(char encoder) { |
218 | 224 |
|
219 |
if(!encoders_initd) |
|
225 |
if(!encoders_initd) { |
|
226 |
DRAGONFLY_DEBUG_PRINT("ERROR: encoders not init'd\r\n"); |
|
220 | 227 |
return ERROR_LIBRARY_NOT_INITD; |
228 |
} |
|
221 | 229 |
|
222 | 230 |
if(encoder==LEFT) |
223 | 231 |
left_dx = 0; |
... | ... | |
241 | 249 |
* @return 0 if init succesfull, an error code otherwise |
242 | 250 |
*/ |
243 | 251 |
int encoder_rst_tc(void) { |
244 |
if(!encoders_initd) |
|
252 |
if(!encoders_initd) { |
|
253 |
DRAGONFLY_DEBUG_PRINT("ERROR: encoders not init'd\r\n"); |
|
245 | 254 |
return ERROR_LIBRARY_NOT_INITD; |
255 |
} |
|
246 | 256 |
|
247 | 257 |
timecount = 0; |
248 | 258 |
|
... | ... | |
258 | 268 |
* @return 0 if init succesfull, an error code otherwise |
259 | 269 |
*/ |
260 | 270 |
int encoder_wait(int n){ |
261 |
if(!encoders_initd) |
|
271 |
if(!encoders_initd) { |
|
272 |
DRAGONFLY_DEBUG_PRINT("ERROR: encoders not init'd\r\n"); |
|
262 | 273 |
return ERROR_LIBRARY_NOT_INITD; |
274 |
} |
|
263 | 275 |
|
264 | 276 |
while(data_ready<n); |
265 | 277 |
data_ready=0; |
... | ... | |
277 | 289 |
int encoder_recv(char data){ |
278 | 290 |
short int dx; |
279 | 291 |
|
280 |
if(!encoders_initd) |
|
292 |
if(!encoders_initd) { |
|
293 |
DRAGONFLY_DEBUG_PRINT("ERROR: encoders not init'd\r\n"); |
|
281 | 294 |
return ERROR_LIBRARY_NOT_INITD; |
295 |
} |
|
282 | 296 |
|
283 | 297 |
//Parse the encoder data, comes in over 5 bytes 16 bits per encoder, |
284 | 298 |
// second is offset by 1 bit. |
branches/init_refactor/code/projects/libdragonfly/bom.c | ||
---|---|---|
38 | 38 |
#include "serial.h" |
39 | 39 |
#include "analog.h" |
40 | 40 |
|
41 |
//#define DEBUG_BOM_VERBOSE |
|
42 |
|
|
41 | 43 |
//On the original BOM1.0, the emmitter angular order does not match the analog mux order |
42 | 44 |
//so you need to iterate through the mux index in the following order if you want to get |
43 | 45 |
//the detector readings in order: |
... | ... | |
132 | 134 |
**/ |
133 | 135 |
int bom_init(char type) { |
134 | 136 |
|
135 |
if(bom_initd) |
|
136 |
return ERROR_INIT_ALREADY_INITD; |
|
137 |
if(bom_initd) { |
|
138 |
DRAGONFLY_DEBUG_PRINT("ERROR: BOM already init'd\r\n"); |
|
139 |
return ERROR_INIT_ALREADY_INITD; |
|
140 |
} |
|
137 | 141 |
|
138 | 142 |
|
139 | 143 |
bom_type = type; |
... | ... | |
159 | 163 |
case RBOM: |
160 | 164 |
break; |
161 | 165 |
default: |
166 |
DRAGONFLY_DEBUG_PRINT("ERROR: unknown BOM type "); |
|
167 |
DRAGONFLY_DEBUG_PRINT_INT(bom_type); |
|
168 |
DRAGONFLY_DEBUG_PRINT_STR("\r\n"); |
|
162 | 169 |
return -1; |
163 | 170 |
//default: |
164 | 171 |
} |
... | ... | |
184 | 191 |
int i; |
185 | 192 |
int loop_was_running = 0; |
186 | 193 |
|
187 |
if(!bom_initd) |
|
194 |
if(!bom_initd) { |
|
195 |
DRAGONFLY_DEBUG_PRINT("ERROR: BOM not init'd\r\n"); |
|
188 | 196 |
return ERROR_LIBRARY_NOT_INITD; |
197 |
} |
|
189 | 198 |
|
190 | 199 |
|
191 | 200 |
//Check analog loop status |
... | ... | |
222 | 231 |
* see bom_refresh |
223 | 232 |
**/ |
224 | 233 |
int bom_get(int which) { |
225 |
if(!bom_initd) |
|
226 |
return -1; |
|
234 |
if(!bom_initd) { |
|
235 |
DRAGONFLY_DEBUG_PRINT("ERROR: BOM not init'd\r\n"); |
|
236 |
return -1; |
|
237 |
} |
|
227 | 238 |
|
228 | 239 |
return bom_val[which]; |
229 | 240 |
} |
... | ... | |
238 | 249 |
int bom_get_max(void) { |
239 | 250 |
int i, lowest_val, lowest_i; |
240 | 251 |
|
241 |
if(!bom_initd) |
|
252 |
if(!bom_initd) { |
|
253 |
DRAGONFLY_DEBUG_PRINT("ERROR: BOM not init'd\r\n"); |
|
242 | 254 |
return -2; |
255 |
} |
|
243 | 256 |
|
244 | 257 |
lowest_i = -1; |
245 | 258 |
lowest_val = 255; |
... | ... | |
252 | 265 |
|
253 | 266 |
if(lowest_val < BOM_VALUE_THRESHOLD) |
254 | 267 |
return lowest_i; |
255 |
else |
|
268 |
else { |
|
269 |
#ifdef DEBUG_BOM_VERBOSE |
|
270 |
DRAGONFLY_DEBUG_PRINT("ERROR: no BOM values above threshold\r\n"); |
|
271 |
#endif |
|
256 | 272 |
return -1; |
273 |
} |
|
257 | 274 |
} |
258 | 275 |
|
259 | 276 |
/** |
... | ... | |
268 | 285 |
int i, max; |
269 | 286 |
long long mean = 0, sum = 0; |
270 | 287 |
|
271 |
if(!bom_initd) |
|
288 |
if(!bom_initd) { |
|
289 |
DRAGONFLY_DEBUG_PRINT("ERROR: BOM not init'd\r\n"); |
|
272 | 290 |
return ERROR_LIBRARY_NOT_INITD; |
291 |
} |
|
273 | 292 |
|
274 | 293 |
|
275 | 294 |
max = bom_get_max(); |
... | ... | |
279 | 298 |
{ |
280 | 299 |
*dist = -1; |
281 | 300 |
} |
301 |
#ifdef DEBUG_BOM_VERBOSE |
|
302 |
DRAGONFLY_DEBUG_PRINT("ERROR: no BOM values above threshold\r\n"); |
|
303 |
#endif |
|
282 | 304 |
return -1; |
283 | 305 |
} |
284 | 306 |
/* Record values into an array */ |
... | ... | |
314 | 336 |
int i; |
315 | 337 |
unsigned int mask = 1<<(NUM_BOM_LEDS-1); |
316 | 338 |
|
317 |
if(!bom_initd) |
|
339 |
if(!bom_initd) { |
|
340 |
DRAGONFLY_DEBUG_PRINT("ERROR: BOM not init'd\r\n"); |
|
318 | 341 |
return ERROR_LIBRARY_NOT_INITD; |
342 |
} |
|
319 | 343 |
|
320 | 344 |
switch(bom_type) { |
321 | 345 |
case BOM10: |
... | ... | |
371 | 395 |
**/ |
372 | 396 |
int bom_on(void) |
373 | 397 |
{ |
374 |
if(!bom_initd) |
|
398 |
if(!bom_initd) { |
|
399 |
DRAGONFLY_DEBUG_PRINT("ERROR: BOM not init'd\r\n"); |
|
375 | 400 |
return ERROR_LIBRARY_NOT_INITD; |
401 |
} |
|
376 | 402 |
|
377 | 403 |
switch(bom_type) { |
378 | 404 |
case BOM10: |
... | ... | |
384 | 410 |
case RBOM: |
385 | 411 |
break; |
386 | 412 |
default: |
413 |
DRAGONFLY_DEBUG_PRINT("ERROR: no valid BOM type, cannot turn on\r\n"); |
|
387 | 414 |
return -1; |
388 | 415 |
} |
389 | 416 |
|
... | ... | |
399 | 426 |
**/ |
400 | 427 |
int bom_off(void) |
401 | 428 |
{ |
402 |
if(!bom_initd) |
|
429 |
if(!bom_initd) { |
|
430 |
DRAGONFLY_DEBUG_PRINT("ERROR: BOM not init'd\r\n"); |
|
403 | 431 |
return ERROR_LIBRARY_NOT_INITD; |
432 |
} |
|
404 | 433 |
|
405 | 434 |
switch(bom_type) { |
406 | 435 |
case BOM10: |
branches/init_refactor/code/projects/libdragonfly/reset.c | ||
---|---|---|
51 | 51 |
* and Status Register (MCUCSR). |
52 | 52 |
**/ |
53 | 53 |
void reset(void) { |
54 |
|
|
55 |
DRAGONFLY_DEBUG_PRINT("System going down for reboot now!\r\n"); |
|
56 |
|
|
54 | 57 |
WDTCR &= 0xF8; |
55 | 58 |
WDTCR |= 0x08; |
56 | 59 |
_delay_ms(15); |
branches/init_refactor/code/projects/libdragonfly/rangefinder.c | ||
---|---|---|
122 | 122 |
**/ |
123 | 123 |
int range_init(void) |
124 | 124 |
{ |
125 |
if(range_initd) |
|
125 |
if(range_initd) { |
|
126 |
DRAGONFLY_DEBUG_PRINT("ERROR: rangefinders not init'd\r\n"); |
|
126 | 127 |
return ERROR_INIT_ALREADY_INITD; |
128 |
} |
|
127 | 129 |
|
128 | 130 |
digital_output(_PIN_B4,0); |
129 | 131 |
|
... | ... | |
143 | 145 |
* @see range_init |
144 | 146 |
**/ |
145 | 147 |
int range_read_distance(int range_id) { |
146 |
if(!range_initd) |
|
148 |
if(!range_initd) { |
|
149 |
DRAGONFLY_DEBUG_PRINT("ERROR: rangefinders not init'd\r\n"); |
|
147 | 150 |
return -3; |
151 |
} |
|
148 | 152 |
|
149 | 153 |
return linearize_distance(analog8(range_id)); |
150 | 154 |
} |
branches/init_refactor/code/projects/libdragonfly/dragonfly_defs.h | ||
---|---|---|
91 | 91 |
|
92 | 92 |
|
93 | 93 |
#ifdef DRAGONFLY_DEBUG |
94 |
#define DRAGONFLY_DEBUG_PRINT(s) usb_puts(s)
|
|
95 |
#define DRAGONFLY_DEBUG_PRINTLN(s) usb_puts(__FILE__ ":" __LINE__ ">>" s "\r\n")
|
|
94 |
#define DRAGONFLY_DEBUG_PRINT(s) usb_puts(__FILE__ ":" __LINE__ ">>" s "\r\n")
|
|
95 |
#define DRAGONFLY_DEBUG_PRINT_STR(s) usb_puts(s)
|
|
96 | 96 |
#define DRAGONFLY_DEBUG_PRINT_INT(i) usb_puti(i) |
97 | 97 |
#else |
98 | 98 |
#define DRAGONFLY_DEBUG_PRINT(s) |
99 |
#define DRAGONFLY_DEBUG_PRINTLN(s)
|
|
99 |
#define DRAGONFLY_DEBUG_PRINT_STR(s)
|
|
100 | 100 |
#define DRAGONFLY_DEBUG_PRINT_INT(i) |
101 | 101 |
#endif |
102 | 102 |
|
103 |
//TODO: write a STR_ERROR function which returns strings for the error codes |
|
104 |
|
|
103 | 105 |
#endif |
Also available in: Unified diff