Skip to content
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

feat(color): add FILE type for widget options #5605

Merged
merged 1 commit into from
Oct 18, 2024

Conversation

philmoz
Copy link
Collaborator

@philmoz philmoz commented Oct 11, 2024

Resolves #5573

Parameters:

  • Option name
  • FILE
  • default value
  • Folder to open to select file

Only the filename is returned for the option, excluding the path.
Filenames are limited to 12 characters maximum length.

Note

String widget option is increased from 8 characters to 12 characters

Example:

  { "File", FILE, "testimg.png", "/IMAGES"},

@philmoz philmoz added color Related generally to color LCD radios widget lua labels Oct 11, 2024
@philmoz philmoz added this to the 2.11 milestone Oct 11, 2024
@wimalopaan
Copy link
Contributor

Just tested in simulator: works for me! Many thanks!!!

@wimalopaan
Copy link
Contributor

If a widget wants to use this feature but uses fw without this PR, in simulator it gives a PANIC.
What is the best way to check if this feature is available (apart from checking the fw version)?

@pfeerick pfeerick changed the title feat(color): add FILE type for widget options. feat(color): add FILE type for widget options Oct 18, 2024
@pfeerick
Copy link
Member

LGTM with a dumb picture widget on TX16S. This should be handy for quite a few types of widget :)

As has been the case when using other capabilities not existant in older firmware , a widget that uses this new option will simply not be available on older firmware.

local name = "showimg"

-- Create a table with default options
-- Options can be changed by the user from the Widget Settings menu
-- Notice that each line is a table inside { }
local options = {
  { "File", FILE, "testimg.png", "/IMAGES"},
  { "Text", STRING, "Max8chrs" } -- now 12
}

local function log(s)
  print("showimg: " .. s)
  return
end

local function create(zone, options)
  -- Runs one time when the widget instance is registered
  -- Store zone and options in the widget table for later use
  local wgt= {
    zone = zone,
    options = options
  }
  -- Return widget table to EdgeTX
  return wgt
end

local function update(wgt, options)
  -- Runs if options are changed from the Widget Settings menu
  if (wgt == nil) then return end
  wgt.options = options
end

local function background(wgt)
  -- Runs periodically only when widget instance is not visible
end

local function refresh(wgt, event, touchState)
  -- Runs periodically only when widget instance is visible
  -- If full screen, then event is 0 or event value, otherwise nil

  if (wgt == nil)               then log("refresh(nil)")                   return end
  if (wgt.options == nil)       then log("refresh(wgt.options=nil)")       return end

  log("check if file exists")
  local file = io.open("/IMAGES/" .. wgt.options.File, "r")
  if file then
    log("show image - " .. wgt.options.File)
    io.close(file)
    local myLogo = bitmap.open("/IMAGES/" .. wgt.options.File)
    lcd.drawBitmap(myLogo,10,10)
  else
    log("refresh(wgt.options.File=not exist)")
    return
  end
end

return {
  name = name,
  options = options,
  create = create,
  update = update,
  refresh = refresh,
  background = background
}

@pfeerick pfeerick merged commit 1deac60 into main Oct 18, 2024
51 checks passed
@pfeerick pfeerick deleted the philmoz/add-file-option-type branch October 18, 2024 00:47
@philmoz
Copy link
Collaborator Author

philmoz commented Oct 22, 2024

If a widget wants to use this feature but uses fw without this PR, in simulator it gives a PANIC.

Where are you seeing a PANIC? If you try and use the option on 2.10 or earlier it should ignore the widget because of the unknown option type.

@wimalopaan
Copy link
Contributor

In simulator211 (e.g. main just before merging this PR) I get:

30ms: luaLoadWidgetCallback()
-E- PANIC: unprotected error in call to Lua API (bad argument #-1 (number expected, got string))
30ms: error in theme/widget options
munmap_chunk(): invalid pointer
Aborted (core dumped)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
color Related generally to color LCD radios lua widget
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add file selector for LUA widget options
3 participants