Subversion Repositories FlightCtrl

Rev

Rev 1133 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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