├── Dockerfile ├── LICENSE.md ├── README.md ├── ddc-mqtt ├── devices.py ├── mqtt_client.py ├── rename_to_config.yml ├── requirements.txt ├── start.py └── timer.py ├── docker-compose.yml ├── hass_display_kvm.jpg └── simpleddc-extension ├── setup.py ├── simple-ddc.h ├── simpleddc-python.c └── simpleddc.c /Dockerfile: -------------------------------------------------------------------------------- 1 | # Use an official Python runtime as a parent image 2 | FROM python:3.11 3 | 4 | # Install system dependencies 5 | RUN apt-get update && apt-get install -y \ 6 | libddcutil-dev \ 7 | libddcutil4 \ 8 | && rm -rf /var/lib/apt/lists/* 9 | 10 | # Set the working directory in the container 11 | WORKDIR /usr/src/app 12 | 13 | # Copy the current directory contents into the container at /usr/src/app 14 | COPY . . 15 | 16 | # Build the extension module 17 | RUN (cd simpleddc-extension && python setup.py install) 18 | 19 | # Install Python dependencies for the ddc-mqtt project 20 | RUN pip install --no-cache-dir -r ./ddc-mqtt/requirements.txt 21 | 22 | # Ensure the built module is available to the project 23 | ENV PYTHONPATH "${PYTHONPATH}:/usr/src/app/simpleddc" 24 | 25 | # Change the working directory to run the ddc-mqtt project 26 | WORKDIR /usr/src/app/ddc-mqtt 27 | 28 | # Run start.py when the container launches 29 | CMD ["python", "start.py"] 30 | 31 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2024 Moises Martinez 2 | 3 | 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: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | 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. 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ddc-mqtt - A simple software Display Input switch for DDC-supporting monitors 2 | 3 | [!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/moimartb) 4 | 5 | - Do you have a display with multiple inputs? 6 | - Would you like to be able to switch inputs without the need of meddling with clunky OSD menus and akwardly-positioned control 'nipples'? 7 | - Does this happen to you even with fancy, expensive displays like the Neo G9 line from Samsung? 8 | - Can you imagine KVM scenarios based on home assistant automations? 9 | 10 | Then this software is for you!!! 11 | 12 | You only need a Linux machine connected to the display, a bit of knowledge on your display's support of DDC capabilities and this will 13 | create a device for your Home Assistance (or your MQTT setup) so you can control the display 14 | 15 | ## Display's DDC capabilities 16 | 17 | First of all, you'd need some info about your display and its DDC capabilities wrt display inputs. You'd need the *ddcutil* tool to figure 18 | things out. For example: this is what my G95NC Samsung Neo G9 Reports: 19 | 20 | ``` 21 | $ ddcutil capabilities 22 | Model: FALCON 23 | MCCS version: 2.0 24 | Commands: 25 | Op Code: 01 (VCP Request) 26 | Op Code: 02 (VCP Response) 27 | Op Code: 03 (VCP Set) 28 | Op Code: 07 (Timing Request) 29 | Op Code: 0C (Save Settings) 30 | Op Code: E3 (Capabilities Reply) 31 | Op Code: F3 (Capabilities Request) 32 | VCP Features: 33 | Feature: 02 (New control value) 34 | Feature: 04 (Restore factory defaults) 35 | Feature: 05 (Restore factory brightness/contrast defaults) 36 | Feature: 08 (Restore color defaults) 37 | Feature: 10 (Brightness) 38 | Feature: 12 (Contrast) 39 | Feature: 14 (Select color preset) 40 | Values: 41 | 05: 6500 K 42 | 08: 9300 K 43 | 0b: User 1 44 | 0c: User 2 45 | Feature: 16 (Video gain: Red) 46 | Feature: 18 (Video gain: Green) 47 | Feature: 1A (Video gain: Blue) 48 | Feature: 52 (Active control) 49 | Feature: 60 (Input Source) 50 | Values: 51 | 01: VGA-1 52 | 03: DVI-1 53 | 04: DVI-2 54 | 11: HDMI-1 55 | 12: HDMI-2 56 | 0f: DisplayPort-1 57 | 10: DisplayPort-2 58 | Feature: 62 (Audio speaker volume) 59 | Feature: 8D (Audio Mute) 60 | Feature: FF (Manufacturer specific feature) 61 | ``` 62 | 63 | We'll focus on the **Feature: 60 (Input Source)** ... I have good news and bad news: 64 | 65 | 1. Good news: The display supports changing inputs with DDC! 66 | 2. Bad news: **The inputs and the values are, for the most part, bullsh\*t!!** 67 | 68 | Because of this, we will need to figure out the actual input values for each actual input of the monitor. 69 | 70 | You can use **ddcutil** again to figure them out like so: 71 | 72 | ``` 73 | # change the last number to figure the actual values that change the input. 74 | # Have in mind these are hexadecimal values you'll need to convert to integers 75 | $ sudo ddcutil setvcp 0x60 0x01 76 | ``` 77 | 78 | ## Configuration 79 | 80 | Once you have the values for the inputs you want to control, you can fill out the config.yml inside the folder ddc-mqtt that you'd need for the software to run. For my display this would be: 81 | 82 | ``` 83 | mqtt: 84 | username: #your mqtt server's username 85 | password: #your mqtt server's password 86 | host: 1.2.3.4 #your mqtt server's host 87 | port: 1883 88 | display: 89 | - id: 1 #display to control. if only a single monitor, this must be 1 90 | inputs: 91 | HDMI1: 5 # key: value — you can change the name of the input. 92 | HDMI2: 6 # The codes here are input as integers, not hexadecimal 93 | HDMI3: 7 94 | DP: 15 95 | interval: 20 96 | ``` 97 | 98 | ## Setup 99 | 100 | You might want to use the docker container that comes with the code. If you use a Raspberry Pi you just do: 101 | 102 | ``` 103 | $ docker-compose up -d 104 | ``` 105 | 106 | And if your config is well formed, that should be it! 107 | 108 | If you don't use a Raspberry Pi, you might need to pay attention to the *docker-compose.yml* in the root folder as we are 109 | forwarding the i2c devices for the ddcutil library to access. 110 | 111 | ``` 112 | devices: 113 | - "/dev/i2c-20:/dev/i2c-20" 114 | - "/dev/i2c-21:/dev/i2c-21" #these might be different in your machine 115 | ``` 116 | 117 | ## Usage 118 | 119 | If your MQTT server is shared or is part of a *Home Assistant* setup, the usage is simple. You'll get a device with switches to change inputs and that's all! 120 | 121 | ![Display KVM](https://raw.githubusercontent.com/moimart/ddc-mqtt/main/hass_display_kvm.jpg)' 122 | 123 | If you want to use it MQTT RAW!!! you'd have access to the entities in the following paths: 124 | 125 | ``` 126 | Subscribe to kikkei/display-kvm/{number_of_display}/{input_name_in_the_config}/state 127 | -> with values 'true' or 'false' to check the state 128 | Publish 'ON' to kikkei/display-kvm/{number_of_display}/{input_name_in_the_config}/command for activation 129 | -> no need to send 'OFF'; switching is taken care of 130 | 131 | Example: kikkei/display-kvm/1/HDMI1/state 132 | ``` 133 | 134 | ## Observations 135 | 136 | This software is polling at an interval to re-check of the state of the active input— just in case you switch it manually... 137 | 138 | This interval can be configured in the config.yml with the key interval. It is optional and by default is 20 seconds... 139 | 140 | I coded this to support multiple monitors but I have not tested it at all... contributions are very welcome! :) 141 | 142 | **Hope it works for you as well as it works for me!** -------------------------------------------------------------------------------- /ddc-mqtt/devices.py: -------------------------------------------------------------------------------- 1 | device = { 2 | "identifiers": ["Kikkei Labs Display KVM"], 3 | "name": "Display KVM #?", 4 | "model": "Kikkei-display-kvm-0", 5 | "manufacturer": "Kikkei Labs", 6 | } 7 | 8 | 9 | display_device = { 10 | "identifiers": ["Input"], 11 | "name": "Display Input KVM #?", 12 | "model": "Kikkei-display-kvm", 13 | "manufacturer": "Kikkei Labs", 14 | } 15 | 16 | display_input_entity = { 17 | "generic_switch": 'homeassistant/switch/display-kvm-#/?-switch/config', 18 | "generic_switch_config": { 19 | "availability_topic": "kikkei/display-kvm/availability", 20 | "state_topic": "kikkei/display-kvm/#/?/state", 21 | "name": "", 22 | "unique_id": "", 23 | "object_id": "", 24 | "payload_available": "online", 25 | "payload_not_available": "offline", 26 | #"json_attributes_topic": "kikkei/household/#/%/attributes", 27 | "state_on": "true", 28 | "state_off": "false", 29 | "command_topic": "kikkei/display-kvm/#/?/command", 30 | "device": display_device 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /ddc-mqtt/mqtt_client.py: -------------------------------------------------------------------------------- 1 | import paho.mqtt.client as mqtt 2 | import json 3 | from timer import Timer 4 | 5 | class MQTTClient: 6 | def on_connect(self, client, userdata, flags, rc): 7 | print("Connected with result code " + str(rc)) 8 | 9 | def on_disconnect(self, client, userdata, rc): 10 | self.timer.reset() 11 | self.timer.active = True 12 | 13 | def on_message(self, client, userdata, msg): 14 | if self.delegate != None: 15 | self.delegate.on_message(msg.topic, msg.payload) 16 | 17 | def __init__(self, username, password, host, port): 18 | self.client = mqtt.Client() 19 | 20 | self.client.username_pw_set(username, password) 21 | 22 | self.host = host 23 | self.port = port 24 | self.client.on_connect = self.on_connect 25 | self.client.on_message = self.on_message 26 | self.client.on_disconnect = self.on_disconnect 27 | self.client.connect(host, port, 60) 28 | self.delegate = None 29 | self.timer = Timer(60, self) 30 | self.timer.active = False 31 | 32 | def on_timer(self, timer, elapsed): 33 | self.client.connect(self.host, self.port, 60) 34 | 35 | def step(self, dt): 36 | self.client.loop() 37 | self.timer.step(dt) -------------------------------------------------------------------------------- /ddc-mqtt/rename_to_config.yml: -------------------------------------------------------------------------------- 1 | mqtt: 2 | username: 3 | password: 4 | host: 5 | port: 1883 6 | display: 7 | - id: 1 8 | inputs: 9 | HDMI1: 5 10 | HDMI2: 6 11 | HDMI3: 7 12 | DP: 15 13 | interval: 20 14 | -------------------------------------------------------------------------------- /ddc-mqtt/requirements.txt: -------------------------------------------------------------------------------- 1 | pyyaml>=6.0 2 | paho-mqtt==1.6.1 -------------------------------------------------------------------------------- /ddc-mqtt/start.py: -------------------------------------------------------------------------------- 1 | from mqtt_client import MQTTClient 2 | from timer import Timer 3 | from timeit import default_timer as timer 4 | import yaml 5 | import os 6 | import json 7 | from devices import display_device, display_input_entity 8 | import simpleddc 9 | 10 | class Service: 11 | def __init__(self): 12 | self.dt = 0 13 | 14 | try: 15 | with open("config.yml","r") as config: 16 | config = yaml.safe_load(config) 17 | except Exception as e: 18 | with open("rename_to_config.yml","r") as config: 19 | config = yaml.safe_load(config) 20 | 21 | self.mqtt = MQTTClient(config["mqtt"]["username"], 22 | config["mqtt"]["password"], 23 | config["mqtt"]["host"], 24 | config["mqtt"]["port"]) 25 | 26 | poll_interval = 20 if "interval" not in config else config["interval"] 27 | 28 | self.mqtt.delegate = self 29 | 30 | self.inputs = {} 31 | display_data = config['display'] 32 | 33 | print(display_data) 34 | 35 | self.inputs = {} 36 | 37 | for display in display_data: 38 | self.inputs[display['id']] = { "switches": [] } 39 | for input_name, input_code in display['inputs'].items(): 40 | self.create_display_switch(display['id'],input_name,input_code) 41 | 42 | self.timer = Timer(poll_interval, self) 43 | self.update_inputs_states() 44 | 45 | def update_inputs_states(self): 46 | for display_id in self.inputs.keys(): 47 | input_code = simpleddc.show_input(int(display_id)) 48 | 49 | print(f"Input code is {input_code}") 50 | 51 | for entry in self.inputs[display_id]["switches"]: 52 | if entry["code"] == input_code: 53 | self.mqtt.client.publish(entry["topic"], "true") 54 | entry["state"] = True 55 | else: 56 | self.mqtt.client.publish(entry["topic"], "false") 57 | entry["state"] = False 58 | 59 | def on_message(self, topic, payload): 60 | if payload =='OFF': 61 | return #do nothing 62 | 63 | if "command" in topic: 64 | self.activate_input_deactivate_rest(int(topic.split("/")[2]),topic.split("/")[3]) 65 | 66 | def activate_input_deactivate_rest(self, display_id,display_input): 67 | print(f"Display {display_id} name {display_input}") 68 | 69 | for entry in self.inputs[display_id]["switches"]: 70 | if entry["id"] == display_input: 71 | entry["state"] = True 72 | self.mqtt.client.publish(entry["topic"], "true") 73 | print(f'switching to {entry["code"]}') 74 | simpleddc.switch_to_input(display_id, int(entry["code"])) 75 | 76 | else: 77 | entry["state"] = False 78 | self.mqtt.client.publish(entry["topic"], "false") 79 | 80 | def on_timer(self, timer, elapsed): 81 | #check input states 82 | self.timer.reset() 83 | self.timer.active = True 84 | self.update_inputs_states() 85 | 86 | def step(self, dt): 87 | self.timer.step(dt) 88 | self.mqtt.step(dt) 89 | 90 | def create_display_switch(self, display_id, input_name, input_code): 91 | topic = display_input_entity["generic_switch"] 92 | topic = topic.replace("#", str(display_id)) 93 | topic = topic.replace("?", input_name) 94 | 95 | config = display_input_entity["generic_switch_config"].copy() 96 | config["unique_id"] = "{}_{}_switch".format(display_id,input_name) 97 | config["object_id"] = "{}_{}_switch".format(display_id,input_name) 98 | config["name"] = input_name 99 | config["state_topic"] = config["state_topic"].replace("#", str(display_id)) 100 | config["state_topic"] = config["state_topic"].replace("?", input_name) 101 | 102 | device = display_device.copy() 103 | device["name"] = device["name"].replace("?", input_name) 104 | device["model"] = "{}-{}".format(device["model"],display_id) 105 | config["device"] = device 106 | 107 | config["command_topic"] = config["command_topic"].replace("#", str(display_id)) 108 | config["command_topic"] = config["command_topic"].replace("?", input_name) 109 | 110 | self.mqtt.client.publish(config["availability_topic"],"online", retain=True) 111 | self.mqtt.client.publish(config["state_topic"], "off") 112 | self.mqtt.client.publish(topic, json.dumps(config), retain=True) 113 | 114 | self.mqtt.client.subscribe(config["command_topic"]) 115 | 116 | self.inputs[display_id]["switches"].append({"id": input_name, "topic": config["state_topic"], "config": config, "code": input_code, "state": False}) 117 | 118 | def start(self): 119 | while True: 120 | t0 = timer() 121 | self.step(self.dt) 122 | t1 = timer() 123 | self.dt = t1 - t0 124 | 125 | service = Service() 126 | service.start() -------------------------------------------------------------------------------- /ddc-mqtt/timer.py: -------------------------------------------------------------------------------- 1 | class Timer: 2 | def __init__(self, time, delegate): 3 | self.delegate = delegate 4 | self.time = time 5 | self.elapsed = 0 6 | self.active = True 7 | self.payload = None 8 | self.name = "" 9 | 10 | def step(self, dt): 11 | if not self.active: 12 | return 13 | self.elapsed += dt 14 | if self.elapsed >= self.time: 15 | self.active = False 16 | self.delegate.on_timer(self, self.elapsed) 17 | self.elapsed = 0 18 | 19 | def reset(self): 20 | self.elapsed = 0 -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.8' 2 | services: 3 | app: 4 | restart: unless-stopped 5 | build: . 6 | network_mode: "host" 7 | volumes: 8 | - .:/usr/src/app 9 | devices: 10 | - "/dev/i2c-20:/dev/i2c-20" 11 | - "/dev/i2c-21:/dev/i2c-21" 12 | environment: 13 | - PYTHONUNBUFFERED=1 14 | -------------------------------------------------------------------------------- /hass_display_kvm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moimart/ddc-mqtt/a908c0be7ae7c3af6b02123a7b4179c392ce5fdf/hass_display_kvm.jpg -------------------------------------------------------------------------------- /simpleddc-extension/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, Extension 2 | 3 | module = Extension('simpleddc', 4 | sources=['simpleddc.c', 'simpleddc-python.c'], 5 | libraries=['ddcutil'], 6 | library_dirs=['/usr/lib/aarch64-linux-gnu/libddcutil.so.4'], 7 | include_dirs=['/usr/include']) 8 | 9 | setup(name='simpleddc', 10 | version='1.0', 11 | ext_modules=[module]) 12 | -------------------------------------------------------------------------------- /simpleddc-extension/simple-ddc.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | DDCA_Display_Handle * open_first_display_by_dlist(); 10 | DDCA_Display_Handle * open_display_by_dlist(unsigned int display); 11 | DDCA_Status switch_input(DDCA_Display_Handle* handle, uint8_t input); 12 | uint8_t show_any_value( 13 | DDCA_Display_Handle dh, 14 | DDCA_Vcp_Value_Type value_type, 15 | DDCA_Vcp_Feature_Code feature_code); 16 | -------------------------------------------------------------------------------- /simpleddc-extension/simpleddc-python.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "simple-ddc.h" 3 | 4 | static PyObject* switch_to_input(PyObject* self, PyObject* args) { 5 | uint8_t* display = malloc(sizeof(uint8_t)); 6 | uint8_t* input = malloc(sizeof(uint8_t));; 7 | 8 | if (!PyArg_ParseTuple(args, "ii", display, input)) 9 | return NULL; 10 | 11 | DDCA_Display_Handle* handle = open_first_display_by_dlist(); 12 | switch_input(handle,*input); 13 | ddca_close_display(handle); 14 | 15 | free(display); 16 | free(input); 17 | 18 | Py_RETURN_NONE; 19 | } 20 | 21 | static PyObject* show_input(PyObject* self, PyObject* args) { 22 | uint8_t* display = malloc(sizeof(uint8_t)); 23 | 24 | if (!PyArg_ParseTuple(args, "i", display)) 25 | *display = 0; 26 | 27 | DDCA_Display_Handle* handle = open_display_by_dlist(*display); 28 | int result = show_any_value(handle,DDCA_NON_TABLE_VCP_VALUE, 0x60); 29 | ddca_close_display(handle); 30 | 31 | free(display); 32 | return PyLong_FromLong(result); 33 | } 34 | 35 | static PyMethodDef Methods[] = { 36 | {"switch_to_input", switch_to_input, METH_VARARGS, "Switch to input"}, 37 | {"show_input", show_input, METH_VARARGS, "Show input"}, 38 | {NULL, NULL, 0, NULL} /* Sentinel */ 39 | }; 40 | 41 | static struct PyModuleDef module = { 42 | PyModuleDef_HEAD_INIT, 43 | "simpleddc", 44 | NULL, /* module documentation, may be NULL */ 45 | -1, /* size of per-interpreter state of the module, 46 | or -1 if the module keeps state in global variables. */ 47 | Methods 48 | }; 49 | 50 | PyMODINIT_FUNC PyInit_simpleddc(void) { 51 | return PyModule_Create(&module); 52 | } 53 | -------------------------------------------------------------------------------- /simpleddc-extension/simpleddc.c: -------------------------------------------------------------------------------- 1 | #include "simple-ddc.h" 2 | 3 | #define DDC_ERRMSG(function_name,status_code) \ 4 | do { \ 5 | printf("(%s) %s() returned %d (%s): %s\n", \ 6 | __func__, function_name, status_code, \ 7 | ddca_rc_name(status_code), \ 8 | ddca_rc_desc(status_code)); \ 9 | } while(0) 10 | 11 | DDCA_Display_Handle * open_first_display_by_dlist() 12 | { 13 | printf("Check for monitors using ddca_get_displays()...\n"); 14 | DDCA_Display_Handle dh = NULL; 15 | 16 | // Inquire about detected monitors. 17 | DDCA_Display_Info_List* dlist = NULL; 18 | ddca_get_display_info_list2( 19 | false, // don't include invalid displays 20 | &dlist); 21 | 22 | if (dlist->ct == 0) { 23 | printf(" No DDC capable displays found\n"); 24 | } else { 25 | DDCA_Display_Info * dinf = &dlist->info[0]; 26 | DDCA_Display_Ref * dref = dinf->dref; 27 | printf("Opening display %s\n", dinf->model_name); 28 | printf("Model: %s\n", dinf->model_name); 29 | 30 | DDCA_Status rc = ddca_open_display2(dref, false, &dh); 31 | if (rc != 0) { 32 | DDC_ERRMSG("ddca_open_display2", rc); 33 | } 34 | } 35 | ddca_free_display_info_list(dlist); 36 | return dh; 37 | } 38 | 39 | DDCA_Display_Handle * open_display_by_dlist(unsigned int display) 40 | { 41 | DDCA_Display_Handle dh = NULL; 42 | 43 | // Inquire about detected monitors. 44 | DDCA_Display_Info_List* dlist = NULL; 45 | ddca_get_display_info_list2( 46 | false, // don't include invalid displays 47 | &dlist); 48 | 49 | if (dlist->ct == 0 || dlist->ct < display) { 50 | printf(" No DDC capable displays found\n"); 51 | } else { 52 | DDCA_Display_Info * dinf = &dlist->info[display - 1]; 53 | DDCA_Display_Ref * dref = dinf->dref; 54 | printf("Opening display %s\n", dinf->model_name); 55 | printf("Model: %s\n", dinf->model_name); 56 | 57 | DDCA_Status rc = ddca_open_display2(dref, false, &dh); 58 | if (rc != 0) { 59 | DDC_ERRMSG("ddca_open_display2", rc); 60 | } 61 | } 62 | ddca_free_display_info_list(dlist); 63 | return dh; 64 | } 65 | 66 | uint8_t show_any_value( 67 | DDCA_Display_Handle dh, 68 | DDCA_Vcp_Value_Type value_type, 69 | DDCA_Vcp_Feature_Code feature_code) 70 | { 71 | DDCA_Status ddcrc; 72 | DDCA_Any_Vcp_Value * valrec; 73 | 74 | ddcrc = ddca_get_any_vcp_value_using_explicit_type( 75 | dh, 76 | feature_code, 77 | value_type, 78 | &valrec); 79 | if (ddcrc != 0) { 80 | DDC_ERRMSG("ddca_get_any_vcp_value_using_explicit_type", ddcrc); 81 | goto bye; 82 | } 83 | 84 | if (valrec->value_type == DDCA_NON_TABLE_VCP_VALUE) { 85 | uint8_t ret_value = valrec->val.c_nc.sl; 86 | free(valrec); 87 | return ret_value; 88 | } 89 | else { 90 | assert(valrec->value_type == DDCA_TABLE_VCP_VALUE); 91 | printf("Table value: 0x"); 92 | for (int ndx=0; ndxval.t.bytect; ndx++) 93 | printf("%02x", valrec->val.t.bytes[ndx]); 94 | puts(""); 95 | } 96 | 97 | bye: 98 | if (valrec != NULL) 99 | free(valrec); 100 | return 0; 101 | } 102 | 103 | DDCA_Status switch_input(DDCA_Display_Handle* handle, uint8_t input) { 104 | bool saved_enable_verify = ddca_enable_verify(true); 105 | 106 | DDCA_Status ddcrc = ddca_set_non_table_vcp_value(handle,0x60, 0, input); 107 | 108 | if (ddcrc == DDCRC_VERIFY) { 109 | printf("Value verification failed. Current value is now:\n"); 110 | show_any_value(handle, DDCA_NON_TABLE_VCP_VALUE, 0x60); 111 | } 112 | else if (ddcrc != 0) { 113 | DDC_ERRMSG("ddca_set_non_table_vcp_value", ddcrc); 114 | } 115 | else { 116 | printf("Setting new value succeeded.\n"); 117 | } 118 | 119 | ddca_enable_verify(saved_enable_verify); 120 | return ddcrc; 121 | } 122 | --------------------------------------------------------------------------------