OpenTx 2.1.9 Lua script Haptic access

openTx has introduced a range of new features, ideas and bling. It is fast becoming the firmware of choice for many users. openTx will run on ALL current hardware platforms, including the gruvin9x and sky9x boards. Work has already started to support the new FrSky X9D radio!
Post Reply
jctpro
Posts: 3
Joined: Tue Dec 20, 2016 5:01 pm
Country: -

OpenTx 2.1.9 Lua script Haptic access

Post by jctpro »

I have a Taranis X9D Plus and am trying to get a Hapic call to work in a mix lua script. If I remove the comment on the playHaptic line the script fails. Any advice how to make haptic work in the script? Here is the script:

local channelValue = 0
local duration
-- local targetTime not declared so it is global and the value will stick between calls
-- local running not declared so it is global


local inp = { }
local out = { "gunV" }

local function ini_func()

end

local function run_func()
local remainingTime

duration = model.getGlobalVariable(0,0)
if (duration == 0) then
return 0
end

channelValue = 1024
local timenow = getTime() -- 10ms tick count

if not running then
running = true
playFile("gun.wav")

-- playHaptic(1000, 10, 10)

targetTime = timenow + (duration * 10)
end

remainingTime = targetTime - timenow
model.setGlobalVariable(4,0,remainingTime)

if remainingTime < 10 then
model.setGlobalVariable(0,0,0)
-- Time ran out
running = false
channelValue = 0
end

return channelValue
end

return { init=init_func, run=run_func, input=inp, output=out }

Post Reply

Return to “openTx”