LUA Script for remote start/stop and status led

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
neoraptor
Posts: 43
Joined: Thu May 16, 2013 3:08 pm
Location: Alsace, France

LUA Script for remote start/stop and status led

Post by neoraptor »

Hello,
The unit is mounted under my seat, and it is actually quite annoying to open it to start the logging before each session.

In order to improve that, I would like to have :
* a remote LED to see whether the unit is logging or not
* a button to start/stop the logging manually (GPS script does not seems to work, and I can't see the logging status)

So which functions should I use to switch an output and to read an input?
Is there already a script defined?

redparchel
Posts: 22
Joined: Fri Nov 01, 2013 9:48 pm
Location: Bay Area, CA

Post by redparchel »

I don't have my RCP yet but I was hoping to do something similar looking at the lua guide and some examples I THINK you should be able to hook up a switch to one of the digital inputs and an LED to one of the digital outputs with proper voltage to each and do something like this in lua:

Code: Select all

function onTick&#40;&#41; 
    if getGpio&#40; <switch channel> &#41; > 0 then 
        startLogging&#40;&#41; 
        setGpio&#40; <LED channel>, 1 &#41;
    else
        stopLogging&#40;&#41;
        setGpio&#40; <LED channel>, 0 &#41;
    end 
end


If that works you can do other things things (Assuming you got the gps part to work) log if the switch is on or if going above 10 mph:

Code: Select all

function onTick&#40;&#41; 
    if getGpio&#40; <switch channel> &#41; > 0 or getGpsSpeed&#40;&#41; > 10  then 
        startLogging&#40;&#41; 
        setGpio&#40; <LED channel>, 1 &#41;
    else
        stopLogging&#40;&#41;
        setGpio&#40; <LED channel>, 0 &#41;
    end 
end
or log if you're above 10mph AND the switch is on

Code: Select all

function onTick&#40;&#41; 
    if getGpio&#40; <switch channel> &#41; > 0 and getGpsSpeed&#40;&#41; > 10  then 
        startLogging&#40;&#41; 
        setGpio&#40; <LED channel>, 1 &#41;
    else
        stopLogging&#40;&#41;
        setGpio&#40; <LED channel>, 0 &#41;
    end 
end
I'll test these once my RCP arrives, I only verified the lua syntax using http://doris.sourceforge.net/lua/weblua.php

Another option is to use one of the analog inputs and a resistor ladder to be able to use more than one switch and only one input.


EDIT: updated examples as this version of Lua doesnt want to support "greater than or equal to" operators
Last edited by redparchel on Wed Nov 13, 2013 6:06 am, edited 1 time in total.

redparchel
Posts: 22
Joined: Fri Nov 01, 2013 9:48 pm
Location: Bay Area, CA

Post by redparchel »

While looking at this and the lua guide for RCP I wish there was a isLogging() or getLogging() that would return whether the system was logging or not .. this could be used like the below to show logging status or errors on a remote LED

Code: Select all

function onTick&#40;&#41; 
    if getLogging > 0 then  
        setGpio&#40; <LED channel>, 1 &#41; 
    else 
        setGpio&#40; <LED channel>, 0 &#41; 
    end 
end

then again you're probably not going to "pull over" on the track to fix it mid race, but you or a co-driver could try flipping the switch again to see if it starts logging again

sorry for the thread jack

EDIT: updated examples as this version of Lua doesnt want to support "greater than or equal to" operators
Last edited by redparchel on Wed Nov 13, 2013 6:07 am, edited 2 times in total.

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

Post by brentp »

if you're concerned whether the system is logging or not, you could use the bluetooth connected dash as an indicator - if the data is not updating, then you will know!
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

neoraptor
Posts: 43
Joined: Thu May 16, 2013 3:08 pm
Location: Alsace, France

Post by neoraptor »

Thank you redparchel for the scripts. I will look to make it work.
I also consider start logging wenn the unit is powered, as I only start the motor 2 minutes before going to the track.

@Brent: this is a good idea, but on my motorcycle it is difficult to put a smartphone or a tablet.

redparchel
Posts: 22
Joined: Fri Nov 01, 2013 9:48 pm
Location: Bay Area, CA

Post by redparchel »

neoraptor wrote:Thank you redparchel for the scripts. I will look to make it work.
sure thing! hope something works for ya
neoraptor wrote:@Brent: this is a good idea, but on my motorcycle it is difficult to put a smartphone or a tablet.
I think there may be a solution to that problem :wink: that autosportslabs just posted on their Facebook page (bretp do you manage that page?) http://www.autoblog.com/2013/10/23/skul ... met-video/

Post Reply