Subversion Repositories FlightCtrl

Rev

Rev 1118 | Rev 1131 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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