Subversion Repositories FlightCtrl

Rev

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

Rev 2119 Rev 2130
Line 17... Line 17...
17
#include "eeprom.h"
17
#include "eeprom.h"
18
#include "printf_P.h"
18
#include "printf_P.h"
Line 19... Line 19...
19
 
19
 
20
int16_t main(void) {
20
int16_t main(void) {
-
 
21
  uint16_t timer;
Line 21... Line 22...
21
  uint16_t timer;
22
  static uint8_t profileTimer;
22
 
23
 
Line 23... Line 24...
23
  // disable interrupts global
24
  // disable interrupts global
Line 28... Line 29...
28
  WDTCSR |= (1 << WDCE) | (1 << WDE);
29
  WDTCSR |= (1 << WDCE) | (1 << WDE);
29
  WDTCSR = 0;
30
  WDTCSR = 0;
Line 30... Line 31...
30
 
31
 
31
// This is strange: It should NOT be necessarty to do. But the call of the same,
32
// This is strange: It should NOT be necessarty to do. But the call of the same,
32
// in channelMap_readOrDefault (if eeprom read fails) just sets all to 0,0,0,....
33
// in channelMap_readOrDefault (if eeprom read fails) just sets all to 0,0,0,....
Line 33... Line 34...
33
  channelMap_default();
34
// channelMap_default();
34
 
35
 
35
  // initalize modules
36
  // initalize modules
36
  output_init();
37
  output_init();
Line 41... Line 42...
41
  analog_init();
42
  analog_init();
Line 42... Line 43...
42
 
43
 
43
  // Parameter Set handling
44
  // Parameter Set handling
44
  IMUConfig_readOrDefault();
45
  IMUConfig_readOrDefault();
-
 
46
  channelMap_readOrDefault();
45
  channelMap_readOrDefault();
47
  rcTrim_readOrDefault();
Line 46... Line 48...
46
  paramSet_readOrDefault();
48
  paramSet_readOrDefault();
47
 
49
 
Line 48... Line -...
48
  // enable interrupts global
-
 
49
  sei();
-
 
50
 
-
 
51
  printf("\n\r===================================");
-
 
52
  printf("\n\rFlightControl");
-
 
53
  printf("\n\rHardware: Custom");
-
 
54
  printf("\n\r     CPU: Atmega328");
-
 
55
  printf("\n\rSoftware: V%d.%d%c",
-
 
56
      VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH + 'a');
-
 
57
  printf("\n\r===================================");
-
 
58
 
-
 
59
  // Wait for a short time (otherwise the RC channel check won't work below)
-
 
60
  // timer = SetDelay(500);
-
 
61
  // while(!CheckDelay(timer));
-
 
62
 
-
 
63
  // Instead, while away the time by flashing the 2 outputs:
-
 
64
  // First J16, then J17. Makes it easier to see which is which.
-
 
65
  timer = setDelay(200);
-
 
66
  outputSet(0, 1);
-
 
67
  GRN_OFF;
-
 
68
  RED_ON;
-
 
69
  while (!checkDelay(timer))
-
 
70
    ;
-
 
71
 
-
 
72
  timer = setDelay(200);
-
 
73
  outputSet(0, 0);
-
 
74
  outputSet(1, 1);
-
 
75
  RED_OFF;
-
 
76
  GRN_ON;
-
 
77
  while (!checkDelay(timer))
-
 
78
    ;
-
 
79
 
-
 
80
  timer = setDelay(200);
-
 
81
  while (!checkDelay(timer))
-
 
82
    ;
-
 
83
  outputSet(1, 0);
-
 
84
  GRN_OFF;
-
 
85
 
-
 
86
  printf("\n\r===================================");
-
 
87
 
-
 
88
#ifdef USE_NAVICTRL
-
 
89
  printf("\n\rSupport for NaviCtrl");
-
 
90
#endif
-
 
91
 
-
 
92
#ifdef USE_DIRECT_GPS
-
 
93
  printf("\n\rDirect (no NaviCtrl) navigation");
50
  // enable interrupts global
Line 94... Line 51...
94
#endif
51
  sei();
95
 
52
 
Line 96... Line 53...
96
  controlMixer_setNeutral();
53
  controlMixer_setNeutral();
97
 
-
 
98
  // Cal. attitude sensors and reset integrals.
-
 
99
  attitude_setNeutral();
54
 
Line 100... Line -...
100
 
-
 
101
  // Init flight parameters
-
 
102
  // flight_setNeutral();
55
  // Cal. attitude sensors and reset integrals.
103
 
56
  attitude_setNeutral();
104
  beep(2000);
57
 
105
 
58
  // This is not a busy-wait operation and should be OK.
106
  printf("\n\n\r");
59
  beep(2000);
Line 130... Line 83...
130
        usart0_transmitTxData();
83
        usart0_transmitTxData();
131
      }
84
      }
Line 132... Line 85...
132
 
85
 
Line 133... Line -...
133
      usart0_processRxData();
-
 
134
 
-
 
135
      if (checkDelay(timer)) {
86
      usart0_processRxData();
136
        // Do nothing. The voltage on the input side of the regulator is <5V;
-
 
137
        // we must be running off USB power. Keep it quiet.
-
 
138
      } else if (UBat < staticParams.batteryWarningVoltage && UBat > UBAT_AT_5V) {
-
 
Line 139... Line 87...
139
        beepBatteryAlarm();
87
 
-
 
88
        static uint8_t aboveWarningLimitVoltageSeen = 0;
-
 
89
 
-
 
90
        if (checkDelay(timer)) {
-
 
91
          if (UBat >= staticParams.batteryWarningVoltage) {
140
      }
92
            aboveWarningLimitVoltageSeen = 1;
-
 
93
          } else { // If we are above USB voltage, or if we have once been above warning voltage
-
 
94
            if (aboveWarningLimitVoltageSeen || UBat > UBAT_AT_5V) {
-
 
95
              beepBatteryAlarm();
-
 
96
            }
141
 
97
          }
Line 142... Line 98...
142
      timer = setDelay(20); // every 20 ms
98
          calculateFeaturedServoValues();
Line 143... Line 99...
143
      output_update();
99
          timer = setDelay(20); // every 20 ms
144
    }
100
        }
145
 
101
 
146
    calculateFeaturedServoValues();
102
    output_update();