PK 3U 9 instruments/3172aa53-47b5-415e-3366-878815a98a49/info.xml Boeing 737-700 (PMDG)Overhead - Generator Switches3172aa53-47b5-415e-3366-878815a98a49Detlef von ReusnerControl illumination per user prop and the when "Dial" is selected per light dials in the cockpit, captain side left of the FMC.
falsefalsefalsefalsetrue1001100400400WINDOWSMACLINUXRASPBERRY_PIANDROIDIPADESP32HOME_USE_STANDARDPKr] PK U C : instruments/3172aa53-47b5-415e-3366-878815a98a49/logic.luaC-- Detlef von Reusner
-- PMDG B737-700 Overhead panel generator switches (and ground power)
-- FS2020
-- Aug 3 2022 V1.00
local gPropIllumination = user_prop_get(user_prop_add_enum("Illumination","Day,Night,Dial","Day","Select fix or left forward panel dial controlled illumination"))
img_add_fullscreen("bg-day.png")
local gNightColor = img_add_fullscreen("night-color.png")
opacity(gNightColor, 0) -- max. .2 for night color
local gBlackMask = canvas_add(0, 0, 400, 400, function()
_rect(0, 0, 400, 400)
_fill("black")
end)
opacity(gBlackMask, 0.) -- 0 == full brightness, .9 == darkest value that makes sense
local gColorAmber = string.format(";color:#%02x%02x%02x", 243, 163, 90)
local gColorBlue = string.format(";color:#%02x%02x%02x", 250, 250, 250)
local gColorGreen = string.format(";color:#%02x%02x%02x", 98, 208, 103)
local gColorPrint = "#E0E0E0FF"
local gColorBg = "#101010FF"
--- night color for texts and lines
local gNightR = 248
local gNightG = 217
local gNightB = 135
local gDaylight
local gScalesLight
local gFontLight = "font:arimo_bold.ttf; size:14"
local gDebugShowTouchFields = false
local gTouchField
if gDebugShowTouchFields then
gTouchField = "touch-field-on.png"
else
gTouchField = "touch-field-off.png"
end
-- =================== Draw lines ==================
function DrawPath(x, y, path)
-- path = {x1, y1, x2, y2} and so on
local count = #path/2
local x0, x1, x2, y0, y1, y2, dx, dy
x0 = x
y0 = y
-- background
_move_to(x, y)
for k=0,count-1 do
_line_to(path[2*k+1], path[2*k+2])
end
_stroke(gColorBg, 15)
-- ----------------- outer line
for k=0,count-1 do
x1 = path[2*k+1] -- line target
y1 = path[2*k+2]
x2 = path[2*k+3] -- next line target
y2 = path[2*k+4]
if y1 == y then -- horizontal
if x1 > x then
dx = 4
else
dx = -4
end
if y2 == nil then
-- no change
elseif y2y then
dy = 4
else
dy = -4
end
if x2 == nil then
-- no change
elseif x2>x1 then
dx = -4
else
dy = 4
end
if k==0 then
_move_to(x+dx, y+dy)
end
_line_to(x+dx, y1+dy)
end
x = x1
y = y1
end
_stroke(gColorPrint, 2)
-- ------------------- inner line
x = x0
y = y0
for k=0,count-1 do
x1 = path[2*k+1] -- line target
y1 = path[2*k+2]
x2 = path[2*k+3] -- next line target
y2 = path[2*k+4]
if y1 == y then -- horizontal
if x1 > x then
dx = -4
else
dx = 4
end
if y2 == nil then
-- no change
elseif y2y then
dy = -4
else
dy = 4
end
if x2 == nil then
-- no change
elseif x2>x1 then
dx = 4
else
dy = -4
end
if k==0 then
_move_to(x+dx, y+dy)
end
_line_to(x+dx, y1+dy)
end
x = x1
y = y1
end
_stroke(gColorPrint, 2)
end
function DrawAllLines()
_move_to(40, 392)
_line_to(358, 392)
_stroke(gColorPrint, 2)
DrawPath(250, 343, {216, 343, 216, 238, 322, 238, 322, 343}) -- always clockwise!
DrawPath(79, 343, {79, 238, 185, 238, 185, 343, 150, 343})
end
local gImgLines = canvas_add(0, 0, 400, 400, DrawAllLines)
-- ====================== Texts =================
local gFontPrintBig = "font:roboto_bold.ttf; size:24"
local gFontPrintSmall = "font:roboto_bold.ttf; size:18"
function PrintText(text, x, y, style, size)
local count = string.len(text)
_rect(x-3, y, count/2*size+7, size)
_fill(gColorBg)
_txt(text, style, x, y-1)
end
function PrintVertText(text, x, y, style, size)
local count = string.len(text)
local step = size*.7
_rect(x, y, size, count*step+step/2)
_fill(gColorBg)
for k=1,count do
_txt(string.sub(text, k, k), style, x+5, y+(k-1)*step)
end
end
function DrawAllTexts()
local style = gFontPrintBig..";color:"..gColorPrint.."; halign:left"
PrintText("BUSTRANS", 154, 145, style, 24)
PrintText("GRD", 132, 86, style, 24)
PrintText("PWR", 230, 86, style, 24)
PrintText("APUGEN", 165, 356, style, 24)
PrintText("APU", 186, 374, style, 24)
PrintText("GEN1", 56, 367, style, 24)
PrintText("GEN2", 302, 367, style, 24)
style = gFontPrintSmall..";color:"..gColorPrint.."; halign:left"
PrintText("OFF", 100, 313, style, 18)
PrintText("ON", 105, 351, style, 18)
PrintText("OFF", 275, 313, style, 18)
PrintText("ON", 277, 351, style, 18)
PrintText("OFF", 154, 66, style, 18)
PrintText("ON", 158, 112, style, 18)
PrintVertText("OFF", 135, 176, style, 18)
PrintVertText("AUTO", 253, 169, style, 18)
end
local gImgTexts = canvas_add(0, 0, 400, 400, DrawAllTexts)
-- ===================== images above lines ================
img_add("frames.png", 0, 0, 400, 400)
-- =============================== switch lib functions ====================
local gSwitch = {}
local gSwitchCount = 0
function ShowTouchField(x, y, w, h)
if not gDebugShowTouchFields then return end
canvas_add(x, y, w, h, function()
_rect(0, 0, w, h)
_fill("#FF000020")
end)
end
function AddVerticalSwitch(x, y, p1, p2, p3, call_back)
-- e.g.: if p1, p2 and p3 are true, this switch has all three positions
x = x - 76
y = y - 20
gSwitchCount = gSwitchCount+1
gSwitch[gSwitchCount] = {}
local s = gSwitch[gSwitchCount]
local w, h, img, meta
img = "switch-up.png" -- all three switch position pictures assumed the same size
meta = resource_info(img)
if meta == nil then print(img.." not found"); return 0 end
w = meta.WIDTH
h = meta.HEIGHT
local x_touch, y_touch, w_touch, h_touch
x_touch = x + w/8
y_touch = y
w_touch = w * 3/4
h_touch = h/2-1
do
local n = gSwitchCount
button_add(gTouchField, nil, x_touch, y_touch, w_touch, h_touch, function() call_back(n, -1) end, nil) -- dec button
button_add(gTouchField, nil, x_touch, y_touch+1+h_touch, w_touch, h_touch, function() call_back(n, 1) end, nil) -- inc button
end
s.img = {} -- stores the images for all switch positions
if p1 then
img = "switch-up.png"
s.img[1] = img_add(img, x, y, w, h)
visible(s.img[1], false)
end
if p2 then
img = "switch-middle.png"
s.img[2] = img_add(img, x, y, w, h)
visible(s.img[2], false)
end
if p3 then
img = "switch-down.png"
s.img[3] = img_add(img, x, y, w, h)
visible(s.img[3], false)
end
s.pos = nil
return gSwitchCount
end
function AddHorGuardSwitch(x, y, p1, p2, p3, cb_switch, cb_guard)
gSwitchCount = gSwitchCount+1
gSwitch[gSwitchCount] = {}
local s = gSwitch[gSwitchCount]
local x_touch, y_touch, w_touch, h_touch
local img, meta, w, h, dx, dy -- dx, dy offset for switch
dx = 34
dy = 20
img = "black-hor-guard-open.png"
meta = resource_info(img)
if meta == nil then print(img.." not found"); return 0 end
w = meta.WIDTH
h = meta.HEIGHT
s.img_open = img_add(img, x, y, w, h)
visible(s.img_open, false)
x_touch = x
y_touch = y
w_touch = w/4-1
h_touch = h
do -- create buttons for guard open/close and switch increment/decrement
local n = gSwitchCount
button_add(gTouchField, nil, x_touch, y_touch, w_touch, h_touch, function() cb_guard(n, -1) end, nil)
button_add(gTouchField, nil, x+3*(w_touch+1), y_touch, w_touch, h_touch, function() cb_guard(n, 1) end, nil)
button_add(gTouchField, nil, x_touch+w_touch+1, y_touch, w_touch, h_touch, function() cb_switch(n, -1) end, nil)
button_add(gTouchField, nil, x_touch+2*(w_touch+1), y_touch, w_touch, h_touch, function() cb_switch(n, 1) end, nil)
end
s.img = {} -- stores the images for all switch positions
do
local w, h
img = "small-hor-switch-left.png"
meta = resource_info(img)
if meta == nil then print(img.." not found"); return 0 end
w = meta.WIDTH
h = meta.HEIGHT
if p1 then
img = "small-hor-switch-left.png"
s.img[1] = img_add(img, x+dx, y+dy, w, h)
visible(s.img[1], false)
end
if p2 then
img = "small-hor-switch-middle.png"
s.img[2] = img_add(img, x+dx, y+dy, w, h)
visible(s.img[2], false)
end
if p3 then
img = "small-hor-switch-right.png"
s.img[3] = img_add(img, x+dx, y+dy, w, h)
visible(s.img[3], false)
end
end
img = "black-hor-guard-closed.png"
s.img_closed = img_add(img, x, y, w, h)
visible(s.img_closed, true)
s.closed = true
s.pos = nil
return gSwitchCount
end
function SetSwitchPosition(switch, target)
local s = gSwitch[switch]
if target == nil then return end
visible(s.img[target], true)
if s.pos ~= nil then visible(s.img[s.pos], false) end
s.pos = target
end
function CloseGuard(switch, yes)
local s = gSwitch[switch]
visible(s.img_closed, yes)
visible(s.img_open, not yes)
s.closed = yes
end
-- ====================== operate switches ==================
---------------------- Gen1 switch ----------------
local gSwitchGen1
function cbSwitchGen1(switch, dir)
if dir > 0 then
fs2020_event("ROTOR_BRAKE", 2701)
else
fs2020_event("ROTOR_BRAKE", 2702)
end
end
fs2020_variable_subscribe("L:switch_27_73X", "number", function(v)
SetSwitchPosition(gSwitchGen1, math.floor(v/50)+1)
end)
gSwitchGen1 = AddVerticalSwitch(105, 301, true, true, true, cbSwitchGen1)
----------------- APU left switch ----------------
local gSwitchApuLeft
function cbSwitchApuLeft(switch, dir)
if dir>0 then
fs2020_event("ROTOR_BRAKE", 2801)
else
fs2020_event("ROTOR_BRAKE", 2802)
end
end
fs2020_variable_subscribe("L:switch_28_73X", "number", function(v)
SetSwitchPosition(gSwitchApuLeft, math.floor(v/50)+1)
end)
gSwitchApuLeft = AddVerticalSwitch(174, 301, true, true, true, cbSwitchApuLeft)
----------------- APU right switch ----------------
local gSwitchApuRight
function cbSwitchApuRight(switch, dir)
if dir>0 then
fs2020_event("ROTOR_BRAKE", 2901)
else
fs2020_event("ROTOR_BRAKE", 2902)
end
end
fs2020_variable_subscribe("L:switch_29_73X", "number", function(v)
SetSwitchPosition(gSwitchApuRight, math.floor(v/50)+1)
end)
gSwitchApuRight = AddVerticalSwitch(278, 301, true, true, true, cbSwitchApuRight)
---------------------- Gen2 switch ----------------
local gSwitchGen2
function cbSwitchGen2(switch, dir)
if dir>0 then
fs2020_event("ROTOR_BRAKE", 3001)
else
fs2020_event("ROTOR_BRAKE", 3002)
end
end
fs2020_variable_subscribe("L:switch_30_73X", "number", function(v)
SetSwitchPosition(gSwitchGen2, math.floor(v/50)+1)
end)
gSwitchGen2 = AddVerticalSwitch(349, 301, true, true, true, cbSwitchGen2)
---------------------------- Ground power available switch -------------------
local gSwitchGroundPowerAvailable
function cbSwitchGroundPowerAvailable(switch, dir)
if dir>0 then
fs2020_event("ROTOR_BRAKE", 1701)
else
fs2020_event("ROTOR_BRAKE", 1702)
end
end
fs2020_variable_subscribe("L:switch_17_73X", "number", function(v)
SetSwitchPosition(gSwitchGroundPowerAvailable, math.floor(v/50)+1)
end)
gSwitchGroundPowerAvailable = AddVerticalSwitch(226, 57, true, true, true, cbSwitchGroundPowerAvailable)
------------------ Bus trans switch with guard cover ---------------------------
local gSwitchBusTrans
function cbSwitchBusTrans(switch, dir)
local s = gSwitch[switch]
if s.closed then
fs2020_event("ROTOR_BRAKE", 1901) -- open cover with any button
return
end
fs2020_event("ROTOR_BRAKE", 1801)
-- if dir>0 then
-- fs2020_event("ROTOR_BRAKE", 1801)
-- else
-- fs2020_event("ROTOR_BRAKE", 1802)
-- end
end
fs2020_variable_subscribe("L:switch_18_73X", "number", function(v)
if v==0 then
SetSwitchPosition(gSwitchBusTrans, 1)
else
SetSwitchPosition(gSwitchBusTrans, 2)
end
end)
function cbGuardBusTrans(switch, dir)
local s = gSwitch[switch]
if not s.closed and dir>0 then
fs2020_event("ROTOR_BRAKE", 1801) -- incr switch with cover open button
return
end
fs2020_event("ROTOR_BRAKE", 1901)
-- if dir>1 then
-- fs2020_event("ROTOR_BRAKE", 1901)
-- else
-- fs2020_event("ROTOR_BRAKE", 1902)
-- end
end
gSwitchBusTrans = AddHorGuardSwitch(135, 169, true, true, false, cbSwitchBusTrans, cbGuardBusTrans)
fs2020_variable_subscribe("L:switch_19_73X", "number", function(v)
CloseGuard(gSwitchBusTrans, v==0)
end)
-- ======================= Dimm all, except lights ================
local gBlackMask2 = canvas_add(0, 0, 400, 400, function()
_rect(0, 0, 400, 400)
_fill("black")
end)
opacity(gBlackMask2, 0)
-- ============================ lib functions for lights =======================
local gLight = {}
local gLightCount = 0
function AddLight(lvar, img, x, y, text1, text2)
gLightCount = gLightCount + 1
gLight[gLightCount] = {}
local w, h, color, font
if string.find(img, "amber", 1, true) ~= nil then
color = gColorAmber
elseif string.find(img, "blue", 1, true) ~= nil then
color = gColorBlue
elseif string.find(img, "green", 1, true) ~= nil then
color = gColorGreen
else
color = ";color:#FFFFFF"
end
font = gFontLight
meta = resource_info(img)
w = meta.WIDTH
h = meta.HEIGHT
img_add(img, x, y, w, h)
if text2 == nil then -- one line only
txt_add(text1, font..color..";halign:center", x+w/15, y+h/3, w*7/8, h)
else
txt_add(text1, font..color..";halign:center", x+w/15, y+h/5, w*7/8, h)
txt_add(text2, font..color..";halign:center", x+w/15, y+h/2, w*7/8, h)
end
gLight[gLightCount].img_shade = canvas_add(x+3, y+3, 79, 44, function ()
_rect(0, 0, 79, 44)
_fill("#000000D0")
end)
if lvar ~= nil then
local n = gLightCount
fs2020_variable_subscribe(lvar, "number", function(v)
if v==0 then
visible(gLight[n].img_shade, true)
else
visible(gLight[n].img_shade, false)
end
end)
end
return gLightCount
end
-- ======================== add lights ======================
AddLight("L:switch_20_73X", "light-amber-1.png", 35, 151, "TRANSFER", "BUS OFF")
AddLight("L:switch_22_73X", "light-amber-2.png", 35, 203, "SOURCE", "OFF")
AddLight("L:switch_24_73X", "light-blue-1.png", 35, 255, "GEN OFF", "BUS")
AddLight("L:switch_21_73X", "light-amber-2.png", 279, 151, "TRANSFER", "BUS OFF")
AddLight("L:switch_23_73X", "light-amber-1.png", 279, 203, "SOURCE", "OFF")
AddLight("L:switch_26_73X", "light-blue-1.png", 279, 255, "GEN OFF", "BUS")
AddLight("L:switch_16_73X", "light-blue-1.png", 160, 9, "GRD POWER", "AVAILABLE")
AddLight("L:switch_25_73X", "light-blue-1.png", 160, 254, "APU GEN", "OFF BUS")
-- ================== illumination ========================
function cbLightChange()
-- based on two inputs:
-- gDaylight 0..1: for dark to bright sunshine
-- gScalesLight 0..1: for no artificial light to full scales light and full illumination
if gDaylight==nil or gScalesLight==nil then return end
-- print("daylight: " .. gDaylight .. " scales: ".. gScalesLight)
local dimm_black, dimm_night_color, brightness, brightness_bg, brightness_lines
if gScalesLight < .05 then
dimm_night_color = 0
else
dimm_night_color = 2*gDaylight / gScalesLight
dimm_night_color = var_cap((1-var_cap(dimm_night_color, 0, 1)), 0, .5)
end
-- print("dimm night color is "..dimm_night_color)
opacity(gNightColor, dimm_night_color)
brightness = var_cap(gScalesLight+gDaylight, 0, 1)
opacity(gBlackMask, 1-brightness)
if brightness < .1 then -- this is to dimm down switches, which are above the first black mask
dimm_all = 1-brightness
brightness = 1
else
dimm_all = 0
end
opacity(gBlackMask2, dimm_all)
brightness_lines = var_cap(brightness*5, .4, .9)
print("brightness / brightness lines "..brightness.." / "..brightness_lines)
if dimm_night_color > .2 then
gColorPrint = string.format("#%02X%02X%02XFF",
math.floor(gNightR*brightness_lines),
math.floor(gNightG*brightness_lines),
math.floor(gNightB*brightness_lines))
else
gColorPrint = string.format("#%02X%02X%02XFF",
math.floor(255*brightness_lines),
math.floor(255*brightness_lines),
math.floor(255*brightness_lines))
end
brightness_bg = math.floor(brightness * 32)
gColorBg = string.format("#%02X%02X%02XFF", brightness_bg, brightness_bg, brightness_bg)
canvas_draw(gImgLines, DrawAllLines)
canvas_draw(gImgTexts, DrawAllTexts)
end
if gPropIllumination == "Day" then
gDaylight = .99
gScalesLight = 0
cbLightChange()
elseif gPropIllumination == "Night" then
gDaylight = 0.0
gScalesLight = .18
cbLightChange()
else
fs2020_variable_subscribe("A:LIGHT POTENTIOMETER:2", "Number", function(v) gDaylight = v; cbLightChange() end)
fs2020_variable_subscribe("A:LIGHT POTENTIOMETER:3", "Number", function(v) gScalesLight = v; cbLightChange() end)
end
---------------------
PKtC C PK ܐU ( <