Rev 1133 | 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 | |||
1135 | krheinwald | 5 | uint16_t LED1_Timing = 0; |
1133 | thjac | 6 | uint16_t LED2_Timing = 0; |
1112 | thjac | 7 | |
1133 | thjac | 8 | unsigned char J16Blinkcount = 0, J16Mask = 1; |
9 | unsigned char J17Blinkcount = 0, J17Mask = 1; |
||
10 | unsigned char J16 = 0, J17 = 0; |
||
1112 | thjac | 11 | |
1133 | thjac | 12 | unsigned char lightsEnabled = 0, lightsOn = 0; |
1112 | thjac | 13 | |
1133 | thjac | 14 | extern char MotorenEin; |
1112 | thjac | 15 | |
16 | |||
1133 | 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 | if((enabled && lightsOn) ^ LED_NEGATE_J16) |
||
26 | J16_ON; |
||
27 | else |
||
28 | J16_OFF; |
||
1114 | thjac | 29 | } |
30 | |||
1133 | thjac | 31 | void setJ17( char enabled ) { |
32 | /* if( PARAM_LED_NEGATE ) |
||
33 | enabled = !enabled; |
||
34 | if( enabled && forceEnabled ) |
||
35 | J17_ON; |
||
36 | else |
||
37 | J17_OFF;*/ |
||
38 | |||
39 | if((enabled && lightsOn) ^ 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 |
1133 | thjac | 46 | void LED_Init( void ) { |
47 | // set PC2 & PC3 as output (control of J16 & J17) |
||
48 | DDRC |= (1<<DDC2)|(1<<DDC3); |
||
49 | |||
1118 | krheinwald | 50 | lightsOn = lightsEnabled = 0; |
1133 | thjac | 51 | |
52 | setJ16( 0); |
||
53 | setJ17( 0); |
||
54 | |||
55 | J16Blinkcount = 0; J16Mask = 128; |
||
56 | J17Blinkcount = 0; J17Mask = 128; |
||
1112 | thjac | 57 | } |
58 | |||
1118 | krheinwald | 59 | void checkLightsEnabled(void) { |
1112 | thjac | 60 | |
1118 | krheinwald | 61 | // Mit dem Gier-Stick rechts lassen sich bei stehenden Motoren die LED's ein- und mit links ausschalten |
1133 | thjac | 62 | if( !MotorenEin) { |
63 | if( PARAM_LED_STICK_ENABLED) { |
||
64 | if ( PPM_in[ EE_Parameter.Kanalbelegung[ K_GAS ] ] > 35-120 |
||
65 | && PPM_in[ EE_Parameter.Kanalbelegung[ K_GAS ] ] < 80 ) { |
||
66 | if( PPM_in[ EE_Parameter.Kanalbelegung[ K_GIER ] ] < -75 ) |
||
1118 | krheinwald | 67 | lightsEnabled = 1; |
1133 | thjac | 68 | if( PPM_in[ EE_Parameter.Kanalbelegung[ K_GIER ] ] > 75 ) |
1118 | krheinwald | 69 | lightsEnabled = 0; |
1133 | thjac | 70 | } |
1118 | krheinwald | 71 | } else |
1133 | thjac | 72 | lightsEnabled = 1; |
1118 | krheinwald | 73 | } |
74 | |||
1133 | thjac | 75 | // Die LED's können mit den Motoren ein- ausgeschaltet werden |
76 | if( PARAM_LED_ENGINE_ENABLED) |
||
77 | lightsEnabled = MotorenEin; |
||
1118 | krheinwald | 78 | |
79 | lightsOn = lightsEnabled; |
||
80 | } |
||
81 | |||
1112 | thjac | 82 | // called in UpdateMotors() every 2ms |
1133 | thjac | 83 | void LED_Update( void ) { |
1112 | thjac | 84 | |
1133 | thjac | 85 | static char delay = 0; |
86 | |||
87 | checkLightsEnabled(); |
||
88 | |||
89 | if( !delay-- ) { |
||
1112 | thjac | 90 | |
1133 | thjac | 91 | delay = 9; // 20ms Intervall |
1112 | thjac | 92 | |
1133 | thjac | 93 | // Soll die Unterspannungswarnung zu einem schnelleren Blinken führen? |
94 | // Grenze für Unterspannungswarnung erreicht? |
||
95 | if( PARAM_LED_WARNING_SPEEDUP && UBat < EE_Parameter.UnterspannungsWarnung ) { |
||
96 | if( PARAM_LED_FORCE_WARNING_ENABLED ) // Erzwingt die Aktivierung der Ausgänge |
||
97 | lightsOn = 1; |
||
98 | delay /= PARAM_LED_WARNING_SPEEDUP+1; |
||
99 | } |
||
100 | |||
101 | // J16 |
||
102 | if( EE_Parameter.J16Timing > 250 && Parameter_J16Timing > 230 ) |
||
103 | J16 = EE_Parameter.J16Bitmask & 128; |
||
104 | else if( EE_Parameter.J16Timing > 250 && Parameter_J16Timing < 10 ) |
||
105 | J16 = !( EE_Parameter.J16Bitmask & 128 ); |
||
106 | else if( !J16Blinkcount-- ) { |
||
107 | J16Blinkcount = Parameter_J16Timing-1; |
||
108 | J16Mask = (J16Mask == 1 ? 0x80 : J16Mask >> 1); |
||
109 | J16 = EE_Parameter.J16Bitmask & J16Mask; |
||
110 | } |
||
111 | |||
112 | // J17 |
||
113 | if( EE_Parameter.J17Timing > 250 && Parameter_J17Timing > 230) |
||
114 | J17 = EE_Parameter.J17Bitmask & 128 ; |
||
115 | else if( EE_Parameter.J17Timing > 250 && Parameter_J17Timing < 10) |
||
116 | J17 = !( EE_Parameter.J17Bitmask & 128 ); |
||
117 | else if( !J17Blinkcount-- ) { |
||
118 | J17Blinkcount = Parameter_J17Timing-1; |
||
119 | J17Mask = (J17Mask == 1 ? 0x80 : J17Mask >> 1); |
||
120 | J17 = EE_Parameter.J17Bitmask & J17Mask; |
||
121 | } |
||
122 | } |
||
1116 | krheinwald | 123 | |
1133 | thjac | 124 | // delay: 0...9 - BRIGHTNESS/23: 0-Aus...10-Max - Bei Unterspannung volle Leuchtkraft |
125 | setJ16( J16 && (delay < Parameter_J16Brightness/23 || UBat < EE_Parameter.UnterspannungsWarnung )); |
||
126 | setJ17( J17 && (delay < Parameter_J17Brightness/23 || UBat < EE_Parameter.UnterspannungsWarnung )); |
||
1112 | thjac | 127 | } |