From 71a65c91c96643777662459e17ae0c4113f53d1e Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Sat, 10 Jun 2017 16:31:35 +0200 Subject: [PATCH] Implemented lights.lua Fixed syntax error in instruments.lua Added scripts to setup Update documentation to reflect automatic creation of scripts folders --- Docs/scripting.rst | 2 +- G940LEDControl/Scripts/FSX/instruments.lua | 2 +- G940LEDControl/Scripts/FSX/lights.lua | 72 +++++++++++++++++++--- Setup/G940LEDControl.iss | 1 + 4 files changed, 67 insertions(+), 10 deletions(-) diff --git a/Docs/scripting.rst b/Docs/scripting.rst index c6041e6..10b92b9 100644 --- a/Docs/scripting.rst +++ b/Docs/scripting.rst @@ -10,7 +10,7 @@ Script locations ---------------- The default scripts included with G940LEDControl can be found in the folder selected during installation, for example "C:\\Program Files (x86)\\G940 LED Control". In there you will find a Scripts\\FSX folder containing the Lua files. -In addition scripts are loaded from your user data path. This folder is automatically created by G940LEDControl after you have changed any button configuration or settings. To open the folder, type or paste "%APPDATA%\\G940LEDControl" into a Windows Explorer address bar and press Enter. Inside you can create the same Scripts\\FSX folder structure. Scripts in this folder will not be overwritten when installing a new version. +In addition scripts are loaded from your user data path. This folder is automatically created by G940LEDControl. To open the folder, type or paste "%APPDATA%\\G940LEDControl\\Scripts\\FSX" into a Windows Explorer address bar and press Enter. Scripts in this folder will not be overwritten when installing a new version. Anatomy of a button function diff --git a/G940LEDControl/Scripts/FSX/instruments.lua b/G940LEDControl/Scripts/FSX/instruments.lua index 835c868..a507bd0 100644 --- a/G940LEDControl/Scripts/FSX/instruments.lua +++ b/G940LEDControl/Scripts/FSX/instruments.lua @@ -52,7 +52,7 @@ RegisterFunction( SetState(context, prefix..'50To75') elseif ice >= 75 and ice <= 99 then SetState(context, prefix..'75To100') - elseif ice = 100 then + elseif ice == 100 then SetState(context, prefix..'100') else SetState(context, prefix..'0') diff --git a/G940LEDControl/Scripts/FSX/lights.lua b/G940LEDControl/Scripts/FSX/lights.lua index 52b8252..b66d782 100644 --- a/G940LEDControl/Scripts/FSX/lights.lua +++ b/G940LEDControl/Scripts/FSX/lights.lua @@ -1,8 +1,64 @@ --- Beacon lights --- Instrument lights --- Landing lights --- Nav lights --- Recognition lights --- Strobe lights --- Taxi lights --- All lights \ No newline at end of file +local strings = require './lib/strings' + +-- Lights +local function RegisterLightsFunction(functionUid, functionDisplayName, lightsMask) + RegisterFunction( + { + uid = functionUid, + category = strings.Category.FSX.Lights, + displayName = functionDisplayName, + states = { + on = { displayName = 'On', default = LEDColor.Green, order = 1 }, + off = { displayName = 'Off', default = LEDColor.Red, order = 2 } + } + }, + function(context) + SetState(context, 'on') + + OnSimConnect(context, + { + states = { variable = 'LIGHT ON STATES', type = SimConnectDataType.Int32, units = 'mask' } + }, + function(context, data) + if bit32.band(data.states, lightsMask) ~= 0 then + SetState(context, 'on') + else + SetState(context, 'off') + end + end) + end +) +end + + +local LightsMaskNav = 0x0001 +local LightsMaskBeacon = 0x0002 +local LightsMaskLanding = 0x0004 +local LightsMaskTaxi = 0x0008 +local LightsMaskStrobe = 0x0010 +local LightsMaskPanel = 0x0020 +local LightsMaskRecognition = 0x0040 +local LightsMaskWing = 0x0080 +local LightsMaskLogo = 0x0100 +local LightsMaskCabin = 0x0200 + +local LightsMaskAll = bit32.bor( + LightsMaskNav, + LightsMaskBeacon, + LightsMaskLanding, + LightsMaskTaxi, + LightsMaskStrobe, + LightsMaskPanel, + LightsMaskRecognition, + LightsMaskWing, + LightsMaskLogo, + LightsMaskCabin +) + + +RegisterLightsFunction('beaconLights', 'Beacon lights', LightsMaskBeacon) +RegisterLightsFunction('navLights', 'Nav lights', LightsMaskNav) +RegisterLightsFunction('strobeLights', 'Strobe lights', LightsMaskStrobe) +RegisterLightsFunction('taxiLights', 'Taxi lights', LightsMaskTaxi) +RegisterLightsFunction('recognitionLights', 'Recognition lights', LightsMaskRecognition) +RegisterLightsFunction('allLights', 'All lights', LightsMaskAll) diff --git a/Setup/G940LEDControl.iss b/Setup/G940LEDControl.iss index 6f88e24..fa73735 100644 --- a/Setup/G940LEDControl.iss +++ b/Setup/G940LEDControl.iss @@ -32,6 +32,7 @@ Source: "..\G940LEDControl\Bin\{#AppExeName}"; DestDir: "{app}"; Flags: ignoreve Source: "..\G940LEDControl\Bin\LogiJoystickDLL.dll"; DestDir: "{app}"; Flags: ignoreversion Source: "..\G940LEDControl\Bin\FSX-SimConnect.dll"; DestDir: "{app}"; Flags: ignoreversion Source: "..\G940LEDControl\Bin\FSX-SE-SimConnect.dll"; DestDir: "{app}"; Flags: ignoreversion +Source: "..\G940LEDControl\Scripts\*.lua"; DestDir: "{app}\Scripts"; Flags: ignoreversion recursesubdirs [Dirs] Name: "{userappdata}\G940LEDControl\Scripts\FSX"