Rev 360 | Rev 464 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 360 | Rev 454 | ||
---|---|---|---|
Line 61... | Line 61... | ||
61 | #include "timer1.h" |
61 | #include "timer1.h" |
62 | #include "led.h" |
62 | #include "led.h" |
63 | #include "main.h" |
63 | #include "main.h" |
64 | #include "uart1.h" |
64 | #include "uart1.h" |
65 | #include "compass.h" |
65 | #include "compass.h" |
- | 66 | #include "spi_slave.h" |
|
Line 66... | Line 67... | ||
66 | 67 | ||
Line 67... | Line 68... | ||
67 | #define MK3MAG_SLAVE_ADDRESS 0x50 // i2C slave address |
68 | #define MK3MAG_SLAVE_ADDRESS 0x50 // i2C slave address |
Line 264... | Line 265... | ||
264 | //---------------------------------------------------------------- |
265 | //---------------------------------------------------------------- |
265 | void MK3MAG_Update(void) |
266 | void MK3MAG_Update(void) |
266 | { |
267 | { |
267 | static u32 TimerUpdate = 0; |
268 | static u32 TimerUpdate = 0; |
268 | static s16 x_max,y_max,z_max,x_min,y_min,z_min; |
269 | static s16 x_max,y_max,z_max,x_min,y_min,z_min; |
269 | static u8 last_state; |
270 | static u8 last_state,speak = 0; |
270 | u8 msg[64]; |
271 | u8 msg[64]; |
271 | u16 MinCaclibration = 500; |
272 | u16 MinCaclibration = 500; |
Line 272... | Line 273... | ||
272 | 273 | ||
Line 300... | Line 301... | ||
300 | } |
301 | } |
301 | else UART1_PutString("without GPS\n\r"); |
302 | else UART1_PutString("without GPS\n\r"); |
302 | } |
303 | } |
303 | x_max = -30000; y_max = -30000; z_max = -30000; |
304 | x_max = -30000; y_max = -30000; z_max = -30000; |
304 | x_min = 30000; y_min = 30000; z_min = 30000; |
305 | x_min = 30000; y_min = 30000; z_min = 30000; |
- | 306 | speak = 1; |
|
305 | break; |
307 | break; |
306 | - | ||
307 | case 2: |
308 | case 2: |
- | 309 | if(speak) SpeakHoTT = SPEAK_CALIBRATE; speak = 0; |
|
- | 310 | ||
308 | if(MagVector.X > x_max) { x_max = MagVector.X; BeepTime = 60; } |
311 | if(MagVector.X > x_max) { x_max = MagVector.X; BeepTime = 60; } |
309 | else if(MagVector.X < x_min) { x_min = MagVector.X; BeepTime = 20; } |
312 | else if(MagVector.X < x_min) { x_min = MagVector.X; BeepTime = 20; } |
310 | if(MagVector.Y > y_max) { y_max = MagVector.Y; BeepTime = 60; } |
313 | if(MagVector.Y > y_max) { y_max = MagVector.Y; BeepTime = 60; } |
311 | else if(MagVector.Y < y_min) { y_min = MagVector.Y; BeepTime = 20; } |
314 | else if(MagVector.Y < y_min) { y_min = MagVector.Y; BeepTime = 20; } |
312 | break; |
- | |
Line -... | Line 315... | ||
- | 315 | ||
- | 316 | break; |
|
- | 317 | case 3: |
|
- | 318 | speak = 1; |
|
313 | 319 | break; |
|
- | 320 | case 4: |
|
314 | case 4: |
321 | if(speak) SpeakHoTT = SPEAK_CALIBRATE; speak = 0; |
315 | if(MagVector.Z > z_max) { z_max = MagVector.Z; BeepTime = 80; } |
322 | if(MagVector.Z > z_max) { z_max = MagVector.Z; BeepTime = 80; } |
316 | else if(MagVector.Z < z_min) { z_min = MagVector.Z; BeepTime = 80; } |
323 | else if(MagVector.Z < z_min) { z_min = MagVector.Z; BeepTime = 80; } |
317 | break; |
324 | break; |
318 | case 5: |
325 | case 5: |
319 | if(last_state == Compass_CalState) break; |
326 | if(last_state == Compass_CalState) break; |
320 | if(((x_max - x_min) > MinCaclibration) && ((y_max - y_min) > MinCaclibration) && ((z_max - z_min) > MinCaclibration)) |
327 | if(((x_max - x_min) > MinCaclibration) && ((y_max - y_min) > MinCaclibration) && ((z_max - z_min) > MinCaclibration)) |
321 | { |
328 | { |
322 | BeepTime = 2500; |
329 | BeepTime = 2500; |
- | 330 | UART1_PutString("\r\n-> Calibration okay <-\n\r"); |
|
323 | UART1_PutString("\r\n-> Calibration okay <-\n\r"); |
331 | SpeakHoTT = SPEAK_MIKROKOPTER; |
324 | } |
332 | } |
325 | else |
333 | else |
326 | { |
334 | { |
327 | UART1_PutString("\r\nCalibration FAILED - Values too low: "); |
335 | UART1_PutString("\r\nCalibration FAILED - Values too low: "); |
328 | if((x_max - x_min) < MinCaclibration) UART1_PutString("X! "); |
336 | if((x_max - x_min) < MinCaclibration) UART1_PutString("X! "); |
329 | if((y_max - y_min) < MinCaclibration) UART1_PutString("Y! "); |
337 | if((y_max - y_min) < MinCaclibration) UART1_PutString("Y! "); |
330 | if((z_max - z_min) < MinCaclibration) UART1_PutString("Z! "); |
338 | if((z_max - z_min) < MinCaclibration) UART1_PutString("Z! "); |
- | 339 | UART1_PutString("\r\n"); |
|
331 | UART1_PutString("\r\n"); |
340 | SpeakHoTT = SPEAK_ERR_CALIBARTION; |
332 | } |
341 | } |
333 | UART1_PutString(msg); |
342 | UART1_PutString(msg); |
334 | sprintf(msg, "\r\nX: (%i - %i = %i)\r\n",x_max,x_min,x_max - x_min); |
343 | sprintf(msg, "\r\nX: (%i - %i = %i)\r\n",x_max,x_min,x_max - x_min); |
335 | UART1_PutString(msg); |
344 | UART1_PutString(msg); |