Skip to content

Instantly share code, notes, and snippets.

@clofresh
Created January 20, 2014 22:59

Revisions

  1. clofresh created this gist Jan 20, 2014.
    77 changes: 77 additions & 0 deletions main.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,77 @@
    -- Love debugging app for discovering joysticks
    --

    pressed = {}

    function love.draw()
    local x = 100
    local y = 100
    local dx = 12
    local joysticks = love.joystick.getJoysticks()
    for i, joystick in pairs(joysticks) do
    local id, instanceid = joystick:getID()
    love.graphics.print(joystick:getName() .. '(' .. joystick:getGUID() .. ':' .. instanceid .. ')', x, y)
    y = y + dx

    local isGamepad = joystick:isGamepad()
    if isGamepad then
    love.graphics.print("isGamepad? true", x, y)
    else
    love.graphics.print("isGamepad? false", x, y)
    end
    y = y + dx

    local supportsVibration = joystick:isVibrationSupported()
    if supportsVibration then
    love.graphics.print("isVibrationSupported? true", x, y)
    else
    love.graphics.print("isVibrationSupported? false", x, y)
    end
    y = y + dx

    local numAxes = joystick:getAxisCount()
    for axis = 1, numAxes do
    local direction = joystick:getAxis(axis)
    love.graphics.print('axis ' .. axis .. ': ' .. direction, x, y)
    y = y + dx
    end

    local numHats = joystick:getHatCount()
    for hat = 1, numHats do
    local direction = joystick:getHat(hat)
    love.graphics.print('hat ' .. hat .. ': ' .. direction, x, y)
    y = y + dx
    end

    local buttons = pressed[instanceid]
    if buttons then
    for button, isPressed in pairs(buttons) do
    local isPressedStr
    if isPressed then
    isPressedStr = 'pressed'
    else
    isPressedStr = 'unpressed'
    end
    love.graphics.print('button ' .. button .. ': ' .. isPressedStr, x, y)
    y = y + dx
    end
    end
    y = y + dx
    end
    end

    function love.joystickpressed(joystick, button)
    local id, instanceid = joystick:getID()
    if pressed[instanceid] then
    pressed[instanceid][button] = true
    else
    pressed[instanceid] = {[button] = true}
    end
    end

    function love.joystickreleased(joystick, button)
    local id, instanceid = joystick:getID()
    if pressed[instanceid] then
    pressed[instanceid][button] = false
    end
    end