summaryrefslogtreecommitdiff
path: root/scripts/simracef1.lua
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/simracef1.lua')
-rw-r--r--scripts/simracef1.lua1388
1 files changed, 694 insertions, 694 deletions
diff --git a/scripts/simracef1.lua b/scripts/simracef1.lua
index c7503cd..152b684 100644
--- a/scripts/simracef1.lua
+++ b/scripts/simracef1.lua
@@ -1,694 +1,694 @@
--- SIMRACE F1 Lua Script v1.1.3
--- Copyright (c)2012-2013 by Zappadoc - All Rights Reserved.
--- this script builds all functions associated with
--- left and right panels of SIMRACE-F1 device
--- last change by Zappadoc - 2013-10
-
--- ============================================================
--- Left and Right Panel functions
--- ============================================================
-function srf1LeftDigitsEvent(swFunction)
- return srf1DigitsEvent(swFunction, 0)
-end
-function srf1RightDigitsEvent(swFunction)
- return srf1DigitsEvent(swFunction, 1)
-end
--- IN function of left panel
--- param: recieve from SLI Manager the current switch position
-function srf1DigitsEvent(swFunction, side)
- swValue = swFunction + 1
-
- -- call custom script
- if side == 0 then
- local result = custom_srf1LeftDigitsEvent(swValue)
- -- 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_srf1LeftDigitsEvent(swValue)
- -- 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
- else
- local result = custom_srf1RightDigitsEvent(swValue)
- -- 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_srf1RightDigitsEvent(swValue)
- -- 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
- end
-
- local hr = 0
- local mn = 0
- local sc = 0
- local ms = 0
- local hd = 0
- local lpt = 0.0
- local diffTimeFlag = false
- local timeFlag = false
- local systemflag = false
- local unit = false
- local inf = ""
- local spd = 0.0
- local isSlowUpdate = false
- local srf1Panel = ""
-
- -- get speed in kph or mph (use "rawspeed" to get value in meter/sec)
- local spd = GetCarInfo("speed")
- -- get current display unit metric or imperial
- unit = GetContextInfo("speedmetric")
-
- -- lap finished, display lap time a few seconds
- local dlt = false
- dlt = GetContextInfo("displaylaptime")
- if dlt == nil then dlt = false end
- if dlt and side == 1 and swValue ~= 47 and swValue ~= 48 then
- swValue = 11
- end
-
- -- check if quick info button is down
- local qi = false
- qi = GetContextInfo("quickinfobutton")
- if qi == nil or qi == 0 then qi = false end
- if qi then
- -- get index for left and right panel
- local qiInf = 1
- if side == 0 then
- qiInf = GetContextInfo("quickinfoleft")
- else
- qiInf = GetContextInfo("quickinforight")
- end
- if qiInf == nil then qiInf = 1 end
- -- force position to match QI preference
- swValue = qiInf
- end
-
- -- check if PIT Feedback ON
- local pf = false
- pf = GetContextInfo("pitfeedback")
- if pf == nil or pf == 0 then pf = false end
- if pf then
- -- force position to PIT/SPEED function if car pits
- local pit = GetCarInfo("inpits")
- if pit > 0 then
- if side == 0 then
- swValue = 45
- else
- swValue = 1
- end
- end
- end
-
- -- get current simulation name
- local sim = GetContextInfo("simulation")
-
- --print ( "swValue: " .. swValue .. "\n")
-
- -- check postion and compute left panel string
- if swValue == 1 then
- -- speed only
- srf1Panel = string.format("%3.0f ", spd )
-
- elseif swValue == 2 then
- -- fuel
- local fuel = GetCarInfo("fuel")
- if fuel ~= nil then
- fuel = GetFuel(fuel, unit)
- if fuel >= 100 then
- srf1Panel = string.format("F%3d", round(fuel))
- elseif fuel >= 10 then
- srf1Panel = string.format("F%2d ", round(fuel))
- else
- srf1Panel = string.format("F%1.1f ", fuel)
- end
- end
- elseif swValue == 3 then
- -- position
- inf = GetContextInfo("position")
- if inf ~= nil then
- if inf >= 100 then
- srf1Panel = string.format("P%3d", inf)
- elseif inf >= 10 then
- srf1Panel = string.format("P%2d ", inf)
- else
- srf1Panel = string.format("P%1d ", inf)
- end
- end
- elseif swValue == 4 then
- -- laps completed
- inf = GetContextInfo("laps")
- if inf ~= nil then
- -- if more then 99 laps
- if inf >= 100 then
- srf1Panel = string.format("L%3d", inf)
- elseif inf >= 10 then
- srf1Panel = string.format("L%2d ", inf)
- else
- srf1Panel = string.format("L%1d ", inf)
- end
- end
- elseif swValue == 5 then
- -- sector
- inf = GetCarInfo("sector")
- if inf ~= nil then
- -- check if sector > 9
- if inf >9 then
- srf1Panel = string.format("S%2d ", inf)
- else
- srf1Panel = string.format("S%1d ", inf)
- end
- end
- elseif swValue == 6 then
- -- total laps if available
- local tl = GetContextInfo("lapscount")
- if tl < 1 then tl = 0 end
- -- if more then 99 laps
- if tl >= 100 then
- srf1Panel = string.format("T%3d", tl)
- elseif tl >= 10 then
- srf1Panel = string.format("T%2d ", tl)
- else
- srf1Panel = string.format("T%1d ", tl)
- end
-
- elseif swValue == 7 then
- -- water temp
- inf = GetCarInfo("watertemp")
- if inf ~= nil then
- inf = GetTemp(inf, unit)
- srf1Panel = string.format("W%2.1f", inf)
- end
- elseif swValue == 8 then
- -- oil temp
- inf = GetCarInfo("oiltemp")
- if inf ~= nil then
- inf = GetTemp(inf, unit)
- srf1Panel = string.format("o%2.1f", inf)
- end
-
- elseif swValue == 9 then
- -- best lap time
- timeFlag = true
- lpt = GetTimeInfo("laptime")
-
- elseif swValue == 10 then
- -- best lap time
- timeFlag = true
- lpt = GetTimeInfo("bestlaptime")
-
- elseif swValue == 11 then
- -- last lap time
- timeFlag = true
- lpt = GetTimeInfo("lastlaptime")
-
- elseif swValue >= 12 and swValue <= 18 and isAppIRacing(sim) then
- timeFlag = true
- diffTimeFlag = true
- -- iRacing partials
- local ts = GetContextInfo("partialcount")
- local sector = GetCarInfo("sector")
- if ts ~= nil and ts > 0 then
- if swValue == 12 then
- lpt = GetPartialTimeInfo("currentpartial", sector)
- elseif swValue == 13 then
- lpt = GetPartialTimeInfo("vsbestlap", sector)
- elseif swValue == 14 then
- lpt = GetPartialTimeInfo("vsoptimallap", sector)
- elseif swValue == 15 then
- lpt = GetPartialTimeInfo("vsoptimalsector", sector)
- elseif swValue == 16 then
- lpt = GetPartialTimeInfo("vssessionbestlap", sector)
- elseif swValue == 17 then
- lpt = GetPartialTimeInfo("vssessionoptimallap", sector)
- elseif swValue == 18 then
- lpt = GetPartialTimeInfo("vssessionoptimalsector", sector)
- end
- else
- lpt = 0.0
- end
-
- elseif swValue == 19 then
- -- real time diff vs your best
- diffTimeFlag = true
- timeFlag = true
- lpt = GetTimeInfo("realdiffbest")
-
- elseif swValue == 20 then
- -- real time diff vs your last
- diffTimeFlag = true
- timeFlag = true
- lpt = GetTimeInfo("realdifflast")
-
- elseif swValue == 21 then
- -- get an average consumption of fuel per lap and gives the remaining laps
- local remainintank = GetCarInfo("remainlapsintank")
- srf1Panel = string.format("L%3.0f", math.floor(remainintank) )
-
- elseif swValue == 22 then
- -- rpm
- isSlowUpdate = true
- --timeFlag = true
- local rpm = GetCarInfo("rpm")
- local r = rpm / 10.0
- if r < 1000 then
- srf1Panel = string.format("%3.1f", r)
- else
- srf1Panel = string.format("%4d.", round(r))
- end
- elseif swValue == 23 then
- -- track size
- isSlowUpdate = true
- --timeFlag = true
- local trcksz = GetContextInfo("tracksize")
- local r = trcksz / 10
- if r < 1000 then
- srf1Panel = string.format("%3.1f", r)
- else
- srf1Panel = string.format("%4d.", round(r))
- end
-
- elseif swValue == 24 then
- -- distance percent
- local dist = GetContextInfo("lapdistance")
- -- track size
- local trcksz = GetContextInfo("tracksize")
- local p = round(dist / (trcksz / 100))
- srf1Panel = string.format("D%3d", p )
-
- elseif swValue == 25 then
- -- kers
- local kers = GetCarInfo("kers")
- srf1Panel = string.format("K%3d", round(kers/1000))
-
- elseif swValue == 26 then
- -- kers max
- local kmx = GetCarInfo("kersmax")
- srf1Panel = string.format("K%3d", round(kmx/1000))
-
- elseif swValue == 27 then
- -- drs
- local drs = GetCarInfo("drs")
- if drs == 1 then
- srf1Panel = "ON "
- else
- srf1Panel = "OFF"
- end
-
- elseif swValue == 28 then
- -- kers percent
- local kers = GetCarInfo("kers")
- srf1Panel = string.format("K%3d", round((kers/1000)/4))
-
- elseif swValue == 29 then
- -- wheels temp if available
- inf = GetCarInfo("wheeltempfrontleft")
- if inf ~= nil then
- -- if rFactor convert Kelvin to Celsius (see global.lua)
- if isAppRFactor(sim) then inf = KtoC(inf) end
- srf1Panel = string.format("%3.0f ", inf)
- end
-
- elseif swValue == 30 then
- inf = GetCarInfo("wheeltempfrontright")
- if inf ~= nil then
- if isAppRFactor(sim) then inf = KtoC(inf) end
- srf1Panel = string.format("%3.0f ", inf)
- end
-
- elseif swValue == 31 then
- inf = GetCarInfo("wheeltemprearleft")
- if inf ~= nil then
- if isAppRFactor(sim) then inf = KtoC(inf) end
- srf1Panel = string.format("%3.0f ", inf)
- end
-
- elseif swValue == 32 then
- inf = GetCarInfo("wheeltemprearright")
- if inf ~= nil then
- if isAppRFactor(sim) then inf = KtoC(inf) end
- srf1Panel = string.format("%3.0f ", inf)
- end
-
- elseif swValue == 33 then
- -- wheels pressure if available
- inf = GetCarInfo("wheelpressfrontleft")
- if inf ~= nil then
- -- convert to psi
- srf1Panel = string.format("%2.1f ", inf / 6.88)
- end
-
- elseif swValue == 34 then
- inf = GetCarInfo("wheelpressfrontright")
- if inf ~= nil then
- srf1Panel = string.format("%2.1f ", inf / 6.88)
- end
-
- elseif swValue == 35 then
- inf = GetCarInfo("wheelpressrearleft")
- if inf ~= nil then
- srf1Panel = string.format("%2.1f ", inf / 6.88)
- end
-
- elseif swValue == 36 then
- inf = GetCarInfo("wheelpressrearright")
- if inf ~= nil then
- srf1Panel = string.format("%2.1f ", inf / 6.88)
- end
-
- elseif swValue == 37 then
- -- brakes temp if available
- inf = GetCarInfo("braketempfrontleft")
- if inf ~= nil then
- if isAppRFactor(sim) or sim == "GTR2.exe" then inf = KtoC(inf) end
- srf1Panel = string.format("%3.0f ", inf)
- end
-
- elseif swValue == 38 then
- inf = GetCarInfo("braketempfrontright")
- if inf ~= nil then
- if isAppRFactor(sim) or sim == "GTR2.exe" then inf = KtoC(inf) end
- srf1Panel = string.format("%3.0f ", inf)
- end
-
- elseif swValue == 39 then
- inf = GetCarInfo("braketemprearleft")
- if inf ~= nil then
- if isAppRFactor(sim) or sim == "GTR2.exe" then inf = KtoC(inf) end
- srf1Panel = string.format("%3.0f ", inf)
- end
-
- elseif swValue == 40 then
- inf = GetCarInfo("braketemprearright")
- if inf ~= nil then
- if isAppRFactor(sim) or sim == "GTR2.exe" then inf = KtoC(inf) end
- srf1Panel = string.format("%3.0f ", inf)
- end
-
- elseif swValue == 41 then
- -- time remaining if available
- lpt = GetTimeInfo("timeremaining")
- timeFlag = true
-
- elseif swValue == 42 then
- -- PC system time
- systemflag = true
- lpt = GetTimeInfo("systemtime")
- timeFlag = true
- --diffTimeFlag = true
- elseif swValue == 43 then
- -- time elapsed if available
- lpt = GetTimeInfo("timetotalelapsed")
- timeFlag = true
-
- elseif swValue == 44 then
- -- last sector 1, 2 and 3
- local sector = GetCarInfo("sector")
- timeFlag = true
- --diffTimeFlag = true
- if sector == 1 then
- -- sector 3
- local ls1 = GetTimeInfo("lastsector1")
- local ls2 = GetTimeInfo("lastsector2")
- local lt = GetTimeInfo("lastlaptime")
- if ls1 > 0 and ls2 > 0 then
- lpt = lt - (ls1 + ls2)
- end
- elseif sector == 2 then
- local ls1 = GetTimeInfo("lastsector1")
- lpt = ls1
- else
- -- sector 3
- local ls2 = GetTimeInfo("lastsector2")
- lpt = ls2
- end
-
- elseif swValue == 45 then
- -- PIT
- srf1Panel = "PIT "
-
- elseif swValue == 46 then
- -- sc
- local sc = GetContextInfo("safetycare")
- if sc == 1 then
- srf1Panel = "SCAR"
- else
- srf1Panel = "OFF "
- end
-
- elseif swValue == 47 then
- -- real time delta vs last + last sector diff 1, 2 and 3
- local sector = GetCarInfo("sector")
- timeFlag = true
- diffTimeFlag = true
- if mDiffSectorDelay == nil or mDiffOldSector == nil or mDiffOldSector ~= sector then
- -- 8s delay, increase it if needed
- mDiffSectorDelay = GetTicks() + 8000
- mDiffOldSector = sector
- end
- -- init backup vars
- if mOld_lt == nil then
- mOld_ls1 = 0.00000
- mOld_ls2 = 0.00000
- mOld_lt = 0.00000
- mDelta_lpt = 0.00000
- mDelta_lptb = 0.00000
- end
-
- -- display delta by default
- lpt = GetTimeInfo("realdifflast")
-
- if mDiffSectorDelay > GetTicks() then
- -- display sector
- if sector == 1 then
- -- sector 3
- --local ls1 = GetTimeInfo("lastsector1")
- --local ls2 = GetTimeInfo("lastsector2")
- local lt = GetTimeInfo("lastlaptime")
-
- --i-- delta sector 3f ls1 > 0 and ls2 > 0 and lt > 0 and mOld_ls1 > 0 and mOld_ls2 > 0 and mOld_lt > 0 then
- -- delta sector 3
- --lpt = (lt - (ls1 + ls2)) - (mOld_lt - (mOld_ls1 + mOld_ls2))
- if lt > 0 and mOld_lt > 0 then
- if lt ~= mOld_lt then
- mDelta_lpt = lt - mOld_lt
- print(mDelta_lpt, lt, mOld_lt)
- end
- lpt = mDelta_lpt
- end
-
- mOld_lt = lt
-
-
- elseif sector == 2 then
- -- sector 1
- local ls1 = GetTimeInfo("lastsector1")
- if ls1 > 0 and mOld_ls1 > 0 then
- lpt = ls1 - mOld_ls1
- end
- mOld_ls2 = GetTimeInfo("lastsector2")
- print(lpt, ls1 , mOld_ls1, mOld_ls2)
-
- else
- -- sector 2
- local ls2 = GetTimeInfo("lastsector2")
- if ls2 > 0 and mOld_ls2 > 0 then
- lpt = ls2 - mOld_ls2
- end
- mOld_ls1 = GetTimeInfo("lastsector1")
- print(lpt, ls2 , mOld_ls1, mOld_ls2)
- end
- end
-
- elseif swValue == 48 then
- -- real time delta vs best + last sector diff 1, 2 and 3
-
- -- get sector
- local sector = GetCarInfo("sector")
- -- set flags
- timeFlag = true
- diffTimeFlag = true
-
- -- set delay
- if mDiffSectorDelay == nil or mDiffOldSector == nil or mDiffOldSector ~= sector then
- -- 8s delay, increase it if needed
- mDiffSectorDelay = GetTicks() + 8000
- mDiffOldSector = sector
- end
-
- -- init backup vars
- if mOld_bt == nil then
- mOld_bs1 = 0.00000
- mOld_bs2 = 0.00000
- mOld_bt = 0.00000
- mDelta_lpt = 0.00000
- mDelta_lptb = 0.00000
- end
-
- -- display delta by default
- lpt = GetTimeInfo("realdiffbest")
-
- if mDiffSectorDelay > GetTicks() then
- -- display sector diff during delay
- if sector == 1 then
- -- sector 3
- --local bs1 = GetTimeInfo("bestsector1")
- --local bs2 = GetTimeInfo("bestsector2")
- local bt = GetTimeInfo("bestlaptime")
-
- --if bs1 > 0 and bs2 > 0 and bt > 0 and mOld_bs1 > 0 and mOld_bs2 > 0 and mOld_bt > 0 then
- -- delta sector 3
- -- lpt = (bt - (bs1 + bs2)) - (mOld_bt - (mOld_bs1 + mOld_bs2))
- if bt > 0 and mOld_bt > 0 then
- if bt ~= mOld_bt then
- mDelta_lptb = bt - mOld_bt
- print(mDelta_lpt, bt, mOld_bt)
- end
- lpt = mDelta_lptb
- end
-
- mOld_bt = bt
-
- elseif sector == 2 then
- -- sector 1
- local bs1 = GetTimeInfo("bestsector1")
- if bs1 > 0 and mOld_bs1 > 0 then
- lpt = bs1 - mOld_bs1
- end
- print(lpt, bs1 )
- mOld_bs2 = GetTimeInfo("bestsector2")
-
- else
- -- sector 2
- local bs2 = GetTimeInfo("bestsector2")
- if bs2 > 0 and mOld_bs2 > 0 then
- lpt = bs2 - mOld_bs2
- end
- print(lpt, bs2 )
- mOld_bs1 = GetTimeInfo("bestsector1")
- end
- end
-
- else
- srf1Panel = " "
- end
- -- check if diff time is ready
- local diffOK = GetTimeInfo("realdifftimeready")
- if diffTimeFlag and diffOK == false then
- diffTimeFlag = false
- timeFlag = false
- srf1Panel = "NPEF"
-
- mOld_ls1 = 0.00000
- mOld_ls2 = 0.00000
- mOld_lt = 0.00000
- mDelta_lpt = 0.00000
- mDelta_lptb = 0.00000
- end
-
- local c = ""
- local refreshRate = mRefreshLapTimeRate
- if diffTimeFlag then
- c = "+"
- refreshRate = mDeltaTimeDelay
- end
-
- if timeFlag and lpt ~= nil then
-
- -- set char of negative number
- if diffTimeFlag then
- if lpt < 0 then c = "-" end
- end
- -- explod time
- hr, mn, sc, hd, ms = timeDispatcher(lpt)
-
- --print("lpt: " .. lpt .. " m: " .. mn .. " - s: " .. sc .. " - ms: " .. ms .."\n" )
-
- -- update display every mDeltaTimeDelay time
- if GetTicks() > (refreshRate + mDeltaTimeOldTicks ) then
- mDeltaTimeOldTicks = GetTicks()
-
- if lpt == -1 or (mn + sc + ms) == 0.0000 then
- mDeltaTimeBackup = "-.---"
-
- elseif systemflag then
- mDeltaTimeBackup = string.format( "%2d.%02d", mn, sc)
-
- elseif mn > 9 then
- -- > 9mn
- if c == "" then
- mDeltaTimeBackup = string.format( "%2d.%2d", mn, sc)
- else
- mDeltaTimeBackup = string.format( "%s%2d ", c, mn)
- end
-
- elseif mn > 0 and mn < 10 then
- -- < 10mn
- if c == "" then
- mDeltaTimeBackup = string.format( "%1d.%02d.%01d", mn, sc, hd)
- else
- mDeltaTimeBackup = string.format( "%s%1d.%02d", c, mn, sc)
- end
-
- else
- -- sc > 9
- if sc > 9 then
- if c == "" then
- mDeltaTimeBackup = string.format( "0.%2d.%1d", sc, hd)
- else
- mDeltaTimeBackup = string.format( "%s%02d.%01d", c, sc, hd)
- end
-
- else
- -- sc < 0
- if c == "" then
- mDeltaTimeBackup = string.format( "0.%01d.%02d", sc, hd)
- else
- mDeltaTimeBackup = string.format( "%s%01d.%02d", c, sc, hd)
- end
-
- end
- end
- end
-
- --print(srf1Panel,mDeltaTimeBackup)
- srf1Panel = mDeltaTimeBackup
- end
-
- if isSlowUpdate then
-
- if GetTicks() > ( refreshRate + mDeltaTimeOldTicks ) then
- mDeltaTimeOldTicks = GetTicks()
- if side == 0 then
- mSRF1LeftText = srf1Panel
- else
- mSRF1RightText = srf1Panel
- end
- -- print(GetTicks() .. mSRF1RightText .."\n")
- end
- else
- if side == 0 then
- mSRF1LeftText = srf1Panel
- else
- mSRF1RightText = srf1Panel
- end
- end
-
- -- print(mSRF1LeftText, mSRF1RightText, srf1Panel)
- -- send string to sli manager
- if side == 0 then
- SetLeftDigits( mSRF1LeftText )
- else
- SetRightDigits( mSRF1RightText )
- end
-
- return 1
-end
+-- SIMRACE F1 Lua Script v1.1.3
+-- Copyright (c)2012-2013 by Zappadoc - All Rights Reserved.
+-- this script builds all functions associated with
+-- left and right panels of SIMRACE-F1 device
+-- last change by Zappadoc - 2013-10
+
+-- ============================================================
+-- Left and Right Panel functions
+-- ============================================================
+function srf1LeftDigitsEvent(swFunction)
+ return srf1DigitsEvent(swFunction, 0)
+end
+function srf1RightDigitsEvent(swFunction)
+ return srf1DigitsEvent(swFunction, 1)
+end
+-- IN function of left panel
+-- param: recieve from SLI Manager the current switch position
+function srf1DigitsEvent(swFunction, side)
+ swValue = swFunction + 1
+
+ -- call custom script
+ if side == 0 then
+ local result = custom_srf1LeftDigitsEvent(swValue)
+ -- 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_srf1LeftDigitsEvent(swValue)
+ -- 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
+ else
+ local result = custom_srf1RightDigitsEvent(swValue)
+ -- 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_srf1RightDigitsEvent(swValue)
+ -- 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
+ end
+
+ local hr = 0
+ local mn = 0
+ local sc = 0
+ local ms = 0
+ local hd = 0
+ local lpt = 0.0
+ local diffTimeFlag = false
+ local timeFlag = false
+ local systemflag = false
+ local unit = false
+ local inf = ""
+ local spd = 0.0
+ local isSlowUpdate = false
+ local srf1Panel = ""
+
+ -- get speed in kph or mph (use "rawspeed" to get value in meter/sec)
+ local spd = GetCarInfo("speed")
+ -- get current display unit metric or imperial
+ unit = GetContextInfo("speedmetric")
+
+ -- lap finished, display lap time a few seconds
+ local dlt = false
+ dlt = GetContextInfo("displaylaptime")
+ if dlt == nil then dlt = false end
+ if dlt and side == 1 and swValue ~= 47 and swValue ~= 48 then
+ swValue = 11
+ end
+
+ -- check if quick info button is down
+ local qi = false
+ qi = GetContextInfo("quickinfobutton")
+ if qi == nil or qi == 0 then qi = false end
+ if qi then
+ -- get index for left and right panel
+ local qiInf = 1
+ if side == 0 then
+ qiInf = GetContextInfo("quickinfoleft")
+ else
+ qiInf = GetContextInfo("quickinforight")
+ end
+ if qiInf == nil then qiInf = 1 end
+ -- force position to match QI preference
+ swValue = qiInf
+ end
+
+ -- check if PIT Feedback ON
+ local pf = false
+ pf = GetContextInfo("pitfeedback")
+ if pf == nil or pf == 0 then pf = false end
+ if pf then
+ -- force position to PIT/SPEED function if car pits
+ local pit = GetCarInfo("inpits")
+ if pit > 0 then
+ if side == 0 then
+ swValue = 45
+ else
+ swValue = 1
+ end
+ end
+ end
+
+ -- get current simulation name
+ local sim = GetContextInfo("simulation")
+
+ --print ( "swValue: " .. swValue .. "\n")
+
+ -- check postion and compute left panel string
+ if swValue == 1 then
+ -- speed only
+ srf1Panel = string.format("%3.0f ", spd )
+
+ elseif swValue == 2 then
+ -- fuel
+ local fuel = GetCarInfo("fuel")
+ if fuel ~= nil then
+ fuel = GetFuel(fuel, unit)
+ if fuel >= 100 then
+ srf1Panel = string.format("F%3d", round(fuel))
+ elseif fuel >= 10 then
+ srf1Panel = string.format("F%2d ", round(fuel))
+ else
+ srf1Panel = string.format("F%1.1f ", fuel)
+ end
+ end
+ elseif swValue == 3 then
+ -- position
+ inf = GetContextInfo("position")
+ if inf ~= nil then
+ if inf >= 100 then
+ srf1Panel = string.format("P%3d", inf)
+ elseif inf >= 10 then
+ srf1Panel = string.format("P%2d ", inf)
+ else
+ srf1Panel = string.format("P%1d ", inf)
+ end
+ end
+ elseif swValue == 4 then
+ -- laps completed
+ inf = GetContextInfo("laps")
+ if inf ~= nil then
+ -- if more then 99 laps
+ if inf >= 100 then
+ srf1Panel = string.format("L%3d", inf)
+ elseif inf >= 10 then
+ srf1Panel = string.format("L%2d ", inf)
+ else
+ srf1Panel = string.format("L%1d ", inf)
+ end
+ end
+ elseif swValue == 5 then
+ -- sector
+ inf = GetCarInfo("sector")
+ if inf ~= nil then
+ -- check if sector > 9
+ if inf >9 then
+ srf1Panel = string.format("S%2d ", inf)
+ else
+ srf1Panel = string.format("S%1d ", inf)
+ end
+ end
+ elseif swValue == 6 then
+ -- total laps if available
+ local tl = GetContextInfo("lapscount")
+ if tl < 1 then tl = 0 end
+ -- if more then 99 laps
+ if tl >= 100 then
+ srf1Panel = string.format("T%3d", tl)
+ elseif tl >= 10 then
+ srf1Panel = string.format("T%2d ", tl)
+ else
+ srf1Panel = string.format("T%1d ", tl)
+ end
+
+ elseif swValue == 7 then
+ -- water temp
+ inf = GetCarInfo("watertemp")
+ if inf ~= nil then
+ inf = GetTemp(inf, unit)
+ srf1Panel = string.format("W%2.1f", inf)
+ end
+ elseif swValue == 8 then
+ -- oil temp
+ inf = GetCarInfo("oiltemp")
+ if inf ~= nil then
+ inf = GetTemp(inf, unit)
+ srf1Panel = string.format("o%2.1f", inf)
+ end
+
+ elseif swValue == 9 then
+ -- best lap time
+ timeFlag = true
+ lpt = GetTimeInfo("laptime")
+
+ elseif swValue == 10 then
+ -- best lap time
+ timeFlag = true
+ lpt = GetTimeInfo("bestlaptime")
+
+ elseif swValue == 11 then
+ -- last lap time
+ timeFlag = true
+ lpt = GetTimeInfo("lastlaptime")
+
+ elseif swValue >= 12 and swValue <= 18 and isAppIRacing(sim) then
+ timeFlag = true
+ diffTimeFlag = true
+ -- iRacing partials
+ local ts = GetContextInfo("partialcount")
+ local sector = GetCarInfo("sector")
+ if ts ~= nil and ts > 0 then
+ if swValue == 12 then
+ lpt = GetPartialTimeInfo("currentpartial", sector)
+ elseif swValue == 13 then
+ lpt = GetPartialTimeInfo("vsbestlap", sector)
+ elseif swValue == 14 then
+ lpt = GetPartialTimeInfo("vsoptimallap", sector)
+ elseif swValue == 15 then
+ lpt = GetPartialTimeInfo("vsoptimalsector", sector)
+ elseif swValue == 16 then
+ lpt = GetPartialTimeInfo("vssessionbestlap", sector)
+ elseif swValue == 17 then
+ lpt = GetPartialTimeInfo("vssessionoptimallap", sector)
+ elseif swValue == 18 then
+ lpt = GetPartialTimeInfo("vssessionoptimalsector", sector)
+ end
+ else
+ lpt = 0.0
+ end
+
+ elseif swValue == 19 then
+ -- real time diff vs your best
+ diffTimeFlag = true
+ timeFlag = true
+ lpt = GetTimeInfo("realdiffbest")
+
+ elseif swValue == 20 then
+ -- real time diff vs your last
+ diffTimeFlag = true
+ timeFlag = true
+ lpt = GetTimeInfo("realdifflast")
+
+ elseif swValue == 21 then
+ -- get an average consumption of fuel per lap and gives the remaining laps
+ local remainintank = GetCarInfo("remainlapsintank")
+ srf1Panel = string.format("L%3.0f", math.floor(remainintank) )
+
+ elseif swValue == 22 then
+ -- rpm
+ isSlowUpdate = true
+ --timeFlag = true
+ local rpm = GetCarInfo("rpm")
+ local r = rpm / 10.0
+ if r < 1000 then
+ srf1Panel = string.format("%3.1f", r)
+ else
+ srf1Panel = string.format("%4d.", round(r))
+ end
+ elseif swValue == 23 then
+ -- track size
+ isSlowUpdate = true
+ --timeFlag = true
+ local trcksz = GetContextInfo("tracksize")
+ local r = trcksz / 10
+ if r < 1000 then
+ srf1Panel = string.format("%3.1f", r)
+ else
+ srf1Panel = string.format("%4d.", round(r))
+ end
+
+ elseif swValue == 24 then
+ -- distance percent
+ local dist = GetContextInfo("lapdistance")
+ -- track size
+ local trcksz = GetContextInfo("tracksize")
+ local p = round(dist / (trcksz / 100))
+ srf1Panel = string.format("D%3d", p )
+
+ elseif swValue == 25 then
+ -- kers
+ local kers = GetCarInfo("kers")
+ srf1Panel = string.format("K%3d", round(kers/1000))
+
+ elseif swValue == 26 then
+ -- kers max
+ local kmx = GetCarInfo("kersmax")
+ srf1Panel = string.format("K%3d", round(kmx/1000))
+
+ elseif swValue == 27 then
+ -- drs
+ local drs = GetCarInfo("drs")
+ if drs == 1 then
+ srf1Panel = "ON "
+ else
+ srf1Panel = "OFF"
+ end
+
+ elseif swValue == 28 then
+ -- kers percent
+ local kers = GetCarInfo("kers")
+ srf1Panel = string.format("K%3d", round((kers/1000)/4))
+
+ elseif swValue == 29 then
+ -- wheels temp if available
+ inf = GetCarInfo("wheeltempfrontleft")
+ if inf ~= nil then
+ -- if rFactor convert Kelvin to Celsius (see global.lua)
+ if isAppRFactor(sim) then inf = KtoC(inf) end
+ srf1Panel = string.format("%3.0f ", inf)
+ end
+
+ elseif swValue == 30 then
+ inf = GetCarInfo("wheeltempfrontright")
+ if inf ~= nil then
+ if isAppRFactor(sim) then inf = KtoC(inf) end
+ srf1Panel = string.format("%3.0f ", inf)
+ end
+
+ elseif swValue == 31 then
+ inf = GetCarInfo("wheeltemprearleft")
+ if inf ~= nil then
+ if isAppRFactor(sim) then inf = KtoC(inf) end
+ srf1Panel = string.format("%3.0f ", inf)
+ end
+
+ elseif swValue == 32 then
+ inf = GetCarInfo("wheeltemprearright")
+ if inf ~= nil then
+ if isAppRFactor(sim) then inf = KtoC(inf) end
+ srf1Panel = string.format("%3.0f ", inf)
+ end
+
+ elseif swValue == 33 then
+ -- wheels pressure if available
+ inf = GetCarInfo("wheelpressfrontleft")
+ if inf ~= nil then
+ -- convert to psi
+ srf1Panel = string.format("%2.1f ", inf / 6.88)
+ end
+
+ elseif swValue == 34 then
+ inf = GetCarInfo("wheelpressfrontright")
+ if inf ~= nil then
+ srf1Panel = string.format("%2.1f ", inf / 6.88)
+ end
+
+ elseif swValue == 35 then
+ inf = GetCarInfo("wheelpressrearleft")
+ if inf ~= nil then
+ srf1Panel = string.format("%2.1f ", inf / 6.88)
+ end
+
+ elseif swValue == 36 then
+ inf = GetCarInfo("wheelpressrearright")
+ if inf ~= nil then
+ srf1Panel = string.format("%2.1f ", inf / 6.88)
+ end
+
+ elseif swValue == 37 then
+ -- brakes temp if available
+ inf = GetCarInfo("braketempfrontleft")
+ if inf ~= nil then
+ if isAppRFactor(sim) or sim == "GTR2.exe" then inf = KtoC(inf) end
+ srf1Panel = string.format("%3.0f ", inf)
+ end
+
+ elseif swValue == 38 then
+ inf = GetCarInfo("braketempfrontright")
+ if inf ~= nil then
+ if isAppRFactor(sim) or sim == "GTR2.exe" then inf = KtoC(inf) end
+ srf1Panel = string.format("%3.0f ", inf)
+ end
+
+ elseif swValue == 39 then
+ inf = GetCarInfo("braketemprearleft")
+ if inf ~= nil then
+ if isAppRFactor(sim) or sim == "GTR2.exe" then inf = KtoC(inf) end
+ srf1Panel = string.format("%3.0f ", inf)
+ end
+
+ elseif swValue == 40 then
+ inf = GetCarInfo("braketemprearright")
+ if inf ~= nil then
+ if isAppRFactor(sim) or sim == "GTR2.exe" then inf = KtoC(inf) end
+ srf1Panel = string.format("%3.0f ", inf)
+ end
+
+ elseif swValue == 41 then
+ -- time remaining if available
+ lpt = GetTimeInfo("timeremaining")
+ timeFlag = true
+
+ elseif swValue == 42 then
+ -- PC system time
+ systemflag = true
+ lpt = GetTimeInfo("systemtime")
+ timeFlag = true
+ --diffTimeFlag = true
+ elseif swValue == 43 then
+ -- time elapsed if available
+ lpt = GetTimeInfo("timetotalelapsed")
+ timeFlag = true
+
+ elseif swValue == 44 then
+ -- last sector 1, 2 and 3
+ local sector = GetCarInfo("sector")
+ timeFlag = true
+ --diffTimeFlag = true
+ if sector == 1 then
+ -- sector 3
+ local ls1 = GetTimeInfo("lastsector1")
+ local ls2 = GetTimeInfo("lastsector2")
+ local lt = GetTimeInfo("lastlaptime")
+ if ls1 > 0 and ls2 > 0 then
+ lpt = lt - (ls1 + ls2)
+ end
+ elseif sector == 2 then
+ local ls1 = GetTimeInfo("lastsector1")
+ lpt = ls1
+ else
+ -- sector 3
+ local ls2 = GetTimeInfo("lastsector2")
+ lpt = ls2
+ end
+
+ elseif swValue == 45 then
+ -- PIT
+ srf1Panel = "PIT "
+
+ elseif swValue == 46 then
+ -- sc
+ local sc = GetContextInfo("safetycare")
+ if sc == 1 then
+ srf1Panel = "SCAR"
+ else
+ srf1Panel = "OFF "
+ end
+
+ elseif swValue == 47 then
+ -- real time delta vs last + last sector diff 1, 2 and 3
+ local sector = GetCarInfo("sector")
+ timeFlag = true
+ diffTimeFlag = true
+ if mDiffSectorDelay == nil or mDiffOldSector == nil or mDiffOldSector ~= sector then
+ -- 8s delay, increase it if needed
+ mDiffSectorDelay = GetTicks() + 8000
+ mDiffOldSector = sector
+ end
+ -- init backup vars
+ if mOld_lt == nil then
+ mOld_ls1 = 0.00000
+ mOld_ls2 = 0.00000
+ mOld_lt = 0.00000
+ mDelta_lpt = 0.00000
+ mDelta_lptb = 0.00000
+ end
+
+ -- display delta by default
+ lpt = GetTimeInfo("realdifflast")
+
+ if mDiffSectorDelay > GetTicks() then
+ -- display sector
+ if sector == 1 then
+ -- sector 3
+ --local ls1 = GetTimeInfo("lastsector1")
+ --local ls2 = GetTimeInfo("lastsector2")
+ local lt = GetTimeInfo("lastlaptime")
+
+ --i-- delta sector 3f ls1 > 0 and ls2 > 0 and lt > 0 and mOld_ls1 > 0 and mOld_ls2 > 0 and mOld_lt > 0 then
+ -- delta sector 3
+ --lpt = (lt - (ls1 + ls2)) - (mOld_lt - (mOld_ls1 + mOld_ls2))
+ if lt > 0 and mOld_lt > 0 then
+ if lt ~= mOld_lt then
+ mDelta_lpt = lt - mOld_lt
+ print(mDelta_lpt, lt, mOld_lt)
+ end
+ lpt = mDelta_lpt
+ end
+
+ mOld_lt = lt
+
+
+ elseif sector == 2 then
+ -- sector 1
+ local ls1 = GetTimeInfo("lastsector1")
+ if ls1 > 0 and mOld_ls1 > 0 then
+ lpt = ls1 - mOld_ls1
+ end
+ mOld_ls2 = GetTimeInfo("lastsector2")
+ print(lpt, ls1 , mOld_ls1, mOld_ls2)
+
+ else
+ -- sector 2
+ local ls2 = GetTimeInfo("lastsector2")
+ if ls2 > 0 and mOld_ls2 > 0 then
+ lpt = ls2 - mOld_ls2
+ end
+ mOld_ls1 = GetTimeInfo("lastsector1")
+ print(lpt, ls2 , mOld_ls1, mOld_ls2)
+ end
+ end
+
+ elseif swValue == 48 then
+ -- real time delta vs best + last sector diff 1, 2 and 3
+
+ -- get sector
+ local sector = GetCarInfo("sector")
+ -- set flags
+ timeFlag = true
+ diffTimeFlag = true
+
+ -- set delay
+ if mDiffSectorDelay == nil or mDiffOldSector == nil or mDiffOldSector ~= sector then
+ -- 8s delay, increase it if needed
+ mDiffSectorDelay = GetTicks() + 8000
+ mDiffOldSector = sector
+ end
+
+ -- init backup vars
+ if mOld_bt == nil then
+ mOld_bs1 = 0.00000
+ mOld_bs2 = 0.00000
+ mOld_bt = 0.00000
+ mDelta_lpt = 0.00000
+ mDelta_lptb = 0.00000
+ end
+
+ -- display delta by default
+ lpt = GetTimeInfo("realdiffbest")
+
+ if mDiffSectorDelay > GetTicks() then
+ -- display sector diff during delay
+ if sector == 1 then
+ -- sector 3
+ --local bs1 = GetTimeInfo("bestsector1")
+ --local bs2 = GetTimeInfo("bestsector2")
+ local bt = GetTimeInfo("bestlaptime")
+
+ --if bs1 > 0 and bs2 > 0 and bt > 0 and mOld_bs1 > 0 and mOld_bs2 > 0 and mOld_bt > 0 then
+ -- delta sector 3
+ -- lpt = (bt - (bs1 + bs2)) - (mOld_bt - (mOld_bs1 + mOld_bs2))
+ if bt > 0 and mOld_bt > 0 then
+ if bt ~= mOld_bt then
+ mDelta_lptb = bt - mOld_bt
+ print(mDelta_lpt, bt, mOld_bt)
+ end
+ lpt = mDelta_lptb
+ end
+
+ mOld_bt = bt
+
+ elseif sector == 2 then
+ -- sector 1
+ local bs1 = GetTimeInfo("bestsector1")
+ if bs1 > 0 and mOld_bs1 > 0 then
+ lpt = bs1 - mOld_bs1
+ end
+ print(lpt, bs1 )
+ mOld_bs2 = GetTimeInfo("bestsector2")
+
+ else
+ -- sector 2
+ local bs2 = GetTimeInfo("bestsector2")
+ if bs2 > 0 and mOld_bs2 > 0 then
+ lpt = bs2 - mOld_bs2
+ end
+ print(lpt, bs2 )
+ mOld_bs1 = GetTimeInfo("bestsector1")
+ end
+ end
+
+ else
+ srf1Panel = " "
+ end
+ -- check if diff time is ready
+ local diffOK = GetTimeInfo("realdifftimeready")
+ if diffTimeFlag and diffOK == false then
+ diffTimeFlag = false
+ timeFlag = false
+ srf1Panel = "NPEF"
+
+ mOld_ls1 = 0.00000
+ mOld_ls2 = 0.00000
+ mOld_lt = 0.00000
+ mDelta_lpt = 0.00000
+ mDelta_lptb = 0.00000
+ end
+
+ local c = ""
+ local refreshRate = mRefreshLapTimeRate
+ if diffTimeFlag then
+ c = "+"
+ refreshRate = mDeltaTimeDelay
+ end
+
+ if timeFlag and lpt ~= nil then
+
+ -- set char of negative number
+ if diffTimeFlag then
+ if lpt < 0 then c = "-" end
+ end
+ -- explod time
+ hr, mn, sc, hd, ms = timeDispatcher(lpt)
+
+ --print("lpt: " .. lpt .. " m: " .. mn .. " - s: " .. sc .. " - ms: " .. ms .."\n" )
+
+ -- update display every mDeltaTimeDelay time
+ if GetTicks() > (refreshRate + mDeltaTimeOldTicks ) then
+ mDeltaTimeOldTicks = GetTicks()
+
+ if lpt == -1 or (mn + sc + ms) == 0.0000 then
+ mDeltaTimeBackup = "-.---"
+
+ elseif systemflag then
+ mDeltaTimeBackup = string.format( "%2d.%02d", mn, sc)
+
+ elseif mn > 9 then
+ -- > 9mn
+ if c == "" then
+ mDeltaTimeBackup = string.format( "%2d.%2d", mn, sc)
+ else
+ mDeltaTimeBackup = string.format( "%s%2d ", c, mn)
+ end
+
+ elseif mn > 0 and mn < 10 then
+ -- < 10mn
+ if c == "" then
+ mDeltaTimeBackup = string.format( "%1d.%02d.%01d", mn, sc, hd)
+ else
+ mDeltaTimeBackup = string.format( "%s%1d.%02d", c, mn, sc)
+ end
+
+ else
+ -- sc > 9
+ if sc > 9 then
+ if c == "" then
+ mDeltaTimeBackup = string.format( "0.%2d.%1d", sc, hd)
+ else
+ mDeltaTimeBackup = string.format( "%s%02d.%01d", c, sc, hd)
+ end
+
+ else
+ -- sc < 0
+ if c == "" then
+ mDeltaTimeBackup = string.format( "0.%01d.%02d", sc, hd)
+ else
+ mDeltaTimeBackup = string.format( "%s%01d.%02d", c, sc, hd)
+ end
+
+ end
+ end
+ end
+
+ --print(srf1Panel,mDeltaTimeBackup)
+ srf1Panel = mDeltaTimeBackup
+ end
+
+ if isSlowUpdate then
+
+ if GetTicks() > ( refreshRate + mDeltaTimeOldTicks ) then
+ mDeltaTimeOldTicks = GetTicks()
+ if side == 0 then
+ mSRF1LeftText = srf1Panel
+ else
+ mSRF1RightText = srf1Panel
+ end
+ -- print(GetTicks() .. mSRF1RightText .."\n")
+ end
+ else
+ if side == 0 then
+ mSRF1LeftText = srf1Panel
+ else
+ mSRF1RightText = srf1Panel
+ end
+ end
+
+ -- print(mSRF1LeftText, mSRF1RightText, srf1Panel)
+ -- send string to sli manager
+ if side == 0 then
+ SetLeftDigits( mSRF1LeftText )
+ else
+ SetRightDigits( mSRF1RightText )
+ end
+
+ return 1
+end