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