Rev 1140 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1140 | Rev 1142 | ||
---|---|---|---|
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 | void checkLightsEnabled(void) { |
43 | static inline void checkLightsEnabled(void) { |
44 | 44 | ||
45 | // Mit dem Gier-Stick rechts lassen sich bei stehenden Motoren die LED's ein- und mit links ausschalten |
45 | // Mit dem Gier-Stick rechts lassen sich bei stehenden Motoren die LED's ein- und mit links ausschalten |
46 | if (!MotorenEin) { |
46 | if (!MotorenEin) { |
47 | if (PARAM_LED_STICK_ENABLED) { |
47 | if (PARAM_LED_STICK_ENABLED) { |
48 | if (PPM_in[ EE_Parameter.Kanalbelegung[ K_GAS ] ] > 35 - 120 |
48 | if (PPM_in[ EE_Parameter.Kanalbelegung[ K_GAS ] ] > 35 - 120 |
49 | && PPM_in[ EE_Parameter.Kanalbelegung[ K_GAS ] ] < 120 - 35) { |
49 | && PPM_in[ EE_Parameter.Kanalbelegung[ K_GAS ] ] < 120 - 35) { |
50 | if (PPM_in[ EE_Parameter.Kanalbelegung[ K_GIER ] ] < -75) |
50 | if (PPM_in[ EE_Parameter.Kanalbelegung[ K_GIER ] ] < -75) |
51 | lightsEnabled = 1; |
51 | lightsEnabled = 1; |
52 | if (PPM_in[ EE_Parameter.Kanalbelegung[ K_GIER ] ] > 75) |
52 | if (PPM_in[ EE_Parameter.Kanalbelegung[ K_GIER ] ] > 75) |
53 | lightsEnabled = 0; |
53 | lightsEnabled = 0; |
54 | } |
54 | } |
55 | } else |
55 | } else |
56 | lightsEnabled = 1; |
56 | lightsEnabled = 1; |
57 | } |
57 | } |
58 | 58 | ||
59 | // Die LED's können mit den Motoren ein- ausgeschaltet werden |
59 | // Die LED's können mit den Motoren ein- ausgeschaltet werden |
60 | if (PARAM_LED_ENGINE_ENABLED) |
60 | if (PARAM_LED_ENGINE_ENABLED) |
61 | lightsEnabled = MotorenEin; |
61 | lightsEnabled = MotorenEin; |
62 | 62 | ||
63 | lightsOn = lightsEnabled; |
63 | lightsOn = lightsEnabled; |
64 | } |
64 | } |
65 | 65 | ||
66 | // called in UpdateMotors() every 2ms |
66 | // called in UpdateMotors() every 2ms |
67 | 67 | ||
68 | void LED_Update(void) { |
68 | void LED_Update(void) { |
69 | 69 | ||
70 | static char delay = 0; |
70 | static char delay = 0; |
71 | 71 | ||
72 | checkLightsEnabled(); |
72 | checkLightsEnabled(); |
73 | 73 | ||
74 | if (!delay--) { |
74 | if (!delay--) { |
75 | 75 | ||
76 | delay = 9; // 20ms Intervall |
76 | delay = 9; // 20ms Intervall |
77 | 77 | ||
78 | // Soll die Unterspannungswarnung zu einem schnelleren Blinken führen? |
78 | // Soll die Unterspannungswarnung zu einem schnelleren Blinken führen? |
79 | // Grenze für Unterspannungswarnung erreicht? |
79 | // Grenze für Unterspannungswarnung erreicht? |
80 | if (PARAM_LED_WARNING_SPEEDUP && UBat < EE_Parameter.UnterspannungsWarnung) { |
80 | if (PARAM_LED_WARNING_SPEEDUP && UBat < EE_Parameter.UnterspannungsWarnung) { |
81 | if (PARAM_LED_FORCE_WARNING_ENABLED) // Erzwingt die Aktivierung der Ausgänge |
81 | if (PARAM_LED_FORCE_WARNING_ENABLED) // Erzwingt die Aktivierung der Ausgänge |
82 | lightsOn = 1; |
82 | lightsOn = 1; |
83 | delay /= PARAM_LED_WARNING_SPEEDUP + 1; |
83 | delay /= PARAM_LED_WARNING_SPEEDUP + 1; |
84 | } |
84 | } |
85 | 85 | ||
86 | // J16 |
86 | // J16 |
87 | if (EE_Parameter.J16Timing > 250 && Parameter_J16Timing > 230) |
87 | if (EE_Parameter.J16Timing > 250 && Parameter_J16Timing > 230) |
88 | J16 = EE_Parameter.J16Bitmask & 128; |
88 | J16 = EE_Parameter.J16Bitmask & 128; |
89 | else if (EE_Parameter.J16Timing > 250 && Parameter_J16Timing < 10) |
89 | else if (EE_Parameter.J16Timing > 250 && Parameter_J16Timing < 10) |
90 | J16 = !(EE_Parameter.J16Bitmask & 128); |
90 | J16 = !(EE_Parameter.J16Bitmask & 128); |
91 | else if (!J16Blinkcount--) { |
91 | else if (!J16Blinkcount--) { |
92 | J16Blinkcount = Parameter_J16Timing - 1; |
92 | J16Blinkcount = Parameter_J16Timing - 1; |
93 | J16Mask = (J16Mask == 1 ? 0x80 : J16Mask >> 1); |
93 | J16Mask = (J16Mask == 1 ? 0x80 : J16Mask >> 1); |
94 | 94 | ||
95 | J16 = EE_Parameter.J16Bitmask & J16Mask; |
95 | J16 = EE_Parameter.J16Bitmask & J16Mask; |
96 | 96 | ||
97 | if (EE_Parameter.J16Bitmask & J16Mask) |
97 | if (EE_Parameter.J16Bitmask & J16Mask) |
98 | J16Brightness = Parameter_J16Brightness / 23; |
98 | J16Brightness = Parameter_J16Brightness / 23; |
99 | else |
99 | else |
100 | J16Brightness = 0; |
100 | J16Brightness = 0; |
101 | } |
101 | } |
102 | 102 | ||
103 | // J17 |
103 | // J17 |
104 | if (EE_Parameter.J17Timing > 250 && Parameter_J17Timing > 230) |
104 | if (EE_Parameter.J17Timing > 250 && Parameter_J17Timing > 230) |
105 | J17 = EE_Parameter.J17Bitmask & 128; |
105 | J17 = EE_Parameter.J17Bitmask & 128; |
106 | else if (EE_Parameter.J17Timing > 250 && Parameter_J17Timing < 10) |
106 | else if (EE_Parameter.J17Timing > 250 && Parameter_J17Timing < 10) |
107 | J17 = !(EE_Parameter.J17Bitmask & 128); |
107 | J17 = !(EE_Parameter.J17Bitmask & 128); |
108 | else if (!J17Blinkcount--) { |
108 | else if (!J17Blinkcount--) { |
109 | J17Blinkcount = Parameter_J17Timing - 1; |
109 | J17Blinkcount = Parameter_J17Timing - 1; |
110 | J17Mask = (J17Mask == 1 ? 0x80 : J17Mask >> 1); |
110 | J17Mask = (J17Mask == 1 ? 0x80 : J17Mask >> 1); |
111 | 111 | ||
112 | J17 = EE_Parameter.J17Bitmask & J17Mask; |
112 | J17 = EE_Parameter.J17Bitmask & J17Mask; |
113 | 113 | ||
114 | if (EE_Parameter.J17Bitmask & J17Mask) |
114 | if (EE_Parameter.J17Bitmask & J17Mask) |
115 | J17Brightness = Parameter_J17Brightness / 23; |
115 | J17Brightness = Parameter_J17Brightness / 23; |
116 | else |
116 | else |
117 | J17Brightness = 0; |
117 | J17Brightness = 0; |
118 | } |
118 | } |
119 | } |
119 | } |
120 | 120 | ||
121 | // delay: 0...9 - BRIGHTNESS/23: 0-Aus...10-Max - Bei Unterspannung volle Leuchtkraft |
121 | // delay: 0...9 - BRIGHTNESS/23: 0-Aus...10-Max - Bei Unterspannung volle Leuchtkraft |
122 | setJ16(J16 && (delay < J16Brightness || UBat < EE_Parameter.UnterspannungsWarnung)); |
122 | setJ16(J16 && (delay < J16Brightness || UBat < EE_Parameter.UnterspannungsWarnung)); |
123 | setJ17(J17 && (delay < J17Brightness || UBat < EE_Parameter.UnterspannungsWarnung)); |
123 | setJ17(J17 && (delay < J17Brightness || UBat < EE_Parameter.UnterspannungsWarnung)); |
124 | } |
124 | } |
125 | 125 |