Subversion Repositories FlightCtrl

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2751 - 1
#include <inttypes.h>
2
#include "main.h"
3
 
4
uint16_t LED1_Timing = 0;
5
uint16_t LED2_Timing = 0;
6
unsigned char J16Blinkcount = 0, J16Mask = 1;
7
unsigned char J17Blinkcount = 0, J17Mask = 1;
8
unsigned char NC_Wait_for_LED = 0;  // signal to NC: Wait for the LAD PAtter before switching to the next WP
9
 
10
// initializes the LED control outputs J16, J17
11
void LED_Init(void)
12
{
13
        // set PC2 & PC3 as output (control of J16 & J17)
14
        DDRC |= (1<<DDC2)|(1<<DDC3);
15
        J16_OFF;
16
        J17_OFF;
17
        J16Blinkcount = 0; J16Mask = 128;
18
        J17Blinkcount = 0; J17Mask = 128;
19
}
20
 
21
// called in UpdateMotors() every 2ms
22
void LED_Update(void)
23
{
24
        static char delay = 0;
25
        static unsigned char J16Bitmask = 0;
26
        static unsigned char J17Bitmask = 0;
27
        static unsigned char J16Warn = 0, J17Warn = 0;
28
    static unsigned char from_nc = 0;
29
 
30
        if(FromNC_WP_EventChannel != -127) { from_nc = (unsigned char) FromNC_WP_EventChannel + 127; /*beeptime = 300;*/};
31
        if(!delay--)  // 20ms Intervall
32
        {
33
        J16Bitmask = EE_Parameter.J16Bitmask;
34
        J17Bitmask = EE_Parameter.J17Bitmask;
35
        delay = 9;
36
        if(FC_StatusFlags & (FC_STATUS_LOWBAT | FC_STATUS_EMERGENCY_LANDING) || (VersionInfo.HardwareError[1] & FC_ERROR1_I2C))
37
        {
38
                if(EE_Parameter.WARN_J16_Bitmask)
39
                 {
40
          if(!J16Warn) J16Blinkcount = 4;
41
          J16Warn = 1;
42
                 }
43
                if(EE_Parameter.WARN_J17_Bitmask)
44
                 {
45
          if(!J17Warn) J17Blinkcount = 4;
46
          J17Warn = 1;
47
                 }
48
        }
49
        else
50
        {
51
        J16Warn = 0;
52
        J17Warn = 0;
53
        }
54
//DebugOut.Analog[29] = EE_Parameter.GlobalConfig3;
55
// Output 1
56
 if(!J16Warn)    
57
  {
58
  if((EE_Parameter.BitConfig & CFG_MOTOR_BLINK1) && !MotorenEin) {if(EE_Parameter.BitConfig & CFG_MOTOR_OFF_LED1) J16_ON; else J16_OFF;}
59
  else
60
  if((EE_Parameter.J16Timing > 247) && (Parameter_J16Timing > 220)) {if(J16Bitmask & 128) J16_OFF; else J16_ON; J16Mask = 1; NC_Wait_for_LED = 0;}  // Manual overwrite
61
  else
62
  if((EE_Parameter.J16Timing > 247) && (Parameter_J16Timing == 5))  {if(J16Bitmask & 128) J16_ON; else J16_OFF; J16Mask = 1; NC_Wait_for_LED = 0;}  // Manual overwrite
63
  else
64
  if(!J16Blinkcount--)
65
   {
66
    if(EE_Parameter.GlobalConfig3 & CFG3_USE_NC_FOR_OUT1)
67
         {
68
          J16Blinkcount = from_nc / 2;
69
          if(!from_nc) { NC_Wait_for_LED = 0; if(J16Bitmask & 128) J16_ON; else J16_OFF; J16Mask = 0; } // Ausschalten
70
          else
71
           {
72
        NC_Wait_for_LED = 1;
73
        if(J16Mask == 0)
74
                 {
75
                  from_nc = 0;
76
                  J16Mask = 64;
77
                  if(J16Bitmask & 128) J16_ON; else J16_OFF; // Ausschalten
78
                 }
79
                else
80
                 {
81
//if(FromNC_WP_EventChannel != -127)  
82
          if(J16Mask & J16Bitmask) J16_ON; else J16_OFF;
83
                  J16Mask /= 2;
84
                 }
85
           }   
86
         }
87
        else
88
         {
89
          J16Blinkcount = Parameter_J16Timing / 2;
90
      if(J16Mask == 1) { from_nc = 0; J16Mask = 64; } else J16Mask /= 2;
91
      if(J16Mask & J16Bitmask) J16_ON; else J16_OFF;
92
          NC_Wait_for_LED = 0;
93
         }
94
   }
95
  }
96
  else  // warning case
97
  if(!J16Blinkcount--)
98
   {
99
     J16Blinkcount = 10-1;
100
     if(J16Mask == 1) J16Mask = 128; else J16Mask /= 2;
101
     if(J16Mask & EE_Parameter.WARN_J16_Bitmask) J16_ON; else J16_OFF;
102
   }
103
// Output 2
104
 
105
 if(!J17Warn)
106
  {
107
  if((EE_Parameter.BitConfig & CFG_MOTOR_BLINK2) && !MotorenEin) {if(EE_Parameter.BitConfig & CFG_MOTOR_OFF_LED2) J17_ON; else J17_OFF;}
108
  else
109
  if((EE_Parameter.J17Timing > 247) && (Parameter_J17Timing > 220)) {if(J17Bitmask & 128) J17_OFF; else J17_ON; J17Mask = 1;}
110
  else
111
  if((EE_Parameter.J17Timing > 247) && (Parameter_J17Timing == 5))  {if(J17Bitmask & 128) J17_ON; else J17_OFF; J17Mask = 1;}
112
  else
113
  if(!J17Blinkcount--)
114
   {
115
         J17Blinkcount = Parameter_J17Timing / 2;
116
     if(J17Mask == 1) J17Mask = 64; else J17Mask /= 2;
117
     if(J17Mask & J17Bitmask) J17_ON; else J17_OFF;
118
   }
119
  }
120
  else  // warning case
121
  if(!J17Blinkcount--)
122
   {
123
     J17Blinkcount = 10-1;
124
     if(J17Mask == 1) J17Mask = 128; else J17Mask /= 2;
125
     if(J17Mask & EE_Parameter.WARN_J17_Bitmask) J17_ON; else J17_OFF;
126
   }
127
 
128
   if(PORTC & (1<<PORTC2)) FC_StatusFlags2 |= FC_STATUS2_OUT1_ACTIVE; //else FC_StatusFlags2 &= ~FC_STATUS2_OUT1_ACTIVE;      // Out1 (J16) -> wird in der SPI zurück gesetzt
129
   if(PORTC & (1<<PORTC3)) FC_StatusFlags2 |= FC_STATUS2_OUT2_ACTIVE; else FC_StatusFlags2 &= ~FC_STATUS2_OUT2_ACTIVE;       // Out2 (J17)
130
 }
131
}
132