Subversion Repositories FlightCtrl

Rev

Rev 1927 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1910 - 1
#include <stdlib.h>
2
#include "commands.h"
3
#include "controlMixer.h"
4
#include "flight.h"
5
#include "eeprom.h"
6
#include "attitude.h"
7
#include "output.h"
8
 
9
void commands_handleCommands(void) {
10
        /*
11
         * Get the current command (start/stop motors, calibrate), if any.
12
         */
13
        uint8_t command = controlMixer_getCommand();
14
        uint8_t repeated = controlMixer_isCommandRepeated();
15
        uint8_t argument = controlMixer_getArgument();
16
 
17
        if (!(MKFlags & MKFLAG_MOTOR_RUN)) {
18
                if (command == COMMAND_GYROCAL && !repeated) {
19
                        // Run gyro calibration but do not repeat it.
20
                        GRN_OFF;
21
 
22
                        // TODO: out of here. Anyway, MKFLAG_MOTOR_RUN is cleared. Not enough?
23
                        // isFlying = 0;
24
                        // check roll/pitch stick position
25
                        // if pitch stick is top or roll stick is left or right --> change parameter setting
26
                        // according to roll/pitch stick position
27
 
28
                        if (argument < 6) {
29
                                // Gyro calinbration, with or without selecting a new parameter-set.
30
                                if (argument > 0 && argument < 6) {
31
                                        // A valid parameter-set (1..5) was chosen - use it.
32
                                        setActiveParamSet(argument);
33
                                }
34
                                ParamSet_ReadFromEEProm(getActiveParamSet());
35
                                attitude_setNeutral();
36
                                flight_setNeutral();
37
                                controlMixer_setNeutral();
38
                                beepNumber(getActiveParamSet());
39
                        } else if (staticParams.GlobalConfig & (CFG_COMPASS_ACTIVE
40
                                        | CFG_GPS_ACTIVE) && argument == 7) {
41
                                // If right stick is centered and down
42
                                // TODO: Out of here! State machine instead.
43
                                compassCalState = 1;
44
                                beep(1000);
45
                        }
46
                }
47
 
48
                // save the ACC neutral setting to eeprom
49
                else {
50
                        if (command == COMMAND_ACCCAL && !repeated) {
51
                                // Run gyro and acc. meter calibration but do not repeat it.
52
                                GRN_OFF;
53
                                analog_calibrateAcc();
54
                                attitude_setNeutral();
55
                                flight_setNeutral();
56
                                controlMixer_setNeutral();
57
                                beepNumber(getActiveParamSet());
58
                        }
59
                }
60
        } // end !MOTOR_RUN condition.
61
        if (command == COMMAND_START) {
62
                isFlying = 1; // TODO: Really????
63
                // if (!controlMixer_isCommandRepeated()) {
64
                // attitude_startDynamicCalibration(); // Try sense the effect of the motors on sensors.
65
                MKFlags |= (MKFLAG_MOTOR_RUN | MKFLAG_START); // set flag RUN and START. TODO: Is that START flag used at all???
66
                // } else { // Pilot is holding stick, ever after motor start. Continue to sense the effect of the motors on sensors.
67
                // attitude_continueDynamicCalibration();
68
                // setPointYaw = 0;
69
                // IPartPitch = 0;
70
                // IPartRoll = 0;
71
                // }
72
        } else if (command == COMMAND_STOP) {
73
                isFlying = 0;
74
                MKFlags &= ~(MKFLAG_MOTOR_RUN);
75
        }
76
}