toio.cube package

class toio.cube.ToioCoreCube(interface: CubeInterface, name: str | None = None)[source]

Bases: CubeInterface

Access to toio Core Cube

interface

control interface (e.g. BleCube)

Type:

CubeInterface

name

cube name (optional)

Type:

str

api

API class

Type:

ToioCoreCubeLowLevelAPI

__init__(interface: CubeInterface, name: str | None = None)[source]
async connect() bool[source]
async disconnect() bool[source]
async read(uuid: UUID) bytearray[source]
async write(uuid: UUID, data: bytes | bytearray | memoryview, response: bool = False)[source]
async register_notification_handler(uuid: UUID, handler: Callable[[BleakGATTCharacteristic, bytearray], None | Awaitable[None]]) bool[source]
async unregister_notification_handler(uuid: UUID) bool[source]
class toio.cube.ToioCoreCubeLowLevelAPI(interface: CubeInterface)[source]

Bases: object

Control APIs This class has control APIs for each characteristic.

version

Version of supported API

Type:

str

battery

Interface to battery characteristic

Type:

api.Battery

button

Interface to button characteristic

Type:

api.Button

configuration

Interface to configuration characteristic

Type:

api.Configuration

id_information

Interface to id information characteristic

Type:

api.IdInformation

indicator

Interface to indicator characteristic

Type:

api.IdInformation

motor

Interface to motor characteristic

Type:

api.Motor

sensor

Interface to sensor characteristic ( Motion Posture Magnet )

Type:

api.Sensor

sound

Interface to sound characteristic

Type:

api.Sound

__init__(interface: CubeInterface)[source]
toio.cube.BatteryResponseType

alias of BatteryInformation

class toio.cube.BatteryInformation(payload: bytearray)[source]

Bases: CubeResponse

Cube remaining battery level response

battery_level

Battery level ( 0 <= battery_level <= 100)

Type:

int

References

https://toio.github.io/toio-spec/en/docs/ble_battery#read-operations

static is_myself(payload: bytearray) bool[source]

If argument data is a byte representation of this class, this function converts the byte representation to an object and returns it.

Parameters:

data (GattReadData) – received data from the cube.

__init__(payload: bytearray)[source]
__str__() str[source]

Return str(self).

class toio.cube.Battery(interface)[source]

Bases: CubeCharacteristic

Battery characteristic

References

https://toio.github.io/toio-spec/en/docs/ble_battery

static is_my_data(payload: bytearray) BatteryInformation | None[source]

If payload is my characteristic response, this function returns CubeResponse object. Otherwise, it returns None.

Parameters:

payload (GattReadData) – received data from the cube.

__init__(interface)[source]
async read() BatteryInformation | None[source]

Read the battery level

Returns:

BatteryInformation or None (None returns when read fails)

References

https://toio.github.io/toio-spec/en/docs/ble_battery#read-operations

toio.cube.ButtonResponseType

alias of ButtonInformation

class toio.cube.ButtonState(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Value of the state of cube button

RELEASED = 0
PRESSED = 128
class toio.cube.ButtonInformation(payload: bytearray)[source]

Bases: CubeResponse

Cube button state response

state

State of the cube button

Type:

ButtonState

References

https://toio.github.io/toio-spec/en/docs/ble_button#read-operations

static is_myself(payload: bytearray) bool[source]

If argument data is a byte representation of this class, this function converts the byte representation to an object and returns it.

Parameters:

data (GattReadData) – received data from the cube.

__init__(payload: bytearray)[source]
__str__() str[source]

Return str(self).

class toio.cube.Button(interface: CubeInterface)[source]

Bases: CubeCharacteristic

Button characteristic

References

https://toio.github.io/toio-spec/en/docs/ble_button

static is_my_data(payload: bytearray) ButtonInformation | None[source]

If payload is my characteristic response, this function returns CubeResponse object. Otherwise, it returns None.

Parameters:

payload (GattReadData) – received data from the cube.

__init__(interface: CubeInterface)[source]
async read() ButtonInformation | None[source]

Read the state of button

Returns:

ButtonInformation or None (None returns when read fails)

References

https://toio.github.io/toio-spec/en/docs/ble_button#read-operations

class toio.cube.NotificationCondition(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Notification conditions of ID notification

References

https://toio.github.io/toio-spec/en/docs/ble_configuration#notification-conditions

Always = 0
ChangeDetection = 1
Periodic = 255
class toio.cube.MagneticSensorFunction(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Disable = 0
MagnetState = 1
MagneticForce = 2
class toio.cube.MagneticSensorCondition(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Always = 0
ChangeDetection = 1
class toio.cube.MotorSpeedInformationAcquisitionState(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Disable = 0
Enable = 1
class toio.cube.PostureAngleDetectionType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Euler = 1
Quaternions = 2
class toio.cube.PostureAngleDetectionCondition(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Notification condition of posture angle detection

References

https://toio.github.io/toio-spec/en/docs/ble_configuration#notification-conditions-1

Always = 0
ChangeDetection = 1
class toio.cube.ProtocolVersion(payload: bytearray)[source]

Bases: CubeResponse

Protocol version response

version

version (UTF-8)

Type:

str

References

https://toio.github.io/toio-spec/en/docs/ble_configuration#obtaining-the-ble-protocol-version

static is_myself(payload: bytearray) bool[source]

If argument data is a byte representation of this class, this function converts the byte representation to an object and returns it.

Parameters:

data (GattReadData) – received data from the cube.

__init__(payload: bytearray)[source]
__str__() str[source]

Return str(self).

class toio.cube.ResponseIdNotificationSettings(payload: bytearray)[source]

Bases: CubeResponse

ID notification setting response

result

Result of the command

Type:

bool

References

https://toio.github.io/toio-spec/en/docs/ble_configuration#responses-to-identification-sensor-id-notification-settings

static is_myself(payload: bytearray) bool[source]

If argument data is a byte representation of this class, this function converts the byte representation to an object and returns it.

Parameters:

data (GattReadData) – received data from the cube.

__init__(payload: bytearray)[source]
__str__() str[source]

Return str(self).

class toio.cube.ResponseIdMissedNotificationSettings(payload: bytearray)[source]

Bases: CubeResponse

ID missed notification setting response

result

Result of the command

Type:

bool

References

https://toio.github.io/toio-spec/en/docs/ble_configuration#responses-to-identification-sensor-id-missed-notification-settings

static is_myself(payload: bytearray) bool[source]

If argument data is a byte representation of this class, this function converts the byte representation to an object and returns it.

Parameters:

data (GattReadData) – received data from the cube.

__init__(payload: bytearray)[source]
__str__() str[source]

Return str(self).

class toio.cube.ResponseMagneticSensorSettings(payload: bytearray)[source]

Bases: CubeResponse

Magnetic sensor setting response

result

Result of the command

Type:

bool

References

https://toio.github.io/toio-spec/en/docs/ble_configuration#responses-to-magnetic-sensor-settings

static is_myself(payload: bytearray) bool[source]

If argument data is a byte representation of this class, this function converts the byte representation to an object and returns it.

Parameters:

data (GattReadData) – received data from the cube.

__init__(payload: bytearray)[source]
__str__() str[source]

Return str(self).

class toio.cube.ResponseMotorSpeedInformationAcquisitionSettings(payload: bytearray)[source]

Bases: CubeResponse

Motor speed information setting response

result

Result of the command

Type:

bool

References

https://toio.github.io/toio-spec/en/docs/ble_configuration#responses-to-motor-speed-information-acquisition-settings

static is_myself(payload: bytearray) bool[source]

If argument data is a byte representation of this class, this function converts the byte representation to an object and returns it.

Parameters:

data (GattReadData) – received data from the cube.

__init__(payload: bytearray)[source]
__str__() str[source]

Return str(self).

class toio.cube.ResponsePostureAngleDetectionSettings(payload: bytearray)[source]

Bases: CubeResponse

Posture angle detection setting response

result

Result of the command

Type:

bool

References

https://toio.github.io/toio-spec/en/docs/ble_configuration#responses-to-posture-angle-detection-settings-

static is_myself(payload: bytearray) bool[source]

If argument data is a byte representation of this class, this function converts the byte representation to an object and returns it.

Parameters:

data (GattReadData) – received data from the cube.

__init__(payload: bytearray)[source]
__str__() str[source]

Return str(self).

class toio.cube.Configuration(interface: CubeInterface)[source]

Bases: CubeCharacteristic

Configuration characteristic

References

https://toio.github.io/toio-spec/en/docs/ble_configuration

static is_my_data(payload: bytearray) ProtocolVersion | ResponseIdNotificationSettings | ResponseIdMissedNotificationSettings | ResponseMagneticSensorSettings | ResponseMotorSpeedInformationAcquisitionSettings | ResponsePostureAngleDetectionSettings | None[source]

If payload is my characteristic response, this function returns CubeResponse object. Otherwise, it returns None.

Parameters:

payload (GattReadData) – received data from the cube.

__init__(interface: CubeInterface) None[source]
async request_protocol_version() None[source]

Send protocol version request command

This function DO NOT return response payload. Receive the result by notification.

References

https://toio.github.io/toio-spec/en/docs/ble_configuration#requesting-the-ble-protocol-version

async set_horizontal_detection_threshold(threshold: int) None[source]

Send horizontal detection threshold setting command

This function DO NOT return response payload. Receive the result by notification.

Parameters:

threshold (int) – Threshold

References

https://toio.github.io/toio-spec/en/docs/ble_configuration#horizontal-detection-threshold-settings

async set_collision_detection_threshold(threshold: int) None[source]

Send collision detection threshold setting request command

This function DO NOT return response payload. Receive the result by notification.

Parameters:

threshold (int) – Threshold

References

https://toio.github.io/toio-spec/en/docs/ble_configuration#collision-detection-threshold-settings

async set_double_tap_detection_threshold(threshold: int) None[source]

Send double-tap detection threshold setting request command

This function DO NOT return response payload. Receive the result by notification.

Parameters:

threshold (int) – Threshold

References

https://toio.github.io/toio-spec/en/docs/ble_configuration#double-tap-detection-time-interval-settings

async set_id_notification(interval_ms: int, condition: NotificationCondition) None[source]

Send id information notification setting request command

This function DO NOT return response payload. Receive the result by notification.

Parameters:

References

https://toio.github.io/toio-spec/en/docs/ble_configuration#identification-sensor-id-notification-settings

async set_id_missed_notification(sensitivity_ms: int) None[source]

Send ID missed notification setting request command

This function DO NOT return response payload. Receive the result by notification.

Parameters:

sensitivity_ms (int) – Sensitivity [ms]

References

https://toio.github.io/toio-spec/en/docs/ble_configuration#identification-sensor-id-missed-notification-settings

async set_magnetic_sensor(function_type: MagneticSensorFunction, interval_ms: int, condition: MagneticSensorCondition) None[source]

Send magnetic sensor setting request command

This function DO NOT return response payload. Receive the result by notification.

Parameters:

References

https://toio.github.io/toio-spec/en/docs/ble_configuration#magnetic-sensor-settings-

async set_motor_speed_information_acquisition(state: MotorSpeedInformationAcquisitionState) None[source]

Send motor speed information acquisition setting request command

This function DO NOT return response payload. Receive the result by notification.

Parameters:

state (MotorSpeedInformationAcquisitionState) – state

References

https://toio.github.io/toio-spec/en/docs/ble_configuration#motor-speed-information-acquisition-settings

async set_posture_angle_detection(detection_type: PostureAngleDetectionType, interval_ms: int, condition: PostureAngleDetectionCondition) None[source]

Send posture angle setting request command

This function DO NOT return response payload. Receive the result by notification.

Parameters:

References

https://toio.github.io/toio-spec/en/docs/ble_configuration#posture-angle-detection-settings-

class toio.cube.PositionId(payload: bytearray)[source]

Bases: CubeResponse

Position id information response

References

https://toio.github.io/toio-spec/en/docs/ble_id#position-id

static is_myself(payload: bytearray) bool[source]

If argument data is a byte representation of this class, this function converts the byte representation to an object and returns it.

Parameters:

data (GattReadData) – received data from the cube.

__init__(payload: bytearray)[source]
__str__() str[source]

Return str(self).

class toio.cube.StandardId(payload: bytearray)[source]

Bases: CubeResponse

Standard id information response

References

https://toio.github.io/toio-spec/en/docs/ble_id#standard-id

static is_myself(data: bytearray) bool[source]

If argument data is a byte representation of this class, this function converts the byte representation to an object and returns it.

Parameters:

data (GattReadData) – received data from the cube.

__init__(payload: bytearray)[source]
__str__() str[source]

Return str(self).

class toio.cube.PositionIdMissed(payload: bytearray)[source]

Bases: CubeResponse

Position id missed response

References

https://toio.github.io/toio-spec/en/docs/ble_id#position-id-missed

static is_myself(data: bytearray) bool[source]

If argument data is a byte representation of this class, this function converts the byte representation to an object and returns it.

Parameters:

data (GattReadData) – received data from the cube.

__init__(payload: bytearray)[source]
__str__() str[source]

Return str(self).

class toio.cube.StandardIdMissed(payload: bytearray)[source]

Bases: CubeResponse

Standard id information response

References

https://toio.github.io/toio-spec/en/docs/ble_id#standard-id-missed

static is_myself(data: bytearray) bool[source]

If argument data is a byte representation of this class, this function converts the byte representation to an object and returns it.

Parameters:

data (GattReadData) – received data from the cube.

__init__(payload: bytearray)[source]
__str__() str[source]

Return str(self).

class toio.cube.IdInformation(interface: CubeInterface)[source]

Bases: CubeCharacteristic

ID sensor characteristic

References

https://toio.github.io/toio-spec/en/docs/ble_id

static is_my_data(payload: bytearray) PositionId | StandardId | PositionIdMissed | StandardIdMissed | None[source]

If payload is my characteristic response, this function returns CubeResponse object. Otherwise, it returns None.

Parameters:

payload (GattReadData) – received data from the cube.

__init__(interface: CubeInterface)[source]
async read() PositionId | StandardId | PositionIdMissed | StandardIdMissed | None[source]

Read id information response

Returns:

One of IdInformationData or None (None returns when read fails)

class toio.cube.Color(r: int, g: int, b: int)[source]

Bases: object

Indicator color in RGB

r: int

R value (0 - 255)

g: int

G value (0 - 255)

b: int

B value (0 - 255)

flatten()[source]

Return the tuple representation of this dataclass

__init__(r: int, g: int, b: int) None
class toio.cube.IndicatorParam(duration_ms: int, color: Color)[source]

Bases: object

Indicator color and lighting period

duration_ms: int
Duration of lighting:
Any fraction less than 10ms will be truncated.
0 - 9: no time limit
10 - 2550: duration [ms]
color: Color
RGB value
flatten()[source]
__init__(duration_ms: int, color: Color) None
class toio.cube.Indicator(interface: CubeInterface)[source]

Bases: CubeCharacteristic

Indicator characteristic

References

https://toio.github.io/toio-spec/en/docs/ble_light

static is_my_data(_payload: bytearray) None[source]

If payload is my characteristic response, this function returns CubeResponse object. Otherwise, it returns None.

Parameters:

payload (GattReadData) – received data from the cube.

__init__(interface: CubeInterface)[source]
async turn_on(param: IndicatorParam) None[source]

Send indicator turn on / off command

Parameters:

param – Indicator parameter

References

https://toio.github.io/toio-spec/en/docs/ble_light#repeated-turning-on-and-off-of-indicator

async repeated_turn_on(repeat: int, param_list: list[toio.cube.api.indicator.IndicatorParam] | tuple[toio.cube.api.indicator.IndicatorParam, ...]) None[source]

Send repeated indicator turning on / off command

Parameters:

References

https://toio.github.io/toio-spec/en/docs/ble_light#repeated-turning-on-and-off-of-indicator

async turn_off_all() None[source]

Send all off command

References

https://toio.github.io/toio-spec/en/docs/ble_light#turn-off-all-indicators

async turn_off(indicator_id: int) None[source]

Send off command

Parameters:

indicator_id (int) – Indicator ID

References

https://toio.github.io/toio-spec/en/docs/ble_light#turn-off-a-specific-indicator

class toio.cube.MovementType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Movement type

References

https://toio.github.io/toio-spec/en/docs/ble_motor#movement-type

Curve = 0
CurveWithoutReverse = 1
Linear = 2
class toio.cube.RotationOption(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Rotation Option

Angle of the cube at the target point

References

https://toio.github.io/toio-spec/en/docs/ble_motor#%CE%B8-angle-of-the-cube-at-the-target-point

AbsoluteOptimal = 0
AbsolutePositive = 1
AbsoluteNegative = 2
RelativePositive = 3
RelativeNegative = 4
WithoutRotation = 5
SameAsAtWriting = 6
class toio.cube.TargetPosition(cube_location: CubeLocation, rotation_option: RotationOption = RotationOption.AbsoluteOptimal)[source]

Bases: object

Target position parameter

cube_location: CubeLocation

Target position of the cube

rotation_option: RotationOption = 0

Rotation option

flatten()[source]
__init__(cube_location: CubeLocation, rotation_option: RotationOption = RotationOption.AbsoluteOptimal) None
class toio.cube.SpeedChangeType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Speed change type

References

https://toio.github.io/toio-spec/en/docs/ble_motor#motor-speed-change-types

Constant = 0
Acceleration = 1
Deceleration = 2
AccelerationAndDeceleration = 3
class toio.cube.Speed(max: int = 0, speed_change_type: SpeedChangeType = SpeedChangeType.Constant)[source]

Bases: object

Speed parameter

max: int = 0

Max speed

speed_change_type: SpeedChangeType = 0

Speed change type

flatten()[source]
__init__(max: int = 0, speed_change_type: SpeedChangeType = SpeedChangeType.Constant) None
class toio.cube.WriteMode(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Write mode of MotorControlMultipleTargets()

References

https://toio.github.io/toio-spec/en/docs/ble_motor#additional-write-operation-settings

Overwrite = 0
Append = 1
class toio.cube.AccelerationRotation(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Rotational direction when the cube is changing orientation

References

https://toio.github.io/toio-spec/en/docs/ble_motor/#rotational-direction-when-cube-changes-orientation

Positive = 0
Negative = 1
class toio.cube.AccelerationDirection(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Direction of cube travel

References

https://toio.github.io/toio-spec/en/docs/ble_motor/#direction-of-cube-travel

Forward = 0
Backward = 1
class toio.cube.AccelerationPriority(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Priority to the translational speed or the rotational velocity

References

https://toio.github.io/toio-spec/en/docs/ble_motor/#priority-designation

TranslationalVelocity = 0
RotationalVelocity = 1
class toio.cube.MotorResponseCode(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Response code of motor control APIs

References

https://toio.github.io/toio-spec/en/docs/ble_motor#response-content

SUCCESS = 0
ERROR_TIMEOUT = 1
ERROR_ID_MISSED = 2
ERROR_INVALID_PARAMETER = 3
ERROR_INVALID_CUBE_STATE = 4
SUCCESS_WITH_OVERWRITE = 5
ERROR_NOT_SUPPORTED = 6
ERROR_FAILED_TO_APPEND = 7
class toio.cube.ResponseMotorControlTarget(payload: bytearray)[source]

Bases: CubeResponse

Target specified motor control response

response_code

Response code

Type:

MotorResponseCode

References

https://toio.github.io/toio-spec/en/docs/ble_motor#responses-to-motor-control-with-target-specified

static is_myself(payload: bytearray) bool[source]

If argument data is a byte representation of this class, this function converts the byte representation to an object and returns it.

Parameters:

data (GattReadData) – received data from the cube.

__init__(payload: bytearray)[source]
__str__() str[source]

Return str(self).

class toio.cube.ResponseMotorControlMultipleTargets(payload: bytearray)[source]

Bases: CubeResponse

Multiple target specified motor control response

response_code

Response code

Type:

MotorResponseCode

References

https://toio.github.io/toio-spec/en/docs/ble_motor#responses-to-motor-control-with-multiple-targets-specified

static is_myself(payload: bytearray) bool[source]

If argument data is a byte representation of this class, this function converts the byte representation to an object and returns it.

Parameters:

data (GattReadData) – received data from the cube.

__init__(payload: bytearray)[source]
__str__() str[source]

Return str(self).

class toio.cube.ResponseMotorSpeed(payload: bytearray)[source]

Bases: CubeResponse

Motor speed response

left

motor speed (left)

Type:

int

right

motor speed (right)

Type:

int

References

https://toio.github.io/toio-spec/en/docs/ble_motor#obtaining-motor-speed-information

static is_myself(payload: bytearray) bool[source]

If argument data is a byte representation of this class, this function converts the byte representation to an object and returns it.

Parameters:

data (GattReadData) – received data from the cube.

__init__(payload: bytearray)[source]
__str__() str[source]

Return str(self).

class toio.cube.Motor(interface: CubeInterface)[source]

Bases: CubeCharacteristic

Motor characteristic

References

https://toio.github.io/toio-spec/en/docs/ble_motor

static is_my_data(payload: bytearray) ResponseMotorControlTarget | ResponseMotorControlMultipleTargets | ResponseMotorSpeed | None[source]

If payload is my characteristic response, this function returns CubeResponse object. Otherwise, it returns None.

Parameters:

payload (GattReadData) – received data from the cube.

__init__(interface: CubeInterface)[source]
async motor_control(left: int, right: int, duration_ms: int | None = None) None[source]

Send motor control command

Parameters:
  • left (int) – Motor speed (left)

  • right (int) – Motor speed (right)

  • duration_ms (Optional[int], optional) – Motor driving period [ms]. Defaults to None.

References

https://toio.github.io/toio-spec/en/docs/ble_motor#motor-control

async motor_control_target(timeout: int, movement_type: MovementType, speed: Speed, target: TargetPosition) None[source]

Send target specified motor control command

Parameters:
  • timeout (int) – Timeout [s] (Note: not [ms])

  • movement_type (MovementType) – Movement type

  • speed (Speed) – Speed parameter

  • target (TargetPosition) – Target parameter

References

https://toio.github.io/toio-spec/en/docs/ble_motor#motor-control-with-target-specified

async motor_control_multiple_targets(timeout: int, movement_type: MovementType, speed: Speed, mode: WriteMode, target_list: list[toio.cube.api.motor.TargetPosition]) None[source]

Send multiple target specified motor control command

Parameters:
  • timeout (int) – Timeout [s] (Note: not [ms])

  • movement_type (MovementType) – Movement type

  • speed (Speed) – Speed parameter

  • mode (WriteMode) – Write mode

  • target_list (list[TargetPosition]) – Target parameter

References

https://toio.github.io/toio-spec/en/docs/ble_motor#motor-control-with-multiple-targets-specified

async motor_control_acceleration(translation: int, acceleration: int, rotation_velocity: int, rotation_direction: AccelerationRotation, cube_direction: AccelerationDirection, priority: AccelerationPriority, duration_ms: int) None[source]

Send acceleration specified motor control command

Parameters:
  • translation (int) – Speed at which the cube moves in relation to the direction of travel.

  • acceleration (int) – Specify the increment (or decrement) in speed every 100 milliseconds.

  • rotation_velocity (int) – Rotational velocity when the cube is changing orientation.

  • rotation_direction (AccelerationRotation) – Rotational direction when the cube is changing orientation.

  • cube_direction (AccelerationDirection) – Direction the cube travels.

  • priority (AccelerationPriority) – Priority to the translational speed or the rotational velocity.

  • duration_ms (int) – Motor driving period [ms].

References

https://toio.github.io/toio-spec/en/docs/ble_motor/#motor-control-with-acceleration-specified

class toio.cube.PostureDataType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Euler = 1
Quaternions = 2
class toio.cube.Posture(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Orientation of the cube.

Reference:

https://toio.github.io/toio-spec/en/docs/ble_sensor/#posture-detection

Unknown = 0
Top = 1
Bottom = 2
Rear = 3
Front = 4
Right = 5
Left = 6
class toio.cube.MotionDetectionData(payload: bytearray)[source]

Bases: CubeResponse

Information on the cube’s motion detection.

horizontal

Horizontal detection

Type:

bool

collision

Collision detection

Type:

bool

double_tap

Double-tap detection

Type:

bool

posture

Posture detection

Type:

Posture

shake

Shake detection (0:no shake, 1:Level1 - 10:Level10)

Type:

int

Reference:

https://toio.github.io/toio-spec/en/docs/ble_sensor/#obtaining-motion-detection-information

static is_myself(payload: bytearray) bool[source]

If argument data is a byte representation of this class, this function converts the byte representation to an object and returns it.

Parameters:

data (GattReadData) – received data from the cube.

__init__(payload: bytearray)[source]
__str__() str[source]

Return str(self).

class toio.cube.PostureAngleEulerData(payload: bytearray)[source]

Bases: CubeResponse

Information of posture angle (Euler angle)

roll

Roll (X axis)

Type:

int

pitch

Pitch (Y axis)

Type:

int

yaw

Yaw (Z axis)

Type:

nt

References

https://toio.github.io/toio-spec/en/docs/ble_high_precision_tilt_sensor#obtaining-posture-angle-information-notifications-in-euler-angles

static is_myself(payload: bytearray) bool[source]

If argument data is a byte representation of this class, this function converts the byte representation to an object and returns it.

Parameters:

data (GattReadData) – received data from the cube.

__init__(payload: bytearray)[source]
__str__() str[source]

Return str(self).

class toio.cube.PostureAngleQuaternionsData(payload: bytearray)[source]

Bases: CubeResponse

PostureAngleQuaternionData

Information of posture angle (Quaternion)

w
Type:

int

x
Type:

int

y
Type:

int

z
Type:

int

References

https://toio.github.io/toio-spec/en/docs/ble_high_precision_tilt_sensor#obtaining-posture-angle-information-notifications-in-quaternions

static is_myself(payload: bytearray) bool[source]

If argument data is a byte representation of this class, this function converts the byte representation to an object and returns it.

Parameters:

data (GattReadData) – received data from the cube.

__init__(payload: bytearray)[source]
__str__() str[source]

Return str(self).

class toio.cube.MagneticSensorData(payload: bytearray)[source]

Bases: CubeResponse

Information of magnetic sensor

state

Magnet state

Type:

int

strength

Magnetic force strength

Type:

int

x

Magnetic force direction (X axis)

Type:

int

y

Magnetic force direction (Y axis)

Type:

int

z

Magnetic force direction (Z axis)

Type:

int

References

https://toio.github.io/toio-spec/en/docs/ble_magnetic_sensor/#obtaining-magnetic-sensor-information-

static is_myself(payload: bytearray) bool[source]

If argument data is a byte representation of this class, this function converts the byte representation to an object and returns it.

Parameters:

data (GattReadData) – received data from the cube.

__init__(payload: bytearray)[source]
class toio.cube.Sensor(interface: CubeInterface)[source]

Bases: CubeCharacteristic

Sensor information characteristic

References

Motion detection

Posture angle detection

Magnetic sensor

static is_my_data(payload: bytearray) MotionDetectionData | PostureAngleEulerData | PostureAngleQuaternionsData | MagneticSensorData | None[source]

If payload is my characteristic response, this function returns CubeResponse object. Otherwise, it returns None.

Parameters:

payload (GattReadData) – received data from the cube.

__init__(interface: CubeInterface)[source]
async read() MotionDetectionData | PostureAngleEulerData | PostureAngleQuaternionsData | MagneticSensorData | None[source]

Read sensor information response

Returns:

One of SensorInformationData or None (None returns when read fails)

async request_motion_information() None[source]

Send motion information request command

async request_posture_angle_information(data_type: PostureDataType) None[source]

Send posture angle information request command

async request_magnetic_sensor_information() None[source]

Send magnetic sensor information request

class toio.cube.SoundId(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Sound effect ID

References

https://toio.github.io/toio-spec/en/docs/ble_sound#sound-effect-id

Enter = 0
Selected = 1
Cancel = 2
Cursor = 3
MatIn = 4
MatOut = 5
Get1 = 6
Get2 = 7
Get3 = 8
Effect1 = 9
Effect2 = 10
class toio.cube.Note(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Midi notes

References

https://toio.github.io/toio-spec/en/docs/ble_sound#midi-note-number-and-note-name

C0 = 0
CS0 = 1
D0 = 2
DS0 = 3
E0 = 4
F0 = 5
FS0 = 6
G0 = 7
GS0 = 8
A0 = 9
AS0 = 10
B0 = 11
C1 = 12
CS1 = 13
D1 = 14
DS1 = 15
E1 = 16
F1 = 17
FS1 = 18
G1 = 19
GS1 = 20
A1 = 21
AS1 = 22
B1 = 23
C2 = 24
CS2 = 25
D2 = 26
DS2 = 27
E2 = 28
F2 = 29
FS2 = 30
G2 = 31
GS2 = 32
A2 = 33
AS2 = 34
B2 = 35
C3 = 36
CS3 = 37
D3 = 38
DS3 = 39
E3 = 40
F3 = 41
FS3 = 42
G3 = 43
GS3 = 44
A3 = 45
AS3 = 46
B3 = 47
C4 = 48
CS4 = 49
D4 = 50
DS4 = 51
E4 = 52
F4 = 53
FS4 = 54
G4 = 55
GS4 = 56
A4 = 57
AS4 = 58
B4 = 59
C5 = 60
CS5 = 61
D5 = 62
DS5 = 63
E5 = 64
F5 = 65
FS5 = 66
G5 = 67
GS5 = 68
A5 = 69
AS5 = 70
B5 = 71
C6 = 72
CS6 = 73
D6 = 74
DS6 = 75
E6 = 76
F6 = 77
FS6 = 78
G6 = 79
GS6 = 80
A6 = 81
AS6 = 82
B6 = 83
C7 = 84
CS7 = 85
D7 = 86
DS7 = 87
E7 = 88
F7 = 89
FS7 = 90
G7 = 91
GS7 = 92
A7 = 93
AS7 = 94
B7 = 95
C8 = 96
CS8 = 97
D8 = 98
DS8 = 99
E8 = 100
F8 = 101
FS8 = 102
G8 = 103
GS8 = 104
A8 = 105
AS8 = 106
B8 = 107
C9 = 108
CS9 = 109
D9 = 110
DS9 = 111
E9 = 112
F9 = 113
FS9 = 114
G9 = 115
GS9 = 116
A9 = 117
AS9 = 118
B9 = 119
C10 = 120
CS10 = 121
D10 = 122
DS10 = 123
E10 = 124
F10 = 125
FS10 = 126
G10 = 127
NO_SOUND = 128
class toio.cube.MidiNote(duration_ms: int, note: Note, volume: int)[source]

Bases: object

Midi note

duration_ms: int
Duration of sounding note:
Any fraction less than 10ms will be truncated.
0 - 9: zero
10 - 2550: duration [ms]
note: Note

Midi note

volume: int
Volume:
0: off
1 - 255: max volume
flatten()[source]
__init__(duration_ms: int, note: Note, volume: int) None
class toio.cube.Sound(interface: CubeInterface)[source]

Bases: CubeCharacteristic

Sound characteristic

References

https://toio.github.io/toio-spec/en/docs/ble_sound

static is_my_data(_payload: bytearray) None[source]

If payload is my characteristic response, this function returns CubeResponse object. Otherwise, it returns None.

Parameters:

payload (GattReadData) – received data from the cube.

__init__(interface: CubeInterface)[source]
async play_sound_effect(sound_id: SoundId, volume: int)[source]

Send play sound effect command

Parameters:
  • sound_id (SoundId) – Sound ID

  • volume (int) – Volume

async play_midi(repeat: int, midi_notes: list[toio.cube.api.sound.MidiNote] | tuple[toio.cube.api.sound.MidiNote, ...])[source]

Send play midi note command

Parameters:
  • repeat (int) – Number of repetitions (0: Infinite)

  • midi_notes (Union[list[MidiNote], tuple[MidiNote, ...]]) – List of midi notes

async stop()[source]

Send sound stop command

Subpackages