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