Rev 2527 | Rev 2598 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2527 | Rev 2540 | ||
---|---|---|---|
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 | unsigned int ShutterCounter = 0; |
9 | unsigned int ShutterCounter = 0; |
10 | unsigned char Out1ChangedFlag = 0; // can be 0 or 0x80 |
10 | unsigned char Out1ChangedFlag = 0; // can be 0 or 0x80 |
11 | // initializes the LED control outputs J16, J17 |
11 | // initializes the LED control outputs J16, J17 |
12 | void LED_Init(void) |
12 | void LED_Init(void) |
13 | { |
13 | { |
14 | // set PC2 & PC3 as output (control of J16 & J17) |
14 | // set PC2 & PC3 as output (control of J16 & J17) |
15 | DDRC |= (1<<DDC2)|(1<<DDC3); |
15 | DDRC |= (1<<DDC2)|(1<<DDC3); |
16 | J16_OFF; |
16 | J16_OFF; |
17 | J17_OFF; |
17 | J17_OFF; |
18 | J16Blinkcount = 0; J16Mask = 128; |
18 | J16Blinkcount = 0; J16Mask = 128; |
19 | J17Blinkcount = 0; J17Mask = 128; |
19 | J17Blinkcount = 0; J17Mask = 128; |
20 | } |
20 | } |
21 | 21 | ||
22 | // called in UpdateMotors() every 2ms |
22 | // called in UpdateMotors() every 2ms |
23 | void LED_Update(void) |
23 | void LED_Update(void) |
24 | { |
24 | { |
25 | static char delay = 0, last_portC = 0; |
25 | static char delay = 0, last_portC = 0; |
26 | static unsigned char J16Bitmask = 0; |
26 | static unsigned char J16Bitmask = 0; |
27 | static unsigned char J17Bitmask = 0; |
27 | static unsigned char J17Bitmask = 0; |
28 | static unsigned char J16Warn = 0, J17Warn = 0; |
28 | static unsigned char J16Warn = 0, J17Warn = 0; |
29 | static unsigned char from_nc = 0; // Copy for the timing |
29 | static unsigned char from_nc = 0; // Copy for the timing |
30 | 30 | ||
- | 31 | if(!NC_Wait_for_LED) from_nc = (unsigned char) PPM_in[WP_EVENT_PPM_IN] + 127; |
|
31 | if(FromNC_WP_EventChannel_New) from_nc = FromNC_WP_EventChannel_New; |
32 | |
32 | if(!delay--) // 20ms Intervall |
33 | if(!delay--) // 20ms Intervall |
33 | { |
34 | { |
34 | J16Bitmask = EE_Parameter.J16Bitmask; |
35 | J16Bitmask = EE_Parameter.J16Bitmask; |
35 | J17Bitmask = EE_Parameter.J17Bitmask; |
36 | J17Bitmask = EE_Parameter.J17Bitmask; |
36 | delay = 9; |
37 | delay = 9; |
37 | if(FC_StatusFlags & (FC_STATUS_LOWBAT | FC_STATUS_EMERGENCY_LANDING) || (VersionInfo.HardwareError[1] & FC_ERROR1_I2C) || !SenderOkay) |
38 | if(FC_StatusFlags & (FC_STATUS_LOWBAT | FC_STATUS_EMERGENCY_LANDING) || (VersionInfo.HardwareError[1] & FC_ERROR1_I2C) || !SenderOkay) |
38 | { |
39 | { |
39 | if(EE_Parameter.WARN_J16_Bitmask) |
40 | if(EE_Parameter.WARN_J16_Bitmask) |
40 | { |
41 | { |
41 | if(!J16Warn) J16Blinkcount = 4; |
42 | if(!J16Warn) J16Blinkcount = 4; |
42 | J16Warn = 1; |
43 | J16Warn = 1; |
43 | } |
44 | } |
44 | if(EE_Parameter.WARN_J17_Bitmask) |
45 | if(EE_Parameter.WARN_J17_Bitmask) |
45 | { |
46 | { |
46 | if(!J17Warn) J17Blinkcount = 4; |
47 | if(!J17Warn) J17Blinkcount = 4; |
47 | J17Warn = 1; |
48 | J17Warn = 1; |
48 | } |
49 | } |
49 | } |
50 | } |
50 | else |
51 | else |
51 | { |
52 | { |
52 | J16Warn = 0; |
53 | J16Warn = 0; |
53 | J17Warn = 0; |
54 | J17Warn = 0; |
54 | } |
55 | } |
55 | //DebugOut.Analog[29] = EE_Parameter.GlobalConfig3; |
56 | //DebugOut.Analog[29] = EE_Parameter.GlobalConfig3; |
56 | // Output 1 |
57 | // Output 1 |
57 | if(!J16Warn) |
58 | if(!J16Warn) |
58 | { |
59 | { |
59 | if((EE_Parameter.BitConfig & CFG_MOTOR_BLINK1) && !MotorenEin) {if(EE_Parameter.BitConfig & CFG_MOTOR_OFF_LED1) J16_ON; else J16_OFF;} |
60 | if((EE_Parameter.BitConfig & CFG_MOTOR_BLINK1) && !MotorenEin) {if(EE_Parameter.BitConfig & CFG_MOTOR_OFF_LED1) J16_ON; else J16_OFF;} |
60 | else |
61 | else |
61 | 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 |
62 | 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 |
62 | else |
63 | else |
63 | 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 |
64 | 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 |
64 | else |
65 | else |
65 | if(!J16Blinkcount--) |
66 | if(!J16Blinkcount--) |
66 | { |
67 | { |
67 | if(EE_Parameter.GlobalConfig3 & CFG3_USE_NC_FOR_OUT1) |
68 | if(EE_Parameter.GlobalConfig3 & CFG3_USE_NC_FOR_OUT1) |
68 | { |
69 | { |
69 | J16Blinkcount = from_nc / 2; |
70 | J16Blinkcount = from_nc / 2; |
70 | if(!from_nc) { NC_Wait_for_LED = 0; if(J16Bitmask & 128) J16_ON; else J16_OFF; J16Mask = 0; } // Ausschalten |
71 | if(!from_nc) { NC_Wait_for_LED = 0; if(J16Bitmask & 128) J16_ON; else J16_OFF; J16Mask = 0; } // Ausschalten |
71 | else |
72 | else |
72 | { |
73 | { |
73 | NC_Wait_for_LED = 1; |
74 | NC_Wait_for_LED = 1; |
74 | if(J16Mask == 0) |
75 | if(J16Mask == 0) |
75 | { |
76 | { |
76 | from_nc = FromNC_WP_EventChannel_New; |
77 | from_nc = FromNC_WP_EventChannel_New; |
77 | FromNC_WP_EventChannel_New = 0; |
- | |
78 | J16Mask = 64; |
78 | J16Mask = 64; |
79 | if(J16Bitmask & 128) J16_ON; else J16_OFF; // Ausschalten |
79 | if(J16Bitmask & 128) J16_ON; else J16_OFF; // Ausschalten |
80 | } |
80 | } |
81 | else |
81 | else |
82 | { |
82 | { |
83 | if(J16Mask & J16Bitmask) J16_ON; else J16_OFF; |
83 | if(J16Mask & J16Bitmask) J16_ON; else J16_OFF; |
84 | J16Mask /= 2; |
84 | J16Mask /= 2; |
- | 85 | if(J16Mask == 0x01) FromNC_WP_EventChannel_New = 0; // Last Bit -> Refresh the value by NC now |
|
85 | } |
86 | } |
86 | } |
87 | } |
87 | } |
88 | } |
88 | else |
89 | else |
89 | { |
90 | { |
90 | J16Blinkcount = Parameter_J16Timing / 2; |
91 | J16Blinkcount = Parameter_J16Timing / 2; |
91 | if(J16Mask == 1) { from_nc = 0; J16Mask = 64; } else J16Mask /= 2; |
92 | if(J16Mask == 1) { from_nc = 0; J16Mask = 64; } else J16Mask /= 2; |
92 | if(J16Mask & J16Bitmask) J16_ON; else J16_OFF; |
93 | if(J16Mask & J16Bitmask) J16_ON; else J16_OFF; |
93 | NC_Wait_for_LED = 0; |
94 | NC_Wait_for_LED = 0; |
94 | } |
95 | } |
95 | } |
96 | } |
96 | } |
97 | } |
97 | else // warning case |
98 | else // warning case |
98 | if(!J16Blinkcount--) |
99 | if(!J16Blinkcount--) |
99 | { |
100 | { |
100 | J16Blinkcount = 10-1; |
101 | J16Blinkcount = 10-1; |
101 | if(J16Mask == 1) J16Mask = 128; else J16Mask /= 2; |
102 | if(J16Mask == 1) J16Mask = 128; else J16Mask /= 2; |
102 | if(J16Mask & EE_Parameter.WARN_J16_Bitmask) J16_ON; else J16_OFF; |
103 | if(J16Mask & EE_Parameter.WARN_J16_Bitmask) J16_ON; else J16_OFF; |
103 | } |
104 | } |
104 | // Output 2 |
105 | // Output 2 |
105 | 106 | ||
106 | if(!J17Warn) |
107 | if(!J17Warn) |
107 | { |
108 | { |
108 | if((EE_Parameter.BitConfig & CFG_MOTOR_BLINK2) && !MotorenEin) {if(EE_Parameter.BitConfig & CFG_MOTOR_OFF_LED2) J17_ON; else J17_OFF;} |
109 | if((EE_Parameter.BitConfig & CFG_MOTOR_BLINK2) && !MotorenEin) {if(EE_Parameter.BitConfig & CFG_MOTOR_OFF_LED2) J17_ON; else J17_OFF;} |
109 | else |
110 | else |
110 | if((EE_Parameter.J17Timing > 247) && (Parameter_J17Timing > 220)) {if(J17Bitmask & 128) J17_OFF; else J17_ON; J17Mask = 1;} |
111 | if((EE_Parameter.J17Timing > 247) && (Parameter_J17Timing > 220)) {if(J17Bitmask & 128) J17_OFF; else J17_ON; J17Mask = 1;} |
111 | else |
112 | else |
112 | if((EE_Parameter.J17Timing > 247) && (Parameter_J17Timing == 5)) {if(J17Bitmask & 128) J17_ON; else J17_OFF; J17Mask = 1;} |
113 | if((EE_Parameter.J17Timing > 247) && (Parameter_J17Timing == 5)) {if(J17Bitmask & 128) J17_ON; else J17_OFF; J17Mask = 1;} |
113 | else |
114 | else |
114 | if(!J17Blinkcount--) |
115 | if(!J17Blinkcount--) |
115 | { |
116 | { |
116 | J17Blinkcount = Parameter_J17Timing / 2; |
117 | J17Blinkcount = Parameter_J17Timing / 2; |
117 | if(J17Mask == 1) J17Mask = 64; else J17Mask /= 2; |
118 | if(J17Mask == 1) J17Mask = 64; else J17Mask /= 2; |
118 | if(J17Mask & J17Bitmask) J17_ON; else J17_OFF; |
119 | if(J17Mask & J17Bitmask) J17_ON; else J17_OFF; |
119 | } |
120 | } |
120 | } |
121 | } |
121 | else // warning case |
122 | else // warning case |
122 | if(!J17Blinkcount--) |
123 | if(!J17Blinkcount--) |
123 | { |
124 | { |
124 | J17Blinkcount = 10-1; |
125 | J17Blinkcount = 10-1; |
125 | if(J17Mask == 1) J17Mask = 128; else J17Mask /= 2; |
126 | if(J17Mask == 1) J17Mask = 128; else J17Mask /= 2; |
126 | if(J17Mask & EE_Parameter.WARN_J17_Bitmask) J17_ON; else J17_OFF; |
127 | if(J17Mask & EE_Parameter.WARN_J17_Bitmask) J17_ON; else J17_OFF; |
127 | } |
128 | } |
128 | 129 | ||
129 | 130 | ||
130 | if(PORTC & (1<<PORTC2)) // output is on |
131 | if(PORTC & (1<<PORTC2)) // output is on |
131 | { |
132 | { |
132 | if(!(last_portC & (1<<PORTC2))) |
133 | if(!(last_portC & (1<<PORTC2))) |
133 | { |
134 | { |
134 | Out1ChangedFlag = 0x80;// this Flag marks a changed Out1; |
135 | Out1ChangedFlag = 0x80;// this Flag marks a changed Out1; |
135 | ShutterCounter++; // count if output swiched to high |
136 | ShutterCounter++; // count if output swiched to high |
136 | } |
137 | } |
137 | FC_StatusFlags2 |= FC_STATUS2_OUT1_ACTIVE; //else FC_StatusFlags2 &= ~FC_STATUS2_OUT1_ACTIVE; // Out1 (J16) -> wird in der SPI zurück gesetzt |
138 | FC_StatusFlags2 |= FC_STATUS2_OUT1_ACTIVE; //else FC_StatusFlags2 &= ~FC_STATUS2_OUT1_ACTIVE; // Out1 (J16) -> wird in der SPI zurück gesetzt |
138 | } |
139 | } |
139 | if(PORTC & (1<<PORTC3)) FC_StatusFlags2 |= FC_STATUS2_OUT2_ACTIVE; else FC_StatusFlags2 &= ~FC_STATUS2_OUT2_ACTIVE; // Out2 (J17) |
140 | if(PORTC & (1<<PORTC3)) FC_StatusFlags2 |= FC_STATUS2_OUT2_ACTIVE; else FC_StatusFlags2 &= ~FC_STATUS2_OUT2_ACTIVE; // Out2 (J17) |
140 | last_portC = PORTC; |
141 | last_portC = PORTC; |
141 | } |
142 | } |
142 | } |
143 | } |
143 | 144 | ||
144 | 145 |