Subversion Repositories FlightCtrl

Rev

Rev 2088 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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