def turn_on_light_with_scenario(self, operations: List[LightOperation], repeat_count: int = 0): if self._light_characteristic: return self._light_characteristic.turn_on_light_with_scenario( operations, repeat_count) else: raise ToioException("light_characteristic is null")
def play_sound(self, operations: List[SoundOperation], repeat_count: int = 0): if self._sound_characteristic: return self._sound_characteristic.play_sound( operations, repeat_count) else: raise ToioException("sound_characteristic is null")
def discover(self, provider): set_timeout(lambda: None, NearestScanner.SCAN_WINDOW_MS) peripherals = provider.find_devices([Cube.TOIO_SERVICE_ID]) if peripherals is None: raise ToioException("Failed to find device") peripherals = peripherals if type(peripherals) is list else [ peripherals ] print("{0} device discover".format(len(peripherals))) for peripheral in peripherals: if "toio" in peripheral.name: peripheral.connect() set_timeout(lambda: None, NearestScanner.SCAN_WINDOW_MS) peripheral._peripheral.readRSSI() if not peripheral._rssi_read.wait( NearestScanner.SCAN_WINDOW_MS / 1000): raise RuntimeError( "Exceeded timeout waiting for RSSI value!") if (self._nearest_peripheral is None or peripheral._rssi > self._nearest_peripheral._rssi): self._nearest_peripheral = peripheral set_timeout(lambda: None, NearestScanner.SCAN_WINDOW_MS) print("discovered")
def move(self, left: int, right: int, duration: int): if self._motor_characteristic: self._motor_characteristic.move(left, right, duration) else: raise ToioException("motor_characteristic is null")
def get_ble_protocol_version(self): if self._configuration_characteristic: return self._configuration_characteristic.get_ble_protocol_version( ) else: raise ToioException("configuration_characteristic is null")
def set_collision_threshold(self, threshold: int): if self._configuration_characteristic: self._configuration_characteristic.set_collision_threshold( threshold) else: raise ToioException("configuration_characteristic is null")
def get_button_status(self) -> Optional[ButtonTypeData]: if self._button_characteristic: return self._button_characteristic.get_button_status() else: raise ToioException("button_characteristic is null")
def get_battery_status(self) -> Optional[BatteryTypeData]: if self._battery_characteristic: return self._battery_characteristic.get_battery_status() else: raise ToioException("battery_characteristic is null")
def get_double_tap_status(self) -> Optional[SensorTypeData]: if self._sensor_characteristic: return self._sensor_characteristic.get_double_tap_status() else: raise ToioException("sensor_characteristic is null")
def get_orientation(self) -> Optional[SensorTypeData]: if self._sensor_characteristic: return self._sensor_characteristic.get_orientation() else: raise ToioException("sensor_characteristic is null")
def executor(self) -> Cube: if self._nearest_peripheral is None: raise ToioException("Failed to find device") return Cube(self._nearest_peripheral)
def stop_sound(self): if self._sound_characteristic: return self._sound_characteristic.stop_sound() else: raise ToioException("sound_characteristic is null")
def play_preset_sound(self, sound_id: int): if self._sound_characteristic: return self._sound_characteristic.play_preset_sound(sound_id) else: raise ToioException("sound_characteristic is null")
def turn_off_light(self): if self._light_characteristic: return self._light_characteristic.turn_off_light() else: raise ToioException("light_characteristic is null")
def move_to(self, targets, options=MoveToOptions(0, 115, 0, 0, True)): if self._motor_characteristic: self._motor_characteristic.move_to(targets, options) else: raise ToioException("motor_characteristic is null")
def turn_on_light(self, operation: LightOperation): if self._light_characteristic: return self._light_characteristic.turn_on_light(operation) else: raise ToioException("light_characteristic is null")
def stop(self): if self._motor_characteristic: self._motor_characteristic.stop() else: raise ToioException("motor_characteristic is null")