Skip to content

Instantly share code, notes, and snippets.

@werpu
Created February 16, 2020 10:57
Show Gist options
  • Save werpu/1735c39fd3970b9ae041eb6f897e520f to your computer and use it in GitHub Desktop.
Save werpu/1735c39fd3970b9ae041eb6f897e520f to your computer and use it in GitHub Desktop.
/* MIT License
#
# Copyright (c) 2019 Werner Punz
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
######################################################################
# device definitions
#######################################################################
*/
#parse("macros.vm")
{
/**
* Input devices
*/
inputs: {
/*second match after the first, responsible for delivering
the mouse signals, unfortunately same name*/
#input_def_phys( "trackball_paddle_y" "usb-0000:01:00.0-1.1.2/input1" "true" "1"),
#input_def( "digital" "Ultimarc I-PAC Ultimarc I-PAC" "true" "1"),
#input_def_mm_re( "analog_left" "^Ultimarc.*Ultra-Stik\\\\s+Player\\\\s+1$" "true" "1" "0" "255" "18"),
#input_def_re( "analog_right" "^Ultimarc.*Ultra-Stik\\\\s+Player\\\\s+2$" "true" "1")
},
/**
* output device definitions
*/
outputs: {
#output_def( "xbox2" "Microsoft X-Box 360 pad" "xbx360"),
/**
* register an execution driver for external script execution of shell scripts
*/
#output_def( "exec1" "Execution Driver" "exec"),
/**
* register an eval driver for python plugin execution
*/
#output_def( "eval1" "Evaluation Driver" "eval"),
/**
* Register a serial line uart communications driver to our first
* external board
*/
#output_def_meta( "serial0" "Serial Line 0 (first external joystick)" "serial" "/dev/serial0")
},
rules: [
{
from: "trackball_paddle_y",
target_rules: [
#mapping( "(EV_REL), code 0 (REL_X)" "serial0" "(EV_REL), code 0 (REL_X)" ),
#mapping( "(EV_REL), code 1 (REL_Y)" "serial0" "(EV_REL), code 1 (REL_Y)" )
]
},
{
from: "digital",
/*
* First set of rules mapping for the simulated pad
*/
target_rules: [
/*
* HAT controls top bottom, left, right
*/
#mapping( "(EV_KEY), code 103 (KEY_UP)" "serial0" "(EV_ABS), code 17 (ABS_HAT0Y), value -1" ),
//key down left digital
#mapping( "(EV_KEY), code 108 (KEY_DOWN)" "serial0" "(EV_ABS), code 17 (ABS_HAT0Y), value 1" ),
//left left stick digital
#mapping( "(EV_KEY), code 105 (KEY_LEFT)" "serial0" "(EV_ABS), code 16 (ABS_HAT0X), value -1" ),
//right left stick digital
#mapping( "(EV_KEY), code 106 (KEY_RIGHT)" "serial0" "(EV_ABS), code 16 (ABS_HAT0X), value 1" ),
//BTN A - auto frequency mapping for periodical trigger
#af_mapping( "(EV_KEY), code 29 (KEY_LEFTCTRL)" "serial0" "(EV_KEY), code 304 (BTN_SOUTH)" "1" "200" ),
//BTN B
#mapping( "(EV_KEY), code 56 (KEY_LEFTALT)" "serial0" "(EV_KEY), code 305 (BTN_EAST)" ),
//BTN X
#mapping( "(EV_KEY), code 57 (KEY_SPAVE)" "serial0" "(EV_KEY), code 307 (BTN_NORTH)" ),
//BTN Y
#mapping( "(EV_KEY), code 42 (KEY_LEFTSHIFT)" "serial0" "(EV_KEY), code 308 (BTN_WEST)" ),
//BTN L
#mapping( "(EV_KEY), code 44 (KEY_Z)" "serial0" "(EV_KEY), code 310 (BTN_TL)" ),
//BTN R
#mapping( "(EV_KEY), code 45 (KEY_X)" "serial0" "(EV_KEY), code 311 (BTN_TR)" ),
//BTN TL
#mapping( "(EV_KEY), code 47 (KEY_V)" "serial0" "(EV_KEY), code 312 (BTN_TL2)" ),
//BTN TR
#mapping( "(EV_KEY), code 25 (KEY_P)" "serial0" "(EV_KEY), code 313 (BTN_TR2)" ),
//THUMB LEFT
#mapping( "(EV_KEY), code 46 (KEY_C)" "serial0" "(EV_KEY), code 317 (BTN_THUMBL)" ),
//THUMB RIGHT
#mapping( "(EV_KEY), code 15 (KEY_TAB)" "serial0" "(EV_KEY), code 318 (BTN_THUMBR)" ),
//SELECT
#mapping( "(EV_KEY), code 6 (KEY_5)" "serial0" "(EV_KEY), code 314 (BTN_SELECT)" ),
//START
#mapping( "(EV_KEY), code 2 (KEY_1)" "serial0" "(EV_KEY), code 315 (BTN_START)" ),
//MODE XBOX BUTTON
{
from_ev: "(EV_KEY), code 102 (KEY_HOME)",
targets: [
#output("xbox2" "(EV_KEY), code 316 (BTN_MODE)"),
#output("serial0" "(EV_KEY), code 316 (BTN_MODE)")
]
}
]
},
//ANALOG STICK
{
from: "analog_left",
target_rules: [
#forward( "(EV_ABS), code 1 (ABS_Y)" "serial0"),
#forward( "(EV_ABS), code 0 (ABS_X)" "serial0"),
]
},
//ANALOG STICK RIGHT
{
from: "analog_right",
target_rules: [
{
from_ev: "(EV_ABS), code 1 (ABS_Y)",
targets: [
#output("xbox2" "(EV_ABS), code 1 (ABS_Y)"),
#output("serial0" "(EV_ABS), code 4 (ABS_RY)")
]
},
{
from_ev: "(EV_ABS), code 0 (ABS_X)",
targets: [
#output("xbox2" "(EV_ABS), code 0 (ABS_X)"),
#output("serial0" "(EV_ABS), code 3 (ABS_RX)")
]
},
//front orange button left -> 4 way switch
#mapping( "(EV_KEY), code 292 (BTN_TOP2)" "exec1" "(META), /home/pi/jstools/4way.sh" ),
//front orange button left -> 8 way switch
#mapping( "(EV_KEY), code 291 (BTN_TOP1)" "exec1" "(META), /home/pi/jstools/8way.sh" ),
//button front right -> special key
{
from_ev: "(EV_KEY), code 290 (BTN_THUMB2)",
targets: [
{
to: "eval1",
to_ev: "(META), /home/werpu/gamepadservice/burping.py"
//burp sound
}
]
},
{
from_ev: "(EV_KEY), code 293 (BTN_PINKIE)",
targets: [
{
to: "eval1",
to_ev: "(META), /home/werpu/gamepadservice/florence.py"
//on screen keyboard toggle
}
]
}
]
},
{
//digital pad2 definition (right digital)
from: "digital",
target_rules: [
{
from_ev: "(EV_KEY), code 32 (KEY_D)",
targets: [
{
to: "xbox2",
to_ev: "(EV_ABS), code 17 (ABS_HAT0Y), value -1"
}
]
},
{
from_ev: "(EV_KEY), code 33 (KEY_F)",
targets: [
{
to: "xbox2",
to_ev: "(EV_ABS), code 17 (ABS_HAT0Y), value 1"
}
]
},
{
from_ev: "(EV_KEY), code 34 (KEY_G)",
targets: [
{
to: "xbox2",
to_ev: "(EV_ABS), code 16 (ABS_HAT0X), value -1"
}
]
},
{
from_ev: "(EV_KEY), code 19 (KEY_R)",
targets: [
{
to: "xbox2",
to_ev: "(EV_ABS), code 16 (ABS_HAT0X), value 1"
}
]
},
{
from_ev: "(EV_KEY), code 31 (KEY_S)",
targets: [
{
to: "xbox2",
to_ev: "(EV_KEY), code 304 (BTN_SOUTH)"
}
]
},
// btn A
{
from_ev: "(EV_KEY), code 30 (KEY_A)",
targets: [
{
to: "xbox2",
to_ev: "(EV_KEY), code 305 (BTN_EAST)"
}
]
},
// B
{
from_ev: "(EV_KEY), code 16 (KEY_Q)",
targets: [
{
to: "xbox2",
to_ev: "(EV_KEY), code 307 (BTN_NORTH)"
}
]
},
// X
{
from_ev: "(EV_KEY), code 17 (KEY_W)",
targets: [
{
to: "xbox2",
to_ev: "(EV_KEY), code 308 (BTN_WEST)"
}
]
},
// Y
{
from_ev: "(EV_KEY), code 37 (KEY_K)",
targets: [
{
to: "xbox2",
to_ev: "(EV_KEY), code 310 (BTN_TL)"
}
]
},
// L
{
from_ev: "(EV_KEY), code 23 (KEY_I)",
targets: [
{
to: "xbox2",
to_ev: "(EV_KEY), code 311 (BTN_TR)"
}
]
},
// R
{
from_ev: "(EV_KEY), code 36 (KEY_J)",
targets: [
{
to: "xbox2",
to_ev: "(EV_KEY), code 312 (BTN_TL2)"
}
]
},
// LT
{
from_ev: "(EV_KEY), code 38 (KEY_L)",
targets: [
{
to: "xbox2",
to_ev: "(EV_KEY), code 313 (BTN_TR2)"
}
]
},
// RT
{
from_ev: "(EV_KEY), code 15 (KEY_TAB)",
targets: [
{
to: "xbox2",
to_ev: "(EV_KEY), code 317 (BTN_THUMBL)"
}
]
},
// select
{
from_ev: "(EV_KEY), code 7 (KEY_6)",
targets: [
{
to: "xbox2",
to_ev: "(EV_KEY), code 314 (BTN_SELECT)"
}
]
},
// start
{
from_ev: "(EV_KEY), code 3 (KEY_2)",
targets: [
{
to: "xbox2",
to_ev: "(EV_KEY), code 315 (BTN_START)"
}
]
},
// select 1 + start 2 => alt f4
{
from_ev: "(EV_KEY), code 56 (KEY_LEFTALT)",
//alt f4
targets: [
{
to: "serial0",
to_ev: "(EV_KEY), code 56 (KEY_LEFTALT)"
}
]
},
// player2 home -> f4
{
from_ev: "(EV_KEY), code 62 (KEY_F4)",
targets: [
{
to: "serial0",
to_ev: "(EV_KEY), code 62 (KEY_F4)"
}
]
}
]
},
//mouse left (button left 2
{
from: "analog_left",
target_rules: [
{
from_ev: "(EV_KEY), code 288 (BTN_TRIGGER)",
targets: [
{
to: "serial0",
to_ev: "(EV_KEY), code 272 (BTN_LEFT)"
}
]
},
//mouse right (button left 1)
{
from_ev: "(EV_KEY), code 289 (BTN_THUMB)",
targets: [
{
to: "serial0",
to_ev: "(EV_KEY), code 273 (BTN_RIGHT)"
}
]
},
{
from_ev: "(EV_KEY), code 290 (BTN_THUMB2)",
targets: [
{
to: "serial0",
to_ev: "(EV_KEY), code 2 (KEY_1)"
}
]
},
{
from_ev: "(EV_KEY), code 291 (BTN_TOP)",
targets: [
{
to: "serial0",
to_ev: "(EV_KEY), code 3 (KEY_2)"
}
]
},
{
from_ev: "(EV_KEY), code 292 (BTN_TOP2)",
targets: [
{
to: "serial0",
to_ev: "(EV_KEY), code 4 (KEY_3)"
}
]
},
{
from_ev: "(EV_KEY), code 293 (BTN_PINKIE)",
targets: [
{
to: "serial0",
to_ev: "(EV_KEY), code 5 (KEY_4)"
}
]
},
{
from_ev: "(EV_KEY), code 294 (BTN_BASE)",
targets: [
{
to: "serial0",
to_ev: "(EV_KEY), code 6 (KEY_5)"
}
]
},
{
from_ev: "(EV_KEY), code 295 (BTN_BASE2)",
targets: [
{
to: "serial0",
to_ev: "(EV_KEY), code 7 (KEY_6)"
}
]
},
{
from_ev: "(EV_KEY), code 295 (BTN_BASE2)",
targets: [
{
to: "serial0",
to_ev: "(EV_KEY), code 8 (KEY_7)"
}
]
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment