Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.03 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. # This file is part of The RetroPie Project
  4. #
  5. # The RetroPie Project is the legal property of its developers, whose names are
  6. # too numerous to list here. Please refer to the COPYRIGHT.md file distributed with this source.
  7. #
  8. # See the LICENSE.md file at the top-level directory of this distribution and
  9. # at https://raw.githubusercontent.com/RetroPie/RetroPie-Setup/master/LICENSE.md
  10. #
  11.  
  12. function onstart_emulationstation_joystick() {
  13. local es_conf="$home/.emulationstation/es_input.cfg"
  14.  
  15. mkdir -p "$home/.emulationstation"
  16.  
  17. if [[ ! -f "$es_conf" ]]; then
  18. echo "<inputList />" >"$es_conf"
  19. else
  20. cp "$es_conf" "$es_conf.bak"
  21. fi
  22.  
  23. # look for existing inputConfig in config by GUID
  24. if [[ $(xmlstarlet sel -t -v "count(/inputList/inputConfig[@deviceGUID=\"$DEVICE_GUID\"])" "$es_conf") -eq 0 ]]; then
  25. # if not found by GUID, look for inputConfig with deviceName only
  26. if [[ $(xmlstarlet sel -t -v "count(/inputList/inputConfig[@deviceName=\"$DEVICE_NAME\"][not(@deviceGUID)])" "$es_conf") -eq 0 ]]; then
  27. # insert new inputConfig entry
  28. xmlstarlet ed -L -s "/inputList" -t elem -n newInputConfig -v "" \
  29. -i //newInputConfig -t attr -n "type" -v "$DEVICE_TYPE" \
  30. -i //newInputConfig -t attr -n "deviceName" -v "$DEVICE_NAME" \
  31. -i //newInputConfig -t attr -n "deviceGUID" -v "$DEVICE_GUID" \
  32. -r //newInputConfig -v inputConfig \
  33. "$es_conf"
  34. else
  35. # add deviceGUID to inputConfig
  36. xmlstarlet ed -L \
  37. -i "/inputList/inputConfig[@deviceName=\"$DEVICE_NAME\"]" -t attr -n "deviceGUID" -v "$DEVICE_GUID" \
  38. "$es_conf"
  39. fi
  40. fi
  41. }
  42.  
  43. function map_emulationstation_joystick() {
  44. local input_name="$1"
  45. local input_type="$2"
  46. local input_id="$3"
  47. local input_value="$4"
  48.  
  49. local key
  50. case "$input_name" in
  51. leftbottom|leftshoulder)
  52. key="pageup"
  53. ;;
  54. rightbottom|rightshoulder)
  55. key="pagedown"
  56. ;;
  57. up|right|down|left|start|select|x|y|leftanalogup|leftanalogright|leftanalogdown|leftanalogleft|rightanalogup|rightanalogright|rightanalogdown|rightanalogleft)
  58. key="$input_name"
  59. ;;
  60. a)
  61. key="$input_name"
  62. getAutoConf es_swap_a_b && key="b"
  63. ;;
  64. b)
  65. key="$input_name"
  66. getAutoConf es_swap_a_b && key="a"
  67. ;;
  68. *)
  69. return
  70. ;;
  71. esac
  72. local es_conf="$home/.emulationstation/es_input.cfg"
  73.  
  74. # add or update element
  75. if [[ $(xmlstarlet sel -t -v "count(/inputList/inputConfig[@deviceGUID=\"$DEVICE_GUID\"]/input[@name=\"$key\"])" "$es_conf") -eq 0 ]]; then
  76. xmlstarlet ed -L -s "/inputList/inputConfig[@deviceGUID=\"$DEVICE_GUID\"]" -t elem -n newinput -v "" \
  77. -i //newinput -t attr -n "name" -v "$key" \
  78. -i //newinput -t attr -n "type" -v "$input_type" \
  79. -i //newinput -t attr -n "id" -v "$input_id" \
  80. -i //newinput -t attr -n "value" -v "$input_value" \
  81. -r //newinput -v input \
  82. "$es_conf"
  83. else # if device already exists, update it
  84. xmlstarlet ed -L \
  85. -u "/inputList/inputConfig[@deviceGUID=\"$DEVICE_GUID\"]/input[@name=\"$key\"]/@type" -v "$input_type" \
  86. -u "/inputList/inputConfig[@deviceGUID=\"$DEVICE_GUID\"]/input[@name=\"$key\"]/@id" -v "$input_id" \
  87. -u "/inputList/inputConfig[@deviceGUID=\"$DEVICE_GUID\"]/input[@name=\"$key\"]/@value" -v "$input_value" \
  88. "$es_conf"
  89. fi
  90. }
  91.  
  92. function onstart_emulationstation_keyboard() {
  93. onstart_emulationstation_joystick "$@"
  94. }
  95.  
  96. function map_emulationstation_keyboard() {
  97. map_emulationstation_joystick "$@"
  98. }
  99.  
  100. function onstart_emulationstation_cec() {
  101. onstart_emulationstation_joystick "$@"
  102. }
  103.  
  104. function map_emulationstation_cec() {
  105. map_emulationstation_joystick "$@"
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement