2017-07-27 147 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代碼。 –