2017-07-27 96 views
0

我正在为OpenTX RC遥控器制作Lua遥测脚本,并且我想在用户按下按钮后创建自定义菜单。我想出了如何检查按钮点击,但我想知道是否有任何功能为我创建自定义菜单。Lua OpenTX自定义菜单

我在opentx github文档中找到了函数popupInput(title, event, input, min, max),但是当我调用这个函数时似乎没有任何事情发生。

我想要的东西,就像股票一样的菜单是在OpenTX系统enter image description here

在这里,您可以看到选项重置遥测技术的菜单和复位飞行我要让类似的东西。

那么有没有什么方法可以创建自定义菜单?还是我必须自己做所有的绘图和处理输入?

+0

等都需要“OpenTX”标签。 –

+0

但是没有这样的标签,我没有创建一个 –

+0

的声望,你可能想分享你的代码,你的firmeware版本......也可以考虑在opentx社区询问这个,因为这是非常特殊的。你有没有检查他们的聊天或邮件列表? – Piglet

回答

0

我放弃了发现功能,会做我的事,而是让我自己

下面是函数:

local function drawMenu(items, event) 

    local maxLen = 0; 
    local itemCount = 0; 
    for index, action in pairs(items) do 
    itemCount = itemCount + 1; 
    if string.len(index) > maxLen then 
     maxLen = string.len(index); 
    end 
    end 

    local width = maxLen * 5; -- width of the menu frame 
    local height = (itemCount * 9) + 2; -- height of the menu frame 
    if event == EVT_EXIT_BREAK then 
    menu = false; 
    end 

    if event == EVT_PLUS_BREAK or event == EVT_ROT_LEFT then 
    selected = selected + 1; 
    end 

    if event == EVT_MINUS_BREAK or event ==EVT_ROT_RIGHT then 
    selected = selected - 1; 
    end 

    count = 0; 
    actions = {}; 

    lcd.drawFilledRectangle((LCD_W/2) - (width/2), (LCD_H/2) - (height/2), width, height, ERASE); 
    lcd.drawRectangle((LCD_W/2) - (width/2), (LCD_H/2) - (height/2), width, height, SOLID); 
    for index, action in pairs(items) do 
    actions[count] = action; 
    if count == selected then 
     lcd.drawText((LCD_W/2) - (width/2) + 3, (LCD_H/2) - (height/2) + (count * 8) + 2, index, 0+ INVERS); 
    else 
     lcd.drawText((LCD_W/2) - (width/2) + 3, (LCD_H/2) - (height/2) + (count * 8) + 2, index, 0); 
    end 
    count = count + 1; 
    end 

    if event == EVT_ROT_BREAK or event == EVT_ENTER_BREAK then 
    actions[selected](); 
    menu = false; 
    end 

    if selected >= count then 
    selected = 0; 
    end 
    if selected < 0 then 
    selected = count - 1; 
    end 

end 

它接受与字符串索引的功能阵列。索引是菜单中的名称,该功能在用户选择时执行。菜单的大小很差,所以它可能有时太宽。

为了使它工作,你还需要一个全局变量菜单,它应该控制菜单的可见性。您应该打开菜单:

local menu = false; 
local function run_func(event) 
    if event == EVT_MENU_LONG then 
    menu = true; 
    end 
    if menu then 
    drawMenu(items, event); 
    end 
end 

并且还需要选择全局变量。

local selected = 0; 

但这种作用是无法完成它不支持滚动,当过多的物品传递给这个函数

截图它的行为可能奇怪:enter image description here

+0

也许你应该知道为什么popupInput不起作用,或者为什么我发现一个完整的功能请求的弹出式菜单在Lua脚本中不可用。但嘿拥有自己的东西无论如何都更好。现在你有完全控制 – Piglet

+0

这就是真的。我不知道怎么用popupInput或甚至每隔一个弹出方法。它不会抛出任何错误或它执行的任何错误,也不会发生任何事情。我可能会尝试在OpenTX端查看Lua代码。 –