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