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