Skip to content

Commit

Permalink
Update model-lua scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
lthole committed Nov 10, 2024
1 parent 18af36a commit 33259d1
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 1 deletion.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified english/dev-environment/.DS_Store
Binary file not shown.
11 changes: 11 additions & 0 deletions english/dev-environment/manual/macro_support/modellua.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

ETHOS='/mnt/c/Program Files (x86)/FrSky/Ethos'

# These scripts only needed for this macro
cp -r 'macro_support/scripts/lua task example' scripts
cp -r 'macro_support/scripts/source example' scripts
"${ETHOS}/X20S/simulator.exe" --read-only --no-audio --documents-directory ./sd/documents --radio-settings ./x20s-en.bin --sd-directory ./sd --flash-directory ./flash --exec ./macros/model-lua.lua
# Remove the scripts again so the LUA icon only appears in this macro
rm -r 'scripts/lua task example'
rm -r 'scripts/source example'
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
-- Lua Task Example

local taskMin = -100
local taskMax = 100

local function taskInit()
print("Task init")
end

local function taskWakeup(task)
-- print("Task wakeup")
end

local function taskEvent(task)
print("Task event")
end

local function taskConfigure(task)
print("Task configure")
local line = form.addLine("Range")
local slots = form.getFieldSlots(line, {0, "-", 0})
form.addNumberField(line, slots[1], -1024, 1024, function() return taskMin end, function(value) taskMin = value end)
form.addStaticText(line, slots[2], "-")
form.addNumberField(line, slots[3], -1024, 1024, function() return taskMax end, function(value) taskMax = value end)
end

local function taskRead(task)
print("Task read")
taskMin = storage.read("min")
taskMax = storage.read("max")
end

local function taskWrite(task)
print("Task write")
storage.write("min", taskMin)
storage.write("max", taskMax)
end

local function init()
system.registerTask({key="LuaTask", name="Task Example", init=taskInit, wakeup=taskWakeup, event=taskEvent, configure=taskConfigure, read=taskRead, write=taskWrite})
end

return {init=init}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
-- Lua Source Example

local translations = {en="Lua Source", fr="Source Lua"}

local function sourceName(source)
local locale = system.getLocale()
return translations[locale] or translations["en"]
end

local function sourceInit(source)
print("Source init")
source:decimals(2)
source:unit(UNIT_VOLT)
source:value(0.0)
end

local function sourceReset(source)
print("Source reset")
source:value(0.0)
end

local function sourceRead(source)
print("Source read")
source:value(storage.read("Some Key"))
end

local function sourceWrite(source)
print("Source write")
storage.write("Some Key", source:value())
end

local function sourceWakeup(source)
-- print("Source wakeup")
source:value(source:value() + 0.1)
end

local function sourceConfigure(source)
end

local function init()
system.registerSource({key="Example", name=sourceName, init=sourceInit, reset=sourceReset, wakeup=sourceWakeup, configure=sourceConfigure, read=sourceRead, write=sourceWrite})
end

return {init=init}
7 changes: 6 additions & 1 deletion english/dev-environment/manual/modellua.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@

ETHOS='/mnt/c/Program Files (x86)/FrSky/Ethos'

# These scripts only needed for this macro
cp -r 'macro_support/scripts/lua task example' scripts
cp -r 'macro_support/scripts/source example' scripts
"${ETHOS}/X20S/simulator.exe" --read-only --no-audio --documents-directory ./sd/documents --radio-settings ./x20s-en.bin --sd-directory ./sd --flash-directory ./flash --exec ./macros/model-lua.lua

# Remove the scripts again so the LUA icon only appears in this macro
rm -r 'scripts/lua task example'
rm -r 'scripts/source example'

0 comments on commit 33259d1

Please sign in to comment.