Skip to content

elrsV3.lua: added editing of parameter type string #2995

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: 3.x.x-maintenance
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactored
  • Loading branch information
wimalopaan committed Oct 19, 2024
commit 696132dd2223ce6080174a0e59a80a5a2463f906
30 changes: 6 additions & 24 deletions src/lua/elrsV3.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,30 +72,12 @@ local function getField(line)
end

local subFieldIndex = 1

local function textEdit(field, step)
local stringPossibleChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_#-."
local function incrCharInTextField(field, step)
local c = string.sub(field.value, subFieldIndex, subFieldIndex)
if (step == 1) then
if (c == "Z") then
c = "a"
elseif (c == "z") then
c = "0"
elseif (c == "9") then
c = "A"
else
c = string.char(string.byte(c) + 1)
end
elseif (step == -1) then
if (c == "A") then
c = "9"
elseif (c == "0") then
c = "z"
elseif (c == "a") then
c = "Z"
else
c = string.char(string.byte(c) - 1)
end
end
local idx = string.find(stringPossibleChars, c, 1, true)
idx = (idx + step + #stringPossibleChars - 1) % #stringPossibleChars + 1
c = string.sub(stringPossibleChars, idx, idx)
field.value = string.sub(field.value, 1, subFieldIndex - 1) .. c .. string.sub(field.value, subFieldIndex + 1, string.len(field.value))
end

Expand All @@ -120,7 +102,7 @@ local function incrField(step)
min = 0
max = #field.values - 1
elseif field.type == 10 then
return textEdit(field, step)
return incrCharInTextField(field, step)
end

local newval = field.value
Expand Down