Rev 264 | Rev 266 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 264 | Rev 265 | ||
---|---|---|---|
Line 322... | Line 322... | ||
322 | 322 | ||
323 | case 5: |
323 | case 5: |
324 | // Save values |
324 | // Save values |
325 | if(Compass_CalState != OldCalState) // avoid continously writing of eeprom! |
325 | if(Compass_CalState != OldCalState) // avoid continously writing of eeprom! |
- | 326 | { |
|
326 | { |
327 | #define MIN_CALIBRATION 350 |
327 | Calibration.MagX.Range = Xmax - Xmin; |
328 | Calibration.MagX.Range = Xmax - Xmin; |
328 | Calibration.MagX.Offset = (Xmin + Xmax) / 2; |
329 | Calibration.MagX.Offset = (Xmin + Xmax) / 2; |
329 | Calibration.MagY.Range = Ymax - Ymin; |
330 | Calibration.MagY.Range = Ymax - Ymin; |
330 | Calibration.MagY.Offset = (Ymin + Ymax) / 2; |
331 | Calibration.MagY.Offset = (Ymin + Ymax) / 2; |
331 | Calibration.MagZ.Range = Zmax - Zmin; |
332 | Calibration.MagZ.Range = Zmax - Zmin; |
332 | Calibration.MagZ.Offset = (Zmin + Zmax) / 2; |
333 | Calibration.MagZ.Offset = (Zmin + Zmax) / 2; |
333 | if((Calibration.MagX.Range > 512) && (Calibration.MagY.Range > 512) && (Calibration.MagZ.Range > 512)) |
334 | if((Calibration.MagX.Range > MIN_CALIBRATION) && (Calibration.MagY.Range > MIN_CALIBRATION) && (Calibration.MagZ.Range > MIN_CALIBRATION)) |
334 | { |
335 | { |
- | 336 | NCMAG_IsCalibrated = NCMag_CalibrationWrite(); |
|
335 | NCMAG_IsCalibrated = NCMag_CalibrationWrite(); |
337 | UART1_PutString("\r\n Calibration okay"); |
336 | } |
338 | } |
337 | else |
339 | else |
338 | { |
340 | { |
339 | // restore old calibration data from eeprom |
341 | // restore old calibration data from eeprom |
- | 342 | NCMAG_IsCalibrated = NCMag_CalibrationRead(); |
|
- | 343 | UART1_PutString("\r\n Calibration FAILED - Values too low: "); |
|
- | 344 | if(Calibration.MagX.Range < MIN_CALIBRATION) UART1_PutString("X! "); |
|
- | 345 | if(Calibration.MagY.Range < MIN_CALIBRATION) UART1_PutString("Y! "); |
|
340 | NCMAG_IsCalibrated = NCMag_CalibrationRead(); |
346 | if(Calibration.MagZ.Range < MIN_CALIBRATION) UART1_PutString("Z! "); |
341 | } |
347 | } |
342 | } |
348 | } |
Line 343... | Line 349... | ||
343 | break; |
349 | break; |