Rev 2380 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2380 | Rev 2402 | ||
---|---|---|---|
1 | #include <inttypes.h> |
1 | #include <inttypes.h> |
2 | #include "main.h" |
2 | #include "main.h" |
3 | 3 | ||
4 | uint16_t LED1_Timing = 0; |
4 | uint16_t LED1_Timing = 0; |
5 | uint16_t LED2_Timing = 0; |
5 | uint16_t LED2_Timing = 0; |
6 | unsigned char J16Blinkcount = 0, J16Mask = 1; |
6 | unsigned char J16Blinkcount = 0, J16Mask = 1; |
7 | unsigned char J17Blinkcount = 0, J17Mask = 1; |
7 | unsigned char J17Blinkcount = 0, J17Mask = 1; |
8 | unsigned char NC_Wait_for_LED = 0; // signal to NC: Wait for the LAD PAtter before switching to the next WP |
8 | unsigned char NC_Wait_for_LED = 0; // signal to NC: Wait for the LAD PAtter before switching to the next WP |
9 | 9 | ||
10 | // initializes the LED control outputs J16, J17 |
10 | // initializes the LED control outputs J16, J17 |
11 | void LED_Init(void) |
11 | void LED_Init(void) |
12 | { |
12 | { |
13 | // set PC2 & PC3 as output (control of J16 & J17) |
13 | // set PC2 & PC3 as output (control of J16 & J17) |
14 | DDRC |= (1<<DDC2)|(1<<DDC3); |
14 | DDRC |= (1<<DDC2)|(1<<DDC3); |
15 | J16_OFF; |
15 | J16_OFF; |
16 | J17_OFF; |
16 | J17_OFF; |
17 | J16Blinkcount = 0; J16Mask = 128; |
17 | J16Blinkcount = 0; J16Mask = 128; |
18 | J17Blinkcount = 0; J17Mask = 128; |
18 | J17Blinkcount = 0; J17Mask = 128; |
19 | } |
19 | } |
20 | 20 | ||
21 | // called in UpdateMotors() every 2ms |
21 | // called in UpdateMotors() every 2ms |
22 | void LED_Update(void) |
22 | void LED_Update(void) |
23 | { |
23 | { |
24 | static char delay = 0; |
24 | static char delay = 0; |
25 | static unsigned char J16Bitmask = 0; |
25 | static unsigned char J16Bitmask = 0; |
26 | static unsigned char J17Bitmask = 0; |
26 | static unsigned char J17Bitmask = 0; |
27 | static unsigned char J16Warn = 0, J17Warn = 0; |
27 | static unsigned char J16Warn = 0, J17Warn = 0; |
28 | static unsigned char from_nc = 0; |
28 | static unsigned char from_nc = 0; |
29 | 29 | ||
30 | if(FromNC_WP_EventChannel != -127) { from_nc = (unsigned char) FromNC_WP_EventChannel + 127; /*beeptime = 300;*/}; |
30 | if(FromNC_WP_EventChannel != -127) { from_nc = (unsigned char) FromNC_WP_EventChannel + 127; /*beeptime = 300;*/}; |
31 | if(!delay--) // 20ms Intervall |
31 | if(!delay--) // 20ms Intervall |
32 | { |
32 | { |
- | 33 | J16Bitmask = EE_Parameter.J16Bitmask; |
|
- | 34 | J17Bitmask = EE_Parameter.J17Bitmask; |
|
33 | delay = 9; |
35 | delay = 9; |
34 | if(FC_StatusFlags & (FC_STATUS_LOWBAT | FC_STATUS_EMERGENCY_LANDING) || (VersionInfo.HardwareError[1] & FC_ERROR1_I2C)) |
36 | if(FC_StatusFlags & (FC_STATUS_LOWBAT | FC_STATUS_EMERGENCY_LANDING) || (VersionInfo.HardwareError[1] & FC_ERROR1_I2C)) |
35 | { |
37 | { |
36 | if(EE_Parameter.WARN_J16_Bitmask) |
38 | if(EE_Parameter.WARN_J16_Bitmask) |
37 | { |
39 | { |
38 | if(!J16Warn) J16Blinkcount = 4; |
40 | if(!J16Warn) J16Blinkcount = 4; |
39 | J16Warn = 1; |
41 | J16Warn = 1; |
40 | } |
42 | } |
41 | if(EE_Parameter.WARN_J17_Bitmask) |
43 | if(EE_Parameter.WARN_J17_Bitmask) |
42 | { |
44 | { |
43 | if(!J17Warn) J17Blinkcount = 4; |
45 | if(!J17Warn) J17Blinkcount = 4; |
44 | J17Warn = 1; |
46 | J17Warn = 1; |
45 | } |
47 | } |
46 | } |
48 | } |
47 | else |
49 | else |
48 | { |
50 | { |
49 | J16Warn = 0; |
51 | J16Warn = 0; |
50 | J17Warn = 0; |
52 | J17Warn = 0; |
51 | J16Bitmask = EE_Parameter.J16Bitmask; |
- | |
52 | J17Bitmask = EE_Parameter.J17Bitmask; |
- | |
53 | } |
53 | } |
54 | //DebugOut.Analog[29] = EE_Parameter.GlobalConfig3; |
54 | //DebugOut.Analog[29] = EE_Parameter.GlobalConfig3; |
55 | // Output 1 |
55 | // Output 1 |
56 | if(!J16Warn) |
56 | if(!J16Warn) |
57 | { |
57 | { |
58 | if((EE_Parameter.BitConfig & CFG_MOTOR_BLINK1) && !MotorenEin) {if(EE_Parameter.BitConfig & CFG_MOTOR_OFF_LED1) J16_ON; else J16_OFF;} |
58 | if((EE_Parameter.BitConfig & CFG_MOTOR_BLINK1) && !MotorenEin) {if(EE_Parameter.BitConfig & CFG_MOTOR_OFF_LED1) J16_ON; else J16_OFF;} |
59 | else |
59 | else |
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 |
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 |
61 | else |
61 | else |
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 |
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 |
63 | else |
63 | else |
64 | if(!J16Blinkcount--) |
64 | if(!J16Blinkcount--) |
65 | { |
65 | { |
66 | if(EE_Parameter.GlobalConfig3 & CFG3_USE_NC_FOR_OUT1) |
66 | if(EE_Parameter.GlobalConfig3 & CFG3_USE_NC_FOR_OUT1) |
67 | { |
67 | { |
68 | J16Blinkcount = from_nc / 2; |
68 | J16Blinkcount = from_nc / 2; |
69 | if(!from_nc) { NC_Wait_for_LED = 0; if(J16Bitmask & 128) J16_ON; else J16_OFF; J16Mask = 0; } // Ausschalten |
69 | if(!from_nc) { NC_Wait_for_LED = 0; if(J16Bitmask & 128) J16_ON; else J16_OFF; J16Mask = 0; } // Ausschalten |
70 | else |
70 | else |
71 | { |
71 | { |
72 | NC_Wait_for_LED = 1; |
72 | NC_Wait_for_LED = 1; |
73 | if(J16Mask == 0) |
73 | if(J16Mask == 0) |
74 | { |
74 | { |
75 | from_nc = 0; |
75 | from_nc = 0; |
76 | J16Mask = 64; |
76 | J16Mask = 64; |
77 | if(J16Bitmask & 128) J16_ON; else J16_OFF; // Ausschalten |
77 | if(J16Bitmask & 128) J16_ON; else J16_OFF; // Ausschalten |
78 | } |
78 | } |
79 | else |
79 | else |
80 | { |
80 | { |
81 | //if(FromNC_WP_EventChannel != -127) |
81 | //if(FromNC_WP_EventChannel != -127) |
82 | if(J16Mask & J16Bitmask) J16_ON; else J16_OFF; |
82 | if(J16Mask & J16Bitmask) J16_ON; else J16_OFF; |
83 | J16Mask /= 2; |
83 | J16Mask /= 2; |
84 | } |
84 | } |
85 | } |
85 | } |
86 | } |
86 | } |
87 | else |
87 | else |
88 | { |
88 | { |
89 | J16Blinkcount = Parameter_J16Timing / 2; |
89 | J16Blinkcount = Parameter_J16Timing / 2; |
90 | if(J16Mask == 1) { from_nc = 0; J16Mask = 128; } else J16Mask /= 2; |
90 | if(J16Mask == 1) { from_nc = 0; J16Mask = 64; } else J16Mask /= 2; |
91 | if(J16Mask & J16Bitmask) J16_ON; else J16_OFF; |
91 | if(J16Mask & J16Bitmask) J16_ON; else J16_OFF; |
92 | NC_Wait_for_LED = 0; |
92 | NC_Wait_for_LED = 0; |
93 | } |
93 | } |
94 | } |
94 | } |
95 | } |
95 | } |
96 | else // warning case |
96 | else // warning case |
97 | if(!J16Blinkcount--) |
97 | if(!J16Blinkcount--) |
98 | { |
98 | { |
99 | J16Blinkcount = 10-1; |
99 | J16Blinkcount = 10-1; |
100 | if(J16Mask == 1) J16Mask = 128; else J16Mask /= 2; |
100 | if(J16Mask == 1) J16Mask = 128; else J16Mask /= 2; |
101 | if(J16Mask & EE_Parameter.WARN_J16_Bitmask) J16_ON; else J16_OFF; |
101 | if(J16Mask & EE_Parameter.WARN_J16_Bitmask) J16_ON; else J16_OFF; |
102 | } |
102 | } |
103 | // Output 2 |
103 | // Output 2 |
104 | 104 | ||
105 | if(!J17Warn) |
105 | if(!J17Warn) |
106 | { |
106 | { |
107 | if((EE_Parameter.BitConfig & CFG_MOTOR_BLINK2) && !MotorenEin) {if(EE_Parameter.BitConfig & CFG_MOTOR_OFF_LED2) J17_ON; else J17_OFF;} |
107 | if((EE_Parameter.BitConfig & CFG_MOTOR_BLINK2) && !MotorenEin) {if(EE_Parameter.BitConfig & CFG_MOTOR_OFF_LED2) J17_ON; else J17_OFF;} |
108 | else |
108 | else |
109 | if((EE_Parameter.J17Timing > 247) && (Parameter_J17Timing > 220)) {if(J17Bitmask & 128) J17_OFF; else J17_ON; J17Mask = 1;} |
109 | if((EE_Parameter.J17Timing > 247) && (Parameter_J17Timing > 220)) {if(J17Bitmask & 128) J17_OFF; else J17_ON; J17Mask = 1;} |
110 | else |
110 | else |
111 | if((EE_Parameter.J17Timing > 247) && (Parameter_J17Timing == 5)) {if(J17Bitmask & 128) J17_ON; else J17_OFF; J17Mask = 1;} |
111 | if((EE_Parameter.J17Timing > 247) && (Parameter_J17Timing == 5)) {if(J17Bitmask & 128) J17_ON; else J17_OFF; J17Mask = 1;} |
112 | else |
112 | else |
113 | if(!J17Blinkcount--) |
113 | if(!J17Blinkcount--) |
114 | { |
114 | { |
115 | J17Blinkcount = Parameter_J17Timing / 2; |
115 | J17Blinkcount = Parameter_J17Timing / 2; |
116 | if(J17Mask == 1) J17Mask = 64; else J17Mask /= 2; |
116 | if(J17Mask == 1) J17Mask = 64; else J17Mask /= 2; |
117 | if(J17Mask & J17Bitmask) J17_OFF; else J17_ON; |
117 | if(J17Mask & J17Bitmask) J17_ON; else J17_OFF; |
118 | } |
118 | } |
119 | } |
119 | } |
120 | else // warning case |
120 | else // warning case |
121 | if(!J17Blinkcount--) |
121 | if(!J17Blinkcount--) |
122 | { |
122 | { |
123 | J17Blinkcount = 10-1; |
123 | J17Blinkcount = 10-1; |
124 | if(J17Mask == 1) J17Mask = 128; else J17Mask /= 2; |
124 | if(J17Mask == 1) J17Mask = 128; else J17Mask /= 2; |
125 | if(J17Mask & EE_Parameter.WARN_J17_Bitmask) J17_ON; else J17_OFF; |
125 | if(J17Mask & EE_Parameter.WARN_J17_Bitmask) J17_ON; else J17_OFF; |
126 | } |
126 | } |
127 | 127 | ||
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 |
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 |
129 | if(PORTC & (1<<PORTC3)) FC_StatusFlags2 |= FC_STATUS2_OUT2_ACTIVE; else FC_StatusFlags2 &= ~FC_STATUS2_OUT2_ACTIVE; // Out2 (J17) |
129 | if(PORTC & (1<<PORTC3)) FC_StatusFlags2 |= FC_STATUS2_OUT2_ACTIVE; else FC_StatusFlags2 &= ~FC_STATUS2_OUT2_ACTIVE; // Out2 (J17) |
130 | } |
130 | } |
131 | } |
131 | } |
132 | 132 | ||
133 | 133 |