Skip to content

Commit

Permalink
Parse text as utf-8
Browse files Browse the repository at this point in the history
Apparently some cameras return utf-8 strings. This should be backwards
compatible with ascii so no need to try both.

Ref: #11
  • Loading branch information
tgorochowik committed May 2, 2022
1 parent 7b161c7 commit 19108c3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pyvidctrl/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def query_v4l2_ctrls(dev):
break

if ctrl.type == V4L2_CTRL_TYPE_CTRL_CLASS:
current_class = ctrl.name.decode("ascii")
current_class = ctrl.name.decode("utf-8")
controls[current_class] = []

controls[current_class].append(ctrl)
Expand Down Expand Up @@ -203,7 +203,7 @@ def on_keypress(self, key):

def store_ctrls(self):
driver = query_driver(self.device)
fname = ".pyvidctrl-" + driver.decode("ascii")
fname = ".pyvidctrl-" + driver.decode("utf-8")

if not hasattr(self, "video_controller_tabs"):
print(f"WARNING: Device {driver.decode('ascii')} has no controls")
Expand All @@ -228,7 +228,7 @@ def store_ctrls(self):

def restore_ctrls(self):
driver = query_driver(self.device)
fname = ".pyvidctrl-" + driver.decode("ascii")
fname = ".pyvidctrl-" + driver.decode("utf-8")

try:
with open(fname, "r") as fd:
Expand Down
8 changes: 4 additions & 4 deletions pyvidctrl/ctrl_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, device, ctrl):
self.device = device
self.ctrl = ctrl

self.name = ctrl.name.decode("ascii")
self.name = ctrl.name.decode("utf-8")
self.label = Label(self.name)
self.widget = Label("Not implemented!", align="center")

Expand Down Expand Up @@ -231,7 +231,7 @@ def __init__(self, device, ctrl):
querymenu.index = i
try:
ioctl(device, VIDIOC_QUERYMENU, querymenu)
options[i] = querymenu.name.decode("ascii")
options[i] = querymenu.name.decode("utf-8")
except OSError:
# querymenu can fail for given index, but there can
# still be more valid indexes
Expand Down Expand Up @@ -417,7 +417,7 @@ def value(self):
except OSError:
return None

return ectrl.string.decode("ascii")
return ectrl.string.decode("utf-8")

@value.setter
def value(self, value):
Expand All @@ -427,7 +427,7 @@ def value(self, value):

ectrl = v4l2_ext_control()
ectrl.id = self.ctrl.id
ectrl.string = value.encode("ascii")
ectrl.string = value.encode("utf-8")
ectrl.size = self.ctrl.elem_size

ectrls = v4l2_ext_controls()
Expand Down

0 comments on commit 19108c3

Please sign in to comment.