Rev 1112 | Rev 1116 | 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 ) { |
18 | if( PARAM_LED_NEGATE ) |
||
19 | enabled = !enabled; |
||
20 | if( enabled && forceEnabled ) |
||
21 | J16_ON; |
||
22 | else |
||
23 | J16_OFF; |
||
24 | } |
||
25 | |||
26 | void setJ17( char enabled ) { |
||
27 | if( PARAM_LED_NEGATE ) |
||
28 | enabled = !enabled; |
||
29 | if( enabled && forceEnabled ) |
||
30 | J17_ON; |
||
31 | else |
||
32 | J17_OFF; |
||
33 | } |
||
34 | |||
1112 | thjac | 35 | // initializes the LED control outputs J16, J17 |
36 | void LED_Init( void ) { |
||
37 | // set PC2 & PC3 as output (control of J16 & J17) |
||
38 | DDRC |= (1<<DDC2)|(1<<DDC3); |
||
1114 | thjac | 39 | setJ16( 0 ); |
40 | setJ17( 0 ); |
||
1112 | thjac | 41 | J16Blinkcount = 0; J16Mask = 128; |
42 | J17Blinkcount = 0; J17Mask = 128; |
||
43 | } |
||
44 | |||
45 | |||
46 | // called in UpdateMotors() every 2ms |
||
47 | void LED_Update( void ) { |
||
48 | |||
1114 | thjac | 49 | static char delay = 0; |
50 | |||
1112 | thjac | 51 | if( !MotorenEin ) { |
52 | |||
53 | /* Mit dem Gier-Stick links lassen sich die LED's ein- und ausschalten. |
||
54 | */ |
||
55 | if( PARAM_LED_STICK_ENABLED ) { |
||
56 | |||
57 | if( PPM_in[ EE_Parameter.Kanalbelegung[ K_GAS ] ] > 35-120 && |
||
58 | PPM_in[ EE_Parameter.Kanalbelegung[ K_GAS ] ] < 80 ) { |
||
59 | |||
60 | if( PPM_in[ EE_Parameter.Kanalbelegung[ K_GIER ] ] < -75 ) { |
||
61 | lightsEnabled = 1; |
||
62 | } |
||
63 | |||
64 | if( PPM_in[ EE_Parameter.Kanalbelegung[ K_GIER ] ] > 75 ) { |
||
65 | lightsEnabled = 0; |
||
66 | } |
||
67 | } |
||
68 | } else { |
||
69 | lightsEnabled = 1; |
||
70 | } |
||
71 | } |
||
72 | |||
73 | if( PARAM_LED_ENGINE_ENABLED ) { |
||
74 | lightsEnabled = MotorenEin; |
||
75 | } |
||
1114 | thjac | 76 | |
77 | forceEnabled = lightsEnabled; |
||
78 | |||
1112 | thjac | 79 | if( !delay-- ) { |
80 | |||
81 | delay = 4; // 10ms Intervall |
||
82 | |||
83 | // Soll die Unterspannungswarnung zu einem schnelleren Blinken führen? |
||
84 | if( PARAM_LED_WARNING_ENABLED ) { |
||
85 | |||
86 | // Grenze für Unterspannungswarnung erreicht? |
||
87 | if( UBat < EE_Parameter.UnterspannungsWarnung ) { |
||
88 | |||
1114 | thjac | 89 | // Erzwingt die Aktivierung der Ausgänge |
90 | if( PARAM_LED_FORCE_WARNING_ENABLED ) |
||
91 | forceEnabled = 1; |
||
92 | |||
93 | if( PARAM_LED_WARNING_FAST_ENABLED ) { |
||
94 | delay = 1; // 2,5ms Intervall |
||
95 | } else { |
||
96 | delay = 2; // 5ms Intervall |
||
97 | } |
||
1112 | thjac | 98 | } |
99 | } |
||
100 | |||
101 | /* J16 |
||
102 | */ |
||
103 | if( ( EE_Parameter.J16Timing > 250 ) && ( Parameter_J16Timing > 230 ) ) { |
||
1114 | thjac | 104 | setJ16( EE_Parameter.J16Bitmask & 128 ); |
1112 | thjac | 105 | } else if( ( EE_Parameter.J16Timing > 250 ) && ( Parameter_J16Timing < 10 ) ) { |
1114 | thjac | 106 | setJ16( !( EE_Parameter.J16Bitmask & 128 ) ); |
1112 | thjac | 107 | } else if( !J16Blinkcount-- ) { |
108 | |||
109 | J16Blinkcount = Parameter_J16Timing-1; |
||
110 | |||
111 | if( J16Mask == 1 ) |
||
112 | J16Mask = 128; |
||
113 | else |
||
114 | J16Mask /= 2; |
||
1114 | thjac | 115 | setJ16( J16Mask & EE_Parameter.J16Bitmask ); |
1112 | thjac | 116 | } |
117 | |||
118 | /* J17 |
||
119 | */ |
||
120 | if( ( EE_Parameter.J17Timing > 250 ) && ( Parameter_J17Timing > 230 ) ) { |
||
1114 | thjac | 121 | setJ17( EE_Parameter.J17Bitmask & 128 ); |
1112 | thjac | 122 | } else if( ( EE_Parameter.J17Timing > 250 ) && ( Parameter_J17Timing < 10 ) ) { |
1114 | thjac | 123 | setJ17( !( EE_Parameter.J17Bitmask & 128 ) ); |
1112 | thjac | 124 | } else if( !J17Blinkcount-- ) { |
125 | |||
126 | J17Blinkcount = Parameter_J17Timing-1; |
||
127 | |||
128 | if( J17Mask == 1 ) |
||
129 | J17Mask = 128; |
||
130 | else |
||
131 | J17Mask /= 2; |
||
1114 | thjac | 132 | setJ17( J17Mask & EE_Parameter.J17Bitmask ); |
1112 | thjac | 133 | } |
134 | } |
||
135 | } |