def IsDetected(self): """Returns if the device can be detected.""" # Enables Bluetooth HID port controller. # Enables USB port device mode controller so USB host on the other side will # not get confused when trying to enumerate this USB device. self._usb_ctrl.EnableUSBOTGDriver() self._usb_ctrl.EnableDriver() # Our Bluetooth HID flow differs substantially from other flows. # Everything needed for IsDetected does the job of InitDevice: # Initialize a TTY, and report detecting it instead of a driver. # (Other USB flows simulate Plug/Unplug by Enabling/Diabling the driver.) # Ultimately, this is reasonable given that we expect the kit to stay # plugged in to chameleon, but Plug/Unplug for resetting the USB device # might be useful. # TODO(josephsih): Investigate plug/unplug for the Bluetooth HID Flow. try: common.WaitForCondition(lambda: bool(self._FindAndSetTty()), True, self.DETECT_INTERVAL_SECS, self.DETECT_TIMEOUT_SECS) return True except common.TimeoutError: logging.warn( "Did not detect bluetooth kit for %s before timing out.", self.__class__.__name__) return False
def WriteData(self, data): """Writes TX data. Args: data: TX data. """ if data > 0xffff: raise SpimError('Write data is over 16-bit long!! Input = 0x%x' % data) common.WaitForCondition(self._IsTxFifoEmpty, True, self._WAIT_DELAY, self._WAIT_TIMEOUT) self._memory.Write(self._base_addr + self._DR_OFFSET, data & 0xffff) common.WaitForCondition(self._IsTxFifoEmpty, True, self._WAIT_DELAY, self._WAIT_TIMEOUT) common.WaitForCondition(self._IsSpimBusy, False, self._WAIT_DELAY, self._WAIT_TIMEOUT)
def GetAudioRate(self): """Gets the audio rate in Hz.""" common.WaitForCondition(self.IsAudioInputStable, True, self._DELAY_AUDIO_STABLE_PROBE, self._TIMEOUT_AUDIO_STABLE_PROBE) rate_id = self.Get(self._REG_SAMPLE_RATE) & self._MASK_SAMPLE_RATE return self._SAMPLE_RATES[rate_id]
def WaitVideoOutputStable(self, timeout=None): """Waits the video output stable or timeout.""" if timeout is None: timeout = self._TIMEOUT_VIDEO_STABLE_PROBE try: common.WaitForCondition(self._IsFrameLocked, True, self._DELAY_VIDEO_MODE_PROBE, timeout) except common.TimeoutError: return False return True
def _WaitForFieldCount(self, field_count, timeout): """Waits until the given field_count reached or timeout. Args: field_count: A number of fields to wait. timeout: Time in second of timeout. """ self._last_field.value = 0 # Give the lambda method a better name, for debugging. func = lambda: self._HasFieldsDumpedAtLeast(field_count) func.__name__ = 'HasFieldsDumpedAtLeast%d' % field_count common.WaitForCondition(func, True, self._DELAY_VIDEO_DUMP_PROBE, timeout)
def WaitVideoInputStable(self, timeout=None): """Waits the video input stable or timeout. Returns: True if the video input is stable before timeout; otherwise, False. """ if timeout is None: timeout = self._TIMEOUT_VIDEO_STABLE_PROBE try: common.WaitForCondition(self.IsVideoInputStable, True, self._DELAY_VIDEO_MODE_PROBE, timeout) return True except common.TimeoutError: return False
def WaitVideoInputStable(self, timeout=None): """Waits the video input stable or timeout. Returns: True if the video input is stable before timeout; otherwise, False. """ if timeout is None: timeout = self._TIMEOUT_CHECKING_STABLE try: # Check if H-Sync/V-Sync recevied from the source. common.WaitForCondition( self.IsSyncDetected and self.IsValidVGAMode, True, self._DELAY_CHECKING_STABLE_PROBE, timeout) except common.TimeoutError: return False return True
def WaitVideoOutputStable(self, timeout=None): """Waits the video output stable or timeout. Raises: InputFlowError if timeout. """ if timeout is None: timeout = self._TIMEOUT_VIDEO_STABLE_PROBE try: common.WaitForCondition(self._IsFrameLocked, True, self._DELAY_VIDEO_MODE_PROBE, timeout) except common.TimeoutError: message = 'Timeout waiting video output stable' logging.error(message) logging.error('RX dump: %r', self._rx.Get(0, 256)) raise InputFlowError(message)
def WaitVideoOutputStable(self, timeout=None): """Waits the video output stable or timeout. Raises: InputFlowError if timeout. """ if timeout is None: timeout = self._TIMEOUT_CHECKING_STABLE try: # Wait a valid resolution and not floating. common.WaitForCondition(self._IsResolutionValid, True, self._DELAY_CHECKING_STABLE_PROBE, timeout) except common.TimeoutError: message = 'Timeout waiting video output stable' logging.error(message) logging.error('RX dump: %r', self._rx.Get(0, 256)) raise InputFlowError(message)
def GetAudioChannels(self): """Returns the number of received audio channels.""" common.WaitForCondition(self.IsAudioInputStable, True, self._DELAY_AUDIO_STABLE_PROBE, self._TIMEOUT_AUDIO_STABLE_PROBE) return (self.Get(self._REG_CHANNELS) & self._MASK_CHANNELS) + 1