Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
project = pyproject["project"]["name"]
year = datetime.datetime.now().year
author = pyproject["project"]["authors"][0]["name"]
copyright = f"2019 - {year}, {author}"
copyright = f"2019 - {year}, {author}" # noqa: A001
version = pyproject["project"]["version"]
release = pyproject["project"]["version"]
language = "en"
Expand Down
22 changes: 11 additions & 11 deletions monitorcontrol/vcp/vcp_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ class VCPCode:
Args:
name: VCP code name.
value: VCP code value.
type: VCP code type.
code_type: VCP code type.
function: VCP code function.

Raises:
KeyError: VCP code not found.
"""

def __init__(self, name: str, value: int, type: str, function: str):
def __init__(self, name: str, value: int, code_type: str, function: str):
self.name = name
self.value = value
self.type = type
self.type = code_type
self.function = function

def __str__(self) -> str:
Expand Down Expand Up @@ -47,48 +47,48 @@ def writeable(self) -> bool:
image_factory_default = VCPCode(
name="restore factory default image",
value=0x04,
type="wo",
code_type="wo",
function="nc",
)
image_luminance = VCPCode(
name="image luminance",
value=0x10,
type="rw",
code_type="rw",
function="c",
)
image_contrast = VCPCode(
name="image contrast",
value=0x12,
type="rw",
code_type="rw",
function="c",
)
image_color_preset = VCPCode(
name="image color preset",
value=0x14,
type="rw",
code_type="rw",
function="nc",
)
active_control = VCPCode(
name="active control",
value=0x52,
type="ro",
code_type="ro",
function="nc",
)
input_select = VCPCode(
name="input select",
value=0x60,
type="rw",
code_type="rw",
function="nc",
)
image_orientation = VCPCode(
name="image orientation",
value=0xAA,
type="ro",
code_type="ro",
function="nc",
)
display_power_mode = VCPCode(
name="display power mode",
value=0xD6,
type="rw",
code_type="rw",
function="nc",
)
34 changes: 26 additions & 8 deletions monitorcontrol/vcp/vcp_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ def set_vcp_feature(self, code: int, value: int):
data.append(self.get_checksum(bytearray([self.DDCCI_ADDR << 1]) + data))

# write data
self.logger.debug("data=" + " ".join([f"{x:02X}" for x in data]))
self.logger.debug(
"data=",
extra=dict(data=" ".join([f"{x:02X}" for x in data])),
)
self.write_bytes(data)

# store time of last set VCP
Expand Down Expand Up @@ -156,18 +159,27 @@ def get_vcp_feature(self, code: int) -> Tuple[int, int]:
data.append(self.get_checksum(bytearray([self.DDCCI_ADDR << 1]) + data))

# write data
self.logger.debug("data=" + " ".join([f"{x:02X}" for x in data]))
self.logger.debug(
"data=",
extra=dict(data=" ".join([f"{x:02X}" for x in data])),
)
self.write_bytes(data)

time.sleep(self.GET_VCP_TIMEOUT)

# read the data
header = self.read_bytes(self.GET_VCP_HEADER_LENGTH)
self.logger.debug("header=" + " ".join([f"{x:02X}" for x in header]))
self.logger.debug(
"header={header}",
extra=dict(header=" ".join([f"{x:02X}" for x in header])),
)
source, length = struct.unpack("=BB", header)
length &= ~self.PROTOCOL_FLAG # clear protocol flag
payload = self.read_bytes(length + 1)
self.logger.debug("payload=" + " ".join([f"{x:02X}" for x in payload]))
self.logger.debug(
"payload={payload}",
extra=dict(payload=" ".join([f"{x:02X}" for x in payload])),
)

# check checksum
payload, checksum = struct.unpack(f"={length}sB", payload)
Expand Down Expand Up @@ -206,7 +218,7 @@ def get_vcp_feature(self, code: int) -> Tuple[int, int]:

return feature_current, feature_max

def get_vcp_capabilities(self):
def get_vcp_capabilities(self) -> str:
"""
Gets capabilities string from the virtual control panel.

Expand Down Expand Up @@ -255,11 +267,17 @@ def get_vcp_capabilities(self):

# read the data
header = self.read_bytes(self.GET_VCP_HEADER_LENGTH)
self.logger.debug("header=" + " ".join([f"{x:02X}" for x in header]))
self.logger.debug(
"header={header}",
extra=dict(header=" ".join([f"{x:02X}" for x in header])),
)
source, length = struct.unpack("BB", header)
length &= ~self.PROTOCOL_FLAG # clear protocol flag
payload = self.read_bytes(length + 1)
self.logger.debug("payload=" + " ".join([f"{x:02X}" for x in payload]))
self.logger.debug(
"payload={payload}",
extra=dict(payload=" ".join([f"{x:02X}" for x in payload])),
)

# check if length is valid
if length < 3 or length > 35:
Expand Down Expand Up @@ -297,7 +315,7 @@ def get_vcp_capabilities(self):
# update the offset and go again
offset += length

self.logger.debug(f"caps str={caps_str}")
self.logger.debug("caps str={caps_str}", extra=dict(caps_str=caps_str))

if loop_count >= loop_count_limit:
raise VCPIOError("Capabilities string incomplete or too long")
Expand Down
12 changes: 8 additions & 4 deletions monitorcontrol/vcp/vcp_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ def set_vcp_feature(self, code: int, value: int):
Raises:
VCPError: Failed to set VCP feature.
"""
self.logger.debug(f"SetVCPFeature(_, {code=}, {value=})")
self.logger.debug(
"SetVCPFeature(_, {code=}, {value=})",
extra=dict(code=code, value=value),
)
try:
if not ctypes.windll.dxva2.SetVCPFeature(
HANDLE(self.handle), BYTE(code), DWORD(value)
Expand All @@ -131,7 +134,8 @@ def get_vcp_feature(self, code: int) -> Tuple[int, int]:
feature_current = DWORD()
feature_max = DWORD()
self.logger.debug(
f"GetVCPFeatureAndVCPFeatureReply(_, {code=}, None, _, _)"
"GetVCPFeatureAndVCPFeatureReply(_, {code=}, None, _, _)",
extra=dict(code=code),
)
try:
if not ctypes.windll.dxva2.GetVCPFeatureAndVCPFeatureReply(
Expand All @@ -145,8 +149,8 @@ def get_vcp_feature(self, code: int) -> Tuple[int, int]:
except OSError as e:
raise VCPError("failed to get VCP feature") from e
self.logger.debug(
"GetVCPFeatureAndVCPFeatureReply -> "
f"({feature_current.value}, {feature_max.value})"
"GetVCPFeatureAndVCPFeatureReply -> ({feat_cur}, {feat_max})",
extra=dict(feat_cur=feature_current.value, feat_max=feature_max.value),
)
return feature_current.value, feature_max.value

Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ packages = ["monitorcontrol"]

[tool.ruff.lint]
extend-select = [
# flake8-builtins
"A",
# flake8-unused-arguments
"ARG",
# flake8-bugbear
"B",
# flake8-logging-format
"G",
# pep8-naming
"N",
]