Skip to content

Commit

Permalink
fix(wizard): only add safety SF when configured on (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
offer-shmuely authored Feb 14, 2024
1 parent 1415ff9 commit e3f017e
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 72 deletions.
67 changes: 34 additions & 33 deletions sdcard/c480x272/TEMPLATES/1.Wizard/1.Plane.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

-- Author: 3djc (2017)
-- Update by: Offer Shmuely (2023)
-- version: 2.0
local app_ver="2.1"

local VALUE = 0
local COMBO = 1
Expand Down Expand Up @@ -122,13 +122,13 @@ local function lcdSizeTextFixed(txt, font_size)
elseif font_size == FONT_6 then
v_offset = 0
end
return ts_w, ts_h, v_offset
return ts_w, ts_h +2*v_offset, v_offset
end

local function drawBadgedText(txt, field, font_size, is_selected, is_edit)
local ts_w, ts_h, v_offset = lcdSizeTextFixed(txt, font_size)
ts_h = 10 + ts_h + v_offset * 2
local r = ts_h / 2
local bdg_h = 5 + ts_h + 5
local r = bdg_h / 2

if (field.w > 0) then
ts_w = field.w
Expand All @@ -143,7 +143,7 @@ local function drawBadgedText(txt, field, font_size, is_selected, is_edit)
end
lcd.drawFilledCircle(field.x, field.y + r, r, bg_color)
lcd.drawFilledCircle(field.x + ts_w, field.y + r, r, bg_color)
lcd.drawFilledRectangle(field.x, field.y, ts_w, ts_h, bg_color)
lcd.drawFilledRectangle(field.x, field.y, ts_w, bdg_h, bg_color)
local attr = 0
if (is_selected and is_edit) then
attr = attr + BLINK
Expand Down Expand Up @@ -546,13 +546,6 @@ local function drawNextLine(text, chNum, text2)
lineIndex = lineIndex + 20
end

local ConfigSummaryFields = {
ack = { id = 'ack', x = 110, y = 250, w = 0, type = COMBO, is_visible = 1, value = 0, avail_values = { "No, I need to change something", "Yes, all is well, create the plane !" } },
}
ConfigSummaryFields.page = {
ConfigSummaryFields.ack
}

local ImgSummary

local function runConfigSummary(event)
Expand Down Expand Up @@ -602,7 +595,7 @@ local function runConfigSummary(event)
drawNextLine("V-Tail Left", TailFields.ch_b.value)
end

-- retracts
-- retracts gear
if (GearFields.is_gear.value == 1) then
local switchName = GearFields.switch.avail_values[1 + GearFields.switch.value]
drawNextLine("Gear Switch", nil, switchName)
Expand All @@ -623,12 +616,20 @@ local function runConfigSummary(event)
drawNextLine("Arm switch", nil, switchName)
end

local result = runFieldsPage(ConfigSummaryFields.page, event)
lcd.drawFilledRectangle(60-10, 250-2, 240, 25, YELLOW)
lcd.drawText(60, 250, "Hold [Enter] to apply changes...", COLOR_THEME_PRIMARY1)

if event == EVT_VIRTUAL_EXIT then
-- exit script
return 2
end

if (ConfigSummaryFields.ack.value == 1 and is_edit == false) then
-- approve settings
if (event == EVT_VIRTUAL_ENTER_LONG) then
selectPage(1)
end
return result

return 0
end

local function addMix(channel, input, name, weight, index)
Expand Down Expand Up @@ -691,21 +692,19 @@ local function createModel(event)
updateInputLine(defaultChannel_0_RUD, 0, expoVal, 100, nil)
end



-- motor
if (MotorFields.is_motor.value == 1) then
addMix(MotorFields.motor_ch.value, MIXSRC_FIRST_INPUT + defaultChannel_0_THR, "Motor")
end

-- Ailerons
-- ailerons
if (AilFields.ail_type.value == 1) then
addMix(AilFields.ail_ch_a.value, MIXSRC_FIRST_INPUT + defaultChannel_0_AIL, "Ail")
elseif (AilFields.ail_type.value == 2) then
addMix(AilFields.ail_ch_a.value, MIXSRC_FIRST_INPUT + defaultChannel_0_AIL, "Ail-R")
addMix(AilFields.ail_ch_b.value, MIXSRC_FIRST_INPUT + defaultChannel_0_AIL, "Ail-L", -100)
end
-- Flaps
-- flaps
if (FlapsFields.flap_type.value == 1) then
addMix(FlapsFields.flap_ch_a.value, MIXSRC_SA, "Flaps")
elseif (FlapsFields.flap_type.value == 2) then
Expand Down Expand Up @@ -735,19 +734,21 @@ local function createModel(event)
addMix(GearFields.channel.value, switchIndex, "Gear", 100, 0)
end

-- special function for arm switch
local switchName = MotorFields.arm_switch.avail_values[1 + MotorFields.arm_switch.value]
local switchIndex = getSwitchIndex(switchName .. CHAR_DOWN)
local channelIndex = MotorFields.motor_ch.value

model.setCustomFunction(FUNC_OVERRIDE_CHANNEL, {
switch = switchIndex,
func = 0,
value = -100,
mode = 0,
param = channelIndex, --"CH3"
active = 1
})
-- SF arm switch
if (MotorFields.is_arm.value == 1) then
local switchName = MotorFields.arm_switch.avail_values[1 + MotorFields.arm_switch.value]
local switchIndex = getSwitchIndex(switchName .. CHAR_DOWN)
local channelIndex = MotorFields.motor_ch.value

model.setCustomFunction(FUNC_OVERRIDE_CHANNEL, {
switch = switchIndex,
func = 0,
value = -100,
mode = 0,
param = channelIndex, --"CH3"
active = 1
})
end

selectPage(1)
return 0
Expand Down
35 changes: 16 additions & 19 deletions sdcard/c480x272/TEMPLATES/1.Wizard/1.Plane.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
semver: 2.9.0
header:
name: "Plane"
name: "New Plane"
bitmap: "plane.jpg"
labels: ""
timers:
Expand Down Expand Up @@ -33,27 +33,9 @@ showInstanceIds: 0
customThrottleWarningPosition: 0
beepANACenter: 0
logicalSw:
0:
func: FUNC_VNEG
def: "tele(0),365"
andsw: "NONE"
delay: 0
duration: 0
customFn:
0:
swtch: "SF2"
func: OVERRIDE_CHANNEL
def: "2,-100,1"
1:
swtch: "L1"
func: PLAY_VALUE
def: "tele(0),7"
thrTraceSrc: Thr
switchWarningState: C-FdHu
rssiSource: none
rfAlarms:
warning: 45
critical: 42
thrTrimSw: 0
potsWarnMode: WARN_OFF
jitterFilter: GLOBAL
Expand Down Expand Up @@ -119,6 +101,10 @@ screenData:
type: Bool
value:
boolValue: 0
4:
type: Bool
value:
boolValue: 0
options:
0:
type: Bool
Expand Down Expand Up @@ -225,3 +211,14 @@ topbarData:
boolValue: 1
view: 0

radioThemesDisabled: GLOBAL
radioGFDisabled: GLOBAL
radioTrainerDisabled: GLOBAL
modelHeliDisabled: OFF
modelFMDisabled: OFF
modelCurvesDisabled: GLOBAL
modelGVDisabled: OFF
modelLSDisabled: GLOBAL
modelSFDisabled: GLOBAL
modelCustomScriptsDisabled: OFF
modelTelemetryDisabled: GLOBAL
51 changes: 31 additions & 20 deletions sdcard/c480x272/TEMPLATES/1.Wizard/3.Wing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ local function addField(fields, step)
elseif field.type == COMBO then
min = 0
max = #(field.avail_values) - 1
elseif field.type == HEADER then
min = 0
max = 0
end
if (step < 0 and field.value > min) or (step > 0 and field.value < max) then
field.value = field.value + step
Expand All @@ -86,6 +89,9 @@ local function selectField(fields, step)
repeat
print(string.format("selectField: current: %s (vis: %s)", current, fields[current].is_visible))
current = 1 + ((current + step - 1 + #fields) % #fields)
if fields[current].type == HEADER then
current = 1 + ((current + step - 1 + #fields) % #fields)
end
until fields[current].is_visible == 1
print(string.format("selectField-end: current: %s", current))
end
Expand Down Expand Up @@ -115,7 +121,6 @@ local function lcdSizeTextFixed(txt, font_size)
return ts_w, ts_h, v_offset
end


local function drawBadgedText(txt, field, font_size, is_selected, is_edit)
local ts_w, ts_h, v_offset = lcdSizeTextFixed(txt, font_size)
ts_h = 10 + ts_h + v_offset * 2
Expand All @@ -132,9 +137,9 @@ local function drawBadgedText(txt, field, font_size, is_selected, is_edit)
if (is_selected) then
bg_color = GREEN
end
lcd.drawFilledCircle(field.x , field.y + r, r, bg_color)
lcd.drawFilledCircle(field.x + ts_w , field.y + r, r, bg_color)
lcd.drawFilledRectangle(field.x, field.y , ts_w, ts_h, bg_color)
lcd.drawFilledCircle(field.x, field.y + r, r, bg_color)
lcd.drawFilledCircle(field.x + ts_w, field.y + r, r, bg_color)
lcd.drawFilledRectangle(field.x, field.y, ts_w, ts_h, bg_color)
local attr = 0
if (is_selected and is_edit) then
attr = attr + BLINK
Expand Down Expand Up @@ -165,6 +170,8 @@ local function redrawFieldsPage(fields, event)
--lcd.drawText(field.x, field.y, field.avail_values[1 + field.value], attr)
drawBadgedText(field.avail_values[1 + field.value], field, FONT_8, is_selected, is_edit)
end
elseif field.type == HEADER then
lcd.drawText(field.x, field.y, field.value, FONT_8 + BLACK + attr + BOLD)
end
end
end
Expand Down Expand Up @@ -226,10 +233,9 @@ local function drawTitle(txt)
lcd.drawText(150, 8, txt, COLOR_THEME_PRIMARY1)
end


local MotorFields = {
is_motor = { id='is_motor' , x=170, y=50 , w=0, type=COMBO, is_visible=1, value=1 , avail_values={ "No", "Yes" } },
motor_ch = { id='motor_ch' , x=170, y=90 , w=0, type=COMBO, is_visible=1, value=defaultChannel_0_THR, avail_values={ "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7", "CH8" } },
motor_ch = { id='motor_ch' , x=170, y=90 , w=0, type=COMBO, is_visible=1, value=defaultChannel_0_THR, avail_values={ "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7", "CH8", "CH9", "CH10" } },
is_arm = { id='is_arm' , x=170, y=130, w=0, type=COMBO, is_visible=1, value=1 , avail_values={ "No", "Yes" } },
arm_switch = { id='arm_switch', x=230, y=130, w=0, type=COMBO, is_visible=1, value=5 , avail_values={ "SA", "SB", "SC", "SD", "SE", "SF", "SG", "SH" } },
page = {}
Expand Down Expand Up @@ -393,7 +399,9 @@ end
local function addMix(channel, input, name, weight, index)
local mix = {
source = input,
name = name
name = name,
--carryTrim= 0 -- 0=on
--trimSource= 0 -- 0=on
}
if weight ~= nil then
mix.weight = weight
Expand All @@ -411,6 +419,7 @@ local function updateInputLine(channel, lineNo, expoWeight, weight, switch_name_
inInfo.curveType = 1
inInfo.curveValue = expoWeight
inInfo.weight = weight
inInfo.trimSource = 0 -- 0=on
if (switch_name_position ~= nil) then
local switchIndex = getSwitchIndex(switch_name_position)
inInfo.switch = switchIndex
Expand Down Expand Up @@ -457,19 +466,21 @@ local function createModel(event)
addMix(ElevronFields.ail_ch_l.value, MIXSRC_FIRST_INPUT + defaultChannel(STICK_NUMBER_ELE), "ele-L", 50)
addMix(ElevronFields.ail_ch_l.value, MIXSRC_FIRST_INPUT + defaultChannel(STICK_NUMBER_AIL), "ail-L", 50)

-- special function for arm switch
local switchName = MotorFields.arm_switch.avail_values[1 + MotorFields.arm_switch.value]
local switchIndex = getSwitchIndex(switchName .. CHAR_DOWN)
local channelIndex = MotorFields.motor_ch.value

model.setCustomFunction(FUNC_OVERRIDE_CHANNEL, {
switch = switchIndex,
func = 0,
value = -100,
mode = 0,
param = channelIndex, --"CH3"
active = 1
})
-- SF arm switch
if (MotorFields.is_arm.value == 1) then
local switchName = MotorFields.arm_switch.avail_values[1 + MotorFields.arm_switch.value]
local switchIndex = getSwitchIndex(switchName .. CHAR_DOWN)
local channelIndex = MotorFields.motor_ch.value

model.setCustomFunction(FUNC_OVERRIDE_CHANNEL, {
switch = switchIndex,
func = 0,
value = -100,
mode = 0,
param = channelIndex, --"CH3"
active = 1
})
end

selectPage(1)
return 0
Expand Down

0 comments on commit e3f017e

Please sign in to comment.