Rev 1118 |
Rev 1131 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
#include <inttypes.h>
#include "main.h"
#include "parameter.h"
unsigned char J16Blinkcount = 0, J16Mask = 1;
unsigned char J17Blinkcount = 0, J17Mask = 1;
unsigned char J16 = 0, J17 = 0;
unsigned char pwmJ16 = 0, pwmJ17 = 0;
static unsigned char pwmtable[32] ={0, 1, 2, 2, 2, 3, 3, 4, 5, 6, 7, 8, 10, 11,
13, 16, 19, 23, 27, 32, 38, 45, 54, 64, 76,
91, 108, 128, 152, 181, 215, 250};
unsigned char J16 = 0, J17 = 0;
unsigned char lightsEnabled = 0, lightsOn = 0;
extern char MotorenEin;
void setJ16(char enabled) {
/* if( PARAM_LED_NEGATE )
enabled = !enabled;
if( enabled && forceEnabled )
J16_ON;
else
J16_OFF;*/
if ((enabled && lightsOn) ^ 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 && lightsOn) ^ 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);
lightsOn = lightsEnabled = 0;
setJ16(0);
setJ17(0);
J16Blinkcount = 0;
J16Mask = 128;
J17Blinkcount = 0;
J17Mask = 128;
}
void checkLightsEnabled(void) {
// Mit dem Gier-Stick rechts lassen sich bei stehenden Motoren die LED's ein- und mit links ausschalten
if (!MotorenEin) {
if (PARAM_LED_STICK_ENABLED) {
if (PPM_in[ EE_Parameter.Kanalbelegung[ K_GAS ] ] > 35 - 125
&& PPM_in[ EE_Parameter.Kanalbelegung[ K_GAS ] ] < 125 - 35) {
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;
}
// Die LED's können mit den Motoren ein- ausgeschaltet werden
if (PARAM_LED_ENGINE_ENABLED)
lightsEnabled = MotorenEin;
lightsOn = lightsEnabled;
}
// called in UpdateMotors() every 2ms
void LED_Update(void) {
static char delay = 0;
checkLightsEnabled();
if (!delay--) {
delay = 9; // 20ms Intervall
// Soll die Unterspannungswarnung zu einem schnelleren Blinken führen?
// Grenze für Unterspannungswarnung erreicht?
if (PARAM_LED_WARNING_SPEEDUP && UBat < EE_Parameter.UnterspannungsWarnung) {
if (PARAM_LED_FORCE_WARNING_ENABLED) // Erzwingt die Aktivierung der Ausgänge
lightsOn = 1;
delay /= PARAM_LED_WARNING_SPEEDUP + 1;
}
// J16
if (EE_Parameter.J16Timing > 250 && Parameter_J16Timing > 230)
J16 = EE_Parameter.J16Bitmask & 128;
else if (EE_Parameter.J16Timing > 250 && Parameter_J16Timing < 10)
J16 = !(EE_Parameter.J16Bitmask & 128);
else if (!J16Blinkcount--) {
J16Blinkcount = Parameter_J16Timing - 1;
J16Mask = (J16Mask == 1 ? 0x80 : J16Mask >> 1);
J16 = EE_Parameter.J16Bitmask & J16Mask;
if (EE_Parameter.J16Bitmask & J16Mask)
pwmJ16 = pwmtable[(Parameter_J16Brightness + 6) / 4];
else
pwmJ16 = 0;
}
// J17
if (EE_Parameter.J17Timing > 250 && Parameter_J17Timing > 230)
J17 = EE_Parameter.J17Bitmask & 128;
else if (EE_Parameter.J17Timing > 250 && Parameter_J17Timing < 10)
J17 = !(EE_Parameter.J17Bitmask & 128);
else if (!J17Blinkcount--) {
J17Blinkcount = Parameter_J17Timing - 1;
J17Mask = (J17Mask == 1 ? 0x80 : J17Mask >> 1);
J17 = EE_Parameter.J17Bitmask & J17Mask;
if (EE_Parameter.J17Bitmask & J17Mask)
pwmJ17 = pwmtable[(Parameter_J17Brightness + 6) / 4];
else
pwmJ17 = 0;
}
}
// delay: 0...9 - BRIGHTNESS/23: 0-Aus...10-Max - Bei Unterspannung volle Leuchtkraft
setJ16(J16 && (delay < Parameter_J16Brightness / 23 || UBat < EE_Parameter.UnterspannungsWarnung));
setJ17(J17 && (delay < Parameter_J17Brightness / 23 || UBat < EE_Parameter.UnterspannungsWarnung));
}