Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Suggestion: allow brute forcing ddcutil commands to "fix" issues on Samsung displays #28

Open
pacjo opened this issue Jun 1, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@pacjo
Copy link

pacjo commented Jun 1, 2023

Hi there, this one will require some explanation.
So I have an older Samsung monitor, specifically 24" CF390. The issue is that DDC/CI communication works sporadically (it's just nowhere near consistent) (similar issue here).

So, the fix:
If you try enough times, at some point, you will get a proper output. As such running all ddcutil commands until one is successful fixes the issue with my display. I did a very basic modification your code and it works. However I'm not experienced enough to implement this properly, so this issue.

If this would be implemented, something like --force option could be used with ddcci_plasmoid_backend to enable this functionality.

my code (only subprocess_wrapper and async_subprocess_wrapper require modification):

# Wrap sync and async subprocess calls for mocking
def subprocess_wrapper(cmd: str) -> CommandOutput:
    logger.debug('Execute command: `' + cmd + '`')
    proc = subprocess.run(cmd.split(' '), capture_output=True)
    stdout = proc.stdout.decode()
    while "DDC communication failed" in stdout:
        proc = subprocess.run(cmd.split(' '), capture_output=True)
        stdout = proc.stdout.decode()
        #print(stdout)
        stderr = proc.stderr.decode()
        command_output = {
            'returnCode': proc.returncode,
            'stdout': stdout,
            'stderr': stderr,
        }

    log_subprocess_output(cmd, command_output)
    if proc.returncode > 0:
        raise subprocess.CalledProcessError(returncode=proc.returncode, cmd=cmd, output=stdout, stderr=stderr)
    return command_output


async def async_subprocess_wrapper(cmd: str) -> CommandOutput:
    logger.debug('Execute command: `' + cmd + '`')
    proc = await asyncio.subprocess.create_subprocess_shell(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    # it's safe to assume that the return code is not None at this point
    return_code: int = 1 if proc.returncode is None else proc.returncode
    stdout, stderr = await proc.communicate()
    stdout = stdout.decode()
    while "DDC communication failed" in stdout:
        proc = await asyncio.subprocess.create_subprocess_shell(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        # it's safe to assume that the return code is not None at this point
        return_code: int = 1 if proc.returncode is None else proc.returncode
        stdout, stderr = await proc.communicate()
        stdout = stdout.decode()
        stderr = stderr.decode()
        command_output = {
            'returnCode': return_code,
            'stdout': stdout,
            'stderr': stderr,
        }

    log_subprocess_output(cmd, command_output)
    if proc.returncode > 0:
        raise subprocess.CalledProcessError(returncode=proc.returncode, cmd=cmd, output=stdout, stderr=stderr)
    return command_output
@davidhi7 davidhi7 added enhancement New feature or request v0.2 labels Jul 20, 2023
@davidhi7
Copy link
Owner

Will be part of the next major release

@davidhi7 davidhi7 removed the v1.0.0 label Jan 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants