static void applyLedGpsLayer(bool updateNow, uint32_t *timer) { static uint8_t gpsFlashCounter = 0; static uint8_t gpsPauseCounter = 0; const uint8_t blinkPauseLength = 4; if (updateNow) { if (gpsPauseCounter > 0) { gpsPauseCounter--; } else if (gpsFlashCounter >= GPS_numSat) { gpsFlashCounter = 0; gpsPauseCounter = blinkPauseLength; } else { gpsFlashCounter++; gpsPauseCounter = 1; } *timer += LED_STRIP_HZ(2.5); } const hsvColor_t *gpsColor; if (GPS_numSat == 0 || !sensors(SENSOR_GPS)) { gpsColor = getSC(LED_SCOLOR_GPSNOSATS); } else { bool colorOn = gpsPauseCounter == 0; // each interval starts with pause if (STATE(GPS_FIX)) { gpsColor = colorOn ? getSC(LED_SCOLOR_GPSLOCKED) : getSC(LED_SCOLOR_BACKGROUND); } else { gpsColor = colorOn ? getSC(LED_SCOLOR_GPSNOLOCK) : getSC(LED_SCOLOR_GPSNOSATS); } } applyLedHsv(LED_MOV_FUNCTION(LED_FUNCTION_GPS), gpsColor); }
static void applyLedBatteryLayer(bool updateNow, uint32_t *timer) { static bool flash = false; int state; int timeOffset = 1; if (updateNow) { state = getBatteryState(); switch (state) { case BATTERY_OK: flash = false; timeOffset = 1; break; case BATTERY_WARNING: timeOffset = 2; break; default: timeOffset = 8; break; } flash = !flash; } *timer += LED_STRIP_HZ(timeOffset); if (!flash) { hsvColor_t *bgc = getSC(LED_SCOLOR_BACKGROUND); applyLedHsv(LED_MOV_FUNCTION(LED_FUNCTION_BATTERY), bgc); } }
static void applyLedRssiLayer(bool updateNow, uint32_t *timer) { static bool flash = false; int state; int timeOffset = 0; if (updateNow) { state = (rssi * 100) / 1023; if (state > 50) { flash = false; timeOffset = 1; } else if (state > 20) { timeOffset = 2; } else { timeOffset = 8; } flash = !flash; } *timer += LED_STRIP_HZ(timeOffset); if (!flash) { hsvColor_t *bgc = getSC(LED_SCOLOR_BACKGROUND); applyLedHsv(LED_MOV_FUNCTION(LED_FUNCTION_RSSI), bgc); } }
static void applyLedRssiLayer(bool updateNow, timeUs_t *timer) { static bool flash = false; int timerDelay = HZ_TO_US(1); if (updateNow) { int state = (rssi * 100) / 1023; if (state > 50) { flash = true; timerDelay = HZ_TO_US(1); } else if (state > 20) { flash = !flash; timerDelay = HZ_TO_US(2); } else { flash = !flash; timerDelay = HZ_TO_US(8); } } *timer += timerDelay; if (!flash) { const hsvColor_t *bgc = getSC(LED_SCOLOR_BACKGROUND); applyLedHsv(LED_MOV_FUNCTION(LED_FUNCTION_RSSI), bgc); } }
static void applyLedBatteryLayer(bool updateNow, timeUs_t *timer) { static bool flash = false; int timerDelayUs = HZ_TO_US(1); if (updateNow) { switch (getBatteryState()) { case BATTERY_OK: flash = true; timerDelayUs = HZ_TO_US(1); break; case BATTERY_WARNING: flash = !flash; timerDelayUs = HZ_TO_US(2); break; default: flash = !flash; timerDelayUs = HZ_TO_US(8); break; } } *timer += timerDelayUs; if (!flash) { const hsvColor_t *bgc = getSC(LED_SCOLOR_BACKGROUND); applyLedHsv(LED_MOV_FUNCTION(LED_FUNCTION_BATTERY), bgc); } }
static void applyLedWarningLayer(bool updateNow, timeUs_t *timer) { static uint8_t warningFlashCounter = 0; static uint8_t warningFlags = 0; // non-zero during blinks if (updateNow) { // keep counter running, so it stays in sync with blink warningFlashCounter++; warningFlashCounter &= 0xF; if (warningFlashCounter == 0) { // update when old flags was processed warningFlags = 0; if (batteryConfig()->voltageMeterSource != VOLTAGE_METER_NONE && getBatteryState() != BATTERY_OK) warningFlags |= 1 << WARNING_LOW_BATTERY; if (failsafeIsActive()) warningFlags |= 1 << WARNING_FAILSAFE; if (!ARMING_FLAG(ARMED) && isArmingDisabled()) warningFlags |= 1 << WARNING_ARMING_DISABLED; } *timer += HZ_TO_US(10); } const hsvColor_t *warningColor = NULL; if (warningFlags) { bool colorOn = (warningFlashCounter % 2) == 0; // w_w_ warningFlags_e warningId = warningFlashCounter / 4; if (warningFlags & (1 << warningId)) { switch (warningId) { case WARNING_ARMING_DISABLED: warningColor = colorOn ? &HSV(GREEN) : &HSV(BLACK); break; case WARNING_LOW_BATTERY: warningColor = colorOn ? &HSV(RED) : &HSV(BLACK); break; case WARNING_FAILSAFE: warningColor = colorOn ? &HSV(YELLOW) : &HSV(BLUE); break; default:; } } } else { if (isBeeperOn()) { warningColor = &HSV(ORANGE); } } if (warningColor) { applyLedHsv(LED_MOV_OVERLAY(LED_FLAG_OVERLAY(LED_OVERLAY_WARNING)), warningColor); } }
static void applyLedWarningLayer(bool updateNow, uint32_t *timer) { static uint8_t warningFlashCounter = 0; static uint8_t warningFlags = 0; // non-zero during blinks if (updateNow) { // keep counter running, so it stays in sync with blink warningFlashCounter++; warningFlashCounter &= 0xF; if (warningFlashCounter == 0) { // update when old flags was processed warningFlags = 0; if (feature(FEATURE_VBAT) && getBatteryState() != BATTERY_OK) warningFlags |= 1 << WARNING_LOW_BATTERY; if (feature(FEATURE_FAILSAFE) && failsafeIsActive()) warningFlags |= 1 << WARNING_FAILSAFE; if (!ARMING_FLAG(ARMED) && !ARMING_FLAG(OK_TO_ARM)) warningFlags |= 1 << WARNING_ARMING_DISABLED; } *timer += LED_STRIP_HZ(10); } if (warningFlags) { const hsvColor_t *warningColor = NULL; bool colorOn = (warningFlashCounter % 2) == 0; // w_w_ warningFlags_e warningId = warningFlashCounter / 4; if (warningFlags & (1 << warningId)) { switch (warningId) { case WARNING_ARMING_DISABLED: warningColor = colorOn ? &HSV(GREEN) : &HSV(BLACK); break; case WARNING_LOW_BATTERY: warningColor = colorOn ? &HSV(RED) : &HSV(BLACK); break; case WARNING_FAILSAFE: warningColor = colorOn ? &HSV(YELLOW) : &HSV(BLUE); break; default:; } } if (warningColor) applyLedHsv(LED_MOV_OVERLAY(LED_FLAG_OVERLAY(LED_OVERLAY_WARNING)), warningColor); } }
static void applyLedVtxLayer(bool updateNow, timeUs_t *timer) { static uint16_t frequency = 0; static uint8_t power = 255; static uint8_t pit = 255; static uint8_t showSettings = false; static uint16_t lastCheck = 0; static bool blink = false; const vtxDevice_t *vtxDevice = vtxCommonDevice(); if (!vtxDevice) { return; } uint8_t band = 255, channel = 255; uint16_t check = 0; if (updateNow) { // keep counter running, so it stays in sync with vtx vtxCommonGetBandAndChannel(vtxDevice, &band, &channel); vtxCommonGetPowerIndex(vtxDevice, &power); vtxCommonGetPitMode(vtxDevice, &pit); frequency = vtx58frequencyTable[band - 1][channel - 1]; //subtracting 1 from band and channel so that correct frequency is returned. //might not be correct for tramp but should fix smart audio. // check if last vtx values have changed. check = pit + (power << 1) + (band << 4) + (channel << 8); if (!showSettings && check != lastCheck) { // display settings for 3 seconds. showSettings = 15; } lastCheck = check; // quick way to check if any settings changed. if (showSettings) { showSettings--; } blink = !blink; *timer += HZ_TO_US(5); // check 5 times a second } hsvColor_t color = {0, 0, 0}; if (showSettings) { // show settings uint8_t vtxLedCount = 0; for (int i = 0; i < ledCounts.count && vtxLedCount < 6; ++i) { const ledConfig_t *ledConfig = &ledStripConfig()->ledConfigs[i]; if (ledGetOverlayBit(ledConfig, LED_OVERLAY_VTX)) { if (vtxLedCount == 0) { color.h = HSV(GREEN).h; color.s = HSV(GREEN).s; color.v = blink ? 15 : 0; // blink received settings } else if (vtxLedCount > 0 && power >= vtxLedCount && !pit) { // show power color.h = HSV(ORANGE).h; color.s = HSV(ORANGE).s; color.v = blink ? 15 : 0; // blink received settings } else { // turn rest off color.h = HSV(BLACK).h; color.s = HSV(BLACK).s; color.v = HSV(BLACK).v; } setLedHsv(i, &color); ++vtxLedCount; } } } else { // show frequency // calculate the VTX color based on frequency int colorIndex = 0; if (frequency <= 5672) { colorIndex = COLOR_WHITE; } else if (frequency <= 5711) { colorIndex = COLOR_RED; } else if (frequency <= 5750) { colorIndex = COLOR_ORANGE; } else if (frequency <= 5789) { colorIndex = COLOR_YELLOW; } else if (frequency <= 5829) { colorIndex = COLOR_GREEN; } else if (frequency <= 5867) { colorIndex = COLOR_BLUE; } else if (frequency <= 5906) { colorIndex = COLOR_DARK_VIOLET; } else { colorIndex = COLOR_DEEP_PINK; } hsvColor_t color = ledStripConfig()->colors[colorIndex]; color.v = pit ? (blink ? 15 : 0) : 255; // blink when in pit mode applyLedHsv(LED_MOV_OVERLAY(LED_FLAG_OVERLAY(LED_OVERLAY_VTX)), &color); } }