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