Rev 1152 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1152 | Rev 1163 | ||
---|---|---|---|
1 | #include <inttypes.h> |
1 | #include <inttypes.h> |
2 | #include "main.h" |
2 | #include "main.h" |
3 | #include "parameter.h" |
3 | #include "parameter.h" |
4 | 4 | ||
5 | unsigned char J16Blinkcount = 0, J16Mask = 1, J16Brightness = 0, J16 = 0; |
5 | unsigned char J16Blinkcount = 0, J16Mask = 1, J16Brightness = 0, J16 = 0; |
6 | unsigned char J17Blinkcount = 0, J17Mask = 1, J17Brightness = 0, J17 = 0; |
6 | unsigned char J17Blinkcount = 0, J17Mask = 1, J17Brightness = 0, J17 = 0; |
7 | 7 | ||
8 | unsigned char lightsEnabled = 0, lightsOn = 0; |
8 | unsigned char lightsEnabled = 0, lightsOn = 0; |
9 | 9 | ||
10 | extern char MotorenEin; |
10 | extern char MotorenEin; |
11 | 11 | ||
12 | void setJ16(char enabled) { |
12 | void setJ16(char enabled) { |
13 | if ((enabled && lightsOn) ^ LED_NEGATE_J16) |
13 | if ((enabled && lightsOn) ^ LED_NEGATE_J16) |
14 | J16_ON; |
14 | J16_ON; |
15 | else |
15 | else |
16 | J16_OFF; |
16 | J16_OFF; |
17 | } |
17 | } |
18 | 18 | ||
19 | void setJ17(char enabled) { |
19 | void setJ17(char enabled) { |
20 | if ((enabled && lightsOn) ^ LED_NEGATE_J17) |
20 | if ((enabled && lightsOn) ^ LED_NEGATE_J17) |
21 | J17_ON; |
21 | J17_ON; |
22 | else |
22 | else |
23 | J17_OFF; |
23 | J17_OFF; |
24 | } |
24 | } |
25 | 25 | ||
26 | // initializes the LED control outputs J16, J17 |
26 | // initializes the LED control outputs J16, J17 |
27 | 27 | ||
28 | void LED_Init(void) { |
28 | void LED_Init(void) { |
29 | // set PC2 & PC3 as output (control of J16 & J17) |
29 | // set PC2 & PC3 as output (control of J16 & J17) |
30 | DDRC |= (1 << DDC2) | (1 << DDC3); |
30 | DDRC |= (1 << DDC2) | (1 << DDC3); |
31 | 31 | ||
32 | lightsOn = lightsEnabled = 0; |
32 | lightsOn = lightsEnabled = 0; |
33 | 33 | ||
34 | setJ16(0); |
34 | setJ16(0); |
35 | setJ17(0); |
35 | setJ17(0); |
36 | 36 | ||
37 | J16Blinkcount = 0; |
37 | J16Blinkcount = 0; |
38 | J16Mask = 128; |
38 | J16Mask = 128; |
39 | J17Blinkcount = 0; |
39 | J17Blinkcount = 0; |
40 | J17Mask = 128; |
40 | J17Mask = 128; |
41 | } |
41 | } |
42 | 42 | ||
43 | static inline void checkLightsEnabled(void) { |
43 | static inline void checkLightsEnabled(void) { |
- | 44 | ||
- | 45 | // Die LED's können mit den Motoren ein- ausgeschaltet werden |
|
- | 46 | if (PARAM_LED_ENGINE_ENABLED) |
|
44 | 47 | lightsEnabled = MotorenEin; |
|
- | 48 | // Die LED's können mit den Motoren ein- ausgeschaltet werden |
|
45 | // Mit dem Gier-Stick rechts lassen sich bei stehenden Motoren die LED's ein- und mit links ausschalten |
49 | else if (PARAM_LED_STICK_ENABLED) { |
46 | if (!MotorenEin) { |
- | |
47 | if (PARAM_LED_STICK_ENABLED) { |
50 | if (!MotorenEin) { |
48 | if (PPM_in[ EE_Parameter.Kanalbelegung[ K_GAS ] ] > 35 - 120 |
51 | if (PPM_in[ EE_Parameter.Kanalbelegung[ K_GAS ] ] > 35 - 120 |
49 | && PPM_in[ EE_Parameter.Kanalbelegung[ K_GAS ] ] < 120 - 35) { |
52 | && PPM_in[ EE_Parameter.Kanalbelegung[ K_GAS ] ] < 120 - 35) { |
50 | if (PPM_in[ EE_Parameter.Kanalbelegung[ K_GIER ] ] < -75) |
53 | if (PPM_in[ EE_Parameter.Kanalbelegung[ K_GIER ] ] < -75) |
51 | lightsEnabled = 1; |
54 | lightsEnabled = 1; |
52 | if (PPM_in[ EE_Parameter.Kanalbelegung[ K_GIER ] ] > 75) |
55 | if (PPM_in[ EE_Parameter.Kanalbelegung[ K_GIER ] ] > 75) |
53 | lightsEnabled = 0; |
56 | lightsEnabled = 0; |
54 | } |
57 | } |
- | 58 | } |
|
55 | } else |
59 | } else |
56 | lightsEnabled = 1; |
60 | lightsEnabled = 1; |
57 | } |
- | |
58 | - | ||
59 | // Die LED's können mit den Motoren ein- ausgeschaltet werden |
- | |
60 | if (PARAM_LED_ENGINE_ENABLED) |
- | |
61 | lightsEnabled = MotorenEin; |
- | |
62 | 61 | ||
63 | lightsOn = lightsEnabled; |
62 | lightsOn = lightsEnabled; |
64 | } |
63 | } |
65 | 64 | ||
66 | // called in UpdateMotors() every 2ms |
65 | // called in UpdateMotors() every 2ms |
67 | 66 | ||
68 | void LED_Update(void) { |
67 | void LED_Update(void) { |
69 | 68 | ||
70 | static char delay = 0; |
69 | static char delay = 0; |
71 | 70 | ||
72 | if (!delay--) { |
71 | if (!delay--) { |
73 | 72 | ||
74 | delay = 9; // 20ms Intervall |
73 | delay = 9; // 20ms Intervall |
75 | 74 | ||
76 | checkLightsEnabled(); |
75 | checkLightsEnabled(); |
77 | 76 | ||
78 | // Soll die Unterspannungswarnung zu einem schnelleren Blinken führen? |
77 | // Soll die Unterspannungswarnung zu einem schnelleren Blinken führen? |
79 | // Grenze für Unterspannungswarnung erreicht? |
78 | // Grenze für Unterspannungswarnung erreicht? |
80 | if (PARAM_LED_WARNING_SPEEDUP && UBat < EE_Parameter.UnterspannungsWarnung) { |
79 | if (PARAM_LED_WARNING_SPEEDUP && UBat < EE_Parameter.UnterspannungsWarnung) { |
81 | if (PARAM_LED_FORCE_WARNING_ENABLED) // Erzwingt die Aktivierung der Ausgänge |
80 | if (PARAM_LED_FORCE_WARNING_ENABLED) // Erzwingt die Aktivierung der Ausgänge |
82 | lightsOn = 1; |
81 | lightsOn = 1; |
83 | delay /= PARAM_LED_WARNING_SPEEDUP + 1; |
82 | delay /= PARAM_LED_WARNING_SPEEDUP + 1; |
84 | } |
83 | } |
85 | 84 | ||
86 | // J16 |
85 | // J16 |
87 | if (EE_Parameter.J16Timing > 250 && Parameter_J16Timing > 230) |
86 | if (EE_Parameter.J16Timing > 250 && Parameter_J16Timing > 230) |
88 | J16 = EE_Parameter.J16Bitmask & 128; |
87 | J16 = EE_Parameter.J16Bitmask & 128; |
89 | else if (EE_Parameter.J16Timing > 250 && Parameter_J16Timing < 10) |
88 | else if (EE_Parameter.J16Timing > 250 && Parameter_J16Timing < 10) |
90 | J16 = !(EE_Parameter.J16Bitmask & 128); |
89 | J16 = !(EE_Parameter.J16Bitmask & 128); |
91 | else if (!J16Blinkcount--) { |
90 | else if (!J16Blinkcount--) { |
92 | J16Blinkcount = Parameter_J16Timing - 1; |
91 | J16Blinkcount = Parameter_J16Timing - 1; |
93 | J16Mask = (J16Mask == 1 ? 0x80 : J16Mask >> 1); |
92 | J16Mask = (J16Mask == 1 ? 0x80 : J16Mask >> 1); |
94 | 93 | ||
95 | J16 = EE_Parameter.J16Bitmask & J16Mask; |
94 | J16 = EE_Parameter.J16Bitmask & J16Mask; |
96 | - | ||
97 | if (EE_Parameter.J16Bitmask & J16Mask) |
- | |
98 | J16Brightness = Parameter_J16Brightness / 23; |
- | |
99 | else |
- | |
100 | J16Brightness = 0; |
- | |
101 | } |
95 | } |
- | 96 | ||
- | 97 | J16Brightness = EE_Parameter.J16Bitmask & J16Mask ? Parameter_J16Brightness / 23 : 0; |
|
102 | 98 | ||
103 | // J17 |
99 | // J17 |
104 | if (EE_Parameter.J17Timing > 250 && Parameter_J17Timing > 230) |
100 | if (EE_Parameter.J17Timing > 250 && Parameter_J17Timing > 230) |
105 | J17 = EE_Parameter.J17Bitmask & 128; |
101 | J17 = EE_Parameter.J17Bitmask & 128; |
106 | else if (EE_Parameter.J17Timing > 250 && Parameter_J17Timing < 10) |
102 | else if (EE_Parameter.J17Timing > 250 && Parameter_J17Timing < 10) |
107 | J17 = !(EE_Parameter.J17Bitmask & 128); |
103 | J17 = !(EE_Parameter.J17Bitmask & 128); |
108 | else if (!J17Blinkcount--) { |
104 | else if (!J17Blinkcount--) { |
109 | J17Blinkcount = Parameter_J17Timing - 1; |
105 | J17Blinkcount = Parameter_J17Timing - 1; |
110 | J17Mask = (J17Mask == 1 ? 0x80 : J17Mask >> 1); |
106 | J17Mask = (J17Mask == 1 ? 0x80 : J17Mask >> 1); |
111 | 107 | ||
112 | J17 = EE_Parameter.J17Bitmask & J17Mask; |
108 | J17 = EE_Parameter.J17Bitmask & J17Mask; |
113 | - | ||
114 | if (EE_Parameter.J17Bitmask & J17Mask) |
- | |
115 | J17Brightness = Parameter_J17Brightness / 23; |
- | |
116 | else |
- | |
117 | J17Brightness = 0; |
- | |
118 | } |
109 | } |
- | 110 | ||
- | 111 | J17Brightness = EE_Parameter.J17Bitmask & J17Mask ? Parameter_J17Brightness / 23 : 0; |
|
119 | } |
112 | } |
120 | 113 | ||
121 | // delay: 0...9 - BRIGHTNESS/23: 0-Aus...10-Max - Bei Unterspannung volle Leuchtkraft |
114 | // delay: 0...9 - BRIGHTNESS/23: 0-Aus...10-Max - Bei Unterspannung volle Leuchtkraft |
122 | setJ16(J16 && (delay < J16Brightness || UBat < EE_Parameter.UnterspannungsWarnung)); |
115 | setJ16(J16 && (delay < J16Brightness || UBat < EE_Parameter.UnterspannungsWarnung)); |
123 | setJ17(J17 && (delay < J17Brightness || UBat < EE_Parameter.UnterspannungsWarnung)); |
116 | setJ17(J17 && (delay < J17Brightness || UBat < EE_Parameter.UnterspannungsWarnung)); |
124 | } |
117 | } |
125 | 118 |