Skip to content

Commit

Permalink
RSSI Model Locator: Add TX Power & Haptic Feedback (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
AegisCrusader authored Dec 15, 2024
1 parent 25c062e commit ddededf
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 18 deletions.
42 changes: 33 additions & 9 deletions sdcard/c480x272/SCRIPTS/TOOLS/Model Locator (by RSSI).lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
-- Model Locator by RSSI
-- Offer Shmuely (based on code from Scott Bauer 6/21/2015)
-- Date: 2022-2024
-- ver: 0.5
local app_ver = "0.5"
-- ver: 0.6
local app_ver = "0.6"

-- This widget help to find a lost/crashed model based on the RSSI (if still available)
-- The widget produce audio representation (vario-meter style) of the RSSI from the lost model
Expand All @@ -39,8 +39,10 @@ local app_ver = "0.5"
-- triangulate the two lines, and it will be :-)

local delayMillis = 100
local targetTXPower = 25
local nextPlayTime = getTime()
local img = bitmap.open("/SCRIPTS/TOOLS/Model Locator (by RSSI).png")
local useHaptic = false

--------------------------------------------------------------
local function log(s)
Expand Down Expand Up @@ -88,13 +90,19 @@ local function getRangeColor(value, red_value, green_value)
end

local function getSignalValues()
-- try to get transmitter power
local txPowerField = getFieldInfo("TPWR")
local txPowerValue = nil
if txPowerField then
txPowerValue = getValue("TPWR")
end

-- 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
return v, 0, 100, txPowerValue, "Using signal: Frsky RSSI", nil
end

-- try expressLRS antenna 1
Expand All @@ -104,7 +112,7 @@ local function getSignalValues()
if v == 0 then
v = -115
end
return v, -115, 20, "Using signal: elrs 1RSS", "Set tx power to 25mW non dynamic"
return v, -115, 20, txPowerValue, "Using signal: ELRS 1RSS", "Set TX Power to 25mW Non-Dynamic"
end

-- try expressLRS antenna 2
Expand All @@ -114,7 +122,7 @@ local function getSignalValues()
if v == 0 then
v = -115
end
return v, -115, 20, "Using signal: elrs 2RSS", "Set tx power to 25mW non dynamic"
return v, -115, 20, txPowerValue, "Using signal: ELRS 2RSS", "Set TX Power to 25mW Non-Dynamic"
end

---- try UNI-ACSST firmware VFR
Expand Down Expand Up @@ -149,23 +157,31 @@ local function main(event, touchState)
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()
local signalValue, signalMin, signalMax, txPower, 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)

if txPower then
lcd.drawText(3, 60, "Current TX Power: " .. tostring(txPower) .. "mW", (txPower == targetTXPower) and DARKGREEN or RED)

if txPower ~= targetTXPower then
lcd.drawText(3, 75, line2 or "", RED + BLINK)
end
end

lcd.drawText(10, LCD_H-22, line1, WHITE)
lcd.drawText(300, LCD_H-22, "[ENTER] to toggle haptic", 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)
lcd.drawText(3, 90, tostring(signalValue) .. "db", XXLSIZE + CUSTOM_COLOR)

-- draw main bar
local xMin = 10
Expand All @@ -180,9 +196,17 @@ local function main(event, touchState)
lcd.drawFilledRectangle(xx, yMin - h, 15, h, CUSTOM_COLOR)
end

-- toggle haptic
if event == EVT_VIRTUAL_ENTER then
useHaptic = not useHaptic
end

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

Expand Down
42 changes: 33 additions & 9 deletions sdcard/c480x320/SCRIPTS/TOOLS/Model Locator (by RSSI).lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
-- Model Locator by RSSI
-- Offer Shmuely (based on code from Scott Bauer 6/21/2015)
-- Date: 2022-2024
-- ver: 0.5
local app_ver = "0.5"
-- ver: 0.6
local app_ver = "0.6"

-- This widget help to find a lost/crashed model based on the RSSI (if still available)
-- The widget produce audio representation (vario-meter style) of the RSSI from the lost model
Expand All @@ -39,8 +39,10 @@ local app_ver = "0.5"
-- triangulate the two lines, and it will be :-)

local delayMillis = 100
local targetTXPower = 25
local nextPlayTime = getTime()
local img = bitmap.open("/SCRIPTS/TOOLS/Model Locator (by RSSI).png")
local useHaptic = false

--------------------------------------------------------------
local function log(s)
Expand Down Expand Up @@ -88,13 +90,19 @@ local function getRangeColor(value, red_value, green_value)
end

local function getSignalValues()
-- try to get transmitter power
local txPowerField = getFieldInfo("TPWR")
local txPowerValue = nil
if txPowerField then
txPowerValue = getValue("TPWR")
end

-- 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
return v, 0, 100, txPowerValue, "Using signal: Frsky RSSI", nil
end

-- try expressLRS antenna 1
Expand All @@ -104,7 +112,7 @@ local function getSignalValues()
if v == 0 then
v = -115
end
return v, -115, 20, "Using signal: elrs 1RSS", "Set tx power to 25mW non dynamic"
return v, -115, 20, txPowerValue, "Using signal: ELRS 1RSS", "Set TX Power to 25mW Non-Dynamic"
end

-- try expressLRS antenna 2
Expand All @@ -114,7 +122,7 @@ local function getSignalValues()
if v == 0 then
v = -115
end
return v, -115, 20, "Using signal: elrs 2RSS", "Set tx power to 25mW non dynamic"
return v, -115, 20, txPowerValue, "Using signal: ELRS 2RSS", "Set TX Power to 25mW Non-Dynamic"
end

---- try UNI-ACSST firmware VFR
Expand Down Expand Up @@ -149,23 +157,31 @@ local function main(event, touchState)
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()
local signalValue, signalMin, signalMax, txPower, 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)

if txPower then
lcd.drawText(3, 60, "Current TX Power: " .. tostring(txPower) .. "mW", (txPower == targetTXPower) and DARKGREEN or RED)

if txPower ~= targetTXPower then
lcd.drawText(3, 75, line2 or "", RED + BLINK)
end
end

lcd.drawText(10, LCD_H-22, line1, WHITE)
lcd.drawText(300, LCD_H-22, "[ENTER] to toggle haptic", 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)
lcd.drawText(3, 90, tostring(signalValue) .. "db", XXLSIZE + CUSTOM_COLOR)

-- draw main bar
local xMin = 10
Expand All @@ -180,9 +196,17 @@ local function main(event, touchState)
lcd.drawFilledRectangle(xx, yMin - h, 15, h, CUSTOM_COLOR)
end

-- toggle haptic
if event == EVT_VIRTUAL_ENTER then
useHaptic = not useHaptic
end

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

Expand Down

0 comments on commit ddededf

Please sign in to comment.