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