From db7d99359d62b05a1f6e2c551106b7bf26764889 Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Mon, 18 Nov 2013 21:04:19 +0100 Subject: 3.3.0.3 -> 3.3.0.5 --- scripts/global.lua | 592 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 405 insertions(+), 187 deletions(-) (limited to 'scripts/global.lua') diff --git a/scripts/global.lua b/scripts/global.lua index 6008f9f..867e73e 100644 --- a/scripts/global.lua +++ b/scripts/global.lua @@ -1,15 +1,78 @@ --- SLIMax Mgr Lua Script v3.8.1 +-- SLIMax Mgr Lua Script v3.9 -- PART OF SLIMAX Manager pkg -- Copyright (c)2012-2013 by Zappadoc - All Rights Reserved. --- last change by Zappadoc - 2013-10 +-- last change by Zappadoc - 2013-11 -mSMX_VERSION = 3.8 +mSMX_VERSION = 3.9 -- see slimax_script_readme.txt for implementation -- load left and right functions tools require "scripts/functions_tools" +-- ============================================================ +-- GLOBAL FLAGS +-- set this flags to change the std behaviors of SLIMax Mgr +-- ============================================================ + +-- true to show the total delta splits sector 1 + sector 2 +-- false to show the delta of sector 2 only +mDelta_total_split_sectors = true + +-- delta time delay +mDeltaTimeBackup = 0 +mDeltaTimeOldTicks = 0 +mDeltaTimeAlternateOldTicks = 0 +-- change the delay below to increase or decrease the update of delta time +mDeltaTimeDelay = 200 +-- change the delay below to increase or decrease the update of lap time +mRefreshLapTimeRate = 50 + +-- get feedback on display when you turn encoder or press button assigned to internal functions, see control.lua +-- true if you want to display switch pos and value +mSwitchFeedbackAllowed = false + +-- Fanatec Digits Status +mFanatecDigitsFeedbackAllowed = true +-- Fanatec speedlimiter method seleted +mFanatecSpeedLimiterFeedbackAllowed = true +-- Fanatec osp method seleted +mFanatecOSPFeedbackAllowed = true +-- Fanatec shiftlights method seleted +mFanatecShiftlightsFeedbackAllowed = true + +-- Low Fuel status +mLowFuelFeedbackAllowed = true + +-- Left and Right Digits status +mLeftDigitsFeedbackAllowed = false +mRightDigitsFeedbackAllowed = false + +-- display KPH or KMH +mUnitFeedbackAllowed = true + +-- show the current OSP Factor +mOSPFeedbackAllowed = true + +-- cool global brightness feedback +mBrightnessFeedbackAllowed = true + +-- show the current value of maxgear option +mMaxGearFeedbackAllowed = true + +-- activate or deactivate lap dump telemetry +-- using button 9 by default +mDumpLapAllowed = false +mDumpLapButton = 9 + +-- dump telemetry +TelemetryTools("dumplastlap", false); + +-- mapping to keystroke demo script +-- see the support forum for more info on key mapping +mDemoMapToKeyAllowed = false +mDemoMapToKeySwitch = 5 + -- ============================================================ -- GLOBAL VAR -- ============================================================ @@ -70,56 +133,6 @@ mSRDlxRightText = "" mSRF1LeftText = "" mSRF1RightText = "" --- get feedback on display when you turn encoder or press button assigned to internal functions, see control.lua --- true if you want to display switch pos and value -mSwitchFeedbackAllowed = true - --- mapping to keystroke demo script --- see the support forum for more info on key mapping -mDemoMapToKeyAllowed = false -mDemoMapToKeySwitch = 5 - --- Fanatec Digits Status -mFanatecDigitsFeedbackAllowed = true --- Fanatec speedlimiter method seleted -mFanatecSpeedLimiterFeedbackAllowed = true --- Fanatec osp method seleted -mFanatecOSPFeedbackAllowed = true --- Fanatec shiftlights method seleted -mFanatecShiftlightsFeedbackAllowed = true - --- Low Fuel status -mLowFuelFeedbackAllowed = true - --- Left and Right Digits status -mLeftDigitsFeedbackAllowed = true -mRightDigitsFeedbackAllowed = true - --- display KPH or KMH -mUnitFeedbackAllowed = true - --- show the current OSP Factor -mOSPFeedbackAllowed = true - --- cool global brightness feedback -mBrightnessFeedbackAllowed = true - --- show the current value of maxgear option -mMaxGearFeedbackAllowed = true - --- activate or deactivate lap dump telemetry --- using button 9 by default -mDumpLapAllowed = false -mDumpLapButton = 9 - --- delta time delay -mDeltaTimeBackup = 0 -mDeltaTimeOldTicks = 0 -mDeltaTimeDelay = 100 -mRefreshLapTimeRate = 50 - --- dump telemetry -TelemetryTools("dumplastlap", false); -- ============================================================ -- init globals flag @@ -140,7 +153,7 @@ mRPMLedTable = { RPM10=0, RPM11=0, RPM12=0, - RPM13=0, + RPM13=0, RPM14=0 } @@ -149,6 +162,23 @@ mRPMLedTable = { -- mDeviceType no longer avaialable use GetDeviceType(devID) see 2.3 API +-- init globals +if mOld_ls1 == nil then + mOld_bs1 = 0.00000 + mOld_bs2 = 0.00000 + mOld_bt = 0.00000 + mDelta_lpt = 0.00000 + mDelta_lptb = 0.00000 + mOld_ls1 = 0.00000 + mOld_ls2 = 0.00000 + mOld_lt = 0.00000 + mDelta_lpt = 0.00000 + mDelta_lptb = 0.00000 + mDelta_Sect1 = 0.0000 + mDelta_Sect1b = 0.0000 +end + + -- -------------------------------------------- -- KERS functions -- -------------------------------------------- @@ -158,7 +188,7 @@ function GetKersPercent() local kers_level = GetCarInfo("kers") local k_percent = 0 if kers_level ~= nil and kers_level > 0 then - k_percent = round((kers_level/1000) / 4 ) + k_percent = round((kers_level/1000) / 4 ) end return k_percent end @@ -187,10 +217,10 @@ end -- set RPM threshold value in percentage ( SLIMax Manager 2.1 ) function SetRPMPercentValue(index, value) if index <1 or index>15 then - return + return end if value <0 or value >100 then - return + return end RPM_PERCENT_VALUES[index] = value @@ -199,10 +229,10 @@ end -- set RPM threshold value ( SLIMax Manager 2.1 ) function SetRPMAbsoluteValue(index, value) if index <1 or index>15 then - return + return end if value <0 or value >20000 then - return + return end RPM_ABSOLUTE_VALUES[index] = value @@ -253,7 +283,7 @@ function GetSLIMaxInfo() end -- get cpu ticks -function GetTicks() + function GetTicks() local tcks = GetContextInfo("ticks") if tcks == nil then tcks = 0 end return tcks @@ -262,9 +292,9 @@ end -- reset table function function initLedTable(ibl, value) if ibl ~= nil then - for k, v in pairs(ibl) do - ibl[k] = value - end + for k, v in pairs(ibl) do + ibl[k] = value + end end end @@ -290,36 +320,15 @@ function round(num) return i end --- The following function calculate hr, mn, sec, hd, ms --- param: time in meter/sec -function timeDispatcher( tt) - if tms == nil then tms = 0 end - local tms = math.abs(tt) - local t_hr = 0 - local t_mn = 0 - local t_sc = 0 - local t_ms = 0 - local t_hd = 0 - - if tms > 0 then - t_hr, n = math.modf(tms/3600) - t_mn, c = math.modf(n*60) - t_sc, s = math.modf(c*60) - t_hd, h = math.modf(s*100) - t_ms, m = math.modf(s*1000) - end --- print( tt, t_hr, t_mn, t_sc, t_hd, t_ms) - return t_hr, t_mn, t_sc, t_hd, t_ms -end -- return speed in KPH or MPH function speed(spd, selector) if spd == nil then spd = 0 end if selector then - -- MPH - return ( spd * 2.237) + -- MPH + return ( spd * 2.237) else - return (spd * 3.6) + return (spd * 3.6) end end @@ -352,10 +361,10 @@ end function GetFuel(fl, selector) if fl == nil then fl = 0 end if selector then - -- gallons - return LtoG( fl) + -- gallons + return LtoG( fl) else - return fl + return fl end end @@ -363,10 +372,10 @@ end function GetTemp(tmp, selector) if tmp == nil then tmp = 0 end if selector then - -- gallons - return CtoF( tmp) + -- gallons + return CtoF( tmp) else - return tmp + return tmp end end @@ -396,12 +405,12 @@ function GetCurrentGear() local result = g if g == 0 then - -- if neutral and using custom OSP record then add a dot to gear digit - if ospcustom_on then n = n + 128 end - result = string.char(n) + -- if neutral and using custom OSP record then add a dot to gear digit + if ospcustom_on then n = n + 128 end + result = string.char(n) elseif g < 0 then - -- reverse - result = r + -- reverse + result = r end return result @@ -409,111 +418,320 @@ end function isAppIRacing(sim) if sim == "iRacingSim.exe" or sim == "iRacingSim64.exe" then - return true + return true end return false end function isAppRFactor(sim) if sim == "rFactor.exe" or sim == "rFactor2.exe" then - return true + return true end return false end +-- force display text on left or/and right panel during delay in ms +function LeftRightMessageText(delay, left_text, right_text) + -- disallow Mgr to display info on digits + SetDigitsAllowed(false) + + -- set timeout + local oldTcks = GetTicks() + delay + + -- loop until timeout + while(oldTcks > GetTicks()) do + SLISleep(1) + if left_text ~= "" then + SetLeftDigits(left_text) + end + if right_text ~= "" then + SetRightDigits(right_text) + end + SLISendReport(0) + end + + -- cleanup device + UpdateDigits(" ", " ") + SLISendReport(0) + + -- allow Mgr to display info on digits + SetDigitsAllowed(true) +end + + +-- The following function calculate hr, mn, sec, hd, ms +-- param: time in meter/sec +function timeDispatcher( tt) + if tms == nil then tms = 0 end + local tms = math.abs(tt) + local t_hr = 0 + local t_mn = 0 + local t_sc = 0 + local t_ms = 0 + local t_hd = 0 + + if tms > 0 then + t_hr, n = math.modf(tms/3600) + t_mn, c = math.modf(n*60) + t_sc, s = math.modf(c*60) + t_hd, h = math.modf(s*100) + t_ms, m = math.modf(s*1000) + end +-- print( tt, t_hr, t_mn, t_sc, t_hd, t_ms) + return t_hr, t_mn, t_sc, t_hd, t_ms +end + function DisplayFormatTime(lptime, delay, dec, deltaflag, numDigits) local ticks = GetTicks() if dft_old_time == nil or (ticks - dft_old_time) > delay then - -- global to backup ticks (ms) - dft_old_time = ticks - - local hr = 0 - local mn = 0 - local sc = 0 - local ms = 0 - local hd = 0 - local panel = "" - local prefix = " " - - if lptime < 0 then - prefix = "-" - end - -- explod time - hr, mn, sc, hd, ms = timeDispatcher(lptime) - - if deltaflag == 1 then - --display delta time - if lptime == -1 or (mn + sc + ms) == 0.0 then - if numDigits == 3 then - Panel = "-.--" - else - Panel = " -.-- " - end - elseif mn > 0 then - if numDigits == 3 then - if mn < 100 then - Panel = string.format( "%s%02d.", prefix, mn) - else - Panel = " ." - end - - else - Panel = string.format( " %s%1d.%02d ", prefix, mn, sc) - end - else - - if numDigits == 3 then - if sc < 10 then - if prefix == "-" then - Panel = string.format( "%s%1d.%01d ", prefix, sc, hd) - else - Panel = string.format( "%1d.%02d ", sc, hd) - end - else - Panel = " . " - end - else - if Ndig == 2 then - Panel = string.format( " %s%1d.%02d ", prefix, sc, hd) - else - Panel = string.format( " %s%1d.%03d", prefix, sc, ms) - end - end - - end - - elseif deltaflag == 0 then - --display laptime - if lptime == -1 or (mn + sc + ms) == 0.0 then - if numDigits == 3 then - Panel = "-.--" - else - Panel = "-:--.---" - end - - elseif mn < 10 then - if numDigits == 3 then - Panel = string.format( "%1d.%02d", mn, sc) - else - Panel = string.format( "%1d:%02d.%03d", mn, sc, ms) - end - elseif hr > 0 then - if numDigits == 3 then - Panel = " . " - else - Panel = string.format( " %02d.%02d ", hr, mn) - end - else - if numDigits == 3 then - Panel = string.format( " %02d.", mn) - else - Panel = string.format( " %02d.%02d.%01d", mn, sc, ms) - end - end - end + -- global to backup ticks (ms) + dft_old_time = ticks + + local hr = 0 + local mn = 0 + local sc = 0 + local ms = 0 + local hd = 0 + local panel = "" + local prefix = " " + + if lptime < 0 then + prefix = "-" + end + -- explod time + hr, mn, sc, hd, ms = timeDispatcher(lptime) + + if deltaflag == 1 then + --display delta time + if lptime == -1 or (mn + sc + ms) == 0.0 then + if numDigits == 3 then + Panel = "-.--" + else + Panel = " -.-- " + end + elseif mn > 0 then + if numDigits == 3 then + if mn < 100 then + Panel = string.format( "%s%02d.", prefix, mn) + else + Panel = " ." + end + + else + Panel = string.format( " %s%1d.%02d ", prefix, mn, sc) + end + else + + if numDigits == 3 then + if sc < 10 then + if prefix == "-" then + Panel = string.format( "%s%1d.%01d ", prefix, sc, hd) + else + Panel = string.format( "%1d.%02d ", sc, hd) + end + else + Panel = " . " + end + else + if Ndig == 2 then + Panel = string.format( " %s%1d.%02d ", prefix, sc, hd) + else + Panel = string.format( " %s%1d.%03d", prefix, sc, ms) + end + end + + end + + elseif deltaflag == 0 then + --display laptime + if lptime == -1 or (mn + sc + ms) == 0.0 then + if numDigits == 3 then + Panel = "-.--" + else + Panel = "-:--.---" + end + + elseif mn < 10 then + if numDigits == 3 then + Panel = string.format( "%1d.%02d", mn, sc) + else + Panel = string.format( "%1d:%02d.%03d", mn, sc, ms) + end + elseif hr > 0 then + if numDigits == 3 then + Panel = " . " + else + Panel = string.format( " %02d.%02d ", hr, mn) + end + else + if numDigits == 3 then + Panel = string.format( " %02d.", mn) + else + Panel = string.format( " %02d.%02d.%01d", mn, sc, ms) + end + end + end end return Panel end + + +-- return delta time vs last time + sector diff +function GetDeltaLastTime(isRF) + + local lpt = 0.0 + + local sector = GetCarInfo("sector") + + if mDiffSectorDelay == nil or mDiffOldSector == nil or mDiffOldSector ~= sector then + -- 8s delay, increase it if needed + mDiffSectorDelay = GetTicks() + 8000 + mDiffOldSector = sector + + if sector == 1 then + -- diff lap time 3 + local lt = GetTimeInfo("lastlaptime") + + if lt > 0 and mOld_lt > 0 then + -- diff + mDelta_lpt = lt - mOld_lt + end + -- backup lt + mOld_lt = lt + -- save bt for delta vs best function + mOld_bt = GetTimeInfo("bestlaptime") + + + elseif sector == 2 then + -- diff sector 1 + local ls1 = GetTimeInfo("lastsector1") + if isRF then + ls1 = GetTimeInfo("sector1") + end + + if ls1 > 0 and mOld_ls1 > 0 then + mDelta_lpt = ls1 - mOld_ls1 + mDelta_Sect1 = mDelta_lpt + end + + -- backup + mOld_ls1 = ls1 + -- save bt for delta vs best function + mOld_bs = GetTimeInfo("bestsector1") + + else + -- diff sector 2 + local ls2 = GetTimeInfo("lastsector2") + if isRF then + ls2 = GetTimeInfo("sector2") + end + + + if ls2 > 0 and mOld_ls2 > 0 then + if mDelta_total_split_sectors then + mDelta_lpt = mDelta_Sect1 + (ls2 - mOld_ls2) + else + mDelta_lpt = ls2 - mOld_ls2 + end + end + -- backup value + mOld_ls2 = ls2 + -- save bt for delta vs best function below + mOld_bs2 = GetTimeInfo("bestsector2") + + end + end + + -- display delta by default + lpt = GetTimeInfo("realdifflast") + + if mDiffSectorDelay > GetTicks() then + lpt = mDelta_lpt + end + + return lpt +end + +-- return delta time vs best time + sector diff +function GetDeltaBestTime(isRF) + local lpt = 0.0 + + -- get sector + local sector = GetCarInfo("sector") + + -- set delay + if mDiffSectorDelay == nil or mDiffOldSector == nil or mDiffOldSector ~= sector then + -- 8s delay, increase it if needed + mDiffSectorDelay = GetTicks() + 8000 + mDiffOldSector = sector + + -- display sector diff during delay + if sector == 1 then + + -- diff last lap time vs best + local bt = GetTimeInfo("lastlaptime") + + -- save lt for delta vs last function above + mOld_lt = bt + + -- compare + if bt > 0 and mOld_bt > 0 then + -- delta + mDelta_lptb = bt - mOld_bt + end + -- backup + mOld_bt = GetTimeInfo("bestlaptime") + + + elseif sector == 2 then + -- diff sector 1 + local bs1 = GetTimeInfo("lastsector1") + if isRF then + bs1 = GetTimeInfo("sector1") + end + -- save lt for delta vs last function + mOld_ls1 = bs1 + + -- compare + if bs1 > 0 and mOld_bs1 > 0 then + mDelta_lptb = bs1 - mOld_bs1 + mDelta_Sect1b = mDelta_lptb + end + + mOld_bs1 = GetTimeInfo("bestsector1") + + else + -- diff sector 2 + local bs2 = GetTimeInfo("lastsector2") + if isRF then + bs2 = GetTimeInfo("sector2") + end + -- save lt for delta vs last function + mOld_ls2 = bs2 + + -- compare with old value + if bs2 > 0 and mOld_bs2 > 0 then + if mDelta_total_split_sectors then + mDelta_lptb = mDelta_Sect1b + (bs2 - mOld_bs2) + else + mDelta_lptb = bs2 - mOld_bs2 + end + end + -- backup + mOld_bs2 = GetTimeInfo("bestsector2") + end + end + + -- display delta by default + lpt = GetTimeInfo("realdiffbest") + + if mDiffSectorDelay > GetTicks() then + lpt = mDelta_lptb + end + + return lpt +end + --============================================== require "scripts/slidevice" -- cgit v1.2.3