Multiplexed ShiftX lights

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
paulbutcher
Posts: 42
Joined: Sat Dec 20, 2014 1:48 pm
Location: UK
Contact:

Multiplexed ShiftX lights

Post by paulbutcher »

This weekend I've been testing a script which multiplexes the ShiftX so that it operates as both shift lights and an error light.

If there's an error condition (temperature too high or oil pressure too low), only the central red light is illuminated. If there's no error condition, it operates as shift lights.

Here's the script:

Code: Select all

FREQUENCY_HZ = 10
RPM_THRESHOLDS = &#123;12000, 12300, 12500&#125;
MAX_OIL_TEMP = 100
MAX_WATER_TEMP = 100
MIN_OIL_PRESSURE_LOW_REVS = 5
MIN_OIL_PRESSURE_HIGH_REVS = 10
LOW_REVS = 3000

setTickRate&#40;FREQUENCY_HZ&#41; 

function lightOn&#40;light, on&#41;
  if on then
    setPwmDutyCycle&#40;light, 0&#41;
  else
    setPwmDutyCycle&#40;light, 100&#41;
  end
end

function updateShiftLights&#40;&#41;
  local rpm = getTimerRpm&#40;0&#41;
  lightOn&#40;0, rpm > RPM_THRESHOLDS&#91;1&#93;&#41;
  lightOn&#40;1, rpm > RPM_THRESHOLDS&#91;2&#93;&#41;
  lightOn&#40;2, rpm > RPM_THRESHOLDS&#91;3&#93;&#41;
end

function oilTempError&#40;&#41;
  return getAnalog&#40;0&#41; > MAX_OIL_TEMP
end

function waterTempError&#40;&#41;
  return getAnalog&#40;1&#41; > MAX_WATER_TEMP
end

function oilPressureError&#40;&#41;
  local oilp = getAnalog&#40;2&#41;
  if getTimerRpm&#40;0&#41; < LOW_REVS then
    return oilp < MIN_OIL_PRESSURE_LOW_REVS
  else
    return oilp < MIN_OIL_PRESSURE_HIGH_REVS
  end
end

function errorCondition&#40;&#41;
  return oilTempError&#40;&#41; or waterTempError&#40;&#41; or oilPressureError&#40;&#41;
end

function displayError&#40;&#41;
  lightOn&#40;0, false&#41;
  lightOn&#40;1, false&#41;
  lightOn&#40;2, true&#41;
end

function onTick&#40;&#41;
  if getGpsSpeed&#40;&#41; > 10 then
    startLogging&#40;&#41;
  end

  if errorCondition&#40;&#41; then
    displayError&#40;&#41;
  else
    updateShiftLights&#40;&#41;
  end
end
paul.butcher->msgCount++

Silverstone, Brands Hatch, Donington Park...
Who says I have a one track mind?

http://www.paulbutcher.com/

Author of Seven Concurrency Models in Seven Weeks: When Threads Unravel
http://pragprog.com/book/pb7con

brentp
Site Admin
Posts: 5986
Joined: Wed Jan 24, 2007 6:36 am

Post by brentp »

This is great. mind if we put it in the wiki?
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

paulbutcher
Posts: 42
Joined: Sat Dec 20, 2014 1:48 pm
Location: UK
Contact:

Post by paulbutcher »

brentp wrote:This is great. mind if we put it in the wiki?
Of course not - feel free!
paul.butcher->msgCount++

Silverstone, Brands Hatch, Donington Park...
Who says I have a one track mind?

http://www.paulbutcher.com/

Author of Seven Concurrency Models in Seven Weeks: When Threads Unravel
http://pragprog.com/book/pb7con

Post Reply