-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsappRSSI.lua
More file actions
76 lines (60 loc) · 1.85 KB
/
sappRSSI.lua
File metadata and controls
76 lines (60 loc) · 1.85 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
68
69
70
71
72
73
74
75
76
-- RSSI LED Ring script
-- This script is based on the throttle indicator on the LED bar
-- by btastic_fpv
local LED_GROUP1 = {10,11,12,13,14,15,16,17,18,19}
local LED_GROUP2 = {0,1,2,3,4,5,6,7,8,9}
local function init()
end
local function fillSlots(ledValue,ledGroup)
local numLedsTotal = #ledGroup
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: all LEDs full brightness
if ledValue == 255 then
numLeds = numLedsTotal
brightness = 255
end
-- LEDs are sapphire
for i = 1, numLedsTotal, 1 do
local ledIndex = i - 1
if ledIndex < numLeds - 1 then
setRGBLedColor(ledGroup[i], 0, 255, 255)
elseif ledIndex == numLeds - 1 then
setRGBLedColor(ledGroup[i], 0, brightness, brightness)
else
setRGBLedColor(ledGroup[i], 0, 0, 0)
end
end
end
local function calcLEDValue(source)
-- map -117dBm ... -3dBm into 0...255
local ledValue = math.floor((source + 117) * 255 / 114)
ledValue = math.max(0, math.min(255, ledValue))
return ledValue
end
local function run()
-- Get RSSI Telem values
local elrs1RSS = getValue("1RSS")
local elrs2RSS = getValue("2RSS")
local ledValue1 = calcLEDValue(elrs1RSS)
local ledValue2 = calcLEDValue(elrs2RSS)
if not elrs1RSS == nil or elrs1RSS == 0 then
fillSlots(0,LED_GROUP1)
else
fillSlots(ledValue1,LED_GROUP1)
end
if not elrs2RSS == nil or elrs2RSS == 0 then
fillSlots(0,LED_GROUP2)
else
fillSlots(ledValue2,LED_GROUP2)
end
applyRGBLedColors()
end
local function background()
end
return { run=run, background=background, init=init }