Rev 1114 |
Rev 1118 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
#include <inttypes.h>
#include "main.h"
#include "parameter.h"
uint16_t LED1_Timing = 0;
uint16_t LED2_Timing = 0;
unsigned char J16Blinkcount = 0, J16Mask = 1;
unsigned char J17Blinkcount = 0, J17Mask = 1;
unsigned char lightsEnabled = 0;
unsigned char forceEnabled = 0;
extern char MotorenEin;
void setJ16( char enabled ) {
/* if( PARAM_LED_NEGATE )
enabled = !enabled;
if( enabled && forceEnabled )
J16_ON;
else
J16_OFF;*/
if((enabled && forceEnabled) ^ LED_NEGATE_J16)
J16_ON;
else
J16_OFF;
}
void setJ17( char enabled ) {
/* if( PARAM_LED_NEGATE )
enabled = !enabled;
if( enabled && forceEnabled )
J17_ON;
else
J17_OFF;*/
if((enabled && forceEnabled) ^ LED_NEGATE_J17)
J17_ON;
else
J17_OFF;
}
// initializes the LED control outputs J16, J17
void LED_Init( void ) {
// set PC2 & PC3 as output (control of J16 & J17)
DDRC |= (1<<DDC2)|(1<<DDC3);
setJ16( 0 );
setJ17( 0 );
J16Blinkcount = 0; J16Mask = 128;
J17Blinkcount = 0; J17Mask = 128;
}
// called in UpdateMotors() every 2ms
void LED_Update( void ) {
static char delay = 0;
static char j16 = 0;
static char j17 = 0;
if( !MotorenEin ) {
/* Mit dem Gier-Stick rechts lassen sich die LED's ein- und mit links ausschalten.
*/
if( PARAM_LED_STICK_ENABLED ) {
if( PPM_in[ EE_Parameter.Kanalbelegung[ K_GAS ] ] > 35-120 &&
PPM_in[ EE_Parameter.Kanalbelegung[ K_GAS ] ] < 80 ) {
if( PPM_in[ EE_Parameter.Kanalbelegung[ K_GIER ] ] < -75 ) {
lightsEnabled = 1;
}
if( PPM_in[ EE_Parameter.Kanalbelegung[ K_GIER ] ] > 75 ) {
lightsEnabled = 0;
}
}
} else {
lightsEnabled = 1;
}
}
if( PARAM_LED_ENGINE_ENABLED ) {
lightsEnabled = MotorenEin;
}
forceEnabled = lightsEnabled;
if( !delay-- ) {
delay = 4; // 10ms Intervall
// Soll die Unterspannungswarnung zu einem schnelleren Blinken führen?
if( PARAM_LED_WARNING_ENABLED ) {
// Grenze für Unterspannungswarnung erreicht?
if( UBat < EE_Parameter.UnterspannungsWarnung ) {
// Erzwingt die Aktivierung der Ausgänge
if( PARAM_LED_FORCE_WARNING_ENABLED )
forceEnabled = 1;
if( PARAM_LED_WARNING_FAST_ENABLED ) {
delay = 1; // 2,5ms Intervall
} else {
delay = 2; // 5ms Intervall
}
}
}
/* J16
*/
if( ( EE_Parameter.J16Timing > 250 ) && ( Parameter_J16Timing > 230 ) ) {
setJ16( EE_Parameter.J16Bitmask & 128 );
} else if( ( EE_Parameter.J16Timing > 250 ) && ( Parameter_J16Timing < 10 ) ) {
setJ16( !( EE_Parameter.J16Bitmask & 128 ) );
} else if( !J16Blinkcount-- ) {
J16Blinkcount = Parameter_J16Timing-1;
if( J16Mask == 1 )
J16Mask = 128;
else
J16Mask /= 2;
j16 = J16Mask & EE_Parameter.J16Bitmask;
}
/* J17
*/
if( ( EE_Parameter.J17Timing > 250 ) && ( Parameter_J17Timing > 230 ) ) {
setJ17( EE_Parameter.J17Bitmask & 128 );
} else if( ( EE_Parameter.J17Timing > 250 ) && ( Parameter_J17Timing < 10 ) ) {
setJ17( !( EE_Parameter.J17Bitmask & 128 ) );
} else if( !J17Blinkcount-- ) {
J17Blinkcount = Parameter_J17Timing-1;
if( J17Mask == 1 )
J17Mask = 128;
else
J17Mask /= 2;
j17 = J17Mask & EE_Parameter.J17Bitmask;
}
}
/*delay: 0...4 - BRIGHTNESS: 0-Aus...5-Max*/
setJ16( j16 && (delay < PARAM_LED_BRIGHTNESS_J16 || UBat < EE_Parameter.UnterspannungsWarnung ));
setJ17( j17 && (delay < PARAM_LED_BRIGHTNESS_J17 || UBat < EE_Parameter.UnterspannungsWarnung ));
}