11from digit_interface .digit import Digit
2- from rcs .camera .hw import BaseHardwareCameraSet , HWCameraSetConfig
2+ from rcs ._core .common import BaseCameraConfig
3+ from rcs .camera .hw import HardwareCamera
34from rcs .camera .interface import CameraFrame , DataFrame , Frame
45
56
6- class DigitConfig (HWCameraSetConfig ):
7- """
8- Configuration for the DIGIT device.
9- This class is used to define the settings for the DIGIT device.
10- """
11-
12- stream_name : str = "QVGA" # options: "QVGA" (60 and 30 fps), "VGA" (30 and 15 fps)
13-
14-
15- class DigitCam (BaseHardwareCameraSet ):
7+ class DigitCam (HardwareCamera ):
168 """
179 This module provides an interface to interact with the DIGIT device.
1810 It allows for connecting to the device, changing settings, and retrieving information.
1911 """
2012
21- def __init__ (self , cfg : DigitConfig ):
22- self ._cfg = cfg
23- super (). __init__ ( )
13+ def __init__ (self , cameras : dict [ str , BaseCameraConfig ] ):
14+ self .cameras = cameras
15+ self . _camera_names = list ( self . cameras . keys () )
2416 self ._cameras : dict [str , Digit ] = {}
25- self .initalize (self .config )
2617
27- def initalize (self , cfg : HWCameraSetConfig ):
18+ def open (self ):
2819 """
2920 Initialize the digit interface with the given configuration.
3021 :param cfg: Configuration for the DIGIT device.
3122 """
32- for name , serial in cfg . name_to_identifier .items ():
33- digit = Digit (serial , name )
23+ for name , camera in self . cameras .items ():
24+ digit = Digit (camera . identifier , name )
3425 digit .connect ()
3526 self ._cameras [name ] = digit
3627
37- def _poll_frame (self , camera_name : str ) -> Frame :
28+ @property
29+ def camera_names (self ) -> list [str ]:
30+ """Returns the names of the cameras in this set."""
31+ return self ._camera_names
32+
33+ def poll_frame (self , camera_name : str ) -> Frame :
3834 """Polls the frame from the camera with the given name."""
3935 digit = self ._cameras [camera_name ]
4036 frame = digit .get_frame ()
@@ -45,6 +41,13 @@ def _poll_frame(self, camera_name: str) -> Frame:
4541
4642 return Frame (camera = cf )
4743
48- @property
49- def config (self ) -> DigitConfig :
50- return self ._cfg
44+ def close (self ):
45+ """
46+ Closes the connection to the DIGIT device.
47+ """
48+ for digit in self ._cameras .values ():
49+ digit .disconnect ()
50+ self ._cameras = {}
51+
52+ def config (self , camera_name ) -> BaseCameraConfig :
53+ return self .cameras [camera_name ]
0 commit comments