Skip to content

Commit

Permalink
Check the first few /dev/video nodes to find the platform
Browse files Browse the repository at this point in the history
It could happen that there's a USB cam plugged in, so /dev/video0
might not tell us which platform we are.

Signed-off-by: David Plowman <[email protected]>
  • Loading branch information
davidplowman committed Oct 6, 2023
1 parent a907876 commit 3d04990
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions picamera2/platform.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fcntl
import os
from enum import Enum

import v4l2
Expand All @@ -11,11 +12,18 @@ class Platform(Enum):

_platform = Platform.VC4
try:
with open('/dev/video0', 'rb+', buffering=0) as fd:
caps = v4l2.v4l2_capability()
fcntl.ioctl(fd, v4l2.VIDIOC_QUERYCAP, caps)
if caps.card.decode('utf-8') == "rp1-cfe":
_platform = Platform.PISP
for num in range(5):
device = '/dev/video' + str(num)
if os.path.exists(device):
with open(device, 'rb+', buffering=0) as fd:
caps = v4l2.v4l2_capability()
fcntl.ioctl(fd, v4l2.VIDIOC_QUERYCAP, caps)
decoded = caps.card.decode('utf-8')
if decoded == "rp1-cfe":
_platform = Platform.PISP
break
elif decoded == "unicam":
break
except Exception:
pass

Expand Down

0 comments on commit 3d04990

Please sign in to comment.