Revision 1543
Added a bunch of debug prints to the library
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. |
Also available in: Unified diff