Page 1 of 1

LUA Script for remote start/stop and status led

Posted: Mon Oct 21, 2013 3:32 pm
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?

Posted: Mon Nov 11, 2013 10:36 pm
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() 
    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

Posted: Mon Nov 11, 2013 10:51 pm
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

Posted: Wed Nov 13, 2013 5:15 am
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!

Posted: Wed Nov 13, 2013 10:33 am
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.

Posted: Thu Nov 14, 2013 1:19 am
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/