Global variables: share data between mix-script and widget
Global variables: share data between mix-script and widget
I used to use global variables to exchange data between telemetry scripts and mixer script.
Now I want to do the same with a widget and a mix-script. Looks like the global var of the widget is not seem from the mix-script.
How can one achieve this?
Thanks!
Now I want to do the same with a widget and a mix-script. Looks like the global var of the widget is not seem from the mix-script.
How can one achieve this?
Thanks!
Re: RE: Global variables: share data between mix-script and widget
You can't. Use a table to store the stuff in a file and read from the other scripts.wilopaan wrote:I used to use global variables to exchange data between telemetry scripts and mixer script.
Now I want to do the same with a widget and a mix-script. Looks like the global var of the widget is not seem from the mix-script.
How can one achieve this?
Thanks!
I gave some info on this on my blog here.
Re: Global variables: share data between mix-script and widget
Well, that is really bad!
writing / reading a file seems to be a quite of overhead.
Are you you sure, that there is not other pssibility? (in the poist above I meant global-lua-script-variables, not global vars in the sense of OpenTx).
The widget i wrote (ab)uses some trims to emulate buttons and produces values that must be sent to a channel. As a telemtry script I could fill a globale lua variable and get this in a mix-script to produce an input for a channel-mixer.
Can you imagine another way to do this?
Thanks!
writing / reading a file seems to be a quite of overhead.
Are you you sure, that there is not other pssibility? (in the poist above I meant global-lua-script-variables, not global vars in the sense of OpenTx).
The widget i wrote (ab)uses some trims to emulate buttons and produces values that must be sent to a channel. As a telemtry script I could fill a globale lua variable and get this in a mix-script to produce an input for a channel-mixer.
Can you imagine another way to do this?
Thanks!
Re: RE: Re: Global variables: share data between mix-script and widget
Create a virtual sensor. Write to it from one script and read from the other.wilopaan wrote:Well, that is really bad!
writing / reading a file seems to be a quite of overhead.
Are you you sure, that there is not other pssibility? (in the poist above I meant global-lua-script-variables, not global vars in the sense of OpenTx).
The widget i wrote (ab)uses some trims to emulate buttons and produces values that must be sent to a channel. As a telemtry script I could fill a globale lua variable and get this in a mix-script to produce an input for a channel-mixer.
Can you imagine another way to do this?
Thanks!
Re: Global variables: share data between mix-script and widget
Well, I can get the value of a sensor with getValue(). How Do I set the value?
Isn't it better to use model.setGlobalVariable() / model.getGlobalVariable() ?
Isn't it better to use model.setGlobalVariable() / model.getGlobalVariable() ?
Re: Global variables: share data between mix-script and widget
Ok, check this script:
https://www.justfly.solutions/index.php ... ogchannels
It writes a channel value to a virtual telemetry channel.
You can just use getValue (sensorname) to read it in the other script.
Don't forget to discover while the sending is active.
https://www.justfly.solutions/index.php ... ogchannels
It writes a channel value to a virtual telemetry channel.
You can just use getValue (sensorname) to read it in the other script.
Don't forget to discover while the sending is active.
Re: Global variables: share data between mix-script and widget
The global variables you referred to are the model gvars.
Re: Global variables: share data between mix-script and widget
Well, I checked your example.
Writing / reading gvars works fine, but clutters the gvars oviously.
setTelemetryValue() / getValue() dows not work for me, since getValue() allways returns 0 for the name used in setTelemetryValue(): the sensor is created, I can see it in the telemetry menu, but getValue() does not work.
Writing / reading gvars works fine, but clutters the gvars oviously.
setTelemetryValue() / getValue() dows not work for me, since getValue() allways returns 0 for the name used in setTelemetryValue(): the sensor is created, I can see it in the telemetry menu, but getValue() does not work.
Re: RE: Re: Global variables: share data between mix-script and widget
Then you are doing something wrong.wilopaan wrote:Well, I checked your example.
Writing / reading gvars works fine, but clutters the gvars oviously.
setTelemetryValue() / getValue() dows not work for me, since getValue() allways returns 0 for the name used in setTelemetryValue(): the sensor is created, I can see it in the telemetry menu, but getValue() does not work.
Post what you have, or at least the write part. Assign the telemetry sensor you created to an input-mix-output chain and watch it on the channel monitor.
Re: Global variables: share data between mix-script and widget
The writing part (widget):
local function background()
local b = setTelemetryValue(0Xabcd,0,101, 42, 0, 0, "wm01");
if (b) then
print("add ch1");
else
print("set ch1");
end
end
The written value is visible in the telemtry screen.
The reading part (mix script):
local function run()
-- print("m: ", model.getGlobalVariable(8, getFlightMode()));
print("m: ", getValue("wm01"));
return 0;
end
The debug output of this script gives always 0.
local function background()
local b = setTelemetryValue(0Xabcd,0,101, 42, 0, 0, "wm01");
if (b) then
print("add ch1");
else
print("set ch1");
end
end
The written value is visible in the telemtry screen.
The reading part (mix script):
local function run()
-- print("m: ", model.getGlobalVariable(8, getFlightMode()));
print("m: ", getValue("wm01"));
return 0;
end
The debug output of this script gives always 0.
Re: Global variables: share data between mix-script and widget
You have to activate the telemetry simuator in the sim as well. little tickbox in the left to corner of the telemetry sensor simulator screen .
testscript (run as telemetry, discover sensors):
return
{
background =
function()
setTelemetryValue(0Xabcd,0,101, getValue('thr'), 0, 0, "wm01");
end,
run =
function()
lcd.clear()
lcd.drawText(10,10,"wm01 : " .. getValue("wm01"))
lcd.drawText(10,20,"telem1: " .. getValue("telem1"))
lcd.drawText(10,30,"telem2: " .. getValue("telem2"))
lcd.drawText(10,40,"telem3: " .. getValue("telem3"))
end,
}
testscript (run as telemetry, discover sensors):
return
{
background =
function()
setTelemetryValue(0Xabcd,0,101, getValue('thr'), 0, 0, "wm01");
end,
run =
function()
lcd.clear()
lcd.drawText(10,10,"wm01 : " .. getValue("wm01"))
lcd.drawText(10,20,"telem1: " .. getValue("telem1"))
lcd.drawText(10,30,"telem2: " .. getValue("telem2"))
lcd.drawText(10,40,"telem3: " .. getValue("telem3"))
end,
}
Re: Global variables: share data between mix-script and widget
Oh yeah, the telemetry simulator ...lshems wrote: ↑Fri Jun 05, 2020 6:44 pm You have to activate the telemetry simuator in the sim as well. little tickbox in the left to corner of the telemetry sensor simulator screen .
testscript (run as telemetry, discover sensors):
return
{
background =
function()
setTelemetryValue(0Xabcd,0,101, getValue('thr'), 0, 0, "wm01");
end,
run =
function()
lcd.clear()
lcd.drawText(10,10,"wm01 : " .. getValue("wm01"))
lcd.drawText(10,20,"telem1: " .. getValue("telem1"))
lcd.drawText(10,30,"telem2: " .. getValue("telem2"))
lcd.drawText(10,40,"telem3: " .. getValue("telem3"))
end,
}
Thanks, I will try that!