2,28 → 2,41 |
#include "output.h" |
#include "eeprom.h" |
#include "timer0.h" |
uint8_t flashCnt[2], flashMask[2]; |
|
// To access the DebugOut struct. |
#include "uart0.h" |
uint8_t flashCnt[2], flashMask[2]; |
// initializes the LED control outputs J16, J17 |
DebugOut_t debugOut; |
|
void output_init(void) { |
// set PC2 & PC3 as output (control of J16 & J17) |
DDRC |= (1 << DDC2) | (1 << DDC3); |
OUTPUT_SET(0,0); |
OUTPUT_SET(1,0); |
outputSet(0,0); |
outputSet(1,0); |
flashCnt[0] = flashCnt[1] = 0; |
flashMask[0] = flashMask[1] = 128; |
} |
|
void flashingLight(uint8_t port, uint8_t timing, uint8_t bitmask, |
uint8_t manual) { |
void outputSet(uint8_t num, uint8_t state) { |
if (staticParams.outputFlags & (OUTPUTFLAGS_INVERT_0 << num)) { |
if (state) OUTPUT_LOW(num) else OUTPUT_HIGH(num); |
} else { |
if (state) OUTPUT_HIGH(num) else OUTPUT_LOW(num); |
} |
if (staticParams.outputFlags & OUTPUTFLAGS_USE_ONBOARD_LEDS) { |
if (num) { |
if (state) GRN_ON else GRN_OFF; |
} else { |
if (state) RED_ON else RED_OFF; |
} |
} |
} |
|
void flashingLight(uint8_t port, uint8_t timing, uint8_t bitmask, uint8_t manual) { |
if (timing > 250 && manual > 230) { |
// "timing" is set to "manual" and the value is very high --> Set to the value in bitmask bit 7. |
OUTPUT_SET(port, bitmask & 128); |
// "timing" is set to "manual (a variable)" and the value is very high --> Set to the value in bitmask bit 7. |
outputSet(port, 1); |
} else if (timing > 250 && manual < 10) { |
// "timing" is set to "manual" and the value is very low --> Set to the negated value in bitmask bit 7. |
OUTPUT_SET(port, !(bitmask & 128)); |
// "timing" is set to "manual" (a variable) and the value is very low --> Set to the negated value in bitmask bit 7. |
outputSet(port, 0); |
} else if (!flashCnt[port]--) { |
// rotating mask over bitmask... |
flashCnt[port] = timing - 1; |
31,44 → 44,36 |
flashMask[port] = 128; |
else |
flashMask[port] >>= 1; |
OUTPUT_SET(port, flashMask[port] & bitmask); |
outputSet(port, flashMask[port] & bitmask); |
} |
} |
|
void flashingLights(void) { |
void output_update(void) { |
static int8_t delay = 0; |
if (!delay--) { // 10 ms intervals |
delay = 4; |
flashingLight(0, staticParams.J16Timing, staticParams.J16Bitmask, |
dynamicParams.J16Timing); |
flashingLight(1, staticParams.J17Timing, staticParams.J17Bitmask, |
dynamicParams.J17Timing); |
} |
} |
|
void output_update(void) { |
if (!DIGITAL_DEBUG_MASK) { |
// If there is a warning beep, also flash it. |
if (beepTime) { |
if (beepTime & beepModulation) { |
OUTPUT_SET(0, 1); |
OUTPUT_SET(1, 1); |
} else { |
OUTPUT_SET(0, 0); |
OUTPUT_SET(1, 0); |
} |
}else |
flashingLights(); |
} |
else if (DIGITAL_DEBUG_MASK == DEBUG_LEDTEST_ON) { |
OUTPUT_SET(0, 1); |
OUTPUT_SET(1, 1); |
} else if (DIGITAL_DEBUG_MASK == DEBUG_LEDTEST_OFF) { |
OUTPUT_SET(0, 0); |
OUTPUT_SET(1, 0); |
if (staticParams.outputFlags & OUTPUTFLAGS_TEST_ON) { |
outputSet(0, 1); |
outputSet(1, 1); |
} else if (staticParams.outputFlags & OUTPUTFLAGS_TEST_OFF) { |
outputSet(0, 0); |
outputSet(1, 0); |
} else { |
OUTPUT_SET(0, DebugOut.Digital[0] & DIGITAL_DEBUG_MASK); |
OUTPUT_SET(1, DebugOut.Digital[1] & DIGITAL_DEBUG_MASK); |
if (staticParams.outputFlags & OUTPUTFLAGS_FLASH_0_AT_BEEP && beepModulation != BEEP_MODULATION_NONE) { |
flashingLight(0, 25, 0x55, 25); |
} else if (staticParams.outputDebugMask) { |
outputSet(0, debugOut.digital[0] & staticParams.outputDebugMask); |
} else if (!delay) { |
flashingLight(0, staticParams.outputFlash[0].timing, staticParams.outputFlash[0].bitmask, dynamicParams.output0Timing); |
} |
if (staticParams.outputFlags & OUTPUTFLAGS_FLASH_1_AT_BEEP && beepModulation != BEEP_MODULATION_NONE) { |
flashingLight(1, 25, 0x55, 25); |
} else if (staticParams.outputDebugMask) { |
outputSet(1, debugOut.digital[1] & staticParams.outputDebugMask); |
} else if (!delay) { |
flashingLight(1, staticParams.outputFlash[1].timing, staticParams.outputFlash[1].bitmask, dynamicParams.output1Timing); |
} |
} |
} |
|
93,27 → 98,17 |
* Beep the R/C alarm signal |
*/ |
void beepRCAlarm(void) { |
if(beepModulation == 0xFFFF) { // If not already beeping an alarm signal (?) |
if(beepModulation == BEEP_MODULATION_NONE) { // If not already beeping an alarm signal (?) |
beepTime = 15000; // 1.5 seconds |
beepModulation = 0x0C00; |
beepModulation = BEEP_MODULATION_RCALARM; |
} |
} |
|
/* |
* Beep the I2C bus error signal |
*/ |
void beepI2CAlarm(void) { |
if((beepModulation == 0xFFFF) && (MKFlags & MKFLAG_MOTOR_RUN)) { |
beepTime = 10000; // 1 second |
beepModulation = 0x0080; |
} |
} |
|
/* |
* Beep the battery low alarm signal |
*/ |
void beepBatteryAlarm(void) { |
beepModulation = 0x0300; |
beepModulation = BEEP_MODULATION_BATTERYALARM; |
if(!beepTime) { |
beepTime = 6000; // 0.6 seconds |
} |
123,7 → 118,7 |
* Beep the EEPROM checksum alarm |
*/ |
void beepEEPROMAlarm(void) { |
beepModulation = 0x0007; |
beepModulation = BEEP_MODULATION_EEPROMALARM; |
if(!beepTime) { |
beepTime = 6000; // 0.6 seconds |
} |