-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfullLQ.lua
More file actions
67 lines (52 loc) · 1.74 KB
/
fullLQ.lua
File metadata and controls
67 lines (52 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
-- LQ LED Bar script
-- This script is based on the throttle indicator on the LED bar
-- by btastic_fpv
local LED_START = 20 -- First LED in the bar
local LED_END = 25 -- Last LED in the bar
local INDICATOR_LED = -1 -- Separate indicator LED (set to -1 to disable)
local function init()
end
local function fillNormal(ledValue)
-- Calculate total number of LEDs
local numLedsTotal = LED_END - LED_START + 1
local segmentSize = 255 / numLedsTotal
-- Calculate how many LEDs should be lit
local numLeds = math.floor(ledValue / segmentSize) + 1
numLeds = math.max(1, math.min(numLedsTotal, numLeds))
-- Calculate brightness for the highest LED
local segment = (ledValue % segmentSize) / segmentSize
local brightness = math.floor(5 + (segment * 250))
-- Special case: at 100% LQ, all LEDs full brightness
if ledValue == 255 then
numLeds = numLedsTotal
brightness = 255
end
-- Light up LEDs progressively
for i = LED_START, LED_END, 1 do
local ledIndex = i - LED_START
if ledIndex < numLeds - 1 then
setRGBLedColor(i, 0, 255, 0)
elseif ledIndex == numLeds - 1 then
setRGBLedColor(i, 0, brightness, 0)
else
setRGBLedColor(i, 0, 0, 0)
end
end
end
local function run()
-- Get LQ Telem value
local lqPercent = getValue("RQly")
-- map LQ values to brightness level 0..255
local ledValue = math.floor(lqPercent * 255 / 100)
-- Clamp value to ensure it stays within 0-255
ledValue = math.max(0, math.min(255, ledValue))
fillNormal(ledValue)
-- Optional indicator LED
if INDICATOR_LED >= 0 then
setRGBLedColor(INDICATOR_LED, 50, 0, 0)
end
applyRGBLedColors()
end
local function background()
end
return { run=run, background=background, init=init }