Guest User

Dell P4317Q Serial Control Program

a guest
Apr 12th, 2017
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 25.99 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import sys
  4. import struct
  5. import serial
  6. import binascii
  7.  
  8. debug=False
  9.  
  10. CMD_HEADER=bytearray([0x37, 0x51])
  11. CMD_READ=0xEB
  12. CMD_WRITE=0xEA
  13.  
  14. # Only get commands have a response.
  15. RSP_HEADER=bytearray([0x6F, 0x37])
  16. RSP_REPLY_CODE=0x02
  17.  
  18. def print_debug(message):
  19.     "Debug print message"
  20.     if (debug == True):
  21.         print message
  22.  
  23. def print_usage():
  24.     "Print program usage"
  25.     print sys.argv[0] + " usage:"
  26.     print sys.argv[0] + "{get|set|reset} {command} [parameter]"
  27.     print ""
  28.     print "get   - Retrieves information from the monitor"
  29.     print "set   - Sets a value in the monitor"
  30.     print "reset - Resets a monitor capability"
  31.     print ""
  32.     print " parameter is required only for set commands"
  33.     print ""
  34.     print "get commands:"
  35.     print "    assettag, monitorname, monitorserial, backlighthours"
  36.     print "    powerstate, powerled, powerusb"
  37.     print "    brightness, contrast, aspectratio, sharpness"
  38.     print "    inputcolorformat, colorpresetcaps, colorpreset, customcolor"
  39.     print "    autoselect, videoinputcaps, videoinput"
  40.     print "    pxpmode, pxpsubinput, pxplocation"
  41.     print "    osdtransparency, osdlanguage, osdtimer, osdbuttonlock"
  42.     print "    versionfirmware, ddcci, lcdconditioning"
  43.     print ""
  44.     print "set commands:"
  45.     print "    powerstate, powerled, powerusb"
  46.     print "    brightness, contrast, aspectratio, sharpness"
  47.     print "    inputcolorformat, colorpreset, customcolor"
  48.     print "    autoselect, videoinput"
  49.     print "       Video Input Names:"
  50.     print "           vga, dp, mdp, hdmi1, hdmi2"
  51.     print "    pxpmode, pxpsubinput, pxplocation"
  52.     print "       PxP modes:"
  53.     print "           4k:        3840x2160 full screen"
  54.     print "           smallPip:  3840x2160 full screen (primary video input)"
  55.     print "                      small inset picture-in-picture"
  56.     print "           bigPip:    3840x2160 full screen (primary video input)"
  57.     print "                      large inset picture-in-picture"
  58.     print "           4x4:       four 1920x1080 panes"
  59.     print "           1x2:       one 3840x1080 window over 2x 1920x1080"
  60.     print "           2x1:       one 1920x2160 window right of 2x 1920x1080"
  61.     print "           SxS:       two 1920x2160 panes"
  62.     print "       PiP Locations:"
  63.     print "           topRight, topLeft, bottomRight, bottomLeft"
  64.     print "    osdtransparency, osdlanguage, osdtimer, osdbuttonlock"
  65.     print "       OSD Languages:"
  66.     print "           english, spanish, french, german, portugese,"
  67.     print "           russian, chinese, japanese"
  68.     print "    ddcci, lcdconditioning"
  69.     print ""
  70.     print "reset commands:"
  71.     print "    power, color, osd, factory"
  72.  
  73. def dump_info():
  74.     commands = ["monitorname", "monitorserial", "backlighthours", "powerstate", "powerled", "powerusb", "brightness", "contrast", "aspectratio", "sharpness", "inputcolorformat", "colorpresetcaps", "colorpreset", "customcolor", "autoselect", "videoinputcaps", "videoinput", "pxpmode", "pxpsubinput", "pxplocation", "osdtransparency", "osdlanguage", "osdtimer", "osdbuttonlock", "versionfirmware", "ddcci", "lcdconditioning"]
  75.  
  76.     for command in commands:
  77.         if (command == "pxpsubinput"):
  78.             for index in range(0,4):
  79.                 p4317q_handle_command("get", command, index)
  80.         else:
  81.             param = None
  82.             if (command == "customcolor"):
  83.                 param = 0
  84.             p4317q_handle_command("get", command, param)
  85.  
  86.  
  87. def p4317q_hex_format(message):
  88.     "Create a hex-ascii string representation of message"
  89.     hex = binascii.b2a_hex(message)
  90.     formatted_hex = ':'.join(hex[i:i+2] for i in range(0, len(hex), 2))
  91.     return formatted_hex
  92.  
  93. def p4317q_checksum(message, begin, length):
  94.     "Calculate the single byte checksum of the input data"
  95.     total = 0
  96.     for index in range(begin,begin+length):
  97.         #total += message[index]
  98.         total ^= message[index]
  99.         #total &= 0xFF
  100.         print_debug("DB:  total ^ 0x" + p4317q_hex_format(bytearray([message[index]])) + " = 0x" + p4317q_hex_format(bytearray([total&0xff])))
  101.     total &= 0xFF
  102.     print_debug("DB:  " + str(total)+ " 0x" + p4317q_hex_format(bytearray([total])))
  103.     # Compute 2's complement of the sum.  Comment out if this isn't needed
  104.     #total = (~total+1) & 0xFF
  105.     print_debug("DB:  " + str(total)+ " 0x" + p4317q_hex_format(bytearray([total])))
  106.     return total
  107.  
  108. #0x6E, 0x51, 0x02, 0xEB, 0x01, D7p
  109.  
  110. def p4317q_build_command(action, value, param):
  111.     "Build a command to be sent to the monitor.  Assumed that param is a bytearray of the correct length"
  112.     cmd_tag = (ACTIONS_MAP[action])[value]
  113.     cmd_len = (ACTIONS_MAP[action])[value+"_len"]
  114.  
  115.     print_debug("DEBUG:  Param is [" + str(param) + "].  Type is [" + str(type(param)) + "].")
  116.     command = CMD_HEADER + bytearray([cmd_len])
  117.     if (action == "set"):
  118.         cmd_act = CMD_WRITE
  119.         command = command + bytearray([cmd_act]) + bytearray([cmd_tag])
  120.         if (isinstance(param, bytearray)):
  121.             command += param
  122.         else:
  123.             command += bytearray([param])
  124.     else:
  125.         cmd_act = CMD_READ
  126.         command = command + bytearray([cmd_act]) + bytearray([cmd_tag])
  127.         if (param is not None): command += bytearray([param])
  128.  
  129.     # compute the checksum and add that to the end
  130.     checksum = p4317q_checksum(command, 2, cmd_len+1)
  131.     command = command + bytearray([checksum])
  132.     return command
  133.  
  134. def p4317q_send_command(ser_port, command):
  135.     ser_port.write(command)
  136.  
  137. def p4317q_parse_response(response, command):
  138.     response_data = bytearray(response)
  139.     hex = p4317q_hex_format(bytearray([command]))
  140.     print_debug("Parsing response.  Expecting command [" + hex + "].")
  141.     print_debug("Response data:\n    " + p4317q_hex_format(response_data))
  142.     print_debug("Verifying checksum.")
  143.     ckdata = bytearray([len(response_data)-1]) + response_data
  144.     #chksum = p4317q_checksum(response_data,0,len(response_data)-1)
  145.     chksum = p4317q_checksum(ckdata,0,len(ckdata)-1)
  146.     if (chksum != response_data[len(response_data)-1]):
  147.         print_debug("ERROR.  CheckSum does not verify.  Calculated == " + p4317q_hex_format(bytearray([chksum])) + ".")
  148.         # Checksum verification doesn't seem to matter (or work)
  149.         return None
  150.     else:
  151.         print_debug("Checksum verified.")
  152.  
  153.     if (response_data[0] != RSP_REPLY_CODE):
  154.         print "ERROR.  Reply code incorrect."
  155.         return None
  156.     print_debug("Result code = " + p4317q_hex_format(bytearray([response_data[1]])))
  157.     # Probably could do with some operation on the result code here...
  158.  
  159.     if (response_data[2] != command):
  160.         print_debug("DEBUG " + str(response_data[2]) + " == " + str(command) + ".")
  161.         print "ERROR.  Received incorrect command response."
  162.         return None
  163.     else:
  164.         print_debug("Command response is correct.")
  165.     print_debug("Response Data:        " + p4317q_hex_format(response_data[3:-1]))
  166.     if (command in (CMD_G_MONITOR_NAME_C, CMD_G_ASSET_TAG_C, CMD_G_MONITOR_SERIAL_C, CMD_G_VERSION_FIRMWARE_C)):
  167.         print_debug("ASCII Response Data:  " + response_data[3:-1])
  168.     print_debug("Done parsing.")
  169.     return response_data[3:-1]
  170.  
  171. def p4317q_read_response(ser_port):
  172.     # Read 2 bytes, make sure they're == RSP_HEADER
  173.     resp_header = ser_port.read(2)
  174.     print_debug("DEBUG:  Response header received has " + str(len(resp_header)) + " bytes.")
  175.     print_debug("DEBUG:  Received response header = [" + p4317q_hex_format(resp_header) + "]")
  176.     print_debug("DEBUG:  Expected response header = [" + p4317q_hex_format(RSP_HEADER) + "]")
  177.     if (ord(resp_header[0]) != RSP_HEADER[0]):
  178.         print_debug(str(ord(resp_header[0])) + " == " + str(RSP_HEADER[0]))
  179.         print_debug("DEBUG:  1st byte of response header does not match " + p4317q_hex_format(RSP_HEADER))
  180.         return None
  181.  
  182.     if (ord(resp_header[1]) != RSP_HEADER[1]):
  183.         print_debug("DEBUG:  2nd byte of response header does not match " + p4317q_hex_format(RSP_HEADER))
  184.         return None
  185.  
  186.     # Read 1 byte of len
  187.     resp_len = ord(ser_port.read(1))
  188.     print_debug("DEBUG:  Received data length of " + str(resp_len))
  189.     # Read resp_len+1 bytes (message + checksum)
  190.     response = ser_port.read(resp_len+1)
  191.     return response
  192.  
  193. def p4317q_handle_command(action, command, param):
  194.     cmd = p4317q_build_command(action, command, param)
  195.     print_debug("DEBUG:  Command:  [" + p4317q_hex_format(cmd) + "]")
  196.  
  197.     port = serial.Serial("/dev/cu.usbserial")
  198.  
  199.     p4317q_send_command(port, cmd)
  200.  
  201.     response = p4317q_read_response(port)
  202.  
  203.     port.close()
  204.  
  205.     if (response is not None):
  206.         print_debug("Response = [" + p4317q_hex_format(response) + "]")
  207.         parsedResponse = p4317q_parse_response(response, (ACTIONS_MAP[action])[command])
  208.  
  209.     if (parsedResponse is not None and action == "get"):
  210.         format_response(command, parsedResponse, param)
  211.  
  212.  
  213. def format_response(command, response, param):
  214.     if   (command == "assettag"):
  215.         print ""
  216.     elif (command == "monitorname"):
  217.         print "Monitor Name         = " + str(response)
  218.     elif (command == "monitorserial"):
  219.         print "Monitor Serial #     = " + str(response)
  220.     elif (command == "backlighthours"):
  221.         print "Backlight Hours      = " + str(struct.unpack("<h", response)[0])
  222.     elif (command == "powerstate"):
  223.         print "Power State          = " + ("ON" if response[0]==1 else "OFF")
  224.     elif (command == "powerled"):
  225.         print "Power LED            = " + ("ON" if response[0]==1 else "OFF")
  226.     elif (command == "powerusb"):
  227.         print "Power USB            = " + ("ON" if response[0]==1 else "OFF")
  228.     elif (command == "brightness"):
  229.         print "Brightness           = " + str(response[0])
  230.     elif (command == "contrast"):
  231.         print "Contrast             = " + str(response[0])
  232.     elif (command == "aspectratio"):
  233.         ratios = { v: k for k, v in aspect_ratios.items() }
  234.         print "Aspect Ratio         = " + ratios[response[0]]
  235.     elif (command == "sharpness"):
  236.         print "Sharpness            = " + str(response[0])
  237.     elif (command == "inputcolorformat"):
  238.         formats = { v: k for k, v in input_color_formats.items() }
  239.         print "Input Color Format   = " + formats[response[0]]
  240.     elif (command == "colorpresetcaps"):
  241.         print "Color Preset Caps    = " + p4317q_hex_format(response)
  242.     elif (command == "colorpreset"):
  243.         print "Color Preset         = " + color_preset_inv[struct.unpack("<h", response[0:2])[0]]
  244.     elif (command == "customcolor"):
  245.         print "Custom Color [R:G:B] = [" + str(response[0]) + ":" + str(response[1]) + ":" + str(response[2]) + "]"
  246.     elif (command == "autoselect"):
  247.         print "Input Auto Select    = " + ("ON" if response[0]==1 else "OFF")
  248.     elif (command == "videoinputcaps"):
  249.         print "Video Input Caps     = " + p4317q_hex_format(response)
  250.     elif (command == "videoinput"):
  251.         inputs = { v[0]: k for k, v in pxp_input.items() }
  252.         print "Video Input          = " + inputs[int(response[0])]
  253.     elif (command == "pxpmode"):
  254.         modes = { v: k for k, v in pxp_mode.items() }
  255.         print "PxP/PiP Mode         = " + modes[response[0]]
  256.     elif (command == "pxpsubinput"):
  257.         inputs = { v[0]: k for k, v in pxp_input.items() }
  258.         print "PxP/PiP Sub Input[" + str(param+1) + "] = " + inputs[int(response[0])]
  259.     elif (command == "pxplocation"):
  260.         locations = { v: k for k, v in pxp_locations.items() }
  261.         print "PiP Window Location  = " + locations[int(response[0])]
  262.     elif (command == "osdtransparency"):
  263.         print "OSD Transparency     = " + str(response[0])
  264.     elif (command == "osdlanguage"):
  265.         languages = { v: k for k, v in osd_language.items() }
  266.         print "OSD Language         = " + languages[int(response[0])]
  267.     elif (command == "osdtimer"):
  268.         print "OSD Timer            = " + str(response[0])
  269.     elif (command == "osdbuttonlock"):
  270.         print "OSD Button Lock      = " + ("ON" if response[0]==1 else "OFF")
  271.     elif (command == "versionfirmware"):
  272.         print "Firmware Version     = " + response
  273.     elif (command == "ddcci"):
  274.         print "DDC/CI               = " + ("ON" if response[0]==1 else "OFF")
  275.     elif (command == "lcdconditioning"):
  276.         print "LCD Conditioning     = " + ("ON" if response[0]==1 else "OFF")
  277.     return
  278.  
  279.  
  280. # MONITOR MANAGEMENT
  281. CMD_G_ASSET_TAG_L=0x02
  282. CMD_G_ASSET_TAG_C=0x00
  283. CMD_G_ASSET_TAG_RESP_L=0x0D
  284. CMD_G_MONITOR_NAME_L=0x02
  285. CMD_G_MONITOR_NAME_C=0x01
  286. CMD_G_MONITOR_NAME_RESP_L=0x0D
  287. CMD_G_MONITOR_SERIAL_L=0x02
  288. CMD_G_MONITOR_SERIAL_C=0x02
  289. CMD_G_MONITOR_SERIAL_RESP_L=0x0D
  290. CMD_G_BACKLIGHT_HOURS_L=0x02
  291. CMD_G_BACKLIGHT_HOURS_C=0x04
  292. CMD_G_BACKLIGHT_HOURS_RESP_L=0x05
  293.  
  294. # POWER MANAGEMENT
  295. CMD_G_POWER_STATE_L=0x02
  296. CMD_G_POWER_STATE_C=0x20
  297. CMD_G_POWER_STATE_RESP_L=0x04
  298. CMD_S_POWER_STATE_L=0x03
  299. CMD_S_POWER_STATE_C=0x20
  300. CMD_G_POWER_LED_L=0x02
  301. CMD_G_POWER_LED_C=0x21
  302. CMD_G_POWER_LED_RESP_L=0x04
  303. CMD_S_POWER_LED_L=0x03
  304. CMD_S_POWER_LED_C=0x21
  305. CMD_G_POWER_USB_L=0x02
  306. CMD_G_POWER_USB_C=0x22
  307. CMD_G_POWER_USB_RESP_L=0x04
  308. CMD_S_POWER_USB_L=0x03
  309. CMD_S_POWER_USB_C=0x22
  310. CMD_RESET_POWER_L=0x02
  311. CMD_RESET_POWER_C=0x2F
  312.  
  313. # IMAGE ADJUSTMENT
  314. CMD_G_BRIGHTNESS_L=0x02
  315. CMD_G_BRIGHTNESS_C=0x30
  316. CMD_G_BRIGHTNESS_RESP_L=0x04
  317. CMD_S_BRIGHTNESS_L=0x03
  318. CMD_S_BRIGHTNESS_C=0x30
  319. CMD_G_CONTRAST_L=0x02
  320. CMD_G_CONTRAST_C=0x31
  321. CMD_G_CONTRAST_RESP_L=0x04
  322. CMD_S_CONTRAST_L=0x03
  323. CMD_S_CONTRAST_C=0x31
  324. CMD_G_ASPECT_RATIO_L=0x02
  325. CMD_G_ASPECT_RATIO_C=0x33
  326. CMD_G_ASPECT_RATIO_RESP_L=0x04
  327. CMD_S_ASPECT_RATIO_L=0x03
  328. CMD_S_ASPECT_RATIO_C=0x33
  329. CMD_G_SHARPNESS_L=0x02
  330. CMD_G_SHARPNESS_C=0x34
  331. CMD_G_SHARPNESS_RESP_L=0x04
  332. CMD_S_SHARPNESS_L=0x03
  333. CMD_S_SHARPNESS_C=0x34
  334.  
  335. aspect_ratios = { "16x9": 0,
  336.                   "4x3":  2,
  337.                   "5x4":  4 }
  338.  
  339. # COLOR MANAGEMENT
  340. CMD_G_INPUT_COLOR_FORMAT_L=0x02
  341. CMD_G_INPUT_COLOR_FORMAT_C=0x46
  342. CMD_G_INPUT_COLOR_FORMAT_RESP_L=0x04
  343. CMD_S_INPUT_COLOR_FORMAT_L=0x03
  344. CMD_S_INPUT_COLOR_FORMAT_C=0x46
  345. CMD_G_COLOR_PRESET_CAPS_L=0x02
  346. CMD_G_COLOR_PRESET_CAPS_C=0x47
  347. CMD_G_COLOR_PRESET_CAPS_RESP_L=0x07
  348. CMD_G_COLOR_PRESET_L=0x02
  349. CMD_G_COLOR_PRESET_C=0x48
  350. CMD_G_COLOR_PRESET_RESP_L=0x07
  351. CMD_S_COLOR_PRESET_L=0x06
  352. CMD_S_COLOR_PRESET_C=0x48
  353. CMD_G_CUSTOM_COLOR_L=0x03
  354. CMD_G_CUSTOM_RESP_L=0x09
  355. CMD_G_CUSTOM_COLOR_C=0x49
  356. CMD_G_CUSTOM_COLOR_RESP_L=0x09
  357. CMD_S_CUSTOM_COLOR_L=0x09
  358. CMD_S_CUSTOM_COLOR_C=0x49
  359. CMD_RESET_COLOR_L=0x02
  360. CMD_RESET_COLOR_C=0x4F
  361.  
  362. input_color_formats = { "RGB": 0,
  363.                         "YPbPr": 1 }
  364.  
  365. color_presets = { "standard": bytearray([0x01, 0x00, 0x00, 0x00]),
  366.                   "paper":    bytearray([0x10, 0x00, 0x00, 0x00]),
  367.                   "warm":     bytearray([0x00, 0x01, 0x00, 0x00]),
  368.                   "cool":     bytearray([0x00, 0x02, 0x00, 0x00]),
  369.                   "custom":   bytearray([0x80, 0x00, 0x00, 0x00]) }
  370. color_preset_inv = { struct.unpack("<h", bytearray([0x01, 0x00]))[0]:  "standard",
  371.                      struct.unpack("<h", bytearray([0x10, 0x00]))[0]:  "paper",
  372.                      struct.unpack("<h", bytearray([0x00, 0x01]))[0]:  "warm",
  373.                      struct.unpack("<h", bytearray([0x00, 0x02]))[0]:  "cool",
  374.                      struct.unpack("<h", bytearray([0x80, 0x00]))[0]:  "custom" }
  375.  
  376. # VIDEO INPUT MANAGEMENT
  377. CMD_G_AUTO_SELECT_L=0x02
  378. CMD_G_AUTO_SELECT_C=0x60
  379. CMD_G_AUTO_SELECT_RESP_L=0x04
  380. CMD_S_AUTO_SELECT_L=0x03
  381. CMD_S_AUTO_SELECT_C=0x60
  382. CMD_G_VIDEO_INPUT_CAPS_L=0x02
  383. CMD_G_VIDEO_INPUT_CAPS_C=0x61
  384. CMD_G_VIDEO_INPUT_CAPS_RESP_L=0x07
  385. CMD_G_VIDEO_INPUT_L=0x02
  386. CMD_G_VIDEO_INPUT_C=0x62
  387. CMD_G_VIDEO_INPUT_RESP_L=0x07
  388. CMD_S_VIDEO_INPUT_L=0x06
  389. CMD_S_VIDEO_INPUT_C=0x62
  390.  
  391. # PIP/PBP MANAGEMENT
  392. CMD_G_PXP_MODE_L=0x02
  393. CMD_G_PXP_MODE_C=0x70
  394. CMD_G_PXP_MODE_RESP_L=0x04
  395. CMD_S_PXP_MODE_L=0x03
  396. CMD_S_PXP_MODE_C=0x70
  397. CMD_G_PXP_SUBINPUT_L=0x03
  398. CMD_G_PXP_SUBINPUT_C=0x71
  399. CMD_G_PXP_SUBINPUT_RESP_L=0x07
  400. CMD_S_PXP_SUBINPUT_L=0x06
  401. CMD_S_PXP_SUBINPUT_C=0x71
  402. CMD_G_PXP_LOCATION_L=0x02
  403. CMD_G_PXP_LOCATION_C=0x72
  404. CMD_G_PXP_LOCATION_RESP_L=0x04
  405. CMD_S_PXP_LOCATION_L=0x03
  406. CMD_S_PXP_LOCATION_C=0x72
  407.  
  408. pxp_mode = { "4k": 0,
  409.              "smallPip": 1,
  410.              "bigPip": 2,
  411.              "SxS": 3,
  412.              "stretchSxS": 4,
  413.              "2x1": 6,
  414.              "1x2": 7,
  415.              "4x4": 8 }
  416.  
  417. pxp_input = { "vga":   bytearray([0x40, 0x00, 0x00, 0x00]),
  418.               "dp":    bytearray([0x08, 0x00, 0x00, 0x00]),
  419.               "mdp":   bytearray([0x10, 0x00, 0x00, 0x00]),
  420.               "hdmi1": bytearray([0x01, 0x00, 0x00, 0x00]),
  421.               "hdmi2": bytearray([0x02, 0x00, 0x00, 0x00]) }
  422.  
  423. pxp_locations = { "topRight": 0,
  424.                   "topLeft": 1,
  425.                   "bottomRight": 2,
  426.                   "bottomLeft": 3 }
  427. # PxP Locations (PiP Location)
  428. # 0 - Top Right
  429. # 1 - Top Left
  430. # 2 - Bottom Right
  431. # 3 - Bottom Left
  432.  
  433. # OSD MANAGEMENT
  434. CMD_S_OSD_TRANSPARENCY_L=0x03
  435. CMD_S_OSD_TRANSPARENCY_C=0x80
  436. CMD_G_OSD_TRANSPARENCY_L=0x02
  437. CMD_G_OSD_TRANSPARENCY_C=0x80
  438. CMD_G_OSD_TRANSPARENCY_RESP_L=0x04
  439. CMD_S_OSD_LANGUAGE_L=0x03
  440. CMD_S_OSD_LANGUAGE_C=0x81
  441. CMD_G_OSD_LANGUAGE_L=0x02
  442. CMD_G_OSD_LANGUAGE_C=0x81
  443. CMD_G_OSD_LANGUAGE_RESP_L=0x04
  444. CMD_S_OSD_TIMER_L=0x03
  445. CMD_S_OSD_TIMER_C=0x83
  446. CMD_G_OSD_TIMER_L=0x02
  447. CMD_G_OSD_TIMER_C=0x83
  448. CMD_G_OSD_TIMER_RESP_L=0x04
  449. CMD_S_OSD_BUTTON_LOCK_L=0x03
  450. CMD_S_OSD_BUTTON_LOCK_C=0x84
  451. CMD_G_OSD_BUTTON_LOCK_L=0x02
  452. CMD_G_OSD_BUTTON_LOCK_C=0x84
  453. CMD_G_OSD_BUTTON_LOCK_RESP_L=0x04
  454. CMD_RESET_OSD_L=0x02
  455. CMD_RESET_OSD_C=0x8F
  456.  
  457. osd_language = { "english": 0,
  458.                  "spanish": 1,
  459.                  "french": 2,
  460.                  "german": 3,
  461.                  "portugese": 4,
  462.                  "russian": 5,
  463.                  "chinese": 6,
  464.                  "japanese": 7 }
  465. # OSD Languages
  466. # 0 - English
  467. # 1 - Spanish
  468. # 2 - French
  469. # 3 - German
  470. # 4 - Portugese
  471. # 5 - Russian
  472. # 6 - Chinese ?
  473. # 7 - Japanese ?
  474.  
  475. # SYSTEM MANAGEMENT
  476. CMD_G_VERSION_FIRMWARE_L=0x02
  477. CMD_G_VERSION_FIRMWARE_C=0xA0
  478. CMD_G_VERSION_FIRMWARE_RESP_L=0x05
  479. CMD_G_DDCCI_L=0x02
  480. CMD_G_DDCCI_C=0xA2
  481. CMD_G_DDCCI_RESP_L=0x04
  482. CMD_S_DDCCI_L=0x03
  483. CMD_S_DDCCI_C=0xA2
  484. CMD_G_LCD_CONDITIONING_L=0x02
  485. CMD_G_LCD_CONDITIONING_C=0xA3
  486. CMD_G_LCD_CONDITIONING_RESP_L=0x04
  487. CMD_S_LCD_CONDITIONING_L=0x03
  488. CMD_S_LCD_CONDITIONING_C=0xA3
  489. CMD_FACTORY_RESET_L=0x02
  490. CMD_FACTORY_RESET_C=0xAF
  491.  
  492. GET_ACTIONS = {
  493.     "assettag": CMD_G_ASSET_TAG_C                  , "assettag_len": CMD_G_ASSET_TAG_L,
  494.     "assettag_resplen": CMD_G_ASSET_TAG_RESP_L,
  495.     "monitorname": CMD_G_MONITOR_NAME_C            , "monitorname_len": CMD_G_MONITOR_NAME_L,
  496.     "monitorname_resplen": CMD_G_MONITOR_NAME_RESP_L,
  497.     "monitorserial": CMD_G_MONITOR_SERIAL_C        , "monitorserial_len": CMD_G_MONITOR_SERIAL_L,
  498.     "monitorserial_resplen": CMD_G_MONITOR_SERIAL_RESP_L,
  499.     "backlighthours": CMD_G_BACKLIGHT_HOURS_C      , "backlighthours_len": CMD_G_BACKLIGHT_HOURS_L,
  500.     "backlighthours_resplen": CMD_G_BACKLIGHT_HOURS_RESP_L,
  501.     "powerstate": CMD_G_POWER_STATE_C              , "powerstate_len": CMD_G_POWER_STATE_L,
  502.     "powerstate_resplen": CMD_G_POWER_STATE_RESP_L,
  503.     "powerled": CMD_G_POWER_LED_C                  , "powerled_len": CMD_G_POWER_LED_L,
  504.     "powerled_resplen": CMD_G_POWER_LED_RESP_L,
  505.     "powerusb": CMD_G_POWER_USB_C                  , "powerusb_len": CMD_G_POWER_USB_L,
  506.     "powerusb_resplen": CMD_G_POWER_USB_RESP_L,
  507.     "brightness": CMD_G_BRIGHTNESS_C               , "brightness_len": CMD_G_BRIGHTNESS_L,
  508.     "brightness_resplen": CMD_G_BRIGHTNESS_RESP_L,
  509.     "contrast": CMD_G_CONTRAST_C                   , "contrast_len": CMD_G_CONTRAST_L,
  510.     "contrast_resplen": CMD_G_CONTRAST_RESP_L,
  511.     "aspectratio": CMD_G_ASPECT_RATIO_C            , "aspectratio_len": CMD_G_ASPECT_RATIO_L,
  512.     "aspectratio_resplen": CMD_G_ASPECT_RATIO_RESP_L,
  513.     "sharpness": CMD_G_SHARPNESS_C                 , "sharpness_len": CMD_G_SHARPNESS_L,
  514.     "sharpness_resplen": CMD_G_SHARPNESS_RESP_L,
  515.     "inputcolorformat": CMD_G_INPUT_COLOR_FORMAT_C , "inputcolorformat_len": CMD_G_INPUT_COLOR_FORMAT_L,
  516.     "inputcolorformat_resplen": CMD_G_INPUT_COLOR_FORMAT_RESP_L,
  517.     "colorpresetcaps": CMD_G_COLOR_PRESET_CAPS_C   , "colorpresetcaps_len": CMD_G_COLOR_PRESET_CAPS_L,
  518.     "colorpresetcaps_resplen": CMD_G_COLOR_PRESET_CAPS_RESP_L,
  519.     "colorpreset": CMD_G_COLOR_PRESET_C            , "colorpreset_len": CMD_G_COLOR_PRESET_L,
  520.     "colorpreset_resplen": CMD_G_COLOR_PRESET_RESP_L,
  521.     "customcolor": CMD_G_CUSTOM_COLOR_C            , "customcolor_len": CMD_G_CUSTOM_COLOR_L,
  522.     "customcolor_resplen": CMD_G_CUSTOM_COLOR_RESP_L,
  523.     "autoselect": CMD_G_AUTO_SELECT_C              , "autoselect_len": CMD_G_AUTO_SELECT_L,
  524.     "autoselect_resplen": CMD_G_AUTO_SELECT_RESP_L,
  525.     "videoinputcaps": CMD_G_VIDEO_INPUT_CAPS_C     , "videoinputcaps_len": CMD_G_VIDEO_INPUT_CAPS_L,
  526.     "videoinputcaps_resplen": CMD_G_VIDEO_INPUT_CAPS_RESP_L,
  527.     "videoinput": CMD_G_VIDEO_INPUT_C              , "videoinput_len": CMD_G_VIDEO_INPUT_L,
  528.     "videoinput_resplen": CMD_G_VIDEO_INPUT_RESP_L,
  529.     "pxpmode": CMD_G_PXP_MODE_C                    , "pxpmode_len": CMD_G_PXP_MODE_L,
  530.     "pxpmode_resplen": CMD_G_PXP_MODE_RESP_L,
  531.     "pxpsubinput": CMD_G_PXP_SUBINPUT_C            , "pxpsubinput_len": CMD_G_PXP_SUBINPUT_L,
  532.     "pxpsubinput_resplen": CMD_G_PXP_SUBINPUT_RESP_L,
  533.     "pxplocation": CMD_G_PXP_LOCATION_C            , "pxplocation_len": CMD_G_PXP_LOCATION_L,
  534.     "pxplocation_resplen": CMD_G_PXP_LOCATION_RESP_L,
  535.     "osdtransparency": CMD_G_OSD_TRANSPARENCY_C    , "osdtransparency_len": CMD_G_OSD_TRANSPARENCY_L,
  536.     "osdtransparency_resplen": CMD_G_OSD_TRANSPARENCY_RESP_L,
  537.     "osdlanguage": CMD_G_OSD_LANGUAGE_C            , "osdlanguage_len": CMD_G_OSD_LANGUAGE_L,
  538.     "osdlanguage_resplen": CMD_G_OSD_LANGUAGE_RESP_L,
  539.     "osdtimer": CMD_G_OSD_TIMER_C                  , "osdtimer_len": CMD_G_OSD_TIMER_L,
  540.     "osdtimer_resplen": CMD_G_OSD_TIMER_RESP_L,
  541.     "osdbuttonlock": CMD_G_OSD_BUTTON_LOCK_C       , "osdbuttonlock_len": CMD_G_OSD_BUTTON_LOCK_L,
  542.     "osdbuttonlock_resplen": CMD_G_OSD_BUTTON_LOCK_RESP_L,
  543.     "versionfirmware": CMD_G_VERSION_FIRMWARE_C    , "versionfirmware_len": CMD_G_VERSION_FIRMWARE_L,
  544.     "versionfirmware_resplen": CMD_G_VERSION_FIRMWARE_RESP_L,
  545.     "ddcci": CMD_G_DDCCI_C                         , "ddcci_len": CMD_G_DDCCI_L,
  546.     "ddcci_resplen": CMD_G_DDCCI_RESP_L,
  547.     "lcdconditioning": CMD_G_LCD_CONDITIONING_C    , "lcdconditioning_len": CMD_G_LCD_CONDITIONING_L,
  548.     "lcdconditioning_resplen": CMD_G_LCD_CONDITIONING_RESP_L
  549. }
  550.  
  551. SET_ACTIONS = {
  552.     "powerstate": CMD_S_POWER_STATE_C              , "powerstate_len": CMD_S_POWER_STATE_L,
  553.     "powerled": CMD_S_POWER_LED_C                  , "powerled_len": CMD_S_POWER_LED_L,
  554.     "powerusb": CMD_S_POWER_USB_C                  , "powerusb_len": CMD_S_POWER_USB_L,
  555.     "brightness": CMD_S_BRIGHTNESS_C               , "brightness_len": CMD_S_BRIGHTNESS_L,
  556.     "contrast": CMD_S_CONTRAST_C                   , "contrast_len": CMD_S_CONTRAST_L,
  557.     "aspectratio": CMD_S_ASPECT_RATIO_C            , "aspectratio_len": CMD_S_ASPECT_RATIO_L,
  558.     "sharpness": CMD_S_SHARPNESS_C                 , "sharpness_len": CMD_S_SHARPNESS_L,
  559.     "inputcolorformat": CMD_S_INPUT_COLOR_FORMAT_C , "inputcolorformat_len": CMD_S_INPUT_COLOR_FORMAT_L,
  560.     "colorpreset": CMD_S_COLOR_PRESET_C            , "colorpreset_len": CMD_S_COLOR_PRESET_L,
  561.     "customcolor": CMD_S_CUSTOM_COLOR_C            , "customcolor_len": CMD_S_CUSTOM_COLOR_L,
  562.     "autoselect": CMD_S_AUTO_SELECT_C              , "autoselect_len": CMD_S_AUTO_SELECT_L,
  563.     "videoinput": CMD_S_VIDEO_INPUT_C              , "videoinput_len": CMD_S_VIDEO_INPUT_L,
  564.     "pxpmode": CMD_S_PXP_MODE_C                    , "pxpmode_len": CMD_S_PXP_MODE_L,
  565.     "pxpsubinput": CMD_S_PXP_SUBINPUT_C            , "pxpsubinput_len": CMD_S_PXP_SUBINPUT_L,
  566.     "pxplocation": CMD_S_PXP_LOCATION_C            , "pxplocation_len": CMD_S_PXP_LOCATION_L,
  567.     "osdtransparency": CMD_S_OSD_TRANSPARENCY_C    , "osdtransparency_len": CMD_S_OSD_TRANSPARENCY_L,
  568.     "osdlanguage": CMD_S_OSD_LANGUAGE_C            , "osdlanguage_len": CMD_S_OSD_LANGUAGE_L,
  569.     "osdtimer": CMD_S_OSD_TIMER_C                  , "osdtimer_len": CMD_S_OSD_TIMER_L,
  570.     "osdbuttonlock": CMD_S_OSD_BUTTON_LOCK_C       , "osdbuttonlock_len": CMD_S_OSD_BUTTON_LOCK_L,
  571.     "ddcci": CMD_S_DDCCI_C                         , "ddcci_len": CMD_S_DDCCI_L,
  572.     "lcdconditioning": CMD_S_LCD_CONDITIONING_C    , "lcdconditioning_len": CMD_S_LCD_CONDITIONING_L
  573. }
  574.  
  575. RESET_ACTIONS = {
  576.     "power": CMD_RESET_POWER_C                     , "power_len": CMD_RESET_POWER_L,
  577.     "color": CMD_RESET_COLOR_C                     , "color_len": CMD_RESET_COLOR_L,
  578.     "osd": CMD_RESET_OSD_C                         , "osd_len": CMD_RESET_OSD_L,
  579.     "factory": CMD_FACTORY_RESET_C                 , "factory_len": CMD_FACTORY_RESET_L
  580. }
  581.  
  582. ACTIONS_MAP = { "get": GET_ACTIONS, "set": SET_ACTIONS, "reset": RESET_ACTIONS }
  583.  
  584. print_debug("len(sys.argv) = " + str(len(sys.argv)))
  585. print_debug("args = " + str(sys.argv))
  586. if (len(sys.argv) < 2 or len(sys.argv) > 5):
  587.     print_usage()
  588.     exit()
  589.  
  590. if (sys.argv[1] == "dump"):
  591.     dump_info()
  592.     exit()
  593.  
  594. if (sys.argv[1] in ("get", "set", "reset")):
  595.     keys = ACTIONS_MAP[sys.argv[1]].keys()
  596.     if (sys.argv[2] not in keys):
  597.         print "ERROR:  Invalid command specified"
  598.         exit()
  599. else:
  600.     print "ERROR:  Invalid action specified"
  601.     exit()
  602.  
  603. param = None
  604. if (len(sys.argv) >= 4):
  605.     if (sys.argv[1] == "set"):
  606.         if   (sys.argv[2] == "osdlanguage"):
  607.             param = osd_language[sys.argv[3]]
  608.         elif (sys.argv[2] == "pxplocation"):
  609.             param = pxp_locations[sys.argv[3]]
  610.         elif (sys.argv[2] == "pxpmode"):
  611.             param = pxp_mode[sys.argv[3]]
  612.         elif (sys.argv[2] == "videoinput"):
  613.             param = pxp_input[sys.argv[3]]
  614.         elif (sys.argv[2] == "pxpsubinput"):
  615.             print "pxpsubinput"
  616.             param = bytearray([int(sys.argv[3])-1])
  617.             param += pxp_input[sys.argv[4]]
  618.             print "param:  " + p4317q_hex_format(param)
  619.         else:
  620.             param = int(sys.argv[3])
  621.     else:
  622.         param = int(sys.argv[3])
  623.  
  624. output = p4317q_handle_command(sys.argv[1], sys.argv[2], param)
Advertisement
Add Comment
Please, Sign In to add comment