From e276665b3200f63d7e64e3ba678de2bcc2260ce1 Mon Sep 17 00:00:00 2001 From: treymarc Date: Wed, 16 Apr 2014 14:39:34 +0000 Subject: [PATCH] type bool and inflight acc calib --- src/mw.c | 19 ++++++++++--------- src/sensors.c | 15 +++++++-------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/mw.c b/src/mw.c index e668ee83d..8168fd7bf 100755 --- a/src/mw.c +++ b/src/mw.c @@ -58,11 +58,11 @@ uint8_t GPS_svinfo_quality[16]; // Bitfield Qualtity uint8_t GPS_svinfo_cno[16]; // Carrier to Noise Ratio (Signal Strength) // Automatic ACC Offset Calibration +bool AccInflightCalibrationArmed = false; +bool AccInflightCalibrationMeasurementDone = false; +bool AccInflightCalibrationSavetoEEProm = false; +bool AccInflightCalibrationActive = false; uint16_t InflightcalibratingA = 0; -int16_t AccInflightCalibrationArmed; -uint16_t AccInflightCalibrationMeasurementDone = 0; -uint16_t AccInflightCalibrationSavetoEEProm = 0; -uint16_t AccInflightCalibrationActive = 0; // Battery monitoring stuff uint8_t batteryCellCount = 3; // cell count @@ -560,8 +560,8 @@ void loop(void) // Inflight ACC Calibration } else if (feature(FEATURE_INFLIGHT_ACC_CAL) && (rcSticks == THR_LO + YAW_LO + PIT_HI + ROL_HI)) { if (AccInflightCalibrationMeasurementDone) { // trigger saving into eeprom after landing - AccInflightCalibrationMeasurementDone = 0; - AccInflightCalibrationSavetoEEProm = 1; + AccInflightCalibrationMeasurementDone = false; + AccInflightCalibrationSavetoEEProm = true; } else { AccInflightCalibrationArmed = !AccInflightCalibrationArmed; if (AccInflightCalibrationArmed) { @@ -623,14 +623,15 @@ void loop(void) if (feature(FEATURE_INFLIGHT_ACC_CAL)) { if (AccInflightCalibrationArmed && f.ARMED && rcData[THROTTLE] > mcfg.mincheck && !rcOptions[BOXARM]) { // Copter is airborne and you are turning it off via boxarm : start measurement InflightcalibratingA = 50; - AccInflightCalibrationArmed = 0; + AccInflightCalibrationArmed = false; } if (rcOptions[BOXCALIB]) { // Use the Calib Option to activate : Calib = TRUE Meausrement started, Land and Calib = 0 measurement stored if (!AccInflightCalibrationActive && !AccInflightCalibrationMeasurementDone) InflightcalibratingA = 50; + AccInflightCalibrationActive = true; } else if (AccInflightCalibrationMeasurementDone && !f.ARMED) { - AccInflightCalibrationMeasurementDone = 0; - AccInflightCalibrationSavetoEEProm = 1; + AccInflightCalibrationMeasurementDone = false; + AccInflightCalibrationSavetoEEProm = true; } } diff --git a/src/sensors.c b/src/sensors.c index cdc1a8001..90a82b5c4 100755 --- a/src/sensors.c +++ b/src/sensors.c @@ -8,10 +8,9 @@ uint16_t acc_1G = 256; // this is the 1G measured acceleration. int16_t heading, magHold; extern uint16_t InflightcalibratingA; -extern int16_t AccInflightCalibrationArmed; -extern uint16_t AccInflightCalibrationMeasurementDone; -extern uint16_t AccInflightCalibrationSavetoEEProm; -extern uint16_t AccInflightCalibrationActive; +extern bool AccInflightCalibrationMeasurementDone; +extern bool AccInflightCalibrationSavetoEEProm; +extern bool AccInflightCalibrationActive; extern uint16_t batteryWarningVoltage; extern uint8_t batteryCellCount; extern float magneticDeclination; @@ -213,8 +212,8 @@ static void ACC_Common(void) } // all values are measured if (InflightcalibratingA == 1) { - AccInflightCalibrationActive = 0; - AccInflightCalibrationMeasurementDone = 1; + AccInflightCalibrationActive = false; + AccInflightCalibrationMeasurementDone = true; toggleBeep = 2; // buzzer for indicatiing the end of calibration // recover saved values to maintain current flight behavior until new values are transferred mcfg.accZero[ROLL] = accZero_saved[ROLL]; @@ -226,8 +225,8 @@ static void ACC_Common(void) InflightcalibratingA--; } // Calculate average, shift Z down by acc_1G and store values in EEPROM at end of calibration - if (AccInflightCalibrationSavetoEEProm == 1) { // the copter is landed, disarmed and the combo has been done again - AccInflightCalibrationSavetoEEProm = 0; + if (AccInflightCalibrationSavetoEEProm) { // the copter is landed, disarmed and the combo has been done again + AccInflightCalibrationSavetoEEProm = false; mcfg.accZero[ROLL] = b[ROLL] / 50; mcfg.accZero[PITCH] = b[PITCH] / 50; mcfg.accZero[YAW] = b[YAW] / 50 - acc_1G; // for nunchuk 200=1G