Lua mixes setup fixes
This commit is contained in:
+23
-13
@@ -550,12 +550,11 @@ static int getFirstMix(int chn)
|
||||
{
|
||||
for (int i=0; i<MAX_MIXERS; i++) {
|
||||
MixData * mix = mixAddress(i);
|
||||
if (!mix->srcRaw || mix->destCh>chn) break;
|
||||
if (mix->destCh == chn) {
|
||||
if (!mix->srcRaw || mix->destCh>=chn) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int getMixesCountFromFirst(int chn, int first)
|
||||
@@ -574,9 +573,6 @@ static int getMixesCountFromFirst(int chn, int first)
|
||||
static int getMixesCount(int chn)
|
||||
{
|
||||
int first = getFirstMix(chn);
|
||||
if (first < 0) {
|
||||
return 0;
|
||||
}
|
||||
return getMixesCountFromFirst(chn, first);
|
||||
}
|
||||
|
||||
@@ -594,7 +590,7 @@ static int luaModelGetMix(lua_State *L)
|
||||
int idx = luaL_checkunsigned(L, 2);
|
||||
int first = getFirstMix(chn);
|
||||
int count = getMixesCountFromFirst(chn, first);
|
||||
if (first>=0 && idx<count) {
|
||||
if (idx<count) {
|
||||
MixData * mix = mixAddress(first+idx);
|
||||
lua_newtable(L);
|
||||
lua_pushtablezstring(L, "name", mix->name);
|
||||
@@ -619,8 +615,7 @@ static int luaModelInsertMix(lua_State *L)
|
||||
int count = getMixesCountFromFirst(chn, first);
|
||||
|
||||
if (chn<NUM_CHNOUT && getExpoMixCount(0)<MAX_MIXERS && idx<=count) {
|
||||
if (first > 0)
|
||||
idx += first;
|
||||
idx += first;
|
||||
s_currCh = chn+1;
|
||||
insertExpoMix(0, idx);
|
||||
MixData *mix = mixAddress(idx);
|
||||
@@ -661,7 +656,7 @@ static int luaModelDeleteMix(lua_State *L)
|
||||
int first = getFirstMix(chn);
|
||||
int count = getMixesCountFromFirst(chn, first);
|
||||
|
||||
if (first>=0 && idx<count) {
|
||||
if (idx<count) {
|
||||
deleteExpoMix(0, first+idx);
|
||||
}
|
||||
|
||||
@@ -895,10 +890,24 @@ static int luaPopupInput(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luaChannelOrder(lua_State *L)
|
||||
static int luaDefaultStick(lua_State *L)
|
||||
{
|
||||
uint8_t channel = luaL_checkinteger(L, 1);
|
||||
lua_pushinteger(L, channel_order(channel+1)-1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luaDefaultChannel(lua_State *L)
|
||||
{
|
||||
uint8_t stick = luaL_checkinteger(L, 1);
|
||||
lua_pushinteger(L, channel_order(stick+1)-1);
|
||||
for (int i=1; i<=4; i++) {
|
||||
int tmp = channel_order(i) - 1;
|
||||
if (tmp == stick) {
|
||||
lua_pushinteger(L, i-1);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1034,7 +1043,8 @@ void luaInit()
|
||||
lua_register(L, "playFile", luaPlayFile);
|
||||
lua_register(L, "playNumber", luaPlayNumber);
|
||||
lua_register(L, "popupInput", luaPopupInput);
|
||||
lua_register(L, "channelOrder", luaChannelOrder);
|
||||
lua_register(L, "defaultStick", luaDefaultStick);
|
||||
lua_register(L, "defaultChannel", luaDefaultChannel);
|
||||
lua_register(L, "killEvents", luaKillEvents);
|
||||
|
||||
// Push OpenTX constants
|
||||
|
||||
@@ -15,7 +15,7 @@ local fieldsMax = 0
|
||||
local engineMode = 0
|
||||
local engineCH1 = 0
|
||||
local elevonsCH1 = 0
|
||||
local elevonsCH2 = 4
|
||||
local elevonsCH2 = 0
|
||||
local elevonsMode = 0
|
||||
local rudderMode = 1
|
||||
local rudderCH1 = 0
|
||||
@@ -113,14 +113,10 @@ end
|
||||
|
||||
-- Init function
|
||||
local function init()
|
||||
for stick = 0, 3, 1 do
|
||||
local index = channelOrder(stick);
|
||||
if index == 0 then
|
||||
rudderCH1 = stick
|
||||
elseif index == 2 then
|
||||
engineCH1 = stick
|
||||
end
|
||||
end
|
||||
rudderCH1 = defaultChannel(0)
|
||||
engineCH1 = defaultChannel(2)
|
||||
elevonsCH1 = defaultChannel(1)
|
||||
elevonsCH2 = defaultChannel(3)
|
||||
end
|
||||
|
||||
-- Engine Menu
|
||||
|
||||
+23
-19
@@ -123,18 +123,10 @@ end
|
||||
|
||||
-- Init function
|
||||
local function init()
|
||||
for stick = 0, 3, 1 do
|
||||
local index = channelOrder(stick);
|
||||
if index == 0 then
|
||||
rudCH1 = stick
|
||||
elseif index == 1 then
|
||||
eleCH1 = stick
|
||||
elseif index == 2 then
|
||||
engineCH1 = stick
|
||||
else
|
||||
aileronsCH1 = stick
|
||||
end
|
||||
end
|
||||
rudCH1 = defaultChannel(0)
|
||||
eleCH1 = defaultChannel(1)
|
||||
engineCH1 = defaultChannel(2)
|
||||
aileronsCH1 = defaultChannel(3)
|
||||
end
|
||||
|
||||
-- Engine Menu
|
||||
@@ -176,7 +168,7 @@ end
|
||||
|
||||
local function applyEngineSettings()
|
||||
if engineMode == 0 then
|
||||
mix = {source=channelOrder(2)}
|
||||
local mix = { source=1+defaultChannel(2) }
|
||||
model.insertMix(engineCH1, 0, mix)
|
||||
end
|
||||
end
|
||||
@@ -228,6 +220,17 @@ local function aileronsMenu(event)
|
||||
end
|
||||
end
|
||||
|
||||
local function applyAileronsSettings()
|
||||
if aileronsMode ~= 1 then
|
||||
local mix = { source=1+defaultChannel(3) }
|
||||
model.insertMix(aileronsCH1, 0, mix)
|
||||
if aileronsMode == 2 then
|
||||
mix = { source=1+defaultChannel(3), weight=-100 }
|
||||
model.insertMix(aileronsCH2, 0, mix)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Flaps Menu
|
||||
local flapsModeItems = {"No", "Yes...", "Yes, 2 channels..."}
|
||||
local function drawFlapsMenu()
|
||||
@@ -429,12 +432,6 @@ local function servoMenu(event)
|
||||
end
|
||||
|
||||
-- Confirmation Menu
|
||||
local function applySettings()
|
||||
model.defaultInputs()
|
||||
model.deleteMixes()
|
||||
applyEngineSettings()
|
||||
end
|
||||
|
||||
local function nextLine(x, y)
|
||||
y = y + 8
|
||||
if y > 50 then
|
||||
@@ -513,6 +510,13 @@ local function drawConfirmationMenu()
|
||||
fieldsMax = 0
|
||||
end
|
||||
|
||||
local function applySettings()
|
||||
model.defaultInputs()
|
||||
model.deleteMixes()
|
||||
applyEngineSettings()
|
||||
applyAileronsSettings()
|
||||
end
|
||||
|
||||
local function confirmationMenu(event)
|
||||
if dirty then
|
||||
dirty = false
|
||||
|
||||
Reference in New Issue
Block a user