Subversion Repositories FlightCtrl

Rev

Rev 2403 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
927 hbuss 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;
2370 holgerb 8
unsigned char NC_Wait_for_LED = 0;  // signal to NC: Wait for the LAD PAtter before switching to the next WP
927 hbuss 9
 
10
// initializes the LED control outputs J16, J17
11
void LED_Init(void)
12
{
1254 killagreg 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;
927 hbuss 19
}
20
 
21
// called in UpdateMotors() every 2ms
22
void LED_Update(void)
23
{
1254 killagreg 24
        static char delay = 0;
25
        static unsigned char J16Bitmask = 0;
26
        static unsigned char J17Bitmask = 0;
1423 hbuss 27
        static unsigned char J16Warn = 0, J17Warn = 0;
2183 holgerb 28
    static unsigned char from_nc = 0;
2348 holgerb 29
 
30
        if(FromNC_WP_EventChannel != -127) { from_nc = (unsigned char) FromNC_WP_EventChannel + 127; /*beeptime = 300;*/};
1933 holgerb 31
        if(!delay--)  // 20ms Intervall
1254 killagreg 32
        {
2402 holgerb 33
        J16Bitmask = EE_Parameter.J16Bitmask;
34
        J17Bitmask = EE_Parameter.J17Bitmask;
1933 holgerb 35
        delay = 9;
1769 holgerb 36
        if(FC_StatusFlags & (FC_STATUS_LOWBAT | FC_STATUS_EMERGENCY_LANDING) || (VersionInfo.HardwareError[1] & FC_ERROR1_I2C))
1254 killagreg 37
        {
1765 killagreg 38
                if(EE_Parameter.WARN_J16_Bitmask)
1423 hbuss 39
                 {
40
          if(!J16Warn) J16Blinkcount = 4;
41
          J16Warn = 1;
1765 killagreg 42
                 }
43
                if(EE_Parameter.WARN_J17_Bitmask)
1423 hbuss 44
                 {
45
          if(!J17Warn) J17Blinkcount = 4;
46
          J17Warn = 1;
1765 killagreg 47
                 }
1254 killagreg 48
        }
49
        else
50
        {
1423 hbuss 51
        J16Warn = 0;
52
        J17Warn = 0;
1254 killagreg 53
        }
2183 holgerb 54
//DebugOut.Analog[29] = EE_Parameter.GlobalConfig3;
55
// Output 1
56
 if(!J16Warn)    
1423 hbuss 57
  {
1940 holgerb 58
  if((EE_Parameter.BitConfig & CFG_MOTOR_BLINK1) && !MotorenEin) {if(EE_Parameter.BitConfig & CFG_MOTOR_OFF_LED1) J16_ON; else J16_OFF;}
927 hbuss 59
  else
2380 holgerb 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
1350 hbuss 61
  else
2380 holgerb 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
1254 killagreg 63
  else
64
  if(!J16Blinkcount--)
927 hbuss 65
   {
2183 holgerb 66
    if(EE_Parameter.GlobalConfig3 & CFG3_USE_NC_FOR_OUT1)
67
         {
68
          J16Blinkcount = from_nc / 2;
2380 holgerb 69
          if(!from_nc) { NC_Wait_for_LED = 0; if(J16Bitmask & 128) J16_ON; else J16_OFF; J16Mask = 0; } // Ausschalten
2183 holgerb 70
          else
71
           {
2370 holgerb 72
        NC_Wait_for_LED = 1;
2183 holgerb 73
        if(J16Mask == 0)
74
                 {
75
                  from_nc = 0;
2380 holgerb 76
                  J16Mask = 64;
77
                  if(J16Bitmask & 128) J16_ON; else J16_OFF; // Ausschalten
2183 holgerb 78
                 }
79
                else
80
                 {
2370 holgerb 81
//if(FromNC_WP_EventChannel != -127)  
2183 holgerb 82
          if(J16Mask & J16Bitmask) J16_ON; else J16_OFF;
83
                  J16Mask /= 2;
84
                 }
85
           }   
86
         }
87
        else
88
         {
89
          J16Blinkcount = Parameter_J16Timing / 2;
2402 holgerb 90
      if(J16Mask == 1) { from_nc = 0; J16Mask = 64; } else J16Mask /= 2;
2183 holgerb 91
      if(J16Mask & J16Bitmask) J16_ON; else J16_OFF;
2370 holgerb 92
          NC_Wait_for_LED = 0;
2183 holgerb 93
         }
1254 killagreg 94
   }
1423 hbuss 95
  }
2183 holgerb 96
  else  // warning case
1423 hbuss 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
   }
2183 holgerb 103
// Output 2
1350 hbuss 104
 
1423 hbuss 105
 if(!J17Warn)
106
  {
1940 holgerb 107
  if((EE_Parameter.BitConfig & CFG_MOTOR_BLINK2) && !MotorenEin) {if(EE_Parameter.BitConfig & CFG_MOTOR_OFF_LED2) J17_ON; else J17_OFF;}
927 hbuss 108
  else
2380 holgerb 109
  if((EE_Parameter.J17Timing > 247) && (Parameter_J17Timing > 220)) {if(J17Bitmask & 128) J17_OFF; else J17_ON; J17Mask = 1;}
1350 hbuss 110
  else
2380 holgerb 111
  if((EE_Parameter.J17Timing > 247) && (Parameter_J17Timing == 5))  {if(J17Bitmask & 128) J17_ON; else J17_OFF; J17Mask = 1;}
1254 killagreg 112
  else
113
  if(!J17Blinkcount--)
927 hbuss 114
   {
1933 holgerb 115
         J17Blinkcount = Parameter_J17Timing / 2;
2380 holgerb 116
     if(J17Mask == 1) J17Mask = 64; else J17Mask /= 2;
2402 holgerb 117
     if(J17Mask & J17Bitmask) J17_ON; else J17_OFF;
1254 killagreg 118
   }
927 hbuss 119
  }
2183 holgerb 120
  else  // warning case
1423 hbuss 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
   }
2183 holgerb 127
 
2348 holgerb 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
2040 holgerb 129
   if(PORTC & (1<<PORTC3)) FC_StatusFlags2 |= FC_STATUS2_OUT2_ACTIVE; else FC_StatusFlags2 &= ~FC_STATUS2_OUT2_ACTIVE;       // Out2 (J17)
1423 hbuss 130
 }
927 hbuss 131
}
1423 hbuss 132