Rev 1116 | Rev 1125 | 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; |
||
1118 | krheinwald | 10 | unsigned char J16 = 0, J17 = 0; |
1112 | thjac | 11 | |
1118 | krheinwald | 12 | unsigned char lightsEnabled = 0, lightsOn = 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 | |||
1118 | krheinwald | 25 | if((enabled && lightsOn) ^ LED_NEGATE_J16) |
1116 | krheinwald | 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 | |||
1118 | krheinwald | 39 | if((enabled && lightsOn) ^ LED_NEGATE_J17) |
1116 | krheinwald | 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); |
1118 | krheinwald | 49 | |
50 | lightsOn = lightsEnabled = 0; |
||
51 | |||
52 | setJ16( 0); |
||
53 | setJ17( 0); |
||
54 | |||
1116 | krheinwald | 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 |
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 ) |
||
67 | lightsEnabled = 1; |
||
68 | if( PPM_in[ EE_Parameter.Kanalbelegung[ K_GIER ] ] > 75 ) |
||
69 | lightsEnabled = 0; |
||
70 | } |
||
71 | } else |
||
72 | lightsEnabled = 1; |
||
73 | } |
||
74 | |||
75 | // Die LED's können mit den Motoren ein- ausgeschaltet werden |
||
76 | if( PARAM_LED_ENGINE_ENABLED) |
||
77 | lightsEnabled = MotorenEin; |
||
78 | |||
79 | lightsOn = lightsEnabled; |
||
80 | } |
||
81 | |||
1112 | thjac | 82 | // called in UpdateMotors() every 2ms |
83 | void LED_Update( void ) { |
||
84 | |||
1114 | thjac | 85 | static char delay = 0; |
86 | |||
1118 | krheinwald | 87 | checkLightsEnabled(); |
1114 | thjac | 88 | |
1112 | thjac | 89 | if( !delay-- ) { |
90 | |||
1118 | krheinwald | 91 | delay = 9; // 20ms Intervall |
1112 | thjac | 92 | |
93 | // Soll die Unterspannungswarnung zu einem schnelleren Blinken führen? |
||
1118 | krheinwald | 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; |
||
1112 | thjac | 99 | } |
100 | |||
1118 | krheinwald | 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; |
||
1112 | thjac | 110 | } |
111 | |||
1118 | krheinwald | 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; |
||
1112 | thjac | 121 | } |
122 | } |
||
1116 | krheinwald | 123 | |
1118 | krheinwald | 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 | } |