Subversion Repositories FlightCtrl

Rev

Details | Last modification | View Log | RSS feed

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