From 17ef33a3fc62a31565193320f1f5583077403b19 Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Fri, 15 Nov 2013 10:09:12 +0100 Subject: SliMax Manager 3.++ --- scripts/controls.lua | 95 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 57 insertions(+), 38 deletions(-) mode change 100755 => 100644 scripts/controls.lua (limited to 'scripts/controls.lua') diff --git a/scripts/controls.lua b/scripts/controls.lua old mode 100755 new mode 100644 index e0ce14d..c687c11 --- a/scripts/controls.lua +++ b/scripts/controls.lua @@ -1,22 +1,26 @@ --- SLIMax Mgr Lua Script v3 +-- SLIMax Mgr Lua Script v3.1.4 -- Copyright (c)2012-2013 by Zappadoc - All Rights Reserved. +-- last change by Zappadoc - 2013-10 --- param deviceIdx = (see GetDeviceType() ) +-- param deviceType = (see GetDeviceType() to get device name ) -- param ctrlType = type of ctrl, switch (0) or button (1) -- param ctrlPos = ctrl index, switch from 1 to 6 and button from 1 to n -- param value = ctrl value, button down (>0) or up (==0) and switch from 1 to 12 +-- param funcIndex = mapped to internal function or -1 +-- param targetDevice = the device targeted, should be equal to deviceType above or different +-- if mapped to other device (see GetDeviceType() to get device name ) -- return 0 to give the control to SLIMax Mgr -- return 1 to force the update of device -function controlsEvent(deviceIdx, ctrlType, ctrlPos, value, funcIndex) +function controlsEvent(deviceType, ctrlType, ctrlPos, value, funcIndex, targetDevice) -- call custom script - local result = custom_controlsEvent(deviceIdx, ctrlType, ctrlPos, value, funcIndex) + local result = custom_controlsEvent(deviceType, ctrlType, ctrlPos, value, funcIndex, targetDevice) -- if result = 0 bypass the script below and return 0 -- if result = 1 bypass the script below and return 1 if result <= 1 then return result end -- if result >= 2 continue -- call global custom script - result = global_custom_controlsEvent(deviceIdx, ctrlType, ctrlPos, value, funcIndex) + result = global_custom_controlsEvent(deviceType, ctrlType, ctrlPos, value, funcIndex, targetDevice) -- if result = 0 bypass the script below and return 0 -- if result = 1 bypass the script below and return 1 if result <= 1 then return result end @@ -24,8 +28,13 @@ function controlsEvent(deviceIdx, ctrlType, ctrlPos, value, funcIndex) local loopFlag = false local dev = "" - dev = GetDeviceType(deviceIdx) + dev = GetDeviceType(deviceType) if dev == nil then dev = "none" end + + local targetdev = "" + targetdev = GetDeviceType(targetDevice) + if targetdev == nil then targetdev = "none" end + -- switches and buttons -- ctrl change event local state = 0 @@ -43,11 +52,11 @@ function controlsEvent(deviceIdx, ctrlType, ctrlPos, value, funcIndex) local mxgear = 0 mxgear = GetCarInfo("maxgear") - leftStr = " GEAR " - rightStr = rightStr.format( "MAX %1d", mxgear) + leftStr = "GEAR " + rightStr = rightStr.format( "MAX%1d ", mxgear) -- set digits - UpdateSLIProDigits(leftStr, rightStr) + UpdateDigits(leftStr, rightStr) SLISendReport(0) state = 1 @@ -56,7 +65,7 @@ function controlsEvent(deviceIdx, ctrlType, ctrlPos, value, funcIndex) elseif IsSLIFunction("brightness", funcIndex) and mBrightnessFeedbackAllowed then -- brightness feedback (switch or buttons) - BrightnessFeedBack(dev) + BrightnessFeedBack(targetdev) leftStr = "888888" rightStr = "888888" @@ -69,13 +78,13 @@ function controlsEvent(deviceIdx, ctrlType, ctrlPos, value, funcIndex) elseif IsSLIFunction("ospfactor", funcIndex) and mOSPFeedbackAllowed then -- OSP Factor feedback - leftStr = "OSP: " + leftStr = "OSP " local ospf = GetContextInfo("ospfactor") rightStr = rightStr.format(" %03d ", ospf) -- set digits - UpdateSLIProDigits(leftStr, rightStr) + UpdateDigits(leftStr, rightStr) SLISendReport(0) state = 1 @@ -87,12 +96,12 @@ function controlsEvent(deviceIdx, ctrlType, ctrlPos, value, funcIndex) local spdm = false spdm = GetContextInfo("speedmetric") - leftStr = "SPD: " + leftStr = "SPD " rightStr = " KPH " if spdm then rightStr = " MPH " end -- set digits - UpdateSLIProDigits(leftStr, rightStr) + UpdateDigits(leftStr, rightStr) SLISendReport(0) state = 1 @@ -151,13 +160,17 @@ function controlsEvent(deviceIdx, ctrlType, ctrlPos, value, funcIndex) elseif IsSLIFunction("rightdigits", funcIndex) and mRightDigitsFeedbackAllowed then -- rightdigits feedback - local info = false - info = GetContextInfo("rightdigits") - leftStr = leftStr.format("Btn: %02d", ctrlPos) - rightStr = rightStr.format(" %02d ", info) + local info = GetContextInfo("rightdigits") + + if ctrlType == 1 then + leftStr = leftStr.format("B%02d ", ctrlPos) + else + leftStr = leftStr.format("S%1d ", ctrlPos) + end + rightStr = rightStr.format("P%02d ", info+1) -- set digits - UpdateSLIProDigits(leftStr, rightStr) + UpdateDigits(leftStr, rightStr) SLISendReport(0) state = 1 @@ -166,13 +179,17 @@ function controlsEvent(deviceIdx, ctrlType, ctrlPos, value, funcIndex) elseif IsSLIFunction("leftdigits", funcIndex) and mLeftDigitsFeedbackAllowed then -- leftdigits feedback - local info = false - info = GetContextInfo("leftdigits") - leftStr = leftStr.format("Btn: %02d", ctrlPos) - rightStr = rightStr.format(" %02d ", info) + local info = GetContextInfo("leftdigits") + rightStr = leftStr.format("P%02d ", info+1) + + if ctrlType == 1 then + leftStr = rightStr.format("B%02d ", ctrlPos) + else + leftStr = rightStr.format("S%1d ", ctrlPos) + end -- set digits - UpdateSLIProDigits(leftStr, rightStr) + UpdateDigits(leftStr, rightStr) SLISendReport(0) state = 1 @@ -182,14 +199,13 @@ function controlsEvent(deviceIdx, ctrlType, ctrlPos, value, funcIndex) elseif IsSLIFunction("lowfuel", funcIndex) and mLowFuelFeedbackAllowed then -- lowfuel feedback -- get the option - local info = false - info = GetContextInfo("lowfuel") + local info = GetContextInfo("lowfuel") -- set digits - leftStr = leftStr.format(" FUEL ", ctrlPos) - rightStr = rightStr.format("LPS %02d", info) + leftStr = leftStr.format("FUEL ", ctrlPos) + rightStr = rightStr.format("L %02d ", info) - UpdateSLIProDigits(leftStr, rightStr) + UpdateDigits(leftStr, rightStr) SLISendReport(0) state = 1 @@ -217,11 +233,11 @@ function controlsEvent(deviceIdx, ctrlType, ctrlPos, value, funcIndex) if mSwitchFeedbackAllowed then -- general switch feedback (see global.lua to activate) - leftStr = leftStr.format("S%1d : ", ctrlPos) - rightStr = rightStr.format(" %02d ", value) + leftStr = leftStr.format("S%1d ", ctrlPos) + rightStr = rightStr.format("P%02d ", value) -- set digits - UpdateSLIProDigits(leftStr, rightStr) + UpdateDigits(leftStr, rightStr) SLISendReport(0) state = 1 @@ -240,11 +256,11 @@ function controlsEvent(deviceIdx, ctrlType, ctrlPos, value, funcIndex) -- set digits leftStr = "tELENN" if flag then - rightStr = " SAVE " + rightStr = "SAVE " else - rightStr = " FALSE" + rightStr = "FALSE " end - UpdateSLIProDigits(leftStr, rightStr) + UpdateDigits(leftStr, rightStr) SLISendReport(0) state = 1 @@ -270,7 +286,7 @@ function controlsEvent(deviceIdx, ctrlType, ctrlPos, value, funcIndex) oldTcks = 0 state = 0 toggleAllLed(0) - UpdateSLIProDigits(" ", " ") + UpdateDigits(" ", " ") SLISendReport(0) -- allow Mgr to display info on digits @@ -282,13 +298,16 @@ function controlsEvent(deviceIdx, ctrlType, ctrlPos, value, funcIndex) end -- set leds, digits, parts to cleanup and timeout -function UpdateSLIProDigits(leftInfo, rightInfo) +function UpdateDigits(leftInfo, rightInfo) -- do not refresh digits until timeout SetDigitsAllowed(false) + mF1LeftSpdLmtText = string.sub(leftInfo,4) + mF1RightSpdLmtText = string.sub(rightInfo,4) -- set digits string SetLeftDigits(leftInfo) SetRightDigits(rightInfo) + end -- brightness feedback function @@ -299,6 +318,6 @@ function BrightnessFeedBack(device) if device == "SLI-PRO" then -- SLI-PRO Device -- set digits - UpdateSLIProDigits("888888", "888888") + UpdateDigits("888888", "888888") end end -- cgit v1.2.3