Ok, I solved it myself.
I'm not sure if this is the right solution, but it works.
In my case, the reason why I need the form to add a parameter when I use a MEZON sensor, to determine the gearbox setting.
Basically, in the setup form I want to be able to switch from
to
I have a variable, called sensorMode, that determines if the sensor is a MUI or a MEZON. If Mezon is active, there is a revolutions parameter that I need to determine and apply the gearbox reduction in order to obtain the actual propeller revolutions.
first, I added a local variable at the start of the lua code:
local previousSensorMode = sensorMode; -- to change the form
second, I slightly change the code in my setup form. so to skip the gearbox field if sensor mode is not MEZON...
-- only for MEZON, we add the gearbox ratio
if (sensorMode == _MEZ) then
form.addRow(2);
form.addLabel({label = locale.SetupFormGearBoxValueLabel, width = 200});
form.addIntbox(revolutionsGearboxRatio, 100, 1000, 100, 2, 1, gearboxRatioChanged);
form.addSpacer(318,7);
end
now, as this code is present in the setupform function, it's only called once, when we setup the form.
So, I added some code also the the sensorChanged function (that is, the code associated to the change of sensors between MUI and MEZON).
local function sensorChanged(value)
previousSensorMode = sensorMode;
-- some more code here
end
this way I know what was the previous value of sensormode.
Lastly, I add a function to my code, and that is the printform
I change my definition of the setup of the form by adding the proper calls
system.registerForm(1, MENU_APPS, locale.AppName, setupForm, nil, printForm);
and I complete the printform function.
this is called as the loop, every 22ms...
-- print Configuration form
local function printForm()
if (sensorMode ~= previousSensorMode) then
previousSensorMode = sensorMode;
form.reinit();
end
end
the important line is
this line basically respawns the initform code, so the form is effectively regenerated.
hope it helps