Advertisement
Guest User

emoctl - XMC-1 control script

a guest
Sep 20th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.23 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. # Quick and dirty XMC-1 remote control. Hard coded port and IP for now.
  4. # Beerware / ian Butler / dualityk (emotiva lounge) / 9/2017
  5.  
  6. # Old XMC-1 firmware will wake up if the screen is off, but not do anything;
  7. # you have to send a second command before it listens. FW 4.1 is fixed.
  8.  
  9. # Set your preamp's IP here. This is all you have to change.
  10.  
  11. EMOPORT = ("192.168.0.111", 7002)
  12.  
  13. import argparse, socket
  14.  
  15. # Heavy lifting done by argument parser
  16.  
  17. args = argparse.ArgumentParser()
  18.  
  19. args.add_argument('--input-1', dest='togs', action='append_const', const='<source_1 value="0" />', help='set source to input 1')
  20. args.add_argument('--input-2', dest='togs', action='append_const', const='<source_2 value="0" />', help='set source to input 2')
  21. args.add_argument('--input-3', dest='togs', action='append_const', const='<source_3 value="0" />', help='set source to input 3')
  22. args.add_argument('--input-4', dest='togs', action='append_const', const='<source_4 value="0" />', help='set source to input 4')
  23. args.add_argument('--input-5', dest='togs', action='append_const', const='<source_5 value="0" />', help='set source to input 5')
  24. args.add_argument('--input-6', dest='togs', action='append_const', const='<source_6 value="0" />', help='set source to input 6')
  25. args.add_argument('--input-7', dest='togs', action='append_const', const='<source_7 value="0" />', help='set source to input 7')
  26. args.add_argument('--input-8', dest='togs', action='append_const', const='<source_8 value="0" />', help='set source to input 8')
  27. args.add_argument('--input-tuner', dest='togs', action='append_const', const='<source_tuner value="0" />', help='set source to tuner')
  28. args.add_argument('-M', '--menu', dest='togs', action='append_const', const='<menu value="0" />', help='toggle menu')
  29. args.add_argument('-u', '--up', dest='togs', action='append_const', const='<up value="0" />', help='menu up')
  30. args.add_argument('-d', '--down', dest='togs', action='append_const', const='<down value="0" />', help='menu down')
  31. args.add_argument('-l', '--left', dest='togs', action='append_const', const='<left value="0" />', help='menu left')
  32. args.add_argument('-r', '--right', dest='togs', action='append_const', const='<right value="0" />', help='menu right')
  33. args.add_argument('-e', '--enter', dest='togs', action='append_const', const='<enter value="0" />', help='menu enter')
  34. args.add_argument('-b', '--brightness', dest='togs', action='append_const', const='<dim value="0" />', help='cycle display brightness')
  35. args.add_argument('-i', '--info', dest='togs', action='append_const', const='<info value="0" />', help='information screen')
  36. args.add_argument('-m', '--mute', dest='togs', action='append_const', const='<mute value="0" />', help='toggle mute')
  37. args.add_argument('-R', '--reference', dest='togs', action='append_const', const='<reference_stereo value="0" />', help='toggle reference stereo')
  38. args.add_argument('--movie', dest='togs', action='append_const', const='<movie value="0" />', help='select movie preset')
  39. args.add_argument('--music', dest='togs', action='append_const', const='<music value="0" />', help='select music preset')
  40. args.add_argument('-o', '--poweron', dest='togs', action='append_const', const='<power_on value="0" />', help='zone 1 power on')
  41. args.add_argument('-O', '--poweroff', dest='togs', action='append_const', const='<power_off value="0" />', help='zone 1 power off')
  42. args.add_argument('-L', '--loudness', dest='togs', action='append_const', const='<loudness value="0" />', help='zone 1 loudness')
  43. args.add_argument('-s', '--speaker-preset', dest='togs', action='append_const', const='<speaker_preset value="0" />', help='cycle speaker presets')
  44. args.add_argument('-z', '--zone2-power', dest='togs', action='append_const', const='<zone2_power value="0" />', help='toggle zone 2 power')
  45. args.add_argument('--band', dest='togs', action='append_const', const='<zone1_band value="0" />', help='tuner band am/fm')
  46. args.add_argument('-v', '--volume', type=int, default=0, help='change zone 1 volume by n dB')
  47. args.add_argument('-D', '--mode', type=int, default=0, help='mode +/-')
  48. args.add_argument('-C', '--center', type=int, default=0, help='center trim +/-')
  49. args.add_argument('-W', '--sub', type=int, default=0, help='sub trim +/-')
  50. args.add_argument('-S', '--surround', type=int, default=0, help='surround trim +/-')
  51. args.add_argument('-B', '--back', type=int, default=0, help='back trim +/-')
  52. args.add_argument('-I', '--input', type=int, default=0, help='cycle zone 1 inputs +/-')
  53. args.add_argument('-Z', '--zone2-input', dest='z2input', type=int, default=0, help='cycle zone 2 inputs +/-')
  54. args.add_argument('-V', '--zone2-volume', dest='z2vol', type=int, default=0, help='change zone 2 volume by n dB')
  55. args.add_argument('-f', '--tuner-frequency', dest='freq', type=int, default=0, help='tuner frequency +/-')
  56. args.add_argument('-F', '--tuner-seek', dest='seek', type=int, default=0, help='tuner seek +/-')
  57. args.add_argument('-c', '--tuner-channel', dest='channel', type=int, default=0, help='tuner preset +/-')
  58.  
  59. x = args.parse_args()
  60.  
  61. # Build the XML payload
  62.  
  63. blast = '<?xml version="1.0"?><emotivaControl>'
  64.  
  65. # Iterate through all the easy pushbutton strings created above
  66.  
  67. if x.togs:
  68. for i in x.togs:
  69. blast += i
  70.  
  71. # Add all the commands that require arguments
  72.  
  73. if x.volume: blast += '<volume value="' +str(x.volume)+ '" />'
  74. if x.mode: blast += '<mode value="' +str(x.mode)+ '" />'
  75. if x.center: blast += '<center value="' +str(x.center)+ '" />'
  76. if x.sub: blast += '<subwoofer value="'+str(x.sub)+ '" />'
  77. if x.surround: blast += '<surround value="' +str(x.surround)+ '" />'
  78. if x.back: blast += '<back value="' +str(x.back)+ '" />'
  79. if x.input: blast += '<input value="' +str(x.input)+ '" />'
  80. if x.z2input: blast += '<zone2_input value="'+str(x.z2input)+'" />'
  81. if x.z2vol: blast += '<zone2_volume value="'+str(x.z2vol)+ '" />'
  82. if x.freq: blast += '<frequency value="'+str(x.freq)+ '" />'
  83. if x.seek: blast += '<seek value="' +str(x.seek)+ '" />'
  84. if x.channel: blast += '<channel value="' +str(x.channel)+ '" />'
  85.  
  86. blast += '</emotivaControl>'
  87.  
  88. # Send and done.
  89.  
  90. socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(blast, EMOPORT)
  91.  
  92. print 'All your problems are over.'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement