Lua mixes setup fixes

This commit is contained in:
bsongis
2014-05-28 22:44:41 +02:00
parent 483e36e646
commit 8c43ec47af
3 changed files with 51 additions and 41 deletions
+23 -13
View File
@@ -550,12 +550,11 @@ static int getFirstMix(int chn)
{ {
for (int i=0; i<MAX_MIXERS; i++) { for (int i=0; i<MAX_MIXERS; i++) {
MixData * mix = mixAddress(i); MixData * mix = mixAddress(i);
if (!mix->srcRaw || mix->destCh>chn) break; if (!mix->srcRaw || mix->destCh>=chn) {
if (mix->destCh == chn) {
return i; return i;
} }
} }
return -1; return 0;
} }
static int getMixesCountFromFirst(int chn, int first) static int getMixesCountFromFirst(int chn, int first)
@@ -574,9 +573,6 @@ static int getMixesCountFromFirst(int chn, int first)
static int getMixesCount(int chn) static int getMixesCount(int chn)
{ {
int first = getFirstMix(chn); int first = getFirstMix(chn);
if (first < 0) {
return 0;
}
return getMixesCountFromFirst(chn, first); return getMixesCountFromFirst(chn, first);
} }
@@ -594,7 +590,7 @@ static int luaModelGetMix(lua_State *L)
int idx = luaL_checkunsigned(L, 2); int idx = luaL_checkunsigned(L, 2);
int first = getFirstMix(chn); int first = getFirstMix(chn);
int count = getMixesCountFromFirst(chn, first); int count = getMixesCountFromFirst(chn, first);
if (first>=0 && idx<count) { if (idx<count) {
MixData * mix = mixAddress(first+idx); MixData * mix = mixAddress(first+idx);
lua_newtable(L); lua_newtable(L);
lua_pushtablezstring(L, "name", mix->name); lua_pushtablezstring(L, "name", mix->name);
@@ -619,8 +615,7 @@ static int luaModelInsertMix(lua_State *L)
int count = getMixesCountFromFirst(chn, first); int count = getMixesCountFromFirst(chn, first);
if (chn<NUM_CHNOUT && getExpoMixCount(0)<MAX_MIXERS && idx<=count) { if (chn<NUM_CHNOUT && getExpoMixCount(0)<MAX_MIXERS && idx<=count) {
if (first > 0) idx += first;
idx += first;
s_currCh = chn+1; s_currCh = chn+1;
insertExpoMix(0, idx); insertExpoMix(0, idx);
MixData *mix = mixAddress(idx); MixData *mix = mixAddress(idx);
@@ -661,7 +656,7 @@ static int luaModelDeleteMix(lua_State *L)
int first = getFirstMix(chn); int first = getFirstMix(chn);
int count = getMixesCountFromFirst(chn, first); int count = getMixesCountFromFirst(chn, first);
if (first>=0 && idx<count) { if (idx<count) {
deleteExpoMix(0, first+idx); deleteExpoMix(0, first+idx);
} }
@@ -895,10 +890,24 @@ static int luaPopupInput(lua_State *L)
return 1; 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); 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; return 1;
} }
@@ -1034,7 +1043,8 @@ void luaInit()
lua_register(L, "playFile", luaPlayFile); lua_register(L, "playFile", luaPlayFile);
lua_register(L, "playNumber", luaPlayNumber); lua_register(L, "playNumber", luaPlayNumber);
lua_register(L, "popupInput", luaPopupInput); 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); lua_register(L, "killEvents", luaKillEvents);
// Push OpenTX constants // Push OpenTX constants
+5 -9
View File
@@ -15,7 +15,7 @@ local fieldsMax = 0
local engineMode = 0 local engineMode = 0
local engineCH1 = 0 local engineCH1 = 0
local elevonsCH1 = 0 local elevonsCH1 = 0
local elevonsCH2 = 4 local elevonsCH2 = 0
local elevonsMode = 0 local elevonsMode = 0
local rudderMode = 1 local rudderMode = 1
local rudderCH1 = 0 local rudderCH1 = 0
@@ -113,14 +113,10 @@ end
-- Init function -- Init function
local function init() local function init()
for stick = 0, 3, 1 do rudderCH1 = defaultChannel(0)
local index = channelOrder(stick); engineCH1 = defaultChannel(2)
if index == 0 then elevonsCH1 = defaultChannel(1)
rudderCH1 = stick elevonsCH2 = defaultChannel(3)
elseif index == 2 then
engineCH1 = stick
end
end
end end
-- Engine Menu -- Engine Menu
+23 -19
View File
@@ -123,18 +123,10 @@ end
-- Init function -- Init function
local function init() local function init()
for stick = 0, 3, 1 do rudCH1 = defaultChannel(0)
local index = channelOrder(stick); eleCH1 = defaultChannel(1)
if index == 0 then engineCH1 = defaultChannel(2)
rudCH1 = stick aileronsCH1 = defaultChannel(3)
elseif index == 1 then
eleCH1 = stick
elseif index == 2 then
engineCH1 = stick
else
aileronsCH1 = stick
end
end
end end
-- Engine Menu -- Engine Menu
@@ -176,7 +168,7 @@ end
local function applyEngineSettings() local function applyEngineSettings()
if engineMode == 0 then if engineMode == 0 then
mix = {source=channelOrder(2)} local mix = { source=1+defaultChannel(2) }
model.insertMix(engineCH1, 0, mix) model.insertMix(engineCH1, 0, mix)
end end
end end
@@ -228,6 +220,17 @@ local function aileronsMenu(event)
end end
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 -- Flaps Menu
local flapsModeItems = {"No", "Yes...", "Yes, 2 channels..."} local flapsModeItems = {"No", "Yes...", "Yes, 2 channels..."}
local function drawFlapsMenu() local function drawFlapsMenu()
@@ -429,12 +432,6 @@ local function servoMenu(event)
end end
-- Confirmation Menu -- Confirmation Menu
local function applySettings()
model.defaultInputs()
model.deleteMixes()
applyEngineSettings()
end
local function nextLine(x, y) local function nextLine(x, y)
y = y + 8 y = y + 8
if y > 50 then if y > 50 then
@@ -513,6 +510,13 @@ local function drawConfirmationMenu()
fieldsMax = 0 fieldsMax = 0
end end
local function applySettings()
model.defaultInputs()
model.deleteMixes()
applyEngineSettings()
applyAileronsSettings()
end
local function confirmationMenu(event) local function confirmationMenu(event)
if dirty then if dirty then
dirty = false dirty = false