Input Tutorial

The dashboard has two user-switch inputs. One is dedicated (at least for now) to the next-page function, but the other (we'll call it u1 here) has no fixed function. We can use the [GLOBAL] INPUT option to define what it does. Being a global option, the u1 input will behave the same regardless of which dashboard page you're on.

Limitations: some of the things described here may not be available to you if you have other devices sharing the CAN bus. The simpler example should still be possible.

Log File Marker

The original reason for including the u1 input was to allow the user to mark a particular moment in the log file. You might want to mark just after a hesitation occurred, or just before you start a particular run. Having a magic value to search for can save time hunting in the log file.

Digital Input

The Megasquirt supports many different inputs via CAN. If you need just one the dashboard's u1 input might be all you need. You could even sneak a second using the lights input, but that's getting towards hackery.

Here, we'll use it to configure u1 as a launch control trigger, including showing the launch control status on a simple dashboard.

Firstly, a rundown on what launch control does:

  1. User holds down button
  2. Megasquirt detects button is pressed and sees that it is configured as the launch control trigger
  3. Megasquirt checks throttle position and, if it is more than was configured when setting up launch control, it takes action to limit the revs. While it does this, it sets a status flag.

In this example, the dashboard will display engine revs, throttle position, whether the launch control button is pressed, and whether the Megasquirt has engaged launch control, and we'll do it for the Microsquirt with 3.4.4 firmware.

Two things need to be looked up in the Megasquirt INI file:

  1. The input port where the button press will be flagged
  2. The status bit where the Megasquirt indicates that launch control is active.

The INI file contains a huge amount of information, but it can be very difficult finding the piece of information you want.

The input port is easy enough. We'll use gpioport2 and, as mentioned, the dashboard always maps the button to bit 0. That's all indicated in the INPUT line, though obviously the Megasquirt must also be configured to expect this.

The status bit is a challenge. If you look through the [FrontPage] section of the INI file you'll see the line:

   indicator = { status2 & 8}, "Launch", "Launch", white, black, green, black

That defines the rectangular Launch indicator in TunerStudio. The box lights up in green when bit 3 (2^3 = 8) of status2 is 1. That's what we needed to know.

Here is a configuration which gets that done:

[global]
;
; Megasquirt INI file -- Microsquirt
;
SIG "MS2Extra comms342hU"

;
; INPUT channel mask
;
INPUT gpioport2 255

[+DLIST]
pre {
        call blackbg
        fg base[1]
        movea 17 147 text "TPS"
}
butdown {
        fg bgr[3] jmp butind
}
butup {
        fg base jmp butind
}
butind {
        move 90 7 rrectfill 20 25
}
launchon {
        bg ogo[2] fg ogo[0] call launchind
        move 13 6 text "Launch"
}
launchoff {
        bg base jmp launchind
}
launchind {
        move 0 5
        rrectfillbg 100 30
}
[PAGE]
main {
        dlist pre none none
        ;
        ; Backlight duty day/night in [0:100]
        ; blduty 100 30
        blduty 100 20
        ;
        ; Things to get from the Megasquirt
	;
        poll
        {
                rpm {method=last round=100}
                status2 {name=flags method=last}
                tps {method=last round=1}
                gpioport2 {name=input method=last}
        }
	;
	; How they are to be displayed
	;
        show
        {
                ;
                ; Slots [0:15] arranged in 8 rows and 2 columns.
                ; slot type {[name=val pairs]}
                ;
                2 BLANK {float=25}
                3 SEG7 {
                        var=rpm low=3500 high=6500 cmap=base
                        inv=0 egval=2800
                }
                6 BOOLEAN {
                        var=input mask=1
                        ifhigh=butup
                        iflow=butdown
                        egval=0
                }
                7 BOOLEAN {
                        var=flags mask=8
                        ifhigh=launchon
                        iflow=launchoff
                        egval=8
                }
                8 LEDBAR {
                        var=tps low=1 high=99
                        n4=10 cmap=base
                        egval=70
                }
        }
}

The highlighted lines are the things that are specially related to the mission here. The INPUT line says where to write the button status. We could equally have used a mask value of 1. With the mask of 255 light on/off events and dashboard page events will appear in other bits in gpioport2

The two highlighted lines in the poll block show where we retrieve the values from the Megasquirt. Not only do we know that the button is pressed, but the fact we read it back from the Megasquirt means we know it knows it too.

The final highlighted line shows the use of the mask=8 value we got from the INI file for the launch control active bit.

The rest of the file is straightforward dashboard stuff. There are quite a few display lists there, but they're pretty simple: butdown and butup just set a foreground colour and hand over to butind which draws the button state indicator in that colour. It's much the same with launchon, launchoff and launchind except launchon prints "Launch" on the indicator.

Getting the bit meanings correct can be tricky. The two we are looking at here have opposite senses. The button is active when the bit is low. That matches the iflow case. Conversely, the Megasquirt sets the status bit high when launch control is active, matching the ifhigh case.

Here is how the dashboard looks when the button isn't being pressed:

Here it is with the button pressed, but the throttle not open enough for the Megasquirt to start speed limiting. The red light tells you the Megasquirt sees that the button is down.

And here is how it looks when you open the throttle while still pressing the button:

The green "Launch" light indicates that the Megasquirt is going to limit revs as configured.