Subversion Repositories FlightCtrl

Rev

Rev 1874 | Rev 1955 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1874 Rev 1908
Line 14... Line 14...
14
// void gyro_init(void) {}
14
// void gyro_init(void) {}
15
void gyro_calibrate(void) {
15
void gyro_calibrate(void) {
16
        uint8_t i, axis, factor, numberOfAxesInRange = 0;
16
        uint8_t i, axis, factor, numberOfAxesInRange = 0;
17
        uint16_t timeout;
17
        uint16_t timeout;
18
        // GyroDefectNick = 0; GyroDefectRoll = 0; GyroDefectYaw = 0;
18
        // GyroDefectNick = 0; GyroDefectRoll = 0; GyroDefectYaw = 0;
19
        timeout = SetDelay(2000);
19
        timeout = setDelay(2000);
Line 20... Line 20...
20
 
20
 
21
        for (i = 140; i != 0; i--) {
21
        for (i = 140; i != 0; i--) {
22
                // If all 3 axis are in range, shorten the remaining number of iterations.
22
                // If all 3 axis are in range, shorten the remaining number of iterations.
23
                if (numberOfAxesInRange == 3 && i > 10)
23
                if (numberOfAxesInRange == 3 && i > 10)
Line 48... Line 48...
48
                I2C_Start(TWI_STATE_GYRO_OFFSET_TX); // initiate data transmission
48
                I2C_Start(TWI_STATE_GYRO_OFFSET_TX); // initiate data transmission
Line 49... Line 49...
49
 
49
 
50
                // Wait for I2C to finish transmission.
50
                // Wait for I2C to finish transmission.
51
                while (twi_state) {
51
                while (twi_state) {
52
                        // Did it take too long?
52
                        // Did it take too long?
53
                        if (CheckDelay(timeout)) {
53
                        if (checkDelay(timeout)) {
54
                                printf("\r\n DAC or I2C Error! check I2C, 3Vref, DAC, and BL-Ctrl");
54
                                printf("\r\n DAC or I2C Error! check I2C, 3Vref, DAC, and BL-Ctrl");
55
                                break;
55
                                break;
56
                        }
56
                        }
Line 57... Line 57...
57
                }
57
                }
Line 58... Line 58...
58
 
58
 
59
                analog_start();
59
                analog_start();
60
 
60
 
61
                Delay_ms_Mess(i < 10 ? 10 : 2);
61
                delay_ms_Mess(i < 10 ? 10 : 2);
Line 62... Line 62...
62
        }
62
        }
63
        Delay_ms_Mess(70);
63
        delay_ms_Mess(70);
64
}
64
}