Subversion Repositories FlightCtrl

Rev

Go to most recent revision | Details | 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
        {
1933 holgerb 33
        delay = 9;
1769 holgerb 34
        if(FC_StatusFlags & (FC_STATUS_LOWBAT | FC_STATUS_EMERGENCY_LANDING) || (VersionInfo.HardwareError[1] & FC_ERROR1_I2C))
1254 killagreg 35
        {
1765 killagreg 36
                if(EE_Parameter.WARN_J16_Bitmask)
1423 hbuss 37
                 {
38
          if(!J16Warn) J16Blinkcount = 4;
39
          J16Warn = 1;
1765 killagreg 40
                 }
41
                if(EE_Parameter.WARN_J17_Bitmask)
1423 hbuss 42
                 {
43
          if(!J17Warn) J17Blinkcount = 4;
44
          J17Warn = 1;
1765 killagreg 45
                 }
1254 killagreg 46
        }
47
        else
48
        {
1423 hbuss 49
        J16Warn = 0;
50
        J17Warn = 0;
1254 killagreg 51
                J16Bitmask = EE_Parameter.J16Bitmask;
52
                J17Bitmask = EE_Parameter.J17Bitmask;
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
2370 holgerb 60
  if((EE_Parameter.J16Timing > 247) && (Parameter_J16Timing > 220)) {if(J16Bitmask & 128) J16_ON; else J16_OFF; J16Mask = 1; NC_Wait_for_LED = 0;}  // Manual overwrite
1350 hbuss 61
  else
2370 holgerb 62
  if((EE_Parameter.J16Timing > 247) && (Parameter_J16Timing == 5))  {if(J16Bitmask & 128) J16_OFF; else J16_ON; 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;
2370 holgerb 69
          if(!from_nc) { NC_Wait_for_LED = 0; if(J16Bitmask & 128) J16_OFF; else J16_ON; 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;
2370 holgerb 76
//                NC_Wait_for_LED = 0;
2183 holgerb 77
                  J16Mask = 128;
78
                  if(J16Bitmask & 128) J16_OFF; else J16_ON; // Ausschalten
79
                 }
80
                else
81
                 {
2370 holgerb 82
//if(FromNC_WP_EventChannel != -127)  
2183 holgerb 83
          if(J16Mask & J16Bitmask) J16_ON; else J16_OFF;
84
                  J16Mask /= 2;
85
                 }
86
           }   
87
         }
88
        else
89
         {
90
          J16Blinkcount = Parameter_J16Timing / 2;
91
      if(J16Mask == 1) { from_nc = 0; J16Mask = 128; } else J16Mask /= 2;
92
      if(J16Mask & J16Bitmask) J16_ON; else J16_OFF;
2370 holgerb 93
          NC_Wait_for_LED = 0;
2183 holgerb 94
         }
1254 killagreg 95
   }
1423 hbuss 96
  }
2183 holgerb 97
  else  // warning case
1423 hbuss 98
  if(!J16Blinkcount--)
99
   {
100
     J16Blinkcount = 10-1;
101
     if(J16Mask == 1) J16Mask = 128; else J16Mask /= 2;
102
     if(J16Mask & EE_Parameter.WARN_J16_Bitmask) J16_ON; else J16_OFF;
103
   }
2183 holgerb 104
// Output 2
1350 hbuss 105
 
1423 hbuss 106
 if(!J17Warn)
107
  {
1940 holgerb 108
  if((EE_Parameter.BitConfig & CFG_MOTOR_BLINK2) && !MotorenEin) {if(EE_Parameter.BitConfig & CFG_MOTOR_OFF_LED2) J17_ON; else J17_OFF;}
927 hbuss 109
  else
2061 holgerb 110
  if((EE_Parameter.J17Timing > 247) && (Parameter_J17Timing > 220)) {if(J17Bitmask & 128) J17_ON; else J17_OFF; J17Mask = 1;}
1350 hbuss 111
  else
2061 holgerb 112
  if((EE_Parameter.J17Timing > 247) && (Parameter_J17Timing == 5))  {if(J17Bitmask & 128) J17_OFF; else J17_ON; J17Mask = 1;}
1254 killagreg 113
  else
114
  if(!J17Blinkcount--)
927 hbuss 115
   {
1933 holgerb 116
         J17Blinkcount = Parameter_J17Timing / 2;
927 hbuss 117
     if(J17Mask == 1) J17Mask = 128; else J17Mask /= 2;
1254 killagreg 118
     if(J17Mask & J17Bitmask) J17_ON; else J17_OFF;
119
   }
927 hbuss 120
  }
2183 holgerb 121
  else  // warning case
1423 hbuss 122
  if(!J17Blinkcount--)
123
   {
124
     J17Blinkcount = 10-1;
125
     if(J17Mask == 1) J17Mask = 128; else J17Mask /= 2;
126
     if(J17Mask & EE_Parameter.WARN_J17_Bitmask) J17_ON; else J17_OFF;
127
   }
2183 holgerb 128
 
2348 holgerb 129
   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 130
   if(PORTC & (1<<PORTC3)) FC_StatusFlags2 |= FC_STATUS2_OUT2_ACTIVE; else FC_StatusFlags2 &= ~FC_STATUS2_OUT2_ACTIVE;       // Out2 (J17)
1423 hbuss 131
 }
927 hbuss 132
}
1423 hbuss 133