Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2231 | - | 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 | if(!delay--) // 20ms Intervall |
||
28 | { |
||
29 | delay = 9; |
||
30 | if(FC_StatusFlags & (FC_STATUS_LOWBAT | FC_STATUS_EMERGENCY_LANDING) || (VersionInfo.HardwareError[1] & FC_ERROR1_I2C)) |
||
31 | { |
||
32 | if(EE_Parameter.WARN_J16_Bitmask) |
||
33 | { |
||
34 | if(!J16Warn) J16Blinkcount = 4; |
||
35 | J16Warn = 1; |
||
36 | } |
||
37 | if(EE_Parameter.WARN_J17_Bitmask) |
||
38 | { |
||
39 | if(!J17Warn) J17Blinkcount = 4; |
||
40 | J17Warn = 1; |
||
41 | } |
||
42 | } |
||
43 | else |
||
44 | { |
||
45 | J16Warn = 0; |
||
46 | J17Warn = 0; |
||
47 | J16Bitmask = EE_Parameter.J16Bitmask; |
||
48 | J17Bitmask = EE_Parameter.J17Bitmask; |
||
49 | } |
||
50 | |||
51 | if(!J16Warn) |
||
52 | { |
||
53 | if((EE_Parameter.BitConfig & CFG_MOTOR_BLINK1) && !MotorenEin) {if(EE_Parameter.BitConfig & CFG_MOTOR_OFF_LED1) J16_ON; else J16_OFF;} |
||
54 | else |
||
55 | if((EE_Parameter.J16Timing > 247) && (Parameter_J16Timing > 220)) {if(J16Bitmask & 128) J16_ON; else J16_OFF; J16Mask = 1;} |
||
56 | else |
||
57 | if((EE_Parameter.J16Timing > 247) && (Parameter_J16Timing == 5)) {if(J16Bitmask & 128) J16_OFF; else J16_ON; J16Mask = 1;} |
||
58 | else |
||
59 | if(!J16Blinkcount--) |
||
60 | { |
||
61 | J16Blinkcount = Parameter_J16Timing / 2; |
||
62 | if(J16Mask == 1) J16Mask = 128; else J16Mask /= 2; |
||
63 | if(J16Mask & J16Bitmask) J16_ON; else J16_OFF; |
||
64 | } |
||
65 | } |
||
66 | else |
||
67 | if(!J16Blinkcount--) |
||
68 | { |
||
69 | J16Blinkcount = 10-1; |
||
70 | if(J16Mask == 1) J16Mask = 128; else J16Mask /= 2; |
||
71 | if(J16Mask & EE_Parameter.WARN_J16_Bitmask) J16_ON; else J16_OFF; |
||
72 | } |
||
73 | |||
74 | if(!J17Warn) |
||
75 | { |
||
76 | if((EE_Parameter.BitConfig & CFG_MOTOR_BLINK2) && !MotorenEin) {if(EE_Parameter.BitConfig & CFG_MOTOR_OFF_LED2) J17_ON; else J17_OFF;} |
||
77 | else |
||
78 | if((EE_Parameter.J17Timing > 247) && (Parameter_J17Timing > 220)) {if(J17Bitmask & 128) J17_ON; else J17_OFF; J17Mask = 1;} |
||
79 | else |
||
80 | if((EE_Parameter.J17Timing > 247) && (Parameter_J17Timing == 5)) {if(J17Bitmask & 128) J17_OFF; else J17_ON; J17Mask = 1;} |
||
81 | else |
||
82 | if(!J17Blinkcount--) |
||
83 | { |
||
84 | J17Blinkcount = Parameter_J17Timing / 2; |
||
85 | if(J17Mask == 1) J17Mask = 128; else J17Mask /= 2; |
||
86 | if(J17Mask & J17Bitmask) J17_ON; else J17_OFF; |
||
87 | } |
||
88 | } |
||
89 | else |
||
90 | if(!J17Blinkcount--) |
||
91 | { |
||
92 | J17Blinkcount = 10-1; |
||
93 | if(J17Mask == 1) J17Mask = 128; else J17Mask /= 2; |
||
94 | if(J17Mask & EE_Parameter.WARN_J17_Bitmask) J17_ON; else J17_OFF; |
||
95 | } |
||
96 | if(PORTC & (1<<PORTC2)) FC_StatusFlags2 |= FC_STATUS2_OUT1_ACTIVE; else FC_StatusFlags2 &= ~FC_STATUS2_OUT1_ACTIVE; // Out1 (J16) |
||
97 | if(PORTC & (1<<PORTC3)) FC_StatusFlags2 |= FC_STATUS2_OUT2_ACTIVE; else FC_StatusFlags2 &= ~FC_STATUS2_OUT2_ACTIVE; // Out2 (J17) |
||
98 | } |
||
99 | } |
||
100 |