Skip to content

Commit

Permalink
Initial implementation of ButtonControl. Not yet tested, since I have
Browse files Browse the repository at this point in the history
no real device that provides a button control and trying vivid did
not work (see otaku42#17).
  • Loading branch information
otaku42 committed May 2, 2023
1 parent 654e47d commit da53ed6
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions v4l2py/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,26 @@ def __repr__(self):
def _get_repr(self) -> str:
return ""

def _get_control(self):
value = get_control(self.device, self.id)
return value

def _set_control(self, value):
if not self.is_writeable:
reasons = []
if self.is_flagged_read_only:
reasons.append("read-only")
if self.is_flagged_inactive:
reasons.append("inactive")
if self.is_flagged_disabled:
reasons.append("disabled")
if self.is_flagged_grabbed:
reasons.append("grabbed")
raise AttributeError(
f"{self.__class__.__name__} {self.config_name} is not writeable: {', '.join(reasons)}"
)
set_control(self.device, self.id, value)

@property
def config_name(self) -> str:
if self._config_name is None:
Expand Down Expand Up @@ -1003,7 +1023,7 @@ def default(self):
@property
def value(self):
if not self.is_flagged_write_only:
v = get_control(self.device, self.id)
v = self._get_control()
return self._convert_read(v)
else:
return None
Expand All @@ -1016,22 +1036,9 @@ def _mangle_write(self, value):

@value.setter
def value(self, value):
if not self.is_writeable:
reasons = []
if self.is_flagged_read_only:
reasons.append("read-only")
if self.is_flagged_inactive:
reasons.append("inactive")
if self.is_flagged_disabled:
reasons.append("disabled")
if self.is_flagged_grabbed:
reasons.append("grabbed")
raise AttributeError(
f"{self.__class__.__name__} {self.config_name} is not writeable: {', '.join(reasons)}"
)
v = self._convert_write(value)
v = self._mangle_write(v)
set_control(self.device, self.id, v)
self._set_control(v)

def set_to_default(self):
self.value = self.default
Expand Down Expand Up @@ -1189,6 +1196,11 @@ def _convert_write(self, value):
return int(value)


class ButtonControl(BaseControl):
def push(self):
self._set_control(1)


class BaseCompoundControl(BaseControl):
def __init__(self, device, info):
raise NotImplementedError()
Expand Down

0 comments on commit da53ed6

Please sign in to comment.