Skip to content

Commit

Permalink
model locator: display error info when no signal found (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
offer-shmuely authored Nov 19, 2024
1 parent 8c0b517 commit b335460
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 127 deletions.
67 changes: 28 additions & 39 deletions sdcard/c480x272/SCRIPTS/TOOLS/Model Locator (by RSSI).lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@

-- Model Locator by RSSI
-- Offer Shmuely (based on code from Scott Bauer 6/21/2015)
-- Date: 2022
-- ver: 0.3
-- Date: 2022-2024
-- ver: 0.5
local app_ver = "0.5"

-- This widget help to find a lost/crashed model based on the RSSI (if still available)
-- The widget produce audio representation (variometer style) of the RSSI from the lost model
-- The widget produce audio representation (vario-meter style) of the RSSI from the lost model
-- The widget also display the RSSI in a visible colorized bar (0-100%)

-- There are two way to use it
Expand Down Expand Up @@ -88,35 +89,32 @@ end

local function getSignalValues()

-- try regular RSSI
-- try regular Frsky RSSI
local fieldinfo = getFieldInfo("RSSI")
if fieldinfo then
local v = getValue("RSSI")
log("RSSI: " .. v)
lcd.drawText(3, 30, "Signal: RSSI", 0)
return v, 0, 100
return v, 0, 100, "Using signal: Frsky RSSI", nil
end

-- try expressLRS
-- try expressLRS antenna 1
local fieldinfo = getFieldInfo("1RSS")
if fieldinfo then
local v = getValue("1RSS")
lcd.drawText(3, 30, "Signal: 1RSS", 0)
if v == 0 then
v = -115
end
return v, -115, 20
return v, -115, 20, "Using signal: elrs 1RSS", "Set tx power to 25mW non dynamic"
end

-- try expressLRS
-- try expressLRS antenna 2
local fieldinfo = getFieldInfo("2RSS")
if fieldinfo then
local v = getValue("2RSS")
lcd.drawText(3, 30, "Signal: 2RSS", 0)
if v == 0 then
v = -115
end
return v, -115, 20
return v, -115, 20, "Using signal: elrs 2RSS", "Set tx power to 25mW non dynamic"
end

---- try UNI-ACSST firmware VFR
Expand All @@ -137,48 +135,42 @@ local function getSignalValues()
-- return v, 0, 100
--end

lcd.drawText(30, 3, "Signal: not found in RSSI/1RSS/2RSS", 0)
return nil, 0, 0
end


local function main(event, touchState)
lcd.clear()
lcd.drawBitmap(img, LCD_W-120, 30, 20)

local signalValue, signalMin, signalMax = getSignalValues()
-- Title
lcd.drawFilledRectangle(0,0, LCD_W, 30, BLACK)
lcd.drawFilledRectangle(0,LCD_H-25, LCD_W, 25, GREY)
lcd.drawText(10, 3, "RSSI Model Locator", WHITE)
lcd.drawText(LCD_W - 50, 3, "ver: " .. app_ver .. "", SMLSIZE + GREEN)

local signalValue, signalMin, signalMax, line1, line2 = getSignalValues()
-- log(signalValue)
if signalValue == nil then
return
lcd.drawText(30, 50, "No signal found (expected: RSSI/1RSS/2RSS)", 0 + BLINK)
return 0
end
log("signalValue:" .. signalValue .. ", signalMin: " .. signalMin .. ", signalMax: " .. signalMax)

-- background
--lcd.drawBitmap(img, 0, 20, 30)
lcd.drawBitmap(img, 250, 50, 40)
lcd.drawText(3, 60, line2 or "", RED)
lcd.drawText(10, LCD_H-22, line1, WHITE)

-- Title
lcd.drawText(3, 3, "RSSI Model Locator", 0)
log("signalValue:" .. signalValue .. ", signalMin: " .. signalMin .. ", signalMax: " .. signalMax)

--if (rssi > 42) then
-- lcd.setColor(CUSTOM_COLOR, YELLOW) -- RED / YELLOW
--else
-- lcd.setColor(CUSTOM_COLOR, RED) -- RED / YELLOW
--end
local signalPercent = 100 * ((signalValue - signalMin) / (signalMax - signalMin))
--myColor = getRangeColor(signalPercent, 0, 100)
--lcd.setColor(CUSTOM_COLOR, myColor)
lcd.setColor(CUSTOM_COLOR, getRangeColor(signalPercent, 0, 100))

-- draw current value
lcd.drawNumber(180, 30, signalValue, XXLSIZE + CUSTOM_COLOR)
lcd.drawText(260, 70, "db", 0 + CUSTOM_COLOR)
lcd.drawNumber(40, 100, signalValue, XXLSIZE + CUSTOM_COLOR)
lcd.drawText(130, 140, "db", 0 + CUSTOM_COLOR)

-- draw main bar
--lcd.setColor(CUSTOM_COLOR, YELLOW) -- RED / YELLOW
local xMin = 0
local yMin = 270
local xMax = 480
local yMax = 200
local xMin = 10
local yMin = LCD_H - 30
local xMax = LCD_W
local h = 0
local rssiAsX = (signalPercent * xMax) / 100
log("signalPercent:" .. signalPercent .. ", signalValue: " .. signalValue .. ", rssiAsX: " .. rssiAsX)
Expand All @@ -188,9 +180,6 @@ local function main(event, touchState)
lcd.drawFilledRectangle(xx, yMin - h, 15, h, CUSTOM_COLOR)
end

-- draw rectangle
--lcd.drawFilledRectangle(0, 250, signalPercent * 4.8, 20, GREY_DEFAULT)

-- beep
if getTime() >= nextPlayTime then
playFile("/SCRIPTS/TOOLS/Model Locator (by RSSI).wav")
Expand Down
220 changes: 132 additions & 88 deletions sdcard/c480x320/SCRIPTS/TOOLS/Model Locator (by RSSI).lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@

-- Model Locator by RSSI
-- Offer Shmuely (based on code from Scott Bauer 6/21/2015)
-- Date: 2021
-- ver: 0.1
-- Date: 2022-2024
-- ver: 0.5
local app_ver = "0.5"

-- This widget help to find a lost/crashed model based on the RSSI (if still available)
-- The widget produce audio representation (variometer style) of the RSSI from the lost model
-- The widget produce audio representation (vario-meter style) of the RSSI from the lost model
-- The widget also display the RSSI in a visible colorized bar (0-100%)

-- There are two way to use it
Expand All @@ -43,107 +44,150 @@ local img = bitmap.open("/SCRIPTS/TOOLS/Model Locator (by RSSI).png")

--------------------------------------------------------------
local function log(s)
--return;
print("locator: " .. s)
-- print("locator: " .. s)
end
--------------------------------------------------------------


-- init_func is called once when model is loaded
local function init()
return 0
end

-- bg_func is called periodically when screen is not visible
local function bg()
return 0
return 0
end

-- This function returns green at gvalue, red at rvalue and graduate in between
local function getRangeColor(value, red_value, green_value)
local range = math.abs(green_value - red_value)
if range == 0 then
return lcd.RGB(0, 0xdf, 0)
end
if value == nil then
return lcd.RGB(0, 0xdf, 0)
end

if green_value > red_value then
if value > green_value then
return lcd.RGB(0, 0xdf, 0)
local range = math.abs(green_value - red_value)
if range == 0 then
return lcd.RGB(0, 0xdf, 0)
end
if value == nil then
return lcd.RGB(0, 0xdf, 0)
end

if green_value > red_value then
if value > green_value then
return lcd.RGB(0, 0xdf, 0)
end
if value < red_value then
return lcd.RGB(0xdf, 0, 0)
end
g = math.floor(0xdf * (value - red_value) / range)
r = 0xdf - g
return lcd.RGB(r, g, 0)
else
if value > green_value then
return lcd.RGB(0, 0xdf, 0)
end
if value < red_value then
return lcd.RGB(0xdf, 0, 0)
end
r = math.floor(0xdf * (value - green_value) / range)
g = 0xdf - r
return lcd.RGB(r, g, 0)
end
if value < red_value then
return lcd.RGB(0xdf, 0, 0)
end

local function getSignalValues()

-- try regular Frsky RSSI
local fieldinfo = getFieldInfo("RSSI")
if fieldinfo then
local v = getValue("RSSI")
log("RSSI: " .. v)
return v, 0, 100, "Using signal: Frsky RSSI", nil
end
g = math.floor(0xdf * (value - red_value) / range)
r = 0xdf - g
return lcd.RGB(r, g, 0)
else
if value > green_value then
return lcd.RGB(0, 0xdf, 0)

-- try expressLRS antenna 1
local fieldinfo = getFieldInfo("1RSS")
if fieldinfo then
local v = getValue("1RSS")
if v == 0 then
v = -115
end
return v, -115, 20, "Using signal: elrs 1RSS", "Set tx power to 25mW non dynamic"
end
if value < red_value then
return lcd.RGB(0xdf, 0, 0)

-- try expressLRS antenna 2
local fieldinfo = getFieldInfo("2RSS")
if fieldinfo then
local v = getValue("2RSS")
if v == 0 then
v = -115
end
return v, -115, 20, "Using signal: elrs 2RSS", "Set tx power to 25mW non dynamic"
end
r = math.floor(0xdf * (value - green_value) / range)
g = 0xdf - r
return lcd.RGB(r, g, 0)
end

---- try UNI-ACSST firmware VFR
--local fieldinfo = getFieldInfo("VFR")
--if fieldinfo then
-- local v = getValue("VFR")
-- log("RSSI: " .. v)
-- lcd.drawText(3, 30, "Signal: VFR", 0)
-- return v, 0, 100
--end
--
---- try elrs RQLY
--local fieldinfo = getFieldInfo("RQLY")
--if fieldinfo then
-- local v = getValue("RQLY")
-- log("RQLY: " .. v)
-- lcd.drawText(3, 30, "Signal: RQLY", 0)
-- return v, 0, 100
--end

return nil, 0, 0
end

local function main(event)

lcd.clear()
local rssi = getValue("RSSI")
-- log(rssi)

-- background
--lcd.drawBitmap(img, 0, 20, 30)
lcd.drawBitmap(img, 250, 50, 40)

-- Title
lcd.drawText(3, 3, "RSSI Model Locator", 0)

--if (rssi > 42) then
-- lcd.setColor(CUSTOM_COLOR, YELLOW) -- RED / YELLOW
--else
-- lcd.setColor(CUSTOM_COLOR, RED) -- RED / YELLOW
--end
myColor = getRangeColor(rssi, 0, 100)
lcd.setColor(CUSTOM_COLOR, myColor)

-- draw current value
lcd.drawNumber(180, 30, rssi, XXLSIZE + CUSTOM_COLOR)
lcd.drawText(260, 70, "db", 0 + CUSTOM_COLOR)

-- draw main bar
lcd.setColor(CUSTOM_COLOR, YELLOW) -- RED / YELLOW
local xMin = 0
local yMin = 270
local xMax = 480
local yMax = 200
local h = 0
local rssiAsX = (rssi * xMax) / 100
-- log("rssi:"..rssi)
for xx = xMin, rssiAsX, 20 do
lcd.setColor(CUSTOM_COLOR, getRangeColor(xx, xMin, xMax - 40))
h = h + 10
lcd.drawFilledRectangle(xx, yMin - h, 15, h, CUSTOM_COLOR)
end

-- draw rectangle
--lcd.drawFilledRectangle(0, 250, rssi * 4.8, 20, GREY_DEFAULT)

-- beep
if getTime() >= nextPlayTime then
playFile("/SCRIPTS/TOOLS/Model Locator (by RSSI).wav")
nextPlayTime = getTime() + delayMillis - rssi
end


return 0

local function main(event, touchState)
lcd.clear()
lcd.drawBitmap(img, LCD_W-120, 30, 20)

-- Title
lcd.drawFilledRectangle(0,0, LCD_W, 30, BLACK)
lcd.drawFilledRectangle(0,LCD_H-25, LCD_W, 25, GREY)
lcd.drawText(10, 3, "RSSI Model Locator", WHITE)
lcd.drawText(LCD_W - 50, 3, "ver: " .. app_ver .. "", SMLSIZE + GREEN)

local signalValue, signalMin, signalMax, line1, line2 = getSignalValues()
-- log(signalValue)
if signalValue == nil then
lcd.drawText(30, 50, "No signal found (expected: RSSI/1RSS/2RSS)", 0 + BLINK)
return 0
end
lcd.drawText(3, 60, line2 or "", RED)
lcd.drawText(10, LCD_H-22, line1, WHITE)

log("signalValue:" .. signalValue .. ", signalMin: " .. signalMin .. ", signalMax: " .. signalMax)

local signalPercent = 100 * ((signalValue - signalMin) / (signalMax - signalMin))
lcd.setColor(CUSTOM_COLOR, getRangeColor(signalPercent, 0, 100))

-- draw current value
lcd.drawNumber(40, 100, signalValue, XXLSIZE + CUSTOM_COLOR)
lcd.drawText(130, 140, "db", 0 + CUSTOM_COLOR)

-- draw main bar
local xMin = 10
local yMin = LCD_H - 30
local xMax = LCD_W
local h = 0
local rssiAsX = (signalPercent * xMax) / 100
log("signalPercent:" .. signalPercent .. ", signalValue: " .. signalValue .. ", rssiAsX: " .. rssiAsX)
for xx = xMin, rssiAsX, 20 do
lcd.setColor(CUSTOM_COLOR, getRangeColor(xx, xMin, xMax - 40))
h = h + 10
lcd.drawFilledRectangle(xx, yMin - h, 15, h, CUSTOM_COLOR)
end

-- beep
if getTime() >= nextPlayTime then
playFile("/SCRIPTS/TOOLS/Model Locator (by RSSI).wav")
nextPlayTime = getTime() + delayMillis - signalPercent
end

return 0
end

return {init = init,run = main,background = bg}
return { init = init, run = main }

0 comments on commit b335460

Please sign in to comment.