Logitech G27 Racing Wheel for Node

June 2, 2015

Do you have a Logitech G27 Racing Wheel and Node? Well you my friend are in for a treat because now you can easily...

...with the just released npm module logitech-g27. Also available on GitHub. Improvements welcome.

Playing Footsie with iTunes

Using iTunes with my feet was becoming a hassle. The keyboard buttons were just too small to press reliably and worst of all, my hands were always in the way. There had to be a better way.

Of course! Use the G27 foot pedals with my hands to control iTunes!


//----------
// Includes
//----------
var g = require('logitech-g27')
var itunes = require('playback')

//-----------
// Variables
//-----------
var recently = {} // will keep track of what commands have been done too recently

//-----------
// Functions
//-----------
function itunesOnce(cmd) {
    if (!recently.hasOwnProperty(cmd)) {
        recently[cmd] = false
    }

    if (recently[cmd] === false) {
        recently[cmd] = true
        itunes[cmd](null)
        setTimeout(function() {
            // wait two seconds then free up this command type to be called again
            recently[cmd] = false
        }, 2000)
    }
}

//--------
// Pedals
//--------
g.on('pedals-gas', function(val) {
    if (val >= 0.9) {
        itunesOnce('next')
    } else if (val >= 0.3 && val < 0.9) {
        itunesOnce('play')
    }
})

g.on('pedals-brake', function(val) {
    if (val >= 0.6) {
        itunesOnce('pause')
    }
})

g.on('pedals-clutch', function(val) {
    if (val > 0.9) {
        itunesOnce('previous')
    }
})

//---------
// Connect
//---------
g.connect(function(err) {
    console.log('Toe-riffic!')
})

A little gas to play or floor it to go to the next song. Brake to pause. Clutch to go to the previous song. Neat. ^_^

Epilogue

I sincerely hope other people get a kick out of this software and make their own unique creations with it.

Feel free to share your ideas, code, issues and/or comments below.

Cheers!