toio.cube package¶
- class toio.cube.ToioCoreCube(interface: CubeInterface, name: str | None = None)[source]
Bases:
CubeInterfaceAccess to toio Core Cube
- interface
control interface (e.g. BleCube)
- Type:
- 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:
objectControl 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
- 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:
CubeResponseCube 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:
CubeCharacteristicBattery 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:
IntEnumValue of the state of cube button
- RELEASED = 0
- PRESSED = 128
- class toio.cube.ButtonInformation(payload: bytearray)[source]
Bases:
CubeResponseCube button state response
- state
State of the cube button
- Type:
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:
CubeCharacteristicButton 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:
IntEnumNotification 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:
IntEnumNotification 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:
CubeResponseProtocol 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:
CubeResponseID notification setting response
- result
Result of the command
- Type:
bool
References
- 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:
CubeResponseID missed notification setting response
- result
Result of the command
- Type:
bool
References
- 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:
CubeResponseMagnetic 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:
CubeResponseMotor speed information setting response
- result
Result of the command
- Type:
bool
References
- 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:
CubeResponsePosture angle detection setting response
- result
Result of the command
- Type:
bool
References
- 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:
CubeCharacteristicConfiguration 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
- 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:
interval_ms (int) – Notification interval [ms]
condition (NotificationCondition) – Condition
References
- 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
- 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:
function_type (MagneticSensorFunction) – Function type
interval_ms (int) – Notification interval [ms]
condition (MagneticSensorCondition) – Condition
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
- 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:
detection_type (PostureAngleDetectionType) – Detection type
interval_ms (int) – Notification interval [ms]
condition (PostureAngleDetectionCondition) – Condition
References
https://toio.github.io/toio-spec/en/docs/ble_configuration#posture-angle-detection-settings-
- class toio.cube.PositionId(payload: bytearray)[source]
Bases:
CubeResponsePosition 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:
CubeResponseStandard 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:
CubeResponsePosition 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:
CubeResponseStandard 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:
CubeCharacteristicID 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:
objectIndicator 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:
objectIndicator color and lighting period
- duration_ms: int
- Duration of lighting:Any fraction less than 10ms will be truncated.0 - 9: no time limit10 - 2550: duration [ms]
- color: Color
- RGB value
- flatten()[source]
- __init__(duration_ms: int, color: Color) None
- class toio.cube.Indicator(interface: CubeInterface)[source]
Bases:
CubeCharacteristicIndicator 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:
repeat (int) – Number of repetitions
param_list (Union[list[IndicatorParam], tuple[IndicatorParam]]) – List of indicator 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:
IntEnumMovement 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:
IntEnumRotation 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:
objectTarget 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:
IntEnumSpeed 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:
objectSpeed 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:
IntEnumWrite 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:
IntEnumRotational direction when the cube is changing orientation
References
- 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:
IntEnumDirection 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:
IntEnumPriority 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:
EnumResponse 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:
CubeResponseTarget specified motor control response
- response_code
Response code
- Type:
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:
CubeResponseMultiple target specified motor control response
- response_code
Response code
- Type:
References
- 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:
CubeResponseMotor 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:
CubeCharacteristicMotor 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:
IntEnumOrientation of the cube.
- Unknown = 0
- Top = 1
- Bottom = 2
- Rear = 3
- Front = 4
- Right = 5
- Left = 6
- class toio.cube.MotionDetectionData(payload: bytearray)[source]
Bases:
CubeResponseInformation 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:
- 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:
CubeResponseInformation of posture angle (Euler angle)
- roll
Roll (X axis)
- Type:
int
- pitch
Pitch (Y axis)
- Type:
int
- yaw
Yaw (Z axis)
- Type:
nt
References
- 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:
CubeResponsePostureAngleQuaternionData
Information of posture angle (Quaternion)
- w
- Type:
int
- x
- Type:
int
- y
- Type:
int
- z
- Type:
int
References
- 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:
CubeResponseInformation 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:
CubeCharacteristicSensor information characteristic
References
- 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:
IntEnumSound 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:
IntEnumMidi 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:
objectMidi note
- duration_ms: int
- Duration of sounding note:Any fraction less than 10ms will be truncated.0 - 9: zero10 - 2550: duration [ms]
- note: Note
Midi note
- volume: int
- Volume:0: off1 - 255: max volume
- flatten()[source]
- __init__(duration_ms: int, note: Note, volume: int) None
- class toio.cube.Sound(interface: CubeInterface)[source]
Bases:
CubeCharacteristicSound 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
- async stop()[source]
Send sound stop command
Subpackages¶
- toio.cube.api package
- Submodules
- toio.cube.api.base_class module
- toio.cube.api.battery module
- toio.cube.api.button module
- toio.cube.api.configuration module
RequestProtocolVersionSetHorizontalDetectionThresholdSetCollisionDetectionThresholdSetDoubleTapDetectionTimeIntervalNotificationConditionSetIdNotificationSetIdMissedNotificationMagneticSensorFunctionMagneticSensorConditionSetMagneticSensorMotorSpeedInformationAcquisitionStateSetMotorSpeedInformationAcquisitionPostureAngleDetectionTypePostureAngleDetectionConditionSetPostureAngleDetectionProtocolVersionResponseIdNotificationSettingsResponseIdMissedNotificationSettingsResponseMagneticSensorSettingsResponseMotorSpeedInformationAcquisitionSettingsResponsePostureAngleDetectionSettingsConfigurationResponseTypeConfigurationConfiguration.is_my_data()Configuration.__init__()Configuration.request_protocol_version()Configuration.set_horizontal_detection_threshold()Configuration.set_collision_detection_threshold()Configuration.set_double_tap_detection_threshold()Configuration.set_id_notification()Configuration.set_id_missed_notification()Configuration.set_magnetic_sensor()Configuration.set_motor_speed_information_acquisition()Configuration.set_posture_angle_detection()
- toio.cube.api.id_information module
- toio.cube.api.indicator module
- toio.cube.api.motor module
MotorControlMovementTypeRotationOptionTargetPositionSpeedChangeTypeSpeedMotorControlTargetWriteModeMotorControlMultipleTargetsAccelerationRotationAccelerationDirectionAccelerationPriorityMotorControlAccelerationMotorResponseCodeResponseMotorControlTargetResponseMotorControlMultipleTargetsResponseMotorSpeedMotorResponseTypeMotor
- toio.cube.api.sensor module
- toio.cube.api.sound module
SoundIdNoteNote.C0Note.CS0Note.D0Note.DS0Note.E0Note.F0Note.FS0Note.G0Note.GS0Note.A0Note.AS0Note.B0Note.C1Note.CS1Note.D1Note.DS1Note.E1Note.F1Note.FS1Note.G1Note.GS1Note.A1Note.AS1Note.B1Note.C2Note.CS2Note.D2Note.DS2Note.E2Note.F2Note.FS2Note.G2Note.GS2Note.A2Note.AS2Note.B2Note.C3Note.CS3Note.D3Note.DS3Note.E3Note.F3Note.FS3Note.G3Note.GS3Note.A3Note.AS3Note.B3Note.C4Note.CS4Note.D4Note.DS4Note.E4Note.F4Note.FS4Note.G4Note.GS4Note.A4Note.AS4Note.B4Note.C5Note.CS5Note.D5Note.DS5Note.E5Note.F5Note.FS5Note.G5Note.GS5Note.A5Note.AS5Note.B5Note.C6Note.CS6Note.D6Note.DS6Note.E6Note.F6Note.FS6Note.G6Note.GS6Note.A6Note.AS6Note.B6Note.C7Note.CS7Note.D7Note.DS7Note.E7Note.F7Note.FS7Note.G7Note.GS7Note.A7Note.AS7Note.B7Note.C8Note.CS8Note.D8Note.DS8Note.E8Note.F8Note.FS8Note.G8Note.GS8Note.A8Note.AS8Note.B8Note.C9Note.CS9Note.D9Note.DS9Note.E9Note.F9Note.FS9Note.G9Note.GS9Note.A9Note.AS9Note.B9Note.C10Note.CS10Note.D10Note.DS10Note.E10Note.F10Note.FS10Note.G10Note.NO_SOUND
MidiNotePlaySoundEffectPlayMidiStopSound
- Submodules