Making Shift lights flash on shiftx

Discussion on the Lua Scripting capabilities for RaceCapture/Pro. Also see the <a href="http://autosportlabs.net/RaceCapturePro_Lua_Scripting">Lua Scripting Guide</a>

Moderators: JeffC, stieg

Post Reply
Ash-b-84
Posts: 14
Joined: Fri Aug 28, 2015 12:58 pm

Making Shift lights flash on shiftx

Post by Ash-b-84 »

How to make all shift lights flash on my shift x or when max rpm is reached if somone could supply a script I can add into my existing one that would be great

stieg
Posts: 100
Joined: Fri Dec 20, 2013 1:37 am
Location: Madison, WI
Contact:

Post by stieg »

Here is a script I wrote a while back. It uses the 3 PWM outputs on the RCP unit to control the lights instead of the GPIO units. You will need to adjust your RPM values accordingly.

Code: Select all

--&#91;&#91;
Inputs as wired on 2014-12-05 -- Stieg

Input
Timer 0 - RPM

Tach Lights
0 - Green Light
1 - Yellow Light
2 - Red Light

&#93;&#93;


-- Globals --
LIGHTS = 3
LIGHT_VALS = &#123;&#125;
FREQUENCY_HZ = 25

-- Global Init --
setTickRate&#40;FREQUENCY_HZ&#41;

function toggleLight&#40;index&#41;
   LIGHT_VALS&#91;index&#93; = not LIGHT_VALS&#91;index&#93;
end

function lightOn&#40;index&#41;
   LIGHT_VALS&#91;index&#93; = true
end

function lightOff&#40;index&#41;
   LIGHT_VALS&#91;index&#93; = false
end

local lCount = 0
repeat
   lightOff&#40;lCount&#41;
   lCount = lCount + 1
until lCount >= LIGHTS

-- Script --
function updateLights&#40;&#41;
   local l = 0
   repeat
      -- Convert our booleans to 1 &#40;true&#41; or 0 &#40;false&#41; --
      local val = LIGHT_VALS&#91;l&#93;
      local dc = 0
      if not val then
         dc = 100
      end
      setPwmDutyCycle&#40;l, dc&#41;

      l = l + 1
   until l >= LIGHTS
end

function checkRpm&#40;&#41;
   local rpm = getTimerRpm&#40;0&#41;
   if rpm < 3000 then
        lightOff&#40;0&#41;
        lightOff&#40;1&#41;
        lightOff&#40;2&#41;
   elseif 3000 < rpm and rpm < 4500 then
	lightOn&#40;0&#41;
        lightOff&#40;1&#41;
        lightOff&#40;2&#41;
   elseif 4500 < rpm and rpm < 5000 then
        lightOn&#40;0&#41;
        lightOn&#40;1&#41;
        lightOff&#40;2&#41;
   elseif 5000 < rpm and rpm < 5500 then
        lightOn&#40;0&#41;
        lightOn&#40;1&#41;
        lightOn&#40;2&#41;
   else
        toggleLight&#40;0&#41;
        toggleLight&#40;1&#41;
        toggleLight&#40;2&#41;
   end
end


function controlLights&#40;&#41;
   checkRpm&#40;&#41;
   updateLights&#40;&#41;
end

-- Start!

function onTick&#40;&#41;
   controlLights&#40;&#41;
end
[/code]
Andrew Stiegmann (Stieg)
Principal Engineer
Autosport Labs Inc.

Ash-b-84
Posts: 14
Joined: Fri Aug 28, 2015 12:58 pm

Post by Ash-b-84 »

I use the gpio so my current one looks like this

Code:

setTickRate(15) --15Hz

--Shift Now!!!!
function onTick()
rpm=getTimerRpm(2) --read RPM

--activate LEDs
if rpm > 8000 then return end --this filters out RPM spikes
if rpm > 6600 then setGpio(2,1) else setGpio(2,0) end
if rpm > 7000 then setGpio(1,1) else setGpio(1,0) end
if rpm > 7400 then setGpio(0,1) else setGpio(0,0) end
end

Ash-b-84
Posts: 14
Joined: Fri Aug 28, 2015 12:58 pm

Post by Ash-b-84 »

Could I ad in a line

If rpm > 7400 toggle Gpio (2,1) (1,1) (0,1) end

stieg
Posts: 100
Joined: Fri Dec 20, 2013 1:37 am
Location: Madison, WI
Contact:

Post by stieg »

Code: Select all

If rpm > 7400 toggle Gpio &#40;2,1&#41; &#40;1,1&#41; &#40;0,1&#41; end
I don't believe that is valid Lua. If you broke it up into 3 calls, then yes. Feel free to use this script.
Andrew Stiegmann (Stieg)
Principal Engineer
Autosport Labs Inc.

Ash-b-84
Posts: 14
Joined: Fri Aug 28, 2015 12:58 pm

Post by Ash-b-84 »

What is meant by 3 calls I am a complete novice

stieg
Posts: 100
Joined: Fri Dec 20, 2013 1:37 am
Location: Madison, WI
Contact:

Post by stieg »

What is meant by 3 calls I am a complete novice
If you intend to edit the scripts then it would be wise to jump into Lua a bit first to get an idea of what is happening. Here is a free tutorial provided by the folks who wrote LUA: https://www.lua.org/pil/contents.html#1. I would suggest you merely adjust the numbers in the checkRpm function in the script provided rather than try to add to it. Trying to jump straight in and do larger edits without experience will lead to lots of frustration, and that is no fun.
Andrew Stiegmann (Stieg)
Principal Engineer
Autosport Labs Inc.

Post Reply