Skip to content

Commit

Permalink
Merge pull request #8 from teckel12/development
Browse files Browse the repository at this point in the history
Added Horus support and standardized tab indenting
  • Loading branch information
teckel12 committed Dec 23, 2018
2 parents 0e1195d + 7a71fcf commit 7137403
Show file tree
Hide file tree
Showing 9 changed files with 767 additions and 752 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Taranis VTx Lua Script
# VTx Lua Script - v1.1

This stripped-down fork of [betaflight-tx-lua-scripts](https://github.com/betaflight/betaflight-tx-lua-scripts) includes only VTx configuration for Taranis transmitters only. Taranis VTx was created to save memory on your transmitter so other Lua scripts (for example [Lua Telemetry](https://github.com/iNavFlight/LuaTelemetry)) can run on the same model. This script should work with [Betaflight](https://github.com/betaflight/betaflight) as well as [INAV](https://github.com/iNavFlight/inav).
This stripped-down fork of [betaflight-tx-lua-scripts](https://github.com/betaflight/betaflight-tx-lua-scripts) includes only VTx configuration on FrSky transmitters. VTx lua script was created to save memory on your transmitter so other Lua scripts (for example [Lua Telemetry](https://github.com/iNavFlight/LuaTelemetry)) can run on the same model. This script should work with [Betaflight](https://github.com/betaflight/betaflight) as well as [INAV](https://github.com/iNavFlight/inav).

### Features

* Uses less memory than [betaflight-tx-lua-scripts](https://github.com/betaflight/betaflight-tx-lua-scripts)
* Allows for multiple Lua scripts to be run on the same model (for example [Lua Telemetry](https://github.com/iNavFlight/LuaTelemetry))
* Only allows for VTx control (no PID adjustments)
* Works only on Taranis transmitters running SmartPort or F.Port telemetry
* Works with [INAV](https://github.com/iNavFlight/inav) and [Betaflight](https://github.com/betaflight/betaflight)
* Works on Taranis and Horus transmitters running SmartPort or F.Port telemetry
* Works with [INAV](https://github.com/iNavFlight/inav) and probably [Betaflight](https://github.com/betaflight/betaflight) (untested)

### Installation instructions

Expand Down
92 changes: 50 additions & 42 deletions SCRIPTS/TELEMETRY/VTx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,58 @@ SMARTPORT_REMOTE_SENSOR_ID = 0x1B
FPORT_REMOTE_SENSOR_ID = 0x00
REQUEST_FRAME_ID = 0x30
REPLY_FRAME_ID = 0x32
HORUS = LCD_W >= 480
local fa = HORUS and 2 or 1

MenuBox = { x=15, y=12, w=100, x_offset=36, h_line=8, h_offset=3 }
SaveBox = { x=15, y=12, w=100, x_offset=4, h=30, h_offset=5 }
NoTelem = { 30, 55, "No Telemetry", BLINK }
MenuBox = { x=15 * fa, y=12 * fa, w=100 * fa, x_offset=36 * fa, h_line=8 * (fa * 1.5), h_offset=3 * fa }
SaveBox = { x=15 * fa, y=12 * fa, w=100 * fa, x_offset=4 * fa, h=30 * fa, h_offset=5 * fa }
NoTelem = { 30 * fa, 55 * fa, "No Telemetry", BLINK }

protocol = {
rssi = function() return getValue("RSSI") end,
exitFunc = function() return 0 end,
stateSensor = "Tmp1",
push = sportTelemetryPush,
maxTxBufferSize = 6,
maxRxBufferSize = 6,
saveMaxRetries = 2,
saveTimeout = 300
rssi = function() return getValue("RSSI") end,
exitFunc = function() return 0 end,
stateSensor = "Tmp1",
push = sportTelemetryPush,
maxTxBufferSize = 6,
maxRxBufferSize = 6,
saveMaxRetries = 2,
saveTimeout = 300
}

protocol.mspSend = function(payload)
local dataId = 0
dataId = payload[1] + bit32.lshift(payload[2],8)
local value = 0
value = payload[3] + bit32.lshift(payload[4],8)
+ bit32.lshift(payload[5],16) + bit32.lshift(payload[6],24)
return sportTelemetryPush(LOCAL_SENSOR_ID, REQUEST_FRAME_ID, dataId, value)
local dataId = 0
dataId = payload[1] + bit32.lshift(payload[2],8)
local value = 0
value = payload[3] + bit32.lshift(payload[4],8)
+ bit32.lshift(payload[5],16) + bit32.lshift(payload[6],24)
return sportTelemetryPush(LOCAL_SENSOR_ID, REQUEST_FRAME_ID, dataId, value)
end

protocol.mspRead = function(cmd)
return mspSendRequest(cmd, {})
return mspSendRequest(cmd, {})
end

protocol.mspWrite = function(cmd, payload)
return mspSendRequest(cmd, payload)
return mspSendRequest(cmd, payload)
end

protocol.mspPoll = function()
local sensorId, frameId, dataId, value = sportTelemetryPop()
if (sensorId == SMARTPORT_REMOTE_SENSOR_ID or sensorId == FPORT_REMOTE_SENSOR_ID) and frameId == REPLY_FRAME_ID then
local payload = {}
payload[1] = bit32.band(dataId,0xFF)
dataId = bit32.rshift(dataId,8)
payload[2] = bit32.band(dataId,0xFF)
payload[3] = bit32.band(value,0xFF)
value = bit32.rshift(value,8)
payload[4] = bit32.band(value,0xFF)
value = bit32.rshift(value,8)
payload[5] = bit32.band(value,0xFF)
value = bit32.rshift(value,8)
payload[6] = bit32.band(value,0xFF)
return mspReceivedReply(payload)
end
return nil
local sensorId, frameId, dataId, value = sportTelemetryPop()
if (sensorId == SMARTPORT_REMOTE_SENSOR_ID or sensorId == FPORT_REMOTE_SENSOR_ID) and frameId == REPLY_FRAME_ID then
local payload = {}
payload[1] = bit32.band(dataId,0xFF)
dataId = bit32.rshift(dataId,8)
payload[2] = bit32.band(dataId,0xFF)
payload[3] = bit32.band(value,0xFF)
value = bit32.rshift(value,8)
payload[4] = bit32.band(value,0xFF)
value = bit32.rshift(value,8)
payload[5] = bit32.band(value,0xFF)
value = bit32.rshift(value,8)
payload[6] = bit32.band(value,0xFF)
return mspReceivedReply(payload)
end
return nil
end

assert(loadScript(SCRIPT_HOME.."/common.luac", "T"))()
Expand All @@ -70,16 +72,22 @@ local MENU_TIMESLICE = 100
local lastMenuEvent = 0

function run(event)
lastMenuEvent = getTime()
collectgarbage()
run_ui(event)
lastMenuEvent = getTime()
collectgarbage()
run_ui(event)
return 0
end

function run_bg()
if lastMenuEvent + MENU_TIMESLICE < getTime() then
background.run_bg()
collectgarbage()
end
if lastMenuEvent + MENU_TIMESLICE < getTime() then
background.run_bg()
collectgarbage()
end
return 0
end

function init()
return 0
end

return { init=background.init, run=run, background=run_bg }
142 changes: 71 additions & 71 deletions SCRIPTS/TELEMETRY/VTx/background.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,86 +8,86 @@ local timeIsSet = false
local mspMsgQueued = false

local function getSensorValue()
if sensorId == -1 then
local sensor = getFieldInfo(protocol.stateSensor)
if type(sensor) == "table" then
sensorId = sensor['id'] or -1
end
end
return getValue(sensorId)
if sensorId == -1 then
local sensor = getFieldInfo(protocol.stateSensor)
if type(sensor) == "table" then
sensorId = sensor['id'] or -1
end
end
return getValue(sensorId)
end

local function modelActive(sensorValue)
return type(sensorValue) == "number" and sensorValue > 0
return type(sensorValue) == "number" and sensorValue > 0
end

local function init()
lastRunTS = 0
lastRunTS = 0
end

local function run_bg()
-- run in intervals

if lastRunTS == 0 or lastRunTS + INTERVAL < getTime() then
mspMsgQueued = false
-- ------------------------------------
-- SYNC DATE AND TIME
-- ------------------------------------
local sensorValue = getSensorValue()

if not timeIsSet and modelActive(sensorValue) then
-- Send datetime when the telemetry connection is available
-- assuming when sensor value higher than 0 there is an telemetry connection
-- only send datetime one time after telemetry connection became available
-- or when connection is restored after e.g. lipo refresh
local now = getDateTime()
local year = now.year;

values = {}
values[1] = bit32.band(year, 0xFF)
year = bit32.rshift(year, 8)
values[2] = bit32.band(year, 0xFF)
values[3] = now.mon
values[4] = now.day
values[5] = now.hour
values[6] = now.min
values[7] = now.sec

-- send msp message
protocol.mspWrite(MSP_SET_RTC, values)
mspMsgQueued = true

timeIsSet = true
elseif not modelActive(sensorValue) then
timeIsSet = false
end


-- ------------------------------------
-- SEND RSSI VALUE
-- ------------------------------------

if mspMsgQueued == false then
local rssi, alarm_low, alarm_crit = getRSSI()
-- Scale the [0, 85] (empirical) RSSI values to [0, 255]
rssi = rssi * 3
if rssi > 255 then
rssi = 255
end

values = {}
values[1] = rssi

-- send msp message
protocol.mspWrite(MSP_TX_INFO, values)
mspMsgQueued = true
end

lastRunTS = getTime()
end

-- process queue
mspProcessTxQ()
-- run in intervals

if lastRunTS == 0 or lastRunTS + INTERVAL < getTime() then
mspMsgQueued = false
-- ------------------------------------
-- SYNC DATE AND TIME
-- ------------------------------------
local sensorValue = getSensorValue()

if not timeIsSet and modelActive(sensorValue) then
-- Send datetime when the telemetry connection is available
-- assuming when sensor value higher than 0 there is an telemetry connection
-- only send datetime one time after telemetry connection became available
-- or when connection is restored after e.g. lipo refresh
local now = getDateTime()
local year = now.year;

values = {}
values[1] = bit32.band(year, 0xFF)
year = bit32.rshift(year, 8)
values[2] = bit32.band(year, 0xFF)
values[3] = now.mon
values[4] = now.day
values[5] = now.hour
values[6] = now.min
values[7] = now.sec

-- send msp message
protocol.mspWrite(MSP_SET_RTC, values)
mspMsgQueued = true

timeIsSet = true
elseif not modelActive(sensorValue) then
timeIsSet = false
end


-- ------------------------------------
-- SEND RSSI VALUE
-- ------------------------------------

if mspMsgQueued == false then
local rssi, alarm_low, alarm_crit = getRSSI()
-- Scale the [0, 85] (empirical) RSSI values to [0, 255]
rssi = rssi * 3
if rssi > 255 then
rssi = 255
end

values = {}
values[1] = rssi

-- send msp message
protocol.mspWrite(MSP_TX_INFO, values)
mspMsgQueued = true
end

lastRunTS = getTime()
end

-- process queue
mspProcessTxQ()

end

Expand Down
Loading

0 comments on commit 7137403

Please sign in to comment.