summaryrefslogtreecommitdiff
path: root/scripts/controls.lua
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/controls.lua')
-rw-r--r--scripts/controls.lua646
1 files changed, 323 insertions, 323 deletions
diff --git a/scripts/controls.lua b/scripts/controls.lua
index c687c11..de6b889 100644
--- a/scripts/controls.lua
+++ b/scripts/controls.lua
@@ -1,323 +1,323 @@
--- SLIMax Mgr Lua Script v3.1.4
--- Copyright (c)2012-2013 by Zappadoc - All Rights Reserved.
--- last change by Zappadoc - 2013-10
-
--- 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(deviceType, ctrlType, ctrlPos, value, funcIndex, targetDevice)
- -- call custom script
- 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(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
-
- local loopFlag = false
- local dev = ""
- 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
- local ftecStr = ""
- local leftStr = ""
- local rightStr = ""
-
- local oldTcks = GetTicks()
-
- local delay = 600
- if funcIndex ~= -1 then
- if IsSLIFunction("maxgear", funcIndex) and mMaxGearFeedbackAllowed then
- -- max gear switch
- -- value from 4 to 7
- local mxgear = 0
- mxgear = GetCarInfo("maxgear")
-
- leftStr = "GEAR "
- rightStr = rightStr.format( "MAX%1d ", mxgear)
-
- -- set digits
- UpdateDigits(leftStr, rightStr)
- SLISendReport(0)
-
- state = 1
- -- set timeout
- oldTcks = GetTicks() + delay
-
- elseif IsSLIFunction("brightness", funcIndex) and mBrightnessFeedbackAllowed then
- -- brightness feedback (switch or buttons)
- BrightnessFeedBack(targetdev)
-
- leftStr = "888888"
- rightStr = "888888"
-
- SLISendReport(0)
-
- state = 1
- -- set timeout
- oldTcks = GetTicks() + delay
-
- elseif IsSLIFunction("ospfactor", funcIndex) and mOSPFeedbackAllowed then
- -- OSP Factor feedback
- leftStr = "OSP "
-
- local ospf = GetContextInfo("ospfactor")
- rightStr = rightStr.format(" %03d ", ospf)
-
- -- set digits
- UpdateDigits(leftStr, rightStr)
- SLISendReport(0)
-
- state = 1
- -- set timeout
- oldTcks = GetTicks() + delay
-
- elseif IsSLIFunction("speedmetric", funcIndex) and mUnitFeedbackAllowed then
- -- metric KPH or MPH
- local spdm = false
- spdm = GetContextInfo("speedmetric")
-
- leftStr = "SPD "
- rightStr = " KPH "
- if spdm then rightStr = " MPH " end
-
- -- set digits
- UpdateDigits(leftStr, rightStr)
- SLISendReport(0)
-
- state = 1
- -- set timeout
- oldTcks = GetTicks() + delay
-
- elseif dev == "FANATEC" and IsSLIFunction("ospmethod", funcIndex) and mFanatecOSPFeedbackAllowed then
- -- fanatec speedlimitermethod feedback
- local info = GetContextInfo("ospmethod")
- ftecStr = ftecStr.format("P%2d", info+1)
-
- -- set digits
- SetFanatecDigits(ftecStr)
- FanatecSendReport(0)
-
- state = 1
- -- set timeout
- oldTcks = GetTicks() + delay
- elseif dev == "FANATEC" and IsSLIFunction("shiftlightsmethod", funcIndex) and mFanatecShiftlightsFeedbackAllowed then
- -- fanatec speedlimitermethod feedback
- local info = GetContextInfo("shiftlightsmethod")
- ftecStr = ftecStr.format("P%2d", info+1)
-
- -- set digits
- SetFanatecDigits(ftecStr)
- FanatecSendReport(0)
-
- state = 1
- -- set timeout
- oldTcks = GetTicks() + delay
- elseif dev == "FANATEC" and IsSLIFunction("speedlimitermethod", funcIndex) and mFanatecSpeedLimiterFeedbackAllowed then
- -- fanatec speedlimitermethod feedback
- local info = GetContextInfo("speedlimitermethod")
- ftecStr = ftecStr.format("P%2d", info+1)
-
- -- set digits
- SetFanatecDigits(ftecStr)
- FanatecSendReport(0)
-
- state = 1
- -- set timeout
- oldTcks = GetTicks() + delay
-
- elseif IsSLIFunction("fanatecdigits", funcIndex) and mFanatecDigitsFeedbackAllowed then
- -- fanatecdigits feedback
- local info = GetContextInfo("fanatecdigits")
- ftecStr = ftecStr.format("P%2d", info+1)
-
- -- set digits
- SetFanatecDigits(ftecStr)
- FanatecSendReport(0)
-
- state = 1
- -- set timeout
- oldTcks = GetTicks() + delay
-
- elseif IsSLIFunction("rightdigits", funcIndex) and mRightDigitsFeedbackAllowed then
- -- rightdigits feedback
- 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
- UpdateDigits(leftStr, rightStr)
- SLISendReport(0)
-
- state = 1
- -- set timeout
- oldTcks = GetTicks() + delay
-
- elseif IsSLIFunction("leftdigits", funcIndex) and mLeftDigitsFeedbackAllowed then
- -- leftdigits feedback
- 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
- UpdateDigits(leftStr, rightStr)
- SLISendReport(0)
-
- state = 1
- -- set timeout
- oldTcks = GetTicks() + delay
-
- elseif IsSLIFunction("lowfuel", funcIndex) and mLowFuelFeedbackAllowed then
- -- lowfuel feedback
- -- get the option
- local info = GetContextInfo("lowfuel")
-
- -- set digits
- leftStr = leftStr.format("FUEL ", ctrlPos)
- rightStr = rightStr.format("L %02d ", info)
-
- UpdateDigits(leftStr, rightStr)
- SLISendReport(0)
-
- state = 1
- -- set timeout
- oldTcks = GetTicks() + delay
- end
- else
-
- if ctrlType == 0 then
- -- switch
-
- if mDemoMapToKeyAllowed and ctrlPos == mDemoMapToKeySwitch then
- -- demo script
- -- mapping a keystroke (see global.lua to set the targeted switch)
- local key = ""
- if value == 2 then key = "v" end
- -- if value == 3 then key = "K" end
- -- if value == 4 then key = "v" end
- -- if value == 5 then key = "F5" end
- if key ~= "" then
- -- params: key, delay, modifier
- SetKeystroke(key, 100, "")
- end
- end
-
- if mSwitchFeedbackAllowed then
- -- general switch feedback (see global.lua to activate)
- leftStr = leftStr.format("S%1d ", ctrlPos)
- rightStr = rightStr.format("P%02d ", value)
-
- -- set digits
- UpdateDigits(leftStr, rightStr)
- SLISendReport(0)
-
- state = 1
- -- set timeout
- oldTcks = GetTicks() + delay
- end
- elseif ctrlType == 1 then
- if ctrlPos == mDumpLapButton and dev == "SLI-PRO" and value>0 and mDumpLapAllowed then
- -- sample script using button of SLI-PRO to
- -- toggle telemetry dumplastlap flag (true or false)
- -- telemetry logs are stored in telemetry directory
- -- after each completed lap
- local dlap = GetContextInfo("dumplastlap")
- local flag = not dlap;
- TelemetryTools("dumplastlap", flag);
- -- set digits
- leftStr = "tELENN"
- if flag then
- rightStr = "SAVE "
- else
- rightStr = "FALSE "
- end
- UpdateDigits(leftStr, rightStr)
- SLISendReport(0)
-
- state = 1
- -- set timeout
- oldTcks = GetTicks() + delay
- end
- end
- end
-
- if state >= 1 then
- -- loop until timeout
- local newtcks = GetTicks()
- loopFlag = true
- while(oldTcks > newtcks and loopFlag ) do
- SLISleep(10)
- newtcks = GetTicks()
- SetLeftDigits(leftStr)
- SetRightDigits(rightStr)
- SLISendReport(0)
- end
-
- -- cleanup device
- oldTcks = 0
- state = 0
- toggleAllLed(0)
- UpdateDigits(" ", " ")
- SLISendReport(0)
-
- -- allow Mgr to display info on digits
- SetDigitsAllowed(true)
- end
-
- -- skip
- return 0
-end
-
--- set leds, digits, parts to cleanup and timeout
-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
-function BrightnessFeedBack(device)
- -- set all leds
- toggleAllLed(1)
-
- if device == "SLI-PRO" then
- -- SLI-PRO Device
- -- set digits
- UpdateDigits("888888", "888888")
- end
-end
+-- SLIMax Mgr Lua Script v3.1.4
+-- Copyright (c)2012-2013 by Zappadoc - All Rights Reserved.
+-- last change by Zappadoc - 2013-10
+
+-- 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(deviceType, ctrlType, ctrlPos, value, funcIndex, targetDevice)
+ -- call custom script
+ 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(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
+
+ local loopFlag = false
+ local dev = ""
+ 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
+ local ftecStr = ""
+ local leftStr = ""
+ local rightStr = ""
+
+ local oldTcks = GetTicks()
+
+ local delay = 600
+ if funcIndex ~= -1 then
+ if IsSLIFunction("maxgear", funcIndex) and mMaxGearFeedbackAllowed then
+ -- max gear switch
+ -- value from 4 to 7
+ local mxgear = 0
+ mxgear = GetCarInfo("maxgear")
+
+ leftStr = "GEAR "
+ rightStr = rightStr.format( "MAX%1d ", mxgear)
+
+ -- set digits
+ UpdateDigits(leftStr, rightStr)
+ SLISendReport(0)
+
+ state = 1
+ -- set timeout
+ oldTcks = GetTicks() + delay
+
+ elseif IsSLIFunction("brightness", funcIndex) and mBrightnessFeedbackAllowed then
+ -- brightness feedback (switch or buttons)
+ BrightnessFeedBack(targetdev)
+
+ leftStr = "888888"
+ rightStr = "888888"
+
+ SLISendReport(0)
+
+ state = 1
+ -- set timeout
+ oldTcks = GetTicks() + delay
+
+ elseif IsSLIFunction("ospfactor", funcIndex) and mOSPFeedbackAllowed then
+ -- OSP Factor feedback
+ leftStr = "OSP "
+
+ local ospf = GetContextInfo("ospfactor")
+ rightStr = rightStr.format(" %03d ", ospf)
+
+ -- set digits
+ UpdateDigits(leftStr, rightStr)
+ SLISendReport(0)
+
+ state = 1
+ -- set timeout
+ oldTcks = GetTicks() + delay
+
+ elseif IsSLIFunction("speedmetric", funcIndex) and mUnitFeedbackAllowed then
+ -- metric KPH or MPH
+ local spdm = false
+ spdm = GetContextInfo("speedmetric")
+
+ leftStr = "SPD "
+ rightStr = " KPH "
+ if spdm then rightStr = " MPH " end
+
+ -- set digits
+ UpdateDigits(leftStr, rightStr)
+ SLISendReport(0)
+
+ state = 1
+ -- set timeout
+ oldTcks = GetTicks() + delay
+
+ elseif dev == "FANATEC" and IsSLIFunction("ospmethod", funcIndex) and mFanatecOSPFeedbackAllowed then
+ -- fanatec speedlimitermethod feedback
+ local info = GetContextInfo("ospmethod")
+ ftecStr = ftecStr.format("P%2d", info+1)
+
+ -- set digits
+ SetFanatecDigits(ftecStr)
+ FanatecSendReport(0)
+
+ state = 1
+ -- set timeout
+ oldTcks = GetTicks() + delay
+ elseif dev == "FANATEC" and IsSLIFunction("shiftlightsmethod", funcIndex) and mFanatecShiftlightsFeedbackAllowed then
+ -- fanatec speedlimitermethod feedback
+ local info = GetContextInfo("shiftlightsmethod")
+ ftecStr = ftecStr.format("P%2d", info+1)
+
+ -- set digits
+ SetFanatecDigits(ftecStr)
+ FanatecSendReport(0)
+
+ state = 1
+ -- set timeout
+ oldTcks = GetTicks() + delay
+ elseif dev == "FANATEC" and IsSLIFunction("speedlimitermethod", funcIndex) and mFanatecSpeedLimiterFeedbackAllowed then
+ -- fanatec speedlimitermethod feedback
+ local info = GetContextInfo("speedlimitermethod")
+ ftecStr = ftecStr.format("P%2d", info+1)
+
+ -- set digits
+ SetFanatecDigits(ftecStr)
+ FanatecSendReport(0)
+
+ state = 1
+ -- set timeout
+ oldTcks = GetTicks() + delay
+
+ elseif IsSLIFunction("fanatecdigits", funcIndex) and mFanatecDigitsFeedbackAllowed then
+ -- fanatecdigits feedback
+ local info = GetContextInfo("fanatecdigits")
+ ftecStr = ftecStr.format("P%2d", info+1)
+
+ -- set digits
+ SetFanatecDigits(ftecStr)
+ FanatecSendReport(0)
+
+ state = 1
+ -- set timeout
+ oldTcks = GetTicks() + delay
+
+ elseif IsSLIFunction("rightdigits", funcIndex) and mRightDigitsFeedbackAllowed then
+ -- rightdigits feedback
+ 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
+ UpdateDigits(leftStr, rightStr)
+ SLISendReport(0)
+
+ state = 1
+ -- set timeout
+ oldTcks = GetTicks() + delay
+
+ elseif IsSLIFunction("leftdigits", funcIndex) and mLeftDigitsFeedbackAllowed then
+ -- leftdigits feedback
+ 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
+ UpdateDigits(leftStr, rightStr)
+ SLISendReport(0)
+
+ state = 1
+ -- set timeout
+ oldTcks = GetTicks() + delay
+
+ elseif IsSLIFunction("lowfuel", funcIndex) and mLowFuelFeedbackAllowed then
+ -- lowfuel feedback
+ -- get the option
+ local info = GetContextInfo("lowfuel")
+
+ -- set digits
+ leftStr = leftStr.format("FUEL ", ctrlPos)
+ rightStr = rightStr.format("L %02d ", info)
+
+ UpdateDigits(leftStr, rightStr)
+ SLISendReport(0)
+
+ state = 1
+ -- set timeout
+ oldTcks = GetTicks() + delay
+ end
+ else
+
+ if ctrlType == 0 then
+ -- switch
+
+ if mDemoMapToKeyAllowed and ctrlPos == mDemoMapToKeySwitch then
+ -- demo script
+ -- mapping a keystroke (see global.lua to set the targeted switch)
+ local key = ""
+ if value == 2 then key = "v" end
+ -- if value == 3 then key = "K" end
+ -- if value == 4 then key = "v" end
+ -- if value == 5 then key = "F5" end
+ if key ~= "" then
+ -- params: key, delay, modifier
+ SetKeystroke(key, 100, "")
+ end
+ end
+
+ if mSwitchFeedbackAllowed then
+ -- general switch feedback (see global.lua to activate)
+ leftStr = leftStr.format("S%1d ", ctrlPos)
+ rightStr = rightStr.format("P%02d ", value)
+
+ -- set digits
+ UpdateDigits(leftStr, rightStr)
+ SLISendReport(0)
+
+ state = 1
+ -- set timeout
+ oldTcks = GetTicks() + delay
+ end
+ elseif ctrlType == 1 then
+ if ctrlPos == mDumpLapButton and dev == "SLI-PRO" and value>0 and mDumpLapAllowed then
+ -- sample script using button of SLI-PRO to
+ -- toggle telemetry dumplastlap flag (true or false)
+ -- telemetry logs are stored in telemetry directory
+ -- after each completed lap
+ local dlap = GetContextInfo("dumplastlap")
+ local flag = not dlap;
+ TelemetryTools("dumplastlap", flag);
+ -- set digits
+ leftStr = "tELENN"
+ if flag then
+ rightStr = "SAVE "
+ else
+ rightStr = "FALSE "
+ end
+ UpdateDigits(leftStr, rightStr)
+ SLISendReport(0)
+
+ state = 1
+ -- set timeout
+ oldTcks = GetTicks() + delay
+ end
+ end
+ end
+
+ if state >= 1 then
+ -- loop until timeout
+ local newtcks = GetTicks()
+ loopFlag = true
+ while(oldTcks > newtcks and loopFlag ) do
+ SLISleep(10)
+ newtcks = GetTicks()
+ SetLeftDigits(leftStr)
+ SetRightDigits(rightStr)
+ SLISendReport(0)
+ end
+
+ -- cleanup device
+ oldTcks = 0
+ state = 0
+ toggleAllLed(0)
+ UpdateDigits(" ", " ")
+ SLISendReport(0)
+
+ -- allow Mgr to display info on digits
+ SetDigitsAllowed(true)
+ end
+
+ -- skip
+ return 0
+end
+
+-- set leds, digits, parts to cleanup and timeout
+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
+function BrightnessFeedBack(device)
+ -- set all leds
+ toggleAllLed(1)
+
+ if device == "SLI-PRO" then
+ -- SLI-PRO Device
+ -- set digits
+ UpdateDigits("888888", "888888")
+ end
+end